| 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 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 this._registerHandler(commands.SetSidebarPage, this._onSetSidebarPage.bind(t
his)); | 75 this._registerHandler(commands.SetSidebarPage, this._onSetSidebarPage.bind(t
his)); |
| 76 this._registerHandler(commands.ShowPanel, this._onShowPanel.bind(this)); | 76 this._registerHandler(commands.ShowPanel, this._onShowPanel.bind(this)); |
| 77 this._registerHandler(commands.StopAuditCategoryRun, this._onStopAuditCatego
ryRun.bind(this)); | 77 this._registerHandler(commands.StopAuditCategoryRun, this._onStopAuditCatego
ryRun.bind(this)); |
| 78 this._registerHandler(commands.Subscribe, this._onSubscribe.bind(this)); | 78 this._registerHandler(commands.Subscribe, this._onSubscribe.bind(this)); |
| 79 this._registerHandler(commands.OpenResource, this._onOpenResource.bind(this)
); | 79 this._registerHandler(commands.OpenResource, this._onOpenResource.bind(this)
); |
| 80 this._registerHandler(commands.Unsubscribe, this._onUnsubscribe.bind(this)); | 80 this._registerHandler(commands.Unsubscribe, this._onUnsubscribe.bind(this)); |
| 81 this._registerHandler(commands.UpdateButton, this._onUpdateButton.bind(this)
); | 81 this._registerHandler(commands.UpdateButton, this._onUpdateButton.bind(this)
); |
| 82 this._registerHandler(commands.UpdateAuditProgress, this._onUpdateAuditProgr
ess.bind(this)); | 82 this._registerHandler(commands.UpdateAuditProgress, this._onUpdateAuditProgr
ess.bind(this)); |
| 83 window.addEventListener("message", this._onWindowMessage.bind(this), false);
// Only for main window. | 83 window.addEventListener("message", this._onWindowMessage.bind(this), false);
// Only for main window. |
| 84 | 84 |
| 85 InspectorFrontendHost.events.addEventListener(InspectorFrontendHostAPI.Event
s.AddExtensions, this._addExtensions, this); |
| 86 InspectorFrontendHost.events.addEventListener(InspectorFrontendHostAPI.Event
s.SetInspectedTabId, this._setInspectedTabId, this); |
| 87 |
| 85 this._initExtensions(); | 88 this._initExtensions(); |
| 86 } | 89 } |
| 87 | 90 |
| 88 WebInspector.ExtensionServer.Events = { | 91 WebInspector.ExtensionServer.Events = { |
| 89 SidebarPaneAdded: "SidebarPaneAdded", | 92 SidebarPaneAdded: "SidebarPaneAdded", |
| 90 AuditCategoryAdded: "AuditCategoryAdded" | 93 AuditCategoryAdded: "AuditCategoryAdded" |
| 91 } | 94 } |
| 92 | 95 |
| 93 WebInspector.ExtensionServer.prototype = { | 96 WebInspector.ExtensionServer.prototype = { |
| 94 initializeExtensions: function() | 97 initializeExtensions: function() |
| 95 { | 98 { |
| 96 this._initializeCommandIssued = true; | 99 this._initializeCommandIssued = true; |
| 97 if (this._pendingExtensionInfos) { | 100 if (this._pendingExtensionInfos) { |
| 98 this._addExtensions(this._pendingExtensionInfos); | 101 this._pendingExtensionInfos.forEach(this._addExtension, this); |
| 99 delete this._pendingExtensionInfos; | 102 delete this._pendingExtensionInfos; |
| 100 } | 103 } |
| 101 }, | 104 }, |
| 102 | 105 |
| 103 /** | 106 /** |
| 104 * @return {boolean} | 107 * @return {boolean} |
| 105 */ | 108 */ |
| 106 hasExtensions: function() | 109 hasExtensions: function() |
| 107 { | 110 { |
| 108 return !!Object.keys(this._registeredExtensions).length; | 111 return !!Object.keys(this._registeredExtensions).length; |
| (...skipping 681 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 790 var request = /** @type {!WebInspector.NetworkRequest} */ (event.data); | 793 var request = /** @type {!WebInspector.NetworkRequest} */ (event.data); |
| 791 this._postNotification(WebInspector.extensionAPI.Events.NetworkRequestFi
nished, this._requestId(request), (new WebInspector.HAREntry(request)).build()); | 794 this._postNotification(WebInspector.extensionAPI.Events.NetworkRequestFi
nished, this._requestId(request), (new WebInspector.HAREntry(request)).build()); |
| 792 }, | 795 }, |
| 793 | 796 |
| 794 _notifyElementsSelectionChanged: function() | 797 _notifyElementsSelectionChanged: function() |
| 795 { | 798 { |
| 796 this._postNotification(WebInspector.extensionAPI.Events.PanelObjectSelec
ted + "elements"); | 799 this._postNotification(WebInspector.extensionAPI.Events.PanelObjectSelec
ted + "elements"); |
| 797 }, | 800 }, |
| 798 | 801 |
| 799 /** | 802 /** |
| 800 * @param {!Array.<!ExtensionDescriptor>} extensionInfos | 803 * @param {!WebInspector.Event} event |
| 801 */ | 804 */ |
| 802 _addExtensions: function(extensionInfos) | 805 _addExtensions: function(event) |
| 803 { | 806 { |
| 807 if (WebInspector.extensionServer._overridePlatformExtensionAPIForTest) |
| 808 window.buildPlatformExtensionAPI = WebInspector.extensionServer._ove
rridePlatformExtensionAPIForTest; |
| 809 |
| 810 var extensionInfos = /** @type {!Array.<!ExtensionDescriptor>} */ (event
.data); |
| 804 if (this._initializeCommandIssued) | 811 if (this._initializeCommandIssued) |
| 805 extensionInfos.forEach(this._addExtension, this); | 812 extensionInfos.forEach(this._addExtension, this); |
| 806 else | 813 else |
| 807 this._pendingExtensionInfos = extensionInfos; | 814 this._pendingExtensionInfos = extensionInfos; |
| 808 }, | 815 }, |
| 809 | 816 |
| 810 /** | 817 /** |
| 818 * @param {!WebInspector.Event} event |
| 819 */ |
| 820 _setInspectedTabId: function(event) |
| 821 { |
| 822 this._inspectedTabId = /** @type {string} */ (event.data); |
| 823 }, |
| 824 |
| 825 /** |
| 811 * @param {!ExtensionDescriptor} extensionInfo | 826 * @param {!ExtensionDescriptor} extensionInfo |
| 812 * @suppressGlobalPropertiesCheck | 827 * @suppressGlobalPropertiesCheck |
| 813 */ | 828 */ |
| 814 _addExtension: function(extensionInfo) | 829 _addExtension: function(extensionInfo) |
| 815 { | 830 { |
| 816 const urlOriginRegExp = new RegExp("([^:]+:\/\/[^/]*)\/"); // Can't use
regexp literal here, MinJS chokes on it. | 831 const urlOriginRegExp = new RegExp("([^:]+:\/\/[^/]*)\/"); // Can't use
regexp literal here, MinJS chokes on it. |
| 817 var startPage = extensionInfo.startPage; | 832 var startPage = extensionInfo.startPage; |
| 818 var name = extensionInfo.name; | 833 var name = extensionInfo.name; |
| 819 | 834 |
| 820 try { | 835 try { |
| 821 var originMatch = urlOriginRegExp.exec(startPage); | 836 var originMatch = urlOriginRegExp.exec(startPage); |
| 822 if (!originMatch) { | 837 if (!originMatch) { |
| 823 console.error("Skipping extension with invalid URL: " + startPag
e); | 838 console.error("Skipping extension with invalid URL: " + startPag
e); |
| 824 return false; | 839 return false; |
| 825 } | 840 } |
| 826 var extensionOrigin = originMatch[1]; | 841 var extensionOrigin = originMatch[1]; |
| 827 if (!this._registeredExtensions[extensionOrigin]) { | 842 if (!this._registeredExtensions[extensionOrigin]) { |
| 828 // See ExtensionAPI.js for details. | 843 // See ExtensionAPI.js for details. |
| 829 InspectorFrontendHost.setInjectedScriptForOrigin(extensionOrigin
, buildExtensionAPIInjectedScript(extensionInfo)); | 844 InspectorFrontendHost.setInjectedScriptForOrigin(extensionOrigin
, buildExtensionAPIInjectedScript(extensionInfo, this._inspectedTabId)); |
| 830 this._registeredExtensions[extensionOrigin] = { name: name }; | 845 this._registeredExtensions[extensionOrigin] = { name: name }; |
| 831 } | 846 } |
| 832 var iframe = createElement("iframe"); | 847 var iframe = createElement("iframe"); |
| 833 iframe.src = startPage; | 848 iframe.src = startPage; |
| 834 iframe.style.display = "none"; | 849 iframe.style.display = "none"; |
| 835 document.body.appendChild(iframe); // Only for main window. | 850 document.body.appendChild(iframe); // Only for main window. |
| 836 } catch (e) { | 851 } catch (e) { |
| 837 console.error("Failed to initialize extension " + startPage + ":" +
e); | 852 console.error("Failed to initialize extension " + startPage + ":" +
e); |
| 838 return false; | 853 return false; |
| 839 } | 854 } |
| (...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1109 this.E_FAILED = makeStatus.bind(null, "E_FAILED", "Operation failed: %s"); | 1124 this.E_FAILED = makeStatus.bind(null, "E_FAILED", "Operation failed: %s"); |
| 1110 } | 1125 } |
| 1111 | 1126 |
| 1112 /** | 1127 /** |
| 1113 * @typedef {{code: string, description: string, details: !Array.<*>}} | 1128 * @typedef {{code: string, description: string, details: !Array.<*>}} |
| 1114 */ | 1129 */ |
| 1115 WebInspector.ExtensionStatus.Record; | 1130 WebInspector.ExtensionStatus.Record; |
| 1116 | 1131 |
| 1117 WebInspector.extensionAPI = {}; | 1132 WebInspector.extensionAPI = {}; |
| 1118 defineCommonExtensionSymbols(WebInspector.extensionAPI); | 1133 defineCommonExtensionSymbols(WebInspector.extensionAPI); |
| 1119 | |
| 1120 WebInspector.addExtensions = function(extensions) | |
| 1121 { | |
| 1122 if (WebInspector.extensionServer._overridePlatformExtensionAPIForTest) | |
| 1123 window.buildPlatformExtensionAPI = WebInspector.extensionServer._overrid
ePlatformExtensionAPIForTest; | |
| 1124 WebInspector.extensionServer._addExtensions(extensions); | |
| 1125 } | |
| 1126 | |
| 1127 WebInspector.setInspectedTabId = function(tabId) | |
| 1128 { | |
| 1129 WebInspector._inspectedTabId = tabId; | |
| 1130 } | |
| OLD | NEW |