Bug 1461247 - Only load FormSubmitObserver.jsm when an invalidformsubmit notification happens. r=MattN draft
authorFelipe Gomes <felipc@gmail.com>
Thu, 17 May 2018 16:44:50 -0300
changeset 796575 cf93406bba01a0485f4f42004708dc46893e254e
parent 796533 e50d0624898f05d43db6fe8010a5a181461d0152
child 796909 08bfd0fef79e6df26c8248a3d3816b3102896286
push id110281
push userfelipc@gmail.com
push dateThu, 17 May 2018 19:45:32 +0000
reviewersMattN
bugs1461247
milestone62.0a1
Bug 1461247 - Only load FormSubmitObserver.jsm when an invalidformsubmit notification happens. r=MattN MozReview-Commit-ID: C0qWX8imRQK
browser/base/content/content.js
browser/modules/FormSubmitObserver.jsm
--- a/browser/base/content/content.js
+++ b/browser/base/content/content.js
@@ -41,20 +41,24 @@ XPCOMUtils.defineLazyGetter(this, "gPipN
 XPCOMUtils.defineLazyGetter(this, "gNSSErrorsBundle", function() {
   return Services.strings.createBundle("chrome://pipnss/locale/nsserrors.properties");
 });
 
 XPCOMUtils.defineLazyProxy(this, "contextMenu", () => {
   return new ContextMenu(global);
 });
 
+XPCOMUtils.defineLazyProxy(this, "formSubmitObserver", () => {
+  return new FormSubmitObserver(content, this);
+}, { QueryInterface: ChromeUtils.generateQI([Ci.nsIFormSubmitObserver, Ci.nsISupportsWeakReference])});
+
+
 Services.els.addSystemEventListener(global, "contextmenu", contextMenu, false);
 
-// Load the form validation popup handler
-var formSubmitObserver = new FormSubmitObserver(content, this);
+Services.obs.addObserver(formSubmitObserver, "invalidformsubmit", true);
 
 addMessageListener("RemoteLogins:fillForm", function(message) {
   // intercept if ContextMenu.jsm had sent a plain object for remote targets
   message.objects.inputElement = contextMenu.getTarget(message, "inputElement");
   LoginManagerContent.receiveMessage(message, content);
 });
 addEventListener("DOMFormHasPassword", function(event) {
   LoginManagerContent.onDOMFormHasPassword(event, content);
--- a/browser/modules/FormSubmitObserver.jsm
+++ b/browser/modules/FormSubmitObserver.jsm
@@ -1,15 +1,19 @@
 /* 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/. */
 
 /*
  * Handles the validation callback from nsIFormFillController and
  * the display of the help panel on invalid elements.
+ *
+ * FormSubmitObserver implements the nsIFormSubmitObserver interface
+ * to get notifications about invalid forms. See HTMLFormElement
+ * for details.
  */
 
 "use strict";
 
 var EXPORTED_SYMBOLS = [ "FormSubmitObserver" ];
 
 ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
 ChromeUtils.import("resource://gre/modules/Services.jsm");
@@ -35,25 +39,21 @@ FormSubmitObserver.prototype =
     this._mm =
       this._content.QueryInterface(Ci.nsIInterfaceRequestor)
                    .getInterface(Ci.nsIDocShell)
                    .sameTypeRootTreeItem
                    .QueryInterface(Ci.nsIDocShell)
                    .QueryInterface(Ci.nsIInterfaceRequestor)
                    .getInterface(Ci.nsIContentFrameMessageManager);
 
-    // nsIFormSubmitObserver callback about invalid forms. See HTMLFormElement
-    // for details.
-    Services.obs.addObserver(this, "invalidformsubmit");
     this._tab.addEventListener("pageshow", this);
     this._tab.addEventListener("unload", this);
   },
 
   uninit() {
-    Services.obs.removeObserver(this, "invalidformsubmit");
     this._content.removeEventListener("pageshow", this);
     this._content.removeEventListener("unload", this);
     this._mm = null;
     this._element = null;
     this._content = null;
     this._tab = null;
   },
 
@@ -222,10 +222,10 @@ FormSubmitObserver.prototype =
     if (this._content == null) {
       return true;
     }
     let target = aEvent.originalTarget;
     return (target == this._content.document ||
             (target.ownerDocument && target.ownerDocument == this._content.document));
   },
 
-  QueryInterface: ChromeUtils.generateQI([Ci.nsIFormSubmitObserver])
+  QueryInterface: ChromeUtils.generateQI([Ci.nsIFormSubmitObserver, Ci.nsISupportsWeakReference])
 };