Bug 1349490 - Part 4: Add "extensions.formautofill.heuristics.enabled" for toggling form autofill heuristics.; r=MattN
authorSean Lee <selee@mozilla.com>
Mon, 29 May 2017 10:51:57 +0800
changeset 409537 c76be60a7965a9f64a4fa648ba1f55764f5fc034
parent 409536 7e3416b4e5fbe92c7afeadf70df91e28ac068c66
child 409538 f1ce296961be3af8cb44f542cbbab7835acce9e4
push id7391
push usermtabara@mozilla.com
push dateMon, 12 Jun 2017 13:08:53 +0000
treeherdermozilla-beta@2191d7f87e2e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersMattN
bugs1349490
milestone55.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1349490 - Part 4: Add "extensions.formautofill.heuristics.enabled" for toggling form autofill heuristics.; r=MattN MozReview-Commit-ID: Le3o7f7AXKn
browser/app/profile/firefox.js
browser/extensions/formautofill/FormAutofillHeuristics.jsm
browser/extensions/formautofill/test/unit/head.js
--- a/browser/app/profile/firefox.js
+++ b/browser/app/profile/firefox.js
@@ -1646,16 +1646,17 @@ pref("browser.crashReports.unsubmittedCh
 
 // Preferences for the form autofill system extension
 #ifdef NIGHTLY_BUILD
 pref("extensions.formautofill.experimental", true);
 #else
 pref("extensions.formautofill.experimental", false);
 #endif
 pref("extensions.formautofill.addresses.enabled", true);
+pref("extensions.formautofill.heuristics.enabled", false);
 pref("extensions.formautofill.loglevel", "Warn");
 
 // Whether or not to restore a session with lazy-browser tabs.
 pref("browser.sessionstore.restore_tabs_lazily", true);
 
 // Enable safebrowsing v4 tables (suffixed by "-proto") update.
 #ifdef NIGHTLY_BUILD
 pref("urlclassifier.malwareTable", "goog-malware-shavar,goog-unwanted-shavar,goog-malware-proto,goog-unwanted-proto,test-malware-simple,test-unwanted-simple");
--- a/browser/extensions/formautofill/FormAutofillHeuristics.jsm
+++ b/browser/extensions/formautofill/FormAutofillHeuristics.jsm
@@ -7,22 +7,25 @@
  */
 
 "use strict";
 
 this.EXPORTED_SYMBOLS = ["FormAutofillHeuristics"];
 
 const {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components;
 
+Cu.import("resource://gre/modules/Services.jsm");
 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
 Cu.import("resource://formautofill/FormAutofillUtils.jsm");
 
 this.log = null;
 FormAutofillUtils.defineLazyLogGetter(this, this.EXPORTED_SYMBOLS[0]);
 
+const PREF_HEURISTICS_ENABLED = "extensions.formautofill.heuristics.enabled";
+
 /**
  * Returns the autocomplete information of fields according to heuristics.
  */
 this.FormAutofillHeuristics = {
   FIELD_GROUPS: {
     NAME: [
       "name",
       "given-name",
@@ -142,16 +145,20 @@ this.FormAutofillHeuristics = {
 
     let info = element.getAutocompleteInfo();
     // An input[autocomplete="on"] will not be early return here since it stll
     // needs to find the field name.
     if (info && info.fieldName && info.fieldName != "on") {
       return info;
     }
 
+    if (!this._prefEnabled) {
+      return null;
+    }
+
     // "email" type of input is accurate for heuristics to determine its Email
     // field or not. However, "tel" type is used for ZIP code for some web site
     // (e.g. HomeDepot, BestBuy), so "tel" type should be not used for "tel"
     // prediction.
     if (element.type == "email") {
       return {
         fieldName: "email",
         section: "",
@@ -193,8 +200,16 @@ XPCOMUtils.defineLazyGetter(this.FormAut
   let sandbox = {};
   let scriptLoader = Cc["@mozilla.org/moz/jssubscript-loader;1"]
                        .getService(Ci.mozIJSSubScriptLoader);
   const HEURISTICS_REGEXP = "chrome://formautofill/content/heuristicsRegexp.js";
   scriptLoader.loadSubScript(HEURISTICS_REGEXP, sandbox, "utf-8");
   return sandbox.HeuristicsRegExp.RULES;
 });
 
+XPCOMUtils.defineLazyGetter(this.FormAutofillHeuristics, "_prefEnabled", () => {
+  return Services.prefs.getBoolPref(PREF_HEURISTICS_ENABLED);
+});
+
+Services.prefs.addObserver(PREF_HEURISTICS_ENABLED, () => {
+  this.FormAutofillHeuristics._prefEnabled = Services.prefs.getBoolPref(PREF_HEURISTICS_ENABLED);
+});
+
--- a/browser/extensions/formautofill/test/unit/head.js
+++ b/browser/extensions/formautofill/test/unit/head.js
@@ -115,14 +115,16 @@ function runHeuristicsTest(patterns, fix
         });
       });
     });
   });
 }
 
 add_task(function* head_initialize() {
   Services.prefs.setBoolPref("extensions.formautofill.experimental", true);
+  Services.prefs.setBoolPref("extensions.formautofill.heuristics.enabled", true);
 
   // Clean up after every test.
   do_register_cleanup(function head_cleanup() {
     Services.prefs.clearUserPref("extensions.formautofill.experimental");
+    Services.prefs.clearUserPref("extensions.formautofill.heuristics.enabled");
   });
 });