Bug 510881 - Entering Private Browsing via command line shows tabs from previous session; r=mconnor,bsmedberg
authorEhsan Akhgari <ehsan.akhgari@gmail.com>
Tue, 15 Sep 2009 14:42:01 +0430
changeset 32490 cdcf1519121ffba0d8b376668390647d44980e0d
parent 32489 376f6bf359c871191faff7d4a5007dada1aa7230
child 32491 b23223d8222baaf56fd5896d75d5df1da824109f
push idunknown
push userunknown
push dateunknown
reviewersmconnor, bsmedberg
bugs510881
milestone1.9.3a1pre
Bug 510881 - Entering Private Browsing via command line shows tabs from previous session; r=mconnor,bsmedberg
browser/components/privatebrowsing/src/nsPrivateBrowsingService.js
chrome/src/nsChromeRegistry.cpp
toolkit/xre/nsAppRunner.cpp
--- a/browser/components/privatebrowsing/src/nsPrivateBrowsingService.js
+++ b/browser/components/privatebrowsing/src/nsPrivateBrowsingService.js
@@ -76,16 +76,17 @@ const Cr = Components.results;
 
 ////////////////////////////////////////////////////////////////////////////////
 //// PrivateBrowsingService
 
 function PrivateBrowsingService() {
   this._obs.addObserver(this, "profile-after-change", true);
   this._obs.addObserver(this, "quit-application-granted", true);
   this._obs.addObserver(this, "private-browsing", true);
+  this._obs.addObserver(this, "command-line-startup", true);
 }
 
 PrivateBrowsingService.prototype = {
   // Observer Service
   __obs: null,
   get _obs() {
     if (!this.__obs)
       this.__obs = Cc["@mozilla.org/observer-service;1"].
@@ -340,16 +341,21 @@ PrivateBrowsingService.prototype = {
         if (!this._inPrivateBrowsing) {
           // Clear the error console
           let consoleService = Cc["@mozilla.org/consoleservice;1"].
                                getService(Ci.nsIConsoleService);
           consoleService.logStringMessage(null); // trigger the listeners
           consoleService.reset();
         }
         break;
+      case "command-line-startup":
+        this._obs.removeObserver(this, "command-line-startup");
+        aSubject.QueryInterface(Ci.nsICommandLine);
+        this.handle(aSubject);
+        break;
     }
   },
 
   // nsICommandLineHandler
 
   handle: function PBS_handle(aCmdLine) {
     if (aCmdLine.handleFlag("private", false)) {
       this.privateBrowsingEnabled = true;
--- a/chrome/src/nsChromeRegistry.cpp
+++ b/chrome/src/nsChromeRegistry.cpp
@@ -549,16 +549,20 @@ nsChromeRegistry::Init()
       if (NS_SUCCEEDED(rv))
         mSelectedLocale = provider;
       
       if (prefs2)
         prefs2->AddObserver(SELECTED_LOCALE_PREF, this, PR_TRUE);
     }
   }
 
+  nsCOMPtr<nsIObserverService> obsService (do_GetService("@mozilla.org/observer-service;1"));
+  if (obsService)
+    obsService->AddObserver(this, "command-line-startup", PR_TRUE);
+
   CheckForNewChrome();
 
   mInitialized = PR_TRUE;
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
--- a/toolkit/xre/nsAppRunner.cpp
+++ b/toolkit/xre/nsAppRunner.cpp
@@ -3361,20 +3361,20 @@ XRE_main(int argc, char* argv[], const n
           NS_ENSURE_TRUE(cmdLine, 1);
 
           rv = cmdLine->Init(gArgc, gArgv,
                              workingDir, nsICommandLine::STATE_INITIAL_LAUNCH);
           NS_ENSURE_SUCCESS(rv, 1);
 
           /* Special-case services that need early access to the command
              line. */
-          nsCOMPtr<nsIObserver> chromeObserver
-            (do_GetService("@mozilla.org/chrome/chrome-registry;1"));
-          if (chromeObserver) {
-            chromeObserver->Observe(cmdLine, "command-line-startup", nsnull);
+          nsCOMPtr<nsIObserverService> obsService
+            (do_GetService("@mozilla.org/observer-service;1"));
+          if (obsService) {
+            obsService->NotifyObservers(cmdLine, "command-line-startup", nsnull);
           }
 
           NS_TIMELINE_ENTER("appStartup->CreateHiddenWindow");
           rv = appStartup->CreateHiddenWindow();
           NS_TIMELINE_LEAVE("appStartup->CreateHiddenWindow");
           NS_ENSURE_SUCCESS(rv, 1);
 
           MOZ_SPLASHSCREEN_UPDATE(50);