| OLD | NEW |
| 1 (function() { | 1 (function() { |
| 2 /* | 2 /* |
| 3 * Copyright (C) 2012 Google Inc. All rights reserved. | 3 * Copyright (C) 2012 Google Inc. All rights reserved. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions are | 6 * modification, are permitted provided that the following conditions are |
| 7 * met: | 7 * met: |
| 8 * | 8 * |
| 9 * * Redistributions of source code must retain the above copyright | 9 * * Redistributions of source code must retain the above copyright |
| 10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
| (...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 243 { | 243 { |
| 244 function callbackWrapper(result) | 244 function callbackWrapper(result) |
| 245 { | 245 { |
| 246 var entries = (result && result.entries) || []; | 246 var entries = (result && result.entries) || []; |
| 247 for (var i = 0; i < entries.length; ++i) { | 247 for (var i = 0; i < entries.length; ++i) { |
| 248 entries[i].__proto__ = new Request(entries[i]._requestId); | 248 entries[i].__proto__ = new Request(entries[i]._requestId); |
| 249 delete entries[i]._requestId; | 249 delete entries[i]._requestId; |
| 250 } | 250 } |
| 251 callback(result); | 251 callback(result); |
| 252 } | 252 } |
| 253 return extensionServer.sendRequest({ command: commands.GetHAR }, callbac
k && callbackWrapper); | 253 extensionServer.sendRequest({ command: commands.GetHAR }, callback && ca
llbackWrapper); |
| 254 }, | 254 }, |
| 255 | 255 |
| 256 addRequestHeaders: function(headers) | 256 addRequestHeaders: function(headers) |
| 257 { | 257 { |
| 258 return extensionServer.sendRequest({ command: commands.AddRequestHeaders
, headers: headers, extensionId: window.location.hostname }); | 258 extensionServer.sendRequest({ command: commands.AddRequestHeaders, heade
rs: headers, extensionId: window.location.hostname }); |
| 259 } | 259 } |
| 260 } | 260 } |
| 261 | 261 |
| 262 /** | 262 /** |
| 263 * @constructor | 263 * @constructor |
| 264 */ | 264 */ |
| 265 function RequestImpl(id) | 265 function RequestImpl(id) |
| 266 { | 266 { |
| 267 this._id = id; | 267 this._id = id; |
| 268 } | 268 } |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 358 * @this {EventSinkImpl} | 358 * @this {EventSinkImpl} |
| 359 */ | 359 */ |
| 360 function dispatchShowEvent(message) | 360 function dispatchShowEvent(message) |
| 361 { | 361 { |
| 362 var frameIndex = message.arguments[0]; | 362 var frameIndex = message.arguments[0]; |
| 363 if (typeof frameIndex === "number") | 363 if (typeof frameIndex === "number") |
| 364 this._fire(window.parent.frames[frameIndex]); | 364 this._fire(window.parent.frames[frameIndex]); |
| 365 else | 365 else |
| 366 this._fire(); | 366 this._fire(); |
| 367 } | 367 } |
| 368 this.onShown = new EventSink(events.ViewShown + id, dispatchShowEvent); | 368 |
| 369 this.onHidden = new EventSink(events.ViewHidden + id); | 369 if (id) { |
| 370 this.onShown = new EventSink(events.ViewShown + id, dispatchShowEvent); |
| 371 this.onHidden = new EventSink(events.ViewHidden + id); |
| 372 } |
| 370 } | 373 } |
| 371 | 374 |
| 372 /** | 375 /** |
| 373 * @constructor | 376 * @constructor |
| 374 * @extends {ExtensionViewImpl} | 377 * @extends {ExtensionViewImpl} |
| 378 * @param {string} hostPanelName |
| 375 */ | 379 */ |
| 376 function PanelWithSidebarImpl(hostPanelName) | 380 function PanelWithSidebarImpl(hostPanelName) |
| 377 { | 381 { |
| 382 ExtensionViewImpl.call(this, null); |
| 378 this._hostPanelName = hostPanelName; | 383 this._hostPanelName = hostPanelName; |
| 379 this.onSelectionChanged = new EventSink(events.PanelObjectSelected + hostPan
elName); | 384 this.onSelectionChanged = new EventSink(events.PanelObjectSelected + hostPan
elName); |
| 380 } | 385 } |
| 381 | 386 |
| 382 PanelWithSidebarImpl.prototype = { | 387 PanelWithSidebarImpl.prototype = { |
| 383 createSidebarPane: function(title, callback) | 388 createSidebarPane: function(title, callback) |
| 384 { | 389 { |
| 385 var id = "extension-sidebar-" + extensionServer.nextObjectId(); | 390 var id = "extension-sidebar-" + extensionServer.nextObjectId(); |
| 386 var request = { | 391 var request = { |
| 387 command: commands.CreateSidebarPane, | 392 command: commands.CreateSidebarPane, |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 470 * @constructor | 475 * @constructor |
| 471 * @extends {ExtensionViewImpl} | 476 * @extends {ExtensionViewImpl} |
| 472 */ | 477 */ |
| 473 function ExtensionPanelImpl(id) | 478 function ExtensionPanelImpl(id) |
| 474 { | 479 { |
| 475 ExtensionViewImpl.call(this, id); | 480 ExtensionViewImpl.call(this, id); |
| 476 this.onSearch = new EventSink(events.PanelSearch + id); | 481 this.onSearch = new EventSink(events.PanelSearch + id); |
| 477 } | 482 } |
| 478 | 483 |
| 479 ExtensionPanelImpl.prototype = { | 484 ExtensionPanelImpl.prototype = { |
| 485 /** |
| 486 * @return {!Object} |
| 487 */ |
| 480 createStatusBarButton: function(iconPath, tooltipText, disabled) | 488 createStatusBarButton: function(iconPath, tooltipText, disabled) |
| 481 { | 489 { |
| 482 var id = "button-" + extensionServer.nextObjectId(); | 490 var id = "button-" + extensionServer.nextObjectId(); |
| 483 var request = { | 491 var request = { |
| 484 command: commands.CreateStatusBarButton, | 492 command: commands.CreateStatusBarButton, |
| 485 panel: this._id, | 493 panel: this._id, |
| 486 id: id, | 494 id: id, |
| 487 icon: iconPath, | 495 icon: iconPath, |
| 488 tooltip: tooltipText, | 496 tooltip: tooltipText, |
| 489 disabled: !!disabled | 497 disabled: !!disabled |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 573 }; | 581 }; |
| 574 | 582 |
| 575 /** | 583 /** |
| 576 * @constructor | 584 * @constructor |
| 577 */ | 585 */ |
| 578 function Audits() | 586 function Audits() |
| 579 { | 587 { |
| 580 } | 588 } |
| 581 | 589 |
| 582 Audits.prototype = { | 590 Audits.prototype = { |
| 591 /** |
| 592 * @return {!AuditCategory} |
| 593 */ |
| 583 addCategory: function(displayName, resultCount) | 594 addCategory: function(displayName, resultCount) |
| 584 { | 595 { |
| 585 var id = "extension-audit-category-" + extensionServer.nextObjectId(); | 596 var id = "extension-audit-category-" + extensionServer.nextObjectId(); |
| 586 if (typeof resultCount !== "undefined") | 597 if (typeof resultCount !== "undefined") |
| 587 console.warn("Passing resultCount to audits.addCategory() is depreca
ted. Use AuditResult.updateProgress() instead."); | 598 console.warn("Passing resultCount to audits.addCategory() is depreca
ted. Use AuditResult.updateProgress() instead."); |
| 588 extensionServer.sendRequest({ command: commands.AddAuditCategory, id: id
, displayName: displayName, resultCount: resultCount }); | 599 extensionServer.sendRequest({ command: commands.AddAuditCategory, id: id
, displayName: displayName, resultCount: resultCount }); |
| 589 return new AuditCategory(id); | 600 return new AuditCategory(id); |
| 590 } | 601 } |
| 591 } | 602 } |
| 592 | 603 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 612 this.onAuditStarted = new EventSink(events.AuditStarted + id, dispatchAuditE
vent); | 623 this.onAuditStarted = new EventSink(events.AuditStarted + id, dispatchAuditE
vent); |
| 613 } | 624 } |
| 614 | 625 |
| 615 /** | 626 /** |
| 616 * @constructor | 627 * @constructor |
| 617 */ | 628 */ |
| 618 function AuditResultImpl(id) | 629 function AuditResultImpl(id) |
| 619 { | 630 { |
| 620 this._id = id; | 631 this._id = id; |
| 621 | 632 |
| 622 this.createURL = this._nodeFactory.bind(null, "url"); | 633 this.createURL = this._nodeFactory.bind(this, "url"); |
| 623 this.createSnippet = this._nodeFactory.bind(null, "snippet"); | 634 this.createSnippet = this._nodeFactory.bind(this, "snippet"); |
| 624 this.createText = this._nodeFactory.bind(null, "text"); | 635 this.createText = this._nodeFactory.bind(this, "text"); |
| 625 this.createObject = this._nodeFactory.bind(null, "object"); | 636 this.createObject = this._nodeFactory.bind(this, "object"); |
| 626 this.createNode = this._nodeFactory.bind(null, "node"); | 637 this.createNode = this._nodeFactory.bind(this, "node"); |
| 627 } | 638 } |
| 628 | 639 |
| 629 AuditResultImpl.prototype = { | 640 AuditResultImpl.prototype = { |
| 630 addResult: function(displayName, description, severity, details) | 641 addResult: function(displayName, description, severity, details) |
| 631 { | 642 { |
| 632 // shorthand for specifying details directly in addResult(). | 643 // shorthand for specifying details directly in addResult(). |
| 633 if (details && !(details instanceof AuditResultNode)) | 644 if (details && !(details instanceof AuditResultNode)) |
| 634 details = new AuditResultNode(details instanceof Array ? details : [
details]); | 645 details = new AuditResultNode(details instanceof Array ? details : [
details]); |
| 635 | 646 |
| 636 var request = { | 647 var request = { |
| 637 command: commands.AddAuditResult, | 648 command: commands.AddAuditResult, |
| 638 resultId: this._id, | 649 resultId: this._id, |
| 639 displayName: displayName, | 650 displayName: displayName, |
| 640 description: description, | 651 description: description, |
| 641 severity: severity, | 652 severity: severity, |
| 642 details: details | 653 details: details |
| 643 }; | 654 }; |
| 644 extensionServer.sendRequest(request); | 655 extensionServer.sendRequest(request); |
| 645 }, | 656 }, |
| 646 | 657 |
| 658 /** |
| 659 * @return {!Object} |
| 660 */ |
| 647 createResult: function() | 661 createResult: function() |
| 648 { | 662 { |
| 649 return new AuditResultNode(Array.prototype.slice.call(arguments)); | 663 return new AuditResultNode(Array.prototype.slice.call(arguments)); |
| 650 }, | 664 }, |
| 651 | 665 |
| 652 updateProgress: function(worked, totalWork) | 666 updateProgress: function(worked, totalWork) |
| 653 { | 667 { |
| 654 extensionServer.sendRequest({ command: commands.UpdateAuditProgress, res
ultId: this._id, progress: worked / totalWork }); | 668 extensionServer.sendRequest({ command: commands.UpdateAuditProgress, res
ultId: this._id, progress: worked / totalWork }); |
| 655 }, | 669 }, |
| 656 | 670 |
| 657 done: function() | 671 done: function() |
| 658 { | 672 { |
| 659 extensionServer.sendRequest({ command: commands.StopAuditCategoryRun, re
sultId: this._id }); | 673 extensionServer.sendRequest({ command: commands.StopAuditCategoryRun, re
sultId: this._id }); |
| 660 }, | 674 }, |
| 661 | 675 |
| 676 /** |
| 677 * @type {!Object.<string, string>} |
| 678 */ |
| 662 get Severity() | 679 get Severity() |
| 663 { | 680 { |
| 664 return apiPrivate.audits.Severity; | 681 return apiPrivate.audits.Severity; |
| 665 }, | 682 }, |
| 666 | 683 |
| 684 /** |
| 685 * @return {!{type: string, arguments: !Array.<string|number>}} |
| 686 */ |
| 667 createResourceLink: function(url, lineNumber) | 687 createResourceLink: function(url, lineNumber) |
| 668 { | 688 { |
| 669 return { | 689 return { |
| 670 type: "resourceLink", | 690 type: "resourceLink", |
| 671 arguments: [url, lineNumber && lineNumber - 1] | 691 arguments: [url, lineNumber && lineNumber - 1] |
| 672 }; | 692 }; |
| 673 }, | 693 }, |
| 674 | 694 |
| 695 /** |
| 696 * @return {!{type: string, arguments: !Array.<string|number>}} |
| 697 */ |
| 675 _nodeFactory: function(type) | 698 _nodeFactory: function(type) |
| 676 { | 699 { |
| 677 return { | 700 return { |
| 678 type: type, | 701 type: type, |
| 679 arguments: Array.prototype.slice.call(arguments, 1) | 702 arguments: Array.prototype.slice.call(arguments, 1) |
| 680 }; | 703 }; |
| 681 } | 704 } |
| 682 } | 705 } |
| 683 | 706 |
| 684 /** | 707 /** |
| 685 * @constructor | 708 * @constructor |
| 686 */ | 709 */ |
| 687 function AuditResultNode(contents) | 710 function AuditResultNode(contents) |
| 688 { | 711 { |
| 689 this.contents = contents; | 712 this.contents = contents; |
| 690 this.children = []; | 713 this.children = []; |
| 691 this.expanded = false; | 714 this.expanded = false; |
| 692 } | 715 } |
| 693 | 716 |
| 694 AuditResultNode.prototype = { | 717 AuditResultNode.prototype = { |
| 718 /** |
| 719 * @return {!Object} |
| 720 */ |
| 695 addChild: function() | 721 addChild: function() |
| 696 { | 722 { |
| 697 var node = new AuditResultNode(Array.prototype.slice.call(arguments)); | 723 var node = new AuditResultNode(Array.prototype.slice.call(arguments)); |
| 698 this.children.push(node); | 724 this.children.push(node); |
| 699 return node; | 725 return node; |
| 700 } | 726 } |
| 701 }; | 727 }; |
| 702 | 728 |
| 703 /** | 729 /** |
| 704 * @constructor | 730 * @constructor |
| (...skipping 24 matching lines...) Expand all Loading... |
| 729 reload: function(optionsOrUserAgent) | 755 reload: function(optionsOrUserAgent) |
| 730 { | 756 { |
| 731 var options = null; | 757 var options = null; |
| 732 if (typeof optionsOrUserAgent === "object") | 758 if (typeof optionsOrUserAgent === "object") |
| 733 options = optionsOrUserAgent; | 759 options = optionsOrUserAgent; |
| 734 else if (typeof optionsOrUserAgent === "string") { | 760 else if (typeof optionsOrUserAgent === "string") { |
| 735 options = { userAgent: optionsOrUserAgent }; | 761 options = { userAgent: optionsOrUserAgent }; |
| 736 console.warn("Passing userAgent as string parameter to inspectedWind
ow.reload() is deprecated. " + | 762 console.warn("Passing userAgent as string parameter to inspectedWind
ow.reload() is deprecated. " + |
| 737 "Use inspectedWindow.reload({ userAgent: value}) instea
d."); | 763 "Use inspectedWindow.reload({ userAgent: value}) instea
d."); |
| 738 } | 764 } |
| 739 return extensionServer.sendRequest({ command: commands.Reload, options:
options }); | 765 extensionServer.sendRequest({ command: commands.Reload, options: options
}); |
| 740 }, | 766 }, |
| 741 | 767 |
| 768 /** |
| 769 * @return {?Object} |
| 770 */ |
| 742 eval: function(expression, evaluateOptions) | 771 eval: function(expression, evaluateOptions) |
| 743 { | 772 { |
| 744 var callback = extractCallbackArgument(arguments); | 773 var callback = extractCallbackArgument(arguments); |
| 745 function callbackWrapper(result) | 774 function callbackWrapper(result) |
| 746 { | 775 { |
| 747 if (result.isError || result.isException) | 776 if (result.isError || result.isException) |
| 748 callback(undefined, result); | 777 callback(undefined, result); |
| 749 else | 778 else |
| 750 callback(result.value); | 779 callback(result.value); |
| 751 } | 780 } |
| 752 var request = { | 781 var request = { |
| 753 command: commands.EvaluateOnInspectedPage, | 782 command: commands.EvaluateOnInspectedPage, |
| 754 expression: expression | 783 expression: expression |
| 755 }; | 784 }; |
| 756 if (typeof evaluateOptions === "object") | 785 if (typeof evaluateOptions === "object") |
| 757 request.evaluateOptions = evaluateOptions; | 786 request.evaluateOptions = evaluateOptions; |
| 758 return extensionServer.sendRequest(request, callback && callbackWrapper)
; | 787 extensionServer.sendRequest(request, callback && callbackWrapper); |
| 788 return null; |
| 759 }, | 789 }, |
| 760 | 790 |
| 761 getResources: function(callback) | 791 getResources: function(callback) |
| 762 { | 792 { |
| 763 function wrapResource(resourceData) | 793 function wrapResource(resourceData) |
| 764 { | 794 { |
| 765 return new Resource(resourceData); | 795 return new Resource(resourceData); |
| 766 } | 796 } |
| 767 function callbackWrapper(resources) | 797 function callbackWrapper(resources) |
| 768 { | 798 { |
| 769 callback(resources.map(wrapResource)); | 799 callback(resources.map(wrapResource)); |
| 770 } | 800 } |
| 771 return extensionServer.sendRequest({ command: commands.GetPageResources
}, callback && callbackWrapper); | 801 extensionServer.sendRequest({ command: commands.GetPageResources }, call
back && callbackWrapper); |
| 772 } | 802 } |
| 773 } | 803 } |
| 774 | 804 |
| 775 /** | 805 /** |
| 776 * @constructor | 806 * @constructor |
| 777 */ | 807 */ |
| 778 function ResourceImpl(resourceData) | 808 function ResourceImpl(resourceData) |
| 779 { | 809 { |
| 780 this._url = resourceData.url | 810 this._url = resourceData.url |
| 781 this._type = resourceData.type; | 811 this._type = resourceData.type; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 792 return this._type; | 822 return this._type; |
| 793 }, | 823 }, |
| 794 | 824 |
| 795 getContent: function(callback) | 825 getContent: function(callback) |
| 796 { | 826 { |
| 797 function callbackWrapper(response) | 827 function callbackWrapper(response) |
| 798 { | 828 { |
| 799 callback(response.content, response.encoding); | 829 callback(response.content, response.encoding); |
| 800 } | 830 } |
| 801 | 831 |
| 802 return extensionServer.sendRequest({ command: commands.GetResourceConten
t, url: this._url }, callback && callbackWrapper); | 832 extensionServer.sendRequest({ command: commands.GetResourceContent, url:
this._url }, callback && callbackWrapper); |
| 803 }, | 833 }, |
| 804 | 834 |
| 805 setContent: function(content, commit, callback) | 835 setContent: function(content, commit, callback) |
| 806 { | 836 { |
| 807 return extensionServer.sendRequest({ command: commands.SetResourceConten
t, url: this._url, content: content, commit: commit }, callback); | 837 extensionServer.sendRequest({ command: commands.SetResourceContent, url:
this._url, content: content, commit: commit }, callback); |
| 808 } | 838 } |
| 809 } | 839 } |
| 810 | 840 |
| 811 /** | 841 /** |
| 812 * @constructor | 842 * @constructor |
| 813 */ | 843 */ |
| 814 function TimelineImpl() | 844 function TimelineImpl() |
| 815 { | 845 { |
| 816 this.onEventRecorded = new EventSink(events.TimelineEventRecorded); | 846 this.onEventRecorded = new EventSink(events.TimelineEventRecorded); |
| 817 } | 847 } |
| 818 | 848 |
| 849 var keyboardEventRequestQueue = []; |
| 850 var forwardTimer = null; |
| 851 |
| 819 function forwardKeyboardEvent(event) | 852 function forwardKeyboardEvent(event) |
| 820 { | 853 { |
| 821 const Esc = "U+001B"; | 854 const Esc = "U+001B"; |
| 822 // We only care about global hotkeys, not about random text | 855 // We only care about global hotkeys, not about random text |
| 823 if (!event.ctrlKey && !event.altKey && !event.metaKey && !/^F\d+$/.test(even
t.keyIdentifier) && event.keyIdentifier !== Esc) | 856 if (!event.ctrlKey && !event.altKey && !event.metaKey && !/^F\d+$/.test(even
t.keyIdentifier) && event.keyIdentifier !== Esc) |
| 824 return; | 857 return; |
| 825 var request = { | 858 var requestPayload = { |
| 826 command: commands.ForwardKeyboardEvent, | |
| 827 eventType: event.type, | 859 eventType: event.type, |
| 828 ctrlKey: event.ctrlKey, | 860 ctrlKey: event.ctrlKey, |
| 829 altKey: event.altKey, | 861 altKey: event.altKey, |
| 830 metaKey: event.metaKey, | 862 metaKey: event.metaKey, |
| 831 keyIdentifier: event.keyIdentifier, | 863 keyIdentifier: event.keyIdentifier, |
| 832 location: event.location | 864 location: event.location, |
| 865 keyCode: event.keyCode |
| 866 }; |
| 867 keyboardEventRequestQueue.push(requestPayload); |
| 868 if (!forwardTimer) |
| 869 forwardTimer = setTimeout(forwardEventQueue, 0); |
| 870 } |
| 871 |
| 872 function forwardEventQueue() |
| 873 { |
| 874 forwardTimer = null; |
| 875 var request = { |
| 876 command: commands.ForwardKeyboardEvent, |
| 877 entries: keyboardEventRequestQueue |
| 833 }; | 878 }; |
| 834 extensionServer.sendRequest(request); | 879 extensionServer.sendRequest(request); |
| 880 keyboardEventRequestQueue = []; |
| 835 } | 881 } |
| 836 | 882 |
| 837 document.addEventListener("keydown", forwardKeyboardEvent, false); | 883 document.addEventListener("keydown", forwardKeyboardEvent, false); |
| 838 document.addEventListener("keypress", forwardKeyboardEvent, false); | 884 document.addEventListener("keypress", forwardKeyboardEvent, false); |
| 839 | 885 |
| 840 /** | 886 /** |
| 841 * @constructor | 887 * @constructor |
| 842 */ | 888 */ |
| 843 function ExtensionServerClient() | 889 function ExtensionServerClient() |
| 844 { | 890 { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 858 } | 904 } |
| 859 | 905 |
| 860 ExtensionServerClient.prototype = { | 906 ExtensionServerClient.prototype = { |
| 861 /** | 907 /** |
| 862 * @param {function()=} callback | 908 * @param {function()=} callback |
| 863 */ | 909 */ |
| 864 sendRequest: function(message, callback) | 910 sendRequest: function(message, callback) |
| 865 { | 911 { |
| 866 if (typeof callback === "function") | 912 if (typeof callback === "function") |
| 867 message.requestId = this._registerCallback(callback); | 913 message.requestId = this._registerCallback(callback); |
| 868 return this._port.postMessage(message); | 914 this._port.postMessage(message); |
| 869 }, | 915 }, |
| 870 | 916 |
| 917 /** |
| 918 * @return {boolean} |
| 919 */ |
| 871 hasHandler: function(command) | 920 hasHandler: function(command) |
| 872 { | 921 { |
| 873 return !!this._handlers[command]; | 922 return !!this._handlers[command]; |
| 874 }, | 923 }, |
| 875 | 924 |
| 876 registerHandler: function(command, handler) | 925 registerHandler: function(command, handler) |
| 877 { | 926 { |
| 878 this._handlers[command] = handler; | 927 this._handlers[command] = handler; |
| 879 }, | 928 }, |
| 880 | 929 |
| 881 unregisterHandler: function(command) | 930 unregisterHandler: function(command) |
| 882 { | 931 { |
| 883 delete this._handlers[command]; | 932 delete this._handlers[command]; |
| 884 }, | 933 }, |
| 885 | 934 |
| 935 /** |
| 936 * @return {string} |
| 937 */ |
| 886 nextObjectId: function() | 938 nextObjectId: function() |
| 887 { | 939 { |
| 888 return injectedScriptId + "_" + ++this._lastObjectId; | 940 return injectedScriptId + "_" + ++this._lastObjectId; |
| 889 }, | 941 }, |
| 890 | 942 |
| 891 _registerCallback: function(callback) | 943 _registerCallback: function(callback) |
| 892 { | 944 { |
| 893 var id = ++this._lastRequestId; | 945 var id = ++this._lastRequestId; |
| 894 this._callbacks[id] = callback; | 946 this._callbacks[id] = callback; |
| 895 return id; | 947 return id; |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 934 } | 986 } |
| 935 | 987 |
| 936 // extensionServer is a closure variable defined by the glue below -- make sure
we fail if it's not there. | 988 // extensionServer is a closure variable defined by the glue below -- make sure
we fail if it's not there. |
| 937 if (!extensionServer) | 989 if (!extensionServer) |
| 938 extensionServer = new ExtensionServerClient(); | 990 extensionServer = new ExtensionServerClient(); |
| 939 | 991 |
| 940 return new InspectorExtensionAPI(); | 992 return new InspectorExtensionAPI(); |
| 941 } | 993 } |
| 942 | 994 |
| 943 /** | 995 /** |
| 944 * @param {!ExtensionDescriptor} extensionInfo | 996 * @suppress {checkVars, checkTypes} |
| 945 * @return {string} | |
| 946 */ | 997 */ |
| 947 function buildExtensionAPIInjectedScript(extensionInfo) | |
| 948 { | |
| 949 return "(function(injectedScriptId){ " + | |
| 950 "var extensionServer;" + | |
| 951 defineCommonExtensionSymbols.toString() + ";" + | |
| 952 injectedExtensionAPI.toString() + ";" + | |
| 953 buildPlatformExtensionAPI(extensionInfo) + ";" + | |
| 954 "platformExtensionAPI(injectedExtensionAPI(injectedScriptId));" + | |
| 955 "return {};" + | |
| 956 "})"; | |
| 957 } | |
| 958 /* | |
| 959 * Copyright (C) 2011 Google Inc. All rights reserved. | |
| 960 * | |
| 961 * Redistribution and use in source and binary forms, with or without | |
| 962 * modification, are permitted provided that the following conditions are | |
| 963 * met: | |
| 964 * | |
| 965 * * Redistributions of source code must retain the above copyright | |
| 966 * notice, this list of conditions and the following disclaimer. | |
| 967 * * Redistributions in binary form must reproduce the above | |
| 968 * copyright notice, this list of conditions and the following disclaimer | |
| 969 * in the documentation and/or other materials provided with the | |
| 970 * distribution. | |
| 971 * * Neither the name of Google Inc. nor the names of its | |
| 972 * contributors may be used to endorse or promote products derived from | |
| 973 * this software without specific prior written permission. | |
| 974 * | |
| 975 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
| 976 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
| 977 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
| 978 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
| 979 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
| 980 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
| 981 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
| 982 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
| 983 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
| 984 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
| 985 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
| 986 */ | |
| 987 | |
| 988 function platformExtensionAPI(coreAPI) | 998 function platformExtensionAPI(coreAPI) |
| 989 { | 999 { |
| 990 function getTabId() | 1000 function getTabId() |
| 991 { | 1001 { |
| 992 return tabId; | 1002 return tabId; |
| 993 } | 1003 } |
| 994 chrome = window.chrome || {}; | 1004 chrome = window.chrome || {}; |
| 995 // Override chrome.devtools as a workaround for a error-throwing getter bein
g exposed | 1005 // Override chrome.devtools as a workaround for a error-throwing getter bein
g exposed |
| 996 // in extension pages loaded into a non-extension process (only happens for
remote client | 1006 // in extension pages loaded into a non-extension process (only happens for
remote client |
| 997 // extensions) | 1007 // extensions) |
| (...skipping 16 matching lines...) Expand all Loading... |
| 1014 for (var i = 0; i < properties.length; ++i) { | 1024 for (var i = 0; i < properties.length; ++i) { |
| 1015 var descriptor = Object.getOwnPropertyDescriptor(coreAPI, properties
[i]); | 1025 var descriptor = Object.getOwnPropertyDescriptor(coreAPI, properties
[i]); |
| 1016 Object.defineProperty(chrome.experimental.devtools, properties[i], d
escriptor); | 1026 Object.defineProperty(chrome.experimental.devtools, properties[i], d
escriptor); |
| 1017 } | 1027 } |
| 1018 chrome.experimental.devtools.inspectedWindow = chrome.devtools.inspected
Window; | 1028 chrome.experimental.devtools.inspectedWindow = chrome.devtools.inspected
Window; |
| 1019 } | 1029 } |
| 1020 if (extensionInfo.exposeWebInspectorNamespace) | 1030 if (extensionInfo.exposeWebInspectorNamespace) |
| 1021 window.webInspector = coreAPI; | 1031 window.webInspector = coreAPI; |
| 1022 } | 1032 } |
| 1023 | 1033 |
| 1034 /** |
| 1035 * @param {!ExtensionDescriptor} extensionInfo |
| 1036 * @return {string} |
| 1037 */ |
| 1038 function buildPlatformExtensionAPI(extensionInfo) |
| 1039 { |
| 1040 return "var extensionInfo = " + JSON.stringify(extensionInfo) + ";" + |
| 1041 "var tabId = " + WebInspector._inspectedTabId + ";" + |
| 1042 platformExtensionAPI.toString(); |
| 1043 } |
| 1044 |
| 1045 /** |
| 1046 * @param {!ExtensionDescriptor} extensionInfo |
| 1047 * @return {string} |
| 1048 */ |
| 1049 function buildExtensionAPIInjectedScript(extensionInfo) |
| 1050 { |
| 1051 return "(function(injectedScriptId){ " + |
| 1052 "var extensionServer;" + |
| 1053 defineCommonExtensionSymbols.toString() + ";" + |
| 1054 injectedExtensionAPI.toString() + ";" + |
| 1055 buildPlatformExtensionAPI(extensionInfo) + ";" + |
| 1056 "platformExtensionAPI(injectedExtensionAPI(injectedScriptId));" + |
| 1057 "return {};" + |
| 1058 "})"; |
| 1059 } |
| 1060 |
| 1024 var tabId; | 1061 var tabId; |
| 1025 var extensionInfo = {}; | 1062 var extensionInfo = {}; |
| 1026 var extensionServer; | 1063 var extensionServer; |
| 1027 platformExtensionAPI(injectedExtensionAPI("remote-" + window.parent.fram
es.length)); | 1064 platformExtensionAPI(injectedExtensionAPI("remote-" + window.parent.fram
es.length)); |
| 1028 })(); | 1065 })(); |
| OLD | NEW |