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

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

Issue 2450973002: [DevTools] Inherit WI.Target from Protocol.Target. (Closed)
Patch Set: 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) 2011 Google Inc. All rights reserved. 2 * Copyright (C) 2011 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 18 matching lines...) Expand all
29 */ 29 */
30 30
31 /** 31 /**
32 * @constructor 32 * @constructor
33 */ 33 */
34 function InspectorBackendClass() 34 function InspectorBackendClass()
35 { 35 {
36 this._agentPrototypes = {}; 36 this._agentPrototypes = {};
37 this._dispatcherPrototypes = {}; 37 this._dispatcherPrototypes = {};
38 this._initialized = false; 38 this._initialized = false;
39 this._initProtocolAgentsConstructor();
40 } 39 }
41 40
42 InspectorBackendClass._DevToolsErrorCode = -32000; 41 InspectorBackendClass._DevToolsErrorCode = -32000;
43 InspectorBackendClass.DevToolsStubErrorCode = -32015; 42 InspectorBackendClass.DevToolsStubErrorCode = -32015;
44 43
45 /** 44 /**
46 * @param {string} error 45 * @param {string} error
47 * @param {!Object} messageObject 46 * @param {!Object} messageObject
48 */ 47 */
49 InspectorBackendClass.reportProtocolError = function(error, messageObject) 48 InspectorBackendClass.reportProtocolError = function(error, messageObject)
50 { 49 {
51 console.error(error + ": " + JSON.stringify(messageObject)); 50 console.error(error + ": " + JSON.stringify(messageObject));
52 }; 51 };
53 52
54 InspectorBackendClass.prototype = { 53 InspectorBackendClass.prototype = {
55 /** 54 /**
56 * @return {boolean} 55 * @return {boolean}
57 */ 56 */
58 isInitialized: function() 57 isInitialized: function()
59 { 58 {
60 return this._initialized; 59 return this._initialized;
61 }, 60 },
62 61
63 _initProtocolAgentsConstructor: function()
64 {
65 window.Protocol = {};
66
67 /**
68 * @constructor
69 * @param {!Object.<string, !Object>} agentsMap
70 */
71 window.Protocol.Agents = function(agentsMap) {
72 this._agentsMap = agentsMap;
73 };
74 },
75
76 /** 62 /**
77 * @param {string} domain 63 * @param {string} domain
78 */ 64 */
79 _addAgentGetterMethodToProtocolAgentsPrototype: function(domain) 65 _addAgentGetterMethodToProtocolTargetPrototype: function(domain)
80 { 66 {
81 var upperCaseLength = 0; 67 var upperCaseLength = 0;
82 while (upperCaseLength < domain.length && domain[upperCaseLength].toLowe rCase() !== domain[upperCaseLength]) 68 while (upperCaseLength < domain.length && domain[upperCaseLength].toLowe rCase() !== domain[upperCaseLength])
83 ++upperCaseLength; 69 ++upperCaseLength;
84 70
85 var methodName = domain.substr(0, upperCaseLength).toLowerCase() + domai n.slice(upperCaseLength) + "Agent"; 71 var methodName = domain.substr(0, upperCaseLength).toLowerCase() + domai n.slice(upperCaseLength) + "Agent";
86 72
87 /** 73 /**
88 * @this {Protocol.Agents} 74 * @this {Protocol.Target}
89 */ 75 */
90 function agentGetter() 76 function agentGetter()
91 { 77 {
92 return this._agentsMap[domain]; 78 return this._agents[domain];
93 } 79 }
94 80
95 window.Protocol.Agents.prototype[methodName] = agentGetter; 81 Protocol.Target.prototype[methodName] = agentGetter;
96 82
97 /** 83 /**
98 * @this {Protocol.Agents} 84 * @this {Protocol.Target}
99 */ 85 */
100 function registerDispatcher(dispatcher) 86 function registerDispatcher(dispatcher)
101 { 87 {
102 this.registerDispatcher(domain, dispatcher); 88 this.registerDispatcher(domain, dispatcher);
103 } 89 }
104 90
105 window.Protocol.Agents.prototype["register" + domain + "Dispatcher"] = r egisterDispatcher; 91 Protocol.Target.prototype["register" + domain + "Dispatcher"] = register Dispatcher;
106 }, 92 },
107 93
108 /** 94 /**
109 * @param {string} domain 95 * @param {string} domain
110 * @return {!InspectorBackendClass.AgentPrototype} 96 * @return {!InspectorBackendClass._AgentPrototype}
111 */ 97 */
112 _agentPrototype: function(domain) 98 _agentPrototype: function(domain)
113 { 99 {
114 if (!this._agentPrototypes[domain]) { 100 if (!this._agentPrototypes[domain]) {
115 this._agentPrototypes[domain] = new InspectorBackendClass.AgentProto type(domain); 101 this._agentPrototypes[domain] = new InspectorBackendClass._AgentProt otype(domain);
116 this._addAgentGetterMethodToProtocolAgentsPrototype(domain); 102 this._addAgentGetterMethodToProtocolTargetPrototype(domain);
117 } 103 }
118 104
119 return this._agentPrototypes[domain]; 105 return this._agentPrototypes[domain];
120 }, 106 },
121 107
122 /** 108 /**
123 * @param {string} domain 109 * @param {string} domain
124 * @return {!InspectorBackendClass.DispatcherPrototype} 110 * @return {!InspectorBackendClass._DispatcherPrototype}
125 */ 111 */
126 _dispatcherPrototype: function(domain) 112 _dispatcherPrototype: function(domain)
127 { 113 {
128 if (!this._dispatcherPrototypes[domain]) 114 if (!this._dispatcherPrototypes[domain])
129 this._dispatcherPrototypes[domain] = new InspectorBackendClass.Dispa tcherPrototype(); 115 this._dispatcherPrototypes[domain] = new InspectorBackendClass._Disp atcherPrototype();
130 return this._dispatcherPrototypes[domain]; 116 return this._dispatcherPrototypes[domain];
131 }, 117 },
132 118
133 /** 119 /**
134 * @param {string} method 120 * @param {string} method
135 * @param {!Array.<!Object>} signature 121 * @param {!Array.<!Object>} signature
136 * @param {!Array.<string>} replyArgs 122 * @param {!Array.<string>} replyArgs
137 * @param {boolean} hasErrorData 123 * @param {boolean} hasErrorData
138 */ 124 */
139 registerCommand: function(method, signature, replyArgs, hasErrorData) 125 registerCommand: function(method, signature, replyArgs, hasErrorData)
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 } 179 }
194 if (constructor) 180 if (constructor)
195 clientCallback(new constructor(value)); 181 clientCallback(new constructor(value));
196 else 182 else
197 clientCallback(value); 183 clientCallback(value);
198 } 184 }
199 return callbackWrapper; 185 return callbackWrapper;
200 } 186 }
201 }; 187 };
202 188
189 var InspectorBackend = new InspectorBackendClass();
190
203 /** 191 /**
204 * @interface 192 * @interface
205 */ 193 */
206 InspectorBackendClass.Connection = function() 194 InspectorBackendClass.Connection = function()
207 { 195 {
208 }; 196 };
209 197
210 InspectorBackendClass.Connection.prototype = { 198 InspectorBackendClass.Connection.prototype = {
211 /** 199 /**
212 * @param {string} message 200 * @param {string} message
(...skipping 12 matching lines...) Expand all
225 * onDisconnect: function(string) 213 * onDisconnect: function(string)
226 * }} 214 * }}
227 */ 215 */
228 InspectorBackendClass.Connection.Params; 216 InspectorBackendClass.Connection.Params;
229 217
230 /** 218 /**
231 * @typedef {function(!InspectorBackendClass.Connection.Params):!InspectorBacken dClass.Connection} 219 * @typedef {function(!InspectorBackendClass.Connection.Params):!InspectorBacken dClass.Connection}
232 */ 220 */
233 InspectorBackendClass.Connection.Factory; 221 InspectorBackendClass.Connection.Factory;
234 222
223 var Protocol = {};
224
225 /** @typedef {string} */
226 Protocol.Error;
227
235 /** 228 /**
236 * @constructor 229 * @constructor
237 * @param {!InspectorBackendClass.Connection.Factory} connectionFactory 230 * @param {!InspectorBackendClass.Connection.Factory} connectionFactory
238 * @param {function(string)} disconnectedCallback
239 */ 231 */
240 InspectorBackendClass.TargetPrototype = function(connectionFactory, disconnected Callback) 232 Protocol.Target = function(connectionFactory)
241 { 233 {
242 this._connection = connectionFactory({onMessage: this.dispatch.bind(this), o nDisconnect: this._disconnected.bind(this)}); 234 this._connection = connectionFactory({onMessage: this._onMessage.bind(this), onDisconnect: this._onDisconnect.bind(this)});
243 this._disconnectedCallback = disconnectedCallback;
244 this._lastMessageId = 1; 235 this._lastMessageId = 1;
245 this._pendingResponsesCount = 0; 236 this._pendingResponsesCount = 0;
246 this._agents = {}; 237 this._agents = {};
247 this._dispatchers = {}; 238 this._dispatchers = {};
248 this._callbacks = {}; 239 this._callbacks = {};
249 this._initialize(InspectorBackend._agentPrototypes, InspectorBackend._dispat cherPrototypes); 240 this._initialize(InspectorBackend._agentPrototypes, InspectorBackend._dispat cherPrototypes);
250 if (!InspectorBackendClass.deprecatedRunAfterPendingDispatches) 241 if (!InspectorBackendClass.deprecatedRunAfterPendingDispatches)
251 InspectorBackendClass.deprecatedRunAfterPendingDispatches = this._deprec atedRunAfterPendingDispatches.bind(this); 242 InspectorBackendClass.deprecatedRunAfterPendingDispatches = this._deprec atedRunAfterPendingDispatches.bind(this);
252 if (!InspectorBackendClass.sendRawMessageForTesting) 243 if (!InspectorBackendClass.sendRawMessageForTesting)
253 InspectorBackendClass.sendRawMessageForTesting = this._sendRawMessageFor Testing.bind(this); 244 InspectorBackendClass.sendRawMessageForTesting = this._sendRawMessageFor Testing.bind(this);
254 }; 245 };
255 246
256 InspectorBackendClass.TargetPrototype.prototype = { 247 Protocol.Target.prototype = {
257 /** 248 /**
258 * @param {!Object.<string, !InspectorBackendClass.AgentPrototype>} agentPro totypes 249 * @param {!Object.<string, !InspectorBackendClass._AgentPrototype>} agentPr ototypes
259 * @param {!Object.<string, !InspectorBackendClass.DispatcherPrototype>} dis patcherPrototypes 250 * @param {!Object.<string, !InspectorBackendClass._DispatcherPrototype>} di spatcherPrototypes
260 */ 251 */
261 _initialize: function(agentPrototypes, dispatcherPrototypes) 252 _initialize: function(agentPrototypes, dispatcherPrototypes)
262 { 253 {
263 for (var domain in agentPrototypes) { 254 for (var domain in agentPrototypes) {
264 this._agents[domain] = Object.create(agentPrototypes[domain]); 255 this._agents[domain] = Object.create(agentPrototypes[domain]);
265 this._agents[domain].setConnection(this); 256 this._agents[domain].setTarget(this);
266 } 257 }
267 258
268 for (var domain in dispatcherPrototypes) 259 for (var domain in dispatcherPrototypes)
269 this._dispatchers[domain] = Object.create(dispatcherPrototypes[domai n]); 260 this._dispatchers[domain] = Object.create(dispatcherPrototypes[domai n]);
270 }, 261 },
271 262
272 /** 263 /**
273 * @return {number} 264 * @return {number}
274 */ 265 */
275 nextMessageId: function() 266 _nextMessageId: function()
276 { 267 {
277 return this._lastMessageId++; 268 return this._lastMessageId++;
278 }, 269 },
279 270
280 /** 271 /**
281 * @param {string} domain 272 * @param {string} domain
282 * @return {!InspectorBackendClass.AgentPrototype} 273 * @return {!InspectorBackendClass._AgentPrototype}
283 */ 274 */
284 agent: function(domain) 275 _agent: function(domain)
285 { 276 {
286 return this._agents[domain]; 277 return this._agents[domain];
287 }, 278 },
288 279
289 /** 280 /**
290 * @return {!Object.<string, !Object>}
291 */
292 agentsMap: function()
293 {
294 return this._agents;
295 },
296
297 /**
298 * @param {string} domain 281 * @param {string} domain
299 * @param {string} method 282 * @param {string} method
300 * @param {?Object} params 283 * @param {?Object} params
301 * @param {?function(*)} callback 284 * @param {?function(*)} callback
302 */ 285 */
303 _wrapCallbackAndSendMessageObject: function(domain, method, params, callback ) 286 _wrapCallbackAndSendMessageObject: function(domain, method, params, callback )
304 { 287 {
305 if (!this._connection) { 288 if (!this._connection) {
306 if (callback) 289 if (callback)
307 this._dispatchConnectionErrorResponse(domain, method, callback); 290 this._dispatchConnectionErrorResponse(domain, method, callback);
308 return; 291 return;
309 } 292 }
310 293
311 var messageObject = {}; 294 var messageObject = {};
312 var messageId = this.nextMessageId(); 295 var messageId = this._nextMessageId();
313 messageObject.id = messageId; 296 messageObject.id = messageId;
314 messageObject.method = method; 297 messageObject.method = method;
315 if (params) 298 if (params)
316 messageObject.params = params; 299 messageObject.params = params;
317 300
318 var wrappedCallback = this._wrap(callback, domain, method); 301 var wrappedCallback = this._wrap(callback, domain, method);
319 var message = JSON.stringify(messageObject); 302 var message = JSON.stringify(messageObject);
320 303
321 if (InspectorBackendClass.Options.dumpInspectorProtocolMessages) 304 if (InspectorBackendClass.Options.dumpInspectorProtocolMessages)
322 this._dumpProtocolMessage("frontend: " + message); 305 this._dumpProtocolMessage("frontend: " + message);
(...skipping 29 matching lines...) Expand all
352 */ 335 */
353 _sendRawMessageForTesting: function(method, params, callback) 336 _sendRawMessageForTesting: function(method, params, callback)
354 { 337 {
355 var domain = method.split(".")[0]; 338 var domain = method.split(".")[0];
356 this._wrapCallbackAndSendMessageObject(domain, method, params, callback) ; 339 this._wrapCallbackAndSendMessageObject(domain, method, params, callback) ;
357 }, 340 },
358 341
359 /** 342 /**
360 * @param {!Object|string} message 343 * @param {!Object|string} message
361 */ 344 */
362 dispatch: function(message) 345 _onMessage: function(message)
363 { 346 {
364 if (InspectorBackendClass.Options.dumpInspectorProtocolMessages) 347 if (InspectorBackendClass.Options.dumpInspectorProtocolMessages)
365 this._dumpProtocolMessage("backend: " + ((typeof message === "string ") ? message : JSON.stringify(message))); 348 this._dumpProtocolMessage("backend: " + ((typeof message === "string ") ? message : JSON.stringify(message)));
366 349
367 var messageObject = /** @type {!Object} */ ((typeof message === "string" ) ? JSON.parse(message) : message); 350 var messageObject = /** @type {!Object} */ ((typeof message === "string" ) ? JSON.parse(message) : message);
368 351
369 if ("id" in messageObject) { // just a response for some request 352 if ("id" in messageObject) { // just a response for some request
370 var callback = this._callbacks[messageObject.id]; 353 var callback = this._callbacks[messageObject.id];
371 if (!callback) { 354 if (!callback) {
372 InspectorBackendClass.reportProtocolError("Protocol Error: the m essage with wrong id", messageObject); 355 InspectorBackendClass.reportProtocolError("Protocol Error: the m essage with wrong id", messageObject);
373 return; 356 return;
374 } 357 }
375 358
376 var processingStartTime; 359 var processingStartTime;
377 if (InspectorBackendClass.Options.dumpInspectorTimeStats) 360 if (InspectorBackendClass.Options.dumpInspectorTimeStats)
378 processingStartTime = Date.now(); 361 processingStartTime = Date.now();
379 362
380 this.agent(callback.domain).dispatchResponse(messageObject, callback .methodName, callback); 363 this._agent(callback.domain).dispatchResponse(messageObject, callbac k.methodName, callback);
381 --this._pendingResponsesCount; 364 --this._pendingResponsesCount;
382 delete this._callbacks[messageObject.id]; 365 delete this._callbacks[messageObject.id];
383 366
384 if (InspectorBackendClass.Options.dumpInspectorTimeStats) 367 if (InspectorBackendClass.Options.dumpInspectorTimeStats)
385 console.log("time-stats: " + callback.methodName + " = " + (proc essingStartTime - callback.sendRequestTime) + " + " + (Date.now() - processingSt artTime)); 368 console.log("time-stats: " + callback.methodName + " = " + (proc essingStartTime - callback.sendRequestTime) + " + " + (Date.now() - processingSt artTime));
386 369
387 if (this._scripts && !this._pendingResponsesCount) 370 if (this._scripts && !this._pendingResponsesCount)
388 this._deprecatedRunAfterPendingDispatches(); 371 this._deprecatedRunAfterPendingDispatches();
389 } else { 372 } else {
390 if (!("method" in messageObject)) { 373 if (!("method" in messageObject)) {
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
449 * @param {string} message 432 * @param {string} message
450 */ 433 */
451 _dumpProtocolMessage: function(message) 434 _dumpProtocolMessage: function(message)
452 { 435 {
453 console.log(message); 436 console.log(message);
454 }, 437 },
455 438
456 /** 439 /**
457 * @param {string} reason 440 * @param {string} reason
458 */ 441 */
459 _disconnected: function(reason) 442 _onDisconnect: function(reason)
460 { 443 {
461 this._connection = null; 444 this._connection = null;
462 this._runPendingCallbacks(); 445 this._runPendingCallbacks();
463 this._disconnectedCallback(reason); 446 this.dispose();
464 this._disconnectedCallback = null; 447 },
448
449 /**
450 * @protected
451 */
452 dispose: function()
453 {
454 },
455
456 /**
457 * @return {boolean}
458 */
459 isDisposed: function()
460 {
461 return !this._connection;
465 }, 462 },
466 463
467 _runPendingCallbacks: function() 464 _runPendingCallbacks: function()
468 { 465 {
469 var keys = Object.keys(this._callbacks).map(function(num) { return parse Int(num, 10); }); 466 var keys = Object.keys(this._callbacks).map(function(num) { return parse Int(num, 10); });
470 for (var i = 0; i < keys.length; ++i) { 467 for (var i = 0; i < keys.length; ++i) {
471 var callback = this._callbacks[keys[i]]; 468 var callback = this._callbacks[keys[i]];
472 this._dispatchConnectionErrorResponse(callback.domain, callback.meth odName, callback); 469 this._dispatchConnectionErrorResponse(callback.domain, callback.meth odName, callback);
473 } 470 }
474 this._callbacks = {}; 471 this._callbacks = {};
475 }, 472 },
476 473
477 /** 474 /**
478 * @param {string} domain 475 * @param {string} domain
479 * @param {string} methodName 476 * @param {string} methodName
480 * @param {function(*)} callback 477 * @param {function(*)} callback
481 */ 478 */
482 _dispatchConnectionErrorResponse: function(domain, methodName, callback) 479 _dispatchConnectionErrorResponse: function(domain, methodName, callback)
483 { 480 {
484 var error = { message: "Connection is closed, can't dispatch pending " + methodName, code: InspectorBackendClass._DevToolsErrorCode, data: null}; 481 var error = { message: "Connection is closed, can't dispatch pending " + methodName, code: InspectorBackendClass._DevToolsErrorCode, data: null};
485 var messageObject = {error: error}; 482 var messageObject = {error: error};
486 setTimeout(InspectorBackendClass.AgentPrototype.prototype.dispatchRespon se.bind(this.agent(domain), messageObject, methodName, callback), 0); 483 setTimeout(InspectorBackendClass._AgentPrototype.prototype.dispatchRespo nse.bind(this._agent(domain), messageObject, methodName, callback), 0);
487 }, 484 },
488 }; 485 };
489 486
490 /** 487 /**
491 * @constructor 488 * @constructor
492 * @param {string} domain 489 * @param {string} domain
493 */ 490 */
494 InspectorBackendClass.AgentPrototype = function(domain) 491 InspectorBackendClass._AgentPrototype = function(domain)
495 { 492 {
496 this._replyArgs = {}; 493 this._replyArgs = {};
497 this._hasErrorData = {}; 494 this._hasErrorData = {};
498 this._domain = domain; 495 this._domain = domain;
499 this._suppressErrorLogging = false;
500 }; 496 };
501 497
502 InspectorBackendClass.AgentPrototype.prototype = { 498 InspectorBackendClass._AgentPrototype.prototype = {
503 /** 499 /**
504 * @param {!InspectorBackendClass.Connection} connection 500 * @param {!Protocol.Target} target
505 */ 501 */
506 setConnection: function(connection) 502 setTarget: function(target)
507 { 503 {
508 this._connection = connection; 504 this._target = target;
509 }, 505 },
510 506
511 /** 507 /**
512 * @param {string} methodName 508 * @param {string} methodName
513 * @param {!Array.<!Object>} signature 509 * @param {!Array.<!Object>} signature
514 * @param {!Array.<string>} replyArgs 510 * @param {!Array.<string>} replyArgs
515 * @param {boolean} hasErrorData 511 * @param {boolean} hasErrorData
516 */ 512 */
517 registerCommand: function(methodName, signature, replyArgs, hasErrorData) 513 registerCommand: function(methodName, signature, replyArgs, hasErrorData)
518 { 514 {
519 var domainAndMethod = this._domain + "." + methodName; 515 var domainAndMethod = this._domain + "." + methodName;
520 516
521 /** 517 /**
522 * @param {...*} vararg 518 * @param {...*} vararg
523 * @this {InspectorBackendClass.AgentPrototype} 519 * @this {InspectorBackendClass._AgentPrototype}
524 * @return {!Promise.<*>} 520 * @return {!Promise.<*>}
525 */ 521 */
526 function sendMessagePromise(vararg) 522 function sendMessagePromise(vararg)
527 { 523 {
528 var params = Array.prototype.slice.call(arguments); 524 var params = Array.prototype.slice.call(arguments);
529 return InspectorBackendClass.AgentPrototype.prototype._sendMessageTo BackendPromise.call(this, domainAndMethod, signature, params); 525 return InspectorBackendClass._AgentPrototype.prototype._sendMessageT oBackendPromise.call(this, domainAndMethod, signature, params);
530 } 526 }
531 527
532 this[methodName] = sendMessagePromise; 528 this[methodName] = sendMessagePromise;
533 529
534 /** 530 /**
535 * @param {...*} vararg 531 * @param {...*} vararg
536 * @this {InspectorBackendClass.AgentPrototype} 532 * @this {InspectorBackendClass._AgentPrototype}
537 */ 533 */
538 function invoke(vararg) 534 function invoke(vararg)
539 { 535 {
540 var params = [domainAndMethod].concat(Array.prototype.slice.call(arg uments)); 536 var params = [domainAndMethod].concat(Array.prototype.slice.call(arg uments));
541 InspectorBackendClass.AgentPrototype.prototype._invoke.apply(this, p arams); 537 InspectorBackendClass._AgentPrototype.prototype._invoke.apply(this, params);
542 } 538 }
543 539
544 this["invoke_" + methodName] = invoke; 540 this["invoke_" + methodName] = invoke;
545 541
546 this._replyArgs[domainAndMethod] = replyArgs; 542 this._replyArgs[domainAndMethod] = replyArgs;
547 if (hasErrorData) 543 if (hasErrorData)
548 this._hasErrorData[domainAndMethod] = true; 544 this._hasErrorData[domainAndMethod] = true;
549 }, 545 },
550 546
551 /** 547 /**
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
617 var userCallback = (args.length && typeof args.peekLast() === "function" ) ? args.pop() : null; 613 var userCallback = (args.length && typeof args.peekLast() === "function" ) ? args.pop() : null;
618 var params = this._prepareParameters(method, signature, args, !userCallb ack, onError); 614 var params = this._prepareParameters(method, signature, args, !userCallb ack, onError);
619 if (errorMessage) 615 if (errorMessage)
620 return Promise.reject(new Error(errorMessage)); 616 return Promise.reject(new Error(errorMessage));
621 else 617 else
622 return new Promise(promiseAction.bind(this)); 618 return new Promise(promiseAction.bind(this));
623 619
624 /** 620 /**
625 * @param {function(?)} resolve 621 * @param {function(?)} resolve
626 * @param {function(!Error)} reject 622 * @param {function(!Error)} reject
627 * @this {InspectorBackendClass.AgentPrototype} 623 * @this {InspectorBackendClass._AgentPrototype}
628 */ 624 */
629 function promiseAction(resolve, reject) 625 function promiseAction(resolve, reject)
630 { 626 {
631 /** 627 /**
632 * @param {...*} vararg 628 * @param {...*} vararg
633 */ 629 */
634 function callback(vararg) 630 function callback(vararg)
635 { 631 {
636 var result = userCallback ? userCallback.apply(null, arguments) : undefined; 632 var result = userCallback ? userCallback.apply(null, arguments) : undefined;
637 resolve(result); 633 resolve(result);
638 } 634 }
639 this._connection._wrapCallbackAndSendMessageObject(this._domain, met hod, params, callback); 635 this._target._wrapCallbackAndSendMessageObject(this._domain, method, params, callback);
640 } 636 }
641 }, 637 },
642 638
643 /** 639 /**
644 * @param {string} method 640 * @param {string} method
645 * @param {?Object} args 641 * @param {?Object} args
646 * @param {?function(*)} callback 642 * @param {?function(*)} callback
647 */ 643 */
648 _invoke: function(method, args, callback) 644 _invoke: function(method, args, callback)
649 { 645 {
650 this._connection._wrapCallbackAndSendMessageObject(this._domain, method, args, callback); 646 this._target._wrapCallbackAndSendMessageObject(this._domain, method, arg s, callback);
651 }, 647 },
652 648
653 /** 649 /**
654 * @param {!Object} messageObject 650 * @param {!Object} messageObject
655 * @param {string} methodName 651 * @param {string} methodName
656 * @param {function(*)|function(?Protocol.Error, ?Object)} callback 652 * @param {function(*)|function(?Protocol.Error, ?Object)} callback
657 */ 653 */
658 dispatchResponse: function(messageObject, methodName, callback) 654 dispatchResponse: function(messageObject, methodName, callback)
659 { 655 {
660 if (messageObject.error && messageObject.error.code !== InspectorBackend Class._DevToolsErrorCode && messageObject.error.code !== InspectorBackendClass.D evToolsStubErrorCode && !InspectorBackendClass.Options.suppressRequestErrors && !this._suppressErrorLogging) { 656 if (messageObject.error && messageObject.error.code !== InspectorBackend Class._DevToolsErrorCode && messageObject.error.code !== InspectorBackendClass.D evToolsStubErrorCode && !InspectorBackendClass.Options.suppressRequestErrors) {
661 var id = InspectorBackendClass.Options.dumpInspectorProtocolMessages ? " with id = " + messageObject.id : ""; 657 var id = InspectorBackendClass.Options.dumpInspectorProtocolMessages ? " with id = " + messageObject.id : "";
662 console.error("Request " + methodName + id + " failed. " + JSON.stri ngify(messageObject.error)); 658 console.error("Request " + methodName + id + " failed. " + JSON.stri ngify(messageObject.error));
663 } 659 }
664 660
665 var argumentsArray = []; 661 var argumentsArray = [];
666 argumentsArray[0] = messageObject.error ? messageObject.error.message : null; 662 argumentsArray[0] = messageObject.error ? messageObject.error.message : null;
667 663
668 if (this._hasErrorData[methodName]) 664 if (this._hasErrorData[methodName])
669 argumentsArray[1] = messageObject.error ? messageObject.error.data : null; 665 argumentsArray[1] = messageObject.error ? messageObject.error.data : null;
670 666
671 if (messageObject.result) { 667 if (messageObject.result) {
672 var paramNames = this._replyArgs[methodName] || []; 668 var paramNames = this._replyArgs[methodName] || [];
673 for (var i = 0; i < paramNames.length; ++i) 669 for (var i = 0; i < paramNames.length; ++i)
674 argumentsArray.push(messageObject.result[paramNames[i]]); 670 argumentsArray.push(messageObject.result[paramNames[i]]);
675 } 671 }
676 672
677 callback.apply(null, argumentsArray); 673 callback.apply(null, argumentsArray);
678 }, 674 },
679
680 suppressErrorLogging: function()
681 {
682 this._suppressErrorLogging = true;
683 }
684 }; 675 };
685 676
686 /** 677 /**
687 * @constructor 678 * @constructor
688 */ 679 */
689 InspectorBackendClass.DispatcherPrototype = function() 680 InspectorBackendClass._DispatcherPrototype = function()
690 { 681 {
691 this._eventArgs = {}; 682 this._eventArgs = {};
692 this._dispatcher = null; 683 this._dispatcher = null;
693 }; 684 };
694 685
695 InspectorBackendClass.DispatcherPrototype.prototype = { 686 InspectorBackendClass._DispatcherPrototype.prototype = {
696 687
697 /** 688 /**
698 * @param {string} eventName 689 * @param {string} eventName
699 * @param {!Object} params 690 * @param {!Object} params
700 */ 691 */
701 registerEvent: function(eventName, params) 692 registerEvent: function(eventName, params)
702 { 693 {
703 this._eventArgs[eventName] = params; 694 this._eventArgs[eventName] = params;
704 }, 695 },
705 696
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
746 if (InspectorBackendClass.Options.dumpInspectorTimeStats) 737 if (InspectorBackendClass.Options.dumpInspectorTimeStats)
747 console.log("time-stats: " + messageObject.method + " = " + (Date.no w() - processingStartTime)); 738 console.log("time-stats: " + messageObject.method + " = " + (Date.no w() - processingStartTime));
748 } 739 }
749 }; 740 };
750 741
751 InspectorBackendClass.Options = { 742 InspectorBackendClass.Options = {
752 dumpInspectorTimeStats: false, 743 dumpInspectorTimeStats: false,
753 dumpInspectorProtocolMessages: false, 744 dumpInspectorProtocolMessages: false,
754 suppressRequestErrors: false 745 suppressRequestErrors: false
755 }; 746 };
756
757 InspectorBackend = new InspectorBackendClass();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698