Minor password manager code simplification b=390447 r=dolske
authorneil@parkwaycc.co.uk
Thu, 09 Aug 2007 11:59:06 -0700
changeset 4417 8c46e6e2ddddc2c96d0bcbe306d65209ce70020e
parent 4416 b7c428889fbe4a9d7ecd91b92cb100db3e543da9
child 4418 f22ceaf5632f063f98c6ae668c39502ed2a6b5a7
push idunknown
push userunknown
push dateunknown
reviewersdolske
bugs390447
milestone1.9a8pre
Minor password manager code simplification b=390447 r=dolske
toolkit/components/passwordmgr/src/nsLoginManager.js
toolkit/components/passwordmgr/src/nsLoginManagerPrompter.js
--- a/toolkit/components/passwordmgr/src/nsLoginManager.js
+++ b/toolkit/components/passwordmgr/src/nsLoginManager.js
@@ -287,43 +287,43 @@ LoginManager.prototype = {
                                                 Ci.nsISupportsWeakReference]),
 
 
         onStateChange : function (aWebProgress, aRequest,
                                   aStateFlags,  aStatus) {
 
             // STATE_START is too early, doc is still the old page.
             if (!(aStateFlags & Ci.nsIWebProgressListener.STATE_TRANSFERRING))
-                return 0;
+                return;
 
             if (!this._pwmgr._remember)
-                return 0;
+                return;
 
             var domWin = aWebProgress.DOMWindow;
             var domDoc = domWin.document;
 
             // Only process things which might have HTML forms.
             if (! domDoc instanceof Ci.nsIDOMHTMLDocument)
-                return 0;
+                return;
 
             this._pwmgr.log("onStateChange accepted: req = " + (aRequest ?
                         aRequest.name : "(null)") + ", flags = " + aStateFlags);
 
             // fastback navigation... We won't get a DOMContentLoaded
             // event again, so process any forms now.
             if (aStateFlags & Ci.nsIWebProgressListener.STATE_RESTORING) {
                 this._pwmgr.log("onStateChange: restoring document");
                 return this._pwmgr._fillDocument(domDoc);
             }
 
             // Add event listener to process page when DOM is complete.
             this._pwmgr.log("onStateChange: adding dom listeners");
             domDoc.addEventListener("DOMContentLoaded",
                                     this._domEventListener, false);
-            return 0;
+            return;
         },
 
         // stubs for the nsIWebProgressListener interfaces which we don't use.
         onProgressChange : function() { throw "Unexpected onProgressChange"; },
         onLocationChange : function() { throw "Unexpected onLocationChange"; },
         onStatusChange   : function() { throw "Unexpected onStatusChange";   },
         onSecurityChange : function() { throw "Unexpected onSecurityChange"; }
     },
@@ -344,26 +344,28 @@ LoginManager.prototype = {
 
         handleEvent : function (event) {
             this._pwmgr.log("domEventListener: got event " + event.type);
 
             var doc, inputElement;
             switch (event.type) {
                 case "DOMContentLoaded":
                     doc = event.target;
-                    return this._pwmgr._fillDocument(doc);
+                    this._pwmgr._fillDocument(doc);
+                    return;
 
                 case "DOMAutoComplete":
                 case "blur":
                     inputElement = event.target;
-                    return this._pwmgr._fillPassword(inputElement);
+                    this._pwmgr._fillPassword(inputElement);
+                    return;
 
                 default:
                     this._pwmgr.log("Oops! This event unexpected.");
-                    return 0;
+                    return;
             }
         }
     },
 
 
 
 
     /* ---------- Primary Public interfaces ---------- */
@@ -430,19 +432,17 @@ LoginManager.prototype = {
      * Get a dump of all stored logins. Used by the login manager UI.
      *
      * |count| is only needed for XPCOM.
      *
      * Returns an array of logins. If there are no logins, the array is empty.
      */
     getAllLogins : function (count) {
         this.log("Getting a list of all logins");
-        var logins = this._storage.getAllLogins({});
-        count.value = logins.length;
-        return logins;
+        return this._storage.getAllLogins(count);
     },
 
 
     /*
      * removeAllLogins
      *
      * Remove all stored logins.
      */
@@ -458,36 +458,32 @@ LoginManager.prototype = {
      *
      * |count| is only needed for XPCOM.
      *
      * Returns an array of disabled logins. If there are no disabled logins,
      * the array is empty.
      */
     getAllDisabledHosts : function (count) {
         this.log("Getting a list of all disabled hosts");
-        var hosts = this._storage.getAllDisabledHosts({});
-        count.value = hosts.length;
-        return hosts;
+        return this._storage.getAllDisabledHosts(count);
     },
 
 
     /*
      * findLogins
      *
      * Search the known logins for entries matching the specified criteria
      * for a protocol login (eg HTTP Auth).
      */
     findLogins : function (count, hostname, formSubmitURL, httpRealm) {
         this.log("Searching for logins matching host: " + hostname +
             ", formSubmitURL: " + formSubmitURL + ", httpRealm: " + httpRealm);
 
-        var logins = this._storage.findLogins({}, hostname, formSubmitURL,
-                                              httpRealm);
-        count.value = logins.length;
-        return logins;
+        return this._storage.findLogins(count, hostname, formSubmitURL,
+                                        httpRealm);
     },
 
 
     /*
      * getLoginSavingEnabled
      *
      * Check to see if user has disabled saving logins for the host.
      */
--- a/toolkit/components/passwordmgr/src/nsLoginManagerPrompter.js
+++ b/toolkit/components/passwordmgr/src/nsLoginManagerPrompter.js
@@ -71,24 +71,18 @@ LoginManagerPromptFactory.prototype = {
 
             // Prompt service for user interaction
             this._promptService = Cc["@mozilla.org/embedcomp/prompt-service;1"]
                                     .getService(Ci.nsIPromptService2);
 
             this._initialized = true;
         }
 
-        if (!aIID.equals(Ci.nsIAuthPrompt2))
-            throw Components.results.NS_ERROR_NO_INTERFACE;
-
-        var prompter = new LoginManagerPrompter();
-        prompter.init(this._pwmgr, this._promptService, aWindow);
-        prompter.QueryInterface(Ci.nsIAuthPrompt2);
-
-        return prompter;
+        return new LoginManagerPrompter(this._pwmgr, this._promptService,
+                                        aWindow).QueryInterface(aIID);
     }
 }; // end of LoginManagerPromptFactory implementation
 
 
 
 
 /* ==================== LoginManagerPrompter ==================== */
 
@@ -98,17 +92,23 @@ LoginManagerPromptFactory.prototype = {
 /*
  * LoginManagerPrompter
  *
  * Implements nsIAuthPrompt2.
  *
  * Invoked by a channel for protocol-based authentication (eg HTTP
  * Authenticate, FTP login)
  */
-function LoginManagerPrompter() {}
+function LoginManagerPrompter(pwmgr, promptService, window) {
+  this._pwmgr = pwmgr;
+  this._promptService = promptService;
+  this._window = window;
+
+  this.log("===== initialized =====");
+}
 LoginManagerPrompter.prototype = {
 
     QueryInterface : XPCOMUtils.generateQI([Ci.nsIAuthPrompt2]),
 
     __logService : null, // Console logging service, used for debugging.
     get _logService() {
         if (!this.__logService)
             this.__logService = Cc["@mozilla.org/consoleservice;1"]
@@ -118,25 +118,16 @@ LoginManagerPrompter.prototype = {
 
     _promptService : null,
     _pwmgr         : null,
     _window        : null,
 
     _debug         : false,
 
 
-    init : function (aPWManager, aPromptService, aWindow) {
-        this._pwmgr = aPWManager;
-        this._promptService = aPromptService;
-        this._window = aWindow;
-
-        this.log("===== initialized =====");
-    },
-
-
     /*
      * log
      *
      * Internal function for logging debug messages to the Error Console window.
      */
     log : function (message) {
         if (!this._debug)
             return;