Chromium Code Reviews| OLD | NEW |
|---|---|
| 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.SubTargetConnection>} */ |
| 20 this._connections = new Map(); | 20 this._connections = new Map(); |
| 21 /** @type {!Map<string, !WebInspector.PendingConnection>} */ | |
| 22 this._pendingConnections = new Map(); | |
| 21 | 23 |
| 22 this._agent.setAutoAttach(true /* autoAttach */, true /* waitForDebuggerOnSt art */); | 24 this._agent.setAutoAttach(true /* autoAttach */, true /* waitForDebuggerOnSt art */); |
| 23 this._agent.setAttachToFrames(Runtime.experiments.isEnabled("autoAttachToCro ssProcessSubframes")); | 25 this._agent.setAttachToFrames(Runtime.experiments.isEnabled("autoAttachToCro ssProcessSubframes")); |
| 24 | 26 |
| 25 if (Runtime.experiments.isEnabled("nodeDebugging") && !target.parentTarget() ) { | 27 if (Runtime.experiments.isEnabled("nodeDebugging") && !target.parentTarget() ) { |
| 26 var defaultLocations = [{host: "localhost", port: 9229}]; | 28 var defaultLocations = [{host: "localhost", port: 9229}]; |
| 27 this._agent.setRemoteLocations(defaultLocations); | 29 this._agent.setRemoteLocations(defaultLocations); |
| 28 this._agent.setDiscoverTargets(true); | 30 this._agent.setDiscoverTargets(true); |
| 29 } | 31 } |
| 30 }; | 32 }; |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 64 | 66 |
| 65 /** | 67 /** |
| 66 * @override | 68 * @override |
| 67 */ | 69 */ |
| 68 dispose: function() | 70 dispose: function() |
| 69 { | 71 { |
| 70 for (var connection of this._connections.values()) { | 72 for (var connection of this._connections.values()) { |
| 71 this._agent.detachFromTarget(connection._targetId); | 73 this._agent.detachFromTarget(connection._targetId); |
| 72 connection._onDisconnect.call(null, "disposed"); | 74 connection._onDisconnect.call(null, "disposed"); |
| 73 } | 75 } |
| 76 for (var pending of this._pendingConnections.values()) | |
| 77 WebInspector.targetConnectionManager.removeConnection(pending); | |
| 74 this._connections.clear(); | 78 this._connections.clear(); |
| 75 this._attachedTargets.clear(); | 79 this._attachedTargets.clear(); |
| 76 }, | 80 }, |
| 77 | 81 |
| 78 /** | 82 /** |
| 79 * @param {!TargetAgent.TargetID} targetId | 83 * @param {!TargetAgent.TargetID} targetId |
| 80 */ | 84 */ |
| 81 activateTarget: function(targetId) | 85 activateTarget: function(targetId) |
| 82 { | 86 { |
| 83 this._agent.activateTarget(targetId); | 87 this._agent.activateTarget(targetId); |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 151 */ | 155 */ |
| 152 _attachedToTarget: function(targetInfo, waitingForDebugger) | 156 _attachedToTarget: function(targetInfo, waitingForDebugger) |
| 153 { | 157 { |
| 154 var targetName = ""; | 158 var targetName = ""; |
| 155 if (targetInfo.type === "node") { | 159 if (targetInfo.type === "node") { |
| 156 targetName = targetInfo.title; | 160 targetName = targetInfo.title; |
| 157 } else if (targetInfo.type !== "iframe") { | 161 } else if (targetInfo.type !== "iframe") { |
| 158 var parsedURL = targetInfo.url.asParsedURL(); | 162 var parsedURL = targetInfo.url.asParsedURL(); |
| 159 targetName = parsedURL ? parsedURL.lastPathComponentWithFragment() : "#" + (++this._lastAnonymousTargetId); | 163 targetName = parsedURL ? parsedURL.lastPathComponentWithFragment() : "#" + (++this._lastAnonymousTargetId); |
| 160 } | 164 } |
| 161 var target = WebInspector.targetManager.createTarget(targetName, this._c apabilitiesForType(targetInfo.type), this._createConnection.bind(this, targetInf o.id), this.target()); | 165 var target = WebInspector.targetManager.createTarget(targetName, this._c apabilitiesForType(targetInfo.type), this._createConnection.bind(this, targetInf o.id), this.target(), true); |
| 166 var targetConnection = this._targetCreated(targetInfo); | |
| 167 targetConnection && targetConnection._attached(target); | |
|
dgozman
2016/10/26 22:14:06
Why do we need this?
eostroukhov
2016/10/27 23:42:24
For targets, that can be disconnected from, mappin
| |
| 168 WebInspector.targetManager.addTarget(target); | |
| 162 target[WebInspector.SubTargetsManager._InfoSymbol] = targetInfo; | 169 target[WebInspector.SubTargetsManager._InfoSymbol] = targetInfo; |
| 163 this._attachedTargets.set(targetInfo.id, target); | 170 this._attachedTargets.set(targetInfo.id, target); |
| 164 | 171 |
| 165 // Only pause new worker if debugging SW - we are going through the paus e on start checkbox. | 172 // Only pause new worker if debugging SW - we are going through the paus e on start checkbox. |
| 166 var mainIsServiceWorker = !this.target().parentTarget() && this.target() .hasWorkerCapability() && !this.target().hasBrowserCapability(); | 173 var mainIsServiceWorker = !this.target().parentTarget() && this.target() .hasWorkerCapability() && !this.target().hasBrowserCapability(); |
| 167 if (mainIsServiceWorker && waitingForDebugger) | 174 if (mainIsServiceWorker && waitingForDebugger) |
| 168 target.debuggerAgent().pause(); | 175 target.debuggerAgent().pause(); |
| 169 target.runtimeAgent().runIfWaitingForDebugger(); | 176 target.runtimeAgent().runIfWaitingForDebugger(); |
| 170 | 177 |
| 171 this.dispatchEventToListeners(WebInspector.SubTargetsManager.Events.SubT argetAdded, target); | 178 this.dispatchEventToListeners(WebInspector.SubTargetsManager.Events.SubT argetAdded, target); |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 188 */ | 195 */ |
| 189 _detachedFromTarget: function(targetId) | 196 _detachedFromTarget: function(targetId) |
| 190 { | 197 { |
| 191 var target = this._attachedTargets.get(targetId); | 198 var target = this._attachedTargets.get(targetId); |
| 192 this._attachedTargets.delete(targetId); | 199 this._attachedTargets.delete(targetId); |
| 193 this.dispatchEventToListeners(WebInspector.SubTargetsManager.Events.SubT argetRemoved, target); | 200 this.dispatchEventToListeners(WebInspector.SubTargetsManager.Events.SubT argetRemoved, target); |
| 194 var connection = this._connections.get(targetId); | 201 var connection = this._connections.get(targetId); |
| 195 if (connection) | 202 if (connection) |
| 196 connection._onDisconnect.call(null, "target terminated"); | 203 connection._onDisconnect.call(null, "target terminated"); |
| 197 this._connections.delete(targetId); | 204 this._connections.delete(targetId); |
| 205 var targetConnection = this._pendingConnections.get(targetId); | |
| 206 targetConnection && targetConnection._detached(); | |
|
dgozman
2016/10/26 22:14:06
style: let's follow the surrounding code and do pr
eostroukhov
2016/10/27 23:42:24
Done.
| |
| 198 }, | 207 }, |
| 199 | 208 |
| 200 /** | 209 /** |
| 201 * @param {string} targetId | 210 * @param {string} targetId |
| 202 * @param {string} message | 211 * @param {string} message |
| 203 */ | 212 */ |
| 204 _receivedMessageFromTarget: function(targetId, message) | 213 _receivedMessageFromTarget: function(targetId, message) |
| 205 { | 214 { |
| 206 var connection = this._connections.get(targetId); | 215 var connection = this._connections.get(targetId); |
| 207 if (connection) | 216 if (connection) |
| 208 connection._onMessage.call(null, message); | 217 connection._onMessage.call(null, message); |
| 209 }, | 218 }, |
| 210 | 219 |
| 211 /** | 220 /** |
| 212 * @param {!WebInspector.TargetInfo} targetInfo | 221 * @param {!WebInspector.TargetInfo} targetInfo |
| 222 * @return {?WebInspector.PendingConnection} | |
| 213 */ | 223 */ |
| 214 _targetCreated: function(targetInfo) | 224 _targetCreated: function(targetInfo) |
| 215 { | 225 { |
| 216 if (targetInfo.type !== "node") | 226 if (targetInfo.type !== "node") |
| 217 return; | 227 return null; |
| 218 this._agent.attachToTarget(targetInfo.id); | 228 var connection = this._pendingConnections.get(targetInfo.id); |
|
dgozman
2016/10/26 22:14:06
How come we could have one?
eostroukhov
2016/10/27 23:42:24
Speculatively, the code supports a case when attac
| |
| 229 if (connection) | |
| 230 return connection; | |
| 231 connection = new WebInspector.PendingConnection(targetInfo, this.target( ).targetAgent()); | |
|
dgozman
2016/10/26 22:14:06
this._agent
eostroukhov
2016/10/27 23:42:24
Done.
| |
| 232 WebInspector.targetConnectionManager.addConnection(connection); | |
| 233 this._pendingConnections.set(targetInfo.id, connection); | |
| 234 return connection; | |
| 219 }, | 235 }, |
| 220 | 236 |
| 221 /** | 237 /** |
| 222 * @param {string} targetId | 238 * @param {string} targetId |
| 223 */ | 239 */ |
| 224 _targetDestroyed: function(targetId) | 240 _targetDestroyed: function(targetId) |
| 225 { | 241 { |
| 226 // All the work is done in _detachedFromTarget. | 242 var connection = this._pendingConnections.get(targetId); |
| 243 if (!connection) | |
| 244 return; | |
| 245 WebInspector.targetConnectionManager.removeConnection(connection); | |
| 246 this._pendingConnections.delete(targetId); | |
| 227 }, | 247 }, |
| 228 | 248 |
| 229 __proto__: WebInspector.SDKModel.prototype | 249 __proto__: WebInspector.SDKModel.prototype |
| 230 }; | 250 }; |
| 231 | 251 |
| 232 /** | 252 /** |
| 233 * @constructor | 253 * @constructor |
| 234 * @implements {TargetAgent.Dispatcher} | 254 * @implements {TargetAgent.Dispatcher} |
| 235 * @param {!WebInspector.SubTargetsManager} manager | 255 * @param {!WebInspector.SubTargetsManager} manager |
| 236 */ | 256 */ |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 325 | 345 |
| 326 /** | 346 /** |
| 327 * @constructor | 347 * @constructor |
| 328 * @param {!TargetAgent.TargetInfo} payload | 348 * @param {!TargetAgent.TargetInfo} payload |
| 329 */ | 349 */ |
| 330 WebInspector.TargetInfo = function(payload) | 350 WebInspector.TargetInfo = function(payload) |
| 331 { | 351 { |
| 332 this.id = payload.targetId; | 352 this.id = payload.targetId; |
| 333 this.url = payload.url; | 353 this.url = payload.url; |
| 334 this.type = payload.type; | 354 this.type = payload.type; |
| 335 if (this.type !== "page" && this.type !== "iframe") { | 355 if (this.type !== "page" && this.type !== "iframe" && this.type !== "node") { |
| 336 this.title = WebInspector.UIString("Worker: %s", this.url); | 356 this.title = WebInspector.UIString("Worker: %s", this.url); |
| 337 this.canActivate = false; | 357 this.canActivate = false; |
| 338 } else { | 358 } else { |
| 339 this.title = payload.title; | 359 this.title = payload.title; |
| 340 this.canActivate = true; | 360 this.canActivate = true; |
| 341 } | 361 } |
| 342 }; | 362 }; |
| 363 | |
| 364 /** | |
| 365 * @constructor | |
| 366 * @implements {WebInspector.TargetConnectionManager.Connection} | |
| 367 * @param {!WebInspector.TargetInfo} info | |
| 368 * @param {!Protocol.TargetAgent} targetAgent | |
| 369 */ | |
| 370 WebInspector.PendingConnection = function(info, targetAgent) | |
| 371 { | |
| 372 this._info = info; | |
| 373 this._targetAgent = targetAgent; | |
| 374 /** @type {?Promise} */ | |
| 375 this._connectPromise = null; | |
| 376 /** @type {?WebInspector.Target} */ | |
| 377 this._target = null; | |
| 378 }; | |
| 379 | |
| 380 WebInspector.PendingConnection.prototype = { | |
| 381 /** | |
| 382 * @override | |
| 383 * @return {string} | |
| 384 */ | |
| 385 id: function() | |
| 386 { | |
| 387 return this._info.id; | |
| 388 }, | |
| 389 | |
| 390 /** | |
| 391 * @override | |
| 392 * @return {string} | |
| 393 */ | |
| 394 name: function() | |
| 395 { | |
| 396 return this._info.title; | |
| 397 }, | |
| 398 | |
| 399 /** | |
| 400 * @override | |
| 401 * @return {!Promise} | |
| 402 */ | |
| 403 connect: function() | |
| 404 { | |
| 405 if (this._target) | |
| 406 return Promise.resolve(this._target); | |
| 407 if (this._connectPromise) | |
| 408 return this._connectPromise; | |
| 409 var resolveFn, rejectFn; | |
| 410 var promise = new Promise((resolve, reject) => { | |
|
dgozman
2016/10/26 22:14:06
The following pattern is used heavily in inspector
eostroukhov
2016/10/27 23:42:24
Done (TIL - parentheses are optional for arrow fun
| |
| 411 resolveFn = resolve; | |
| 412 rejectFn = reject; | |
| 413 }).then((target) => { | |
| 414 this._target = target | |
| 415 this._connectPromise = null; | |
| 416 }); | |
| 417 promise[WebInspector.PendingConnection._resolveSymbol] = resolveFn; | |
| 418 this._connectPromise = promise; | |
| 419 this._targetAgent.attachToTarget(this.id()); | |
| 420 return promise; | |
| 421 }, | |
| 422 | |
| 423 /** | |
| 424 * @override | |
| 425 * @return {!Promise} | |
| 426 */ | |
| 427 disconnect: function() | |
| 428 { | |
| 429 var agent = this._targetAgent; | |
| 430 var detachFn = agent.detachFromTarget.bind(agent, this.id()); | |
| 431 if (this._connectPromise) | |
| 432 return this._connectPromise.then(detachFn); | |
| 433 if (this._target) | |
| 434 detachFn(); | |
| 435 return Promise.resolve(); | |
| 436 }, | |
| 437 | |
| 438 /** | |
| 439 * @return {?WebInspector.Target} | |
| 440 */ | |
| 441 target: function() | |
| 442 { | |
| 443 return this._target; | |
| 444 }, | |
| 445 | |
| 446 _attached: function(target) { | |
| 447 target[WebInspector.TargetConnectionManager.Connection.symbol] = this; | |
| 448 this._connectPromise && this._connectPromise[WebInspector.PendingConnect ion._resolveSymbol](target); | |
| 449 }, | |
| 450 | |
| 451 _detached: function() | |
| 452 { | |
| 453 this._target = null; | |
| 454 }, | |
| 455 }; | |
| 456 | |
| 457 WebInspector.PendingConnection._LastAnonymousTargetId = 0; | |
| 458 WebInspector.PendingConnection._resolveSymbol = Symbol("resolve"); | |
| OLD | NEW |