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

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

mercurial