1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
3 * You can obtain one at http://mozilla.org/MPL/2.0/. */
5 const kAutoStartPref = "browser.privatebrowsing.autostart";
7 // This will be set to true when the PB mode is autostarted from the command
8 // line for the current session.
9 var gTemporaryAutoStartMode = false;
11 export var PrivateBrowsingUtils = {
13 return Services.policies.isAllowed("privatebrowsing");
16 // Rather than passing content windows to this function, please use
17 // isBrowserPrivate since it works with e10s.
18 isWindowPrivate: function pbu_isWindowPrivate(aWindow) {
19 if (!aWindow.isChromeWindow) {
21 "WARNING: content window passed to PrivateBrowsingUtils.isWindowPrivate. " +
22 "Use isContentWindowPrivate instead (but only for frame scripts).\n" +
27 return this.privacyContextFromWindow(aWindow).usePrivateBrowsing;
30 // This should be used only in frame scripts.
31 isContentWindowPrivate: function pbu_isWindowPrivate(aWindow) {
32 return this.privacyContextFromWindow(aWindow).usePrivateBrowsing;
35 isBrowserPrivate(aBrowser) {
36 let chromeWin = aBrowser.ownerGlobal;
37 if (chromeWin.gMultiProcessBrowser || !aBrowser.contentWindow) {
38 // In e10s we have to look at the chrome window's private
39 // browsing status since the only alternative is to check the
40 // content window, which is in another process. If the browser
41 // is lazy or is running in windowless configuration then the
42 // content window doesn't exist.
43 return this.isWindowPrivate(chromeWin);
45 return this.privacyContextFromWindow(aBrowser.contentWindow)
49 privacyContextFromWindow: function pbu_privacyContextFromWindow(aWindow) {
50 return aWindow.docShell.QueryInterface(Ci.nsILoadContext);
53 get permanentPrivateBrowsing() {
56 gTemporaryAutoStartMode || Services.prefs.getBoolPref(kAutoStartPref)
59 // The pref does not exist
64 // These should only be used from internal code
65 enterTemporaryAutoStartMode: function pbu_enterTemporaryAutoStartMode() {
66 gTemporaryAutoStartMode = true;
68 get isInTemporaryAutoStartMode() {
69 return gTemporaryAutoStartMode;