2012-07-03 14:35:03 +00:00
|
|
|
/* 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/. */
|
|
|
|
|
2012-10-31 16:13:28 +00:00
|
|
|
this.EXPORTED_SYMBOLS = ["PrivateBrowsingUtils"];
|
2012-07-03 14:35:03 +00:00
|
|
|
|
2012-10-16 22:06:38 +00:00
|
|
|
Components.utils.import("resource://gre/modules/Services.jsm");
|
|
|
|
|
2012-11-07 19:07:35 +00:00
|
|
|
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;
|
2012-10-16 22:06:38 +00:00
|
|
|
|
2012-10-10 00:34:59 +00:00
|
|
|
const Cc = Components.classes;
|
2012-07-03 14:35:03 +00:00
|
|
|
const Ci = Components.interfaces;
|
|
|
|
|
2012-10-31 16:13:28 +00:00
|
|
|
this.PrivateBrowsingUtils = {
|
2014-09-18 15:56:55 +00:00
|
|
|
// Rather than passing content windows to this function, please use
|
|
|
|
// isBrowserPrivate since it works with e10s.
|
2012-07-03 14:35:03 +00:00
|
|
|
isWindowPrivate: function pbu_isWindowPrivate(aWindow) {
|
2014-09-23 22:48:52 +00:00
|
|
|
if (!(aWindow instanceof Components.interfaces.nsIDOMChromeWindow)) {
|
|
|
|
dump("WARNING: content window passed to PrivateBrowsingUtils.isWindowPrivate. " +
|
|
|
|
"Use isContentWindowPrivate instead (but only for frame scripts).\n"
|
|
|
|
+ new Error().stack);
|
|
|
|
}
|
|
|
|
|
|
|
|
return this.privacyContextFromWindow(aWindow).usePrivateBrowsing;
|
|
|
|
},
|
|
|
|
|
|
|
|
// This should be used only in frame scripts.
|
|
|
|
isContentWindowPrivate: function pbu_isWindowPrivate(aWindow) {
|
2012-10-25 18:17:35 +00:00
|
|
|
return this.privacyContextFromWindow(aWindow).usePrivateBrowsing;
|
|
|
|
},
|
|
|
|
|
2014-09-18 15:56:55 +00:00
|
|
|
isBrowserPrivate: function(aBrowser) {
|
2014-09-30 20:53:09 +00:00
|
|
|
let chromeWin = aBrowser.ownerDocument.defaultView;
|
|
|
|
if (chromeWin.gMultiProcessBrowser) {
|
|
|
|
// In e10s we have to look at the chrome window's private
|
|
|
|
// browsing status since the only alternative is to check the
|
|
|
|
// content window, which is in another process.
|
|
|
|
return this.isWindowPrivate(chromeWin);
|
|
|
|
} else {
|
|
|
|
return this.privacyContextFromWindow(aBrowser.contentWindow).usePrivateBrowsing;
|
|
|
|
}
|
2014-09-18 15:56:55 +00:00
|
|
|
},
|
|
|
|
|
2012-10-25 18:17:35 +00:00
|
|
|
privacyContextFromWindow: function pbu_privacyContextFromWindow(aWindow) {
|
2012-07-03 14:35:03 +00:00
|
|
|
return aWindow.QueryInterface(Ci.nsIInterfaceRequestor)
|
|
|
|
.getInterface(Ci.nsIWebNavigation)
|
2012-10-25 18:17:35 +00:00
|
|
|
.QueryInterface(Ci.nsILoadContext);
|
2012-10-10 00:34:59 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
get permanentPrivateBrowsing() {
|
2013-02-26 16:31:35 +00:00
|
|
|
try {
|
|
|
|
return gTemporaryAutoStartMode ||
|
|
|
|
Services.prefs.getBoolPref(kAutoStartPref);
|
|
|
|
} catch (e) {
|
|
|
|
// The pref does not exist
|
|
|
|
return false;
|
|
|
|
}
|
2012-11-07 19:07:35 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
// These should only be used from internal code
|
|
|
|
enterTemporaryAutoStartMode: function pbu_enterTemporaryAutoStartMode() {
|
|
|
|
gTemporaryAutoStartMode = true;
|
|
|
|
},
|
|
|
|
get isInTemporaryAutoStartMode() {
|
|
|
|
return gTemporaryAutoStartMode;
|
2013-03-14 21:51:49 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
2012-07-03 14:35:03 +00:00
|
|
|
}
|
|
|
|
};
|
2012-10-16 22:06:38 +00:00
|
|
|
|