Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(129)

Side by Side Diff: Source/devtools/front_end/extensions/ExtensionServer.js

Issue 667623002: DevTools: make extension server a part of core, panels' code should depend on it. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: for review Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 12 matching lines...) Expand all
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 30
31 /** 31 /**
32 * @constructor 32 * @constructor
33 * @implements {WebInspector.ExtensionServerAPI} 33 * @extends {WebInspector.Object}
34 */ 34 */
35 WebInspector.ExtensionServer = function() 35 WebInspector.ExtensionServer = function()
36 { 36 {
37 this._clientObjects = {}; 37 this._clientObjects = {};
38 this._handlers = {}; 38 this._handlers = {};
39 this._subscribers = {}; 39 this._subscribers = {};
40 this._subscriptionStartHandlers = {}; 40 this._subscriptionStartHandlers = {};
41 this._subscriptionStopHandlers = {}; 41 this._subscriptionStopHandlers = {};
42 this._extraHeaders = {}; 42 this._extraHeaders = {};
43 this._requests = {}; 43 this._requests = {};
44 this._lastRequestId = 0; 44 this._lastRequestId = 0;
45 this._registeredExtensions = {}; 45 this._registeredExtensions = {};
46 this._status = new WebInspector.ExtensionStatus(); 46 this._status = new WebInspector.ExtensionStatus();
47 /** @type {!Array.<!WebInspector.ExtensionSidebarPane>} */
48 this._sidebarPanes = [];
49 /** @type {!Array.<!WebInspector.ExtensionAuditCategory>} */
50 this._auditCategories = [];
47 51
48 var commands = WebInspector.extensionAPI.Commands; 52 var commands = WebInspector.extensionAPI.Commands;
49 53
50 this._registerHandler(commands.AddAuditCategory, this._onAddAuditCategory.bi nd(this)); 54 this._registerHandler(commands.AddAuditCategory, this._onAddAuditCategory.bi nd(this));
51 this._registerHandler(commands.AddAuditResult, this._onAddAuditResult.bind(t his)); 55 this._registerHandler(commands.AddAuditResult, this._onAddAuditResult.bind(t his));
52 this._registerHandler(commands.AddConsoleMessage, this._onAddConsoleMessage. bind(this)); 56 this._registerHandler(commands.AddConsoleMessage, this._onAddConsoleMessage. bind(this));
53 this._registerHandler(commands.AddRequestHeaders, this._onAddRequestHeaders. bind(this)); 57 this._registerHandler(commands.AddRequestHeaders, this._onAddRequestHeaders. bind(this));
54 this._registerHandler(commands.ApplyStyleSheet, this._onApplyStyleSheet.bind (this)); 58 this._registerHandler(commands.ApplyStyleSheet, this._onApplyStyleSheet.bind (this));
55 this._registerHandler(commands.CreatePanel, this._onCreatePanel.bind(this)); 59 this._registerHandler(commands.CreatePanel, this._onCreatePanel.bind(this));
56 this._registerHandler(commands.CreateSidebarPane, this._onCreateSidebarPane. bind(this)); 60 this._registerHandler(commands.CreateSidebarPane, this._onCreateSidebarPane. bind(this));
(...skipping 16 matching lines...) Expand all
73 this._registerHandler(commands.Subscribe, this._onSubscribe.bind(this)); 77 this._registerHandler(commands.Subscribe, this._onSubscribe.bind(this));
74 this._registerHandler(commands.OpenResource, this._onOpenResource.bind(this) ); 78 this._registerHandler(commands.OpenResource, this._onOpenResource.bind(this) );
75 this._registerHandler(commands.Unsubscribe, this._onUnsubscribe.bind(this)); 79 this._registerHandler(commands.Unsubscribe, this._onUnsubscribe.bind(this));
76 this._registerHandler(commands.UpdateButton, this._onUpdateButton.bind(this) ); 80 this._registerHandler(commands.UpdateButton, this._onUpdateButton.bind(this) );
77 this._registerHandler(commands.UpdateAuditProgress, this._onUpdateAuditProgr ess.bind(this)); 81 this._registerHandler(commands.UpdateAuditProgress, this._onUpdateAuditProgr ess.bind(this));
78 window.addEventListener("message", this._onWindowMessage.bind(this), false); 82 window.addEventListener("message", this._onWindowMessage.bind(this), false);
79 83
80 this._initExtensions(); 84 this._initExtensions();
81 } 85 }
82 86
87 WebInspector.ExtensionServer.Events = {
88 SidebarPaneAdded: "SidebarPaneAdded",
89 AuditCategoryAdded: "AuditCategoryAdded"
90 }
91
83 WebInspector.ExtensionServer.prototype = { 92 WebInspector.ExtensionServer.prototype = {
84 /** 93 /**
85 * @return {boolean} 94 * @return {boolean}
86 */ 95 */
87 hasExtensions: function() 96 hasExtensions: function()
88 { 97 {
89 return !!Object.keys(this._registeredExtensions).length; 98 return !!Object.keys(this._registeredExtensions).length;
90 }, 99 },
91 100
92 /** 101 /**
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 135
127 _inspectedURLChanged: function(event) 136 _inspectedURLChanged: function(event)
128 { 137 {
129 this._requests = {}; 138 this._requests = {};
130 var url = event.data; 139 var url = event.data;
131 this._postNotification(WebInspector.extensionAPI.Events.InspectedURLChan ged, url); 140 this._postNotification(WebInspector.extensionAPI.Events.InspectedURLChan ged, url);
132 }, 141 },
133 142
134 143
135 /** 144 /**
136 * @param {!WebInspector.ExtensionAuditCategory} category 145 * @param {string} categoryId
137 * @param {!WebInspector.ExtensionAuditCategoryResults} auditResults 146 * @param {!WebInspector.ExtensionAuditCategoryResults} auditResults
138 */ 147 */
139 startAuditRun: function(category, auditResults) 148 startAuditRun: function(categoryId, auditResults)
140 { 149 {
141 this._clientObjects[auditResults.id] = auditResults; 150 this._clientObjects[auditResults.id()] = auditResults;
142 this._postNotification("audit-started-" + category.id, auditResults.id); 151 this._postNotification("audit-started-" + categoryId, auditResults.id()) ;
143 }, 152 },
144 153
145 /** 154 /**
146 * @param {!WebInspector.ExtensionAuditCategoryResults} auditResults 155 * @param {!WebInspector.ExtensionAuditCategoryResults} auditResults
147 */ 156 */
148 stopAuditRun: function(auditResults) 157 stopAuditRun: function(auditResults)
149 { 158 {
150 delete this._clientObjects[auditResults.id]; 159 delete this._clientObjects[auditResults.id()];
151 }, 160 },
152 161
153 /** 162 /**
154 * @param {string} type 163 * @param {string} type
155 * @return {boolean} 164 * @return {boolean}
156 */ 165 */
157 hasSubscribers: function(type) 166 hasSubscribers: function(type)
158 { 167 {
159 return !!this._subscribers[type]; 168 return !!this._subscribers[type];
160 }, 169 },
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 if (!button || !(button instanceof WebInspector.ExtensionButton)) 289 if (!button || !(button instanceof WebInspector.ExtensionButton))
281 return this._status.E_NOTFOUND(message.id); 290 return this._status.E_NOTFOUND(message.id);
282 button.update(this._expandResourcePath(port._extensionOrigin, message.ic on), message.tooltip, message.disabled); 291 button.update(this._expandResourcePath(port._extensionOrigin, message.ic on), message.tooltip, message.disabled);
283 return this._status.OK(); 292 return this._status.OK();
284 }, 293 },
285 294
286 _onCreateSidebarPane: function(message) 295 _onCreateSidebarPane: function(message)
287 { 296 {
288 if (message.panel !== "elements" && message.panel !== "sources") 297 if (message.panel !== "elements" && message.panel !== "sources")
289 return this._status.E_NOTFOUND(message.panel); 298 return this._status.E_NOTFOUND(message.panel);
290 var panel = message.panel === "elements" ? WebInspector.ElementsPanel.in stance() : WebInspector.SourcesPanel.instance();
291 var id = message.id; 299 var id = message.id;
292 var sidebar = new WebInspector.ExtensionSidebarPane(this, message.title, id); 300 var sidebar = new WebInspector.ExtensionSidebarPane(this, message.panel, message.title, id);
301 this._sidebarPanes.push(sidebar);
293 this._clientObjects[id] = sidebar; 302 this._clientObjects[id] = sidebar;
294 panel.addExtensionSidebarPane(id, sidebar); 303 this.dispatchEventToListeners(WebInspector.ExtensionServer.Events.Sideba rPaneAdded, sidebar);
295 304
296 return this._status.OK(); 305 return this._status.OK();
297 }, 306 },
298 307
308 /**
309 * @return {!Array.<!WebInspector.ExtensionSidebarPane>}
310 */
311 sidebarPanes: function()
312 {
313 return this._sidebarPanes;
314 },
315
299 _onSetSidebarHeight: function(message) 316 _onSetSidebarHeight: function(message)
300 { 317 {
301 var sidebar = this._clientObjects[message.id]; 318 var sidebar = this._clientObjects[message.id];
302 if (!sidebar) 319 if (!sidebar)
303 return this._status.E_NOTFOUND(message.id); 320 return this._status.E_NOTFOUND(message.id);
304 sidebar.setHeight(message.height); 321 sidebar.setHeight(message.height);
305 return this._status.OK(); 322 return this._status.OK();
306 }, 323 },
307 324
308 _onSetSidebarContent: function(message, port) 325 _onSetSidebarContent: function(message, port)
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after
600 return request._extensionRequestId; 617 return request._extensionRequestId;
601 }, 618 },
602 619
603 _requestById: function(id) 620 _requestById: function(id)
604 { 621 {
605 return this._requests[id]; 622 return this._requests[id];
606 }, 623 },
607 624
608 _onAddAuditCategory: function(message, port) 625 _onAddAuditCategory: function(message, port)
609 { 626 {
610 var category = new WebInspector.ExtensionAuditCategory(this, port._exten sionOrigin, message.id, message.displayName, message.resultCount); 627 var category = new WebInspector.ExtensionAuditCategory(port._extensionOr igin, message.id, message.displayName, message.resultCount);
611 if (WebInspector.AuditsPanel.instance().getCategory(category.id))
612 return this._status.E_EXISTS(category.id);
613 this._clientObjects[message.id] = category; 628 this._clientObjects[message.id] = category;
614 WebInspector.AuditsPanel.instance().addCategory(category); 629 this._auditCategories.push(category);
630 this.dispatchEventToListeners(WebInspector.ExtensionServer.Events.AuditC ategoryAdded, category);
631 },
632
633 /**
634 * @return {!Array.<!WebInspector.ExtensionAuditCategory>}
635 */
636 auditCategories: function()
637 {
638 return this._auditCategories;
615 }, 639 },
616 640
617 _onAddAuditResult: function(message) 641 _onAddAuditResult: function(message)
618 { 642 {
619 var auditResult = this._clientObjects[message.resultId]; 643 var auditResult = /** {!WebInspector.ExtensionAuditCategoryResults} */ ( this._clientObjects[message.resultId]);
620 if (!auditResult) 644 if (!auditResult)
621 return this._status.E_NOTFOUND(message.resultId); 645 return this._status.E_NOTFOUND(message.resultId);
622 try { 646 try {
623 auditResult.addResult(message.displayName, message.description, mess age.severity, message.details); 647 auditResult.addResult(message.displayName, message.description, mess age.severity, message.details);
624 } catch (e) { 648 } catch (e) {
625 return e; 649 return e;
626 } 650 }
627 return this._status.OK(); 651 return this._status.OK();
628 }, 652 },
629 653
630 _onUpdateAuditProgress: function(message) 654 _onUpdateAuditProgress: function(message)
631 { 655 {
632 var auditResult = this._clientObjects[message.resultId]; 656 var auditResult = /** {!WebInspector.ExtensionAuditCategoryResults} */ ( this._clientObjects[message.resultId]);
633 if (!auditResult) 657 if (!auditResult)
634 return this._status.E_NOTFOUND(message.resultId); 658 return this._status.E_NOTFOUND(message.resultId);
635 auditResult.updateProgress(Math.min(Math.max(0, message.progress), 1)); 659 auditResult.updateProgress(Math.min(Math.max(0, message.progress), 1));
636 }, 660 },
637 661
638 _onStopAuditCategoryRun: function(message) 662 _onStopAuditCategoryRun: function(message)
639 { 663 {
640 var auditRun = this._clientObjects[message.resultId]; 664 var auditRun = /** {!WebInspector.ExtensionAuditCategoryResults} */ (thi s._clientObjects[message.resultId]);
641 if (!auditRun) 665 if (!auditRun)
642 return this._status.E_NOTFOUND(message.resultId); 666 return this._status.E_NOTFOUND(message.resultId);
643 auditRun.done(); 667 auditRun.done();
644 }, 668 },
645 669
646 _onForwardKeyboardEvent: function(message) 670 _onForwardKeyboardEvent: function(message)
647 { 671 {
648 const Esc = "U+001B"; 672 const Esc = "U+001B";
649 message.entries.forEach(handleEventEntry); 673 message.entries.forEach(handleEventEntry);
650 674
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
705 /** 729 /**
706 * @this {WebInspector.ExtensionServer} 730 * @this {WebInspector.ExtensionServer}
707 */ 731 */
708 function onElementsSubscriptionStopped() 732 function onElementsSubscriptionStopped()
709 { 733 {
710 WebInspector.notifications.removeEventListener(WebInspector.Notifica tionService.Events.SelectedNodeChanged, this._notifyElementsSelectionChanged, th is); 734 WebInspector.notifications.removeEventListener(WebInspector.Notifica tionService.Events.SelectedNodeChanged, this._notifyElementsSelectionChanged, th is);
711 } 735 }
712 736
713 this._registerSubscriptionHandler(WebInspector.extensionAPI.Events.Panel ObjectSelected + "elements", 737 this._registerSubscriptionHandler(WebInspector.extensionAPI.Events.Panel ObjectSelected + "elements",
714 onElementsSubscriptionStarted.bind(this), onElementsSubscriptionStop ped.bind(this)); 738 onElementsSubscriptionStarted.bind(this), onElementsSubscriptionStop ped.bind(this));
715
716 this._registerAutosubscriptionHandler(WebInspector.extensionAPI.Events.P anelObjectSelected + "sources",
717 WebInspector.notifications,
718 WebInspector.SourceFrame.Events.SelectionChanged,
719 this._notifySourceFrameSelectionChanged);
720 this._registerResourceContentCommittedHandler(this._notifyUISourceCodeCo ntentCommitted); 739 this._registerResourceContentCommittedHandler(this._notifyUISourceCodeCo ntentCommitted);
721 740
722 WebInspector.targetManager.addEventListener(WebInspector.TargetManager.E vents.InspectedURLChanged, 741 WebInspector.targetManager.addEventListener(WebInspector.TargetManager.E vents.InspectedURLChanged,
723 this._inspectedURLChanged, this); 742 this._inspectedURLChanged, this);
724 743
725 InspectorExtensionRegistry.getExtensionsAsync(); 744 InspectorExtensionRegistry.getExtensionsAsync();
726 }, 745 },
727 746
728 /**
729 * @param {!WebInspector.TextRange} textRange
730 */
731 _makeSourceSelection: function(textRange)
732 {
733 var sourcesPanel = WebInspector.SourcesPanel.instance();
734 var selection = {
735 startLine: textRange.startLine,
736 startColumn: textRange.startColumn,
737 endLine: textRange.endLine,
738 endColumn: textRange.endColumn,
739 url: sourcesPanel.sourcesView().currentUISourceCode().uri()
740 };
741
742 return selection;
743 },
744
745 _notifySourceFrameSelectionChanged: function(event)
caseq 2014/10/20 09:20:10 Please state the fact that we remove support for s
746 {
747 this._postNotification(WebInspector.extensionAPI.Events.PanelObjectSelec ted + "sources", this._makeSourceSelection(event.data));
748 },
749
750 _notifyConsoleMessageAdded: function(event) 747 _notifyConsoleMessageAdded: function(event)
751 { 748 {
752 this._postNotification(WebInspector.extensionAPI.Events.ConsoleMessageAd ded, this._makeConsoleMessage(event.data)); 749 this._postNotification(WebInspector.extensionAPI.Events.ConsoleMessageAd ded, this._makeConsoleMessage(event.data));
753 }, 750 },
754 751
755 _notifyResourceAdded: function(event) 752 _notifyResourceAdded: function(event)
756 { 753 {
757 var uiSourceCode = /** @type {!WebInspector.UISourceCode} */ (event.data ); 754 var uiSourceCode = /** @type {!WebInspector.UISourceCode} */ (event.data );
758 this._postNotification(WebInspector.extensionAPI.Events.ResourceAdded, t his._makeResource(uiSourceCode)); 755 this._postNotification(WebInspector.extensionAPI.Events.ResourceAdded, t his._makeResource(uiSourceCode));
759 }, 756 },
(...skipping 12 matching lines...) Expand all
772 }, 769 },
773 770
774 _notifyElementsSelectionChanged: function() 771 _notifyElementsSelectionChanged: function()
775 { 772 {
776 this._postNotification(WebInspector.extensionAPI.Events.PanelObjectSelec ted + "elements"); 773 this._postNotification(WebInspector.extensionAPI.Events.PanelObjectSelec ted + "elements");
777 }, 774 },
778 775
779 /** 776 /**
780 * @param {!Array.<!ExtensionDescriptor>} extensionInfos 777 * @param {!Array.<!ExtensionDescriptor>} extensionInfos
781 */ 778 */
782 addExtensions: function(extensionInfos) 779 _addExtensions: function(extensionInfos)
783 { 780 {
784 extensionInfos.forEach(this._addExtension, this); 781 extensionInfos.forEach(this._addExtension, this);
785 }, 782 },
786 783
787 /** 784 /**
788 * @param {!ExtensionDescriptor} extensionInfo 785 * @param {!ExtensionDescriptor} extensionInfo
789 */ 786 */
790 _addExtension: function(extensionInfo) 787 _addExtension: function(extensionInfo)
791 { 788 {
792 const urlOriginRegExp = new RegExp("([^:]+:\/\/[^/]*)\/"); // Can't use regexp literal here, MinJS chokes on it. 789 const urlOriginRegExp = new RegExp("([^:]+:\/\/[^/]*)\/"); // Can't use regexp literal here, MinJS chokes on it.
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
1002 context = executionContext; 999 context = executionContext;
1003 1000
1004 } 1001 }
1005 if (!context) 1002 if (!context)
1006 return this._status.E_FAILED(frame.url + " has no execution context"); 1003 return this._status.E_FAILED(frame.url + " has no execution context");
1007 } 1004 }
1008 1005
1009 contextId = context.id; 1006 contextId = context.id;
1010 } 1007 }
1011 RuntimeAgent.evaluate(expression, "extension", exposeCommandLineAPI, tru e, contextId, returnByValue, false, callback); 1008 RuntimeAgent.evaluate(expression, "extension", exposeCommandLineAPI, tru e, contextId, returnByValue, false, callback);
1012 } 1009 },
1010
1011 __proto__: WebInspector.Object.prototype
1013 } 1012 }
1014 1013
1015 /** 1014 /**
1016 * @constructor 1015 * @constructor
1017 * @param {string} name 1016 * @param {string} name
1018 * @param {string} title 1017 * @param {string} title
1019 * @param {!WebInspector.Panel} panel 1018 * @param {!WebInspector.Panel} panel
1020 * @implements {WebInspector.PanelDescriptor} 1019 * @implements {WebInspector.PanelDescriptor}
1021 */ 1020 */
1022 WebInspector.ExtensionServerPanelDescriptor = function(name, title, panel) 1021 WebInspector.ExtensionServerPanelDescriptor = function(name, title, panel)
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
1083 this.E_FAILED = makeStatus.bind(null, "E_FAILED", "Operation failed: %s"); 1082 this.E_FAILED = makeStatus.bind(null, "E_FAILED", "Operation failed: %s");
1084 } 1083 }
1085 1084
1086 /** 1085 /**
1087 * @typedef {{code: string, description: string, details: !Array.<*>}} 1086 * @typedef {{code: string, description: string, details: !Array.<*>}}
1088 */ 1087 */
1089 WebInspector.ExtensionStatus.Record; 1088 WebInspector.ExtensionStatus.Record;
1090 1089
1091 WebInspector.extensionAPI = {}; 1090 WebInspector.extensionAPI = {};
1092 defineCommonExtensionSymbols(WebInspector.extensionAPI); 1091 defineCommonExtensionSymbols(WebInspector.extensionAPI);
1092
1093 WebInspector.addExtensions = function(extensions)
1094 {
1095 if (WebInspector.extensionServer._overridePlatformExtensionAPIForTest)
1096 window.buildPlatformExtensionAPI = WebInspector.extensionServer._overrid ePlatformExtensionAPIForTest;
1097 WebInspector.extensionServer._addExtensions(extensions);
1098 }
1099
1100 WebInspector.setInspectedTabId = function(tabId)
1101 {
1102 WebInspector._inspectedTabId = tabId;
1103 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698