browser/metro/base/content/helperui/OfflineApps.js

Wed, 31 Dec 2014 06:55:50 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:55:50 +0100
changeset 2
7e26c7da4463
permissions
-rw-r--r--

Added tag UPSTREAM_283F7C6 for changeset ca08bd8f51b2

michael@0 1 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 2 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 4
michael@0 5 /*
michael@0 6 * Provide supports for Offline Applications
michael@0 7 */
michael@0 8 var OfflineApps = {
michael@0 9 offlineAppRequested: function(aRequest, aTarget) {
michael@0 10 if (!Services.prefs.getBoolPref("browser.offline-apps.notify"))
michael@0 11 return;
michael@0 12
michael@0 13 let currentURI = Services.io.newURI(aRequest.location, aRequest.charset, null);
michael@0 14
michael@0 15 // don't bother showing UI if the user has already made a decision
michael@0 16 if (Services.perms.testExactPermission(currentURI, "offline-app") != Ci.nsIPermissionManager.UNKNOWN_ACTION)
michael@0 17 return;
michael@0 18
michael@0 19 try {
michael@0 20 if (Services.prefs.getBoolPref("offline-apps.allow_by_default")) {
michael@0 21 // all pages can use offline capabilities, no need to ask the user
michael@0 22 return;
michael@0 23 }
michael@0 24 } catch(e) {
michael@0 25 // this pref isn't set by default, ignore failures
michael@0 26 }
michael@0 27
michael@0 28 let host = currentURI.asciiHost;
michael@0 29 let notificationID = "offline-app-requested-" + host;
michael@0 30 let notificationBox = Browser.getNotificationBox(aTarget);
michael@0 31
michael@0 32 let notification = notificationBox.getNotificationWithValue(notificationID);
michael@0 33 let strings = Strings.browser;
michael@0 34 if (notification) {
michael@0 35 notification.documents.push(aRequest);
michael@0 36 } else {
michael@0 37 let buttons = [{
michael@0 38 label: strings.GetStringFromName("offlineApps.allow"),
michael@0 39 accessKey: "",
michael@0 40 callback: function() {
michael@0 41 for (let i = 0; i < notification.documents.length; i++)
michael@0 42 OfflineApps.allowSite(notification.documents[i], aTarget);
michael@0 43 }
michael@0 44 },{
michael@0 45 label: strings.GetStringFromName("contentPermissions.neverForSite"),
michael@0 46 accessKey: "",
michael@0 47 callback: function() {
michael@0 48 for (let i = 0; i < notification.documents.length; i++)
michael@0 49 OfflineApps.disallowSite(notification.documents[i]);
michael@0 50 }
michael@0 51 }];
michael@0 52
michael@0 53 const priority = notificationBox.PRIORITY_INFO_LOW;
michael@0 54 let message = strings.formatStringFromName("offlineApps.wantsTo", [host], 1);
michael@0 55 notification = notificationBox.appendNotification(message, notificationID, "", priority, buttons);
michael@0 56 notification.documents = [aRequest];
michael@0 57 }
michael@0 58 },
michael@0 59
michael@0 60 allowSite: function(aRequest, aTarget) {
michael@0 61 let currentURI = Services.io.newURI(aRequest.location, aRequest.charset, null);
michael@0 62 Services.perms.add(currentURI, "offline-app", Ci.nsIPermissionManager.ALLOW_ACTION);
michael@0 63
michael@0 64 // When a site is enabled while loading, manifest resources will start
michael@0 65 // fetching immediately. This one time we need to do it ourselves.
michael@0 66 // The update must be started on the content process.
michael@0 67 aTarget.messageManager.sendAsyncMessage("Browser:MozApplicationCache:Fetch", aRequest);
michael@0 68 },
michael@0 69
michael@0 70 disallowSite: function(aRequest) {
michael@0 71 let currentURI = Services.io.newURI(aRequest.location, aRequest.charset, null);
michael@0 72 Services.perms.add(currentURI, "offline-app", Ci.nsIPermissionManager.DENY_ACTION);
michael@0 73 },
michael@0 74
michael@0 75 receiveMessage: function receiveMessage(aMessage) {
michael@0 76 if (aMessage.name == "Browser:MozApplicationManifest") {
michael@0 77 this.offlineAppRequested(aMessage.json, aMessage.target);
michael@0 78 }
michael@0 79 }
michael@0 80 };
michael@0 81

mercurial