Bug 1416066 - Add page-content-fully-loaded notification to process-content.js. draft
authorimjching <jlim@mozilla.com>
Fri, 22 Jun 2018 17:12:02 -0400
changeset 810241 bc9614e645c2f791b061329d3eb1b706a4fecc56
parent 810240 abfb687941462e3eaf38e6698b1098dd993ba491
child 810242 c9770752d4bdd5cf25edc8a5a995ac22f4d5e54b
push id113933
push userbmo:jlim@mozilla.com
push dateMon, 25 Jun 2018 15:36:29 +0000
bugs1416066
milestone62.0a1
Bug 1416066 - Add page-content-fully-loaded notification to process-content.js. MozReview-Commit-ID: 3xfh5SRjvkA
toolkit/content/process-content.js
--- a/toolkit/content/process-content.js
+++ b/toolkit/content/process-content.js
@@ -17,16 +17,17 @@ Services.cpmm.addMessageListener("gmp-pl
                      .getService(Ci.mozIGeckoMediaPluginService);
 
   gmpservice.RunPluginCrashCallbacks(msg.data.pluginID, msg.data.pluginName);
 });
 
 if (gInContentProcess) {
   let ProcessObserver = {
     TOPICS: [
+      "content-document-global-created",
       "inner-window-destroyed",
       "xpcom-shutdown",
     ],
 
     init() {
       for (let topic of this.TOPICS) {
         Services.obs.addObserver(this, topic);
         Services.cpmm.addMessageListener("Memory:GetSummary", this);
@@ -57,16 +58,26 @@ if (gInContentProcess) {
           rss,
           ghosts,
         }
       });
     },
 
     observe(subject, topic, data) {
       switch (topic) {
+        case "content-document-global-created": {
+          let loadListener = () => {
+            subject.removeEventListener("load", loadListener);
+            if (subject.document.location.pathname !== "blank") {
+              Services.obs.notifyObservers(subject, "page-content-fully-loaded");
+            }
+          };
+          subject.addEventListener("load", loadListener);
+          break;
+        }
         case "inner-window-destroyed": {
           // Forward inner-window-destroyed notifications with the
           // inner window ID, so that code in the parent that should
           // do something when content windows go away can do it
           let innerWindowID =
             subject.QueryInterface(Ci.nsISupportsPRUint64).data;
           Services.cpmm.sendAsyncMessage("Toolkit:inner-window-destroyed",
                                          innerWindowID);