Bug 1232651 - don't show search suggestions in private browsing r=mcomella draft
authorAndrzej Hunt <ahunt@mozilla.com>
Wed, 06 Jan 2016 15:43:13 -0800
changeset 320166 b58f40911311a1b74bc650dccdd973b7ba23acaa
parent 320165 ea01aa74be131267e98f034d115df035bd86cd9d
child 512695 78f02dedb0e8751f2f540a430346d4e278870f98
push id9143
push userahunt@mozilla.com
push dateFri, 08 Jan 2016 21:30:53 +0000
reviewersmcomella
bugs1232651
milestone46.0a1
Bug 1232651 - don't show search suggestions in private browsing r=mcomella We also remove the special case for updating mSuggestClient when search engines are modified during private browsing - this causes a weird edge case where we potentially show history suggestions after switching search engines (this seems to be because having mSuggestClient == null avoids us even reaching the stage where we usually recycle unneeded suggestions).
mobile/android/base/java/org/mozilla/gecko/home/BrowserSearch.java
--- a/mobile/android/base/java/org/mozilla/gecko/home/BrowserSearch.java
+++ b/mobile/android/base/java/org/mozilla/gecko/home/BrowserSearch.java
@@ -592,17 +592,20 @@ public class BrowserSearch extends HomeF
         return searchDomains(searchTerm);
     }
 
     public void resetScrollState() {
         mSearchEngineBar.scrollToPosition(0);
     }
 
     private void filterSuggestions() {
-        if (mSuggestClient == null || (!mSuggestionsEnabled && !mSavedSearchesEnabled)) {
+        Tab tab = Tabs.getInstance().getSelectedTab();
+        final boolean isPrivate = (tab != null && tab.isPrivate());
+
+        if (isPrivate || mSuggestClient == null || (!mSuggestionsEnabled && !mSavedSearchesEnabled)) {
             return;
         }
 
         // Suggestions from search engine
         if (mSearchEngineSuggestionLoaderCallbacks == null) {
             mSearchEngineSuggestionLoaderCallbacks = new SearchEngineSuggestionLoaderCallbacks();
         }
         getLoaderManager().restartLoader(LOADER_ID_SUGGESTION, null, mSearchEngineSuggestionLoaderCallbacks);
@@ -669,26 +672,19 @@ public class BrowserSearch extends HomeF
                 final SearchEngine engine = new SearchEngine((Context) getActivity(), engineJSON);
 
                 if (engine.name.equals(suggestEngine) && suggestTemplate != null) {
                     // Suggest engine should be at the front of the list.
                     // We're baking in an assumption here that the suggest engine
                     // is also the default engine.
                     searchEngines.add(0, engine);
 
-                    // The only time Tabs.getInstance().getSelectedTab() should
-                    // be null is when we're restoring after a crash. We should
-                    // never restore private tabs when that happens, so it
-                    // should be safe to assume that null means non-private.
-                    Tab tab = Tabs.getInstance().getSelectedTab();
-                    final boolean isPrivate = (tab != null && tab.isPrivate());
-
                     // Only create a new instance of SuggestClient if it hasn't been
                     // set yet.
-                    maybeSetSuggestClient(suggestTemplate, isPrivate);
+                    maybeSetSuggestClient(suggestTemplate);
                 } else {
                     searchEngines.add(engine);
                 }
             }
 
             // checking if the new searchEngine is different from mSearchEngine, will have to re-layout if yes
             boolean change = shouldUpdateSearchEngine(searchEngines);
 
@@ -734,22 +730,17 @@ public class BrowserSearch extends HomeF
     @Override
     public void onSearchBarClickListener(final SearchEngine searchEngine) {
         Telemetry.sendUIEvent(TelemetryContract.Event.LOAD_URL, TelemetryContract.Method.LIST_ITEM,
                 "searchenginebar");
 
         mSearchListener.onSearch(searchEngine, mSearchTerm);
     }
 
-    private void maybeSetSuggestClient(final String suggestTemplate, final boolean isPrivate) {
-        if (isPrivate) {
-            mSuggestClient = null;
-            return;
-        }
-
+    private void maybeSetSuggestClient(final String suggestTemplate) {
         if (mSuggestClient != null) {
             return;
         }
 
         mSuggestClient = sSuggestClientFactory.getSuggestClient(getActivity(), suggestTemplate, SUGGESTION_TIMEOUT, NETWORK_SUGGESTION_MAX);
     }
 
     private void showSuggestionsOptIn() {