michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this file, michael@0: * You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: this.EXPORTED_SYMBOLS = ["PrivateBrowsingUtils"]; michael@0: michael@0: Components.utils.import("resource://gre/modules/Services.jsm"); michael@0: michael@0: const kAutoStartPref = "browser.privatebrowsing.autostart"; michael@0: michael@0: // This will be set to true when the PB mode is autostarted from the command michael@0: // line for the current session. michael@0: let gTemporaryAutoStartMode = false; michael@0: michael@0: const Cc = Components.classes; michael@0: const Ci = Components.interfaces; michael@0: michael@0: this.PrivateBrowsingUtils = { michael@0: isWindowPrivate: function pbu_isWindowPrivate(aWindow) { michael@0: return this.privacyContextFromWindow(aWindow).usePrivateBrowsing; michael@0: }, michael@0: michael@0: privacyContextFromWindow: function pbu_privacyContextFromWindow(aWindow) { michael@0: return aWindow.QueryInterface(Ci.nsIInterfaceRequestor) michael@0: .getInterface(Ci.nsIWebNavigation) michael@0: .QueryInterface(Ci.nsILoadContext); michael@0: }, michael@0: michael@0: get permanentPrivateBrowsing() { michael@0: try { michael@0: return gTemporaryAutoStartMode || michael@0: Services.prefs.getBoolPref(kAutoStartPref); michael@0: } catch (e) { michael@0: // The pref does not exist michael@0: return false; michael@0: } michael@0: }, michael@0: michael@0: // These should only be used from internal code michael@0: enterTemporaryAutoStartMode: function pbu_enterTemporaryAutoStartMode() { michael@0: gTemporaryAutoStartMode = true; michael@0: }, michael@0: get isInTemporaryAutoStartMode() { michael@0: return gTemporaryAutoStartMode; michael@0: }, michael@0: michael@0: whenHiddenPrivateWindowReady: function pbu_whenHiddenPrivateWindowReady(cb) { michael@0: Components.utils.import("resource://gre/modules/Timer.jsm"); michael@0: michael@0: let win = Services.appShell.hiddenPrivateDOMWindow; michael@0: function isNotLoaded() { michael@0: return ["complete", "interactive"].indexOf(win.document.readyState) == -1; michael@0: } michael@0: if (isNotLoaded()) { michael@0: setTimeout(function poll() { michael@0: if (isNotLoaded()) { michael@0: setTimeout(poll, 100); michael@0: return; michael@0: } michael@0: cb(Services.appShell.hiddenPrivateDOMWindow); michael@0: }, 4); michael@0: } else { michael@0: cb(Services.appShell.hiddenPrivateDOMWindow); michael@0: } michael@0: } michael@0: }; michael@0: