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

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/sdk/SubTargetsManager.js

Issue 2441933002: [DevTools] Refactor connection-related classes. (Closed)
Patch Set: test fixes Created 4 years, 2 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 unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 /** 5 /**
6 * @constructor 6 * @constructor
7 * @extends {WebInspector.SDKModel} 7 * @extends {WebInspector.SDKModel}
8 * @param {!WebInspector.Target} target 8 * @param {!WebInspector.Target} target
9 */ 9 */
10 WebInspector.SubTargetsManager = function(target) 10 WebInspector.SubTargetsManager = function(target)
11 { 11 {
12 WebInspector.SDKModel.call(this, WebInspector.SubTargetsManager, target); 12 WebInspector.SDKModel.call(this, WebInspector.SubTargetsManager, target);
13 target.registerTargetDispatcher(new WebInspector.SubTargetsDispatcher(this)) ; 13 target.registerTargetDispatcher(new WebInspector.SubTargetsDispatcher(this)) ;
14 this._lastAnonymousTargetId = 0; 14 this._lastAnonymousTargetId = 0;
15 this._agent = target.targetAgent(); 15 this._agent = target.targetAgent();
16 16
17 /** @type {!Map<string, !WebInspector.Target>} */ 17 /** @type {!Map<string, !WebInspector.Target>} */
18 this._attachedTargets = new Map(); 18 this._attachedTargets = new Map();
19 /** @type {!Map<string, !WebInspector.SubTargetConnection>} */ 19 /** @type {!Map<string, !WebInspector.SubTargetChannel>} */
20 this._connections = new Map(); 20 this._channels = new Map();
21 21
22 this._agent.setAutoAttach(true /* autoAttach */, true /* waitForDebuggerOnSt art */); 22 this._agent.setAutoAttach(true /* autoAttach */, true /* waitForDebuggerOnSt art */);
23 this._agent.setAttachToFrames(Runtime.experiments.isEnabled("autoAttachToCro ssProcessSubframes")); 23 this._agent.setAttachToFrames(Runtime.experiments.isEnabled("autoAttachToCro ssProcessSubframes"));
24 24
25 if (Runtime.experiments.isEnabled("nodeDebugging") && !target.parentTarget() ) { 25 if (Runtime.experiments.isEnabled("nodeDebugging") && !target.parentTarget() ) {
26 var defaultLocations = [{host: "localhost", port: 9229}]; 26 var defaultLocations = [{host: "localhost", port: 9229}];
27 this._agent.setRemoteLocations(defaultLocations); 27 this._agent.setRemoteLocations(defaultLocations);
28 this._agent.setDiscoverTargets(true); 28 this._agent.setDiscoverTargets(true);
29 } 29 }
30 } 30 }
(...skipping 29 matching lines...) Expand all
60 var promise = new Promise(f => fulfill = f); 60 var promise = new Promise(f => fulfill = f);
61 this._agent.setAutoAttach(true /* autoAttach */, true /* waitForDebugger OnStart */, fulfill); 61 this._agent.setAutoAttach(true /* autoAttach */, true /* waitForDebugger OnStart */, fulfill);
62 return promise; 62 return promise;
63 }, 63 },
64 64
65 /** 65 /**
66 * @override 66 * @override
67 */ 67 */
68 dispose: function() 68 dispose: function()
69 { 69 {
70 for (var connection of this._connections.values()) 70 for (var channel of this._channels.values())
71 connection.close(); 71 channel._detach();
72 this._connections.clear(); 72 this._channels.clear();
73 this._attachedTargets.clear(); 73 this._attachedTargets.clear();
74 }, 74 },
75 75
76 /** 76 /**
77 * @param {!TargetAgent.TargetID} targetId 77 * @param {!TargetAgent.TargetID} targetId
78 */ 78 */
79 activateTarget: function(targetId) 79 activateTarget: function(targetId)
80 { 80 {
81 this._agent.activateTarget(targetId); 81 this._agent.activateTarget(targetId);
82 }, 82 },
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 return WebInspector.Target.Capability.JS; 142 return WebInspector.Target.Capability.JS;
143 return 0; 143 return 0;
144 }, 144 },
145 145
146 /** 146 /**
147 * @param {!WebInspector.TargetInfo} targetInfo 147 * @param {!WebInspector.TargetInfo} targetInfo
148 * @param {boolean} waitingForDebugger 148 * @param {boolean} waitingForDebugger
149 */ 149 */
150 _attachedToTarget: function(targetInfo, waitingForDebugger) 150 _attachedToTarget: function(targetInfo, waitingForDebugger)
151 { 151 {
152 var connection = new WebInspector.SubTargetConnection(this._agent, targe tInfo.id); 152 var channel = new WebInspector.SubTargetChannel(this._agent, targetInfo. id);
153 this._connections.set(targetInfo.id, connection); 153 this._channels.set(targetInfo.id, channel);
154 154
155 var targetName = ""; 155 var targetName = "";
156 if (targetInfo.type === "node") { 156 if (targetInfo.type === "node") {
157 targetName = targetInfo.title; 157 targetName = targetInfo.title;
158 } else if (targetInfo.type !== "iframe") { 158 } else if (targetInfo.type !== "iframe") {
159 var parsedURL = targetInfo.url.asParsedURL(); 159 var parsedURL = targetInfo.url.asParsedURL();
160 targetName = parsedURL ? parsedURL.lastPathComponentWithFragment() : "#" + (++this._lastAnonymousTargetId); 160 targetName = parsedURL ? parsedURL.lastPathComponentWithFragment() : "#" + (++this._lastAnonymousTargetId);
161 } 161 }
162 var target = WebInspector.targetManager.createTarget(targetName, this._c apabilitiesForType(targetInfo.type), connection, this.target()); 162 var target = WebInspector.targetManager.createTarget(targetName, this._c apabilitiesForType(targetInfo.type), channel, this.target());
163 target[WebInspector.SubTargetsManager._InfoSymbol] = targetInfo; 163 target[WebInspector.SubTargetsManager._InfoSymbol] = targetInfo;
164 this._attachedTargets.set(targetInfo.id, target); 164 this._attachedTargets.set(targetInfo.id, target);
165 165
166 // Only pause new worker if debugging SW - we are going through the paus e on start checkbox. 166 // Only pause new worker if debugging SW - we are going through the paus e on start checkbox.
167 var mainIsServiceWorker = !this.target().parentTarget() && this.target() .hasWorkerCapability() && !this.target().hasBrowserCapability(); 167 var mainIsServiceWorker = !this.target().parentTarget() && this.target() .hasWorkerCapability() && !this.target().hasBrowserCapability();
168 if (mainIsServiceWorker && waitingForDebugger) 168 if (mainIsServiceWorker && waitingForDebugger)
169 target.debuggerAgent().pause(); 169 target.debuggerAgent().pause();
170 target.runtimeAgent().runIfWaitingForDebugger(); 170 target.runtimeAgent().runIfWaitingForDebugger();
171 171
172 this.dispatchEventToListeners(WebInspector.SubTargetsManager.Events.SubT argetAdded, target); 172 this.dispatchEventToListeners(WebInspector.SubTargetsManager.Events.SubT argetAdded, target);
173 }, 173 },
174 174
175 /** 175 /**
176 * @param {string} targetId 176 * @param {string} targetId
177 */ 177 */
178 _detachedFromTarget: function(targetId) 178 _detachedFromTarget: function(targetId)
179 { 179 {
180 var connection = this._connections.get(targetId);
181 if (connection)
182 connection._reportClosed();
183 this._connections.delete(targetId);
184 var target = this._attachedTargets.get(targetId); 180 var target = this._attachedTargets.get(targetId);
185 this._attachedTargets.delete(targetId); 181 this._attachedTargets.delete(targetId);
186 this.dispatchEventToListeners(WebInspector.SubTargetsManager.Events.SubT argetRemoved, target); 182 this.dispatchEventToListeners(WebInspector.SubTargetsManager.Events.SubT argetRemoved, target);
183 var channel = this._channels.get(targetId);
184 if (channel)
185 channel._channelClosed();
186 this._channels.delete(targetId);
187 }, 187 },
188 188
189 /** 189 /**
190 * @param {string} targetId 190 * @param {string} targetId
191 * @param {string} message 191 * @param {string} message
192 */ 192 */
193 _receivedMessageFromTarget: function(targetId, message) 193 _receivedMessageFromTarget: function(targetId, message)
194 { 194 {
195 var connection = this._connections.get(targetId); 195 var channel = this._channels.get(targetId);
196 if (connection) 196 if (channel)
197 connection.dispatch(message); 197 channel.dispatchEventToListeners(InspectorBackendClass.Channel.Event s.MessageReceived, message);
198 }, 198 },
199 199
200 /** 200 /**
201 * @param {!WebInspector.TargetInfo} targetInfo 201 * @param {!WebInspector.TargetInfo} targetInfo
202 */ 202 */
203 _targetCreated: function(targetInfo) 203 _targetCreated: function(targetInfo)
204 { 204 {
205 if (targetInfo.type !== "node") 205 if (targetInfo.type !== "node")
206 return; 206 return;
207 this._agent.attachToTarget(targetInfo.id); 207 this._agent.attachToTarget(targetInfo.id);
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
272 * @param {string} message 272 * @param {string} message
273 */ 273 */
274 receivedMessageFromTarget: function(targetId, message) 274 receivedMessageFromTarget: function(targetId, message)
275 { 275 {
276 this._manager._receivedMessageFromTarget(targetId, message); 276 this._manager._receivedMessageFromTarget(targetId, message);
277 } 277 }
278 } 278 }
279 279
280 /** 280 /**
281 * @constructor 281 * @constructor
282 * @extends {InspectorBackendClass.Connection} 282 * @extends {WebInspector.Object}
283 * @implements {InspectorBackendClass.Channel}
283 * @param {!Protocol.TargetAgent} agent 284 * @param {!Protocol.TargetAgent} agent
284 * @param {string} targetId 285 * @param {string} targetId
285 */ 286 */
286 WebInspector.SubTargetConnection = function(agent, targetId) 287 WebInspector.SubTargetChannel = function(agent, targetId)
287 { 288 {
288 InspectorBackendClass.Connection.call(this); 289 WebInspector.Object.call(this);
289 this._agent = agent; 290 this._agent = agent;
290 this._targetId = targetId; 291 this._targetId = targetId;
291 } 292 }
292 293
293 WebInspector.SubTargetConnection.prototype = { 294 WebInspector.SubTargetChannel.prototype = {
294 /** 295 /**
295 * @override 296 * @override
296 * @param {!Object} messageObject 297 * @param {string} message
297 */ 298 */
298 sendMessage: function(messageObject) 299 sendMessage: function(message)
299 { 300 {
300 this._agent.sendMessageToTarget(this._targetId, JSON.stringify(messageOb ject)); 301 this._agent.sendMessageToTarget(this._targetId, message);
301 }, 302 },
302 303
303 /** 304 /**
304 * @override 305 * @override
306 * @param {function()} callback
305 */ 307 */
306 forceClose: function() 308 reconnect: function(callback)
309 {
310 throw new Error("Not implemented");
311 },
312
313 _detach: function()
307 { 314 {
308 this._agent.detachFromTarget(this._targetId); 315 this._agent.detachFromTarget(this._targetId);
316 this._channelClosed();
309 }, 317 },
310 318
311 _reportClosed: function() 319 _channelClosed: function()
312 { 320 {
313 this.connectionClosed("target_terminated"); 321 this.dispatchEventToListeners(InspectorBackendClass.Channel.Events.Chann elClosed, "target terminated");
314 }, 322 },
315 323
316 __proto__: InspectorBackendClass.Connection.prototype 324 __proto__: WebInspector.Object.prototype
317 } 325 }
318 326
319 /** 327 /**
320 * @constructor 328 * @constructor
321 * @param {!TargetAgent.TargetInfo} payload 329 * @param {!TargetAgent.TargetInfo} payload
322 */ 330 */
323 WebInspector.TargetInfo = function(payload) 331 WebInspector.TargetInfo = function(payload)
324 { 332 {
325 this.id = payload.targetId; 333 this.id = payload.targetId;
326 this.url = payload.url; 334 this.url = payload.url;
327 this.type = payload.type; 335 this.type = payload.type;
328 if (this.type !== "page" && this.type !== "iframe") { 336 if (this.type !== "page" && this.type !== "iframe") {
329 this.title = WebInspector.UIString("Worker: %s", this.url); 337 this.title = WebInspector.UIString("Worker: %s", this.url);
330 this.canActivate = false; 338 this.canActivate = false;
331 } else { 339 } else {
332 this.title = payload.title; 340 this.title = payload.title;
333 this.canActivate = true; 341 this.canActivate = true;
334 } 342 }
335 } 343 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698