diff --git a/browser/extensions/formautofill/FormAutofillContent.jsm b/browser/extensions/formautofill/FormAutofillContent.jsm index f5ea0cce7a55..740b8906a5b9 100644 --- a/browser/extensions/formautofill/FormAutofillContent.jsm +++ b/browser/extensions/formautofill/FormAutofillContent.jsm @@ -587,14 +587,8 @@ var FormAutofillContent = { this._activeItems = {}; return; } - let handler = this._getFormHandler(element); - if (handler) { - handler.focusedInput = element; - } this._activeItems = { - handler, elementWeakRef: Cu.getWeakReference(element), - section: handler ? handler.activeSection : null, fieldDetail: null, }; }, @@ -605,11 +599,25 @@ var FormAutofillContent = { }, get activeHandler() { - return this._activeItems.handler; + const activeInput = this.activeInput; + if (!activeInput) { + return null; + } + + // XXX: We are recomputing the activeHandler every time to avoid keeping a + // reference on the active element. This might be called quite frequently + // so if _getFormHandler/findRootForField become more costly, we should + // look into caching this result (eg by adding a weakmap). + let handler = this._getFormHandler(activeInput); + if (handler) { + handler.focusedInput = activeInput; + } + return handler; }, get activeSection() { - return this._activeItems.section; + let formHandler = this.activeHandler; + return formHandler ? formHandler.activeSection : null; }, /** diff --git a/browser/extensions/formautofill/content/FormAutofillFrameScript.js b/browser/extensions/formautofill/content/FormAutofillFrameScript.js index d37fd573365b..88fe15b5a65e 100644 --- a/browser/extensions/formautofill/content/FormAutofillFrameScript.js +++ b/browser/extensions/formautofill/content/FormAutofillFrameScript.js @@ -78,10 +78,6 @@ var FormAutofillFrameScript = { this.onFocusIn(evt); break; } - case "focusout": { - this.onFocusOut(); - break; - } case "DOMFormBeforeSubmit": { this.onDOMFormBeforeSubmit(evt); break; @@ -120,12 +116,6 @@ var FormAutofillFrameScript = { this._doIdentifyAutofillFields(); }, - onFocusOut() { - // Update active input on blur to release references on the previously - // focused element in FormAutofillContent. - FormAutofillContent.updateActiveInput(); - }, - /** * Handle the DOMFormBeforeSubmit event. * @param {Event} evt diff --git a/browser/extensions/formautofill/test/browser/focus-leak/browser_iframe_typecontent_input_focus.js b/browser/extensions/formautofill/test/browser/focus-leak/browser_iframe_typecontent_input_focus.js index 3091dc12566c..74b25994be62 100644 --- a/browser/extensions/formautofill/test/browser/focus-leak/browser_iframe_typecontent_input_focus.js +++ b/browser/extensions/formautofill/test/browser/focus-leak/browser_iframe_typecontent_input_focus.js @@ -50,6 +50,6 @@ add_task(async function() { "The .focusme input is the active element" ); - // Stop the test without blurring the input, the cleanup should still prevent - // leaks in the test. + info("Remove the focused input"); + focusMeInput.remove(); });