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 | this.EXPORTED_SYMBOLS = ["PrivateBrowsingUtils"]; |
michael@0 | 6 | |
michael@0 | 7 | Components.utils.import("resource://gre/modules/Services.jsm"); |
michael@0 | 8 | |
michael@0 | 9 | const kAutoStartPref = "browser.privatebrowsing.autostart"; |
michael@0 | 10 | |
michael@0 | 11 | // This will be set to true when the PB mode is autostarted from the command |
michael@0 | 12 | // line for the current session. |
michael@0 | 13 | let gTemporaryAutoStartMode = false; |
michael@0 | 14 | |
michael@0 | 15 | const Cc = Components.classes; |
michael@0 | 16 | const Ci = Components.interfaces; |
michael@0 | 17 | |
michael@0 | 18 | this.PrivateBrowsingUtils = { |
michael@0 | 19 | isWindowPrivate: function pbu_isWindowPrivate(aWindow) { |
michael@0 | 20 | return this.privacyContextFromWindow(aWindow).usePrivateBrowsing; |
michael@0 | 21 | }, |
michael@0 | 22 | |
michael@0 | 23 | privacyContextFromWindow: function pbu_privacyContextFromWindow(aWindow) { |
michael@0 | 24 | return aWindow.QueryInterface(Ci.nsIInterfaceRequestor) |
michael@0 | 25 | .getInterface(Ci.nsIWebNavigation) |
michael@0 | 26 | .QueryInterface(Ci.nsILoadContext); |
michael@0 | 27 | }, |
michael@0 | 28 | |
michael@0 | 29 | get permanentPrivateBrowsing() { |
michael@0 | 30 | try { |
michael@0 | 31 | return gTemporaryAutoStartMode || |
michael@0 | 32 | Services.prefs.getBoolPref(kAutoStartPref); |
michael@0 | 33 | } catch (e) { |
michael@0 | 34 | // The pref does not exist |
michael@0 | 35 | return false; |
michael@0 | 36 | } |
michael@0 | 37 | }, |
michael@0 | 38 | |
michael@0 | 39 | // These should only be used from internal code |
michael@0 | 40 | enterTemporaryAutoStartMode: function pbu_enterTemporaryAutoStartMode() { |
michael@0 | 41 | gTemporaryAutoStartMode = true; |
michael@0 | 42 | }, |
michael@0 | 43 | get isInTemporaryAutoStartMode() { |
michael@0 | 44 | return gTemporaryAutoStartMode; |
michael@0 | 45 | }, |
michael@0 | 46 | |
michael@0 | 47 | whenHiddenPrivateWindowReady: function pbu_whenHiddenPrivateWindowReady(cb) { |
michael@0 | 48 | Components.utils.import("resource://gre/modules/Timer.jsm"); |
michael@0 | 49 | |
michael@0 | 50 | let win = Services.appShell.hiddenPrivateDOMWindow; |
michael@0 | 51 | function isNotLoaded() { |
michael@0 | 52 | return ["complete", "interactive"].indexOf(win.document.readyState) == -1; |
michael@0 | 53 | } |
michael@0 | 54 | if (isNotLoaded()) { |
michael@0 | 55 | setTimeout(function poll() { |
michael@0 | 56 | if (isNotLoaded()) { |
michael@0 | 57 | setTimeout(poll, 100); |
michael@0 | 58 | return; |
michael@0 | 59 | } |
michael@0 | 60 | cb(Services.appShell.hiddenPrivateDOMWindow); |
michael@0 | 61 | }, 4); |
michael@0 | 62 | } else { |
michael@0 | 63 | cb(Services.appShell.hiddenPrivateDOMWindow); |
michael@0 | 64 | } |
michael@0 | 65 | } |
michael@0 | 66 | }; |
michael@0 | 67 |