Commit 7d469598 authored by Tim Giles's avatar Tim Giles
Browse files

Bug 1745248 - Allow each autofill feature to detect if it should be enabled...

Bug 1745248 - Allow each autofill feature to detect if it should be enabled depending on search region. r=dimi,sgalich,preferences-reviewers,skhamis,LougeniaBailey

Differential Revision: https://phabricator.services.mozilla.com/D133818
parent 875c8197
Loading
Loading
Loading
Loading
+11 −3
Original line number Diff line number Diff line
@@ -25,9 +25,17 @@ add_task(async function test_openPreferences_spotlight() {
  ]) {
    if (
      arg == "privacy-credit-card-autofill" &&
      !Services.prefs.getBoolPref(
        "extensions.formautofill.creditCards.available"
      )
      Services.prefs.getCharPref(
        "extensions.formautofill.creditCards.supported"
      ) == "off"
    ) {
      continue;
    }
    if (
      arg == "privacy-address-autofill" &&
      Services.prefs.getCharPref(
        "extensions.formautofill.addresses.supported"
      ) == "off"
    ) {
      continue;
    }
+62 −56
Original line number Diff line number Diff line
@@ -72,29 +72,62 @@ function ensureCssLoaded(domWindow) {
  );
}

function isAvailable() {
  let availablePref = Services.prefs.getCharPref(
    "extensions.formautofill.available"
  );
  if (availablePref == "on") {
    return true;
  } else if (availablePref == "detect") {
    let region = Services.prefs.getCharPref("browser.search.region", "");
    let supportedCountries = Services.prefs
      .getCharPref("extensions.formautofill.supportedCountries")
      .split(",");
    if (
      !Services.prefs.getBoolPref("extensions.formautofill.supportRTL") &&
      Services.locale.isAppLocaleRTL
this.formautofill = class extends ExtensionAPI {
  /**
   * Adjusts and checks form autofill preferences during startup.
   *
   * @param {boolean} addressAutofillAvailable
   * @param {boolean} creditCardAutofillAvailable
   */
  adjustAndCheckFormAutofillPrefs(
    addressAutofillAvailable,
    creditCardAutofillAvailable
  ) {
      return false;
    // Reset the sync prefs in case the features were previously available
    // but aren't now.
    if (!creditCardAutofillAvailable) {
      Services.prefs.clearUserPref(
        "services.sync.engine.creditcards.available"
      );
    }
    return supportedCountries.includes(region);
    if (!addressAutofillAvailable) {
      Services.prefs.clearUserPref("services.sync.engine.addresses.available");
    }
  return false;

    if (!addressAutofillAvailable && !creditCardAutofillAvailable) {
      Services.prefs.clearUserPref("dom.forms.autocomplete.formautofill");
      Services.telemetry.scalarSet("formautofill.availability", false);
      return;
    }

this.formautofill = class extends ExtensionAPI {
    // This pref is used for web contents to detect the autocomplete feature.
    // When it's true, "element.autocomplete" will return tokens we currently
    // support -- otherwise it'll return an empty string.
    Services.prefs.setBoolPref("dom.forms.autocomplete.formautofill", true);
    Services.telemetry.scalarSet("formautofill.availability", true);

    // These "*.available" prefs determines whether the "addresses"/"creditcards" sync engine is
    // available (ie, whether it is shown in any UI etc) - it *does not* determine
    // whether the engine is actually enabled or not.
    if (FormAutofill.isAutofillAddressesAvailable) {
      Services.prefs.setBoolPref(
        "services.sync.engine.addresses.available",
        true
      );
    } else {
      Services.prefs.clearUserPref("services.sync.engine.addresses.available");
    }
    if (FormAutofill.isAutofillCreditCardsAvailable) {
      Services.prefs.setBoolPref(
        "services.sync.engine.creditcards.available",
        true
      );
    } else {
      Services.prefs.clearUserPref(
        "services.sync.engine.creditcards.available"
      );
    }
  }
  onStartup() {
    // We have to do this before actually determining if we're enabled, since
    // there are scripts inside of the core browser code that depend on the
@@ -132,43 +165,16 @@ this.formautofill = class extends ExtensionAPI {
        "Cannot find formautofill chrome.manifest for registring translated strings"
      );
    }

    if (!isAvailable()) {
      Services.prefs.clearUserPref("dom.forms.autocomplete.formautofill");
      // reset the sync related prefs incase the feature was previously available
      // but isn't now.
      Services.prefs.clearUserPref("services.sync.engine.addresses.available");
      Services.prefs.clearUserPref(
        "services.sync.engine.creditcards.available"
    let addressAutofillAvailable = FormAutofill.isAutofillAddressesAvailable;
    let creditCardAutofillAvailable =
      FormAutofill.isAutofillCreditCardsAvailable;
    this.adjustAndCheckFormAutofillPrefs(
      addressAutofillAvailable,
      creditCardAutofillAvailable
    );
      Services.telemetry.scalarSet("formautofill.availability", false);
    if (!creditCardAutofillAvailable && !addressAutofillAvailable) {
      return;
    }

    // This pref is used for web contents to detect the autocomplete feature.
    // When it's true, "element.autocomplete" will return tokens we currently
    // support -- otherwise it'll return an empty string.
    Services.prefs.setBoolPref("dom.forms.autocomplete.formautofill", true);
    Services.telemetry.scalarSet("formautofill.availability", true);

    // This pref determines whether the "addresses"/"creditcards" sync engine is
    // available (ie, whether it is shown in any UI etc) - it *does not* determine
    // whether the engine is actually enabled or not.
    Services.prefs.setBoolPref(
      "services.sync.engine.addresses.available",
      true
    );
    if (FormAutofill.isAutofillCreditCardsAvailable) {
      Services.prefs.setBoolPref(
        "services.sync.engine.creditcards.available",
        true
      );
    } else {
      Services.prefs.clearUserPref(
        "services.sync.engine.creditcards.available"
      );
    }

    // Listen for the autocomplete popup message
    // or the form submitted message (which may trigger a
    // doorhanger) to lazily append our stylesheets related
+1 −1
Original line number Diff line number Diff line
[DEFAULT]
prefs =
  extensions.formautofill.creditCards.available=true
  extensions.formautofill.creditCards.supported=on
  extensions.formautofill.creditCards.enabled=true
  extensions.formautofill.reauth.enabled=true
support-files =
+8 −1
Original line number Diff line number Diff line
[DEFAULT]
prefs =
  extensions.formautofill.creditCards.new.available=on
  extensions.formautofill.creditCards.enabled=true
  extensions.formautofill.addresses.availability=on
  extensions.formautofill.addresses.enabled=true
skip-if = toolkit == 'android' # bug 1730213
support-files =
  ../../../../../toolkit/components/satchel/test/satchel_common.js
@@ -12,7 +17,9 @@ support-files =
[test_basic_autocomplete_form.html]
[test_form_changes.html]
[test_formautofill_preview_highlight.html]
skip-if = verify || (!debug && os == "mac") # perma-fail see Bug 1600059
skip-if = 
  verify 
  (!debug && os == "mac") # perma-fail see Bug 1600059
[test_multi_locale_CA_address_form.html]
[test_multiple_forms.html]
[test_on_address_submission.html]
+16 −1
Original line number Diff line number Diff line
@@ -314,13 +314,28 @@ add_task(async function head_initialize() {
  Services.prefs.setBoolPref("extensions.formautofill.section.enabled", true);
  Services.prefs.setBoolPref("dom.forms.autocomplete.formautofill", true);

  Services.prefs.setCharPref(
    "extensions.formautofill.addresses.supported",
    "on"
  );
  Services.prefs.setCharPref(
    "extensions.formautofill.creditCards.supported",
    "on"
  );
  Services.prefs.setBoolPref("extensions.formautofill.addresses.enabled", true);
  Services.prefs.setBoolPref(
    "extensions.formautofill.creditCards.enabled",
    true
  );

  // Clean up after every test.
  registerCleanupFunction(function head_cleanup() {
    Services.prefs.clearUserPref("extensions.formautofill.available");
    Services.prefs.clearUserPref("extensions.experiments.enabled");
    Services.prefs.clearUserPref(
      "extensions.formautofill.creditCards.available"
      "extensions.formautofill.creditCards.supported"
    );
    Services.prefs.clearUserPref("extensions.formautofill.addresses.supported");
    Services.prefs.clearUserPref("extensions.formautofill.creditCards.enabled");
    Services.prefs.clearUserPref("extensions.formautofill.heuristics.enabled");
    Services.prefs.clearUserPref("extensions.formautofill.section.enabled");
Loading