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