From c357a145a68f2a6e9987f3514d4ab7f9c29b8dea Mon Sep 17 00:00:00 2001 From: Drew Willcoxon Date: Wed, 15 Jul 2015 12:25:55 -0700 Subject: [PATCH] Bug 1182792 - Disable search suggestions in the URL bar in private windows. r=mak --- toolkit/components/places/UnifiedComplete.js | 31 +++++++++++++++++-- .../unifiedcomplete/test_searchSuggestions.js | 24 +++++++++++++- 2 files changed, 51 insertions(+), 4 deletions(-) diff --git a/toolkit/components/places/UnifiedComplete.js b/toolkit/components/places/UnifiedComplete.js index 4027b4bee048..686feb9e62a7 100644 --- a/toolkit/components/places/UnifiedComplete.js +++ b/toolkit/components/places/UnifiedComplete.js @@ -559,9 +559,33 @@ function makeActionURL(action, params) { //////////////////////////////////////////////////////////////////////////////// -//// Search Class -//// Manages a single instance of an autocomplete search. +/** + * Manages a single instance of an autocomplete search. + * + * The first three parameters all originate from the similarly named parameters + * of nsIAutoCompleteSearch.startSearch(). + * + * @param searchString + * The search string. + * @param searchParam + * A space-delimited string of search parameters. The following + * parameters are supported: + * * enable-actions: Include "actions", such as switch-to-tab and search + * engine aliases, in the results. + * * disable-private-actions: The search is taking place in a private + * window outside of permanent private-browsing mode. The search + * should exclude privacy-sensitive results as appropriate. + * * private-window: The search is taking place in a private window, + * possibly in permanent private-browsing mode. The search + * should exclude privacy-sensitive results as appropriate. + * @param autocompleteListener + * An nsIAutoCompleteObserver. + * @param resultListener + * An nsIAutoCompleteSimpleResultListener. + * @param autocompleteSearch + * An nsIAutoCompleteSearch. + */ function Search(searchString, searchParam, autocompleteListener, resultListener, autocompleteSearch) { // We want to store the original string for case sensitive searches. @@ -872,8 +896,9 @@ Search.prototype = { }), *_matchSearchSuggestions() { - if (!this.hasBehavior("searches")) + if (!this.hasBehavior("searches") || this._inPrivateWindow) { return; + } this._searchSuggestionController = PlacesSearchAutocompleteProvider.getSuggestionController( diff --git a/toolkit/components/places/tests/unifiedcomplete/test_searchSuggestions.js b/toolkit/components/places/tests/unifiedcomplete/test_searchSuggestions.js index 37e5cdfe1ceb..290d44c2b212 100644 --- a/toolkit/components/places/tests/unifiedcomplete/test_searchSuggestions.js +++ b/toolkit/components/places/tests/unifiedcomplete/test_searchSuggestions.js @@ -47,8 +47,9 @@ add_task(function* setUp() { Services.search.currentEngine = engine; }); -add_task(function* disabled() { +add_task(function* disabled_urlbarSuggestions() { Services.prefs.setBoolPref(SUGGEST_PREF, false); + Services.prefs.setBoolPref(SUGGEST_ENABLED_PREF, true); yield check_autocomplete({ search: "hello", matches: [], @@ -56,6 +57,27 @@ add_task(function* disabled() { yield cleanUpSuggestions(); }); +add_task(function* disabled_allSuggestions() { + Services.prefs.setBoolPref(SUGGEST_PREF, true); + Services.prefs.setBoolPref(SUGGEST_ENABLED_PREF, false); + yield check_autocomplete({ + search: "hello", + matches: [], + }); + yield cleanUpSuggestions(); +}); + +add_task(function* disabled_privateWindow() { + Services.prefs.setBoolPref(SUGGEST_PREF, true); + Services.prefs.setBoolPref(SUGGEST_ENABLED_PREF, true); + yield check_autocomplete({ + search: "hello", + matches: [], + searchParam: "private-window", + }); + yield cleanUpSuggestions(); +}); + add_task(function* singleWordQuery() { Services.prefs.setBoolPref(SUGGEST_PREF, true); Services.prefs.setBoolPref(SUGGEST_ENABLED_PREF, true);