Bug 723004 - Port nsLoginManagerPrompter to the per-window private browsing API; r=dolske
authorEhsan Akhgari <ehsan@mozilla.com>
Fri, 12 Oct 2012 21:49:26 -0400
changeset 114779 5091701dcc4582baf6914b5b587589942d1ec976
parent 114778 b680d000682fb74d26dfdcd9bd3f2a0028b9abfe
child 114780 7f47eacb16e385d1516171b55c67bd5a8b150a21
push idunknown
push userunknown
push dateunknown
reviewersdolske
bugs723004
milestone19.0a1
Bug 723004 - Port nsLoginManagerPrompter to the per-window private browsing API; r=dolske
toolkit/components/passwordmgr/nsLoginManagerPrompter.js
--- a/toolkit/components/passwordmgr/nsLoginManagerPrompter.js
+++ b/toolkit/components/passwordmgr/nsLoginManagerPrompter.js
@@ -4,16 +4,17 @@
 
 
 const Cc = Components.classes;
 const Ci = Components.interfaces;
 const Cr = Components.results;
 
 Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
 Components.utils.import("resource://gre/modules/Services.jsm");
+Components.utils.import("resource://gre/modules/PrivateBrowsingUtils.jsm");
 
 /*
  * LoginManagerPromptFactory
  *
  * Implements nsIPromptFactory
  *
  * Invoked by [toolkit/components/prompts/src/nsPrompter.js]
  */
@@ -240,23 +241,25 @@ LoginManagerPrompter.prototype = {
             } catch (e) { }
         }
         return this.__ellipsis;
     },
 
 
     // Whether we are in private browsing mode
     get _inPrivateBrowsing() {
-      // The Private Browsing service might not be available.
-      try {
-        var pbs = Cc["@mozilla.org/privatebrowsing;1"].
-                  getService(Ci.nsIPrivateBrowsingService);
-        return pbs.privateBrowsingEnabled;
-      } catch (e) {
-        return false;
+      if (this._window) {
+        return PrivateBrowsingUtils.isWindowPrivate(this._window);
+      } else {
+        // If we don't that we're in private browsing mode if the caller did
+        // not provide a window.  The callers which really care about this
+        // will indeed pass down a window to us, and for those who don't,
+        // we can just assume that we don't want to save the entered login
+        // information.
+        return true;
       }
     },
 
 
     /*
      * log
      *
      * Internal function for logging debug messages to the Error Console window.