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

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

Issue 2493373002: DevTools: rename WebInspector into modules. (Closed)
Patch Set: for bots 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2012 Google Inc. All rights reserved. 2 * Copyright (C) 2012 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 13 matching lines...) Expand all
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 30
31 /** 31 /**
32 * @unrestricted 32 * @unrestricted
33 */ 33 */
34 WebInspector.RuntimeModel = class extends WebInspector.SDKModel { 34 SDK.RuntimeModel = class extends SDK.SDKModel {
35 /** 35 /**
36 * @param {!WebInspector.Target} target 36 * @param {!SDK.Target} target
37 */ 37 */
38 constructor(target) { 38 constructor(target) {
39 super(WebInspector.RuntimeModel, target); 39 super(SDK.RuntimeModel, target);
40 40
41 this._agent = target.runtimeAgent(); 41 this._agent = target.runtimeAgent();
42 this.target().registerRuntimeDispatcher(new WebInspector.RuntimeDispatcher(t his)); 42 this.target().registerRuntimeDispatcher(new SDK.RuntimeDispatcher(this));
43 if (target.hasJSCapability()) 43 if (target.hasJSCapability())
44 this._agent.enable(); 44 this._agent.enable();
45 /** @type {!Map<number, !WebInspector.ExecutionContext>} */ 45 /** @type {!Map<number, !SDK.ExecutionContext>} */
46 this._executionContextById = new Map(); 46 this._executionContextById = new Map();
47 this._executionContextComparator = WebInspector.ExecutionContext.comparator; 47 this._executionContextComparator = SDK.ExecutionContext.comparator;
48 48
49 if (WebInspector.moduleSetting('customFormatters').get()) 49 if (Common.moduleSetting('customFormatters').get())
50 this._agent.setCustomObjectFormatterEnabled(true); 50 this._agent.setCustomObjectFormatterEnabled(true);
51 51
52 WebInspector.moduleSetting('customFormatters').addChangeListener(this._custo mFormattersStateChanged.bind(this)); 52 Common.moduleSetting('customFormatters').addChangeListener(this._customForma ttersStateChanged.bind(this));
53 } 53 }
54 54
55 /** 55 /**
56 * @return {!Array.<!WebInspector.ExecutionContext>} 56 * @return {!Array.<!SDK.ExecutionContext>}
57 */ 57 */
58 executionContexts() { 58 executionContexts() {
59 return this._executionContextById.valuesArray().sort(this.executionContextCo mparator()); 59 return this._executionContextById.valuesArray().sort(this.executionContextCo mparator());
60 } 60 }
61 61
62 /** 62 /**
63 * @param {function(!WebInspector.ExecutionContext,!WebInspector.ExecutionCont ext)} comparator 63 * @param {function(!SDK.ExecutionContext,!SDK.ExecutionContext)} comparator
64 */ 64 */
65 setExecutionContextComparator(comparator) { 65 setExecutionContextComparator(comparator) {
66 this._executionContextComparator = comparator; 66 this._executionContextComparator = comparator;
67 } 67 }
68 68
69 /** 69 /**
70 * @return {function(!WebInspector.ExecutionContext,!WebInspector.ExecutionCon text)} comparator 70 * @return {function(!SDK.ExecutionContext,!SDK.ExecutionContext)} comparator
71 */ 71 */
72 executionContextComparator() { 72 executionContextComparator() {
73 return this._executionContextComparator; 73 return this._executionContextComparator;
74 } 74 }
75 75
76 /** 76 /**
77 * @return {?WebInspector.ExecutionContext} 77 * @return {?SDK.ExecutionContext}
78 */ 78 */
79 defaultExecutionContext() { 79 defaultExecutionContext() {
80 for (var context of this._executionContextById.values()) { 80 for (var context of this._executionContextById.values()) {
81 if (context.isDefault) 81 if (context.isDefault)
82 return context; 82 return context;
83 } 83 }
84 return null; 84 return null;
85 } 85 }
86 86
87 /** 87 /**
88 * @param {!Protocol.Runtime.ExecutionContextId} id 88 * @param {!Protocol.Runtime.ExecutionContextId} id
89 * @return {?WebInspector.ExecutionContext} 89 * @return {?SDK.ExecutionContext}
90 */ 90 */
91 executionContext(id) { 91 executionContext(id) {
92 return this._executionContextById.get(id) || null; 92 return this._executionContextById.get(id) || null;
93 } 93 }
94 94
95 /** 95 /**
96 * @param {!Protocol.Runtime.ExecutionContextDescription} context 96 * @param {!Protocol.Runtime.ExecutionContextDescription} context
97 */ 97 */
98 _executionContextCreated(context) { 98 _executionContextCreated(context) {
99 // The private script context should be hidden behind an experiment. 99 // The private script context should be hidden behind an experiment.
100 if (context.name === WebInspector.RuntimeModel._privateScript && !context.or igin && 100 if (context.name === SDK.RuntimeModel._privateScript && !context.origin &&
101 !Runtime.experiments.isEnabled('privateScriptInspection')) { 101 !Runtime.experiments.isEnabled('privateScriptInspection')) {
102 return; 102 return;
103 } 103 }
104 var data = context.auxData || {isDefault: true}; 104 var data = context.auxData || {isDefault: true};
105 var executionContext = new WebInspector.ExecutionContext( 105 var executionContext = new SDK.ExecutionContext(
106 this.target(), context.id, context.name, context.origin, data['isDefault '], data['frameId']); 106 this.target(), context.id, context.name, context.origin, data['isDefault '], data['frameId']);
107 this._executionContextById.set(executionContext.id, executionContext); 107 this._executionContextById.set(executionContext.id, executionContext);
108 this.dispatchEventToListeners(WebInspector.RuntimeModel.Events.ExecutionCont extCreated, executionContext); 108 this.dispatchEventToListeners(SDK.RuntimeModel.Events.ExecutionContextCreate d, executionContext);
109 } 109 }
110 110
111 /** 111 /**
112 * @param {number} executionContextId 112 * @param {number} executionContextId
113 */ 113 */
114 _executionContextDestroyed(executionContextId) { 114 _executionContextDestroyed(executionContextId) {
115 var executionContext = this._executionContextById.get(executionContextId); 115 var executionContext = this._executionContextById.get(executionContextId);
116 if (!executionContext) 116 if (!executionContext)
117 return; 117 return;
118 this._executionContextById.delete(executionContextId); 118 this._executionContextById.delete(executionContextId);
119 this.dispatchEventToListeners(WebInspector.RuntimeModel.Events.ExecutionCont extDestroyed, executionContext); 119 this.dispatchEventToListeners(SDK.RuntimeModel.Events.ExecutionContextDestro yed, executionContext);
120 } 120 }
121 121
122 fireExecutionContextOrderChanged() { 122 fireExecutionContextOrderChanged() {
123 this.dispatchEventToListeners(WebInspector.RuntimeModel.Events.ExecutionCont extOrderChanged, this); 123 this.dispatchEventToListeners(SDK.RuntimeModel.Events.ExecutionContextOrderC hanged, this);
124 } 124 }
125 125
126 _executionContextsCleared() { 126 _executionContextsCleared() {
127 var debuggerModel = WebInspector.DebuggerModel.fromTarget(this.target()); 127 var debuggerModel = SDK.DebuggerModel.fromTarget(this.target());
128 if (debuggerModel) 128 if (debuggerModel)
129 debuggerModel.globalObjectCleared(); 129 debuggerModel.globalObjectCleared();
130 var contexts = this.executionContexts(); 130 var contexts = this.executionContexts();
131 this._executionContextById.clear(); 131 this._executionContextById.clear();
132 for (var i = 0; i < contexts.length; ++i) 132 for (var i = 0; i < contexts.length; ++i)
133 this.dispatchEventToListeners(WebInspector.RuntimeModel.Events.ExecutionCo ntextDestroyed, contexts[i]); 133 this.dispatchEventToListeners(SDK.RuntimeModel.Events.ExecutionContextDest royed, contexts[i]);
134 } 134 }
135 135
136 /** 136 /**
137 * @param {!Protocol.Runtime.RemoteObject} payload 137 * @param {!Protocol.Runtime.RemoteObject} payload
138 * @return {!WebInspector.RemoteObject} 138 * @return {!SDK.RemoteObject}
139 */ 139 */
140 createRemoteObject(payload) { 140 createRemoteObject(payload) {
141 console.assert(typeof payload === 'object', 'Remote object payload should on ly be an object'); 141 console.assert(typeof payload === 'object', 'Remote object payload should on ly be an object');
142 return new WebInspector.RemoteObjectImpl( 142 return new SDK.RemoteObjectImpl(
143 this.target(), payload.objectId, payload.type, payload.subtype, payload. value, payload.unserializableValue, 143 this.target(), payload.objectId, payload.type, payload.subtype, payload. value, payload.unserializableValue,
144 payload.description, payload.preview, payload.customPreview); 144 payload.description, payload.preview, payload.customPreview);
145 } 145 }
146 146
147 /** 147 /**
148 * @param {!Protocol.Runtime.RemoteObject} payload 148 * @param {!Protocol.Runtime.RemoteObject} payload
149 * @param {!WebInspector.ScopeRef} scopeRef 149 * @param {!SDK.ScopeRef} scopeRef
150 * @return {!WebInspector.RemoteObject} 150 * @return {!SDK.RemoteObject}
151 */ 151 */
152 createScopeRemoteObject(payload, scopeRef) { 152 createScopeRemoteObject(payload, scopeRef) {
153 return new WebInspector.ScopeRemoteObject( 153 return new SDK.ScopeRemoteObject(
154 this.target(), payload.objectId, scopeRef, payload.type, payload.subtype , payload.value, 154 this.target(), payload.objectId, scopeRef, payload.type, payload.subtype , payload.value,
155 payload.unserializableValue, payload.description, payload.preview); 155 payload.unserializableValue, payload.description, payload.preview);
156 } 156 }
157 157
158 /** 158 /**
159 * @param {number|string|boolean|undefined} value 159 * @param {number|string|boolean|undefined} value
160 * @return {!WebInspector.RemoteObject} 160 * @return {!SDK.RemoteObject}
161 */ 161 */
162 createRemoteObjectFromPrimitiveValue(value) { 162 createRemoteObjectFromPrimitiveValue(value) {
163 var type = typeof value; 163 var type = typeof value;
164 var unserializableValue = undefined; 164 var unserializableValue = undefined;
165 if (typeof value === 'number') { 165 if (typeof value === 'number') {
166 var description = String(value); 166 var description = String(value);
167 if (value === 0 && 1 / value < 0) 167 if (value === 0 && 1 / value < 0)
168 unserializableValue = Protocol.Runtime.UnserializableValue.Negative0; 168 unserializableValue = Protocol.Runtime.UnserializableValue.Negative0;
169 if (description === 'NaN') 169 if (description === 'NaN')
170 unserializableValue = Protocol.Runtime.UnserializableValue.NaN; 170 unserializableValue = Protocol.Runtime.UnserializableValue.NaN;
171 if (description === 'Infinity') 171 if (description === 'Infinity')
172 unserializableValue = Protocol.Runtime.UnserializableValue.Infinity; 172 unserializableValue = Protocol.Runtime.UnserializableValue.Infinity;
173 if (description === '-Infinity') 173 if (description === '-Infinity')
174 unserializableValue = Protocol.Runtime.UnserializableValue.NegativeInfin ity; 174 unserializableValue = Protocol.Runtime.UnserializableValue.NegativeInfin ity;
175 if (typeof unserializableValue !== 'undefined') 175 if (typeof unserializableValue !== 'undefined')
176 value = undefined; 176 value = undefined;
177 } 177 }
178 return new WebInspector.RemoteObjectImpl(this.target(), undefined, type, und efined, value, unserializableValue); 178 return new SDK.RemoteObjectImpl(this.target(), undefined, type, undefined, v alue, unserializableValue);
179 } 179 }
180 180
181 /** 181 /**
182 * @param {string} name 182 * @param {string} name
183 * @param {number|string|boolean} value 183 * @param {number|string|boolean} value
184 * @return {!WebInspector.RemoteObjectProperty} 184 * @return {!SDK.RemoteObjectProperty}
185 */ 185 */
186 createRemotePropertyFromPrimitiveValue(name, value) { 186 createRemotePropertyFromPrimitiveValue(name, value) {
187 return new WebInspector.RemoteObjectProperty(name, this.createRemoteObjectFr omPrimitiveValue(value)); 187 return new SDK.RemoteObjectProperty(name, this.createRemoteObjectFromPrimiti veValue(value));
188 } 188 }
189 189
190 discardConsoleEntries() { 190 discardConsoleEntries() {
191 this._agent.discardConsoleEntries(); 191 this._agent.discardConsoleEntries();
192 } 192 }
193 193
194 /** 194 /**
195 * @param {!WebInspector.Event} event 195 * @param {!Common.Event} event
196 */ 196 */
197 _customFormattersStateChanged(event) { 197 _customFormattersStateChanged(event) {
198 var enabled = /** @type {boolean} */ (event.data); 198 var enabled = /** @type {boolean} */ (event.data);
199 this._agent.setCustomObjectFormatterEnabled(enabled); 199 this._agent.setCustomObjectFormatterEnabled(enabled);
200 } 200 }
201 201
202 /** 202 /**
203 * @param {string} expression 203 * @param {string} expression
204 * @param {string} sourceURL 204 * @param {string} sourceURL
205 * @param {boolean} persistScript 205 * @param {boolean} persistScript
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 */ 270 */
271 _inspectRequested(payload, hints) { 271 _inspectRequested(payload, hints) {
272 var object = this.createRemoteObject(payload); 272 var object = this.createRemoteObject(payload);
273 273
274 if (hints.copyToClipboard) { 274 if (hints.copyToClipboard) {
275 this._copyRequested(object); 275 this._copyRequested(object);
276 return; 276 return;
277 } 277 }
278 278
279 if (object.isNode()) { 279 if (object.isNode()) {
280 WebInspector.Revealer.revealPromise(object).then(object.release.bind(objec t)); 280 Common.Revealer.revealPromise(object).then(object.release.bind(object));
281 return; 281 return;
282 } 282 }
283 283
284 if (object.type === 'function') { 284 if (object.type === 'function') {
285 WebInspector.RemoteFunction.objectAsFunction(object).targetFunctionDetails ().then(didGetDetails); 285 SDK.RemoteFunction.objectAsFunction(object).targetFunctionDetails().then(d idGetDetails);
286 return; 286 return;
287 } 287 }
288 288
289 /** 289 /**
290 * @param {?WebInspector.DebuggerModel.FunctionDetails} response 290 * @param {?SDK.DebuggerModel.FunctionDetails} response
291 */ 291 */
292 function didGetDetails(response) { 292 function didGetDetails(response) {
293 object.release(); 293 object.release();
294 if (!response || !response.location) 294 if (!response || !response.location)
295 return; 295 return;
296 WebInspector.Revealer.reveal(response.location); 296 Common.Revealer.reveal(response.location);
297 } 297 }
298 object.release(); 298 object.release();
299 } 299 }
300 300
301 /** 301 /**
302 * @param {!WebInspector.RemoteObject} object 302 * @param {!SDK.RemoteObject} object
303 */ 303 */
304 _copyRequested(object) { 304 _copyRequested(object) {
305 if (!object.objectId) { 305 if (!object.objectId) {
306 InspectorFrontendHost.copyText(object.value); 306 InspectorFrontendHost.copyText(object.value);
307 return; 307 return;
308 } 308 }
309 object.callFunctionJSON( 309 object.callFunctionJSON(
310 toStringForClipboard, [{value: object.subtype}], InspectorFrontendHost.c opyText.bind(InspectorFrontendHost)); 310 toStringForClipboard, [{value: object.subtype}], InspectorFrontendHost.c opyText.bind(InspectorFrontendHost));
311 311
312 /** 312 /**
313 * @param {string} subtype 313 * @param {string} subtype
314 * @this {Object} 314 * @this {Object}
315 * @suppressReceiverCheck 315 * @suppressReceiverCheck
316 */ 316 */
317 function toStringForClipboard(subtype) { 317 function toStringForClipboard(subtype) {
318 if (subtype === 'node') 318 if (subtype === 'node')
319 return this.outerHTML; 319 return this.outerHTML;
320 if (subtype && typeof this === 'undefined') 320 if (subtype && typeof this === 'undefined')
321 return subtype + ''; 321 return subtype + '';
322 try { 322 try {
323 return JSON.stringify(this, null, ' '); 323 return JSON.stringify(this, null, ' ');
324 } catch (e) { 324 } catch (e) {
325 return '' + this; 325 return '' + this;
326 } 326 }
327 } 327 }
328 } 328 }
329 }; 329 };
330 330
331 /** @enum {symbol} */ 331 /** @enum {symbol} */
332 WebInspector.RuntimeModel.Events = { 332 SDK.RuntimeModel.Events = {
333 ExecutionContextCreated: Symbol('ExecutionContextCreated'), 333 ExecutionContextCreated: Symbol('ExecutionContextCreated'),
334 ExecutionContextDestroyed: Symbol('ExecutionContextDestroyed'), 334 ExecutionContextDestroyed: Symbol('ExecutionContextDestroyed'),
335 ExecutionContextChanged: Symbol('ExecutionContextChanged'), 335 ExecutionContextChanged: Symbol('ExecutionContextChanged'),
336 ExecutionContextOrderChanged: Symbol('ExecutionContextOrderChanged') 336 ExecutionContextOrderChanged: Symbol('ExecutionContextOrderChanged')
337 }; 337 };
338 338
339 WebInspector.RuntimeModel._privateScript = 'private script'; 339 SDK.RuntimeModel._privateScript = 'private script';
340 340
341 /** 341 /**
342 * @implements {Protocol.RuntimeDispatcher} 342 * @implements {Protocol.RuntimeDispatcher}
343 * @unrestricted 343 * @unrestricted
344 */ 344 */
345 WebInspector.RuntimeDispatcher = class { 345 SDK.RuntimeDispatcher = class {
346 /** 346 /**
347 * @param {!WebInspector.RuntimeModel} runtimeModel 347 * @param {!SDK.RuntimeModel} runtimeModel
348 */ 348 */
349 constructor(runtimeModel) { 349 constructor(runtimeModel) {
350 this._runtimeModel = runtimeModel; 350 this._runtimeModel = runtimeModel;
351 } 351 }
352 352
353 /** 353 /**
354 * @override 354 * @override
355 * @param {!Protocol.Runtime.ExecutionContextDescription} context 355 * @param {!Protocol.Runtime.ExecutionContextDescription} context
356 */ 356 */
357 executionContextCreated(context) { 357 executionContextCreated(context) {
(...skipping 14 matching lines...) Expand all
372 executionContextsCleared() { 372 executionContextsCleared() {
373 this._runtimeModel._executionContextsCleared(); 373 this._runtimeModel._executionContextsCleared();
374 } 374 }
375 375
376 /** 376 /**
377 * @override 377 * @override
378 * @param {number} timestamp 378 * @param {number} timestamp
379 * @param {!Protocol.Runtime.ExceptionDetails} exceptionDetails 379 * @param {!Protocol.Runtime.ExceptionDetails} exceptionDetails
380 */ 380 */
381 exceptionThrown(timestamp, exceptionDetails) { 381 exceptionThrown(timestamp, exceptionDetails) {
382 var consoleMessage = WebInspector.ConsoleMessage.fromException( 382 var consoleMessage = SDK.ConsoleMessage.fromException(
383 this._runtimeModel.target(), exceptionDetails, undefined, timestamp, und efined); 383 this._runtimeModel.target(), exceptionDetails, undefined, timestamp, und efined);
384 consoleMessage.setExceptionId(exceptionDetails.exceptionId); 384 consoleMessage.setExceptionId(exceptionDetails.exceptionId);
385 this._runtimeModel.target().consoleModel.addMessage(consoleMessage); 385 this._runtimeModel.target().consoleModel.addMessage(consoleMessage);
386 } 386 }
387 387
388 /** 388 /**
389 * @override 389 * @override
390 * @param {string} reason 390 * @param {string} reason
391 * @param {number} exceptionId 391 * @param {number} exceptionId
392 */ 392 */
393 exceptionRevoked(reason, exceptionId) { 393 exceptionRevoked(reason, exceptionId) {
394 var consoleMessage = new WebInspector.ConsoleMessage( 394 var consoleMessage = new SDK.ConsoleMessage(
395 this._runtimeModel.target(), WebInspector.ConsoleMessage.MessageSource.J S, 395 this._runtimeModel.target(), SDK.ConsoleMessage.MessageSource.JS,
396 WebInspector.ConsoleMessage.MessageLevel.RevokedError, reason, undefined , undefined, undefined, undefined, 396 SDK.ConsoleMessage.MessageLevel.RevokedError, reason, undefined, undefin ed, undefined, undefined,
397 undefined, undefined, undefined, undefined, undefined, undefined); 397 undefined, undefined, undefined, undefined, undefined, undefined);
398 consoleMessage.setRevokedExceptionId(exceptionId); 398 consoleMessage.setRevokedExceptionId(exceptionId);
399 this._runtimeModel.target().consoleModel.addMessage(consoleMessage); 399 this._runtimeModel.target().consoleModel.addMessage(consoleMessage);
400 } 400 }
401 401
402 /** 402 /**
403 * @override 403 * @override
404 * @param {string} type 404 * @param {string} type
405 * @param {!Array.<!Protocol.Runtime.RemoteObject>} args 405 * @param {!Array.<!Protocol.Runtime.RemoteObject>} args
406 * @param {number} executionContextId 406 * @param {number} executionContextId
407 * @param {number} timestamp 407 * @param {number} timestamp
408 * @param {!Protocol.Runtime.StackTrace=} stackTrace 408 * @param {!Protocol.Runtime.StackTrace=} stackTrace
409 */ 409 */
410 consoleAPICalled(type, args, executionContextId, timestamp, stackTrace) { 410 consoleAPICalled(type, args, executionContextId, timestamp, stackTrace) {
411 var level = WebInspector.ConsoleMessage.MessageLevel.Log; 411 var level = SDK.ConsoleMessage.MessageLevel.Log;
412 if (type === WebInspector.ConsoleMessage.MessageType.Debug) 412 if (type === SDK.ConsoleMessage.MessageType.Debug)
413 level = WebInspector.ConsoleMessage.MessageLevel.Debug; 413 level = SDK.ConsoleMessage.MessageLevel.Debug;
414 if (type === WebInspector.ConsoleMessage.MessageType.Error || 414 if (type === SDK.ConsoleMessage.MessageType.Error ||
415 type === WebInspector.ConsoleMessage.MessageType.Assert) 415 type === SDK.ConsoleMessage.MessageType.Assert)
416 level = WebInspector.ConsoleMessage.MessageLevel.Error; 416 level = SDK.ConsoleMessage.MessageLevel.Error;
417 if (type === WebInspector.ConsoleMessage.MessageType.Warning) 417 if (type === SDK.ConsoleMessage.MessageType.Warning)
418 level = WebInspector.ConsoleMessage.MessageLevel.Warning; 418 level = SDK.ConsoleMessage.MessageLevel.Warning;
419 if (type === WebInspector.ConsoleMessage.MessageType.Info) 419 if (type === SDK.ConsoleMessage.MessageType.Info)
420 level = WebInspector.ConsoleMessage.MessageLevel.Info; 420 level = SDK.ConsoleMessage.MessageLevel.Info;
421 var message = ''; 421 var message = '';
422 if (args.length && typeof args[0].value === 'string') 422 if (args.length && typeof args[0].value === 'string')
423 message = args[0].value; 423 message = args[0].value;
424 else if (args.length && args[0].description) 424 else if (args.length && args[0].description)
425 message = args[0].description; 425 message = args[0].description;
426 var callFrame = stackTrace && stackTrace.callFrames.length ? stackTrace.call Frames[0] : null; 426 var callFrame = stackTrace && stackTrace.callFrames.length ? stackTrace.call Frames[0] : null;
427 var consoleMessage = new WebInspector.ConsoleMessage( 427 var consoleMessage = new SDK.ConsoleMessage(
428 this._runtimeModel.target(), WebInspector.ConsoleMessage.MessageSource.C onsoleAPI, level, 428 this._runtimeModel.target(), SDK.ConsoleMessage.MessageSource.ConsoleAPI , level,
429 /** @type {string} */ (message), type, callFrame ? callFrame.url : undef ined, 429 /** @type {string} */ (message), type, callFrame ? callFrame.url : undef ined,
430 callFrame ? callFrame.lineNumber : undefined, callFrame ? callFrame.colu mnNumber : undefined, undefined, args, 430 callFrame ? callFrame.lineNumber : undefined, callFrame ? callFrame.colu mnNumber : undefined, undefined, args,
431 stackTrace, timestamp, executionContextId, undefined); 431 stackTrace, timestamp, executionContextId, undefined);
432 this._runtimeModel.target().consoleModel.addMessage(consoleMessage); 432 this._runtimeModel.target().consoleModel.addMessage(consoleMessage);
433 } 433 }
434 434
435 /** 435 /**
436 * @override 436 * @override
437 * @param {!Protocol.Runtime.RemoteObject} payload 437 * @param {!Protocol.Runtime.RemoteObject} payload
438 * @param {!Object=} hints 438 * @param {!Object=} hints
439 */ 439 */
440 inspectRequested(payload, hints) { 440 inspectRequested(payload, hints) {
441 this._runtimeModel._inspectRequested(payload, hints); 441 this._runtimeModel._inspectRequested(payload, hints);
442 } 442 }
443 }; 443 };
444 444
445 /** 445 /**
446 * @unrestricted 446 * @unrestricted
447 */ 447 */
448 WebInspector.ExecutionContext = class extends WebInspector.SDKObject { 448 SDK.ExecutionContext = class extends SDK.SDKObject {
449 /** 449 /**
450 * @param {!WebInspector.Target} target 450 * @param {!SDK.Target} target
451 * @param {number} id 451 * @param {number} id
452 * @param {string} name 452 * @param {string} name
453 * @param {string} origin 453 * @param {string} origin
454 * @param {boolean} isDefault 454 * @param {boolean} isDefault
455 * @param {string=} frameId 455 * @param {string=} frameId
456 */ 456 */
457 constructor(target, id, name, origin, isDefault, frameId) { 457 constructor(target, id, name, origin, isDefault, frameId) {
458 super(target); 458 super(target);
459 this.id = id; 459 this.id = id;
460 this.name = name; 460 this.name = name;
461 this.origin = origin; 461 this.origin = origin;
462 this.isDefault = isDefault; 462 this.isDefault = isDefault;
463 this.runtimeModel = target.runtimeModel; 463 this.runtimeModel = target.runtimeModel;
464 this.debuggerModel = WebInspector.DebuggerModel.fromTarget(target); 464 this.debuggerModel = SDK.DebuggerModel.fromTarget(target);
465 this.frameId = frameId; 465 this.frameId = frameId;
466 466
467 this._label = name; 467 this._label = name;
468 var parsedUrl = origin.asParsedURL(); 468 var parsedUrl = origin.asParsedURL();
469 if (!this._label && parsedUrl) 469 if (!this._label && parsedUrl)
470 this._label = parsedUrl.lastPathComponentWithFragment(); 470 this._label = parsedUrl.lastPathComponentWithFragment();
471 } 471 }
472 472
473 /** 473 /**
474 * @param {!WebInspector.ExecutionContext} a 474 * @param {!SDK.ExecutionContext} a
475 * @param {!WebInspector.ExecutionContext} b 475 * @param {!SDK.ExecutionContext} b
476 * @return {number} 476 * @return {number}
477 */ 477 */
478 static comparator(a, b) { 478 static comparator(a, b) {
479 /** 479 /**
480 * @param {!WebInspector.Target} target 480 * @param {!SDK.Target} target
481 * @return {number} 481 * @return {number}
482 */ 482 */
483 function targetWeight(target) { 483 function targetWeight(target) {
484 if (target.hasBrowserCapability()) 484 if (target.hasBrowserCapability())
485 return 3; 485 return 3;
486 if (target.hasJSCapability()) 486 if (target.hasJSCapability())
487 return 2; 487 return 2;
488 return 1; 488 return 1;
489 } 489 }
490 490
(...skipping 10 matching lines...) Expand all
501 } 501 }
502 502
503 /** 503 /**
504 * @param {string} expression 504 * @param {string} expression
505 * @param {string} objectGroup 505 * @param {string} objectGroup
506 * @param {boolean} includeCommandLineAPI 506 * @param {boolean} includeCommandLineAPI
507 * @param {boolean} silent 507 * @param {boolean} silent
508 * @param {boolean} returnByValue 508 * @param {boolean} returnByValue
509 * @param {boolean} generatePreview 509 * @param {boolean} generatePreview
510 * @param {boolean} userGesture 510 * @param {boolean} userGesture
511 * @param {function(?WebInspector.RemoteObject, !Protocol.Runtime.ExceptionDet ails=)} callback 511 * @param {function(?SDK.RemoteObject, !Protocol.Runtime.ExceptionDetails=)} c allback
512 */ 512 */
513 evaluate( 513 evaluate(
514 expression, 514 expression,
515 objectGroup, 515 objectGroup,
516 includeCommandLineAPI, 516 includeCommandLineAPI,
517 silent, 517 silent,
518 returnByValue, 518 returnByValue,
519 generatePreview, 519 generatePreview,
520 userGesture, 520 userGesture,
521 callback) { 521 callback) {
522 // FIXME: It will be moved to separate ExecutionContext. 522 // FIXME: It will be moved to separate ExecutionContext.
523 if (this.debuggerModel.selectedCallFrame()) { 523 if (this.debuggerModel.selectedCallFrame()) {
524 this.debuggerModel.evaluateOnSelectedCallFrame( 524 this.debuggerModel.evaluateOnSelectedCallFrame(
525 expression, objectGroup, includeCommandLineAPI, silent, returnByValue, generatePreview, callback); 525 expression, objectGroup, includeCommandLineAPI, silent, returnByValue, generatePreview, callback);
526 return; 526 return;
527 } 527 }
528 this._evaluateGlobal.apply(this, arguments); 528 this._evaluateGlobal.apply(this, arguments);
529 } 529 }
530 530
531 /** 531 /**
532 * @param {string} objectGroup 532 * @param {string} objectGroup
533 * @param {boolean} generatePreview 533 * @param {boolean} generatePreview
534 * @param {function(?WebInspector.RemoteObject, !Protocol.Runtime.ExceptionDet ails=)} callback 534 * @param {function(?SDK.RemoteObject, !Protocol.Runtime.ExceptionDetails=)} c allback
535 */ 535 */
536 globalObject(objectGroup, generatePreview, callback) { 536 globalObject(objectGroup, generatePreview, callback) {
537 this._evaluateGlobal('this', objectGroup, false, true, false, generatePrevie w, false, callback); 537 this._evaluateGlobal('this', objectGroup, false, true, false, generatePrevie w, false, callback);
538 } 538 }
539 539
540 /** 540 /**
541 * @param {string} expression 541 * @param {string} expression
542 * @param {string} objectGroup 542 * @param {string} objectGroup
543 * @param {boolean} includeCommandLineAPI 543 * @param {boolean} includeCommandLineAPI
544 * @param {boolean} silent 544 * @param {boolean} silent
545 * @param {boolean} returnByValue 545 * @param {boolean} returnByValue
546 * @param {boolean} generatePreview 546 * @param {boolean} generatePreview
547 * @param {boolean} userGesture 547 * @param {boolean} userGesture
548 * @param {function(?WebInspector.RemoteObject, !Protocol.Runtime.ExceptionDet ails=)} callback 548 * @param {function(?SDK.RemoteObject, !Protocol.Runtime.ExceptionDetails=)} c allback
549 */ 549 */
550 _evaluateGlobal( 550 _evaluateGlobal(
551 expression, 551 expression,
552 objectGroup, 552 objectGroup,
553 includeCommandLineAPI, 553 includeCommandLineAPI,
554 silent, 554 silent,
555 returnByValue, 555 returnByValue,
556 generatePreview, 556 generatePreview,
557 userGesture, 557 userGesture,
558 callback) { 558 callback) {
559 if (!expression) { 559 if (!expression) {
560 // There is no expression, so the completion should happen against global properties. 560 // There is no expression, so the completion should happen against global properties.
561 expression = 'this'; 561 expression = 'this';
562 } 562 }
563 563
564 /** 564 /**
565 * @this {WebInspector.ExecutionContext} 565 * @this {SDK.ExecutionContext}
566 * @param {?Protocol.Error} error 566 * @param {?Protocol.Error} error
567 * @param {!Protocol.Runtime.RemoteObject} result 567 * @param {!Protocol.Runtime.RemoteObject} result
568 * @param {!Protocol.Runtime.ExceptionDetails=} exceptionDetails 568 * @param {!Protocol.Runtime.ExceptionDetails=} exceptionDetails
569 */ 569 */
570 function evalCallback(error, result, exceptionDetails) { 570 function evalCallback(error, result, exceptionDetails) {
571 if (error) { 571 if (error) {
572 console.error(error); 572 console.error(error);
573 callback(null); 573 callback(null);
574 return; 574 return;
575 } 575 }
576 callback(this.runtimeModel.createRemoteObject(result), exceptionDetails); 576 callback(this.runtimeModel.createRemoteObject(result), exceptionDetails);
577 } 577 }
578 this.target().runtimeAgent().evaluate( 578 this.target().runtimeAgent().evaluate(
579 expression, objectGroup, includeCommandLineAPI, silent, this.id, returnB yValue, generatePreview, userGesture, 579 expression, objectGroup, includeCommandLineAPI, silent, this.id, returnB yValue, generatePreview, userGesture,
580 false, evalCallback.bind(this)); 580 false, evalCallback.bind(this));
581 } 581 }
582 582
583 /** 583 /**
584 * @return {string} 584 * @return {string}
585 */ 585 */
586 label() { 586 label() {
587 return this._label; 587 return this._label;
588 } 588 }
589 589
590 /** 590 /**
591 * @param {string} label 591 * @param {string} label
592 */ 592 */
593 setLabel(label) { 593 setLabel(label) {
594 this._label = label; 594 this._label = label;
595 this.runtimeModel.dispatchEventToListeners(WebInspector.RuntimeModel.Events. ExecutionContextChanged, this); 595 this.runtimeModel.dispatchEventToListeners(SDK.RuntimeModel.Events.Execution ContextChanged, this);
596 } 596 }
597 }; 597 };
598 598
599 599
600 /** 600 /**
601 * @unrestricted 601 * @unrestricted
602 */ 602 */
603 WebInspector.EventListener = class extends WebInspector.SDKObject { 603 SDK.EventListener = class extends SDK.SDKObject {
604 /** 604 /**
605 * @param {!WebInspector.Target} target 605 * @param {!SDK.Target} target
606 * @param {!WebInspector.RemoteObject} eventTarget 606 * @param {!SDK.RemoteObject} eventTarget
607 * @param {string} type 607 * @param {string} type
608 * @param {boolean} useCapture 608 * @param {boolean} useCapture
609 * @param {boolean} passive 609 * @param {boolean} passive
610 * @param {boolean} once 610 * @param {boolean} once
611 * @param {?WebInspector.RemoteObject} handler 611 * @param {?SDK.RemoteObject} handler
612 * @param {?WebInspector.RemoteObject} originalHandler 612 * @param {?SDK.RemoteObject} originalHandler
613 * @param {!WebInspector.DebuggerModel.Location} location 613 * @param {!SDK.DebuggerModel.Location} location
614 * @param {?WebInspector.RemoteObject} removeFunction 614 * @param {?SDK.RemoteObject} removeFunction
615 * @param {string=} listenerType 615 * @param {string=} listenerType
616 */ 616 */
617 constructor( 617 constructor(
618 target, 618 target,
619 eventTarget, 619 eventTarget,
620 type, 620 type,
621 useCapture, 621 useCapture,
622 passive, 622 passive,
623 once, 623 once,
624 handler, 624 handler,
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
663 } 663 }
664 664
665 /** 665 /**
666 * @return {boolean} 666 * @return {boolean}
667 */ 667 */
668 once() { 668 once() {
669 return this._once; 669 return this._once;
670 } 670 }
671 671
672 /** 672 /**
673 * @return {?WebInspector.RemoteObject} 673 * @return {?SDK.RemoteObject}
674 */ 674 */
675 handler() { 675 handler() {
676 return this._handler; 676 return this._handler;
677 } 677 }
678 678
679 /** 679 /**
680 * @return {!WebInspector.DebuggerModel.Location} 680 * @return {!SDK.DebuggerModel.Location}
681 */ 681 */
682 location() { 682 location() {
683 return this._location; 683 return this._location;
684 } 684 }
685 685
686 /** 686 /**
687 * @return {string} 687 * @return {string}
688 */ 688 */
689 sourceURL() { 689 sourceURL() {
690 return this._sourceURL; 690 return this._sourceURL;
691 } 691 }
692 692
693 /** 693 /**
694 * @return {?WebInspector.RemoteObject} 694 * @return {?SDK.RemoteObject}
695 */ 695 */
696 originalHandler() { 696 originalHandler() {
697 return this._originalHandler; 697 return this._originalHandler;
698 } 698 }
699 699
700 /** 700 /**
701 * @return {?WebInspector.RemoteObject} 701 * @return {?SDK.RemoteObject}
702 */ 702 */
703 removeFunction() { 703 removeFunction() {
704 return this._removeFunction; 704 return this._removeFunction;
705 } 705 }
706 706
707 /** 707 /**
708 * @return {!Promise<undefined>} 708 * @return {!Promise<undefined>}
709 */ 709 */
710 remove() { 710 remove() {
711 if (!this._removeFunction) 711 if (!this._removeFunction)
712 return Promise.resolve(); 712 return Promise.resolve();
713 return this._removeFunction 713 return this._removeFunction
714 .callFunctionPromise( 714 .callFunctionPromise(
715 callCustomRemove, 715 callCustomRemove,
716 [ 716 [
717 WebInspector.RemoteObject.toCallArgument(this._type), 717 SDK.RemoteObject.toCallArgument(this._type),
718 WebInspector.RemoteObject.toCallArgument(this._originalHandler), 718 SDK.RemoteObject.toCallArgument(this._originalHandler),
719 WebInspector.RemoteObject.toCallArgument(this._useCapture), 719 SDK.RemoteObject.toCallArgument(this._useCapture),
720 WebInspector.RemoteObject.toCallArgument(this._passive), 720 SDK.RemoteObject.toCallArgument(this._passive),
721 ]) 721 ])
722 .then(() => undefined); 722 .then(() => undefined);
723 723
724 /** 724 /**
725 * @param {string} type 725 * @param {string} type
726 * @param {function()} listener 726 * @param {function()} listener
727 * @param {boolean} useCapture 727 * @param {boolean} useCapture
728 * @param {boolean} passive 728 * @param {boolean} passive
729 * @this {Function} 729 * @this {Function}
730 * @suppressReceiverCheck 730 * @suppressReceiverCheck
731 */ 731 */
732 function callCustomRemove(type, listener, useCapture, passive) { 732 function callCustomRemove(type, listener, useCapture, passive) {
733 this.call(null, type, listener, useCapture, passive); 733 this.call(null, type, listener, useCapture, passive);
734 } 734 }
735 } 735 }
736 736
737 /** 737 /**
738 * @return {!Promise<undefined>} 738 * @return {!Promise<undefined>}
739 */ 739 */
740 togglePassive() { 740 togglePassive() {
741 return new Promise(promiseConstructor.bind(this)); 741 return new Promise(promiseConstructor.bind(this));
742 742
743 /** 743 /**
744 * @param {function()} success 744 * @param {function()} success
745 * @this {WebInspector.EventListener} 745 * @this {SDK.EventListener}
746 */ 746 */
747 function promiseConstructor(success) { 747 function promiseConstructor(success) {
748 this._eventTarget 748 this._eventTarget
749 .callFunctionPromise( 749 .callFunctionPromise(
750 callTogglePassive, 750 callTogglePassive,
751 [ 751 [
752 WebInspector.RemoteObject.toCallArgument(this._type), 752 SDK.RemoteObject.toCallArgument(this._type),
753 WebInspector.RemoteObject.toCallArgument(this._originalHandler), 753 SDK.RemoteObject.toCallArgument(this._originalHandler),
754 WebInspector.RemoteObject.toCallArgument(this._useCapture), 754 SDK.RemoteObject.toCallArgument(this._useCapture),
755 WebInspector.RemoteObject.toCallArgument(this._passive), 755 SDK.RemoteObject.toCallArgument(this._passive),
756 ]) 756 ])
757 .then(success); 757 .then(success);
758 758
759 /** 759 /**
760 * @param {string} type 760 * @param {string} type
761 * @param {function()} listener 761 * @param {function()} listener
762 * @param {boolean} useCapture 762 * @param {boolean} useCapture
763 * @param {boolean} passive 763 * @param {boolean} passive
764 * @this {Object} 764 * @this {Object}
765 * @suppressReceiverCheck 765 * @suppressReceiverCheck
(...skipping 27 matching lines...) Expand all
793 this._type === 'wheel'; 793 this._type === 'wheel';
794 } 794 }
795 795
796 /** 796 /**
797 * @return {boolean} 797 * @return {boolean}
798 */ 798 */
799 isNormalListenerType() { 799 isNormalListenerType() {
800 return this._listenerType === 'normal'; 800 return this._listenerType === 'normal';
801 } 801 }
802 }; 802 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698