OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 |
| 6 /** |
| 7 * @constructor |
| 8 * @param {!WebInspector.Target} mainTarget |
| 9 * @param {!WebInspector.TargetManager} targetManager |
| 10 */ |
| 11 WebInspector.WorkerTargetManager = function(mainTarget, targetManager) |
| 12 { |
| 13 this._mainTarget = mainTarget; |
| 14 this._targetManager = targetManager; |
| 15 mainTarget.workerManager.addEventListener(WebInspector.WorkerManager.Events.
WorkerAdded, this._onWorkerAdded, this); |
| 16 } |
| 17 |
| 18 WebInspector.WorkerTargetManager.prototype = { |
| 19 |
| 20 /** |
| 21 * @param {!WebInspector.Event} event |
| 22 */ |
| 23 _onWorkerAdded: function(event) |
| 24 { |
| 25 var data = /** @type {{workerId: number, url: string}} */ (event.data); |
| 26 new WebInspector.WorkerConnection(this._mainTarget, data.workerId, onCon
nectionReady.bind(this)); |
| 27 |
| 28 /** |
| 29 * @this {WebInspector.WorkerTargetManager} |
| 30 * @param {!InspectorBackendClass.Connection} connection |
| 31 */ |
| 32 function onConnectionReady(connection) |
| 33 { |
| 34 this._targetManager.createTarget(connection, workerTargetInitializat
ion) |
| 35 } |
| 36 |
| 37 /** |
| 38 * @param {!WebInspector.Target} target |
| 39 */ |
| 40 function workerTargetInitialization(target) |
| 41 { |
| 42 target.runtimeModel.addWorkerContextList(data.url); |
| 43 } |
| 44 } |
| 45 |
| 46 } |
| 47 |
| 48 /** |
| 49 * @constructor |
| 50 * @extends {InspectorBackendClass.Connection} |
| 51 * @param {!WebInspector.Target} target |
| 52 * @param {number} workerId |
| 53 * @param {!function(!InspectorBackendClass.Connection)} onConnectionReady |
| 54 */ |
| 55 WebInspector.WorkerConnection = function(target, workerId, onConnectionReady) |
| 56 { |
| 57 InspectorBackendClass.Connection.call(this); |
| 58 this._workerId = workerId; |
| 59 this._workerAgent = target.workerAgent(); |
| 60 this._workerAgent.connectToWorker(workerId, onConnectionReady.bind(null, thi
s)); |
| 61 target.workerManager.addEventListener(WebInspector.WorkerManager.Events.Mess
ageFromWorker, this._dispatchMessageFromWorker, this); |
| 62 } |
| 63 |
| 64 WebInspector.WorkerConnection.prototype = { |
| 65 |
| 66 /** |
| 67 * @param {!WebInspector.Event} event |
| 68 */ |
| 69 _dispatchMessageFromWorker: function(event) |
| 70 { |
| 71 var data = /** @type {{workerId: number, command: string, message: !Obje
ct}} */ (event.data); |
| 72 if (data.workerId === this._workerId) |
| 73 this.dispatch(data.message); |
| 74 }, |
| 75 |
| 76 /** |
| 77 * @param {!Object} messageObject |
| 78 */ |
| 79 sendMessage: function(messageObject) |
| 80 { |
| 81 this._workerAgent.sendMessageToWorker(this._workerId, messageObject); |
| 82 }, |
| 83 |
| 84 __proto__: InspectorBackendClass.Connection.prototype |
| 85 } |
OLD | NEW |