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).

--HG--
extra : commitid : 7nSA4lqzGKX
extra : rebase_source : 04ae0ccda497f19152f15dc6592bdb90b6af5864
This commit is contained in:
Andrzej Hunt 2016-01-06 15:43:13 -08:00
Родитель 16a8713da4
Коммит 25ecf5b562
1 изменённых файлов: 12 добавлений и 19 удалений

Просмотреть файл

@ -253,7 +253,7 @@ public class BrowserSearch extends HomeFragment
@Override
public void onHiddenChanged(boolean hidden) {
if (!hidden) {
Tab tab = Tabs.getInstance().getSelectedTab();
final Tab tab = Tabs.getInstance().getSelectedTab();
final boolean isPrivate = (tab != null && tab.isPrivate());
// Removes Search Suggestions Loader if in private browsing mode
@ -593,7 +593,11 @@ public class BrowserSearch extends HomeFragment
}
private void filterSuggestions() {
if (mSuggestClient == null || (!mSuggestionsEnabled && !mSavedSearchesEnabled)) {
Tab tab = Tabs.getInstance().getSelectedTab();
final boolean isPrivate = (tab != null && tab.isPrivate());
if (isPrivate || (!mSuggestionsEnabled && !mSavedSearchesEnabled)) {
mSearchHistorySuggestions.clear();
return;
}
@ -670,16 +674,7 @@ public class BrowserSearch extends HomeFragment
// 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);
ensureSuggestClientIsSet(suggestTemplate);
} else {
searchEngines.add(engine);
}
@ -696,12 +691,15 @@ public class BrowserSearch extends HomeFragment
mAdapter.notifyDataSetChanged();
}
final Tab tab = Tabs.getInstance().getSelectedTab();
final boolean isPrivate = (tab != null && tab.isPrivate());
// Show suggestions opt-in prompt only if suggestions are not enabled yet,
// user hasn't been prompted and we're not on a private browsing tab.
// The prompt might have been inflated already when this view was previously called.
// Remove the opt-in prompt if it has been inflated in the view and dealt with by the user,
// or if we're on a private browsing tab
if (!mSuggestionsEnabled && !suggestionsPrompted && mSuggestClient != null) {
if (!mSuggestionsEnabled && !suggestionsPrompted && !isPrivate) {
showSuggestionsOptIn();
} else {
removeSuggestionsOptIn();
@ -735,12 +733,7 @@ public class BrowserSearch extends HomeFragment
mSearchListener.onSearch(searchEngine, mSearchTerm);
}
private void maybeSetSuggestClient(final String suggestTemplate, final boolean isPrivate) {
if (isPrivate) {
mSuggestClient = null;
return;
}
private void ensureSuggestClientIsSet(final String suggestTemplate) {
if (mSuggestClient != null) {
return;
}