Bug 1385196 - [Form Autofill] Enable the feature based on locale and geoip. r=MattN draft
authorLuke Chang <lchang@mozilla.com>
Thu, 10 Aug 2017 21:36:34 -0700
changeset 644597 3fa5a79f02608153e6301f74433b2647b6a0c478
parent 644586 4d06c9ab80f57e545f9c45fca7f9a7306a2a1586
child 644598 bca338ef318a61e9a786df7895eaf1e7db7539c5
push id73484
push usermozilla@noorenberghe.ca
push dateFri, 11 Aug 2017 06:09:41 +0000
reviewersMattN
bugs1385196
milestone57.0a1
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 {