| 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) |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 connection of this._connections.values()) { |
| 71 connection.close(); | 71 this._agent.detachFromTarget(connection._targetId); |
| 72 connection._onDisconnect.call(null, "disposed"); |
| 73 } |
| 72 this._connections.clear(); | 74 this._connections.clear(); |
| 73 this._attachedTargets.clear(); | 75 this._attachedTargets.clear(); |
| 74 }, | 76 }, |
| 75 | 77 |
| 76 /** | 78 /** |
| 77 * @param {!TargetAgent.TargetID} targetId | 79 * @param {!TargetAgent.TargetID} targetId |
| 78 */ | 80 */ |
| 79 activateTarget: function(targetId) | 81 activateTarget: function(targetId) |
| 80 { | 82 { |
| 81 this._agent.activateTarget(targetId); | 83 this._agent.activateTarget(targetId); |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 return WebInspector.Target.Capability.JS; | 144 return WebInspector.Target.Capability.JS; |
| 143 return 0; | 145 return 0; |
| 144 }, | 146 }, |
| 145 | 147 |
| 146 /** | 148 /** |
| 147 * @param {!WebInspector.TargetInfo} targetInfo | 149 * @param {!WebInspector.TargetInfo} targetInfo |
| 148 * @param {boolean} waitingForDebugger | 150 * @param {boolean} waitingForDebugger |
| 149 */ | 151 */ |
| 150 _attachedToTarget: function(targetInfo, waitingForDebugger) | 152 _attachedToTarget: function(targetInfo, waitingForDebugger) |
| 151 { | 153 { |
| 152 var connection = new WebInspector.SubTargetConnection(this._agent, targe
tInfo.id); | |
| 153 this._connections.set(targetInfo.id, connection); | |
| 154 | |
| 155 var targetName = ""; | 154 var targetName = ""; |
| 156 if (targetInfo.type === "node") { | 155 if (targetInfo.type === "node") { |
| 157 targetName = targetInfo.title; | 156 targetName = targetInfo.title; |
| 158 } else if (targetInfo.type !== "iframe") { | 157 } else if (targetInfo.type !== "iframe") { |
| 159 var parsedURL = targetInfo.url.asParsedURL(); | 158 var parsedURL = targetInfo.url.asParsedURL(); |
| 160 targetName = parsedURL ? parsedURL.lastPathComponentWithFragment() :
"#" + (++this._lastAnonymousTargetId); | 159 targetName = parsedURL ? parsedURL.lastPathComponentWithFragment() :
"#" + (++this._lastAnonymousTargetId); |
| 161 } | 160 } |
| 162 var target = WebInspector.targetManager.createTarget(targetName, this._c
apabilitiesForType(targetInfo.type), connection, this.target()); | 161 var target = WebInspector.targetManager.createTarget(targetName, this._c
apabilitiesForType(targetInfo.type), this._createConnection.bind(this, targetInf
o.id), this.target()); |
| 163 target[WebInspector.SubTargetsManager._InfoSymbol] = targetInfo; | 162 target[WebInspector.SubTargetsManager._InfoSymbol] = targetInfo; |
| 164 this._attachedTargets.set(targetInfo.id, target); | 163 this._attachedTargets.set(targetInfo.id, target); |
| 165 | 164 |
| 166 // Only pause new worker if debugging SW - we are going through the paus
e on start checkbox. | 165 // 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(); | 166 var mainIsServiceWorker = !this.target().parentTarget() && this.target()
.hasWorkerCapability() && !this.target().hasBrowserCapability(); |
| 168 if (mainIsServiceWorker && waitingForDebugger) | 167 if (mainIsServiceWorker && waitingForDebugger) |
| 169 target.debuggerAgent().pause(); | 168 target.debuggerAgent().pause(); |
| 170 target.runtimeAgent().runIfWaitingForDebugger(); | 169 target.runtimeAgent().runIfWaitingForDebugger(); |
| 171 | 170 |
| 172 this.dispatchEventToListeners(WebInspector.SubTargetsManager.Events.SubT
argetAdded, target); | 171 this.dispatchEventToListeners(WebInspector.SubTargetsManager.Events.SubT
argetAdded, target); |
| 173 }, | 172 }, |
| 174 | 173 |
| 175 /** | 174 /** |
| 176 * @param {string} targetId | 175 * @param {string} targetId |
| 176 * @param {!InspectorBackendClass.Connection.Params} params |
| 177 * @return {!InspectorBackendClass.Connection} |
| 178 */ |
| 179 _createConnection: function(targetId, params) |
| 180 { |
| 181 var connection = new WebInspector.SubTargetConnection(this._agent, targe
tId, params); |
| 182 this._connections.set(targetId, connection); |
| 183 return connection; |
| 184 }, |
| 185 |
| 186 /** |
| 187 * @param {string} targetId |
| 177 */ | 188 */ |
| 178 _detachedFromTarget: function(targetId) | 189 _detachedFromTarget: function(targetId) |
| 179 { | 190 { |
| 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); | 191 var target = this._attachedTargets.get(targetId); |
| 185 this._attachedTargets.delete(targetId); | 192 this._attachedTargets.delete(targetId); |
| 186 this.dispatchEventToListeners(WebInspector.SubTargetsManager.Events.SubT
argetRemoved, target); | 193 this.dispatchEventToListeners(WebInspector.SubTargetsManager.Events.SubT
argetRemoved, target); |
| 194 var connection = this._connections.get(targetId); |
| 195 if (connection) |
| 196 connection._onDisconnect.call(null, "target terminated"); |
| 197 this._connections.delete(targetId); |
| 187 }, | 198 }, |
| 188 | 199 |
| 189 /** | 200 /** |
| 190 * @param {string} targetId | 201 * @param {string} targetId |
| 191 * @param {string} message | 202 * @param {string} message |
| 192 */ | 203 */ |
| 193 _receivedMessageFromTarget: function(targetId, message) | 204 _receivedMessageFromTarget: function(targetId, message) |
| 194 { | 205 { |
| 195 var connection = this._connections.get(targetId); | 206 var connection = this._connections.get(targetId); |
| 196 if (connection) | 207 if (connection) |
| 197 connection.dispatch(message); | 208 connection._onMessage.call(null, message); |
| 198 }, | 209 }, |
| 199 | 210 |
| 200 /** | 211 /** |
| 201 * @param {!WebInspector.TargetInfo} targetInfo | 212 * @param {!WebInspector.TargetInfo} targetInfo |
| 202 */ | 213 */ |
| 203 _targetCreated: function(targetInfo) | 214 _targetCreated: function(targetInfo) |
| 204 { | 215 { |
| 205 if (targetInfo.type !== "node") | 216 if (targetInfo.type !== "node") |
| 206 return; | 217 return; |
| 207 this._agent.attachToTarget(targetInfo.id); | 218 this._agent.attachToTarget(targetInfo.id); |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 272 * @param {string} message | 283 * @param {string} message |
| 273 */ | 284 */ |
| 274 receivedMessageFromTarget: function(targetId, message) | 285 receivedMessageFromTarget: function(targetId, message) |
| 275 { | 286 { |
| 276 this._manager._receivedMessageFromTarget(targetId, message); | 287 this._manager._receivedMessageFromTarget(targetId, message); |
| 277 } | 288 } |
| 278 }; | 289 }; |
| 279 | 290 |
| 280 /** | 291 /** |
| 281 * @constructor | 292 * @constructor |
| 282 * @extends {InspectorBackendClass.Connection} | 293 * @implements {InspectorBackendClass.Connection} |
| 283 * @param {!Protocol.TargetAgent} agent | 294 * @param {!Protocol.TargetAgent} agent |
| 284 * @param {string} targetId | 295 * @param {string} targetId |
| 296 * @param {!InspectorBackendClass.Connection.Params} params |
| 285 */ | 297 */ |
| 286 WebInspector.SubTargetConnection = function(agent, targetId) | 298 WebInspector.SubTargetConnection = function(agent, targetId, params) |
| 287 { | 299 { |
| 288 InspectorBackendClass.Connection.call(this); | |
| 289 this._agent = agent; | 300 this._agent = agent; |
| 290 this._targetId = targetId; | 301 this._targetId = targetId; |
| 302 this._onMessage = params.onMessage; |
| 303 this._onDisconnect = params.onDisconnect; |
| 291 }; | 304 }; |
| 292 | 305 |
| 293 WebInspector.SubTargetConnection.prototype = { | 306 WebInspector.SubTargetConnection.prototype = { |
| 294 /** | 307 /** |
| 295 * @override | 308 * @override |
| 296 * @param {!Object} messageObject | 309 * @param {string} message |
| 297 */ | 310 */ |
| 298 sendMessage: function(messageObject) | 311 sendMessage: function(message) |
| 299 { | 312 { |
| 300 this._agent.sendMessageToTarget(this._targetId, JSON.stringify(messageOb
ject)); | 313 this._agent.sendMessageToTarget(this._targetId, message); |
| 301 }, | 314 }, |
| 302 | 315 |
| 303 /** | 316 /** |
| 304 * @override | 317 * @override |
| 318 * @return {!Promise} |
| 305 */ | 319 */ |
| 306 forceClose: function() | 320 disconnect: function() |
| 307 { | 321 { |
| 308 this._agent.detachFromTarget(this._targetId); | 322 throw new Error("Not implemented"); |
| 309 }, | 323 }, |
| 310 | |
| 311 _reportClosed: function() | |
| 312 { | |
| 313 this.connectionClosed("target_terminated"); | |
| 314 }, | |
| 315 | |
| 316 __proto__: InspectorBackendClass.Connection.prototype | |
| 317 }; | 324 }; |
| 318 | 325 |
| 319 /** | 326 /** |
| 320 * @constructor | 327 * @constructor |
| 321 * @param {!TargetAgent.TargetInfo} payload | 328 * @param {!TargetAgent.TargetInfo} payload |
| 322 */ | 329 */ |
| 323 WebInspector.TargetInfo = function(payload) | 330 WebInspector.TargetInfo = function(payload) |
| 324 { | 331 { |
| 325 this.id = payload.targetId; | 332 this.id = payload.targetId; |
| 326 this.url = payload.url; | 333 this.url = payload.url; |
| 327 this.type = payload.type; | 334 this.type = payload.type; |
| 328 if (this.type !== "page" && this.type !== "iframe") { | 335 if (this.type !== "page" && this.type !== "iframe") { |
| 329 this.title = WebInspector.UIString("Worker: %s", this.url); | 336 this.title = WebInspector.UIString("Worker: %s", this.url); |
| 330 this.canActivate = false; | 337 this.canActivate = false; |
| 331 } else { | 338 } else { |
| 332 this.title = payload.title; | 339 this.title = payload.title; |
| 333 this.canActivate = true; | 340 this.canActivate = true; |
| 334 } | 341 } |
| 335 }; | 342 }; |
| OLD | NEW |