Bug 1035131 - Decode user entered URLs to exclude from suggested sites. r=mfinkle, a=lmandel
authorLucas Rocha <lucasr@mozilla.com>
Mon, 07 Jul 2014 15:59:53 +0100
changeset 201122 867e77cc2342c3c79f9e58af924864cfff11f43f
parent 201121 5ece78da865bca6cc7aa14a3798f75de66230bad
child 201123 83c99da37fe31c49fcdca44b46392ea43eaf6782
push id6450
push userryanvm@gmail.com
push dateFri, 11 Jul 2014 21:53:16 +0000
treeherdermozilla-aurora@5de908032305 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmfinkle, lmandel
bugs1035131
milestone32.0a2
Bug 1035131 - Decode user entered URLs to exclude from suggested sites. r=mfinkle, a=lmandel
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
@@ -8,16 +8,17 @@ package org.mozilla.gecko.db;
 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.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.database.ContentObserver;
 import android.database.Cursor;
 import android.graphics.drawable.BitmapDrawable;
 import android.graphics.Color;
 
@@ -176,17 +177,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
@@ -150,16 +151,20 @@ public class StringUtils {
     public static String getFilterFromUrl(String url) {
         if (TextUtils.isEmpty(url)) {
             return null;
         }
 
         return url.substring(FILTER_URL_PREFIX.length());
     }
 
+    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