Bug 1306847 - Add ability to disable search engine suggestions under browser.urlbar.suggest.searchengine; r?adw
MozReview-Commit-ID: EiZ1L8aYWkt
--- a/toolkit/components/places/UnifiedComplete.js
+++ b/toolkit/components/places/UnifiedComplete.js
@@ -40,16 +40,17 @@ const PREF_RESTRICT_SEARCHES = [ "r
const PREF_MATCH_TITLE = [ "match.title", "#" ];
const PREF_MATCH_URL = [ "match.url", "@" ];
const PREF_SUGGEST_HISTORY = [ "suggest.history", true ];
const PREF_SUGGEST_BOOKMARK = [ "suggest.bookmark", true ];
const PREF_SUGGEST_OPENPAGE = [ "suggest.openpage", true ];
const PREF_SUGGEST_HISTORY_ONLYTYPED = [ "suggest.history.onlyTyped", false ];
const PREF_SUGGEST_SEARCHES = [ "suggest.searches", false ];
+const PREF_SUGGEST_SEARCHENGINE = [ "suggest.searchengine", true ];
const PREF_MAX_CHARS_FOR_SUGGEST = [ "maxCharsForSearchSuggestions", 20];
// AutoComplete query type constants.
// Describes the various types of queries that we can process rows for.
const QUERYTYPE_FILTERED = 0;
const QUERYTYPE_AUTOFILL_HOST = 1;
const QUERYTYPE_AUTOFILL_URL = 2;
@@ -365,16 +366,17 @@ XPCOMUtils.defineLazyGetter(this, "Prefs
function syncEnabledPref() {
loadSyncedPrefs();
let suggestPrefs = [
PREF_SUGGEST_HISTORY,
PREF_SUGGEST_BOOKMARK,
PREF_SUGGEST_OPENPAGE,
PREF_SUGGEST_SEARCHES,
+ PREF_SUGGEST_SEARCHENGINE,
];
if (store.enabled) {
// If the autocomplete preference is active, set to default value all suggest
// preferences only if all of them are false.
if (types.every(type => store["suggest" + type] == false)) {
for (let type of suggestPrefs) {
prefs.set(...type);
@@ -390,16 +392,17 @@ XPCOMUtils.defineLazyGetter(this, "Prefs
function loadSyncedPrefs () {
store.enabled = prefs.get(...PREF_ENABLED);
store.suggestHistory = prefs.get(...PREF_SUGGEST_HISTORY);
store.suggestBookmark = prefs.get(...PREF_SUGGEST_BOOKMARK);
store.suggestOpenpage = prefs.get(...PREF_SUGGEST_OPENPAGE);
store.suggestTyped = prefs.get(...PREF_SUGGEST_HISTORY_ONLYTYPED);
store.suggestSearches = prefs.get(...PREF_SUGGEST_SEARCHES);
+ store.suggestSearchEngines = prefs.get(...PREF_SUGGEST_SEARCHENGINE);
}
function loadPrefs(subject, topic, data) {
if (data) {
// Synchronize suggest.* prefs with autocomplete.enabled.
if (data == PREF_BRANCH + PREF_ENABLED[0]) {
syncEnabledPref();
} else if (data.startsWith(PREF_BRANCH + "suggest.")) {
@@ -995,17 +998,17 @@ Search.prototype = {
// it as such. This can happen if the host would require whitelisting,
// but isn't in the whitelist.
let matched = yield this._matchUnknownUrl();
if (matched) {
return true;
}
}
- if (this.pending && this._enableActions && this._originalSearchString) {
+ if (this.pending && this._enableActions && this._originalSearchString && Prefs.suggestSearchEngines) {
// When all else fails, and the search string is non-empty, we search
// using the current search engine.
let matched = yield this._matchCurrentSearchEngine();
if (matched) {
return true;
}
}
@@ -1039,17 +1042,17 @@ Search.prototype = {
this._searchSuggestionController.resultsCount < 2) {
// The original string is used to properly compare with the next search.
this._lastLowResultsSearchSuggestion = this._originalSearchString;
}
while (this.pending && this._remoteMatchesCount < Prefs.maxRichResults) {
let [match, suggestion] = this._searchSuggestionController.consume();
if (!suggestion)
break;
- if (!looksLikeUrl(suggestion)) {
+ if (!looksLikeUrl(suggestion) && !Prefs.suggestSearchEngines) {
// Don't include the restrict token, if present.
let searchString = this._searchTokens.join(" ");
this._addSearchEngineMatch(match, searchString, suggestion);
}
}
});
if (this.hasBehavior("restrict")) {