Bug 1482070 - Move ChannelEventSink to its own file. r=Honza
authorAlexandre Poirot <poirot.alex@gmail.com>
Tue, 14 Aug 2018 08:50:25 -0700
changeset 487540 cc2fffaa4633bebab54f78e42277e8eeb23521c6
parent 487539 f269b019428d8d9e2984c8345d3fd9e40d013b8d
child 487541 e4b6ce31de8d57f7e772232bda29727e82ec6ea5
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 ChannelEventSink to its own file. r=Honza Summary: Depends On D3602 Reviewers: Honza! Tags: #secure-revision Bug #: 1482070 Differential Revision: https://phabricator.services.mozilla.com/D3603 MozReview-Commit-ID: Kr3vYvP1oCZ
devtools/server/actors/moz.build
devtools/server/actors/network-monitor/channel-event-sink.js
devtools/server/actors/network-monitor/moz.build
devtools/shared/webconsole/network-monitor.js
--- a/devtools/server/actors/moz.build
+++ b/devtools/server/actors/moz.build
@@ -5,16 +5,17 @@
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 DIRS += [
     'addon',
     'canvas',
     'emulation',
     'highlighters',
     'inspector',
+    'network-monitor',
     'object',
     'replay',
     'targets',
     'utils',
     'webconsole',
     'worker',
 ]
 
new file mode 100644
--- /dev/null
+++ b/devtools/server/actors/network-monitor/channel-event-sink.js
@@ -0,0 +1,84 @@
+/* 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, Cm, Cr, components} = require("chrome");
+const ChromeUtils = require("ChromeUtils");
+const { XPCOMUtils } = require("resource://gre/modules/XPCOMUtils.jsm");
+
+/**
+ * This is a nsIChannelEventSink implementation that monitors channel redirects and
+ * informs the registered StackTraceCollector about the old and new channels.
+ */
+const SINK_CLASS_DESCRIPTION = "NetworkMonitor Channel Event Sink";
+const SINK_CLASS_ID = components.ID("{e89fa076-c845-48a8-8c45-2604729eba1d}");
+const SINK_CONTRACT_ID = "@mozilla.org/network/monitor/channeleventsink;1";
+const SINK_CATEGORY_NAME = "net-channel-event-sinks";
+
+function ChannelEventSink() {
+  this.wrappedJSObject = this;
+  this.collectors = new Set();
+}
+
+ChannelEventSink.prototype = {
+  QueryInterface: ChromeUtils.generateQI([Ci.nsIChannelEventSink]),
+
+  registerCollector(collector) {
+    this.collectors.add(collector);
+  },
+
+  unregisterCollector(collector) {
+    this.collectors.delete(collector);
+
+    if (this.collectors.size == 0) {
+      ChannelEventSinkFactory.unregister();
+    }
+  },
+
+  // eslint-disable-next-line no-shadow
+  asyncOnChannelRedirect(oldChannel, newChannel, flags, callback) {
+    for (const collector of this.collectors) {
+      try {
+        collector.onChannelRedirect(oldChannel, newChannel, flags);
+      } catch (ex) {
+        console.error("StackTraceCollector.onChannelRedirect threw an exception", ex);
+      }
+    }
+    callback.onRedirectVerifyCallback(Cr.NS_OK);
+  }
+};
+
+const ChannelEventSinkFactory = XPCOMUtils.generateSingletonFactory(ChannelEventSink);
+
+ChannelEventSinkFactory.register = function() {
+  const registrar = Cm.QueryInterface(Ci.nsIComponentRegistrar);
+  if (registrar.isCIDRegistered(SINK_CLASS_ID)) {
+    return;
+  }
+
+  registrar.registerFactory(SINK_CLASS_ID,
+                            SINK_CLASS_DESCRIPTION,
+                            SINK_CONTRACT_ID,
+                            ChannelEventSinkFactory);
+
+  XPCOMUtils.categoryManager.addCategoryEntry(SINK_CATEGORY_NAME, SINK_CONTRACT_ID,
+    SINK_CONTRACT_ID, false, true);
+};
+
+ChannelEventSinkFactory.unregister = function() {
+  const registrar = Cm.QueryInterface(Ci.nsIComponentRegistrar);
+  registrar.unregisterFactory(SINK_CLASS_ID, ChannelEventSinkFactory);
+
+  XPCOMUtils.categoryManager.deleteCategoryEntry(SINK_CATEGORY_NAME, SINK_CONTRACT_ID,
+    false);
+};
+
+ChannelEventSinkFactory.getService = function() {
+  // Make sure the ChannelEventSink service is registered before accessing it
+  ChannelEventSinkFactory.register();
+
+  return Cc[SINK_CONTRACT_ID].getService(Ci.nsIChannelEventSink).wrappedJSObject;
+};
+exports.ChannelEventSinkFactory = ChannelEventSinkFactory;
copy from devtools/server/actors/moz.build
copy to devtools/server/actors/network-monitor/moz.build
--- a/devtools/server/actors/moz.build
+++ b/devtools/server/actors/network-monitor/moz.build
@@ -1,106 +1,9 @@
 # -*- 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/.
 
-DIRS += [
-    'addon',
-    'canvas',
-    'emulation',
-    'highlighters',
-    'inspector',
-    'object',
-    'replay',
-    'targets',
-    'utils',
-    'webconsole',
-    'worker',
-]
-
 DevToolsModules(
-    'accessibility-parent.js',
-    'accessibility.js',
-    'actor-registry.js',
-    'animation-type-longhand.js',
-    'animation.js',
-    'array-buffer.js',
-    'breakpoint.js',
-    'call-watcher.js',
-    'canvas.js',
-    'common.js',
-    'css-properties.js',
-    'csscoverage.js',
-    'device.js',
-    'emulation.js',
-    'environment.js',
-    'errordocs.js',
-    'frame.js',
-    'framerate.js',
-    'gcli.js',
-    'heap-snapshot-file.js',
-    'highlighters.css',
-    'highlighters.js',
-    'layout.js',
-    'memory.js',
-    'network-event.js',
-    'network-monitor.js',
-    'object.js',
-    'pause-scoped.js',
-    'perf.js',
-    'performance-recording.js',
-    'performance.js',
-    'preference.js',
-    'pretty-print-worker.js',
-    'process.js',
-    'promises.js',
-    'reflow.js',
-    'root.js',
-    'source.js',
-    'storage.js',
-    'string.js',
-    'styles.js',
-    'stylesheets.js',
-    'thread.js',
-    'timeline.js',
-    'webaudio.js',
-    'webbrowser.js',
-    'webconsole.js',
-    'webgl.js',
+    'channel-event-sink.js',
 )
-
-with Files('animation.js'):
-    BUG_COMPONENT = ('DevTools', 'Animation Inspector')
-
-with Files('breakpoint.js'):
-    BUG_COMPONENT = ('DevTools', 'Debugger')
-
-with Files('css-properties.js'):
-    BUG_COMPONENT = ('DevTools', 'CSS Rules Inspector')
-
-with Files('csscoverage.js'):
-    BUG_COMPONENT = ('DevTools', 'Graphics Commandline and Toolbar')
-
-with Files('memory.js'):
-    BUG_COMPONENT = ('DevTools', 'Memory')
-
-with Files('performance*'):
-    BUG_COMPONENT = ('DevTools', 'Performance Tools (Profiler/Timeline)')
-
-with Files('source.js'):
-    BUG_COMPONENT = ('DevTools', 'Debugger')
-
-with Files('storage.js'):
-    BUG_COMPONENT = ('DevTools', 'Storage Inspector')
-
-with Files('stylesheets.js'):
-    BUG_COMPONENT = ('DevTools', 'Style Editor')
-
-with Files('webaudio.js'):
-    BUG_COMPONENT = ('DevTools', 'Web Audio Editor')
-
-with Files('webconsole.js'):
-    BUG_COMPONENT = ('DevTools', 'Console')
-
-with Files('webgl.js'):
-    BUG_COMPONENT = ('DevTools', 'WebGL Shader Editor')
--- a/devtools/shared/webconsole/network-monitor.js
+++ b/devtools/shared/webconsole/network-monitor.js
@@ -20,16 +20,19 @@ loader.lazyRequireGetter(this, "flags",
 loader.lazyRequireGetter(this, "NetworkThrottleManager",
                          "devtools/shared/webconsole/throttle", true);
 loader.lazyRequireGetter(this, "CacheEntry",
                          "devtools/shared/platform/cache-entry", true);
 loader.lazyImporter(this, "NetUtil", "resource://gre/modules/NetUtil.jsm");
 loader.lazyServiceGetter(this, "gActivityDistributor",
                          "@mozilla.org/network/http-activity-distributor;1",
                          "nsIHttpActivityDistributor");
+loader.lazyRequireGetter(this, "ChannelEventSinkFactory",
+                         "devtools/server/actors/network-monitor/channel-event-sink",
+                         true);
 
 // Network logging
 
 // The maximum uint32 value.
 const PR_UINT32_MAX = 4294967295;
 
 // HTTP status codes.
 const HTTP_MOVED_PERMANENTLY = 301;
@@ -94,90 +97,16 @@ function matchRequest(channel, filters) 
         // throw when closing a tab while resources are still loading.
       }
     }
   }
 
   return false;
 }
 
-/**
- * This is a nsIChannelEventSink implementation that monitors channel redirects and
- * informs the registered StackTraceCollector about the old and new channels.
- */
-const SINK_CLASS_DESCRIPTION = "NetworkMonitor Channel Event Sink";
-const SINK_CLASS_ID = components.ID("{e89fa076-c845-48a8-8c45-2604729eba1d}");
-const SINK_CONTRACT_ID = "@mozilla.org/network/monitor/channeleventsink;1";
-const SINK_CATEGORY_NAME = "net-channel-event-sinks";
-
-function ChannelEventSink() {
-  this.wrappedJSObject = this;
-  this.collectors = new Set();
-}
-
-ChannelEventSink.prototype = {
-  QueryInterface: ChromeUtils.generateQI([Ci.nsIChannelEventSink]),
-
-  registerCollector(collector) {
-    this.collectors.add(collector);
-  },
-
-  unregisterCollector(collector) {
-    this.collectors.delete(collector);
-
-    if (this.collectors.size == 0) {
-      ChannelEventSinkFactory.unregister();
-    }
-  },
-
-  // eslint-disable-next-line no-shadow
-  asyncOnChannelRedirect(oldChannel, newChannel, flags, callback) {
-    for (const collector of this.collectors) {
-      try {
-        collector.onChannelRedirect(oldChannel, newChannel, flags);
-      } catch (ex) {
-        console.error("StackTraceCollector.onChannelRedirect threw an exception", ex);
-      }
-    }
-    callback.onRedirectVerifyCallback(Cr.NS_OK);
-  }
-};
-
-const ChannelEventSinkFactory = XPCOMUtils.generateSingletonFactory(ChannelEventSink);
-
-ChannelEventSinkFactory.register = function() {
-  const registrar = Cm.QueryInterface(Ci.nsIComponentRegistrar);
-  if (registrar.isCIDRegistered(SINK_CLASS_ID)) {
-    return;
-  }
-
-  registrar.registerFactory(SINK_CLASS_ID,
-                            SINK_CLASS_DESCRIPTION,
-                            SINK_CONTRACT_ID,
-                            ChannelEventSinkFactory);
-
-  XPCOMUtils.categoryManager.addCategoryEntry(SINK_CATEGORY_NAME, SINK_CONTRACT_ID,
-    SINK_CONTRACT_ID, false, true);
-};
-
-ChannelEventSinkFactory.unregister = function() {
-  const registrar = Cm.QueryInterface(Ci.nsIComponentRegistrar);
-  registrar.unregisterFactory(SINK_CLASS_ID, ChannelEventSinkFactory);
-
-  XPCOMUtils.categoryManager.deleteCategoryEntry(SINK_CATEGORY_NAME, SINK_CONTRACT_ID,
-    false);
-};
-
-ChannelEventSinkFactory.getService = function() {
-  // Make sure the ChannelEventSink service is registered before accessing it
-  ChannelEventSinkFactory.register();
-
-  return Cc[SINK_CONTRACT_ID].getService(Ci.nsIChannelEventSink).wrappedJSObject;
-};
-
 function StackTraceCollector(filters, netmonitors) {
   this.filters = filters;
   this.stacktracesById = new Map();
   this.netmonitors = netmonitors;
 }
 
 StackTraceCollector.prototype = {
   init() {