Bug 1385196 - [Form Autofill] Enable the feature based on locale and geoip. r=MattN
authorLuke Chang <lchang@mozilla.com>
Thu, 10 Aug 2017 21:36:34 -0700
changeset 421378 03cb4db8182b7db44601aac19c3803056e87ceab
parent 421377 f6117c7b1161fd89b055ce3cd34f41df610d1631
child 421379 df42573c68fd05d76d99c00e40839702d4754a8e
push id7664
push usermozilla@noorenberghe.ca
push dateThu, 24 Aug 2017 16:38:56 +0000
treeherdermozilla-beta@33a4e7ead964 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersMattN
bugs1385196
milestone56.0
Bug 1385196 - [Form Autofill] Enable the feature based on locale and geoip. r=MattN MozReview-Commit-ID: 3yvCJvB5zdT
browser/extensions/formautofill/bootstrap.js
--- a/browser/extensions/formautofill/bootstrap.js
+++ b/browser/extensions/formautofill/bootstrap.js
@@ -45,18 +45,30 @@ function onMaybeOpenPopup(evt) {
 
 function addUpgradeListener(instanceID) {
   AddonManager.addUpgradeListener(instanceID, upgrade => {
     // don't install the upgrade by doing nothing here.
     // The upgrade will be installed upon next restart.
   });
 }
 
+function isAvailable() {
+  let availablePref = Services.prefs.getCharPref("extensions.formautofill.available");
+  if (availablePref == "on") {
+    return true;
+  } else if (availablePref == "detect") {
+    let locale = Services.locale.getRequestedLocale();
+    let region = Services.prefs.getCharPref("browser.search.region", "");
+    return locale == "en-US" && region == "US";
+  }
+  return false;
+}
+
 function startup(data) {
-  if (Services.prefs.getStringPref("extensions.formautofill.available") != "on") {
+  if (!isAvailable()) {
     Services.prefs.clearUserPref("dom.forms.autocomplete.formautofill");
     return;
   }
 
   if (data.hasOwnProperty("instanceID") && data.instanceID) {
     if (AddonManagerPrivate.isDBLoaded()) {
       addUpgradeListener(data.instanceID);
     } else {