Bug 1322622 - Make form autofill handler a frame script and load from bootstrap.js. r=steveck draft
authorMatthew Noorenberghe <mozilla@noorenberghe.ca>
Fri, 16 Dec 2016 01:26:46 -0500
changeset 450222 5e62eb24e76bf58436e73267ebb8e872e42a71d2
parent 450221 87e6bee2cb6207138400e2f92f9cf8245394cbb4
child 539701 3a1ad7e572549c93e017a60933816597bb31fa4d
push id38797
push usermozilla@noorenberghe.ca
push dateFri, 16 Dec 2016 06:27:16 +0000
reviewerssteveck
bugs1322622
milestone53.0a1
Bug 1322622 - Make form autofill handler a frame script and load from bootstrap.js. r=steveck MozReview-Commit-ID: DeIjzMytVxJ
browser/app/profile/firefox.js
browser/extensions/formautofill/FormAutofillContent.jsm
browser/extensions/formautofill/bootstrap.js
browser/extensions/formautofill/content/FormAutofillContent.js
browser/extensions/formautofill/jar.mn
browser/extensions/formautofill/test/unit/head.js
browser/extensions/formautofill/test/unit/tail.js
browser/extensions/formautofill/test/unit/test_autofillFormFields.js
browser/extensions/formautofill/test/unit/test_collectFormFields.js
browser/extensions/formautofill/test/unit/xpcshell.ini
--- a/browser/app/profile/firefox.js
+++ b/browser/app/profile/firefox.js
@@ -1548,8 +1548,11 @@ pref("browser.crashReports.unsubmittedCh
 pref("browser.crashReports.unsubmittedCheck.chancesUntilSuppress", 4);
 pref("browser.crashReports.unsubmittedCheck.autoSubmit", false);
 
 #ifdef NIGHTLY_BUILD
 // Enable the (fairly costly) client/server validation on nightly only. The other prefs
 // controlling validation are located in /services/sync/services-sync.js
 pref("services.sync.validation.enabled", true);
 #endif
+
+// Preferences for the form autofill system extension
+pref("browser.formautofill.enabled", false);
--- a/browser/extensions/formautofill/bootstrap.js
+++ b/browser/extensions/formautofill/bootstrap.js
@@ -1,12 +1,30 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 "use strict";
 
 /* exported startup, shutdown, install, uninstall */
 
-function startup() {}
+const {classes: Cc, interfaces: Ci, results: Cr, utils: Cu} = Components;
+
+Cu.import("resource://gre/modules/Services.jsm");
+Cu.import("resource://gre/modules/XPCOMUtils.jsm");
+
+XPCOMUtils.defineLazyModuleGetter(this, "FormAutofillParent",
+                                  "resource://formautofill/FormAutofillParent.jsm");
+
+function startup() {
+  // Besides this pref, we'll need dom.forms.autocomplete.experimental enabled
+  // as well to make sure form autocomplete works correctly.
+  if (!Services.prefs.getBoolPref("browser.formautofill.enabled")) {
+    return;
+  }
+
+  FormAutofillParent.init();
+  Services.mm.loadFrameScript("chrome://formautofill/content/FormAutofillContent.js", true);
+}
+
 function shutdown() {}
 function install() {}
 function uninstall() {}
rename from browser/extensions/formautofill/FormAutofillContent.jsm
rename to browser/extensions/formautofill/content/FormAutofillContent.js
--- a/browser/extensions/formautofill/FormAutofillContent.jsm
+++ b/browser/extensions/formautofill/content/FormAutofillContent.js
@@ -1,20 +1,21 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 /*
- * Implements a service used by DOM content to request Form Autofill.
+ * Form Autofill frame script.
  */
 
 "use strict";
 
 const {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components;
 
+
 /**
  * Handles profile autofill for a DOM Form element.
  * @param {HTMLFormElement} form Form that need to be auto filled
  */
 function FormAutofillHandler(form) {
   this.form = form;
   this.fieldDetails = [];
 }
@@ -125,10 +126,8 @@ FormAutofillHandler.prototype = {
         Cu.reportError("Autocomplete tokens mismatched");
         continue;
       }
 
       fieldDetail.element.setUserInput(field.value);
     }
   },
 };
-
-this.EXPORTED_SYMBOLS = ["FormAutofillHandler"];
--- a/browser/extensions/formautofill/jar.mn
+++ b/browser/extensions/formautofill/jar.mn
@@ -1,7 +1,10 @@
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 [features/formautofill@mozilla.org] chrome.jar:
 % resource formautofill %res/
   res/ (*.jsm)
+
+% content formautofill %content/
+  content/ (content/*)
--- a/browser/extensions/formautofill/test/unit/head.js
+++ b/browser/extensions/formautofill/test/unit/head.js
@@ -1,13 +1,13 @@
 /**
  * Provides infrastructure for automated formautofill components tests.
  */
 
-/* exported importAutofillModule, getTempFile */
+/* exported getTempFile */
 
 "use strict";
 
 const {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components;
 
 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
 Cu.import("resource://gre/modules/Services.jsm");
 Cu.import("resource://gre/modules/NetUtil.jsm");
@@ -32,16 +32,27 @@ if (!extensionDir.exists()) {
 Components.manager.addBootstrappedManifestLocation(extensionDir);
 
 // While the previous test file should have deleted all the temporary files it
 // used, on Windows these might still be pending deletion on the physical file
 // system.  Thus, start from a new base number every time, to make a collision
 // with a file that is still pending deletion highly unlikely.
 let gFileCounter = Math.floor(Math.random() * 1000000);
 
+function loadFormAutofillContent() {
+  let facGlobal = {};
+  let loader = Cc["@mozilla.org/moz/jssubscript-loader;1"]
+               .getService(Ci.mozIJSSubScriptLoader);
+  loader.loadSubScriptWithOptions("chrome://formautofill/content/FormAutofillContent.js", {
+    target: facGlobal,
+  });
+
+  return facGlobal;
+}
+
 /**
  * Returns a reference to a temporary file, that is guaranteed not to exist, and
  * to have never been created before.
  *
  * @param {string} leafName
  *        Suggested leaf name for the file to be created.
  *
  * @returns {nsIFile} pointing to a non-existent file in a temporary directory.
@@ -66,15 +77,18 @@ function getTempFile(leafName) {
       file.remove(false);
     }
   });
 
   return file;
 }
 
 add_task(function* test_common_initialize() {
+  Services.prefs.setBoolPref("browser.formautofill.enabled", true);
   Services.prefs.setBoolPref("dom.forms.autocomplete.experimental", true);
+  loadFormAutofillContent();
 
   // Clean up after every test.
   do_register_cleanup(() => {
-    Services.prefs.setBoolPref("dom.forms.autocomplete.experimental", false);
+    Services.prefs.clearUserPref("browser.formautofill.enabled");
+    Services.prefs.clearUserPref("dom.forms.autocomplete.experimental");
   });
 });
deleted file mode 100644
--- a/browser/extensions/formautofill/test/unit/tail.js
+++ /dev/null
@@ -1,5 +0,0 @@
-/**
- * Cleans up the testing environment.
- */
-
-"use strict";
--- a/browser/extensions/formautofill/test/unit/test_autofillFormFields.js
+++ b/browser/extensions/formautofill/test/unit/test_autofillFormFields.js
@@ -1,15 +1,15 @@
 /*
  * Test for form auto fill content helper fill all inputs function.
  */
 
 "use strict";
 
-let {FormAutofillHandler} = Cu.import("resource://formautofill/FormAutofillContent.jsm");
+let {FormAutofillHandler} = loadFormAutofillContent();
 
 const TESTCASES = [
   {
     description: "Form without autocomplete property",
     document: `<form><input id="given-name"><input id="family-name">
                <input id="street-addr"><input id="city"><input id="country">
                <input id='email'><input id="tel"></form>`,
     fieldDetails: [],
--- a/browser/extensions/formautofill/test/unit/test_collectFormFields.js
+++ b/browser/extensions/formautofill/test/unit/test_collectFormFields.js
@@ -1,15 +1,15 @@
 /*
  * Test for form auto fill content helper collectFormFields functions.
  */
 
 "use strict";
 
-let {FormAutofillHandler} = Cu.import("resource://formautofill/FormAutofillContent.jsm");
+let {FormAutofillHandler} = loadFormAutofillContent();
 
 const TESTCASES = [
   {
     description: "Form without autocomplete property",
     document: `<form><input id="given-name"><input id="family-name">
                <input id="street-addr"><input id="city"><input id="country">
                <input id='email'><input id="tel"></form>`,
     returnedFormat: [],
--- a/browser/extensions/formautofill/test/unit/xpcshell.ini
+++ b/browser/extensions/formautofill/test/unit/xpcshell.ini
@@ -1,10 +1,10 @@
 [DEFAULT]
 firefox-appdir = browser
 head = head.js
-tail = tail.js
+tail =
 support-files =
 
 [test_autofillFormFields.js]
 [test_collectFormFields.js]
 [test_populateFieldValues.js]
 [test_profileStorage.js]