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
--- 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