2012-07-03 07:35:03 -07: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 09:13:28 -07:00
|
|
|
this.EXPORTED_SYMBOLS = ["PrivateBrowsingUtils"];
|
2012-07-03 07:35:03 -07:00
|
|
|
|
2012-10-16 15:06:38 -07:00
|
|
|
Components.utils.import("resource://gre/modules/Services.jsm");
|
|
|
|
|
2012-11-07 11:07:35 -08: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 11:19:45 -07:00
|
|
|
var gTemporaryAutoStartMode = false;
|
2012-10-16 15:06:38 -07:00
|
|
|
|
2012-10-09 17:34:59 -07:00
|
|
|
const Cc = Components.classes;
|
2012-07-03 07:35:03 -07:00
|
|
|
const Ci = Components.interfaces;
|
|
|
|
|
2012-10-31 09:13:28 -07:00
|
|
|
this.PrivateBrowsingUtils = {
|
2014-09-18 08:56:55 -07:00
|
|
|
// Rather than passing content windows to this function, please use
|
|
|
|
// isBrowserPrivate since it works with e10s.
|
2012-07-03 07:35:03 -07:00
|
|
|
isWindowPrivate: function pbu_isWindowPrivate(aWindow) {
|
2014-09-23 15:48:52 -07: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 11:17:35 -07:00
|
|
|
return this.privacyContextFromWindow(aWindow).usePrivateBrowsing;
|
|
|
|
},
|
|
|
|
|
2014-09-18 08:56:55 -07:00
|
|
|
isBrowserPrivate: function(aBrowser) {
|
2014-09-30 13:53:09 -07: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 08:56:55 -07:00
|
|
|
},
|
|
|
|
|
2012-10-25 11:17:35 -07:00
|
|
|
privacyContextFromWindow: function pbu_privacyContextFromWindow(aWindow) {
|
2012-07-03 07:35:03 -07:00
|
|
|
return aWindow.QueryInterface(Ci.nsIInterfaceRequestor)
|
|
|
|
.getInterface(Ci.nsIWebNavigation)
|
2012-10-25 11:17:35 -07:00
|
|
|
.QueryInterface(Ci.nsILoadContext);
|
2012-10-09 17:34:59 -07:00
|
|
|
},
|
|
|
|
|
2015-07-24 03:55:54 -07:00
|
|
|
addToTrackingAllowlist(aURI) {
|
2015-07-28 09:17:18 -07:00
|
|
|
let pbmtpWhitelist = Cc["@mozilla.org/pbm-tp-whitelist;1"]
|
2015-07-24 03:55:54 -07:00
|
|
|
.getService(Ci.nsIPrivateBrowsingTrackingProtectionWhitelist);
|
|
|
|
pbmtpWhitelist.addToAllowList(aURI);
|
|
|
|
},
|
|
|
|
|
|
|
|
removeFromTrackingAllowlist(aURI) {
|
2015-07-28 09:17:18 -07:00
|
|
|
let pbmtpWhitelist = Cc["@mozilla.org/pbm-tp-whitelist;1"]
|
2015-07-24 03:55:54 -07:00
|
|
|
.getService(Ci.nsIPrivateBrowsingTrackingProtectionWhitelist);
|
|
|
|
pbmtpWhitelist.removeFromAllowList(aURI);
|
|
|
|
},
|
|
|
|
|
2012-10-09 17:34:59 -07:00
|
|
|
get permanentPrivateBrowsing() {
|
2013-02-26 08:31:35 -08:00
|
|
|
try {
|
|
|
|
return gTemporaryAutoStartMode ||
|
|
|
|
Services.prefs.getBoolPref(kAutoStartPref);
|
|
|
|
} catch (e) {
|
|
|
|
// The pref does not exist
|
|
|
|
return false;
|
|
|
|
}
|
2012-11-07 11:07:35 -08:00
|
|
|
},
|
|
|
|
|
|
|
|
// These should only be used from internal code
|
|
|
|
enterTemporaryAutoStartMode: function pbu_enterTemporaryAutoStartMode() {
|
|
|
|
gTemporaryAutoStartMode = true;
|
|
|
|
},
|
|
|
|
get isInTemporaryAutoStartMode() {
|
|
|
|
return gTemporaryAutoStartMode;
|
2013-03-14 14:51:49 -07: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 07:35:03 -07:00
|
|
|
}
|
|
|
|
};
|
2012-10-16 15:06:38 -07:00
|
|
|
|