Commit c0d73900 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 e9a4e30c
Loading
Loading
Loading
Loading
+72 −6
Original line number Diff line number Diff line
@@ -122,9 +122,25 @@ LoginManager.prototype = {
      log.debug("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);
      }
    }
  },


@@ -160,6 +176,7 @@ LoginManager.prototype = {
        this._pwmgr = null;
      } else if (topic == "passwordmgr-storage-replace") {
        (async () => {
          if (this._pwmgr._storage)
            await this._pwmgr._storage.terminate();
          this._pwmgr._initStorage();
          await this._pwmgr.initializationPromise;
@@ -310,6 +327,9 @@ LoginManager.prototype = {
      throw new Error("This login already exists.");
    }

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

    log.debug("Adding login");
    return this._storage.addLogin(login);
  },
@@ -352,6 +372,12 @@ LoginManager.prototype = {
   */
  removeLogin(login) {
    log.debug("Removing login");

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

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

@@ -361,6 +387,12 @@ LoginManager.prototype = {
   */
  modifyLogin(oldLogin, newLogin) {
    log.debug("Modifying login");

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

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

@@ -373,6 +405,12 @@ LoginManager.prototype = {
   */
  getAllLogins(count) {
    log.debug("Getting a list of all logins");

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

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

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

@@ -421,6 +462,11 @@ LoginManager.prototype = {
    log.debug("Searching for logins matching origin:", origin,
              "formActionOrigin:", formActionOrigin, "httpRealm:", httpRealm);

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

    return this._storage.findLogins(count, origin, formActionOrigin,
                                    httpRealm);
  },
@@ -435,6 +481,11 @@ LoginManager.prototype = {
  searchLogins(count, matchData) {
    log.debug("Searching for logins");

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

    matchData.QueryInterface(Ci.nsIPropertyBag2);
    if (!matchData.hasKey("guid")) {
      if (!matchData.hasKey("hostname")) {
@@ -458,16 +509,27 @@ LoginManager.prototype = {
    log.debug("Counting logins matching origin:", origin,
              "formActionOrigin:", formActionOrigin, "httpRealm:", httpRealm);

    if (!this._storage) {
      log.debug("No storage to count logins");
      return 0;
    }

    return this._storage.countLogins(origin, formActionOrigin, httpRealm);
  },


  get uiBusy() {
    if (!this._storage)
      return false;

    return this._storage.uiBusy;
  },


  get isLoggedIn() {
    if (!this._storage)
      return false;

    return this._storage.isLoggedIn;
  },

@@ -477,7 +539,7 @@ LoginManager.prototype = {
   */
  getLoginSavingEnabled(origin) {
    log.debug("Checking if logins to", origin, "can be saved.");
    if (!this._remember) {
    if (!this._remember || !this._storage) {
      return false;
    }

@@ -493,6 +555,10 @@ LoginManager.prototype = {
    // Throws if there are bogus values.
    LoginHelper.checkHostnameValue(origin);

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

    let uri = Services.io.newURI(origin);
    if (enabled) {
      Services.perms.remove(uri, PERMISSION_SAVE_LOGINS);