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

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/browser/metro/base/content/helperui/OfflineApps.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,81 @@
     1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.7 +
     1.8 +/*
     1.9 + * Provide supports for Offline Applications
    1.10 + */
    1.11 +var OfflineApps = {
    1.12 +  offlineAppRequested: function(aRequest, aTarget) {
    1.13 +    if (!Services.prefs.getBoolPref("browser.offline-apps.notify"))
    1.14 +      return;
    1.15 +
    1.16 +    let currentURI = Services.io.newURI(aRequest.location, aRequest.charset, null);
    1.17 +
    1.18 +    // don't bother showing UI if the user has already made a decision
    1.19 +    if (Services.perms.testExactPermission(currentURI, "offline-app") != Ci.nsIPermissionManager.UNKNOWN_ACTION)
    1.20 +      return;
    1.21 +
    1.22 +    try {
    1.23 +      if (Services.prefs.getBoolPref("offline-apps.allow_by_default")) {
    1.24 +        // all pages can use offline capabilities, no need to ask the user
    1.25 +        return;
    1.26 +      }
    1.27 +    } catch(e) {
    1.28 +      // this pref isn't set by default, ignore failures
    1.29 +    }
    1.30 +
    1.31 +    let host = currentURI.asciiHost;
    1.32 +    let notificationID = "offline-app-requested-" + host;
    1.33 +    let notificationBox = Browser.getNotificationBox(aTarget);
    1.34 +
    1.35 +    let notification = notificationBox.getNotificationWithValue(notificationID);
    1.36 +    let strings = Strings.browser;
    1.37 +    if (notification) {
    1.38 +      notification.documents.push(aRequest);
    1.39 +    } else {
    1.40 +      let buttons = [{
    1.41 +        label: strings.GetStringFromName("offlineApps.allow"),
    1.42 +        accessKey: "",
    1.43 +        callback: function() {
    1.44 +          for (let i = 0; i < notification.documents.length; i++)
    1.45 +            OfflineApps.allowSite(notification.documents[i], aTarget);
    1.46 +        }
    1.47 +      },{
    1.48 +        label: strings.GetStringFromName("contentPermissions.neverForSite"),
    1.49 +        accessKey: "",
    1.50 +        callback: function() {
    1.51 +          for (let i = 0; i < notification.documents.length; i++)
    1.52 +            OfflineApps.disallowSite(notification.documents[i]);
    1.53 +        }
    1.54 +      }];
    1.55 +
    1.56 +      const priority = notificationBox.PRIORITY_INFO_LOW;
    1.57 +      let message = strings.formatStringFromName("offlineApps.wantsTo", [host], 1);
    1.58 +      notification = notificationBox.appendNotification(message, notificationID, "", priority, buttons);
    1.59 +      notification.documents = [aRequest];
    1.60 +    }
    1.61 +  },
    1.62 +
    1.63 +  allowSite: function(aRequest, aTarget) {
    1.64 +    let currentURI = Services.io.newURI(aRequest.location, aRequest.charset, null);
    1.65 +    Services.perms.add(currentURI, "offline-app", Ci.nsIPermissionManager.ALLOW_ACTION);
    1.66 +
    1.67 +    // When a site is enabled while loading, manifest resources will start
    1.68 +    // fetching immediately.  This one time we need to do it ourselves.
    1.69 +    // The update must be started on the content process.
    1.70 +    aTarget.messageManager.sendAsyncMessage("Browser:MozApplicationCache:Fetch", aRequest);
    1.71 +  },
    1.72 +
    1.73 +  disallowSite: function(aRequest) {
    1.74 +    let currentURI = Services.io.newURI(aRequest.location, aRequest.charset, null);
    1.75 +    Services.perms.add(currentURI, "offline-app", Ci.nsIPermissionManager.DENY_ACTION);
    1.76 +  },
    1.77 +
    1.78 +  receiveMessage: function receiveMessage(aMessage) {
    1.79 +    if (aMessage.name == "Browser:MozApplicationManifest") {
    1.80 +      this.offlineAppRequested(aMessage.json, aMessage.target);
    1.81 +    }
    1.82 +  }
    1.83 +};
    1.84 +

mercurial