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 | |
4 * found in the LICENSE file. | |
5 */ | |
6 | |
7 /** | |
8 * @constructor | |
9 * @param {!WebInspector.Target} mainTarget | |
10 * @param {!WebInspector.TargetManager} targetManager | |
11 */ | |
12 WebInspector.WorkerTargetsProvider = function(mainTarget, targetManager) | |
vsevik
2014/03/19 15:54:39
WorkerTargetManager
sergeyv
2014/03/19 16:28:59
Done.
| |
13 { | |
14 this._mainTarget = mainTarget; | |
15 this._targetManager = targetManager; | |
16 mainTarget.workerManager.addEventListener(WebInspector.WorkerManager.Events. WorkerAdded, this._onWorkerAdded, this); | |
17 } | |
18 | |
19 WebInspector.WorkerTargetsProvider.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.WorkerConnectionInSameFrontend(this._mainTarget, data.w orkerId, onConnectionReady.bind(this)); | |
vsevik
2014/03/19 15:54:39
why not var connection = ?
| |
28 | |
29 /** | |
30 * @this {WebInspector.WorkerTargetsProvider} | |
31 * @param {!InspectorBackendClass.Connection} connection | |
32 */ | |
33 function onConnectionReady(connection) | |
vsevik
2014/03/19 15:54:39
why do you need to pass connection as a callback p
| |
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.WorkerConnectionInSameFrontend = function(target, workerId, onConne ctionReady) | |
vsevik
2014/03/19 15:54:39
Let's name this one WorkerConnection and the other
sergeyv
2014/03/19 16:28:59
Done.
| |
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.WorkerConnectionInSameFrontend.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 |