Bug 823945 - Port XUL Fennec's LoginManagerChild to use per-window PB APIs; r=jdm
authorEhsan Akhgari <ehsan@mozilla.com>
Fri, 21 Dec 2012 11:10:11 -0500
changeset 125891 15b8a8271ece82ed8288bfc02db14143998140f5
parent 125890 5fddad57aa058e49caf46d5e255b24e555b870ec
child 125892 93f081cda42e90544c44822c784f147385f14700
push id2151
push userlsblakk@mozilla.com
push dateTue, 19 Feb 2013 18:06:57 +0000
treeherdermozilla-beta@4952e88741ec [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjdm
bugs823945
milestone20.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 823945 - Port XUL Fennec's LoginManagerChild to use per-window PB APIs; r=jdm
mobile/xul/chrome/content/LoginManagerChild.js
--- a/mobile/xul/chrome/content/LoginManagerChild.js
+++ b/mobile/xul/chrome/content/LoginManagerChild.js
@@ -2,52 +2,29 @@
  * 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 Cc = Components.classes;
 var Ci = Components.interfaces;
 
 Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
 Components.utils.import("resource://gre/modules/Services.jsm");
+Components.utils.import("resource://gre/modules/PrivateBrowsingUtils.jsm");
 
 var loginManager = {
 
     /* ---------- private members ---------- */
 
 
     get _formFillService() {
         return this._formFillService =
                         Cc["@mozilla.org/satchel/form-fill-controller;1"].
                         getService(Ci.nsIFormFillController);
     },
 
-    // Private Browsing Service
-    // If the service is not available, null will be returned.
-    __privateBrowsingService : undefined,
-    get _privateBrowsingService() {
-        if (this.__privateBrowsingService == undefined) {
-            if ("@mozilla.org/privatebrowsing;1" in Cc)
-                this.__privateBrowsingService = Cc["@mozilla.org/privatebrowsing;1"].
-                                                getService(Ci.nsIPrivateBrowsingService);
-            else
-                this.__privateBrowsingService = null;
-        }
-        return this.__privateBrowsingService;
-    },
-
-
-    // Whether we are in private browsing mode
-    get _inPrivateBrowsing() {
-        var pbSvc = this._privateBrowsingService;
-        if (pbSvc)
-            return pbSvc.privateBrowsingEnabled;
-        else
-            return false;
-    },
-
     _nsLoginInfo : null, // Constructor for nsILoginInfo implementation
     _debug    : false, // mirrors signon.debug
     _remember : true,  // mirrors signon.rememberSignons preference
 
     init : function () {
         // Cache references to current |this| in utility objects
         this._domEventListener._pwmgr    = this;
         this._observer._pwmgr            = this;
@@ -527,17 +504,17 @@ var loginManager = {
     _fillDocument : function (doc) {
         var forms = doc.forms;
         if (!forms || forms.length == 0)
             return;
 
         this.log("_fillDocument processing " + forms.length +
                  " forms on " + doc.documentURI);
 
-        var autofillForm = !this._inPrivateBrowsing &&
+        var autofillForm = !PrivateBrowsingUtils.isWindowPrivate(doc.defaultView) &&
                            Services.prefs.getBoolPref("signon.autofillForms");
 
         // actionOrigins is a list of each form's action origins for this
         // document. The parent process needs this to find the passwords
         // for each action origin.
         var actionOrigins = [];
 
         for (var i = 0; i < forms.length; i++) {
@@ -604,25 +581,26 @@ var loginManager = {
      * _onFormSubmit
      *
      * Called by the our observer when notified of a form submission.
      * [Note that this happens before any DOM onsubmit handlers are invoked.]
      * Looks for a password change in the submitted form, so we can update
      * our stored password.
      */
     _onFormSubmit : function (form) {
-        if (this._inPrivateBrowsing) {
+        var doc = form.ownerDocument;
+        var win = doc.defaultView;
+
+        if (PrivateBrowsingUtils.isWindowPrivate(win)) {
             // We won't do anything in private browsing mode anyway,
             // so there's no need to perform further checks.
             this.log("(form submission ignored in private browsing mode)");
             return;
         }
 
-        var doc = form.ownerDocument;
-
         // If password saving is disabled (globally or for host), bail out now.
         if (!this._remember)
             return;
 
         var hostname      = this._getPasswordOrigin(doc.documentURI);
         var formSubmitURL = this._getActionOrigin(form);