Bug 1349490 - Part 4: Add "extensions.formautofill.heuristics.enabled" for toggling form autofill heuristics.; r?MattN
MozReview-Commit-ID: Le3o7f7AXKn
--- a/browser/app/profile/firefox.js
+++ b/browser/app/profile/firefox.js
@@ -1634,16 +1634,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");
});
});