Bug 1433876 - Wrap earlyformsubmit observer in try…catch to ensure autofill never stops form submission. r=johannh draft
authorMatthew Noorenberghe <mozilla@noorenberghe.ca>
Wed, 07 Feb 2018 22:26:15 -0800
changeset 786349 c8bc120e9aac1abd5fb8e83266e7bd0368292c77
parent 786348 fcdfda41a46fc13e18e7ecbf881ce8ddd1bb89eb
push id107436
push usermozilla@noorenberghe.ca
push dateSun, 22 Apr 2018 23:20:13 +0000
reviewersjohannh
bugs1433876
milestone61.0a1
Bug 1433876 - Wrap earlyformsubmit observer in try…catch to ensure autofill never stops form submission. r=johannh MozReview-Commit-ID: PO0p8wd9Jw
browser/extensions/formautofill/FormAutofillContent.jsm
--- a/browser/extensions/formautofill/FormAutofillContent.jsm
+++ b/browser/extensions/formautofill/FormAutofillContent.jsm
@@ -382,40 +382,44 @@ var FormAutofillContent = {
    * 2. Could not map any autofill handler by form element.
    * 3. Number of filled fields is less than autofill threshold
    *
    * @param {HTMLElement} formElement Root element which receives earlyformsubmit event.
    * @param {Object} domWin Content window
    * @returns {boolean} Should always return true so form submission isn't canceled.
    */
   notify(formElement, domWin) {
-    this.log.debug("Notifying form early submission");
+    try {
+      this.log.debug("Notifying form early submission");
 
-    if (!FormAutofillUtils.isAutofillEnabled) {
-      this.log.debug("Form Autofill is disabled");
-      return true;
-    }
+      if (!FormAutofillUtils.isAutofillEnabled) {
+        this.log.debug("Form Autofill is disabled");
+        return true;
+      }
 
-    if (domWin && PrivateBrowsingUtils.isContentWindowPrivate(domWin)) {
-      this.log.debug("Ignoring submission in a private window");
-      return true;
-    }
+      if (domWin && PrivateBrowsingUtils.isContentWindowPrivate(domWin)) {
+        this.log.debug("Ignoring submission in a private window");
+        return true;
+      }
 
-    let handler = this._formsDetails.get(formElement);
-    if (!handler) {
-      this.log.debug("Form element could not map to an existing handler");
-      return true;
-    }
+      let handler = this._formsDetails.get(formElement);
+      if (!handler) {
+        this.log.debug("Form element could not map to an existing handler");
+        return true;
+      }
 
-    let records = handler.createRecords();
-    if (!Object.values(records).some(typeRecords => typeRecords.length)) {
-      return true;
+      let records = handler.createRecords();
+      if (!Object.values(records).some(typeRecords => typeRecords.length)) {
+        return true;
+      }
+
+      this._onFormSubmit(records, domWin, handler.timeStartedFillingMS);
+    } catch (ex) {
+      Cu.reportError(ex);
     }
-
-    this._onFormSubmit(records, domWin, handler.timeStartedFillingMS);
     return true;
   },
 
   receiveMessage({name, data}) {
     switch (name) {
       case "FormAutofill:enabledStatus": {
         if (data) {
           ProfileAutocomplete.ensureRegistered();