Bug 1306847 - Add ability to disable search engine suggestions under browser.urlbar.suggest.searchengine; r?adw draft
authorManish Goregaokar <manishsmail@gmail.com>
Sat, 01 Oct 2016 21:29:07 +0530
changeset 419887 23fde64de82fe7d0f5b8067a6a1ba58bc317036a
parent 419886 344920af45b92da6d4f5b84738e1c7a3fb582461
child 419888 f8e9e31c5cf2f5c9bf418c11559d695e6ffca46b
push id31035
push userbmo:manishearth@gmail.com
push dateSat, 01 Oct 2016 16:06:31 +0000
reviewersadw
bugs1306847
milestone52.0a1
Bug 1306847 - Add ability to disable search engine suggestions under browser.urlbar.suggest.searchengine; r?adw MozReview-Commit-ID: EiZ1L8aYWkt
toolkit/components/places/UnifiedComplete.js
--- 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")) {