Wed, 31 Dec 2014 06:09:35 +0100
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 | |
michael@0 | 5 | /** |
michael@0 | 6 | * This component triggers a periodic webapp update check. |
michael@0 | 7 | */ |
michael@0 | 8 | |
michael@0 | 9 | "use strict"; |
michael@0 | 10 | |
michael@0 | 11 | const Cc = Components.classes; |
michael@0 | 12 | const Ci = Components.interfaces; |
michael@0 | 13 | const Cu = Components.utils; |
michael@0 | 14 | |
michael@0 | 15 | Cu.import("resource://gre/modules/Services.jsm"); |
michael@0 | 16 | Cu.import("resource://gre/modules/WebappManager.jsm"); |
michael@0 | 17 | Cu.import("resource://gre/modules/XPCOMUtils.jsm"); |
michael@0 | 18 | |
michael@0 | 19 | function log(message) { |
michael@0 | 20 | // We use *dump* instead of Services.console.logStringMessage so the messages |
michael@0 | 21 | // have the INFO level of severity instead of the ERROR level. And we don't |
michael@0 | 22 | // append a newline character to the end of the message because *dump* spills |
michael@0 | 23 | // into the Android native logging system, which strips newlines from messages |
michael@0 | 24 | // and breaks messages into lines automatically at display time (i.e. logcat). |
michael@0 | 25 | dump(message); |
michael@0 | 26 | } |
michael@0 | 27 | |
michael@0 | 28 | function WebappsUpdateTimer() {} |
michael@0 | 29 | |
michael@0 | 30 | WebappsUpdateTimer.prototype = { |
michael@0 | 31 | QueryInterface: XPCOMUtils.generateQI([Ci.nsITimerCallback, |
michael@0 | 32 | Ci.nsISupportsWeakReference]), |
michael@0 | 33 | classID: Components.ID("{8f7002cb-e959-4f0a-a2e8-563232564385}"), |
michael@0 | 34 | |
michael@0 | 35 | notify: function(aTimer) { |
michael@0 | 36 | if (Services.prefs.getIntPref("browser.webapps.checkForUpdates") == 0) { |
michael@0 | 37 | // Do nothing, because updates are disabled. |
michael@0 | 38 | log("Webapps update timer invoked in webapp process; ignoring."); |
michael@0 | 39 | return; |
michael@0 | 40 | } |
michael@0 | 41 | |
michael@0 | 42 | // If we are offline, wait to be online to start the update check. |
michael@0 | 43 | if (Services.io.offline) { |
michael@0 | 44 | log("network offline for webapp update check; waiting"); |
michael@0 | 45 | Services.obs.addObserver(this, "network:offline-status-changed", true); |
michael@0 | 46 | return; |
michael@0 | 47 | } |
michael@0 | 48 | |
michael@0 | 49 | log("periodic check for webapp updates"); |
michael@0 | 50 | WebappManager.checkForUpdates(); |
michael@0 | 51 | }, |
michael@0 | 52 | |
michael@0 | 53 | observe: function(aSubject, aTopic, aData) { |
michael@0 | 54 | if (aTopic !== "network:offline-status-changed" || aData !== "online") { |
michael@0 | 55 | return; |
michael@0 | 56 | } |
michael@0 | 57 | |
michael@0 | 58 | log("network back online for webapp update check; commencing"); |
michael@0 | 59 | // TODO: observe pref to do this only on wifi. |
michael@0 | 60 | Services.obs.removeObserver(this, "network:offline-status-changed"); |
michael@0 | 61 | WebappManager.checkForUpdates(); |
michael@0 | 62 | } |
michael@0 | 63 | }; |
michael@0 | 64 | |
michael@0 | 65 | this.NSGetFactory = XPCOMUtils.generateNSGetFactory([WebappsUpdateTimer]); |