OLD | NEW |
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 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
278 var messageId = this.nextMessageId(); | 278 var messageId = this.nextMessageId(); |
279 messageObject.id = messageId; | 279 messageObject.id = messageId; |
280 | 280 |
281 messageObject.method = method; | 281 messageObject.method = method; |
282 if (params) | 282 if (params) |
283 messageObject.params = params; | 283 messageObject.params = params; |
284 | 284 |
285 var wrappedCallback = this._wrap(callback, domain, method); | 285 var wrappedCallback = this._wrap(callback, domain, method); |
286 | 286 |
287 if (InspectorBackendClass.Options.dumpInspectorProtocolMessages) | 287 if (InspectorBackendClass.Options.dumpInspectorProtocolMessages) |
288 this._dumpProtocolMessage("frontend: " + JSON.stringify(messageObjec
t)); | 288 this._dumpProtocolMessage("frontend: ", messageObject); |
289 | 289 |
290 this.sendMessage(messageObject); | 290 this.sendMessage(messageObject); |
291 ++this._pendingResponsesCount; | 291 ++this._pendingResponsesCount; |
292 this._callbacks[messageId] = wrappedCallback; | 292 this._callbacks[messageId] = wrappedCallback; |
293 }, | 293 }, |
294 | 294 |
295 /** | 295 /** |
296 * @param {?function(*)} callback | 296 * @param {?function(*)} callback |
297 * @param {string} method | 297 * @param {string} method |
298 * @param {string} domain | 298 * @param {string} domain |
(...skipping 18 matching lines...) Expand all Loading... |
317 sendMessage: function(messageObject) | 317 sendMessage: function(messageObject) |
318 { | 318 { |
319 throw "Not implemented"; | 319 throw "Not implemented"; |
320 }, | 320 }, |
321 | 321 |
322 /** | 322 /** |
323 * @param {!Object|string} message | 323 * @param {!Object|string} message |
324 */ | 324 */ |
325 dispatch: function(message) | 325 dispatch: function(message) |
326 { | 326 { |
| 327 var messageObject = /** @type {!Object} */ ((typeof message === "string"
) ? JSON.parse(message) : message); |
| 328 |
327 if (InspectorBackendClass.Options.dumpInspectorProtocolMessages) | 329 if (InspectorBackendClass.Options.dumpInspectorProtocolMessages) |
328 this._dumpProtocolMessage("backend: " + ((typeof message === "string
") ? message : JSON.stringify(message))); | 330 this._dumpProtocolMessage("backend: ", messageObject); |
329 | |
330 var messageObject = /** @type {!Object} */ ((typeof message === "string"
) ? JSON.parse(message) : message); | |
331 | 331 |
332 if ("id" in messageObject) { // just a response for some request | 332 if ("id" in messageObject) { // just a response for some request |
333 var callback = this._callbacks[messageObject.id]; | 333 var callback = this._callbacks[messageObject.id]; |
334 if (!callback) { | 334 if (!callback) { |
335 InspectorBackendClass.reportProtocolError("Protocol Error: the m
essage with wrong id", messageObject); | 335 InspectorBackendClass.reportProtocolError("Protocol Error: the m
essage with wrong id", messageObject); |
336 return; | 336 return; |
337 } | 337 } |
338 | 338 |
339 var processingStartTime; | 339 var processingStartTime; |
340 if (InspectorBackendClass.Options.dumpInspectorTimeStats) | 340 if (InspectorBackendClass.Options.dumpInspectorTimeStats) |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
398 _executeAfterPendingDispatches: function() | 398 _executeAfterPendingDispatches: function() |
399 { | 399 { |
400 if (!this._pendingResponsesCount) { | 400 if (!this._pendingResponsesCount) { |
401 var scripts = this._scripts; | 401 var scripts = this._scripts; |
402 this._scripts = []; | 402 this._scripts = []; |
403 for (var id = 0; id < scripts.length; ++id) | 403 for (var id = 0; id < scripts.length; ++id) |
404 scripts[id].call(this); | 404 scripts[id].call(this); |
405 } | 405 } |
406 }, | 406 }, |
407 | 407 |
408 _dumpProtocolMessage: function(message) | 408 _dumpProtocolMessage: function(message, messageObject) |
409 { | 409 { |
410 console.log(message); | 410 console.log.call(console, message, messageObject); |
411 }, | 411 }, |
412 | 412 |
413 /** | 413 /** |
414 * @protected | 414 * @protected |
415 * @param {string} reason | 415 * @param {string} reason |
416 */ | 416 */ |
417 connectionClosed: function(reason) | 417 connectionClosed: function(reason) |
418 { | 418 { |
419 this._isConnected = false; | 419 this._isConnected = false; |
420 this._runPendingCallbacks(); | 420 this._runPendingCallbacks(); |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
628 | 628 |
629 /** | 629 /** |
630 * @param {!Object} messageObject | 630 * @param {!Object} messageObject |
631 * @param {string} methodName | 631 * @param {string} methodName |
632 * @param {function(*)|function(?Protocol.Error, ?Object)} callback | 632 * @param {function(*)|function(?Protocol.Error, ?Object)} callback |
633 */ | 633 */ |
634 dispatchResponse: function(messageObject, methodName, callback) | 634 dispatchResponse: function(messageObject, methodName, callback) |
635 { | 635 { |
636 if (messageObject.error && messageObject.error.code !== InspectorBackend
Class._DevToolsErrorCode && messageObject.error.code !== InspectorBackendClass.D
evToolsStubErrorCode && !InspectorBackendClass.Options.suppressRequestErrors &&
!this._suppressErrorLogging) { | 636 if (messageObject.error && messageObject.error.code !== InspectorBackend
Class._DevToolsErrorCode && messageObject.error.code !== InspectorBackendClass.D
evToolsStubErrorCode && !InspectorBackendClass.Options.suppressRequestErrors &&
!this._suppressErrorLogging) { |
637 var id = InspectorBackendClass.Options.dumpInspectorProtocolMessages
? " with id = " + messageObject.id : ""; | 637 var id = InspectorBackendClass.Options.dumpInspectorProtocolMessages
? " with id = " + messageObject.id : ""; |
638 console.error("Request " + methodName + id + " failed. " + JSON.stri
ngify(messageObject.error)); | 638 console.error("Request " + methodName + id + " failed. ", messageObj
ect.error); |
639 } | 639 } |
640 | 640 |
641 var argumentsArray = []; | 641 var argumentsArray = []; |
642 argumentsArray[0] = messageObject.error ? messageObject.error.message: n
ull; | 642 argumentsArray[0] = messageObject.error ? messageObject.error.message: n
ull; |
643 | 643 |
644 if (this._hasErrorData[methodName]) | 644 if (this._hasErrorData[methodName]) |
645 argumentsArray[1] = messageObject.error ? messageObject.error.data :
null; | 645 argumentsArray[1] = messageObject.error ? messageObject.error.data :
null; |
646 | 646 |
647 if (messageObject.result) { | 647 if (messageObject.result) { |
648 var paramNames = this._replyArgs[methodName] || []; | 648 var paramNames = this._replyArgs[methodName] || []; |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
724 } | 724 } |
725 } | 725 } |
726 | 726 |
727 InspectorBackendClass.Options = { | 727 InspectorBackendClass.Options = { |
728 dumpInspectorTimeStats: false, | 728 dumpInspectorTimeStats: false, |
729 dumpInspectorProtocolMessages: false, | 729 dumpInspectorProtocolMessages: false, |
730 suppressRequestErrors: false | 730 suppressRequestErrors: false |
731 } | 731 } |
732 | 732 |
733 InspectorBackend = new InspectorBackendClass(); | 733 InspectorBackend = new InspectorBackendClass(); |
OLD | NEW |