Bug 1035131 - Decode user entered URLs to exclude from suggested sites (r=mfinkle)
authorLucas Rocha <lucasr@mozilla.com>
Mon, 07 Jul 2014 15:59:53 +0100
changeset 192623 f14b47c390139d38f340918d15d95165642bde5c
parent 192622 f26a0f525fb457c09ccd0c4e52a7be82372391fe
child 192664 dfef245594b69c1184b69044bdd9fd47fc77c273
child 192780 6711d62510d5e34f65cefdfc9b98f6693bd9a87e
push id27091
push userkwierso@gmail.com
push dateMon, 07 Jul 2014 21:11:34 +0000
treeherdermozilla-central@f14b47c39013 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmfinkle
bugs1035131
milestone33.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1035131 - Decode user entered URLs to exclude from suggested sites (r=mfinkle)
mobile/android/base/db/BrowserDB.java
mobile/android/base/util/StringUtils.java
--- a/mobile/android/base/db/BrowserDB.java
+++ b/mobile/android/base/db/BrowserDB.java
@@ -9,16 +9,17 @@ import java.util.ArrayList;
 import java.util.EnumSet;
 import java.util.List;
 
 import org.mozilla.gecko.db.BrowserContract.ExpirePriority;
 import org.mozilla.gecko.db.SuggestedSites;
 import org.mozilla.gecko.distribution.Distribution;
 import org.mozilla.gecko.favicons.decoders.LoadFaviconResult;
 import org.mozilla.gecko.mozglue.RobocopTarget;
+import org.mozilla.gecko.util.StringUtils;
 
 import android.content.ContentResolver;
 import android.content.ContentValues;
 import android.content.Context;
 import android.database.ContentObserver;
 import android.database.Cursor;
 import android.graphics.drawable.BitmapDrawable;
 import android.graphics.Color;
@@ -189,17 +190,25 @@ public class BrowserDB {
     public static Cursor filter(ContentResolver cr, CharSequence constraint, int limit,
                                 EnumSet<FilterFlags> flags) {
         return sDb.filter(cr, constraint, limit, flags);
     }
 
     private static void appendUrlsFromCursor(List<String> urls, Cursor c) {
         c.moveToPosition(-1);
         while (c.moveToNext()) {
-            urls.add(c.getString(c.getColumnIndex(URLColumns.URL)));
+            String url = c.getString(c.getColumnIndex(URLColumns.URL));
+
+            // Do a simpler check before decoding to avoid parsing
+            // all URLs unnecessarily.
+            if (StringUtils.isUserEnteredUrl(url)) {
+                url = StringUtils.decodeUserEnteredUrl(url);
+            }
+
+            urls.add(url);
         };
     }
 
     public static Cursor getTopSites(ContentResolver cr, int minLimit, int maxLimit) {
         // Note this is not a single query anymore, but actually returns a mixture
         // of two queries, one for topSites and one for pinned sites.
         Cursor pinnedSites = sDb.getPinnedSites(cr, minLimit);
 
--- a/mobile/android/base/util/StringUtils.java
+++ b/mobile/android/base/util/StringUtils.java
@@ -6,16 +6,17 @@
 package org.mozilla.gecko.util;
 
 import android.net.Uri;
 import android.text.TextUtils;
 
 public class StringUtils {
 
     private static final String FILTER_URL_PREFIX = "filter://";
+    private static final String USER_ENTERED_URL_PREFIX = "user-entered:";
 
     /*
      * This method tries to guess if the given string could be a search query or URL,
      * and returns a previous result if there is ambiguity
      *
      * Search examples:
      *  foo
      *  foo bar.com
@@ -156,16 +157,20 @@ public class StringUtils {
     }
 
     public static boolean isShareableUrl(final String url) {
         final String scheme = Uri.parse(url).getScheme();
         return !("about".equals(scheme) || "chrome".equals(scheme) ||
                 "file".equals(scheme) || "resource".equals(scheme));
     }
 
+    public static boolean isUserEnteredUrl(String url) {
+        return (url != null && url.startsWith(USER_ENTERED_URL_PREFIX));
+    }
+
     /**
      * Given a url with a user-entered scheme, extract the
      * scheme-specific component. For e.g, given "user-entered://www.google.com",
      * this method returns "//www.google.com". If the passed url
      * does not have a user-entered scheme, the same url will be returned.
      *
      * @param  url to be decoded
      * @return url component entered by user