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 /** | 7 * @unrestricted |
8 * @constructor | 8 */ |
9 * @extends {Protocol.Target} | 9 WebInspector.Target = class extends Protocol.Target { |
10 * @param {!WebInspector.TargetManager} targetManager | 10 /** |
11 * @param {string} name | 11 * @param {!WebInspector.TargetManager} targetManager |
12 * @param {number} capabilitiesMask | 12 * @param {string} name |
13 * @param {!InspectorBackendClass.Connection.Factory} connectionFactory | 13 * @param {number} capabilitiesMask |
14 * @param {?WebInspector.Target} parentTarget | 14 * @param {!InspectorBackendClass.Connection.Factory} connectionFactory |
15 */ | 15 * @param {?WebInspector.Target} parentTarget |
16 WebInspector.Target = function(targetManager, name, capabilitiesMask, connection
Factory, parentTarget) | 16 */ |
17 { | 17 constructor(targetManager, name, capabilitiesMask, connectionFactory, parentTa
rget) { |
18 Protocol.Target.call(this, connectionFactory); | 18 super(connectionFactory); |
19 this._targetManager = targetManager; | 19 this._targetManager = targetManager; |
20 this._name = name; | 20 this._name = name; |
21 this._inspectedURL = ""; | 21 this._inspectedURL = ''; |
22 this._capabilitiesMask = capabilitiesMask; | 22 this._capabilitiesMask = capabilitiesMask; |
23 this._parentTarget = parentTarget; | 23 this._parentTarget = parentTarget; |
24 this._id = WebInspector.Target._nextId++; | 24 this._id = WebInspector.Target._nextId++; |
25 | 25 |
26 /** @type {!Map.<!Function, !WebInspector.SDKModel>} */ | 26 /** @type {!Map.<!Function, !WebInspector.SDKModel>} */ |
27 this._modelByConstructor = new Map(); | 27 this._modelByConstructor = new Map(); |
| 28 } |
| 29 |
| 30 /** |
| 31 * @return {boolean} |
| 32 */ |
| 33 isNodeJS() { |
| 34 // TODO(lushnikov): this is an unreliable way to detect Node.js targets. |
| 35 return this._capabilitiesMask === WebInspector.Target.Capability.JS || this.
_isNodeJSForTest; |
| 36 } |
| 37 |
| 38 setIsNodeJSForTest() { |
| 39 this._isNodeJSForTest = true; |
| 40 } |
| 41 |
| 42 /** |
| 43 * @return {number} |
| 44 */ |
| 45 id() { |
| 46 return this._id; |
| 47 } |
| 48 |
| 49 /** |
| 50 * @return {string} |
| 51 */ |
| 52 name() { |
| 53 return this._name || this._inspectedURLName; |
| 54 } |
| 55 |
| 56 /** |
| 57 * @return {!WebInspector.TargetManager} |
| 58 */ |
| 59 targetManager() { |
| 60 return this._targetManager; |
| 61 } |
| 62 |
| 63 /** |
| 64 * @param {number} capabilitiesMask |
| 65 * @return {boolean} |
| 66 */ |
| 67 hasAllCapabilities(capabilitiesMask) { |
| 68 return (this._capabilitiesMask & capabilitiesMask) === capabilitiesMask; |
| 69 } |
| 70 |
| 71 /** |
| 72 * @param {string} label |
| 73 * @return {string} |
| 74 */ |
| 75 decorateLabel(label) { |
| 76 return !this.hasBrowserCapability() ? '\u2699 ' + label : label; |
| 77 } |
| 78 |
| 79 /** |
| 80 * @return {boolean} |
| 81 */ |
| 82 hasBrowserCapability() { |
| 83 return this.hasAllCapabilities(WebInspector.Target.Capability.Browser); |
| 84 } |
| 85 |
| 86 /** |
| 87 * @return {boolean} |
| 88 */ |
| 89 hasJSCapability() { |
| 90 return this.hasAllCapabilities(WebInspector.Target.Capability.JS); |
| 91 } |
| 92 |
| 93 /** |
| 94 * @return {boolean} |
| 95 */ |
| 96 hasLogCapability() { |
| 97 return this.hasAllCapabilities(WebInspector.Target.Capability.Log); |
| 98 } |
| 99 |
| 100 /** |
| 101 * @return {boolean} |
| 102 */ |
| 103 hasNetworkCapability() { |
| 104 return this.hasAllCapabilities(WebInspector.Target.Capability.Network); |
| 105 } |
| 106 |
| 107 /** |
| 108 * @return {boolean} |
| 109 */ |
| 110 hasTargetCapability() { |
| 111 return this.hasAllCapabilities(WebInspector.Target.Capability.Target); |
| 112 } |
| 113 |
| 114 /** |
| 115 * @return {boolean} |
| 116 */ |
| 117 hasDOMCapability() { |
| 118 return this.hasAllCapabilities(WebInspector.Target.Capability.DOM); |
| 119 } |
| 120 |
| 121 /** |
| 122 * @return {?WebInspector.Target} |
| 123 */ |
| 124 parentTarget() { |
| 125 return this._parentTarget; |
| 126 } |
| 127 |
| 128 /** |
| 129 * @override |
| 130 */ |
| 131 dispose() { |
| 132 this._targetManager.removeTarget(this); |
| 133 for (var model of this._modelByConstructor.valuesArray()) |
| 134 model.dispose(); |
| 135 } |
| 136 |
| 137 /** |
| 138 * @param {!Function} modelClass |
| 139 * @return {?WebInspector.SDKModel} |
| 140 */ |
| 141 model(modelClass) { |
| 142 return this._modelByConstructor.get(modelClass) || null; |
| 143 } |
| 144 |
| 145 /** |
| 146 * @return {!Array<!WebInspector.SDKModel>} |
| 147 */ |
| 148 models() { |
| 149 return this._modelByConstructor.valuesArray(); |
| 150 } |
| 151 |
| 152 /** |
| 153 * @return {string} |
| 154 */ |
| 155 inspectedURL() { |
| 156 return this._inspectedURL; |
| 157 } |
| 158 |
| 159 /** |
| 160 * @param {string} inspectedURL |
| 161 */ |
| 162 setInspectedURL(inspectedURL) { |
| 163 this._inspectedURL = inspectedURL; |
| 164 var parsedURL = inspectedURL.asParsedURL(); |
| 165 this._inspectedURLName = parsedURL ? parsedURL.lastPathComponentWithFragment
() : '#' + this._id; |
| 166 if (!this.parentTarget()) |
| 167 InspectorFrontendHost.inspectedURLChanged(inspectedURL || ''); |
| 168 this._targetManager.dispatchEventToListeners(WebInspector.TargetManager.Even
ts.InspectedURLChanged, this); |
| 169 if (!this._name) |
| 170 this._targetManager.dispatchEventToListeners(WebInspector.TargetManager.Ev
ents.NameChanged, this); |
| 171 } |
28 }; | 172 }; |
29 | 173 |
30 /** | 174 /** |
31 * @enum {number} | 175 * @enum {number} |
32 */ | 176 */ |
33 WebInspector.Target.Capability = { | 177 WebInspector.Target.Capability = { |
34 Browser: 1, | 178 Browser: 1, |
35 DOM: 2, | 179 DOM: 2, |
36 JS: 4, | 180 JS: 4, |
37 Log: 8, | 181 Log: 8, |
38 Network: 16, | 182 Network: 16, |
39 Target: 32 | 183 Target: 32 |
40 }; | 184 }; |
41 | 185 |
42 WebInspector.Target._nextId = 1; | 186 WebInspector.Target._nextId = 1; |
43 | 187 |
44 WebInspector.Target.prototype = { | 188 /** |
45 /** | 189 * @unrestricted |
46 * @return {boolean} | 190 */ |
47 */ | 191 WebInspector.SDKObject = class extends WebInspector.Object { |
48 isNodeJS: function() | 192 /** |
49 { | 193 * @param {!WebInspector.Target} target |
50 // TODO(lushnikov): this is an unreliable way to detect Node.js targets. | 194 */ |
51 return this._capabilitiesMask === WebInspector.Target.Capability.JS || t
his._isNodeJSForTest; | 195 constructor(target) { |
52 }, | 196 super(); |
53 | |
54 setIsNodeJSForTest: function() | |
55 { | |
56 this._isNodeJSForTest = true; | |
57 }, | |
58 | |
59 /** | |
60 * @return {number} | |
61 */ | |
62 id: function() | |
63 { | |
64 return this._id; | |
65 }, | |
66 | |
67 /** | |
68 * @return {string} | |
69 */ | |
70 name: function() | |
71 { | |
72 return this._name || this._inspectedURLName; | |
73 }, | |
74 | |
75 /** | |
76 * @return {!WebInspector.TargetManager} | |
77 */ | |
78 targetManager: function() | |
79 { | |
80 return this._targetManager; | |
81 }, | |
82 | |
83 /** | |
84 * @param {number} capabilitiesMask | |
85 * @return {boolean} | |
86 */ | |
87 hasAllCapabilities: function(capabilitiesMask) | |
88 { | |
89 return (this._capabilitiesMask & capabilitiesMask) === capabilitiesMask; | |
90 }, | |
91 | |
92 /** | |
93 * @param {string} label | |
94 * @return {string} | |
95 */ | |
96 decorateLabel: function(label) | |
97 { | |
98 return !this.hasBrowserCapability() ? "\u2699 " + label : label; | |
99 }, | |
100 | |
101 /** | |
102 * @return {boolean} | |
103 */ | |
104 hasBrowserCapability: function() | |
105 { | |
106 return this.hasAllCapabilities(WebInspector.Target.Capability.Browser); | |
107 }, | |
108 | |
109 /** | |
110 * @return {boolean} | |
111 */ | |
112 hasJSCapability: function() | |
113 { | |
114 return this.hasAllCapabilities(WebInspector.Target.Capability.JS); | |
115 }, | |
116 | |
117 /** | |
118 * @return {boolean} | |
119 */ | |
120 hasLogCapability: function() | |
121 { | |
122 return this.hasAllCapabilities(WebInspector.Target.Capability.Log); | |
123 }, | |
124 | |
125 /** | |
126 * @return {boolean} | |
127 */ | |
128 hasNetworkCapability: function() | |
129 { | |
130 return this.hasAllCapabilities(WebInspector.Target.Capability.Network); | |
131 }, | |
132 | |
133 /** | |
134 * @return {boolean} | |
135 */ | |
136 hasTargetCapability: function() | |
137 { | |
138 return this.hasAllCapabilities(WebInspector.Target.Capability.Target); | |
139 }, | |
140 | |
141 /** | |
142 * @return {boolean} | |
143 */ | |
144 hasDOMCapability: function() | |
145 { | |
146 return this.hasAllCapabilities(WebInspector.Target.Capability.DOM); | |
147 }, | |
148 | |
149 /** | |
150 * @return {?WebInspector.Target} | |
151 */ | |
152 parentTarget: function() | |
153 { | |
154 return this._parentTarget; | |
155 }, | |
156 | |
157 /** | |
158 * @override | |
159 */ | |
160 dispose: function() | |
161 { | |
162 this._targetManager.removeTarget(this); | |
163 for (var model of this._modelByConstructor.valuesArray()) | |
164 model.dispose(); | |
165 }, | |
166 | |
167 /** | |
168 * @param {!Function} modelClass | |
169 * @return {?WebInspector.SDKModel} | |
170 */ | |
171 model: function(modelClass) | |
172 { | |
173 return this._modelByConstructor.get(modelClass) || null; | |
174 }, | |
175 | |
176 /** | |
177 * @return {!Array<!WebInspector.SDKModel>} | |
178 */ | |
179 models: function() | |
180 { | |
181 return this._modelByConstructor.valuesArray(); | |
182 }, | |
183 | |
184 /** | |
185 * @return {string} | |
186 */ | |
187 inspectedURL: function() | |
188 { | |
189 return this._inspectedURL; | |
190 }, | |
191 | |
192 /** | |
193 * @param {string} inspectedURL | |
194 */ | |
195 setInspectedURL: function(inspectedURL) | |
196 { | |
197 this._inspectedURL = inspectedURL; | |
198 var parsedURL = inspectedURL.asParsedURL(); | |
199 this._inspectedURLName = parsedURL ? parsedURL.lastPathComponentWithFrag
ment() : "#" + this._id; | |
200 if (!this.parentTarget()) | |
201 InspectorFrontendHost.inspectedURLChanged(inspectedURL || ""); | |
202 this._targetManager.dispatchEventToListeners(WebInspector.TargetManager.
Events.InspectedURLChanged, this); | |
203 if (!this._name) | |
204 this._targetManager.dispatchEventToListeners(WebInspector.TargetMana
ger.Events.NameChanged, this); | |
205 }, | |
206 | |
207 __proto__: Protocol.Target.prototype | |
208 }; | |
209 | |
210 /** | |
211 * @constructor | |
212 * @extends {WebInspector.Object} | |
213 * @param {!WebInspector.Target} target | |
214 */ | |
215 WebInspector.SDKObject = function(target) | |
216 { | |
217 WebInspector.Object.call(this); | |
218 this._target = target; | 197 this._target = target; |
219 }; | 198 } |
220 | 199 |
221 WebInspector.SDKObject.prototype = { | 200 /** |
222 /** | 201 * @return {!WebInspector.Target} |
223 * @return {!WebInspector.Target} | 202 */ |
224 */ | 203 target() { |
225 target: function() | 204 return this._target; |
226 { | 205 } |
227 return this._target; | 206 }; |
228 }, | 207 |
229 | 208 /** |
230 __proto__: WebInspector.Object.prototype | 209 * @unrestricted |
231 }; | 210 */ |
232 | 211 WebInspector.SDKModel = class extends WebInspector.SDKObject { |
233 /** | 212 /** |
234 * @constructor | 213 * @param {!Function} modelClass |
235 * @extends {WebInspector.SDKObject} | 214 * @param {!WebInspector.Target} target |
236 * @param {!Function} modelClass | 215 */ |
237 * @param {!WebInspector.Target} target | 216 constructor(modelClass, target) { |
238 */ | 217 super(target); |
239 WebInspector.SDKModel = function(modelClass, target) | |
240 { | |
241 WebInspector.SDKObject.call(this, target); | |
242 target._modelByConstructor.set(modelClass, this); | 218 target._modelByConstructor.set(modelClass, this); |
243 }; | 219 } |
244 | 220 |
245 WebInspector.SDKModel.prototype = { | 221 /** |
246 /** | 222 * @return {!Promise} |
247 * @return {!Promise} | 223 */ |
248 */ | 224 suspendModel() { |
249 suspendModel: function() | 225 return Promise.resolve(); |
250 { | 226 } |
251 return Promise.resolve(); | 227 |
252 }, | 228 /** |
253 | 229 * @return {!Promise} |
254 /** | 230 */ |
255 * @return {!Promise} | 231 resumeModel() { |
256 */ | 232 return Promise.resolve(); |
257 resumeModel: function() | 233 } |
258 { | 234 |
259 return Promise.resolve(); | 235 dispose() { |
260 }, | 236 } |
261 | 237 |
262 dispose: function() { }, | 238 /** |
263 | 239 * @param {!WebInspector.Event} event |
264 /** | 240 */ |
265 * @param {!WebInspector.Event} event | 241 _targetDisposed(event) { |
266 */ | 242 var target = /** @type {!WebInspector.Target} */ (event.data); |
267 _targetDisposed: function(event) | 243 if (target !== this._target) |
268 { | 244 return; |
269 var target = /** @type {!WebInspector.Target} */ (event.data); | 245 this.dispose(); |
270 if (target !== this._target) | 246 } |
271 return; | 247 }; |
272 this.dispose(); | |
273 }, | |
274 | |
275 __proto__: WebInspector.SDKObject.prototype | |
276 }; | |
OLD | NEW |