From 6be1a8808a6f37a2a575cdc3ffac393705c46e65 Mon Sep 17 00:00:00 2001 From: Shane Tully Date: Tue, 20 Aug 2013 14:54:16 -0700 Subject: [PATCH] Bug 880118 - Provide a way to disable content providers for a GeckoView library. r=blassey --- mobile/android/base/GeckoView.java | 6 ++++++ mobile/android/base/GlobalHistory.java | 4 ++++ mobile/android/base/db/BrowserDB.java | 27 ++++++++++++++++++++------ 3 files changed, 31 insertions(+), 6 deletions(-) diff --git a/mobile/android/base/GeckoView.java b/mobile/android/base/GeckoView.java index 8251b5c89d5..47d4845a710 100644 --- a/mobile/android/base/GeckoView.java +++ b/mobile/android/base/GeckoView.java @@ -39,6 +39,12 @@ public class GeckoView extends LayerView if (!doInit) return; + // If running outside of a GeckoActivity (eg, from a library project), + // load the native code and disable content providers + if (!(context instanceof GeckoActivity)) { + BrowserDB.setEnableContentProviders(false); + } + if (url != null) { GeckoThread.setUri(url); GeckoThread.setAction(Intent.ACTION_VIEW); diff --git a/mobile/android/base/GlobalHistory.java b/mobile/android/base/GlobalHistory.java index 1f18f17bb86..230c10b6ede 100644 --- a/mobile/android/base/GlobalHistory.java +++ b/mobile/android/base/GlobalHistory.java @@ -54,6 +54,10 @@ class GlobalHistory { Cursor c = null; try { c = BrowserDB.getAllVisitedHistory(GeckoAppShell.getContext().getContentResolver()); + if (c == null) { + return; + } + if (c.moveToFirst()) { do { visitedSet.add(c.getString(0)); diff --git a/mobile/android/base/db/BrowserDB.java b/mobile/android/base/db/BrowserDB.java index fbdc8da5884..bac65660746 100644 --- a/mobile/android/base/db/BrowserDB.java +++ b/mobile/android/base/db/BrowserDB.java @@ -20,6 +20,7 @@ import java.util.List; public class BrowserDB { public static String ABOUT_PAGES_URL_FILTER = "about:%"; + private static boolean sAreContentProvidersEnabled = true; public static interface URLColumns { public static String URL = "url"; @@ -146,20 +147,26 @@ public class BrowserDB { } public static void updateVisitedHistory(ContentResolver cr, String uri) { - sDb.updateVisitedHistory(cr, uri); + if (sAreContentProvidersEnabled) { + sDb.updateVisitedHistory(cr, uri); + } } public static void updateHistoryTitle(ContentResolver cr, String uri, String title) { - sDb.updateHistoryTitle(cr, uri, title); + if (sAreContentProvidersEnabled) { + sDb.updateHistoryTitle(cr, uri, title); + } } public static void updateHistoryEntry(ContentResolver cr, String uri, String title, long date, int visits) { - sDb.updateHistoryEntry(cr, uri, title, date, visits); + if (sAreContentProvidersEnabled) { + sDb.updateHistoryEntry(cr, uri, title, date, visits); + } } public static Cursor getAllVisitedHistory(ContentResolver cr) { - return sDb.getAllVisitedHistory(cr); + return (sAreContentProvidersEnabled ? sDb.getAllVisitedHistory(cr) : null); } public static Cursor getRecentHistory(ContentResolver cr, int limit) { @@ -204,11 +211,11 @@ public class BrowserDB { } public static boolean isBookmark(ContentResolver cr, String uri) { - return sDb.isBookmark(cr, uri); + return (sAreContentProvidersEnabled && sDb.isBookmark(cr, uri)); } public static boolean isReadingListItem(ContentResolver cr, String uri) { - return sDb.isReadingListItem(cr, uri); + return (sAreContentProvidersEnabled && sDb.isReadingListItem(cr, uri)); } public static void addBookmark(ContentResolver cr, String title, String uri) { @@ -307,6 +314,14 @@ public class BrowserDB { return sDb.getBookmarkForUrl(cr, url); } + public static boolean areContentProvidersDisabled() { + return sAreContentProvidersEnabled; + } + + public static void setEnableContentProviders(boolean enableContentProviders) { + sAreContentProvidersEnabled = enableContentProviders; + } + public static class PinnedSite { public String title = ""; public String url = "";