Bug 1236387 - Add a URL and length filter for search history suggestions r=ahunt
authorVarun Naganathan <varunnaganathan912@gmail.com>
Wed, 24 Feb 2016 20:46:03 -0800
changeset 285343 e86f91dd77be96bc473c02acf581a4a19d3073ef
parent 285342 c96b93b4d7c0d16b3ae95c4fff365df9d3564adc
child 285344 dbba65699809fcd30759a0c3b521651d2993fa55
push id30029
push usercbook@mozilla.com
push dateThu, 25 Feb 2016 10:53:34 +0000
treeherdermozilla-central@ad029c4e30b0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersahunt
bugs1236387
milestone47.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 1236387 - Add a URL and length filter for search history suggestions r=ahunt MozReview-Commit-ID: 9EFgukC0imw
mobile/android/base/java/org/mozilla/gecko/BrowserApp.java
mobile/android/base/java/org/mozilla/gecko/home/SearchEngineRow.java
--- a/mobile/android/base/java/org/mozilla/gecko/BrowserApp.java
+++ b/mobile/android/base/java/org/mozilla/gecko/BrowserApp.java
@@ -156,16 +156,17 @@ import java.io.IOException;
 import java.lang.reflect.Method;
 import java.net.URLEncoder;
 import java.util.EnumSet;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Locale;
 import java.util.UUID;
 import java.util.Vector;
+import java.util.regex.Pattern;
 
 public class BrowserApp extends GeckoApp
                         implements TabsPanel.TabsLayoutChangeListener,
                                    PropertyAnimator.PropertyAnimationListener,
                                    View.OnKeyListener,
                                    LayerView.DynamicToolbarListener,
                                    BrowserSearch.OnSearchListener,
                                    BrowserSearch.OnEditSuggestionListener,
@@ -2428,16 +2429,21 @@ public class BrowserApp extends GeckoApp
      * @param query
      *        a search query to store. We won't store empty queries.
      */
     private void storeSearchQuery(final String query) {
         if (TextUtils.isEmpty(query)) {
             return;
         }
 
+        // Filter out URLs and long suggestions
+        if (query.length() > 50 || Pattern.matches("^(https?|ftp|file)://.*", query)) {
+            return;
+        }
+
         final GeckoProfile profile = getProfile();
         // Don't bother storing search queries in guest mode
         if (profile.inGuestMode()) {
             return;
         }
 
         final BrowserDB db = profile.getDB();
         ThreadUtils.postToBackgroundThread(new Runnable() {
--- a/mobile/android/base/java/org/mozilla/gecko/home/SearchEngineRow.java
+++ b/mobile/android/base/java/org/mozilla/gecko/home/SearchEngineRow.java
@@ -34,17 +34,19 @@ import android.view.LayoutInflater;
 import android.view.View;
 import android.view.animation.AlphaAnimation;
 import android.widget.ImageView;
 import android.widget.LinearLayout;
 import android.widget.TextView;
 
 import java.util.ArrayList;
 import java.util.EnumSet;
+import java.util.Iterator;
 import java.util.List;
+import java.util.regex.Pattern;
 
 class SearchEngineRow extends AnimatedHeightLayout {
     // Duration for fade-in animation
     private static final int ANIMATION_DURATION = 250;
 
     // Inner views
     private final FlowLayout mSuggestionView;
     private final FaviconView mIconView;
@@ -378,16 +380,28 @@ class SearchEngineRow extends AnimatedHe
         setDescriptionOnSuggestion(mUserEnteredTextView, mUserEnteredTextView.getText().toString());
 
         final int recycledSuggestionCount = mSuggestionView.getChildCount();
         final SharedPreferences prefs = GeckoSharedPrefs.forApp(getContext());
         final boolean savedSearchesEnabled = prefs.getBoolean(GeckoPreferences.PREFS_HISTORY_SAVED_SEARCH, true);
 
         // Remove duplicates of search engine suggestions from saved searches.
         List<String> searchHistorySuggestions = (rawSearchHistorySuggestions != null) ? rawSearchHistorySuggestions : new ArrayList<String>();
+
+        // Filter out URLs and long search suggestions
+        Iterator<String> searchistoryIterator = searchHistorySuggestions.iterator();
+        while (searchistoryIterator.hasNext()) {
+            final String currentSearchHistory = searchistoryIterator.next();
+
+            if (currentSearchHistory.length() > 50 || Pattern.matches("^(https?|ftp|file)://.*", currentSearchHistory)) {
+                searchHistorySuggestions.remove(currentSearchHistory);
+            }
+        }
+
+
         List<String> searchEngineSuggestions = new ArrayList<String>();
         for (String suggestion : searchEngine.getSuggestions()) {
             searchHistorySuggestions.remove(suggestion);
             searchEngineSuggestions.add(suggestion);
         }
         // Make sure the search term itself isn't duplicated. This is more important on phones than tablets where screen
         // space is more precious.
         searchHistorySuggestions.remove(getSuggestionTextFromView(mUserEnteredView));