diff --git a/mobile/android/base/AwesomeBarTabs.java b/mobile/android/base/AwesomeBarTabs.java index 785a2c0bc469..edf566462058 100644 --- a/mobile/android/base/AwesomeBarTabs.java +++ b/mobile/android/base/AwesomeBarTabs.java @@ -41,6 +41,7 @@ package org.mozilla.gecko; import android.content.ContentResolver; import android.content.Context; import android.content.res.Resources; +import android.database.ContentObserver; import android.database.Cursor; import android.graphics.Bitmap; import android.graphics.BitmapFactory; @@ -102,6 +103,7 @@ public class AwesomeBarTabs extends TabHost { private View.OnTouchListener mListTouchListener; private JSONArray mSearchEngines; private ContentResolver mContentResolver; + private ContentObserver mContentObserver; private BookmarksQueryTask mBookmarksQueryTask; private HistoryQueryTask mHistoryQueryTask; @@ -581,6 +583,17 @@ public class AwesomeBarTabs extends TabHost { result.second ); + if (mContentObserver == null) { + // Register an observer to update the history tab contents if they change. + mContentObserver = new ContentObserver(GeckoAppShell.getHandler()) { + public void onChange(boolean selfChange) { + mHistoryQueryTask = new HistoryQueryTask(); + mHistoryQueryTask.execute(); + } + }; + BrowserDB.registerHistoryObserver(mContentResolver, mContentObserver); + } + final ExpandableListView historyList = (ExpandableListView) findViewById(R.id.history_list); @@ -738,6 +751,7 @@ public class AwesomeBarTabs extends TabHost { mInflated = false; mSearchEngines = new JSONArray(); mContentResolver = context.getContentResolver(); + mContentObserver = null; mInflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); } @@ -1001,6 +1015,9 @@ public class AwesomeBarTabs extends TabHost { if (bookmarksCursor != null) bookmarksCursor.close(); } + + if (mContentObserver != null) + BrowserDB.unregisterContentObserver(mContentResolver, mContentObserver); } public void filter(String searchTerm) { diff --git a/mobile/android/base/Tab.java b/mobile/android/base/Tab.java index 531ad8bff657..2bdd952f7984 100644 --- a/mobile/android/base/Tab.java +++ b/mobile/android/base/Tab.java @@ -139,7 +139,7 @@ public final class Tab { public void onDestroy() { mDoorHangers = new HashMap(); - BrowserDB.unregisterBookmarkObserver(mContentResolver, mContentObserver); + BrowserDB.unregisterContentObserver(mContentResolver, mContentObserver); } public int getId() { diff --git a/mobile/android/base/db/AndroidBrowserDB.java b/mobile/android/base/db/AndroidBrowserDB.java index 10ce151d4765..fe3b6c2388f3 100644 --- a/mobile/android/base/db/AndroidBrowserDB.java +++ b/mobile/android/base/db/AndroidBrowserDB.java @@ -313,6 +313,10 @@ public class AndroidBrowserDB implements BrowserDB.BrowserDBIface { registerBookmarkObserverPre11(cr, observer); } + public void registerHistoryObserver(ContentResolver cr, ContentObserver observer) { + // Not implemented + } + public BitmapDrawable getFaviconForUrl(ContentResolver cr, String uri) { Cursor c = cr.query(Browser.BOOKMARKS_URI, new String[] { Browser.BookmarkColumns.FAVICON }, diff --git a/mobile/android/base/db/BrowserDB.java b/mobile/android/base/db/BrowserDB.java index 62a956f70b73..4b9564e4c1c5 100644 --- a/mobile/android/base/db/BrowserDB.java +++ b/mobile/android/base/db/BrowserDB.java @@ -102,6 +102,8 @@ public class BrowserDB { public byte[] getThumbnailForUrl(ContentResolver cr, String uri); public void registerBookmarkObserver(ContentResolver cr, ContentObserver observer); + + public void registerHistoryObserver(ContentResolver cr, ContentObserver observer); } static { @@ -198,7 +200,11 @@ public class BrowserDB { sDb.registerBookmarkObserver(cr, observer); } - public static void unregisterBookmarkObserver(ContentResolver cr, ContentObserver observer) { + public static void registerHistoryObserver(ContentResolver cr, ContentObserver observer) { + sDb.registerHistoryObserver(cr, observer); + } + + public static void unregisterContentObserver(ContentResolver cr, ContentObserver observer) { cr.unregisterContentObserver(observer); } } diff --git a/mobile/android/base/db/LocalBrowserDB.java b/mobile/android/base/db/LocalBrowserDB.java index d7a0db4ae9ce..624576d8ec03 100644 --- a/mobile/android/base/db/LocalBrowserDB.java +++ b/mobile/android/base/db/LocalBrowserDB.java @@ -508,8 +508,11 @@ public class LocalBrowserDB implements BrowserDB.BrowserDBIface { } public void registerBookmarkObserver(ContentResolver cr, ContentObserver observer) { - Uri uri = mBookmarksUriWithProfile; - cr.registerContentObserver(uri, false, observer); + cr.registerContentObserver(mBookmarksUriWithProfile, false, observer); + } + + public void registerHistoryObserver(ContentResolver cr, ContentObserver observer) { + cr.registerContentObserver(mHistoryUriWithProfile, false, observer); } public void updateBookmark(ContentResolver cr, int id, String uri, String title, String keyword) {