Bug 802274 - Part 1: Add support for temporary autostart private browsing mode to PrivateBrowsingUtils; r=jdm
authorEhsan Akhgari <ehsan@mozilla.com>
Wed, 07 Nov 2012 14:07:35 -0500
changeset 112578 76f6e27d3a71b33005d3ebb186500568a782da5a
parent 112577 d105eace108bca6866572ca5c368766423a2851f
child 112579 7990748672869d0899fbbb2eec80e927d98fdf4a
push id23830
push userryanvm@gmail.com
push dateThu, 08 Nov 2012 01:08:07 +0000
treeherdermozilla-central@c652c39732f8 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjdm
bugs802274
milestone19.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 802274 - Part 1: Add support for temporary autostart private browsing mode to PrivateBrowsingUtils; r=jdm
toolkit/content/PrivateBrowsingUtils.jsm
--- a/toolkit/content/PrivateBrowsingUtils.jsm
+++ b/toolkit/content/PrivateBrowsingUtils.jsm
@@ -1,17 +1,21 @@
 /* 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/. */
 
 this.EXPORTED_SYMBOLS = ["PrivateBrowsingUtils"];
 
 Components.utils.import("resource://gre/modules/Services.jsm");
 
-const kAutoStartPref = "browser.components.autostart";
+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;
 
 const Cc = Components.classes;
 const Ci = Components.interfaces;
 
 this.PrivateBrowsingUtils = {
   isWindowPrivate: function pbu_isWindowPrivate(aWindow) {
     return this.privacyContextFromWindow(aWindow).usePrivateBrowsing;
   },
@@ -19,32 +23,41 @@ this.PrivateBrowsingUtils = {
   privacyContextFromWindow: function pbu_privacyContextFromWindow(aWindow) {
     return aWindow.QueryInterface(Ci.nsIInterfaceRequestor)
                   .getInterface(Ci.nsIWebNavigation)
                   .QueryInterface(Ci.nsILoadContext);
   },
 
   get permanentPrivateBrowsing() {
 #ifdef MOZ_PER_WINDOW_PRIVATE_BROWSING
-    return Services.prefs.getBoolPref(kAutoStart, false);
+    return gTemporaryAutoStartMode ||
+           Services.prefs.getBoolPref(kAutoStartPref, false);
 #else
     try {
       return Cc["@mozilla.org/privatebrowsing;1"].
              getService(Ci.nsIPrivateBrowsingService).
              autoStarted;
     } catch (e) {
       return false; // PB not supported
     }
 #endif
+  },
+
+  // These should only be used from internal code
+  enterTemporaryAutoStartMode: function pbu_enterTemporaryAutoStartMode() {
+    gTemporaryAutoStartMode = true;
+  },
+  get isInTemporaryAutoStartMode() {
+    return gTemporaryAutoStartMode;
   }
 };
 
 #ifdef MOZ_PER_WINDOW_PRIVATE_BROWSING
 function autoStartObserver(aSubject, aTopic, aData) {
-  var newValue = Services.prefs.getBoolPref(kAutoStart);
+  var newValue = Services.prefs.getBoolPref(kAutoStartPref);
   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;
   }