mobile/android/chrome/content/OfflineApps.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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 file,
michael@0 3 * You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 4 "use strict";
michael@0 5
michael@0 6 var OfflineApps = {
michael@0 7 offlineAppRequested: function(aContentWindow) {
michael@0 8 if (!Services.prefs.getBoolPref("browser.offline-apps.notify"))
michael@0 9 return;
michael@0 10
michael@0 11 let tab = BrowserApp.getTabForWindow(aContentWindow);
michael@0 12 let currentURI = aContentWindow.document.documentURIObject;
michael@0 13
michael@0 14 // Don't bother showing UI if the user has already made a decision
michael@0 15 if (Services.perms.testExactPermission(currentURI, "offline-app") != Services.perms.UNKNOWN_ACTION)
michael@0 16 return;
michael@0 17
michael@0 18 try {
michael@0 19 if (Services.prefs.getBoolPref("offline-apps.allow_by_default")) {
michael@0 20 // All pages can use offline capabilities, no need to ask the user
michael@0 21 return;
michael@0 22 }
michael@0 23 } catch(e) {
michael@0 24 // This pref isn't set by default, ignore failures
michael@0 25 }
michael@0 26
michael@0 27 let host = currentURI.asciiHost;
michael@0 28 let notificationID = "offline-app-requested-" + host;
michael@0 29
michael@0 30 let strings = Strings.browser;
michael@0 31 let buttons = [{
michael@0 32 label: strings.GetStringFromName("offlineApps.allow"),
michael@0 33 callback: function() {
michael@0 34 OfflineApps.allowSite(aContentWindow.document);
michael@0 35 }
michael@0 36 },
michael@0 37 {
michael@0 38 label: strings.GetStringFromName("offlineApps.dontAllow2"),
michael@0 39 callback: function(aChecked) {
michael@0 40 if (aChecked)
michael@0 41 OfflineApps.disallowSite(aContentWindow.document);
michael@0 42 }
michael@0 43 }];
michael@0 44
michael@0 45 let requestor = BrowserApp.manifest ? "'" + BrowserApp.manifest.name + "'" : host;
michael@0 46 let message = strings.formatStringFromName("offlineApps.ask", [requestor], 1);
michael@0 47 let options = { checkbox: Strings.browser.GetStringFromName("offlineApps.dontAskAgain") };
michael@0 48 NativeWindow.doorhanger.show(message, notificationID, buttons, tab.id, options);
michael@0 49 },
michael@0 50
michael@0 51 allowSite: function(aDocument) {
michael@0 52 Services.perms.add(aDocument.documentURIObject, "offline-app", Services.perms.ALLOW_ACTION);
michael@0 53
michael@0 54 // When a site is enabled while loading, manifest resources will
michael@0 55 // start fetching immediately. This one time we need to do it
michael@0 56 // ourselves.
michael@0 57 this._startFetching(aDocument);
michael@0 58 },
michael@0 59
michael@0 60 disallowSite: function(aDocument) {
michael@0 61 Services.perms.add(aDocument.documentURIObject, "offline-app", Services.perms.DENY_ACTION);
michael@0 62 },
michael@0 63
michael@0 64 _startFetching: function(aDocument) {
michael@0 65 if (!aDocument.documentElement)
michael@0 66 return;
michael@0 67
michael@0 68 let manifest = aDocument.documentElement.getAttribute("manifest");
michael@0 69 if (!manifest)
michael@0 70 return;
michael@0 71
michael@0 72 let manifestURI = Services.io.newURI(manifest, aDocument.characterSet, aDocument.documentURIObject);
michael@0 73 let updateService = Cc["@mozilla.org/offlinecacheupdate-service;1"].getService(Ci.nsIOfflineCacheUpdateService);
michael@0 74 updateService.scheduleUpdate(manifestURI, aDocument.documentURIObject, window);
michael@0 75 }
michael@0 76 };

mercurial