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

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

Issue 2951913002: [DevTools] Support multiple sessions in Target domain (Closed)
Patch Set: simplify Created 3 years, 5 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 /* 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 439 matching lines...) Expand 10 before | Expand all | Expand 10 after
450 resume() { 450 resume() {
451 return this._targetAgent.invoke_setAutoAttach({autoAttach: true, waitForDebu ggerOnStart: true}); 451 return this._targetAgent.invoke_setAutoAttach({autoAttach: true, waitForDebu ggerOnStart: true});
452 } 452 }
453 453
454 dispose() { 454 dispose() {
455 if (Runtime.queryParam('nodeFrontend') && !this._parentTarget.parentTarget() ) { 455 if (Runtime.queryParam('nodeFrontend') && !this._parentTarget.parentTarget() ) {
456 InspectorFrontendHost.events.removeEventListener( 456 InspectorFrontendHost.events.removeEventListener(
457 InspectorFrontendHostAPI.Events.DevicesDiscoveryConfigChanged, this._d evicesDiscoveryConfigChanged, this); 457 InspectorFrontendHostAPI.Events.DevicesDiscoveryConfigChanged, this._d evicesDiscoveryConfigChanged, this);
458 } 458 }
459 459
460 // TODO(dgozman): this is O(n^2) when removing main target. 460 for (var sessionId of Array.from(this._childConnections.keys()))
caseq 2017/06/27 18:29:30 drop Array.from()
461 var childTargets = this._targetManager._targets.filter(child => child.parent Target() === this._parentTarget); 461 this.detachedFromTarget(sessionId);
462 for (var child of childTargets)
463 this.detachedFromTarget(child.id());
464 } 462 }
465 463
466 /** 464 /**
467 * @param {string} type 465 * @param {string} type
468 * @return {number} 466 * @return {number}
469 */ 467 */
470 _capabilitiesForType(type) { 468 _capabilitiesForType(type) {
471 if (type === 'worker') 469 if (type === 'worker')
472 return SDK.Target.Capability.JS | SDK.Target.Capability.Log; 470 return SDK.Target.Capability.JS | SDK.Target.Capability.Log;
473 if (type === 'service_worker') 471 if (type === 'service_worker')
(...skipping 29 matching lines...) Expand all
503 */ 501 */
504 targetDestroyed(targetId) { 502 targetDestroyed(targetId) {
505 if (Runtime.queryParam('nodeFrontend') || !this._targetManager._nodeTargetId s.has(targetId)) 503 if (Runtime.queryParam('nodeFrontend') || !this._targetManager._nodeTargetId s.has(targetId))
506 return; 504 return;
507 this._targetManager._nodeTargetIds.delete(targetId); 505 this._targetManager._nodeTargetIds.delete(targetId);
508 this._targetManager.dispatchEventToListeners(SDK.TargetManager.Events.Availa bleNodeTargetsChanged); 506 this._targetManager.dispatchEventToListeners(SDK.TargetManager.Events.Availa bleNodeTargetsChanged);
509 } 507 }
510 508
511 /** 509 /**
512 * @override 510 * @override
511 * @param {string} sessionId
513 * @param {!Protocol.Target.TargetInfo} targetInfo 512 * @param {!Protocol.Target.TargetInfo} targetInfo
514 * @param {boolean} waitingForDebugger 513 * @param {boolean} waitingForDebugger
515 */ 514 */
516 attachedToTarget(targetInfo, waitingForDebugger) { 515 attachedToTarget(sessionId, targetInfo, waitingForDebugger) {
517 var targetName = ''; 516 var targetName = '';
518 if (targetInfo.type === 'node') { 517 if (targetInfo.type === 'node') {
519 targetName = Common.UIString('Node.js: %s', targetInfo.url); 518 targetName = Common.UIString('Node.js: %s', targetInfo.url);
520 } else if (targetInfo.type !== 'iframe') { 519 } else if (targetInfo.type !== 'iframe') {
521 var parsedURL = targetInfo.url.asParsedURL(); 520 var parsedURL = targetInfo.url.asParsedURL();
522 targetName = 521 targetName =
523 parsedURL ? parsedURL.lastPathComponentWithFragment() : '#' + (++this. _targetManager._lastAnonymousTargetId); 522 parsedURL ? parsedURL.lastPathComponentWithFragment() : '#' + (++this. _targetManager._lastAnonymousTargetId);
524 } 523 }
525 var target = this._targetManager.createTarget( 524 var target = this._targetManager.createTarget(
526 targetInfo.targetId, targetName, this._capabilitiesForType(targetInfo.ty pe), 525 targetInfo.targetId, targetName, this._capabilitiesForType(targetInfo.ty pe),
527 this._createChildConnection.bind(this, this._targetAgent, targetInfo.tar getId), this._parentTarget); 526 this._createChildConnection.bind(this, this._targetAgent, sessionId), th is._parentTarget);
528 527
529 // Only pause the new worker if debugging SW - we are going through the paus e on start checkbox. 528 // Only pause the new worker if debugging SW - we are going through the paus e on start checkbox.
530 if (!this._parentTarget.parentTarget() && Runtime.queryParam('isSharedWorker ') && waitingForDebugger) { 529 if (!this._parentTarget.parentTarget() && Runtime.queryParam('isSharedWorker ') && waitingForDebugger) {
531 var debuggerModel = target.model(SDK.DebuggerModel); 530 var debuggerModel = target.model(SDK.DebuggerModel);
532 if (debuggerModel) 531 if (debuggerModel)
533 debuggerModel.pause(); 532 debuggerModel.pause();
534 } 533 }
535 target.runtimeAgent().runIfWaitingForDebugger(); 534 target.runtimeAgent().runIfWaitingForDebugger();
536 535
537 if (Runtime.queryParam('nodeFrontend')) 536 if (Runtime.queryParam('nodeFrontend'))
538 InspectorFrontendHost.bringToFront(); 537 InspectorFrontendHost.bringToFront();
539 } 538 }
540 539
541 /** 540 /**
542 * @override 541 * @override
543 * @param {string} childTargetId 542 * @param {string} sessionId
544 */ 543 */
545 detachedFromTarget(childTargetId) { 544 detachedFromTarget(sessionId) {
546 this._childConnections.get(childTargetId)._onDisconnect.call(null, 'target t erminated'); 545 this._childConnections.get(sessionId)._onDisconnect.call(null, 'target termi nated');
547 this._childConnections.delete(childTargetId); 546 this._childConnections.delete(sessionId);
548 } 547 }
549 548
550 /** 549 /**
551 * @override 550 * @override
552 * @param {string} childTargetId 551 * @param {string} sessionId
553 * @param {string} message 552 * @param {string} message
554 */ 553 */
555 receivedMessageFromTarget(childTargetId, message) { 554 receivedMessageFromTarget(sessionId, message) {
556 var connection = this._childConnections.get(childTargetId); 555 var connection = this._childConnections.get(sessionId);
557 if (connection) 556 if (connection)
558 connection._onMessage.call(null, message); 557 connection._onMessage.call(null, message);
559 } 558 }
560 559
561 /** 560 /**
562 * @param {!Protocol.TargetAgent} agent 561 * @param {!Protocol.TargetAgent} agent
563 * @param {string} childTargetId 562 * @param {string} sessionId
564 * @param {!Protocol.InspectorBackend.Connection.Params} params 563 * @param {!Protocol.InspectorBackend.Connection.Params} params
565 * @return {!Protocol.InspectorBackend.Connection} 564 * @return {!Protocol.InspectorBackend.Connection}
566 */ 565 */
567 _createChildConnection(agent, childTargetId, params) { 566 _createChildConnection(agent, sessionId, params) {
568 var connection = new SDK.ChildConnection(agent, childTargetId, params); 567 var connection = new SDK.ChildConnection(agent, sessionId, params);
569 this._childConnections.set(childTargetId, connection); 568 this._childConnections.set(sessionId, connection);
570 return connection; 569 return connection;
571 } 570 }
572 }; 571 };
573 572
574 /** 573 /**
575 * @implements {Protocol.InspectorBackend.Connection} 574 * @implements {Protocol.InspectorBackend.Connection}
576 */ 575 */
577 SDK.ChildConnection = class { 576 SDK.ChildConnection = class {
578 /** 577 /**
579 * @param {!Protocol.TargetAgent} agent 578 * @param {!Protocol.TargetAgent} agent
580 * @param {string} targetId 579 * @param {string} sessionId
581 * @param {!Protocol.InspectorBackend.Connection.Params} params 580 * @param {!Protocol.InspectorBackend.Connection.Params} params
582 */ 581 */
583 constructor(agent, targetId, params) { 582 constructor(agent, sessionId, params) {
584 this._agent = agent; 583 this._agent = agent;
585 this._targetId = targetId; 584 this._sessionId = sessionId;
586 this._onMessage = params.onMessage; 585 this._onMessage = params.onMessage;
587 this._onDisconnect = params.onDisconnect; 586 this._onDisconnect = params.onDisconnect;
588 } 587 }
589 588
590 /** 589 /**
591 * @override 590 * @override
592 * @param {string} message 591 * @param {string} message
593 */ 592 */
594 sendMessage(message) { 593 sendMessage(message) {
595 this._agent.sendMessageToTarget(this._targetId, message); 594 this._agent.sendMessageToTarget(this._sessionId, message);
596 } 595 }
597 596
598 /** 597 /**
599 * @override 598 * @override
600 * @return {!Promise} 599 * @return {!Promise}
601 */ 600 */
602 disconnect() { 601 disconnect() {
603 throw 'Not implemented'; 602 throw 'Not implemented';
604 } 603 }
605 }; 604 };
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
644 /** 643 /**
645 * @param {!T} model 644 * @param {!T} model
646 */ 645 */
647 modelRemoved(model) {}, 646 modelRemoved(model) {},
648 }; 647 };
649 648
650 /** 649 /**
651 * @type {!SDK.TargetManager} 650 * @type {!SDK.TargetManager}
652 */ 651 */
653 SDK.targetManager = new SDK.TargetManager(); 652 SDK.targetManager = new SDK.TargetManager();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698