--- a/toolkit/components/passwordmgr/storage-json.js
+++ b/toolkit/components/passwordmgr/storage-json.js
@@ -22,16 +22,19 @@ XPCOMUtils.defineLazyModuleGetter(this,
"resource://gre/modules/LoginStore.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "OS",
"resource://gre/modules/osfile.jsm");
XPCOMUtils.defineLazyServiceGetter(this, "gUUIDGenerator",
"@mozilla.org/uuid-generator;1",
"nsIUUIDGenerator");
+// The permission type we store in the permission manager.
+const PERMISSION_TYPE_LOGIN = "login-saving";
+
this.LoginManagerStorage_json = function () {};
this.LoginManagerStorage_json.prototype = {
classID: Components.ID("{c00c432d-a0c9-46d7-bef6-9c45b4d07341}"),
QueryInterface: XPCOMUtils.generateQI([Ci.nsILoginManagerStorage]),
__crypto: null, // nsILoginManagerCrypto service
get _crypto() {
@@ -79,18 +82,33 @@ this.LoginManagerStorage_json.prototype
// prevent us from marking the operation as completed.
// At the next startup, we will not try the import again.
yield loginImport.import().catch(Cu.reportError);
this._store.saveSoon();
}
// We won't attempt import again on next startup.
Services.prefs.setBoolPref("signon.importedFromSqlite", true);
- }.bind(this)).catch(Cu.reportError);
+ }.bind(this)).catch(Cu.reportError)
+ .then(Task.spawn(function () {
+ // If the storage has a disabledHosts entry we migrate them
+ // to the permissions manager (bug 1058438)
+ if (!this._store.data || !this._store.data.disabledHosts) {
+ return; // already migrated.
+ }
+ for (let host of this._store.data.disabledHosts) {
+ let uri = Services.io.newURI(host);
+ Services.perms.add(uri, PERMISSION_TYPE_LOGIN,
+ Ci.nsIPermissionManager.DENY_ACTION);
+ }
+ delete this._store.data.disabledHosts;
+ this._store.saveSoon();
+ }.bind(this))).catch(Cu.reportError);
} catch (e) {
+ dump("Initialization failed: " + e + "\n");
this.log("Initialization failed:", e);
throw new Error("Initialization failed");
}
},
/**
* Internal method used by regression tests only. It is called before
* replacing this storage module with a new instance.
@@ -361,68 +379,67 @@ this.LoginManagerStorage_json.prototype
this.log("_searchLogins: returning", foundLogins.length, "logins for", matchData,
"with options", aOptions);
return [foundLogins, foundIds];
},
/**
* Removes all logins from storage.
- *
- * Disabled hosts are kept, as one presumably doesn't want to erase those.
*/
removeAllLogins() {
this._store.ensureDataReady();
this.log("Removing all logins");
this._store.data.logins = [];
this._store.saveSoon();
this._sendNotification("removeAllLogins", null);
},
+ // All disabledHost APIs are now delegated to the permission manager
+ // after issuing a deprecation warning.
getAllDisabledHosts(count) {
- this._store.ensureDataReady();
+ let disabledHosts = [];
+ let enumerator = Services.perms.enumerator;
- let disabledHosts = this._store.data.disabledHosts.slice(0);
+ while (enumerator.hasMoreElements()) {
+ let perm = enumerator.getNext();
+ if (perm.type == PERMISSION_TYPE_LOGIN
+ && perm.capability == Services.perms.DENY_ACTION) {
+ disabledHosts.push(perm.principal.URI.prePath);
+ }
+ }
+
+ if (count)
+ count.value = disabledHosts.length; // needed for XPCOM
this.log("_getAllDisabledHosts: returning", disabledHosts.length, "disabled hosts.");
- if (count)
- count.value = disabledHosts.length; // needed for XPCOM
return disabledHosts;
},
- getLoginSavingEnabled(hostname) {
- this._store.ensureDataReady();
-
- this.log("Getting login saving is enabled for", hostname);
- return this._store.data.disabledHosts.indexOf(hostname) == -1;
+ getLoginSavingEnabled(origin) {
+ let uri = Services.io.newURI(origin, null, null);
+ this.log("Getting login saving is enabled for", origin);
+ return Services.perms.testPermission(uri, PERMISSION_TYPE_LOGIN) != Services.perms.DENY_ACTION;
},
- setLoginSavingEnabled(hostname, enabled) {
- this._store.ensureDataReady();
-
+ setLoginSavingEnabled(origin, enabled) {
// Throws if there are bogus values.
- LoginHelper.checkHostnameValue(hostname);
+ LoginHelper.checkHostnameValue(origin);
- this.log("Setting login saving enabled for", hostname, "to", enabled);
- let foundIndex = this._store.data.disabledHosts.indexOf(hostname);
+ this.log("Setting login saving enabled for", origin, "to", enabled);
+ let uri = Services.io.newURI(origin, null, null);
if (enabled) {
- if (foundIndex != -1) {
- this._store.data.disabledHosts.splice(foundIndex, 1);
- this._store.saveSoon();
- }
+ Services.perms.remove(uri, PERMISSION_TYPE_LOGIN);
} else {
- if (foundIndex == -1) {
- this._store.data.disabledHosts.push(hostname);
- this._store.saveSoon();
- }
+ Services.perms.add(uri, PERMISSION_TYPE_LOGIN, Services.perms.DENY_ACTION);
}
- this._sendNotification(enabled ? "hostSavingEnabled" : "hostSavingDisabled", hostname);
+ this._sendNotification(enabled ? "hostSavingEnabled" : "hostSavingDisabled", origin);
},
findLogins(count, hostname, formSubmitURL, httpRealm) {
let loginData = {
hostname: hostname,
formSubmitURL: formSubmitURL,
httpRealm: httpRealm
};