2012-07-03 18:35:03 +04: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/. */
|
|
|
|
|
2018-02-23 22:50:01 +03:00
|
|
|
var EXPORTED_SYMBOLS = ["PrivateBrowsingUtils"];
|
2012-07-03 18:35:03 +04:00
|
|
|
|
2019-01-17 21:18:31 +03:00
|
|
|
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
|
2018-05-24 14:12:30 +03:00
|
|
|
|
2012-11-07 23:07:35 +04: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.
|
2015-09-15 21:19:45 +03:00
|
|
|
var gTemporaryAutoStartMode = false;
|
2012-10-17 02:06:38 +04:00
|
|
|
|
2018-02-23 22:50:01 +03:00
|
|
|
var PrivateBrowsingUtils = {
|
2018-03-01 19:20:38 +03:00
|
|
|
get enabled() {
|
|
|
|
return Services.policies.isAllowed("privatebrowsing");
|
|
|
|
},
|
|
|
|
|
2014-09-18 19:56:55 +04:00
|
|
|
// Rather than passing content windows to this function, please use
|
|
|
|
// isBrowserPrivate since it works with e10s.
|
2012-07-03 18:35:03 +04:00
|
|
|
isWindowPrivate: function pbu_isWindowPrivate(aWindow) {
|
2017-10-06 14:47:27 +03:00
|
|
|
if (!aWindow.isChromeWindow) {
|
2014-09-24 02:48:52 +04:00
|
|
|
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 22:17:35 +04:00
|
|
|
return this.privacyContextFromWindow(aWindow).usePrivateBrowsing;
|
|
|
|
},
|
|
|
|
|
2016-12-30 02:34:54 +03:00
|
|
|
isBrowserPrivate(aBrowser) {
|
2017-01-27 12:51:03 +03:00
|
|
|
let chromeWin = aBrowser.ownerGlobal;
|
2017-08-22 07:04:19 +03:00
|
|
|
if (chromeWin.gMultiProcessBrowser || !aBrowser.contentWindow) {
|
2014-10-01 00:53:09 +04:00
|
|
|
// In e10s we have to look at the chrome window's private
|
|
|
|
// browsing status since the only alternative is to check the
|
2017-04-20 12:01:09 +03:00
|
|
|
// content window, which is in another process. If the browser
|
2017-08-22 07:04:19 +03:00
|
|
|
// is lazy or is running in windowless configuration then the
|
|
|
|
// content window doesn't exist.
|
2014-10-01 00:53:09 +04:00
|
|
|
return this.isWindowPrivate(chromeWin);
|
|
|
|
}
|
2016-08-04 01:54:59 +03:00
|
|
|
return this.privacyContextFromWindow(aBrowser.contentWindow)
|
|
|
|
.usePrivateBrowsing;
|
2014-09-18 19:56:55 +04:00
|
|
|
},
|
|
|
|
|
2012-10-25 22:17:35 +04:00
|
|
|
privacyContextFromWindow: function pbu_privacyContextFromWindow(aWindow) {
|
2018-08-01 20:07:09 +03:00
|
|
|
return aWindow.docShell.QueryInterface(Ci.nsILoadContext);
|
2012-10-10 04:34:59 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
get permanentPrivateBrowsing() {
|
2013-02-26 20:31:35 +04:00
|
|
|
try {
|
|
|
|
return (
|
|
|
|
gTemporaryAutoStartMode || Services.prefs.getBoolPref(kAutoStartPref)
|
|
|
|
);
|
|
|
|
} catch (e) {
|
|
|
|
// The pref does not exist
|
|
|
|
return false;
|
|
|
|
}
|
2012-11-07 23:07:35 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
// These should only be used from internal code
|
|
|
|
enterTemporaryAutoStartMode: function pbu_enterTemporaryAutoStartMode() {
|
|
|
|
gTemporaryAutoStartMode = true;
|
|
|
|
},
|
|
|
|
get isInTemporaryAutoStartMode() {
|
|
|
|
return gTemporaryAutoStartMode;
|
2013-03-15 01:51:49 +04:00
|
|
|
},
|
2012-07-03 18:35:03 +04:00
|
|
|
};
|