forked from mozilla/gecko-dev
-
Notifications
You must be signed in to change notification settings - Fork 2
/
PrivateBrowsingUtils.jsm
67 lines (55 loc) · 2.05 KB
/
PrivateBrowsingUtils.jsm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
this.EXPORTED_SYMBOLS = ["PrivateBrowsingUtils"];
Components.utils.import("resource://gre/modules/Services.jsm");
const kAutoStartPref = "browser.privatebrowsing.autostart";
// This will be set to true when the PB mode is autostarted from the command
// line for the current session.
let gTemporaryAutoStartMode = false;
const Cc = Components.classes;
const Ci = Components.interfaces;
this.PrivateBrowsingUtils = {
isWindowPrivate: function pbu_isWindowPrivate(aWindow) {
return this.privacyContextFromWindow(aWindow).usePrivateBrowsing;
},
privacyContextFromWindow: function pbu_privacyContextFromWindow(aWindow) {
return aWindow.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIWebNavigation)
.QueryInterface(Ci.nsILoadContext);
},
get permanentPrivateBrowsing() {
try {
return gTemporaryAutoStartMode ||
Services.prefs.getBoolPref(kAutoStartPref);
} catch (e) {
// The pref does not exist
return false;
}
},
// These should only be used from internal code
enterTemporaryAutoStartMode: function pbu_enterTemporaryAutoStartMode() {
gTemporaryAutoStartMode = true;
},
get isInTemporaryAutoStartMode() {
return gTemporaryAutoStartMode;
},
whenHiddenPrivateWindowReady: function pbu_whenHiddenPrivateWindowReady(cb) {
Components.utils.import("resource://gre/modules/Timer.jsm");
let win = Services.appShell.hiddenPrivateDOMWindow;
function isNotLoaded() {
return ["complete", "interactive"].indexOf(win.document.readyState) == -1;
}
if (isNotLoaded()) {
setTimeout(function poll() {
if (isNotLoaded()) {
setTimeout(poll, 100);
return;
}
cb(Services.appShell.hiddenPrivateDOMWindow);
}, 4);
} else {
cb(Services.appShell.hiddenPrivateDOMWindow);
}
}
};