Bug 799780 - Remove gPrivateBrowsingUI.autoStarted and move that API to PrivateBrowsingUtils; r=jdm
authorEhsan Akhgari <ehsan@mozilla.com>
Tue, 09 Oct 2012 20:34:59 -0400
changeset 110102 129f5457378ebb43c601bedb2db495704dbf2d11
parent 110101 bc8cbe29588d2194b668725d70694e4bd4fb5c2b
child 110103 f6d177ffd4baf0d89bec3e417ba374adf7843a76
push id93
push usernmatsakis@mozilla.com
push dateWed, 31 Oct 2012 21:26:57 +0000
reviewersjdm
bugs799780
milestone19.0a1
Bug 799780 - Remove gPrivateBrowsingUI.autoStarted and move that API to PrivateBrowsingUtils; r=jdm
browser/base/content/browser.js
browser/base/content/utilityOverlay.js
toolkit/content/Makefile.in
toolkit/content/PrivateBrowsingUtils.jsm
--- a/browser/base/content/browser.js
+++ b/browser/base/content/browser.js
@@ -7063,19 +7063,16 @@ function getNavToolbox() gNavToolbox;
 # We define a new gPrivateBrowsingUI object, as the per-window PB implementation
 # is completely different to the global PB one.  Specifically, the per-window
 # PB implementation does not expose many APIs on the gPrivateBrowsingUI object,
 # and only uses it as a way to initialize and uninitialize private browsing
 # windows.  While we could use #ifdefs all around the global PB mode code to
 # make it work in both modes, the amount of duplicated code is small and the
 # code is much more readable this way.
 let gPrivateBrowsingUI = {
-  _inited: false,
-  _initCallbacks: [],
-
   init: function PBUI_init() {
     // Do nothing for normal windows
     if (!PrivateBrowsingUtils.isWindowPrivate(window)) {
       return;
     }
 
     // Disable the Clear Recent History... menu item when in PB mode
     // temporary fix until bug 463607 is fixed
@@ -7086,83 +7083,48 @@ let gPrivateBrowsingUI = {
       let docElement = document.documentElement;
       docElement.setAttribute("title",
         docElement.getAttribute("title_privatebrowsing"));
       docElement.setAttribute("titlemodifier",
         docElement.getAttribute("titlemodifier_privatebrowsing"));
       docElement.setAttribute("privatebrowsingmode", "temporary");
       gBrowser.updateTitlebar();
     }
-
-    this._inited = true;
-
-    this._initCallbacks.forEach(function (callback) callback.apply());
-    this._initCallbacks = [];
-  },
-
-  get autoStarted() {
-    return false; // auto-started PB not supported for now
-  },
-
-  get initialized() {
-    return this._inited;
-  },
-
-  addInitializationCallback: function PBUI_addInitializationCallback(aCallback) {
-    if (this._inited)
-      return;
-
-    this._initCallbacks.push(aCallback);
   }
 };
 
 #else
 
 let gPrivateBrowsingUI = {
   _privateBrowsingService: null,
   _searchBarValue: null,
   _findBarValue: null,
   _inited: false,
-  _initCallbacks: [],
 
   init: function PBUI_init() {
     Services.obs.addObserver(this, "private-browsing", false);
     Services.obs.addObserver(this, "private-browsing-transition-complete", false);
 
     this._privateBrowsingService = Cc["@mozilla.org/privatebrowsing;1"].
                                    getService(Ci.nsIPrivateBrowsingService);
 
     if (this.privateBrowsingEnabled)
       this.onEnterPrivateBrowsing(true);
 
     this._inited = true;
-
-    this._initCallbacks.forEach(function (callback) callback.apply());
-    this._initCallbacks = [];
   },
 
   uninit: function PBUI_unint() {
     if (!this._inited)
       return;
 
     Services.obs.removeObserver(this, "private-browsing");
     Services.obs.removeObserver(this, "private-browsing-transition-complete");
   },
 
-  get initialized() {
-    return this._inited;
-  },
-
-  addInitializationCallback: function PBUI_addInitializationCallback(aCallback) {
-    if (this._inited)
-      return;
-
-    this._initCallbacks.push(aCallback);
-  },
-
   get _disableUIOnToggle() {
     if (this._privateBrowsingService.autoStarted)
       return false;
 
     try {
       return !gPrefService.getBoolPref("browser.privatebrowsing.keep_current_session");
     }
     catch (e) {
@@ -7355,20 +7317,16 @@ let gPrivateBrowsingUI = {
     if (!this.privateBrowsingEnabled)
       if (!this._shouldEnter())
         return;
 
     this._privateBrowsingService.privateBrowsingEnabled =
       !this.privateBrowsingEnabled;
   },
 
-  get autoStarted() {
-    return this._privateBrowsingService.autoStarted;
-  },
-
   get privateBrowsingEnabled() {
     return this._privateBrowsingService.privateBrowsingEnabled;
   }
 };
 
 #endif
 
 
--- a/browser/base/content/utilityOverlay.js
+++ b/browser/base/content/utilityOverlay.js
@@ -8,24 +8,19 @@ Components.utils.import("resource://gre/
 Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
 Components.utils.import("resource://gre/modules/PrivateBrowsingUtils.jsm");
 
 XPCOMUtils.defineLazyGetter(this, "BROWSER_NEW_TAB_URL", function () {
   const PREF = "browser.newtab.url";
   const TOPIC = "private-browsing-transition-complete";
 
   function getNewTabPageURL() {
-    if (("gPrivateBrowsingUI" in window) &&
-        !Services.prefs.prefHasUserValue(PREF)) {
-      // gPrivateBrowsingUI may not be initialized yet, in that case we'll
-      // update BROWSER_NEW_TAB_URL when it gets initialized.
-      if (!gPrivateBrowsingUI.initialized)
-        gPrivateBrowsingUI.addInitializationCallback(update);
-      else if (PrivateBrowsingUtils.isWindowPrivate(window) &&
-               !gPrivateBrowsingUI.autoStarted)
+    if (!Services.prefs.prefHasUserValue(PREF)) {
+      if (PrivateBrowsingUtils.isWindowPrivate(window) &&
+          !PrivateBrowsingUtils.permanentPrivateBrowsing)
         return "about:privatebrowsing";
     }
     return Services.prefs.getCharPref(PREF) || "about:blank";
   }
 
   function update() {
     BROWSER_NEW_TAB_URL = getNewTabPageURL();
   }
--- a/toolkit/content/Makefile.in
+++ b/toolkit/content/Makefile.in
@@ -59,22 +59,22 @@ TEST_DIRS += tests
 EXTRA_JS_MODULES = \
   debug.js \
   DeferredTask.jsm \
   Dict.jsm \
   Geometry.jsm \
   InlineSpellChecker.jsm \
   PageMenu.jsm \
   PopupNotifications.jsm \
-  PrivateBrowsingUtils.jsm \
   PropertyListUtils.jsm \
   Task.jsm \
   UpdateChannel.jsm \
   $(NULL)
 
 EXTRA_PP_JS_MODULES = \
   LightweightThemeConsumer.jsm \
+  PrivateBrowsingUtils.jsm \
   Services.jsm \
   WindowDraggingUtils.jsm \
   Troubleshoot.jsm \
   $(NULL)
 
 include $(topsrcdir)/config/rules.mk
--- a/toolkit/content/PrivateBrowsingUtils.jsm
+++ b/toolkit/content/PrivateBrowsingUtils.jsm
@@ -1,16 +1,31 @@
 /* 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/. */
 
 var EXPORTED_SYMBOLS = ["PrivateBrowsingUtils"];
 
+const Cc = Components.classes;
 const Ci = Components.interfaces;
 
 var PrivateBrowsingUtils = {
   isWindowPrivate: function pbu_isWindowPrivate(aWindow) {
     return aWindow.QueryInterface(Ci.nsIInterfaceRequestor)
                   .getInterface(Ci.nsIWebNavigation)
                   .QueryInterface(Ci.nsILoadContext)
                   .usePrivateBrowsing;
+  },
+
+  get permanentPrivateBrowsing() {
+#ifdef MOZ_PER_WINDOW_PRIVATE_BROWSING
+    return false; // permanent PB is not supported for now
+#else
+    try {
+      return Cc["@mozilla.org/privatebrowsing;1"].
+             getService(Ci.nsIPrivateBrowsingService).
+             autoStarted;
+    } catch (e) {
+      return false; // PB not supported
+    }
+#endif
   }
 };