Bug 1482070 - Move StackTraceCollector to its own file. r=Honza
authorAlexandre Poirot <poirot.alex@gmail.com>
Tue, 14 Aug 2018 08:54:10 -0700
changeset 487541 e4b6ce31de8d57f7e772232bda29727e82ec6ea5
parent 487540 cc2fffaa4633bebab54f78e42277e8eeb23521c6
child 487542 6871a98b8b0b27c70848cbd3241db7272a1ee60b
push id9719
push userffxbld-merge
push dateFri, 24 Aug 2018 17:49:46 +0000
treeherdermozilla-beta@719ec98fba77 [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 StackTraceCollector to its own file. r=Honza Summary: Depends On D3603 Reviewers: Honza! Tags: #secure-revision Bug #: 1482070 Differential Revision: https://phabricator.services.mozilla.com/D3604 MozReview-Commit-ID: 53aaLHR6lv
devtools/server/actors/network-monitor/moz.build
devtools/server/actors/network-monitor/stack-trace-collector.js
devtools/server/actors/webconsole.js
devtools/shared/webconsole/network-monitor.js
--- a/devtools/server/actors/network-monitor/moz.build
+++ b/devtools/server/actors/network-monitor/moz.build
@@ -1,9 +1,10 @@
 # -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
 # vim: set filetype=python:
 # 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/.
 
 DevToolsModules(
     'channel-event-sink.js',
+    'stack-trace-collector.js',
 )
new file mode 100644
--- /dev/null
+++ b/devtools/server/actors/network-monitor/stack-trace-collector.js
@@ -0,0 +1,115 @@
+/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
+/* vim: set ft= javascript ts=2 et sw=2 tw=80: */
+/* 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 {Ci, components} = require("chrome");
+const Services = require("Services");
+
+loader.lazyRequireGetter(this, "ChannelEventSinkFactory",
+                         "devtools/server/actors/network-monitor/channel-event-sink",
+                         true);
+loader.lazyRequireGetter(this, "matchRequest",
+                         "devtools/server/actors/network-monitor/network-observer",
+                         true);
+
+function StackTraceCollector(filters, netmonitors) {
+  this.filters = filters;
+  this.stacktracesById = new Map();
+  this.netmonitors = netmonitors;
+}
+
+StackTraceCollector.prototype = {
+  init() {
+    Services.obs.addObserver(this, "http-on-opening-request");
+    ChannelEventSinkFactory.getService().registerCollector(this);
+    this.onGetStack = this.onGetStack.bind(this);
+    for (const { messageManager } of this.netmonitors) {
+      messageManager.addMessageListener("debug:request-stack", this.onGetStack);
+    }
+  },
+
+  destroy() {
+    Services.obs.removeObserver(this, "http-on-opening-request");
+    ChannelEventSinkFactory.getService().unregisterCollector(this);
+    for (const { messageManager } of this.netmonitors) {
+      messageManager.removeMessageListener("debug:request-stack", this.onGetStack);
+    }
+  },
+
+  _saveStackTrace(channel, stacktrace) {
+    for (const { messageManager } of this.netmonitors) {
+      messageManager.sendAsyncMessage("debug:request-stack-available", {
+        channelId: channel.channelId,
+        stacktrace: stacktrace && stacktrace.length > 0
+      });
+    }
+    this.stacktracesById.set(channel.channelId, stacktrace);
+  },
+
+  observe(subject) {
+    const channel = subject.QueryInterface(Ci.nsIHttpChannel);
+
+    if (!matchRequest(channel, this.filters)) {
+      return;
+    }
+
+    // Convert the nsIStackFrame XPCOM objects to a nice JSON that can be
+    // passed around through message managers etc.
+    let frame = components.stack;
+    const stacktrace = [];
+    if (frame && frame.caller) {
+      frame = frame.caller;
+      while (frame) {
+        stacktrace.push({
+          filename: frame.filename,
+          lineNumber: frame.lineNumber,
+          columnNumber: frame.columnNumber,
+          functionName: frame.name,
+          asyncCause: frame.asyncCause,
+        });
+        frame = frame.caller || frame.asyncCaller;
+      }
+    }
+
+    this._saveStackTrace(channel, stacktrace);
+  },
+
+  // eslint-disable-next-line no-shadow
+  onChannelRedirect(oldChannel, newChannel, flags) {
+    // We can be called with any nsIChannel, but are interested only in HTTP channels
+    try {
+      oldChannel.QueryInterface(Ci.nsIHttpChannel);
+      newChannel.QueryInterface(Ci.nsIHttpChannel);
+    } catch (ex) {
+      return;
+    }
+
+    const oldId = oldChannel.channelId;
+    const stacktrace = this.stacktracesById.get(oldId);
+    if (stacktrace) {
+      this._saveStackTrace(newChannel, stacktrace);
+    }
+  },
+
+  getStackTrace(channelId) {
+    const trace = this.stacktracesById.get(channelId);
+    this.stacktracesById.delete(channelId);
+    return trace;
+  },
+
+  onGetStack(msg) {
+    const messageManager = msg.target;
+    const channelId = msg.data;
+    const stack = this.getStackTrace(channelId);
+    messageManager.sendAsyncMessage("debug:request-stack", {
+      channelId,
+      stack,
+    });
+  },
+};
+
+exports.StackTraceCollector = StackTraceCollector;
--- a/devtools/server/actors/webconsole.js
+++ b/devtools/server/actors/webconsole.js
@@ -16,17 +16,17 @@ const { ThreadActor } = require("devtool
 const { ObjectActor } = require("devtools/server/actors/object");
 const { LongStringActor } = require("devtools/server/actors/object/long-string");
 const { createValueGrip, stringIsLong } = require("devtools/server/actors/object/utils");
 const DevToolsUtils = require("devtools/shared/DevToolsUtils");
 const ErrorDocs = require("devtools/server/actors/errordocs");
 
 loader.lazyRequireGetter(this, "NetworkMonitorActor", "devtools/server/actors/network-monitor", true);
 loader.lazyRequireGetter(this, "ConsoleProgressListener", "devtools/server/actors/webconsole/listeners/console-progress", true);
-loader.lazyRequireGetter(this, "StackTraceCollector", "devtools/shared/webconsole/network-monitor", true);
+loader.lazyRequireGetter(this, "StackTraceCollector", "devtools/server/actors/network-monitor/stack-trace-collector", true);
 loader.lazyRequireGetter(this, "JSPropertyProvider", "devtools/shared/webconsole/js-property-provider", true);
 loader.lazyRequireGetter(this, "Parser", "resource://devtools/shared/Parser.jsm", true);
 loader.lazyRequireGetter(this, "NetUtil", "resource://gre/modules/NetUtil.jsm", true);
 loader.lazyRequireGetter(this, "WebConsoleCommands", "devtools/server/actors/webconsole/utils", true);
 loader.lazyRequireGetter(this, "addWebConsoleCommands", "devtools/server/actors/webconsole/utils", true);
 loader.lazyRequireGetter(this, "formatCommand", "devtools/server/actors/webconsole/commands", true);
 loader.lazyRequireGetter(this, "isCommand", "devtools/server/actors/webconsole/commands", true);
 loader.lazyRequireGetter(this, "validCommands", "devtools/server/actors/webconsole/commands", true);
--- a/devtools/shared/webconsole/network-monitor.js
+++ b/devtools/shared/webconsole/network-monitor.js
@@ -97,114 +97,16 @@ function matchRequest(channel, filters) 
         // throw when closing a tab while resources are still loading.
       }
     }
   }
 
   return false;
 }
 
-function StackTraceCollector(filters, netmonitors) {
-  this.filters = filters;
-  this.stacktracesById = new Map();
-  this.netmonitors = netmonitors;
-}
-
-StackTraceCollector.prototype = {
-  init() {
-    Services.obs.addObserver(this, "http-on-opening-request");
-    ChannelEventSinkFactory.getService().registerCollector(this);
-    this.onGetStack = this.onGetStack.bind(this);
-    for (const { messageManager } of this.netmonitors) {
-      messageManager.addMessageListener("debug:request-stack", this.onGetStack);
-    }
-  },
-
-  destroy() {
-    Services.obs.removeObserver(this, "http-on-opening-request");
-    ChannelEventSinkFactory.getService().unregisterCollector(this);
-    for (const { messageManager } of this.netmonitors) {
-      messageManager.removeMessageListener("debug:request-stack", this.onGetStack);
-    }
-  },
-
-  _saveStackTrace(channel, stacktrace) {
-    for (const { messageManager } of this.netmonitors) {
-      messageManager.sendAsyncMessage("debug:request-stack-available", {
-        channelId: channel.channelId,
-        stacktrace: stacktrace && stacktrace.length > 0
-      });
-    }
-    this.stacktracesById.set(channel.channelId, stacktrace);
-  },
-
-  observe(subject) {
-    const channel = subject.QueryInterface(Ci.nsIHttpChannel);
-
-    if (!matchRequest(channel, this.filters)) {
-      return;
-    }
-
-    // Convert the nsIStackFrame XPCOM objects to a nice JSON that can be
-    // passed around through message managers etc.
-    let frame = components.stack;
-    const stacktrace = [];
-    if (frame && frame.caller) {
-      frame = frame.caller;
-      while (frame) {
-        stacktrace.push({
-          filename: frame.filename,
-          lineNumber: frame.lineNumber,
-          columnNumber: frame.columnNumber,
-          functionName: frame.name,
-          asyncCause: frame.asyncCause,
-        });
-        frame = frame.caller || frame.asyncCaller;
-      }
-    }
-
-    this._saveStackTrace(channel, stacktrace);
-  },
-
-  // eslint-disable-next-line no-shadow
-  onChannelRedirect(oldChannel, newChannel, flags) {
-    // We can be called with any nsIChannel, but are interested only in HTTP channels
-    try {
-      oldChannel.QueryInterface(Ci.nsIHttpChannel);
-      newChannel.QueryInterface(Ci.nsIHttpChannel);
-    } catch (ex) {
-      return;
-    }
-
-    const oldId = oldChannel.channelId;
-    const stacktrace = this.stacktracesById.get(oldId);
-    if (stacktrace) {
-      this._saveStackTrace(newChannel, stacktrace);
-    }
-  },
-
-  getStackTrace(channelId) {
-    const trace = this.stacktracesById.get(channelId);
-    this.stacktracesById.delete(channelId);
-    return trace;
-  },
-
-  onGetStack(msg) {
-    const messageManager = msg.target;
-    const channelId = msg.data;
-    const stack = this.getStackTrace(channelId);
-    messageManager.sendAsyncMessage("debug:request-stack", {
-      channelId,
-      stack,
-    });
-  },
-};
-
-exports.StackTraceCollector = StackTraceCollector;
-
 /**
  * The network response listener implements the nsIStreamListener and
  * nsIRequestObserver interfaces. This is used within the NetworkMonitor feature
  * to get the response body of the request.
  *
  * The code is mostly based on code listings from:
  *
  *   http://www.softwareishard.com/blog/firebug/