bug 710392 - exclude about:home from top sites on about:home r=lucasr
authorBrad Lassey <blassey@mozilla.com>
Wed, 04 Jan 2012 21:34:06 -0800
changeset 85116 4f11bea71a4a50465fc6b05e02def70a163dca04
parent 85115 e4c773d0f228232e8a022746285f1aa52636bdd0
child 85117 0ac1cbff2a676dd6312e9ee2dcd813e14645fcc8
push id805
push userakeybl@mozilla.com
push dateWed, 01 Feb 2012 18:17:35 +0000
treeherdermozilla-aurora@6fb3bf232436 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerslucasr
bugs710392
milestone12.0a1
bug 710392 - exclude about:home from top sites on about:home r=lucasr
mobile/android/base/AboutHomeContent.java
mobile/android/base/db/AndroidBrowserDB.java
mobile/android/base/db/BrowserDB.java
mobile/android/base/db/LocalBrowserDB.java
--- a/mobile/android/base/AboutHomeContent.java
+++ b/mobile/android/base/AboutHomeContent.java
@@ -163,17 +163,17 @@ public class AboutHomeContent extends Sc
 
         inflater.inflate(R.layout.abouthome_content, this);
         final Runnable generateCursorsRunnable = new Runnable() {
             public void run() {
                 if (mCursor != null)
                     activity.stopManagingCursor(mCursor);
 
                 ContentResolver resolver = GeckoApp.mAppContext.getContentResolver();
-                mCursor = BrowserDB.filter(resolver, "", NUMBER_OF_TOP_SITES_PORTRAIT);
+                mCursor = BrowserDB.filter(resolver, "", NUMBER_OF_TOP_SITES_PORTRAIT, "about:%");
                 activity.startManagingCursor(mCursor);
 
                 mTopSitesAdapter = new TopSitesCursorAdapter(activity,
                                                              R.layout.abouthome_topsite_item,
                                                              mCursor,
                                                              new String[] { URLColumns.TITLE,
                                                                             URLColumns.THUMBNAIL },
                                                              new int[] { R.id.title, R.id.thumbnail });
--- a/mobile/android/base/db/AndroidBrowserDB.java
+++ b/mobile/android/base/db/AndroidBrowserDB.java
@@ -56,28 +56,30 @@ public class AndroidBrowserDB implements
     private static final String URL_COLUMN_ID = "_id";
     private static final String URL_COLUMN_THUMBNAIL = "thumbnail";
 
     // Only available on Android >= 11
     private static final String URL_COLUMN_DELETED = "deleted";
 
     private static final Uri BOOKMARKS_CONTENT_URI_POST_11 = Uri.parse("content://com.android.browser/bookmarks");
 
-    public Cursor filter(ContentResolver cr, CharSequence constraint, int limit) {
+    public Cursor filter(ContentResolver cr, CharSequence constraint, int limit, CharSequence urlFilter) {
         Cursor c = cr.query(Browser.BOOKMARKS_URI,
                             new String[] { URL_COLUMN_ID,
                                            BookmarkColumns.URL,
                                            BookmarkColumns.TITLE,
                                            BookmarkColumns.FAVICON,
                                            URL_COLUMN_THUMBNAIL },
                             // The length restriction on URL is for the same reason as in the general bookmark query
                             // (see comment earlier in this file).
+                            (urlFilter != null ? "(" + Browser.BookmarkColumns.URL + " NOT LIKE ? ) AND " : "" ) + 
                             "(" + Browser.BookmarkColumns.URL + " LIKE ? OR " + Browser.BookmarkColumns.TITLE + " LIKE ?)"
                             + " AND LENGTH(" + Browser.BookmarkColumns.URL + ") > 0",
-                            new String[] {"%" + constraint.toString() + "%", "%" + constraint.toString() + "%",},
+                            urlFilter == null ? new String[] {"%" + constraint.toString() + "%", "%" + constraint.toString() + "%"} :
+                            new String[] {urlFilter.toString(), "%" + constraint.toString() + "%", "%" + constraint.toString() + "%"},
                             // ORDER BY is number of visits times a multiplier from 1 - 120 of how recently the site
                             // was accessed with a site accessed today getting 120 and a site accessed 119 or more
                             // days ago getting 1
                             Browser.BookmarkColumns.VISITS + " * MAX(1, (" +
                             Browser.BookmarkColumns.DATE + " - " + new Date().getTime() + ") / 86400000 + 120) DESC LIMIT " + limit);
 
         return new AndroidDBCursor(c);
     }
--- a/mobile/android/base/db/BrowserDB.java
+++ b/mobile/android/base/db/BrowserDB.java
@@ -48,17 +48,17 @@ public class BrowserDB {
         public static String FAVICON = "favicon";
         public static String THUMBNAIL = "thumbnail";
         public static String DATE_LAST_VISITED = "date-last-visited";
     }
 
     private static BrowserDBIface sDb;
 
     public interface BrowserDBIface {
-        public Cursor filter(ContentResolver cr, CharSequence constraint, int limit);
+        public Cursor filter(ContentResolver cr, CharSequence constraint, int limit, CharSequence urlFilter);
 
         public void updateVisitedHistory(ContentResolver cr, String uri);
 
         public void updateHistoryTitle(ContentResolver cr, String uri, String title);
 
         public void updateHistoryDate(ContentResolver cr, String uri, long date);
 
         public Cursor getAllVisitedHistory(ContentResolver cr);
@@ -83,18 +83,22 @@ public class BrowserDB {
     }
 
     static {
         // FIXME: Still need to figure out how to use local or android
         // database here.
         sDb = new AndroidBrowserDB();
     }
 
+    public static Cursor filter(ContentResolver cr, CharSequence constraint, int limit, CharSequence urlFilter) {
+        return sDb.filter(cr, constraint, limit, urlFilter);
+    }
+
     public static Cursor filter(ContentResolver cr, CharSequence constraint, int limit) {
-        return sDb.filter(cr, constraint, limit);
+        return sDb.filter(cr, constraint, limit, null);
     }
 
     public static void updateVisitedHistory(ContentResolver cr, String uri) {
         sDb.updateVisitedHistory(cr, uri);
     }
 
     public static void updateHistoryTitle(ContentResolver cr, String uri, String title) {
         sDb.updateHistoryTitle(cr, uri, title);
@@ -138,9 +142,9 @@ public class BrowserDB {
 
     public static void updateFaviconForUrl(ContentResolver cr, String uri, BitmapDrawable favicon) {
         sDb.updateFaviconForUrl(cr, uri, favicon);
     }
 
     public static void updateThumbnailForUrl(ContentResolver cr, String uri, BitmapDrawable thumbnail) {
         sDb.updateThumbnailForUrl(cr, uri, thumbnail);
     }
-}
\ No newline at end of file
+}
--- a/mobile/android/base/db/LocalBrowserDB.java
+++ b/mobile/android/base/db/LocalBrowserDB.java
@@ -76,25 +76,27 @@ public class LocalBrowserDB implements B
         return uri.buildUpon().appendQueryParameter(BrowserContract.PARAM_PROFILE, mProfile).
                 appendQueryParameter(BrowserContract.PARAM_LIMIT, String.valueOf(limit)).build();
     }
 
     private Uri appendProfile(Uri uri) {
         return uri.buildUpon().appendQueryParameter(BrowserContract.PARAM_PROFILE, mProfile).build();
     }
 
-    public Cursor filter(ContentResolver cr, CharSequence constraint, int limit) {
+    public Cursor filter(ContentResolver cr, CharSequence constraint, int limit, CharSequence urlFilter) {
         Cursor c = cr.query(appendProfileAndLimit(History.CONTENT_URI, limit),
                             new String[] { History._ID,
                                            History.URL,
                                            History.TITLE,
                                            History.FAVICON,
                                            History.THUMBNAIL },
+                            (urlFilter != null ? "(" + History.URL + " NOT LIKE ? )" : "" )+ 
                             "(" + History.URL + " LIKE ? OR " + History.TITLE + " LIKE ?)",
-                            new String[] {"%" + constraint.toString() + "%", "%" + constraint.toString() + "%"},
+                            urlFilter == null ? new String[] {"%" + constraint.toString() + "%", "%" + constraint.toString() + "%"} :
+                            new String[] {urlFilter.toString(), "%" + constraint.toString() + "%", "%" + constraint.toString() + "%"},
                             // ORDER BY is number of visits times a multiplier from 1 - 120 of how recently the site
                             // was accessed with a site accessed today getting 120 and a site accessed 119 or more
                             // days ago getting 1
                             History.VISITS + " * MAX(1, (" +
                             History.DATE_LAST_VISITED + " - " + new Date().getTime() + ") / 86400000 + 120) DESC");
 
         return new LocalDBCursor(c);
     }