Bug 1058438 - Migrate disabledHosts from json storage to permission manager. r=MattN
☠☠ backed out by b93bc99d4c6e ☠ ☠
authorKapeel Sable <kapeels42@gmail.com>
Wed, 06 Jan 2016 17:57:40 +0530
changeset 348426 d15abe37a931d9e8db0565bdc7d45e17ba5824d3
parent 348425 13df5d72d37359dcbfbfcbdc9d5dbd9ceee8d72e
child 348427 f0ef54ffcec1ded743dd180846292017b50ac858
push id1230
push userjlund@mozilla.com
push dateMon, 31 Oct 2016 18:13:35 +0000
treeherdermozilla-release@5e06e3766db2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersMattN
bugs1058438
milestone50.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 1058438 - Migrate disabledHosts from json storage to permission manager. r=MattN MozReview-Commit-ID: 2qaUCZjqc47
toolkit/components/passwordmgr/LoginStore.jsm
toolkit/components/passwordmgr/storage-json.js
--- a/toolkit/components/passwordmgr/LoginStore.jsm
+++ b/toolkit/components/passwordmgr/LoginStore.jsm
@@ -263,16 +263,18 @@ LoginStore.prototype = {
    * Synchronously work on the data just loaded into memory.
    */
   _processLoadedData: function ()
   {
     // Create any arrays that are not present in the saved file.
     if (!this.data.logins) {
       this.data.logins = [];
     }
+
+    // Stub needed for login imports before data has been migrated.
     if (!this.data.disabledHosts) {
       this.data.disabledHosts = [];
     }
 
     // Indicate that the current version of the code has touched the file.
     this.data.version = kDataVersion;
 
     this.dataReady = true;
--- 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_SAVE_LOGINS = "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,17 +82,34 @@ 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) {
+          try {
+            let uri = Services.io.newURI(host, null, null);
+            Services.perms.add(uri, PERMISSION_SAVE_LOGINS, Services.perms.DENY_ACTION);
+          } catch (e) {
+            Cu.reportError(e);
+          }
+        }
+        delete this._store.data.disabledHosts;
+        this._store.saveSoon();
+      }.bind(this))).catch(Cu.reportError);
     } catch (e) {
       this.log("Initialization failed:", e);
       throw new Error("Initialization failed");
     }
   },
 
   /**
    * Internal method used by regression tests only.  It is called before
@@ -361,18 +381,16 @@ 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();