diff --git a/mobile/android/base/java/org/mozilla/gecko/db/BrowserDB.java b/mobile/android/base/java/org/mozilla/gecko/db/BrowserDB.java index 36684b745fb2..e81c9dba7cbf 100644 --- a/mobile/android/base/java/org/mozilla/gecko/db/BrowserDB.java +++ b/mobile/android/base/java/org/mozilla/gecko/db/BrowserDB.java @@ -176,6 +176,13 @@ public abstract class BrowserDB { */ public abstract CursorLoader getHighlights(Context context, int limit); + /** + * Block a page from the highlights list. + * + * @param url The page URL. Only pages exactly matching this URL will be blocked. + */ + public abstract void blockActivityStreamSite(ContentResolver cr, String url); + public static BrowserDB from(final Context context) { return from(GeckoProfile.get(context)); } diff --git a/mobile/android/base/java/org/mozilla/gecko/db/BrowserProvider.java b/mobile/android/base/java/org/mozilla/gecko/db/BrowserProvider.java index 7c50e4b223c6..8d476e74d2b1 100644 --- a/mobile/android/base/java/org/mozilla/gecko/db/BrowserProvider.java +++ b/mobile/android/base/java/org/mozilla/gecko/db/BrowserProvider.java @@ -133,6 +133,8 @@ public class BrowserProvider extends SharedBrowserDatabaseProvider { static final int HIGHLIGHTS = 1300; + static final int ACTIVITY_STREAM_BLOCKLIST = 1400; + static final String DEFAULT_BOOKMARKS_SORT_ORDER = Bookmarks.TYPE + " ASC, " + Bookmarks.POSITION + " ASC, " + Bookmarks._ID + " ASC"; @@ -297,6 +299,8 @@ public class BrowserProvider extends SharedBrowserDatabaseProvider { URI_MATCHER.addURI(BrowserContract.AUTHORITY, "topsites", TOPSITES); URI_MATCHER.addURI(BrowserContract.AUTHORITY, "highlights", HIGHLIGHTS); + + URI_MATCHER.addURI(BrowserContract.AUTHORITY, ActivityStreamBlocklist.TABLE_NAME, ACTIVITY_STREAM_BLOCKLIST); } private static class ShrinkMemoryReceiver extends BroadcastReceiver { @@ -649,6 +653,12 @@ public class BrowserProvider extends SharedBrowserDatabaseProvider { break; } + case ACTIVITY_STREAM_BLOCKLIST: { + trace("Insert on ACTIVITY_STREAM_BLOCKLIST: " + uri); + id = insertActivityStreamBlocklistSite(uri, values); + break; + } + default: { Table table = findTableFor(match); if (table == null) { @@ -1878,6 +1888,17 @@ public class BrowserProvider extends SharedBrowserDatabaseProvider { return db.insertOrThrow(TABLE_THUMBNAILS, null, values); } + private long insertActivityStreamBlocklistSite(final Uri uri, final ContentValues values) { + final String url = values.getAsString(ActivityStreamBlocklist.URL); + trace("Inserting url into highlights blocklist, URL: " + url); + + final SQLiteDatabase db = getWritableDatabase(uri); + values.put(ActivityStreamBlocklist.CREATED, System.currentTimeMillis()); + + beginWrite(db); + return db.insertOrThrow(TABLE_ACTIVITY_STREAM_BLOCKLIST, null, values); + } + private long insertUrlAnnotation(final Uri uri, final ContentValues values) { final String url = values.getAsString(UrlAnnotations.URL); trace("Inserting url annotations for URL: " + url); diff --git a/mobile/android/base/java/org/mozilla/gecko/db/LocalBrowserDB.java b/mobile/android/base/java/org/mozilla/gecko/db/LocalBrowserDB.java index d857208f8ed4..7ceaabc87557 100644 --- a/mobile/android/base/java/org/mozilla/gecko/db/LocalBrowserDB.java +++ b/mobile/android/base/java/org/mozilla/gecko/db/LocalBrowserDB.java @@ -27,6 +27,7 @@ import org.mozilla.gecko.AppConstants; import org.mozilla.gecko.Telemetry; import org.mozilla.gecko.annotation.RobocopTarget; import org.mozilla.gecko.R; +import org.mozilla.gecko.db.BrowserContract.ActivityStreamBlocklist; import org.mozilla.gecko.db.BrowserContract.Bookmarks; import org.mozilla.gecko.db.BrowserContract.Combined; import org.mozilla.gecko.db.BrowserContract.ExpirePriority; @@ -118,6 +119,7 @@ public class LocalBrowserDB extends BrowserDB { private final Uri mTopSitesUriWithProfile; private final Uri mHighlightsUriWithProfile; private final Uri mSearchHistoryUri; + private final Uri mActivityStreamBlockedUriWithProfile; private LocalSearches searches; private LocalTabsAccessor tabsAccessor; @@ -145,6 +147,7 @@ public class LocalBrowserDB extends BrowserDB { mTopSitesUriWithProfile = DBUtils.appendProfile(profile, TopSites.CONTENT_URI); mHighlightsUriWithProfile = DBUtils.appendProfile(profile, Highlights.CONTENT_URI); mThumbnailsUriWithProfile = DBUtils.appendProfile(profile, Thumbnails.CONTENT_URI); + mActivityStreamBlockedUriWithProfile = DBUtils.appendProfile(profile, ActivityStreamBlocklist.CONTENT_URI); mSearchHistoryUri = BrowserContract.SearchHistory.CONTENT_URI; @@ -1843,4 +1846,12 @@ public class LocalBrowserDB extends BrowserDB { return new CursorLoader(context, uri, null, null, null, null); } + + @Override + public void blockActivityStreamSite(ContentResolver cr, String url) { + final ContentValues values = new ContentValues(); + values.put(ActivityStreamBlocklist.URL, url); + cr.insert(mActivityStreamBlockedUriWithProfile, values); + } + }