Bug 740076 - Disable autoFill when autocomplete is disabled.
authorMarco Bonardo <mbonardo@mozilla.com>
Sat, 05 May 2012 14:26:42 +0200
changeset 26421 42a38643a3b6d9182b0526e43c2f8567eb0bf578
parent 26420 fc9979908a292444c555157e4e32cfbdae96da9b
child 26422 8749fef99a0b62bae822fa86f340eccd5f378cf0
push id1834
push userclokep@gmail.com
push dateMon, 23 Jan 2017 21:48:40 +0000
treeherdercomm-beta@293cffe83e59 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs740076
Bug 740076 - Disable autoFill when autocomplete is disabled. r=dietrich
suite/common/places/nsPlacesAutoComplete.js
--- a/suite/common/places/nsPlacesAutoComplete.js
+++ b/suite/common/places/nsPlacesAutoComplete.js
@@ -98,17 +98,18 @@ const kQueryTypeKeyword = 0;
 const kQueryTypeFiltered = 1;
 
 // This separator is used as an RTL-friendly way to split the title and tags.
 // It can also be used by an nsIAutoCompleteResult consumer to re-split the
 // "comment" back into the title and the tag.
 const kTitleTagsSeparator = " \u2013 ";
 
 const kBrowserUrlbarBranch = "browser.urlbar.";
-
+// Toggle autocomplete.
+const kBrowserUrlbarAutocompleteEnabledPref = "autocomplete.enabled";
 // Toggle autoFill.
 const kBrowserUrlbarAutofillPref = "autoFill";
 // Whether to search only typed entries.
 const kBrowserUrlbarAutofillTypedPref = "autoFill.typed";
 
 ////////////////////////////////////////////////////////////////////////////////
 //// Globals
 
@@ -840,17 +841,19 @@ nsPlacesAutoComplete.prototype = {
    * Loads the preferences that we care about.
    *
    * @param [optional] aRegisterObserver
    *        Indicates if the preference observer should be added or not.  The
    *        default value is false.
    */
   _loadPrefs: function PAC_loadPrefs(aRegisterObserver)
   {
-    this._enabled = safePrefGetter(this._prefs, "autocomplete.enabled", true);
+    this._enabled = safePrefGetter(this._prefs,
+                                   kBrowserUrlbarAutocompleteEnabledPref,
+                                   true);
     this._matchBehavior = safePrefGetter(this._prefs,
                                          "matchBehavior",
                                          MATCH_BOUNDARY_ANYWHERE);
     this._filterJavaScript = safePrefGetter(this._prefs, "filter.javascript", true);
     this._maxRichResults = safePrefGetter(this._prefs, "maxRichResults", 25);
     this._restrictHistoryToken = safePrefGetter(this._prefs,
                                                 "restrict.history", "^");
     this._restrictBookmarkToken = safePrefGetter(this._prefs,
@@ -1296,17 +1299,17 @@ urlInlineComplete.prototype = {
 
 /////////////////////////////////////////////////////////////////////////////////
 //// Database and query getters
 
   __db: null,
 
   get _db()
   {
-    if (!this.__db && this._autofill) {
+    if (!this.__db && this._autofillEnabled) {
       this.__db = PlacesUtils.history.QueryInterface(Ci.nsPIPlacesDatabase).
                   DBConnection.clone(true);
     }
     return this.__db;
   },
 
   __syncQuery: null,
 
@@ -1481,19 +1484,23 @@ urlInlineComplete.prototype = {
    *
    * @param [optional] aRegisterObserver
    *        Indicates if the preference observer should be added or not.  The
    *        default value is false.
    */
   _loadPrefs: function UIC_loadPrefs(aRegisterObserver)
   {
     let prefBranch = Services.prefs.getBranch(kBrowserUrlbarBranch);
-    this._autofill = safePrefGetter(prefBranch,
-                                    kBrowserUrlbarAutofillPref,
-                                    true);
+    let autocomplete = safePrefGetter(prefBranch,
+                                      kBrowserUrlbarAutocompleteEnabledPref,
+                                      true);
+    let autofill = safePrefGetter(prefBranch,
+                                  kBrowserUrlbarAutofillPref,
+                                  true);
+    this._autofillEnabled = autocomplete && autofill;
     this._autofillTyped = safePrefGetter(prefBranch,
                                          kBrowserUrlbarAutofillTypedPref,
                                          true);
     if (aRegisterObserver) {
       Services.prefs.addObserver(kBrowserUrlbarBranch, this, true);
     }
   },
 
@@ -1543,20 +1550,21 @@ urlInlineComplete.prototype = {
 
   observe: function UIC_observe(aSubject, aTopic, aData)
   {
     if (aTopic == kTopicShutdown) {
       this._closeDatabase();
     }
     else if (aTopic == kPrefChanged &&
              (aData.substr(kBrowserUrlbarBranch.length) == kBrowserUrlbarAutofillPref ||
+              aData.substr(kBrowserUrlbarBranch.length) == kBrowserUrlbarAutocompleteEnabledPref ||
               aData.substr(kBrowserUrlbarBranch.length) == kBrowserUrlbarAutofillTypedPref)) {
       let previousAutofillTyped = this._autofillTyped;
       this._loadPrefs();
-      if (!this._autofill) {
+      if (!this._autofillEnabled) {
         this.stopSearch();
         this._closeDatabase();
       }
       else if (this._autofillTyped != previousAutofillTyped) {
         // Invalidate the statements to update them for the new typed status.
         this._invalidateStatements();
       }
     }