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");
|
|
|
|
|
|
|
|
const kAutoStartPref = "browser.components.autostart";
|
|
|
|
|
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 = {
|
2012-07-03 07:35:03 -07:00
|
|
|
isWindowPrivate: function pbu_isWindowPrivate(aWindow) {
|
2012-10-25 11:17:35 -07:00
|
|
|
return this.privacyContextFromWindow(aWindow).usePrivateBrowsing;
|
|
|
|
},
|
|
|
|
|
|
|
|
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
|
|
|
},
|
|
|
|
|
|
|
|
get permanentPrivateBrowsing() {
|
|
|
|
#ifdef MOZ_PER_WINDOW_PRIVATE_BROWSING
|
2012-10-16 15:06:38 -07:00
|
|
|
return Services.prefs.getBoolPref(kAutoStart, false);
|
2012-10-09 17:34:59 -07:00
|
|
|
#else
|
|
|
|
try {
|
|
|
|
return Cc["@mozilla.org/privatebrowsing;1"].
|
|
|
|
getService(Ci.nsIPrivateBrowsingService).
|
|
|
|
autoStarted;
|
|
|
|
} catch (e) {
|
|
|
|
return false; // PB not supported
|
|
|
|
}
|
|
|
|
#endif
|
2012-07-03 07:35:03 -07:00
|
|
|
}
|
|
|
|
};
|
2012-10-16 15:06:38 -07:00
|
|
|
|
|
|
|
#ifdef MOZ_PER_WINDOW_PRIVATE_BROWSING
|
|
|
|
function autoStartObserver(aSubject, aTopic, aData) {
|
|
|
|
var newValue = Services.prefs.getBoolPref(kAutoStart);
|
|
|
|
var windowsEnum = Services.wm.getEnumerator(null);
|
|
|
|
while (windowsEnum.hasMoreElements()) {
|
|
|
|
var window = windowsEnum.getNext();
|
|
|
|
window.QueryInterface(Ci.nsIInterfaceRequestor)
|
|
|
|
.getInterface(Ci.nsIWebNavigation)
|
|
|
|
.QueryInterface(Ci.nsILoadContext)
|
|
|
|
.usePrivateBrowsing = newValue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Services.prefs.addObserver(kAutoStartPref, autoStartObserver, false);
|
|
|
|
#endif
|
|
|
|
|