| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 3 * Use of this source code is governed by a BSD-style license that can be |
| 4 * found in the LICENSE file. | 4 * found in the LICENSE file. |
| 5 */ | 5 */ |
| 6 | 6 |
| 7 SDK.TargetManager = class extends Common.Object { | 7 SDK.TargetManager = class extends Common.Object { |
| 8 constructor() { | 8 constructor() { |
| 9 super(); | 9 super(); |
| 10 /** @type {!Array.<!SDK.Target>} */ | 10 /** @type {!Array.<!SDK.Target>} */ |
| (...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 403 this._targetAgent = parentTarget.targetAgent(); | 403 this._targetAgent = parentTarget.targetAgent(); |
| 404 | 404 |
| 405 /** @type {!Map<string, !SDK.ChildConnection>} */ | 405 /** @type {!Map<string, !SDK.ChildConnection>} */ |
| 406 this._childConnections = new Map(); | 406 this._childConnections = new Map(); |
| 407 | 407 |
| 408 parentTarget.registerTargetDispatcher(this); | 408 parentTarget.registerTargetDispatcher(this); |
| 409 this._targetAgent.invoke_setAutoAttach({autoAttach: true, waitForDebuggerOnS
tart: true}); | 409 this._targetAgent.invoke_setAutoAttach({autoAttach: true, waitForDebuggerOnS
tart: true}); |
| 410 if (Runtime.experiments.isEnabled('autoAttachToCrossProcessSubframes')) | 410 if (Runtime.experiments.isEnabled('autoAttachToCrossProcessSubframes')) |
| 411 this._targetAgent.setAttachToFrames(true); | 411 this._targetAgent.setAttachToFrames(true); |
| 412 | 412 |
| 413 if (!parentTarget.parentTarget()) { | 413 if (!parentTarget.parentTarget()) |
| 414 this._targetAgent.setRemoteLocations([{host: 'localhost', port: 9229}]); | |
| 415 this._targetAgent.setDiscoverTargets(true); | 414 this._targetAgent.setDiscoverTargets(true); |
| 415 |
| 416 if (Runtime.queryParam('nodeFrontend') && !this._parentTarget.parentTarget()
) { |
| 417 InspectorFrontendHost.setDevicesUpdatesEnabled(true); |
| 418 InspectorFrontendHost.events.addEventListener( |
| 419 InspectorFrontendHostAPI.Events.DevicesDiscoveryConfigChanged, this._d
evicesDiscoveryConfigChanged, this); |
| 416 } | 420 } |
| 417 } | 421 } |
| 418 | 422 |
| 419 /** | 423 /** |
| 424 * @param {!Common.Event} event |
| 425 */ |
| 426 _devicesDiscoveryConfigChanged(event) { |
| 427 var config = /** @type {!Adb.Config} */ (event.data); |
| 428 var locations = []; |
| 429 for (var address of config.networkDiscoveryConfig) { |
| 430 var parts = address.split(':'); |
| 431 var port = parseInt(parts[1], 10); |
| 432 locations.push({host: parts[0] || 'localhost', port: port || 9229}); |
| 433 } |
| 434 this._targetAgent.setRemoteLocations(locations); |
| 435 } |
| 436 |
| 437 /** |
| 420 * @return {!Promise} | 438 * @return {!Promise} |
| 421 */ | 439 */ |
| 422 suspend() { | 440 suspend() { |
| 423 return this._targetAgent.invoke_setAutoAttach({autoAttach: true, waitForDebu
ggerOnStart: false}); | 441 return this._targetAgent.invoke_setAutoAttach({autoAttach: true, waitForDebu
ggerOnStart: false}); |
| 424 } | 442 } |
| 425 | 443 |
| 426 /** | 444 /** |
| 427 * @return {!Promise} | 445 * @return {!Promise} |
| 428 */ | 446 */ |
| 429 resume() { | 447 resume() { |
| 430 return this._targetAgent.invoke_setAutoAttach({autoAttach: true, waitForDebu
ggerOnStart: true}); | 448 return this._targetAgent.invoke_setAutoAttach({autoAttach: true, waitForDebu
ggerOnStart: true}); |
| 431 } | 449 } |
| 432 | 450 |
| 433 dispose() { | 451 dispose() { |
| 452 if (Runtime.queryParam('nodeFrontend') && !this._parentTarget.parentTarget()
) { |
| 453 InspectorFrontendHost.events.removeEventListener( |
| 454 InspectorFrontendHostAPI.Events.DevicesDiscoveryConfigChanged, this._d
evicesDiscoveryConfigChanged, this); |
| 455 } |
| 456 |
| 434 // TODO(dgozman): this is O(n^2) when removing main target. | 457 // TODO(dgozman): this is O(n^2) when removing main target. |
| 435 var childTargets = this._targetManager._targets.filter(child => child.parent
Target() === this._parentTarget); | 458 var childTargets = this._targetManager._targets.filter(child => child.parent
Target() === this._parentTarget); |
| 436 for (var child of childTargets) | 459 for (var child of childTargets) |
| 437 this.detachedFromTarget(child.id()); | 460 this.detachedFromTarget(child.id()); |
| 438 } | 461 } |
| 439 | 462 |
| 440 /** | 463 /** |
| 441 * @param {string} type | 464 * @param {string} type |
| 442 * @return {number} | 465 * @return {number} |
| 443 */ | 466 */ |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 501 this._createChildConnection.bind(this, this._targetAgent, targetInfo.tar
getId), this._parentTarget); | 524 this._createChildConnection.bind(this, this._targetAgent, targetInfo.tar
getId), this._parentTarget); |
| 502 target[SDK.TargetManager._isWorkerSymbol] = targetInfo.type === 'worker'; | 525 target[SDK.TargetManager._isWorkerSymbol] = targetInfo.type === 'worker'; |
| 503 | 526 |
| 504 // Only pause the new worker if debugging SW - we are going through the paus
e on start checkbox. | 527 // Only pause the new worker if debugging SW - we are going through the paus
e on start checkbox. |
| 505 if (!this._parentTarget.parentTarget() && Runtime.queryParam('isSharedWorker
') && waitingForDebugger) { | 528 if (!this._parentTarget.parentTarget() && Runtime.queryParam('isSharedWorker
') && waitingForDebugger) { |
| 506 var debuggerModel = target.model(SDK.DebuggerModel); | 529 var debuggerModel = target.model(SDK.DebuggerModel); |
| 507 if (debuggerModel) | 530 if (debuggerModel) |
| 508 debuggerModel.pause(); | 531 debuggerModel.pause(); |
| 509 } | 532 } |
| 510 target.runtimeAgent().runIfWaitingForDebugger(); | 533 target.runtimeAgent().runIfWaitingForDebugger(); |
| 534 |
| 535 if (Runtime.queryParam('nodeFrontend')) |
| 536 InspectorFrontendHost.bringToFront(); |
| 511 } | 537 } |
| 512 | 538 |
| 513 /** | 539 /** |
| 514 * @override | 540 * @override |
| 515 * @param {string} childTargetId | 541 * @param {string} childTargetId |
| 516 */ | 542 */ |
| 517 detachedFromTarget(childTargetId) { | 543 detachedFromTarget(childTargetId) { |
| 518 this._childConnections.get(childTargetId)._onDisconnect.call(null, 'target t
erminated'); | 544 this._childConnections.get(childTargetId)._onDisconnect.call(null, 'target t
erminated'); |
| 519 this._childConnections.delete(childTargetId); | 545 this._childConnections.delete(childTargetId); |
| 520 } | 546 } |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 618 /** | 644 /** |
| 619 * @param {!T} model | 645 * @param {!T} model |
| 620 */ | 646 */ |
| 621 modelRemoved(model) {}, | 647 modelRemoved(model) {}, |
| 622 }; | 648 }; |
| 623 | 649 |
| 624 /** | 650 /** |
| 625 * @type {!SDK.TargetManager} | 651 * @type {!SDK.TargetManager} |
| 626 */ | 652 */ |
| 627 SDK.targetManager = new SDK.TargetManager(); | 653 SDK.targetManager = new SDK.TargetManager(); |
| OLD | NEW |