|
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/. */ |
|
4 |
|
5 this.EXPORTED_SYMBOLS = ["PrivateBrowsingUtils"]; |
|
6 |
|
7 Components.utils.import("resource://gre/modules/Services.jsm"); |
|
8 |
|
9 const kAutoStartPref = "browser.privatebrowsing.autostart"; |
|
10 |
|
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; |
|
14 |
|
15 const Cc = Components.classes; |
|
16 const Ci = Components.interfaces; |
|
17 |
|
18 this.PrivateBrowsingUtils = { |
|
19 isWindowPrivate: function pbu_isWindowPrivate(aWindow) { |
|
20 return this.privacyContextFromWindow(aWindow).usePrivateBrowsing; |
|
21 }, |
|
22 |
|
23 privacyContextFromWindow: function pbu_privacyContextFromWindow(aWindow) { |
|
24 return aWindow.QueryInterface(Ci.nsIInterfaceRequestor) |
|
25 .getInterface(Ci.nsIWebNavigation) |
|
26 .QueryInterface(Ci.nsILoadContext); |
|
27 }, |
|
28 |
|
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 }, |
|
38 |
|
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 }, |
|
46 |
|
47 whenHiddenPrivateWindowReady: function pbu_whenHiddenPrivateWindowReady(cb) { |
|
48 Components.utils.import("resource://gre/modules/Timer.jsm"); |
|
49 |
|
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 }; |
|
67 |