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