Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1793)

Unified Diff: Source/devtools/front_end/WorkerTargetManager.js

Issue 201123007: DevTools: Create target per each worker behind experiment (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Rebase on master Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/devtools/front_end/WorkerManager.js ('k') | Source/devtools/front_end/inspector.html » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/devtools/front_end/WorkerTargetManager.js
diff --git a/Source/devtools/front_end/WorkerTargetManager.js b/Source/devtools/front_end/WorkerTargetManager.js
new file mode 100644
index 0000000000000000000000000000000000000000..d01da86cd5cdbacf8595750bda473fac12d1d86a
--- /dev/null
+++ b/Source/devtools/front_end/WorkerTargetManager.js
@@ -0,0 +1,85 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+
+/**
+ * @constructor
+ * @param {!WebInspector.Target} mainTarget
+ * @param {!WebInspector.TargetManager} targetManager
+ */
+WebInspector.WorkerTargetManager = function(mainTarget, targetManager)
+{
+ this._mainTarget = mainTarget;
+ this._targetManager = targetManager;
+ mainTarget.workerManager.addEventListener(WebInspector.WorkerManager.Events.WorkerAdded, this._onWorkerAdded, this);
+}
+
+WebInspector.WorkerTargetManager.prototype = {
+
+ /**
+ * @param {!WebInspector.Event} event
+ */
+ _onWorkerAdded: function(event)
+ {
+ var data = /** @type {{workerId: number, url: string}} */ (event.data);
+ new WebInspector.WorkerConnection(this._mainTarget, data.workerId, onConnectionReady.bind(this));
+
+ /**
+ * @this {WebInspector.WorkerTargetManager}
+ * @param {!InspectorBackendClass.Connection} connection
+ */
+ function onConnectionReady(connection)
+ {
+ this._targetManager.createTarget(connection, workerTargetInitialization)
+ }
+
+ /**
+ * @param {!WebInspector.Target} target
+ */
+ function workerTargetInitialization(target)
+ {
+ target.runtimeModel.addWorkerContextList(data.url);
+ }
+ }
+
+}
+
+/**
+ * @constructor
+ * @extends {InspectorBackendClass.Connection}
+ * @param {!WebInspector.Target} target
+ * @param {number} workerId
+ * @param {!function(!InspectorBackendClass.Connection)} onConnectionReady
+ */
+WebInspector.WorkerConnection = function(target, workerId, onConnectionReady)
+{
+ InspectorBackendClass.Connection.call(this);
+ this._workerId = workerId;
+ this._workerAgent = target.workerAgent();
+ this._workerAgent.connectToWorker(workerId, onConnectionReady.bind(null, this));
+ target.workerManager.addEventListener(WebInspector.WorkerManager.Events.MessageFromWorker, this._dispatchMessageFromWorker, this);
+}
+
+WebInspector.WorkerConnection.prototype = {
+
+ /**
+ * @param {!WebInspector.Event} event
+ */
+ _dispatchMessageFromWorker: function(event)
+ {
+ var data = /** @type {{workerId: number, command: string, message: !Object}} */ (event.data);
+ if (data.workerId === this._workerId)
+ this.dispatch(data.message);
+ },
+
+ /**
+ * @param {!Object} messageObject
+ */
+ sendMessage: function(messageObject)
+ {
+ this._workerAgent.sendMessageToWorker(this._workerId, messageObject);
+ },
+
+ __proto__: InspectorBackendClass.Connection.prototype
+}
« no previous file with comments | « Source/devtools/front_end/WorkerManager.js ('k') | Source/devtools/front_end/inspector.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698