1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/modules/PrivateBrowsingUtils.jsm Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,67 @@ 1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this file, 1.6 + * You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.7 + 1.8 +this.EXPORTED_SYMBOLS = ["PrivateBrowsingUtils"]; 1.9 + 1.10 +Components.utils.import("resource://gre/modules/Services.jsm"); 1.11 + 1.12 +const kAutoStartPref = "browser.privatebrowsing.autostart"; 1.13 + 1.14 +// This will be set to true when the PB mode is autostarted from the command 1.15 +// line for the current session. 1.16 +let gTemporaryAutoStartMode = false; 1.17 + 1.18 +const Cc = Components.classes; 1.19 +const Ci = Components.interfaces; 1.20 + 1.21 +this.PrivateBrowsingUtils = { 1.22 + isWindowPrivate: function pbu_isWindowPrivate(aWindow) { 1.23 + return this.privacyContextFromWindow(aWindow).usePrivateBrowsing; 1.24 + }, 1.25 + 1.26 + privacyContextFromWindow: function pbu_privacyContextFromWindow(aWindow) { 1.27 + return aWindow.QueryInterface(Ci.nsIInterfaceRequestor) 1.28 + .getInterface(Ci.nsIWebNavigation) 1.29 + .QueryInterface(Ci.nsILoadContext); 1.30 + }, 1.31 + 1.32 + get permanentPrivateBrowsing() { 1.33 + try { 1.34 + return gTemporaryAutoStartMode || 1.35 + Services.prefs.getBoolPref(kAutoStartPref); 1.36 + } catch (e) { 1.37 + // The pref does not exist 1.38 + return false; 1.39 + } 1.40 + }, 1.41 + 1.42 + // These should only be used from internal code 1.43 + enterTemporaryAutoStartMode: function pbu_enterTemporaryAutoStartMode() { 1.44 + gTemporaryAutoStartMode = true; 1.45 + }, 1.46 + get isInTemporaryAutoStartMode() { 1.47 + return gTemporaryAutoStartMode; 1.48 + }, 1.49 + 1.50 + whenHiddenPrivateWindowReady: function pbu_whenHiddenPrivateWindowReady(cb) { 1.51 + Components.utils.import("resource://gre/modules/Timer.jsm"); 1.52 + 1.53 + let win = Services.appShell.hiddenPrivateDOMWindow; 1.54 + function isNotLoaded() { 1.55 + return ["complete", "interactive"].indexOf(win.document.readyState) == -1; 1.56 + } 1.57 + if (isNotLoaded()) { 1.58 + setTimeout(function poll() { 1.59 + if (isNotLoaded()) { 1.60 + setTimeout(poll, 100); 1.61 + return; 1.62 + } 1.63 + cb(Services.appShell.hiddenPrivateDOMWindow); 1.64 + }, 4); 1.65 + } else { 1.66 + cb(Services.appShell.hiddenPrivateDOMWindow); 1.67 + } 1.68 + } 1.69 +}; 1.70 +