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.TargetInfo>} */ |
| 18 this._allTargets = new Map(); |
| 19 |
17 /** @type {!Map<string, !WebInspector.Target>} */ | 20 /** @type {!Map<string, !WebInspector.Target>} */ |
18 this._targets = new Map(); | 21 this._attachedTargets = new Map(); |
19 /** @type {!Map<string, !WebInspector.SubTargetConnection>} */ | 22 /** @type {!Map<string, !WebInspector.SubTargetConnection>} */ |
20 this._connections = new Map(); | 23 this._connections = new Map(); |
21 | 24 |
22 this._agent.setWaitForDebuggerOnStart(true); | 25 this._agent.setAutoAttach(true /* autoAttach */, true /* waitForDebuggerOnSt
art */); |
23 this._agent.setAttachToFrames(Runtime.experiments.isEnabled("autoAttachToCro
ssProcessSubframes")); | 26 this._agent.setAttachToFrames(Runtime.experiments.isEnabled("autoAttachToCro
ssProcessSubframes")); |
24 this._agent.enable(); | 27 this._agent.enable(); |
25 } | 28 } |
26 | 29 |
27 /** @enum {symbol} */ | 30 /** @enum {symbol} */ |
28 WebInspector.SubTargetsManager.Events = { | 31 WebInspector.SubTargetsManager.Events = { |
29 SubTargetAdded: Symbol("SubTargetAdded"), | 32 SubTargetAdded: Symbol("SubTargetAdded"), |
30 SubTargetRemoved: Symbol("SubTargetRemoved"), | 33 SubTargetRemoved: Symbol("SubTargetRemoved"), |
31 } | 34 } |
32 | 35 |
33 WebInspector.SubTargetsManager._TypeSymbol = Symbol("SubTargetType"); | 36 WebInspector.SubTargetsManager._InfoSymbol = Symbol("SubTargetInfo"); |
34 WebInspector.SubTargetsManager._IdSymbol = Symbol("SubTargetId"); | |
35 | 37 |
36 WebInspector.SubTargetsManager.prototype = { | 38 WebInspector.SubTargetsManager.prototype = { |
37 /** | 39 /** |
38 * @override | 40 * @override |
39 * @return {!Promise} | 41 * @return {!Promise} |
40 */ | 42 */ |
41 suspendModel: function() | 43 suspendModel: function() |
42 { | 44 { |
43 var fulfill; | 45 var fulfill; |
44 var promise = new Promise(f => fulfill = f); | 46 var promise = new Promise(f => fulfill = f); |
45 this._agent.setWaitForDebuggerOnStart(false, fulfill); | 47 this._agent.setAutoAttach(true /* autoAttach */, false /* waitForDebugge
rOnStart */, fulfill); |
46 return promise; | 48 return promise; |
47 }, | 49 }, |
48 | 50 |
49 /** | 51 /** |
50 * @override | 52 * @override |
51 * @return {!Promise} | 53 * @return {!Promise} |
52 */ | 54 */ |
53 resumeModel: function() | 55 resumeModel: function() |
54 { | 56 { |
55 var fulfill; | 57 var fulfill; |
56 var promise = new Promise(f => fulfill = f); | 58 var promise = new Promise(f => fulfill = f); |
57 this._agent.setWaitForDebuggerOnStart(true, fulfill); | 59 this._agent.setAutoAttach(true /* autoAttach */, true /* waitForDebugger
OnStart */, fulfill); |
58 return promise; | 60 return promise; |
59 }, | 61 }, |
60 | 62 |
61 /** | 63 /** |
62 * @override | 64 * @override |
63 */ | 65 */ |
64 dispose: function() | 66 dispose: function() |
65 { | 67 { |
66 for (var connection of this._connections.values()) | 68 for (var connection of this._connections.values()) |
67 connection._close(); | 69 connection._close(); |
68 this._connections.clear(); | 70 this._connections.clear(); |
69 this._targets.clear(); | 71 this._attachedTargets.clear(); |
70 }, | 72 }, |
71 | 73 |
72 /** | 74 /** |
73 * @param {!TargetAgent.TargetID} targetId | 75 * @param {!TargetAgent.TargetID} targetId |
74 */ | 76 */ |
75 activateTarget: function(targetId) | 77 activateTarget: function(targetId) |
76 { | 78 { |
77 this._agent.activateTarget(targetId); | 79 this._agent.activateTarget(targetId); |
78 }, | 80 }, |
79 | 81 |
(...skipping 21 matching lines...) Expand all Loading... |
101 } | 103 } |
102 this._agent.getTargetInfo(targetId, innerCallback); | 104 this._agent.getTargetInfo(targetId, innerCallback); |
103 }, | 105 }, |
104 | 106 |
105 /** | 107 /** |
106 * @param {string} targetId | 108 * @param {string} targetId |
107 * @return {?WebInspector.Target} | 109 * @return {?WebInspector.Target} |
108 */ | 110 */ |
109 targetForId: function(targetId) | 111 targetForId: function(targetId) |
110 { | 112 { |
111 return this._targets.get(targetId) || null; | 113 return this._attachedTargets.get(targetId) || null; |
112 }, | 114 }, |
113 | 115 |
114 /** | 116 /** |
115 * @param {!WebInspector.Target} target | 117 * @param {!WebInspector.Target} target |
116 * @return {?string} | 118 * @return {?WebInspector.TargetInfo} |
117 */ | 119 */ |
118 targetId: function(target) | 120 targetInfo: function(target) |
119 { | 121 { |
120 return target[WebInspector.SubTargetsManager._IdSymbol] || null; | 122 return target[WebInspector.SubTargetsManager._InfoSymbol] || null; |
121 }, | 123 }, |
122 | 124 |
123 /** | 125 /** |
124 * @param {!WebInspector.Target} target | |
125 * @return {?string} | |
126 */ | |
127 targetType: function(target) | |
128 { | |
129 return target[WebInspector.SubTargetsManager._TypeSymbol] || null; | |
130 }, | |
131 | |
132 /** | |
133 * @param {string} type | 126 * @param {string} type |
134 * @return {number} | 127 * @return {number} |
135 */ | 128 */ |
136 _capabilitiesForType: function(type) | 129 _capabilitiesForType: function(type) |
137 { | 130 { |
138 if (type === "worker") | 131 if (type === "worker") |
139 return WebInspector.Target.Capability.JS | WebInspector.Target.Capab
ility.Log; | 132 return WebInspector.Target.Capability.JS | WebInspector.Target.Capab
ility.Log; |
140 if (type === "service_worker") | 133 if (type === "service_worker") |
141 return WebInspector.Target.Capability.Log | WebInspector.Target.Capa
bility.Network | WebInspector.Target.Capability.Worker; | 134 return WebInspector.Target.Capability.Log | WebInspector.Target.Capa
bility.Network | WebInspector.Target.Capability.Worker; |
142 if (type === "iframe") | 135 if (type === "iframe") |
143 return WebInspector.Target.Capability.Browser | WebInspector.Target.
Capability.DOM | | 136 return WebInspector.Target.Capability.Browser | WebInspector.Target.
Capability.DOM | |
144 WebInspector.Target.Capability.JS | WebInspector.Target.Capabili
ty.Log | | 137 WebInspector.Target.Capability.JS | WebInspector.Target.Capabili
ty.Log | |
145 WebInspector.Target.Capability.Network | WebInspector.Target.Cap
ability.Worker; | 138 WebInspector.Target.Capability.Network | WebInspector.Target.Cap
ability.Worker; |
146 return 0; | 139 return 0; |
147 }, | 140 }, |
148 | 141 |
149 /** | 142 /** |
| 143 * @param {!WebInspector.TargetInfo} targetInfo |
| 144 */ |
| 145 _targetCreated: function(targetInfo) |
| 146 { |
| 147 console.assert(!this._allTargets.has(targetInfo.id)); |
| 148 console.assert(!this._attachedTargets.has(targetInfo.id)); |
| 149 this._allTargets.set(targetInfo.id, targetInfo); |
| 150 }, |
| 151 |
| 152 /** |
150 * @param {string} targetId | 153 * @param {string} targetId |
151 * @param {string} type | 154 */ |
152 * @param {string} url | 155 _targetRemoved: function(targetId) |
| 156 { |
| 157 console.assert(this._allTargets.has(targetId)); |
| 158 console.assert(!this._attachedTargets.has(targetId)); |
| 159 this._allTargets.delete(targetId); |
| 160 }, |
| 161 |
| 162 /** |
| 163 * @param {string} targetId |
153 * @param {boolean} waitingForDebugger | 164 * @param {boolean} waitingForDebugger |
154 */ | 165 */ |
155 _targetCreated: function(targetId, type, url, waitingForDebugger) | 166 _attachedToTarget: function(targetId, waitingForDebugger) |
156 { | 167 { |
| 168 var targetInfo = /** @type {!WebInspector.TargetInfo} */ (this._allTarge
ts.get(targetId)); |
| 169 |
157 var connection = new WebInspector.SubTargetConnection(this._agent, targe
tId); | 170 var connection = new WebInspector.SubTargetConnection(this._agent, targe
tId); |
158 this._connections.set(targetId, connection); | 171 this._connections.set(targetId, connection); |
159 | 172 |
160 var targetName = ""; | 173 var targetName = ""; |
161 if (type !== "iframe") { | 174 if (targetInfo.type !== "iframe") { |
162 var parsedURL = url.asParsedURL(); | 175 var parsedURL = targetInfo.url.asParsedURL(); |
163 targetName = parsedURL ? parsedURL.lastPathComponentWithFragment() :
"#" + (++this._lastAnonymousTargetId); | 176 targetName = parsedURL ? parsedURL.lastPathComponentWithFragment() :
"#" + (++this._lastAnonymousTargetId); |
164 } | 177 } |
165 var target = WebInspector.targetManager.createTarget(targetName, this._c
apabilitiesForType(type), connection, this.target()); | 178 var target = WebInspector.targetManager.createTarget(targetName, this._c
apabilitiesForType(targetInfo.type), connection, this.target()); |
166 target[WebInspector.SubTargetsManager._TypeSymbol] = type; | 179 target[WebInspector.SubTargetsManager._InfoSymbol] = targetInfo; |
167 target[WebInspector.SubTargetsManager._IdSymbol] = targetId; | 180 this._attachedTargets.set(targetId, target); |
168 this._targets.set(targetId, target); | |
169 | 181 |
170 // Only pause new worker if debugging SW - we are going through the paus
e on start checkbox. | 182 // Only pause new worker if debugging SW - we are going through the paus
e on start checkbox. |
171 var mainIsServiceWorker = !this.target().parentTarget() && this.target()
.hasWorkerCapability() && !this.target().hasBrowserCapability(); | 183 var mainIsServiceWorker = !this.target().parentTarget() && this.target()
.hasWorkerCapability() && !this.target().hasBrowserCapability(); |
172 if (mainIsServiceWorker && waitingForDebugger) | 184 if (mainIsServiceWorker && waitingForDebugger) |
173 target.debuggerAgent().pause(); | 185 target.debuggerAgent().pause(); |
174 target.runtimeAgent().runIfWaitingForDebugger(); | 186 target.runtimeAgent().runIfWaitingForDebugger(); |
175 | 187 |
176 this.dispatchEventToListeners(WebInspector.SubTargetsManager.Events.SubT
argetAdded, target); | 188 this.dispatchEventToListeners(WebInspector.SubTargetsManager.Events.SubT
argetAdded, target); |
177 }, | 189 }, |
178 | 190 |
179 /** | 191 /** |
180 * @param {string} targetId | 192 * @param {string} targetId |
181 */ | 193 */ |
182 _targetRemoved: function(targetId) | 194 _detachedFromTarget: function(targetId) |
183 { | 195 { |
184 var connection = this._connections.get(targetId); | 196 var connection = this._connections.get(targetId); |
185 if (connection) | 197 if (connection) |
186 connection._close(); | 198 connection._close(); |
187 this._connections.delete(targetId); | 199 this._connections.delete(targetId); |
188 var target = this._targets.get(targetId); | 200 var target = this._attachedTargets.get(targetId); |
189 this._targets.delete(targetId); | 201 this._attachedTargets.delete(targetId); |
190 this.dispatchEventToListeners(WebInspector.SubTargetsManager.Events.SubT
argetRemoved, target); | 202 this.dispatchEventToListeners(WebInspector.SubTargetsManager.Events.SubT
argetRemoved, target); |
191 }, | 203 }, |
192 | 204 |
193 /** | 205 /** |
194 * @param {string} targetId | 206 * @param {string} targetId |
195 * @param {string} message | 207 * @param {string} message |
196 */ | 208 */ |
197 _receivedMessageFromTarget: function(targetId, message) | 209 _receivedMessageFromTarget: function(targetId, message) |
198 { | 210 { |
199 var connection = this._connections.get(targetId); | 211 var connection = this._connections.get(targetId); |
(...skipping 10 matching lines...) Expand all Loading... |
210 * @param {!WebInspector.SubTargetsManager} manager | 222 * @param {!WebInspector.SubTargetsManager} manager |
211 */ | 223 */ |
212 WebInspector.SubTargetsDispatcher = function(manager) | 224 WebInspector.SubTargetsDispatcher = function(manager) |
213 { | 225 { |
214 this._manager = manager; | 226 this._manager = manager; |
215 } | 227 } |
216 | 228 |
217 WebInspector.SubTargetsDispatcher.prototype = { | 229 WebInspector.SubTargetsDispatcher.prototype = { |
218 /** | 230 /** |
219 * @override | 231 * @override |
220 * @param {string} targetId | 232 * @param {!TargetAgent.TargetInfo} targetInfo |
221 * @param {string} type | |
222 * @param {string} url | |
223 * @param {boolean} waitingForDebugger | |
224 */ | 233 */ |
225 targetCreated: function(targetId, type, url, waitingForDebugger) | 234 targetCreated: function(targetInfo) |
226 { | 235 { |
227 this._manager._targetCreated(targetId, type, url, waitingForDebugger); | 236 this._manager._targetCreated(new WebInspector.TargetInfo(targetInfo)); |
228 }, | 237 }, |
229 | 238 |
230 /** | 239 /** |
231 * @override | 240 * @override |
232 * @param {string} targetId | 241 * @param {string} targetId |
233 */ | 242 */ |
234 targetRemoved: function(targetId) | 243 targetRemoved: function(targetId) |
235 { | 244 { |
236 this._manager._targetRemoved(targetId); | 245 this._manager._targetRemoved(targetId); |
237 }, | 246 }, |
238 | 247 |
239 /** | 248 /** |
240 * @override | 249 * @override |
241 * @param {string} targetId | 250 * @param {string} targetId |
| 251 * @param {boolean} waitingForDebugger |
| 252 */ |
| 253 attachedToTarget: function(targetId, waitingForDebugger) |
| 254 { |
| 255 this._manager._attachedToTarget(targetId, waitingForDebugger); |
| 256 }, |
| 257 |
| 258 /** |
| 259 * @override |
| 260 * @param {string} targetId |
| 261 */ |
| 262 detachedFromTarget: function(targetId) |
| 263 { |
| 264 this._manager._detachedFromTarget(targetId); |
| 265 }, |
| 266 |
| 267 /** |
| 268 * @override |
| 269 * @param {string} targetId |
242 * @param {string} message | 270 * @param {string} message |
243 */ | 271 */ |
244 receivedMessageFromTarget: function(targetId, message) | 272 receivedMessageFromTarget: function(targetId, message) |
245 { | 273 { |
246 this._manager._receivedMessageFromTarget(targetId, message); | 274 this._manager._receivedMessageFromTarget(targetId, message); |
247 } | 275 } |
248 } | 276 } |
249 | 277 |
250 /** | 278 /** |
251 * @constructor | 279 * @constructor |
(...skipping 27 matching lines...) Expand all Loading... |
279 } | 307 } |
280 | 308 |
281 /** | 309 /** |
282 * @constructor | 310 * @constructor |
283 * @param {!TargetAgent.TargetInfo} payload | 311 * @param {!TargetAgent.TargetInfo} payload |
284 */ | 312 */ |
285 WebInspector.TargetInfo = function(payload) | 313 WebInspector.TargetInfo = function(payload) |
286 { | 314 { |
287 this.id = payload.targetId; | 315 this.id = payload.targetId; |
288 this.url = payload.url; | 316 this.url = payload.url; |
289 if (payload.type !== "page" && payload.type !== "iframe") { | 317 this.type = payload.type; |
| 318 if (this.type !== "page" && this.type !== "iframe") { |
290 this.title = WebInspector.UIString("Worker: %s", this.url); | 319 this.title = WebInspector.UIString("Worker: %s", this.url); |
291 this.canActivate = false; | 320 this.canActivate = false; |
292 } else { | 321 } else { |
293 this.title = payload.title; | 322 this.title = payload.title; |
294 this.canActivate = true; | 323 this.canActivate = true; |
295 } | 324 } |
296 } | 325 } |
OLD | NEW |