| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2009 Google Inc. All rights reserved. | 2 * Copyright (C) 2009 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 620 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 631 })(); | 631 })(); |
| 632 | 632 |
| 633 /** | 633 /** |
| 634 * @constructor | 634 * @constructor |
| 635 */ | 635 */ |
| 636 function InspectorFrontendAPIImpl() | 636 function InspectorFrontendAPIImpl() |
| 637 { | 637 { |
| 638 this._isLoaded = false; | 638 this._isLoaded = false; |
| 639 this._pendingCommands = []; | 639 this._pendingCommands = []; |
| 640 this._debugFrontend = !!WebInspector.queryParam("debugFrontend"); | 640 this._debugFrontend = !!WebInspector.queryParam("debugFrontend"); |
| 641 this._debugCalls = []; | |
| 642 | 641 |
| 643 var descriptors = InspectorFrontendHostAPI.EventDescriptors; | 642 var descriptors = InspectorFrontendHostAPI.EventDescriptors; |
| 644 for (var i = 0; i < descriptors.length; ++i) | 643 for (var i = 0; i < descriptors.length; ++i) |
| 645 this[descriptors[i][0]] = this._dispatch.bind(this, descriptors[i][0], d
escriptors[i][1], descriptors[i][2]); | 644 this[descriptors[i][0]] = this._dispatch.bind(this, descriptors[i][0], d
escriptors[i][1], descriptors[i][2]); |
| 646 } | 645 } |
| 647 | 646 |
| 648 InspectorFrontendAPIImpl.prototype = { | 647 InspectorFrontendAPIImpl.prototype = { |
| 649 loadCompleted: function() | 648 loadCompleted: function() |
| 650 { | 649 { |
| 651 this._isLoaded = true; | 650 this._isLoaded = true; |
| 652 for (var i = 0; i < this._pendingCommands.length; ++i) | 651 for (var i = 0; i < this._pendingCommands.length; ++i) |
| 653 this._pendingCommands[i](); | 652 this._pendingCommands[i](); |
| 654 this._pendingCommands = []; | 653 this._pendingCommands = []; |
| 655 if (window.opener) | 654 if (window.opener) |
| 656 window.opener.postMessage(["loadCompleted"], "*"); | 655 window.opener.postMessage(["loadCompleted"], "*"); |
| 657 }, | 656 }, |
| 658 | 657 |
| 659 /** | 658 /** |
| 660 * @param {string} name | 659 * @param {string} name |
| 661 * @param {!Array.<string>} signature | 660 * @param {!Array.<string>} signature |
| 662 * @param {boolean} runOnceLoaded | 661 * @param {boolean} runOnceLoaded |
| 663 */ | 662 */ |
| 664 _dispatch: function(name, signature, runOnceLoaded) | 663 _dispatch: function(name, signature, runOnceLoaded) |
| 665 { | 664 { |
| 666 var params = Array.prototype.slice.call(arguments, 3); | 665 var params = Array.prototype.slice.call(arguments, 3); |
| 667 | 666 |
| 668 if (this._debugFrontend) { | 667 if (this._debugFrontend) |
| 669 this._debugCalls.push(innerDispatch.bind(this)); | 668 setImmediate(innerDispatch.bind(this)); |
| 670 if (this._debugCalls.length === 1) | 669 else |
| 671 window.setTimeout(this._onDebugTimeout.bind(this), 0); | |
| 672 } else { | |
| 673 innerDispatch.call(this); | 670 innerDispatch.call(this); |
| 674 } | |
| 675 | 671 |
| 676 /** | 672 /** |
| 677 * @this {!InspectorFrontendAPIImpl} | 673 * @this {!InspectorFrontendAPIImpl} |
| 678 */ | 674 */ |
| 679 function innerDispatch() | 675 function innerDispatch() |
| 680 { | 676 { |
| 681 if (runOnceLoaded) | 677 if (runOnceLoaded) |
| 682 this._runOnceLoaded(dispatchAfterLoad); | 678 this._runOnceLoaded(dispatchAfterLoad); |
| 683 else | 679 else |
| 684 dispatchAfterLoad(); | 680 dispatchAfterLoad(); |
| 685 | 681 |
| 686 function dispatchAfterLoad() | 682 function dispatchAfterLoad() |
| 687 { | 683 { |
| 688 // Single argument methods get dispatched with the param. | 684 // Single argument methods get dispatched with the param. |
| 689 if (signature.length < 2) { | 685 if (signature.length < 2) { |
| 690 InspectorFrontendHost.events.dispatchEventToListeners(name,
params[0]); | 686 InspectorFrontendHost.events.dispatchEventToListeners(name,
params[0]); |
| 691 return; | 687 return; |
| 692 } | 688 } |
| 693 var data = {}; | 689 var data = {}; |
| 694 for (var i = 0; i < signature.length; ++i) | 690 for (var i = 0; i < signature.length; ++i) |
| 695 data[signature[i]] = params[i]; | 691 data[signature[i]] = params[i]; |
| 696 InspectorFrontendHost.events.dispatchEventToListeners(name, data
); | 692 InspectorFrontendHost.events.dispatchEventToListeners(name, data
); |
| 697 } | 693 } |
| 698 } | 694 } |
| 699 }, | 695 }, |
| 700 | 696 |
| 701 _onDebugTimeout: function() | |
| 702 { | |
| 703 while (this._debugCalls.length) | |
| 704 this._debugCalls.shift()(); | |
| 705 }, | |
| 706 | |
| 707 /** | 697 /** |
| 708 * @param {function()} command | 698 * @param {function()} command |
| 709 */ | 699 */ |
| 710 _runOnceLoaded: function(command) | 700 _runOnceLoaded: function(command) |
| 711 { | 701 { |
| 712 if (this._isLoaded) { | 702 if (this._isLoaded) { |
| 713 command(); | 703 command(); |
| 714 return; | 704 return; |
| 715 } | 705 } |
| 716 this._pendingCommands.push(command); | 706 this._pendingCommands.push(command); |
| 717 }, | 707 }, |
| 718 | 708 |
| 719 /** | 709 /** |
| 720 * @param {number} id | 710 * @param {number} id |
| 721 * @param {?string} error | 711 * @param {?string} error |
| 722 */ | 712 */ |
| 723 embedderMessageAck: function(id, error) | 713 embedderMessageAck: function(id, error) |
| 724 { | 714 { |
| 725 InspectorFrontendHost["embedderMessageAck"](id, error); | 715 InspectorFrontendHost["embedderMessageAck"](id, error); |
| 726 } | 716 } |
| 727 } | 717 } |
| 728 | 718 |
| 729 var InspectorFrontendAPI = new InspectorFrontendAPIImpl(); | 719 var InspectorFrontendAPI = new InspectorFrontendAPIImpl(); |
| OLD | NEW |