Bug 799784 - Replace usages of nsIPrivateBrowsingService.autoStarted with PrivateBrowsingUtils.permanentPrivateBrowsing; r=ehsan
authorAndres Hernandez <andres@appcoast.com>
Wed, 24 Oct 2012 14:21:33 -0600
changeset 111441 c90c5809e56ea77a060daee2ed9f665d482f3766
parent 111440 d408a2592685803980fd331ee6a0690fcf7ab951
child 111442 0f22d98c98b0646ee9bf2fbbedb0f5ae2a4b3868
push id93
push usernmatsakis@mozilla.com
push dateWed, 31 Oct 2012 21:26:57 +0000
reviewersehsan
bugs799784
milestone19.0a1
Bug 799784 - Replace usages of nsIPrivateBrowsingService.autoStarted with PrivateBrowsingUtils.permanentPrivateBrowsing; r=ehsan
browser/base/content/browser.js
browser/components/preferences/in-content/security.js
browser/components/preferences/security.js
browser/components/sessionstore/src/nsSessionStartup.js
browser/modules/WindowsJumpLists.jsm
toolkit/mozapps/update/test/unit/test_bug497578.js
--- a/browser/base/content/browser.js
+++ b/browser/base/content/browser.js
@@ -7134,17 +7134,17 @@ let gPrivateBrowsingUI = {
     if (!this._inited)
       return;
 
     Services.obs.removeObserver(this, "private-browsing");
     Services.obs.removeObserver(this, "private-browsing-transition-complete");
   },
 
   get _disableUIOnToggle() {
-    if (this._privateBrowsingService.autoStarted)
+    if (PrivateBrowsingUtils.permanentPrivateBrowsing)
       return false;
 
     try {
       return !gPrefService.getBoolPref("browser.privatebrowsing.keep_current_session");
     }
     catch (e) {
       return true;
     }
@@ -7230,17 +7230,17 @@ let gPrivateBrowsingUI = {
 
     this._setPBMenuTitle("stop");
 
     // Disable the Clear Recent History... menu item when in PB mode
     // temporary fix until bug 463607 is fixed
     document.getElementById("Tools:Sanitize").setAttribute("disabled", "true");
 
     let docElement = document.documentElement;
-    if (this._privateBrowsingService.autoStarted) {
+    if (PrivateBrowsingUtils.permanentPrivateBrowsing) {
       // Disable the menu item in auto-start mode
       document.getElementById("privateBrowsingItem")
               .setAttribute("disabled", "true");
 #ifdef MENUBAR_CAN_AUTOHIDE
       document.getElementById("appmenu_privateBrowsing")
               .setAttribute("disabled", "true");
 #endif
       document.getElementById("Tools:PrivateBrowsing")
--- a/browser/components/preferences/in-content/security.js
+++ b/browser/components/preferences/in-content/security.js
@@ -1,12 +1,14 @@
 /* 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/. */
 
+Components.utils.import("resource://gre/modules/PrivateBrowsingUtils.jsm");
+
 var gSecurityPane = {
   _pane: null,
 
   /**
    * Initializes master password UI.
    */
   init: function ()
   {
@@ -85,21 +87,17 @@ var gSecurityPane = {
    * passwords are never saved. When browser is set to start in Private
    * Browsing mode, the "Remember passwords" UI is useless, so we disable it.
    */
   readSavePasswords: function ()
   {
     var pref = document.getElementById("signon.rememberSignons");
     var excepts = document.getElementById("passwordExceptions");
 
-    const Cc = Components.classes, Ci = Components.interfaces;
-    var pbs = Cc["@mozilla.org/privatebrowsing;1"].
-              getService(Ci.nsIPrivateBrowsingService);
-
-    if (pbs.autoStarted) {
+    if (PrivateBrowsingUtils.permanentPrivateBrowsing) {
       document.getElementById("savePasswords").disabled = true;
       excepts.disabled = true;
       return false;
     } else {
       excepts.disabled = !pref.value;
       // don't override pref value in UI
       return undefined;
     }
--- a/browser/components/preferences/security.js
+++ b/browser/components/preferences/security.js
@@ -1,13 +1,15 @@
 /* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
 /* 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/. */
 
+Components.utils.import("resource://gre/modules/PrivateBrowsingUtils.jsm");
+
 var gSecurityPane = {
   _pane: null,
 
   /**
    * Initializes master password UI.
    */
   init: function ()
   {
@@ -85,21 +87,17 @@ var gSecurityPane = {
    * passwords are never saved. When browser is set to start in Private
    * Browsing mode, the "Remember passwords" UI is useless, so we disable it.
    */
   readSavePasswords: function ()
   {
     var pref = document.getElementById("signon.rememberSignons");
     var excepts = document.getElementById("passwordExceptions");
 
-    const Cc = Components.classes, Ci = Components.interfaces;
-    var pbs = Cc["@mozilla.org/privatebrowsing;1"].
-              getService(Ci.nsIPrivateBrowsingService);
-
-    if (pbs.autoStarted) {
+    if (PrivateBrowsingUtils.permanentPrivateBrowsing) {
       document.getElementById("savePasswords").disabled = true;
       excepts.disabled = true;
       return false;
     } else {
       excepts.disabled = !pref.value;
       // don't override pref value in UI
       return undefined;
     }
--- a/browser/components/sessionstore/src/nsSessionStartup.js
+++ b/browser/components/sessionstore/src/nsSessionStartup.js
@@ -33,16 +33,17 @@
 
 const Cc = Components.classes;
 const Ci = Components.interfaces;
 const Cr = Components.results;
 const Cu = Components.utils;
 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
 Cu.import("resource://gre/modules/Services.jsm");
 Cu.import("resource://gre/modules/TelemetryStopwatch.jsm");
+Cu.import("resource://gre/modules/PrivateBrowsingUtils.jsm");
 
 const STATE_RUNNING_STR = "running";
 const MAX_FILE_SIZE = 100 * 1024 * 1024; // 100 megabytes
 
 function debug(aMsg) {
   aMsg = ("SessionStartup: " + aMsg).replace(/\S{80}/g, "$&\n");
   Services.console.logStringMessage(aMsg);
 }
@@ -62,17 +63,18 @@ SessionStartup.prototype = {
 
   /**
    * Initialize the component
    */
   init: function sss_init() {
     // do not need to initialize anything in auto-started private browsing sessions
     let pbs = Cc["@mozilla.org/privatebrowsing;1"].
               getService(Ci.nsIPrivateBrowsingService);
-    if (pbs.autoStarted || pbs.lastChangedByCommandLine)
+    if (PrivateBrowsingUtils.permanentPrivateBrowsing ||
+        pbs.lastChangedByCommandLine)
       return;
 
     let prefBranch = Cc["@mozilla.org/preferences-service;1"].
                      getService(Ci.nsIPrefService).getBranch("browser.");
 
     // get file references
     var dirService = Cc["@mozilla.org/file/directory_service;1"].
                      getService(Ci.nsIProperties);
--- a/browser/modules/WindowsJumpLists.jsm
+++ b/browser/modules/WindowsJumpLists.jsm
@@ -73,16 +73,19 @@ XPCOMUtils.defineLazyServiceGetter(this,
 XPCOMUtils.defineLazyServiceGetter(this, "_winShellService",
                                    "@mozilla.org/browser/shell-service;1",
                                    "nsIWindowsShellService");
 
 XPCOMUtils.defineLazyServiceGetter(this, "_privateBrowsingSvc",
                                    "@mozilla.org/privatebrowsing;1",
                                    "nsIPrivateBrowsingService");
 
+XPCOMUtils.defineLazyModuleGetter(this, "PrivateBrowsingUtils",
+  "resource://gre/modules/PrivateBrowsingUtils.jsm");
+
 /**
  * Global functions
  */
 
 function _getString(name) {
   return _stringBundle.GetStringFromName(name);
 }
 
@@ -137,21 +140,21 @@ var tasksCfg = [
         return _getString("taskbar.tasks.exitPrivacyMode.description");
       else
         return _getString("taskbar.tasks.enterPrivacyMode.description");
     },
     args:             "-private-toggle",
     iconIndex:        4, // Private browsing mode icon
     get open() {
       // Don't show when inside permanent private browsing mode
-      return !_privateBrowsingSvc.autoStarted;
+      return !PrivateBrowsingUtils.permanentPrivateBrowsing;
     },
     get close() {
       // Don't show when inside permanent private browsing mode
-      return !_privateBrowsingSvc.autoStarted;
+      return !PrivateBrowsingUtils.permanentPrivateBrowsing;
     },
   },
 ];
 
 /////////////////////////////////////////////////////////////////////////////
 // Implementation
 
 var WinTaskbarJumpList =
--- a/toolkit/mozapps/update/test/unit/test_bug497578.js
+++ b/toolkit/mozapps/update/test/unit/test_bug497578.js
@@ -67,17 +67,18 @@ function run_test_pt1() {
                      getService(AUS_Ci.nsIPrivateBrowsingService).
                      QueryInterface(AUS_Ci.nsIObserver);
 
   privBrowsing.observe(null, "profile-after-change", "");
   logTestInfo("Testing: private mode should be entered automatically");
   do_check_true(privBrowsing.privateBrowsingEnabled);
 
   logTestInfo("Testing: private browsing is auto-started");
-  do_check_true(privBrowsing.autoStarted);
+  Components.utils.import("resource://gre/modules/PrivateBrowsingUtils.jsm");
+  do_check_true(PrivateBrowsingUtils.permanentPrivateBrowsing);
 
   // Give private browsing time to reset necko.
   do_execute_soon(run_test_pt2);
 }
 function run_test_pt2() {
   logTestInfo("Testing: update count should equal 1");
   do_check_eq(gUpdateManager.updateCount, 1);
   logTestInfo("Testing: activeUpdate should not equal null");