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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 this._subscriptionStopHandlers = {}; | 42 this._subscriptionStopHandlers = {}; |
43 this._extraHeaders = {}; | 43 this._extraHeaders = {}; |
44 this._requests = {}; | 44 this._requests = {}; |
45 this._lastRequestId = 0; | 45 this._lastRequestId = 0; |
46 this._registeredExtensions = {}; | 46 this._registeredExtensions = {}; |
47 this._status = new WebInspector.ExtensionStatus(); | 47 this._status = new WebInspector.ExtensionStatus(); |
48 /** @type {!Array.<!WebInspector.ExtensionSidebarPane>} */ | 48 /** @type {!Array.<!WebInspector.ExtensionSidebarPane>} */ |
49 this._sidebarPanes = []; | 49 this._sidebarPanes = []; |
50 /** @type {!Array.<!WebInspector.ExtensionAuditCategory>} */ | 50 /** @type {!Array.<!WebInspector.ExtensionAuditCategory>} */ |
51 this._auditCategories = []; | 51 this._auditCategories = []; |
| 52 /** @type {!Array.<!WebInspector.ExtensionTraceProvider>} */ |
| 53 this._traceProviders = []; |
| 54 |
52 | 55 |
53 var commands = WebInspector.extensionAPI.Commands; | 56 var commands = WebInspector.extensionAPI.Commands; |
54 | 57 |
55 this._registerHandler(commands.AddAuditCategory, this._onAddAuditCategory.bi
nd(this)); | 58 this._registerHandler(commands.AddAuditCategory, this._onAddAuditCategory.bi
nd(this)); |
56 this._registerHandler(commands.AddAuditResult, this._onAddAuditResult.bind(t
his)); | 59 this._registerHandler(commands.AddAuditResult, this._onAddAuditResult.bind(t
his)); |
| 60 this._registerHandler(commands.AddTraceProvider, this._onAddTraceProvider.bi
nd(this)); |
| 61 this._registerHandler(commands.AddTraceData, this._onAddTraceData.bind(this)
); |
57 this._registerHandler(commands.AddRequestHeaders, this._onAddRequestHeaders.
bind(this)); | 62 this._registerHandler(commands.AddRequestHeaders, this._onAddRequestHeaders.
bind(this)); |
58 this._registerHandler(commands.ApplyStyleSheet, this._onApplyStyleSheet.bind
(this)); | 63 this._registerHandler(commands.ApplyStyleSheet, this._onApplyStyleSheet.bind
(this)); |
59 this._registerHandler(commands.CreatePanel, this._onCreatePanel.bind(this)); | 64 this._registerHandler(commands.CreatePanel, this._onCreatePanel.bind(this)); |
60 this._registerHandler(commands.CreateSidebarPane, this._onCreateSidebarPane.
bind(this)); | 65 this._registerHandler(commands.CreateSidebarPane, this._onCreateSidebarPane.
bind(this)); |
61 this._registerHandler(commands.CreateToolbarButton, this._onCreateToolbarBut
ton.bind(this)); | 66 this._registerHandler(commands.CreateToolbarButton, this._onCreateToolbarBut
ton.bind(this)); |
62 this._registerHandler(commands.EvaluateOnInspectedPage, this._onEvaluateOnIn
spectedPage.bind(this)); | 67 this._registerHandler(commands.EvaluateOnInspectedPage, this._onEvaluateOnIn
spectedPage.bind(this)); |
63 this._registerHandler(commands.ForwardKeyboardEvent, this._onForwardKeyboard
Event.bind(this)); | 68 this._registerHandler(commands.ForwardKeyboardEvent, this._onForwardKeyboard
Event.bind(this)); |
64 this._registerHandler(commands.GetHAR, this._onGetHAR.bind(this)); | 69 this._registerHandler(commands.GetHAR, this._onGetHAR.bind(this)); |
65 this._registerHandler(commands.GetPageResources, this._onGetPageResources.bi
nd(this)); | 70 this._registerHandler(commands.GetPageResources, this._onGetPageResources.bi
nd(this)); |
66 this._registerHandler(commands.GetRequestContent, this._onGetRequestContent.
bind(this)); | 71 this._registerHandler(commands.GetRequestContent, this._onGetRequestContent.
bind(this)); |
(...skipping 13 matching lines...) Expand all Loading... |
80 window.addEventListener("message", this._onWindowMessage.bind(this), false);
// Only for main window. | 85 window.addEventListener("message", this._onWindowMessage.bind(this), false);
// Only for main window. |
81 | 86 |
82 InspectorFrontendHost.events.addEventListener(InspectorFrontendHostAPI.Event
s.AddExtensions, this._addExtensions, this); | 87 InspectorFrontendHost.events.addEventListener(InspectorFrontendHostAPI.Event
s.AddExtensions, this._addExtensions, this); |
83 InspectorFrontendHost.events.addEventListener(InspectorFrontendHostAPI.Event
s.SetInspectedTabId, this._setInspectedTabId, this); | 88 InspectorFrontendHost.events.addEventListener(InspectorFrontendHostAPI.Event
s.SetInspectedTabId, this._setInspectedTabId, this); |
84 | 89 |
85 this._initExtensions(); | 90 this._initExtensions(); |
86 } | 91 } |
87 | 92 |
88 WebInspector.ExtensionServer.Events = { | 93 WebInspector.ExtensionServer.Events = { |
89 SidebarPaneAdded: "SidebarPaneAdded", | 94 SidebarPaneAdded: "SidebarPaneAdded", |
90 AuditCategoryAdded: "AuditCategoryAdded" | 95 AuditCategoryAdded: "AuditCategoryAdded", |
| 96 TraceProviderAdded: "TraceProviderAdded" |
91 } | 97 } |
92 | 98 |
93 WebInspector.ExtensionServer.prototype = { | 99 WebInspector.ExtensionServer.prototype = { |
94 initializeExtensions: function() | 100 initializeExtensions: function() |
95 { | 101 { |
96 this._initializeCommandIssued = true; | 102 this._initializeCommandIssued = true; |
97 if (this._pendingExtensionInfos) { | 103 if (this._pendingExtensionInfos) { |
98 this._pendingExtensionInfos.forEach(this._addExtension, this); | 104 this._pendingExtensionInfos.forEach(this._addExtension, this); |
99 delete this._pendingExtensionInfos; | 105 delete this._pendingExtensionInfos; |
100 } | 106 } |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
163 | 169 |
164 /** | 170 /** |
165 * @param {!WebInspector.ExtensionAuditCategoryResults} auditResults | 171 * @param {!WebInspector.ExtensionAuditCategoryResults} auditResults |
166 */ | 172 */ |
167 stopAuditRun: function(auditResults) | 173 stopAuditRun: function(auditResults) |
168 { | 174 { |
169 delete this._clientObjects[auditResults.id()]; | 175 delete this._clientObjects[auditResults.id()]; |
170 }, | 176 }, |
171 | 177 |
172 /** | 178 /** |
| 179 * @param {string} traceProviderId |
| 180 */ |
| 181 startTraceRecording: function(traceProviderId) |
| 182 { |
| 183 this._postNotification("trace-recording-started-" + traceProviderId); |
| 184 }, |
| 185 |
| 186 /** |
| 187 * @param {string} traceProviderId |
| 188 * @param {!WebInspector.ExtensionTraceData} traceData |
| 189 */ |
| 190 stopTraceRecording: function(traceProviderId, traceData) |
| 191 { |
| 192 this._postNotification("trace-recording-stopped-" + traceProviderId, tra
ceData.id()); |
| 193 }, |
| 194 |
| 195 /** |
173 * @param {string} type | 196 * @param {string} type |
174 * @return {boolean} | 197 * @return {boolean} |
175 */ | 198 */ |
176 hasSubscribers: function(type) | 199 hasSubscribers: function(type) |
177 { | 200 { |
178 return !!this._subscribers[type]; | 201 return !!this._subscribers[type]; |
179 }, | 202 }, |
180 | 203 |
181 /** | 204 /** |
182 * @param {string} type | 205 * @param {string} type |
(...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
575 }, | 598 }, |
576 | 599 |
577 _onAddAuditCategory: function(message, port) | 600 _onAddAuditCategory: function(message, port) |
578 { | 601 { |
579 var category = new WebInspector.ExtensionAuditCategory(port._extensionOr
igin, message.id, message.displayName, message.resultCount); | 602 var category = new WebInspector.ExtensionAuditCategory(port._extensionOr
igin, message.id, message.displayName, message.resultCount); |
580 this._clientObjects[message.id] = category; | 603 this._clientObjects[message.id] = category; |
581 this._auditCategories.push(category); | 604 this._auditCategories.push(category); |
582 this.dispatchEventToListeners(WebInspector.ExtensionServer.Events.AuditC
ategoryAdded, category); | 605 this.dispatchEventToListeners(WebInspector.ExtensionServer.Events.AuditC
ategoryAdded, category); |
583 }, | 606 }, |
584 | 607 |
| 608 _onAddTraceProvider: function(message, port) |
| 609 { |
| 610 var provider = new WebInspector.ExtensionTraceProvider(port._extensionOr
igin, message.id, message.categoryName, message.categoryTooltip); |
| 611 this._clientObjects[message.id] = provider; |
| 612 this._traceProviders.push(provider); |
| 613 this.dispatchEventToListeners(WebInspector.ExtensionServer.Events.TraceP
roviderAdded, provider); |
| 614 }, |
| 615 |
| 616 /** |
| 617 * @return {!Array.<!WebInspector.ExtensionTraceProvider>} |
| 618 */ |
| 619 traceProviders: function() |
| 620 { |
| 621 return this._traceProviders; |
| 622 }, |
| 623 |
585 /** | 624 /** |
586 * @return {!Array.<!WebInspector.ExtensionAuditCategory>} | 625 * @return {!Array.<!WebInspector.ExtensionAuditCategory>} |
587 */ | 626 */ |
588 auditCategories: function() | 627 auditCategories: function() |
589 { | 628 { |
590 return this._auditCategories; | 629 return this._auditCategories; |
591 }, | 630 }, |
592 | 631 |
593 _onAddAuditResult: function(message) | 632 _onAddAuditResult: function(message) |
594 { | 633 { |
595 var auditResult = /** {!WebInspector.ExtensionAuditCategoryResults} */ (
this._clientObjects[message.resultId]); | 634 var auditResult = /** {!WebInspector.ExtensionAuditCategoryResults} */ (
this._clientObjects[message.resultId]); |
596 if (!auditResult) | 635 if (!auditResult) |
597 return this._status.E_NOTFOUND(message.resultId); | 636 return this._status.E_NOTFOUND(message.resultId); |
598 try { | 637 try { |
599 auditResult.addResult(message.displayName, message.description, mess
age.severity, message.details); | 638 auditResult.addResult(message.displayName, message.description, mess
age.severity, message.details); |
600 } catch (e) { | 639 } catch (e) { |
601 return e; | 640 return e; |
602 } | 641 } |
603 return this._status.OK(); | 642 return this._status.OK(); |
604 }, | 643 }, |
605 | 644 |
| 645 _onAddTraceData: function(message) |
| 646 { |
| 647 var traceProvider = /** {!WebInspector.ExtensionTraceProvider} */ (thi
s._clientObjects[message.traceProviderId]); |
| 648 if (!traceProvider) |
| 649 return this._status.E_NOTFOUND(message.traceProviderId); |
| 650 var traceData = traceProvider.traceData; |
| 651 try { |
| 652 traceData.addTraceData(message.threadName, message.events); |
| 653 } catch (e) { |
| 654 return e; |
| 655 } |
| 656 return this._status.OK(); |
| 657 }, |
| 658 |
606 _onUpdateAuditProgress: function(message) | 659 _onUpdateAuditProgress: function(message) |
607 { | 660 { |
608 var auditResult = /** {!WebInspector.ExtensionAuditCategoryResults} */ (
this._clientObjects[message.resultId]); | 661 var auditResult = /** {!WebInspector.ExtensionAuditCategoryResults} */ (
this._clientObjects[message.resultId]); |
609 if (!auditResult) | 662 if (!auditResult) |
610 return this._status.E_NOTFOUND(message.resultId); | 663 return this._status.E_NOTFOUND(message.resultId); |
611 auditResult.updateProgress(Math.min(Math.max(0, message.progress), 1)); | 664 auditResult.updateProgress(Math.min(Math.max(0, message.progress), 1)); |
612 }, | 665 }, |
613 | 666 |
614 _onStopAuditCategoryRun: function(message) | 667 _onStopAuditCategoryRun: function(message) |
615 { | 668 { |
(...skipping 455 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1071 /** | 1124 /** |
1072 * @typedef {{code: string, description: string, details: !Array.<*>}} | 1125 * @typedef {{code: string, description: string, details: !Array.<*>}} |
1073 */ | 1126 */ |
1074 WebInspector.ExtensionStatus.Record; | 1127 WebInspector.ExtensionStatus.Record; |
1075 | 1128 |
1076 WebInspector.extensionAPI = {}; | 1129 WebInspector.extensionAPI = {}; |
1077 defineCommonExtensionSymbols(WebInspector.extensionAPI); | 1130 defineCommonExtensionSymbols(WebInspector.extensionAPI); |
1078 | 1131 |
1079 /** @type {!WebInspector.ExtensionServer} */ | 1132 /** @type {!WebInspector.ExtensionServer} */ |
1080 WebInspector.extensionServer; | 1133 WebInspector.extensionServer; |
OLD | NEW |