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

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

Issue 2431223003: [DevTools]: Require explicit connection (Closed)
Patch Set: Code review comments were addressed Created 4 years, 1 month 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/devtools/front_end/sdk/SubTargetsManager.js
diff --git a/third_party/WebKit/Source/devtools/front_end/sdk/SubTargetsManager.js b/third_party/WebKit/Source/devtools/front_end/sdk/SubTargetsManager.js
index fdd1dabedf4e30b7d0e3e225a645e7a6be93b0b2..0c35bbd86789770fd15b84c1a1520784f8339fbc 100644
--- a/third_party/WebKit/Source/devtools/front_end/sdk/SubTargetsManager.js
+++ b/third_party/WebKit/Source/devtools/front_end/sdk/SubTargetsManager.js
@@ -18,6 +18,8 @@ WebInspector.SubTargetsManager = function(target)
this._attachedTargets = new Map();
/** @type {!Map<string, !WebInspector.SubTargetConnection>} */
this._connections = new Map();
+ /** @type {!Map<string, !WebInspector.PendingSubTarget>} */
+ this._pendingSubTargets = new Map();
this._agent.setAutoAttach(true /* autoAttach */, true /* waitForDebuggerOnStart */);
if (Runtime.experiments.isEnabled("autoAttachToCrossProcessSubframes"))
@@ -35,6 +37,8 @@ WebInspector.SubTargetsManager = function(target)
WebInspector.SubTargetsManager.Events = {
SubTargetAdded: Symbol("SubTargetAdded"),
SubTargetRemoved: Symbol("SubTargetRemoved"),
+ SubTargetAttached: Symbol("SubTargetAttached"),
+ SubTargetDetached: Symbol("SubTargetDetached"),
};
WebInspector.SubTargetsManager._InfoSymbol = Symbol("SubTargetInfo");
@@ -69,12 +73,10 @@ WebInspector.SubTargetsManager.prototype = {
*/
dispose: function()
{
- for (var connection of this._connections.values()) {
- this._agent.detachFromTarget(connection._targetId);
dgozman 2016/11/01 22:07:39 I think it was important to send this to the agent
eostroukhov 2016/11/02 21:55:53 It does so in the _detachedFromTarget
- connection._onDisconnect.call(null, "disposed");
- }
- this._connections.clear();
- this._attachedTargets.clear();
+ for (var attachedTargetId of this._attachedTargets.keys())
+ this._detachedFromTarget(attachedTargetId);
+ for (var pendingConnectionId of this._pendingSubTargets.keys())
+ this._targetDestroyed(pendingConnectionId);
},
/**
@@ -169,8 +171,13 @@ WebInspector.SubTargetsManager.prototype = {
if (mainIsServiceWorker && waitingForDebugger)
target.debuggerAgent().pause();
target.runtimeAgent().runIfWaitingForDebugger();
-
- this.dispatchEventToListeners(WebInspector.SubTargetsManager.Events.SubTargetAdded, target);
+ var connection = this._pendingSubTargets.get(targetInfo.id);
+ if (!connection) {
+ this._targetCreated(targetInfo);
+ connection = this._pendingSubTargets.get(targetInfo.id);
+ }
+ connection.notifyAttached(target);
+ this.dispatchEventToListeners(WebInspector.SubTargetsManager.Events.SubTargetAttached, connection);
},
/**
@@ -192,11 +199,10 @@ WebInspector.SubTargetsManager.prototype = {
{
var target = this._attachedTargets.get(targetId);
this._attachedTargets.delete(targetId);
- this.dispatchEventToListeners(WebInspector.SubTargetsManager.Events.SubTargetRemoved, target);
var connection = this._connections.get(targetId);
- if (connection)
- connection._onDisconnect.call(null, "target terminated");
+ connection._onDisconnect.call(null, "target terminated");
this._connections.delete(targetId);
+ this.dispatchEventToListeners(WebInspector.SubTargetsManager.Events.SubTargetDetached, this._pendingSubTargets.get(targetId));
},
/**
@@ -215,9 +221,11 @@ WebInspector.SubTargetsManager.prototype = {
*/
_targetCreated: function(targetInfo)
{
- if (targetInfo.type !== "node")
- return;
- this._agent.attachToTarget(targetInfo.id);
+ var connection = this._pendingSubTargets.get(targetInfo.id);
+ console.assert(!connection);
+ connection = new WebInspector.PendingSubTarget(targetInfo.id, targetInfo.title, targetInfo.type === "node", this);
+ this._pendingSubTargets.set(targetInfo.id, connection);
+ this.dispatchEventToListeners(WebInspector.SubTargetsManager.Events.SubTargetAdded, connection);
},
/**
@@ -225,7 +233,19 @@ WebInspector.SubTargetsManager.prototype = {
*/
_targetDestroyed: function(targetId)
{
- // All the work is done in _detachedFromTarget.
+ var connection = this._pendingSubTargets.get(targetId);
+ if (!connection)
+ return;
+ this._pendingSubTargets.delete(targetId);
+ this.dispatchEventToListeners(WebInspector.SubTargetsManager.Events.SubTargetRemoved, connection);
+ },
+
+ /**
+ * @return {!Array<!WebInspector.PendingSubTarget>}
+ */
+ subTargets: function()
+ {
+ return this._pendingSubTargets.valuesArray();
},
/**
@@ -250,6 +270,16 @@ WebInspector.SubTargetsManager.prototype = {
};
/**
+ * @param {!WebInspector.Target} target
+ * @return {?WebInspector.SubTargetsManager}
+ */
+WebInspector.SubTargetsManager.fromTarget = function(target)
+{
+ return /** @type {?WebInspector.SubTargetsManager} */ (target.model(WebInspector.SubTargetsManager));
+};
+
+
+/**
* @constructor
* @implements {TargetAgent.Dispatcher}
* @param {!WebInspector.SubTargetsManager} manager
@@ -360,3 +390,94 @@ WebInspector.TargetInfo = function(payload)
else
this.title = WebInspector.UIString("Worker: %s", this.url);
};
+
+/**
+ * @constructor
+ * @param {string} id
+ * @param {string} title
+ * @param {boolean} isRemote
+ * @param {?WebInspector.SubTargetsManager} manager
+ */
+WebInspector.PendingSubTarget = function(id, title, isRemote, manager)
+{
+ this._id = id;
+ this._title = title;
+ this._isRemote = isRemote;
+ this._manager = manager;
+ /** @type {?Promise} */
+ this._connectPromise = null;
+ /** @type {?Function} */
+ this._attachedCallback = null;
+};
+
+WebInspector.PendingSubTarget.prototype = {
+ /**
+ * @return {string}
+ */
+ id: function()
+ {
+ return this._id;
+ },
+
+ /**
+ * @return {?WebInspector.Target}
+ */
+ target: function()
+ {
+ if (!this._manager)
+ return null;
+ return this._manager.targetForId(this.id());
+ },
+
+ /**
+ * @return {string}
+ */
+ name: function()
+ {
+ return this._title;
+ },
+
+ /**
+ * @return {!Promise}
+ */
+ connect: function()
+ {
+ if (!this._manager)
+ return Promise.reject();
+ if (this._connectPromise)
+ return this._connectPromise;
+ if (this.target())
+ return Promise.resolve(this.target());
+ this._connectPromise = new Promise(resolve => {
+ this._attachedCallback = resolve;
+ this._manager._agent.attachToTarget(this.id());
+ });
+ return this._connectPromise;
+ },
+
+ disconnect: function()
+ {
+ if (!this._manager)
+ return;
+ this._manager._agent.detachFromTarget(this.id());
+ },
+
+ /**
+ * @param {!WebInspector.Target} target
+ */
+ notifyAttached: function(target)
+ {
+ if (this._attachedCallback)
+ this._attachedCallback(target);
+ this._connectPromise = null;
+ this._attachedCallback = null;
+ },
+
+ /**
+ * @return {boolean}
+ */
+ isRemote: function()
dgozman 2016/11/01 22:07:39 canConnect?
eostroukhov 2016/11/02 21:55:53 Done.
+ {
+ return this._isRemote;
+ },
+};

Powered by Google App Engine
This is Rietveld 408576698