Bug 1250473 - Convert formSubmitListener.js to a process script instead of a frame script; r=MattN
authorEhsan Akhgari <ehsan@mozilla.com>
Fri, 14 Apr 2017 19:32:47 -0400
changeset 563286 3d8a235f178992885fa6c8381f6804f05d007793
parent 563230 05f0e6fea003df5c3d81fd2254486394ef327cf7
child 563287 fd4b315d43b9de9f9b4faa75867862978fd93ac9
push id54258
push usercpeterson@mozilla.com
push dateSun, 16 Apr 2017 05:52:14 +0000
reviewersMattN
bugs1250473
milestone55.0a1
Bug 1250473 - Convert formSubmitListener.js to a process script instead of a frame script; r=MattN This saves the cost of loading this script once per frame.
toolkit/components/satchel/FormHistoryStartup.js
toolkit/components/satchel/formSubmitListener.js
--- a/toolkit/components/satchel/FormHistoryStartup.js
+++ b/toolkit/components/satchel/FormHistoryStartup.js
@@ -50,21 +50,21 @@ FormHistoryStartup.prototype = {
     this.inited = true;
 
     Services.prefs.addObserver("browser.formfill.", this, true);
 
     // triggers needed service cleanup and db shutdown
     Services.obs.addObserver(this, "profile-before-change", true);
     Services.obs.addObserver(this, "formhistory-expire-now", true);
 
+    Services.ppmm.loadProcessScript("chrome://satchel/content/formSubmitListener.js", true);
+    Services.ppmm.addMessageListener("FormHistory:FormSubmitEntries", this);
+
     let messageManager = Cc["@mozilla.org/globalmessagemanager;1"].
                          getService(Ci.nsIMessageListenerManager);
-    messageManager.loadFrameScript("chrome://satchel/content/formSubmitListener.js", true);
-    messageManager.addMessageListener("FormHistory:FormSubmitEntries", this);
-
     // For each of these messages, we could receive them from content,
     // or we might receive them from the ppmm if the searchbar is
     // having its history queried.
     for (let manager of [messageManager, Services.ppmm]) {
       manager.addMessageListener("FormHistory:AutoCompleteSearchAsync", this);
       manager.addMessageListener("FormHistory:RemoveEntry", this);
     }
   },
--- a/toolkit/components/satchel/formSubmitListener.js
+++ b/toolkit/components/satchel/formSubmitListener.js
@@ -10,29 +10,28 @@ var Cc = Components.classes;
 var Ci = Components.interfaces;
 
 Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
 Components.utils.import("resource://gre/modules/Services.jsm");
 Components.utils.import("resource://gre/modules/PrivateBrowsingUtils.jsm");
 
 var satchelFormListener = {
     QueryInterface: XPCOMUtils.generateQI([Ci.nsIFormSubmitObserver,
-                                            Ci.nsIDOMEventListener,
-                                            Ci.nsIObserver,
-                                            Ci.nsISupportsWeakReference]),
+                                           Ci.nsIObserver,
+                                           Ci.nsISupportsWeakReference]),
 
     debug: true,
     enabled: true,
     saveHttpsForms: true,
 
     init() {
         Services.obs.addObserver(this, "earlyformsubmit");
+        Services.obs.addObserver(this, "xpcom-shutdown");
         Services.prefs.addObserver("browser.formfill.", this);
         this.updatePrefs();
-        addEventListener("unload", this, false);
     },
 
     updatePrefs() {
         this.debug          = Services.prefs.getBoolPref("browser.formfill.debug");
         this.enabled        = Services.prefs.getBoolPref("browser.formfill.enable");
         this.saveHttpsForms = Services.prefs.getBoolPref("browser.formfill.saveHttpsForms");
     },
 
@@ -65,49 +64,34 @@ var satchelFormListener = {
 
     log(message) {
         if (!this.debug)
             return;
         dump("satchelFormListener: " + message + "\n");
         Services.console.logStringMessage("satchelFormListener: " + message);
     },
 
-    /* ---- dom event handler ---- */
-
-    handleEvent(e) {
-        switch (e.type) {
-            case "unload":
-                Services.obs.removeObserver(this, "earlyformsubmit");
-                Services.prefs.removeObserver("browser.formfill.", this);
-                break;
-
-            default:
-                this.log("Oops! Unexpected event: " + e.type);
-                break;
-        }
-    },
-
     /* ---- nsIObserver interface ---- */
 
     observe(subject, topic, data) {
-        if (topic == "nsPref:changed")
+        if (topic == "nsPref:changed") {
             this.updatePrefs();
-        else
+        } else if (topic == "xpcom-shutdown") {
+            Services.obs.removeObserver(this, "earlyformsubmit");
+            Services.obs.removeObserver(this, "xpcom-shutdown");
+            Services.prefs.removeObserver("browser.formfill.", this);
+        } else {
             this.log("Oops! Unexpected notification: " + topic);
+        }
     },
 
     /* ---- nsIFormSubmitObserver interfaces ---- */
 
     notify(form, domWin, actionURI, cancelSubmit) {
         try {
-            // Even though the global context is for a specific browser, we
-            // can receive observer events from other tabs! Ensure this event
-            // is about our content.
-            if (domWin.top != content)
-                return;
             if (!this.enabled)
                 return;
 
             if (PrivateBrowsingUtils.isContentWindowPrivate(domWin))
                 return;
 
             this.log("Form submit observer notified.");