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/. */
|
|
|
|
|
2012-10-31 20:13:28 +04:00
|
|
|
this.EXPORTED_SYMBOLS = ["PrivateBrowsingUtils"];
|
2012-07-03 18:35:03 +04:00
|
|
|
|
2012-10-17 02:06:38 +04:00
|
|
|
Components.utils.import("resource://gre/modules/Services.jsm");
|
|
|
|
|
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.
|
|
|
|
let gTemporaryAutoStartMode = false;
|
2012-10-17 02:06:38 +04:00
|
|
|
|
2012-10-10 04:34:59 +04:00
|
|
|
const Cc = Components.classes;
|
2012-07-03 18:35:03 +04:00
|
|
|
const Ci = Components.interfaces;
|
|
|
|
|
2012-10-31 20:13:28 +04:00
|
|
|
this.PrivateBrowsingUtils = {
|
2012-07-03 18:35:03 +04:00
|
|
|
isWindowPrivate: function pbu_isWindowPrivate(aWindow) {
|
2012-10-25 22:17:35 +04:00
|
|
|
return this.privacyContextFromWindow(aWindow).usePrivateBrowsing;
|
|
|
|
},
|
|
|
|
|
|
|
|
privacyContextFromWindow: function pbu_privacyContextFromWindow(aWindow) {
|
2012-07-03 18:35:03 +04:00
|
|
|
return aWindow.QueryInterface(Ci.nsIInterfaceRequestor)
|
|
|
|
.getInterface(Ci.nsIWebNavigation)
|
2012-10-25 22:17:35 +04:00
|
|
|
.QueryInterface(Ci.nsILoadContext);
|
2012-10-10 04:34:59 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
get permanentPrivateBrowsing() {
|
|
|
|
#ifdef MOZ_PER_WINDOW_PRIVATE_BROWSING
|
2012-11-07 23:07:35 +04:00
|
|
|
return gTemporaryAutoStartMode ||
|
|
|
|
Services.prefs.getBoolPref(kAutoStartPref, false);
|
2012-10-10 04:34:59 +04:00
|
|
|
#else
|
|
|
|
try {
|
|
|
|
return Cc["@mozilla.org/privatebrowsing;1"].
|
|
|
|
getService(Ci.nsIPrivateBrowsingService).
|
|
|
|
autoStarted;
|
|
|
|
} catch (e) {
|
|
|
|
return false; // PB not supported
|
|
|
|
}
|
|
|
|
#endif
|
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;
|
2012-07-03 18:35:03 +04:00
|
|
|
}
|
|
|
|
};
|
2012-10-17 02:06:38 +04:00
|
|
|
|