Bug 946857 - pre : Expose disabled hosts through Password CP r?nalexander draft
authorvivek <vivekb.balakrishnan@gmail.com>
Tue, 15 Dec 2015 19:23:14 +0200
changeset 317407 aef6592eed16ee69534aad41fea471e721785384
parent 317406 14aea198d5b18b4850801a23c61cbd066bf93f4f
child 317408 c9a846a5259be719bac38fb7b9b461a1014f5854
push id8691
push userbmo:vivekb.balakrishnan@gmail.com
push dateWed, 23 Dec 2015 21:07:27 +0000
reviewersnalexander
bugs946857
milestone46.0a1
Bug 946857 - pre : Expose disabled hosts through Password CP r?nalexander
mobile/android/base/java/org/mozilla/gecko/db/BrowserContract.java
mobile/android/base/java/org/mozilla/gecko/db/PasswordsProvider.java
--- a/mobile/android/base/java/org/mozilla/gecko/db/BrowserContract.java
+++ b/mobile/android/base/java/org/mozilla/gecko/db/BrowserContract.java
@@ -243,16 +243,26 @@ public class BrowserContract {
     }
 
     public static final class DeletedPasswords implements DeletedColumns {
         private DeletedPasswords() {}
         public static final String CONTENT_TYPE = "vnd.android.cursor.dir/deleted-passwords";
         public static final Uri CONTENT_URI = Uri.withAppendedPath(PASSWORDS_AUTHORITY_URI, "deleted-passwords");
     }
 
+    @RobocopTarget
+    public static final class GeckoDisabledHosts {
+        private GeckoDisabledHosts() {}
+        public static final String CONTENT_TYPE = "vnd.android.cursor.dir/disabled-hosts";
+        public static final Uri CONTENT_URI = Uri.withAppendedPath(PASSWORDS_AUTHORITY_URI, "disabled-hosts");
+
+        public static final String ID = "id";
+        public static final String HOSTNAME = "hostname";
+    }
+
     public static final class FormHistory {
         private FormHistory() {}
         public static final Uri CONTENT_URI = Uri.withAppendedPath(FORM_HISTORY_AUTHORITY_URI, "formhistory");
         public static final String CONTENT_TYPE = "vnd.android.cursor.dir/formhistory";
 
         public static final String ID = "id";
         public static final String FIELD_NAME = "fieldname";
         public static final String VALUE = "value";
--- a/mobile/android/base/java/org/mozilla/gecko/db/PasswordsProvider.java
+++ b/mobile/android/base/java/org/mozilla/gecko/db/PasswordsProvider.java
@@ -8,16 +8,17 @@ import java.util.HashMap;
 
 import org.mozilla.gecko.CrashHandler;
 import org.mozilla.gecko.GeckoApp;
 import org.mozilla.gecko.GeckoAppShell;
 import org.mozilla.gecko.GeckoEvent;
 import org.mozilla.gecko.GeckoMessageReceiver;
 import org.mozilla.gecko.NSSBridge;
 import org.mozilla.gecko.db.BrowserContract.DeletedPasswords;
+import org.mozilla.gecko.db.BrowserContract.GeckoDisabledHosts;
 import org.mozilla.gecko.db.BrowserContract.Passwords;
 import org.mozilla.gecko.mozglue.GeckoLoader;
 import org.mozilla.gecko.sqlite.MatrixBlobCursor;
 import org.mozilla.gecko.sqlite.SQLiteBridge;
 import org.mozilla.gecko.sync.Utils;
 
 import android.content.ContentValues;
 import android.content.Intent;
@@ -25,29 +26,32 @@ import android.content.UriMatcher;
 import android.database.Cursor;
 import android.net.Uri;
 import android.text.TextUtils;
 import android.util.Log;
 
 public class PasswordsProvider extends SQLiteBridgeContentProvider {
     static final String TABLE_PASSWORDS = "moz_logins";
     static final String TABLE_DELETED_PASSWORDS = "moz_deleted_logins";
+    static final String TABLE_DISABLED_HOSTS = "moz_disabledHosts";
 
     private static final String TELEMETRY_TAG = "SQLITEBRIDGE_PROVIDER_PASSWORDS";
 
     private static final int PASSWORDS = 100;
     private static final int DELETED_PASSWORDS = 101;
+    private static final int DISABLED_HOSTS = 102;
 
     static final String DEFAULT_PASSWORDS_SORT_ORDER = Passwords.HOSTNAME + " ASC";
     static final String DEFAULT_DELETED_PASSWORDS_SORT_ORDER = DeletedPasswords.TIME_DELETED + " ASC";
 
     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 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";
@@ -77,16 +81,21 @@ public class PasswordsProvider extends S
         PASSWORDS_PROJECTION_MAP.put(Passwords.TIMES_USED, Passwords.TIMES_USED);
 
         URI_MATCHER.addURI(BrowserContract.PASSWORDS_AUTHORITY, "deleted-passwords", DELETED_PASSWORDS);
 
         DELETED_PASSWORDS_PROJECTION_MAP = new HashMap<String, String>();
         DELETED_PASSWORDS_PROJECTION_MAP.put(DeletedPasswords.ID, DeletedPasswords.ID);
         DELETED_PASSWORDS_PROJECTION_MAP.put(DeletedPasswords.GUID, DeletedPasswords.GUID);
         DELETED_PASSWORDS_PROJECTION_MAP.put(DeletedPasswords.TIME_DELETED, DeletedPasswords.TIME_DELETED);
+
+        URI_MATCHER.addURI(BrowserContract.PASSWORDS_AUTHORITY, "disabled-hosts", DISABLED_HOSTS);
+
+        DISABLED_HOSTS_PROJECTION_MAP = new HashMap<String, String>();
+        DISABLED_HOSTS_PROJECTION_MAP.put(GeckoDisabledHosts.HOSTNAME, GeckoDisabledHosts.HOSTNAME);
     }
 
     public PasswordsProvider() {
         super(LOG_TAG);
     }
 
     @Override
     public boolean onCreate() {
@@ -129,31 +138,37 @@ public class PasswordsProvider extends S
 
         switch (match) {
             case PASSWORDS:
                 return Passwords.CONTENT_TYPE;
 
             case DELETED_PASSWORDS:
                 return DeletedPasswords.CONTENT_TYPE;
 
+            case DISABLED_HOSTS:
+                return GeckoDisabledHosts.CONTENT_TYPE;
+
             default:
                 throw new UnsupportedOperationException("Unknown type " + uri);
         }
     }
 
     @Override
     public String getTable(Uri uri) {
         final int match = URI_MATCHER.match(uri);
         switch (match) {
             case DELETED_PASSWORDS:
                 return TABLE_DELETED_PASSWORDS;
 
             case PASSWORDS:
                 return TABLE_PASSWORDS;
 
+            case DISABLED_HOSTS:
+                return TABLE_DISABLED_HOSTS;
+
             default:
                 throw new UnsupportedOperationException("Unknown table " + uri);
         }
     }
 
     @Override
     public String getSortOrder(Uri uri, String aRequested) {
         if (!TextUtils.isEmpty(aRequested)) {
@@ -163,16 +178,19 @@ public class PasswordsProvider extends S
         final int match = URI_MATCHER.match(uri);
         switch (match) {
             case DELETED_PASSWORDS:
                 return DEFAULT_DELETED_PASSWORDS_SORT_ORDER;
 
             case PASSWORDS:
                 return DEFAULT_PASSWORDS_SORT_ORDER;
 
+            case DISABLED_HOSTS:
+                return null;
+
             default:
                 throw new UnsupportedOperationException("Unknown URI " + uri);
         }
     }
 
     @Override
     public void setupDefaults(Uri uri, ContentValues values)
             throws IllegalArgumentException {
@@ -205,16 +223,22 @@ public class PasswordsProvider extends S
                 DBUtils.replaceKey(values, null, Passwords.ENCRYPTED_USERNAME, "");
                 DBUtils.replaceKey(values, null, Passwords.ENCRYPTED_PASSWORD, "");
                 DBUtils.replaceKey(values, null, Passwords.ENC_TYPE, "0");
                 DBUtils.replaceKey(values, null, Passwords.TIME_LAST_USED, nowString);
                 DBUtils.replaceKey(values, null, Passwords.TIME_PASSWORD_CHANGED, nowString);
                 DBUtils.replaceKey(values, null, Passwords.TIMES_USED, "0");
                 break;
 
+            case DISABLED_HOSTS:
+                if (!values.containsKey(GeckoDisabledHosts.HOSTNAME)) {
+                    throw new IllegalArgumentException("Must provide a Hostname for a disabled hosts");
+                }
+                break;
+
             default:
                 throw new UnsupportedOperationException("Unknown URI " + uri);
         }
     }
 
     @Override
     public void initGecko() {
         // We're not in the main process.  The receiver of this Intent can