Bug 1298786 - Add hardcoded highlights domain blacklist draft
authorAndrzej Hunt <ahunt@mozilla.com>
Mon, 19 Dec 2016 11:44:38 -0800
changeset 451161 9a4d80cee7ce3ac1892beb482763d31b520d6d85
parent 450066 ad6c9803c654c870fe992dfba4bc4691745e7b61
child 539943 4fbe31029ab6b9597157697190999a10c879e145
push id39071
push userahunt@mozilla.com
push dateMon, 19 Dec 2016 19:45:33 +0000
bugs1298786
milestone53.0a1
Bug 1298786 - Add hardcoded highlights domain blacklist This is really minimal, and incomplete. We'd probably want a dynamic blacklist in future? MozReview-Commit-ID: 9g5K0ewU8ha
mobile/android/base/java/org/mozilla/gecko/db/BrowserProvider.java
--- a/mobile/android/base/java/org/mozilla/gecko/db/BrowserProvider.java
+++ b/mobile/android/base/java/org/mozilla/gecko/db/BrowserProvider.java
@@ -1222,16 +1222,52 @@ public class BrowserProvider extends Sha
 
     /**
      * Obtain a set of links for highlights (from bookmarks and history).
      *
      * Based on the query for Activity^ Stream (desktop):
      * https://github.com/mozilla/activity-stream/blob/9eb9f451b553bb62ae9b8d6b41a8ef94a2e020ea/addon/PlacesProvider.js#L578
      */
     public Cursor getHighlights(final SQLiteDatabase db, String limit) {
+        final String[] blacklistedHosts = new String[] {
+                "www.google.com",
+                "www.google.ca",
+                "calendar.google.com",
+                "mail.google.com",
+                "mail.yahoo.com",
+                "search.yahoo.com",
+                "localhost",
+                "t.co"
+        };
+
+        final String blacklistSubquery;
+        if (blacklistedHosts.length > 0) {
+            final StringBuilder blacklistSubqueryBuilder = new StringBuilder();
+            blacklistSubqueryBuilder.append("SELECT " + Domains._ID +
+                    " FROM " + Domains.TABLE_NAME +
+                    " WHERE " +
+                    Domains.DOMAIN + " IN (");
+
+            boolean appendedFirst = false;
+
+            for (final String s : blacklistedHosts) {
+                if (appendedFirst) {
+                    blacklistSubqueryBuilder.append(',');
+                }
+                appendedFirst = true;
+
+                blacklistSubqueryBuilder.append('?');
+            }
+
+            blacklistSubqueryBuilder.append(")");
+            blacklistSubquery = blacklistSubqueryBuilder.toString();
+        } else {
+            blacklistSubquery = "";
+        }
+
         final int totalLimit = limit == null ? 20 : Integer.parseInt(limit);
 
         final long threeDaysAgo = System.currentTimeMillis() - (1000 * 60 * 60 * 24 * 3);
         final long bookmarkLimit = 1;
 
         // Select recent bookmarks that have not been visited much
         final String bookmarksQuery = "SELECT * FROM (SELECT " +
                 "-1 AS " + Combined.HISTORY_ID + ", " +
@@ -1263,27 +1299,28 @@ public class BrowserProvider extends Sha
                 History.TITLE + ", " +
                 History.DATE_LAST_VISITED + " AS " + Highlights.DATE + " " +
                 "FROM " + History.TABLE_NAME + " " +
                 "WHERE " + History.DATE_LAST_VISITED + " < " + last30Minutes + " " +
                 "AND " + History.VISITS + " <= 3 " +
                 "AND " + History.TITLE + " NOT NULL AND " + History.TITLE + " != '' " +
                 "AND " + History.IS_DELETED + " = 0 " +
                 "AND " + History.URL + " NOT IN (SELECT " + ActivityStreamBlocklist.URL + " FROM " + ActivityStreamBlocklist.TABLE_NAME + " )" +
-                // TODO: Implement domain black list (bug 1298786)
+                "AND " + History.DOMAIN_ID + " NOT IN (" + blacklistSubquery + ")" +
                 // TODO: Group by host (bug 1298785)
                 "ORDER BY " + History.DATE_LAST_VISITED + " DESC " +
                 "LIMIT " + historyLimit + ")";
 
         final String query = "SELECT DISTINCT * " +
                 "FROM (" + bookmarksQuery + " " +
                 "UNION ALL " + historyQuery + ") " +
                 "GROUP BY " + Combined.URL + ";";
 
-        final Cursor cursor = db.rawQuery(query, null);
+        final Cursor cursor = db.rawQuery(query,
+                blacklistedHosts);
 
         cursor.setNotificationUri(getContext().getContentResolver(),
                 BrowserContract.AUTHORITY_URI);
 
         return cursor;
     }
 
     @Override