Commit 5995aea1 authored by Kathleen Brade's avatar Kathleen Brade Committed by Georg Koppen
Browse files

Bug 14716: HTTP Basic Authentication prompt only displayed once

Modify the login manager implementation to handle the situation
where storage is not available.
parent 9064546a
Loading
Loading
Loading
Loading
+75 −6
Original line number Diff line number Diff line
@@ -122,9 +122,25 @@ LoginManager.prototype = {
      log("No alternate nsILoginManagerStorage registered");
    }

    // If the security.nocertdb pref. is true, we skip initialization of
    // login manager storage since we know it will fail.  In this case we
    // pretend that initialization succeeded in order to avoid a cascade of
    // initialization errors.
    if (Services.prefs.getBoolPref("security.nocertdb")) {
      this._storage = null;
      this.initializationPromise = Promise.resolve();
    } else {
      this._storage = Cc[contractID].
                      createInstance(Ci.nsILoginManagerStorage);
      try {
        this.initializationPromise = this._storage.initialize();
      } catch (e) {
        // If storage is not available, set _storage to null so that we can
        // cleanly check for a lack of storage elsewhere in this file.
        this._storage = null;
        this.initializationPromise = Promise.reject(e);
      }
    }
  },


@@ -163,6 +179,7 @@ LoginManager.prototype = {
        this._pwmgr = null;
      } else if (topic == "passwordmgr-storage-replace") {
        Task.spawn(function () {
          if (this._pwmgr._storage)
            yield this._pwmgr._storage.terminate();
          this._pwmgr._initStorage();
          yield this._pwmgr.initializationPromise;
@@ -301,6 +318,9 @@ LoginManager.prototype = {
    if (logins.some(l => login.matches(l, true)))
      throw new Error("This login already exists.");

    if (!this._storage)
      throw new Error("No storage to add login");

    log("Adding login");
    return this._storage.addLogin(login);
  },
@@ -312,6 +332,12 @@ LoginManager.prototype = {
   */
  removeLogin : function (login) {
    log("Removing login");

    if (!this._storage) {
      log("No storage to remove login");
      return null;
    }

    return this._storage.removeLogin(login);
  },

@@ -323,6 +349,12 @@ LoginManager.prototype = {
   */
  modifyLogin : function (oldLogin, newLogin) {
    log("Modifying login");

    if (!this._storage) {
      log("No storage to modify login");
      return null;
    }

    return this._storage.modifyLogin(oldLogin, newLogin);
  },

@@ -338,6 +370,12 @@ LoginManager.prototype = {
   */
  getAllLogins : function (count) {
    log("Getting a list of all logins");

    if (!this._storage) {
      log("No storage to get all logins");
      return null;
    }

    return this._storage.getAllLogins(count);
  },

@@ -349,6 +387,9 @@ LoginManager.prototype = {
   */
  removeAllLogins : function () {
    log("Removing all logins");
    if (!this._storage)
      log("No storage to remove all logins");
    else
      this._storage.removeAllLogins();
  },

@@ -364,6 +405,12 @@ LoginManager.prototype = {
   */
  getAllDisabledHosts : function (count) {
    log("Getting a list of all disabled hosts");

    if (!this._storage) {
      log("No storage to get all disabled hosts");
      return null;
    }

    return this._storage.getAllDisabledHosts(count);
  },

@@ -377,6 +424,11 @@ LoginManager.prototype = {
    log("Searching for logins matching host:", hostname,
        "formSubmitURL:", formSubmitURL, "httpRealm:", httpRealm);

    if (!this._storage) {
      log("No storage to find logins");
      return null;
    }

    return this._storage.findLogins(count, hostname, formSubmitURL,
                                    httpRealm);
  },
@@ -393,6 +445,11 @@ LoginManager.prototype = {
  searchLogins : function(count, matchData) {
   log("Searching for logins");

    if (!this._storage) {
      log("No storage to search logins");
      return null;
    }

    return this._storage.searchLogins(count, matchData);
  },

@@ -407,6 +464,9 @@ LoginManager.prototype = {
    log("Counting logins matching host:", hostname,
        "formSubmitURL:", formSubmitURL, "httpRealm:", httpRealm);

    if (!this._storage)
      return 0;

    return this._storage.countLogins(hostname, formSubmitURL, httpRealm);
  },

@@ -415,6 +475,9 @@ LoginManager.prototype = {
   * uiBusy
   */
  get uiBusy() {
    if (!this._storage)
      return false;

    return this._storage.uiBusy;
  },

@@ -423,6 +486,9 @@ LoginManager.prototype = {
   * isLoggedIn
   */
  get isLoggedIn() {
    if (!this._storage)
      return false;

    return this._storage.isLoggedIn;
  },

@@ -434,7 +500,7 @@ LoginManager.prototype = {
   */
  getLoginSavingEnabled : function (host) {
    log("Checking if logins to", host, "can be saved.");
    if (!this._remember)
    if (!this._remember || !this._storage)
      return false;

    return this._storage.getLoginSavingEnabled(host);
@@ -451,6 +517,9 @@ LoginManager.prototype = {
    if (hostname.indexOf("\0") != -1)
      throw new Error("Invalid hostname");

    if (!this._storage)
      throw new Error("No storage to set login saving enabled");

    log("Login saving for", hostname, "now enabled?", enabled);
    return this._storage.setLoginSavingEnabled(hostname, enabled);
  },