Bug 1482070 - Move ContentProcessListener to its own file. r=Honza
authorAlexandre Poirot <poirot.alex@gmail.com>
Tue, 14 Aug 2018 08:11:57 -0700
changeset 432398 5b6d222516808471f3e435b151f29dd51b587a19
parent 432397 e6cb4956e53f6b9bc7c2e70ff7a5d3f44065c66d
child 432399 f269b019428d8d9e2984c8345d3fd9e40d013b8d
push id106726
push userapoirot@mozilla.com
push dateMon, 20 Aug 2018 16:07:22 +0000
treeherdermozilla-inbound@68bff34cbddd [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersHonza
bugs1482070
milestone63.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1482070 - Move ContentProcessListener to its own file. r=Honza Summary: Depends On D3600 Reviewers: Honza! Tags: #secure-revision Bug #: 1482070 Differential Revision: https://phabricator.services.mozilla.com/D3601 MozReview-Commit-ID: CHReMMFXFHT
devtools/server/actors/webconsole.js
devtools/server/actors/webconsole/listeners.js
devtools/server/actors/webconsole/listeners/content-process.js
devtools/server/actors/webconsole/listeners/moz.build
--- a/devtools/server/actors/webconsole.js
+++ b/devtools/server/actors/webconsole.js
@@ -40,17 +40,17 @@ loader.lazyRequireGetter(this, "EventEmi
 // to load an unsupported module.
 if (isWorker) {
   loader.lazyRequireGetter(this, "ConsoleAPIListener", "devtools/server/actors/webconsole/worker-listeners", true);
   loader.lazyRequireGetter(this, "ConsoleServiceListener", "devtools/server/actors/webconsole/worker-listeners", true);
 } else {
   loader.lazyRequireGetter(this, "ConsoleAPIListener", "devtools/server/actors/webconsole/listeners/console-api", true);
   loader.lazyRequireGetter(this, "ConsoleServiceListener", "devtools/server/actors/webconsole/listeners/console-service", true);
   loader.lazyRequireGetter(this, "ConsoleReflowListener", "devtools/server/actors/webconsole/listeners/console-reflow", true);
-  loader.lazyRequireGetter(this, "ContentProcessListener", "devtools/server/actors/webconsole/listeners", true);
+  loader.lazyRequireGetter(this, "ContentProcessListener", "devtools/server/actors/webconsole/listeners/content-process", true);
   loader.lazyRequireGetter(this, "DocumentEventsListener", "devtools/server/actors/webconsole/listeners", true);
 }
 
 function isObject(value) {
   return Object(value) === value;
 }
 
 /**
--- a/devtools/server/actors/webconsole/listeners.js
+++ b/devtools/server/actors/webconsole/listeners.js
@@ -7,56 +7,16 @@
 const {Cc, Ci, components} = require("chrome");
 const {isWindowIncluded} = require("devtools/shared/layout/utils");
 const Services = require("Services");
 const ChromeUtils = require("ChromeUtils");
 const {CONSOLE_WORKER_IDS, WebConsoleUtils} = require("devtools/server/actors/webconsole/utils");
 
 loader.lazyRequireGetter(this, "EventEmitter", "devtools/shared/event-emitter");
 
-// Process script used to forward console calls from content processes to parent process
-const CONTENT_PROCESS_SCRIPT = "resource://devtools/server/actors/webconsole/content-process-forward.js";
-
-
-/**
- * Forward console message calls from content processes to the parent process.
- * Used by Browser console and toolbox to see messages from all processes.
- *
- * @constructor
- * @param object owner
- *        The listener owner which needs to implement:
- *        - onConsoleAPICall(message)
- */
-function ContentProcessListener(listener) {
-  this.listener = listener;
-
-  Services.ppmm.addMessageListener("Console:Log", this);
-  Services.ppmm.loadProcessScript(CONTENT_PROCESS_SCRIPT, true);
-}
-
-exports.ContentProcessListener = ContentProcessListener;
-
-ContentProcessListener.prototype = {
-  receiveMessage(message) {
-    const logMsg = message.data;
-    logMsg.wrappedJSObject = logMsg;
-    this.listener.onConsoleAPICall(logMsg);
-  },
-
-  destroy() {
-    // Tell the content processes to stop listening and forwarding messages
-    Services.ppmm.broadcastAsyncMessage("DevTools:StopForwardingContentProcessMessage");
-
-    Services.ppmm.removeMessageListener("Console:Log", this);
-    Services.ppmm.removeDelayedProcessScript(CONTENT_PROCESS_SCRIPT);
-
-    this.listener = null;
-  }
-};
-
 /**
  * Forward `DOMContentLoaded` and `load` events with precise timing
  * of when events happened according to window.performance numbers.
  *
  * @constructor
  * @param object console
  *        The web console actor.
  */
copy from devtools/server/actors/webconsole/listeners.js
copy to devtools/server/actors/webconsole/listeners/content-process.js
--- a/devtools/server/actors/webconsole/listeners.js
+++ b/devtools/server/actors/webconsole/listeners/content-process.js
@@ -1,26 +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/. */
 
 "use strict";
 
-const {Cc, Ci, components} = require("chrome");
-const {isWindowIncluded} = require("devtools/shared/layout/utils");
 const Services = require("Services");
-const ChromeUtils = require("ChromeUtils");
-const {CONSOLE_WORKER_IDS, WebConsoleUtils} = require("devtools/server/actors/webconsole/utils");
-
-loader.lazyRequireGetter(this, "EventEmitter", "devtools/shared/event-emitter");
 
 // Process script used to forward console calls from content processes to parent process
 const CONTENT_PROCESS_SCRIPT = "resource://devtools/server/actors/webconsole/content-process-forward.js";
 
-
 /**
  * Forward console message calls from content processes to the parent process.
  * Used by Browser console and toolbox to see messages from all processes.
  *
  * @constructor
  * @param object owner
  *        The listener owner which needs to implement:
  *        - onConsoleAPICall(message)
@@ -46,88 +39,8 @@ ContentProcessListener.prototype = {
     Services.ppmm.broadcastAsyncMessage("DevTools:StopForwardingContentProcessMessage");
 
     Services.ppmm.removeMessageListener("Console:Log", this);
     Services.ppmm.removeDelayedProcessScript(CONTENT_PROCESS_SCRIPT);
 
     this.listener = null;
   }
 };
-
-/**
- * Forward `DOMContentLoaded` and `load` events with precise timing
- * of when events happened according to window.performance numbers.
- *
- * @constructor
- * @param object console
- *        The web console actor.
- */
-function DocumentEventsListener(console) {
-  this.console = console;
-
-  this.onWindowReady = this.onWindowReady.bind(this);
-  this.onContentLoaded = this.onContentLoaded.bind(this);
-  this.onLoad = this.onLoad.bind(this);
-  this.listen();
-}
-
-exports.DocumentEventsListener = DocumentEventsListener;
-
-DocumentEventsListener.prototype = {
-  listen() {
-    EventEmitter.on(this.console.parentActor, "window-ready", this.onWindowReady);
-    this.onWindowReady({ window: this.console.window, isTopLevel: true });
-  },
-
-  onWindowReady({ window, isTopLevel }) {
-    // Ignore iframes
-    if (!isTopLevel) {
-      return;
-    }
-
-    const { readyState } = window.document;
-    if (readyState != "interactive" && readyState != "complete") {
-      window.addEventListener("DOMContentLoaded", this.onContentLoaded, { once: true });
-    } else {
-      this.onContentLoaded({ target: window.document });
-    }
-    if (readyState != "complete") {
-      window.addEventListener("load", this.onLoad, { once: true });
-    } else {
-      this.onLoad({ target: window.document });
-    }
-  },
-
-  onContentLoaded(event) {
-    const window = event.target.defaultView;
-    const packet = {
-      from: this.console.actorID,
-      type: "documentEvent",
-      name: "dom-interactive",
-      // milliseconds since the UNIX epoch, when the parser finished its work
-      // on the main document, that is when its Document.readyState changes to
-      // 'interactive' and the corresponding readystatechange event is thrown
-      time: window.performance.timing.domInteractive
-    };
-    this.console.conn.send(packet);
-  },
-
-  onLoad(event) {
-    const window = event.target.defaultView;
-    const packet = {
-      from: this.console.actorID,
-      type: "documentEvent",
-      name: "dom-complete",
-      // milliseconds since the UNIX epoch, when the parser finished its work
-      // on the main document, that is when its Document.readyState changes to
-      // 'complete' and the corresponding readystatechange event is thrown
-      time: window.performance.timing.domComplete
-    };
-    this.console.conn.send(packet);
-  },
-
-  destroy() {
-    EventEmitter.off(this.console.parentActor, "window-ready", this.onWindowReady);
-
-    this.listener = null;
-  }
-};
-
--- a/devtools/server/actors/webconsole/listeners/moz.build
+++ b/devtools/server/actors/webconsole/listeners/moz.build
@@ -4,9 +4,10 @@
 # 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/.
 
 DevToolsModules(
     'console-api.js',
     'console-progress.js',
     'console-reflow.js',
     'console-service.js',
+    'content-process.js',
 )