Bug 1058438 - Migrate disabledHosts from sqlite storage to permission manager. r=MattN draft
authorSaad Quadri <saad@saadquadri.com>
Tue, 09 Aug 2016 10:14:51 -0700
changeset 398743 398c07c36a8e7ccf7aad600c0487a71a04cab266
parent 398742 12eeefc6057850f34e98b84b13bba64b193845b3
child 398744 92c556c14aeee988d30985ac162493e0212b2909
push id25613
push usersaad@saadquadri.com
push dateTue, 09 Aug 2016 17:16:57 +0000
reviewersMattN
bugs1058438
milestone51.0a1
Bug 1058438 - Migrate disabledHosts from sqlite storage to permission manager. r=MattN MozReview-Commit-ID: BKlAmwzu3is
mobile/android/base/java/org/mozilla/gecko/db/PasswordsProvider.java
toolkit/components/passwordmgr/storage-mozStorage.js
--- a/mobile/android/base/java/org/mozilla/gecko/db/PasswordsProvider.java
+++ b/mobile/android/base/java/org/mozilla/gecko/db/PasswordsProvider.java
@@ -44,17 +44,17 @@ public class PasswordsProvider extends S
 
     private static final UriMatcher URI_MATCHER;
 
     private static final HashMap<String, String> PASSWORDS_PROJECTION_MAP;
     private static final HashMap<String, String> DELETED_PASSWORDS_PROJECTION_MAP;
     private static final HashMap<String, String> DISABLED_HOSTS_PROJECTION_MAP;
 
     // this should be kept in sync with the version in toolkit/components/passwordmgr/storage-mozStorage.js
-    private static final int DB_VERSION = 5;
+    private static final int DB_VERSION = 6;
     private static final String DB_FILENAME = "signons.sqlite";
     private static final String WHERE_GUID_IS_NULL = BrowserContract.DeletedPasswords.GUID + " IS NULL";
     private static final String WHERE_GUID_IS_VALUE = BrowserContract.DeletedPasswords.GUID + " = ?";
 
     private static final String LOG_TAG = "GeckoPasswordsProvider";
 
     private CrashHandler mCrashHandler;
 
--- a/toolkit/components/passwordmgr/storage-mozStorage.js
+++ b/toolkit/components/passwordmgr/storage-mozStorage.js
@@ -1,14 +1,15 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 const { classes: Cc, interfaces: Ci, utils: Cu, results: Cr } = Components;
-const DB_VERSION = 5; // The database schema version
+const DB_VERSION = 6; // The database schema version
+const PERMISSION_SAVE_LOGINS = "login-saving";
 
 Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
 Components.utils.import("resource://gre/modules/Services.jsm");
 Components.utils.import("resource://gre/modules/Promise.jsm");
 
 XPCOMUtils.defineLazyModuleGetter(this, "LoginHelper",
                                   "resource://gre/modules/LoginHelper.jsm");
 
@@ -1176,16 +1177,54 @@ LoginManagerStorage_mozStorage.prototype
    */
   _dbMigrateToVersion5 : function () {
     if (!this._dbConnection.tableExists("moz_deleted_logins")) {
       this._dbConnection.createTable("moz_deleted_logins", this._dbSchema.tables.moz_deleted_logins);
     }
   },
 
   /*
+   * _dbMigrateToVersion6
+   *
+   * Version 6 migrates all the hosts from
+   * moz_disabledHosts to the permission manager.
+   */
+  _dbMigrateToVersion6 : function () {
+    let disabledHosts = [];
+    let query = "SELECT hostname FROM moz_disabledHosts";
+    let stmt;
+
+    try {
+      stmt = this._dbCreateStatement(query);
+
+      while (stmt.executeStep()) {
+        disabledHosts.push(stmt.row.hostname);
+      }
+
+      for (let host of 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);
+        }
+      }
+    } catch (e) {
+      this.log(`_dbMigrateToVersion6 failed: ${e.name} : ${e.message}`);
+    } finally {
+      if (stmt) {
+        stmt.reset();
+      }
+    }
+
+    query = "DELETE FROM moz_disabledHosts";
+    this._dbConnection.executeSimpleSQL(query);
+  },
+
+  /*
    * _dbAreExpectedColumnsPresent
    *
    * Sanity check to ensure that the columns this version of the code expects
    * are present in the DB we're using.
    */
   _dbAreExpectedColumnsPresent : function () {
     let query = "SELECT " +
                    "id, " +