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

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

Issue 1264133002: Devtools: [WIP] Implement enhanced devtools extension language APIs Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Small cleanups - prefer URIs to contentURLs, revert protocol unifications, remove lambdas Created 5 years, 4 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
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 13 matching lines...) Expand all
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 * @extends {WebInspector.Object} 33 * @extends {WebInspector.Object}
34 * @param {!WebInspector.ExtensionServer.UIDelegate} delegate
34 * @suppressGlobalPropertiesCheck 35 * @suppressGlobalPropertiesCheck
35 */ 36 */
36 WebInspector.ExtensionServer = function() 37 WebInspector.ExtensionServer = function(delegate)
37 { 38 {
39 this._delegate = delegate;
38 this._clientObjects = {}; 40 this._clientObjects = {};
39 this._handlers = {}; 41 this._handlers = {};
42 this._callbacks = {};
40 this._subscribers = {}; 43 this._subscribers = {};
41 this._subscriptionStartHandlers = {}; 44 this._subscriptionStartHandlers = {};
42 this._subscriptionStopHandlers = {}; 45 this._subscriptionStopHandlers = {};
43 this._extraHeaders = {}; 46 this._extraHeaders = {};
44 this._requests = {}; 47 this._requests = {};
45 this._lastRequestId = 0; 48 this._lastRequestId = 0;
46 this._registeredExtensions = {}; 49 this._registeredExtensions = {};
47 this._status = new WebInspector.ExtensionStatus(); 50 this._status = new WebInspector.ExtensionStatus();
48 /** @type {!Array.<!WebInspector.ExtensionSidebarPane>} */ 51 /** @type {!Array.<!WebInspector.ExtensionSidebarPane>} */
49 this._sidebarPanes = []; 52 this._sidebarPanes = [];
50 /** @type {!Array.<!WebInspector.ExtensionAuditCategory>} */ 53 /** @type {!Array.<!WebInspector.ExtensionAuditCategory>} */
51 this._auditCategories = []; 54 this._auditCategories = [];
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));
57 this._registerHandler(commands.AddRequestHeaders, this._onAddRequestHeaders. bind(this)); 60 this._registerHandler(commands.AddRequestHeaders, this._onAddRequestHeaders. bind(this));
58 this._registerHandler(commands.ApplyStyleSheet, this._onApplyStyleSheet.bind (this)); 61 this._registerHandler(commands.ApplyStyleSheet, this._onApplyStyleSheet.bind (this));
59 this._registerHandler(commands.CreatePanel, this._onCreatePanel.bind(this)); 62 this._registerHandler(commands.CreatePanel, this._onCreatePanel.bind(this));
60 this._registerHandler(commands.CreateSidebarPane, this._onCreateSidebarPane. bind(this)); 63 this._registerHandler(commands.CreateSidebarPane, this._onCreateSidebarPane. bind(this));
61 this._registerHandler(commands.CreateToolbarButton, this._onCreateToolbarBut ton.bind(this)); 64 this._registerHandler(commands.CreateToolbarButton, this._onCreateToolbarBut ton.bind(this));
65 this._registerHandler(commands.DisplaySearchResults, this._onDisplaySearchRe sults.bind(this));
62 this._registerHandler(commands.EvaluateOnInspectedPage, this._onEvaluateOnIn spectedPage.bind(this)); 66 this._registerHandler(commands.EvaluateOnInspectedPage, this._onEvaluateOnIn spectedPage.bind(this));
63 this._registerHandler(commands.ForwardKeyboardEvent, this._onForwardKeyboard Event.bind(this)); 67 this._registerHandler(commands.ForwardKeyboardEvent, this._onForwardKeyboard Event.bind(this));
64 this._registerHandler(commands.GetHAR, this._onGetHAR.bind(this)); 68 this._registerHandler(commands.GetHAR, this._onGetHAR.bind(this));
65 this._registerHandler(commands.GetPageResources, this._onGetPageResources.bi nd(this)); 69 this._registerHandler(commands.GetPageResources, this._onGetPageResources.bi nd(this));
66 this._registerHandler(commands.GetRequestContent, this._onGetRequestContent. bind(this)); 70 this._registerHandler(commands.GetRequestContent, this._onGetRequestContent. bind(this));
67 this._registerHandler(commands.GetResourceContent, this._onGetResourceConten t.bind(this)); 71 this._registerHandler(commands.GetResourceContent, this._onGetResourceConten t.bind(this));
72 this._registerHandler(commands.RegisterLanguageService, this._onRegisterLang uageService.bind(this));
73 this._registerHandler(commands.NewMimeType, this._onNewMimeType.bind(this));
68 this._registerHandler(commands.Reload, this._onReload.bind(this)); 74 this._registerHandler(commands.Reload, this._onReload.bind(this));
69 this._registerHandler(commands.SetOpenResourceHandler, this._onSetOpenResour ceHandler.bind(this)); 75 this._registerHandler(commands.SetOpenResourceHandler, this._onSetOpenResour ceHandler.bind(this));
70 this._registerHandler(commands.SetResourceContent, this._onSetResourceConten t.bind(this)); 76 this._registerHandler(commands.SetResourceContent, this._onSetResourceConten t.bind(this));
77 this._registerHandler(commands.SetResourceLineMessages, this._onSetResourceL ineMessages.bind(this));
71 this._registerHandler(commands.SetSidebarHeight, this._onSetSidebarHeight.bi nd(this)); 78 this._registerHandler(commands.SetSidebarHeight, this._onSetSidebarHeight.bi nd(this));
72 this._registerHandler(commands.SetSidebarContent, this._onSetSidebarContent. bind(this)); 79 this._registerHandler(commands.SetSidebarContent, this._onSetSidebarContent. bind(this));
73 this._registerHandler(commands.SetSidebarPage, this._onSetSidebarPage.bind(t his)); 80 this._registerHandler(commands.SetSidebarPage, this._onSetSidebarPage.bind(t his));
74 this._registerHandler(commands.ShowPanel, this._onShowPanel.bind(this)); 81 this._registerHandler(commands.ShowPanel, this._onShowPanel.bind(this));
75 this._registerHandler(commands.StopAuditCategoryRun, this._onStopAuditCatego ryRun.bind(this)); 82 this._registerHandler(commands.StopAuditCategoryRun, this._onStopAuditCatego ryRun.bind(this));
76 this._registerHandler(commands.Subscribe, this._onSubscribe.bind(this)); 83 this._registerHandler(commands.Subscribe, this._onSubscribe.bind(this));
77 this._registerHandler(commands.OpenResource, this._onOpenResource.bind(this) ); 84 this._registerHandler(commands.OpenResource, this._onOpenResource.bind(this) );
78 this._registerHandler(commands.Unsubscribe, this._onUnsubscribe.bind(this)); 85 this._registerHandler(commands.Unsubscribe, this._onUnsubscribe.bind(this));
79 this._registerHandler(commands.UpdateButton, this._onUpdateButton.bind(this) ); 86 this._registerHandler(commands.UpdateButton, this._onUpdateButton.bind(this) );
80 this._registerHandler(commands.UpdateAuditProgress, this._onUpdateAuditProgr ess.bind(this)); 87 this._registerHandler(commands.UpdateAuditProgress, this._onUpdateAuditProgr ess.bind(this));
88 this._registerHandler("callback", this._onCallback.bind(this));
81 window.addEventListener("message", this._onWindowMessage.bind(this), false); // Only for main window. 89 window.addEventListener("message", this._onWindowMessage.bind(this), false); // Only for main window.
82 90
83 InspectorFrontendHost.events.addEventListener(InspectorFrontendHostAPI.Event s.AddExtensions, this._addExtensions, this); 91 InspectorFrontendHost.events.addEventListener(InspectorFrontendHostAPI.Event s.AddExtensions, this._addExtensions, this);
84 InspectorFrontendHost.events.addEventListener(InspectorFrontendHostAPI.Event s.SetInspectedTabId, this._setInspectedTabId, this); 92 InspectorFrontendHost.events.addEventListener(InspectorFrontendHostAPI.Event s.SetInspectedTabId, this._setInspectedTabId, this);
85 93
86 this._initExtensions(); 94 this._initExtensions();
87 } 95 }
88 96
89 WebInspector.ExtensionServer.Events = { 97 WebInspector.ExtensionServer.Events = {
90 SidebarPaneAdded: "SidebarPaneAdded", 98 SidebarPaneAdded: "SidebarPaneAdded",
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 180
173 /** 181 /**
174 * @param {string} type 182 * @param {string} type
175 * @return {boolean} 183 * @return {boolean}
176 */ 184 */
177 hasSubscribers: function(type) 185 hasSubscribers: function(type)
178 { 186 {
179 return !!this._subscribers[type]; 187 return !!this._subscribers[type];
180 }, 188 },
181 189
190 _registerCallback: function(callback) {
191 var cbId = Math.random()*Number.MAX_VALUE;
192 if (this._callbacks[cbId]) {
193 return this._registerCallback(callback);
194 }
195 this._callbacks[cbId] = callback;
196 return cbId;
197 },
198
199 /**
200 * @param {!MessagePort} port
201 * @param {*} message
202 * @param {?Function=} callback
203 */
204 _sendRequest: function(port, message, callback) {
205 if (typeof callback === "function")
206 message.requestId = this._registerCallback(callback);
207 port.postMessage(message);
208 },
209
182 /** 210 /**
183 * @param {string} type 211 * @param {string} type
184 * @param {...*} vararg 212 * @param {...*} vararg
185 */ 213 */
186 _postNotification: function(type, vararg) 214 _postNotification: function(type, vararg)
187 { 215 {
188 var subscribers = this._subscribers[type]; 216 var subscribers = this._subscribers[type];
189 if (!subscribers) 217 if (!subscribers)
190 return; 218 return;
191 var message = { 219 var message = {
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 if (typeof headers[name] === "string") 268 if (typeof headers[name] === "string")
241 allHeaders[name] = headers[name]; 269 allHeaders[name] = headers[name];
242 } 270 }
243 } 271 }
244 272
245 WebInspector.multitargetNetworkManager.setExtraHTTPHeaders(allHeaders); 273 WebInspector.multitargetNetworkManager.setExtraHTTPHeaders(allHeaders);
246 }, 274 },
247 275
248 /** 276 /**
249 * @param {*} message 277 * @param {*} message
278 * @param {!MessagePort} port
279 */
280 _onRegisterLanguageService: function(message, port)
281 {
282 if (!(message.mimes && message.name && message.capabilities)) {
283 return;
284 }
285 var _this = this;
286
287 if (message.simplemode) {
288 this._delegate.addSimpleCodeMirrorMode(message.mimes, message.simple mode);
289 }
290
291 var service = new WebInspector.LanguageService.CallbackDelegate(message. name, {});
292
293 if (message.capabilities.indexOf(WebInspector.LanguageService.Capabiliti es.Transpile) !== -1) {
294 service.appendActionHandler(WebInspector.LanguageService.Capabilitie s.Transpile, function(input, location, callback) {
295 if (!callback) {
296 callback = location;
297 location = undefined;
298 }
299 _this._sendRequest(port, {
300 command: WebInspector.LanguageService.Capabilities.Transpile +"-"+message.name,
301 input: input,
302 location: location
303 }, function(result) {
304 if ((!result) || typeof result !== "string") {
305 return callback(input);
306 }
307 callback(result);
308 });
309 });
310 }
311 if (message.capabilities.indexOf(WebInspector.LanguageService.Capabiliti es.PopulateContextMenu) !== -1) {
312 service.appendActionHandler(WebInspector.LanguageService.Capabilitie s.PopulateContextMenu, function(location, callback) {
313 _this._sendRequest(port, {
314 command: WebInspector.LanguageService.Capabilities.PopulateC ontextMenu+"-"+message.name,
315 location: location
316 }, function(items) {
317 if (!items || !(items instanceof Array)) {
318 return callback([]);
319 }
320 callback(items.map(function(item) {
321 if (typeof item.text !== "string") return;
322 if (typeof item.id !== "number") return;
323 return {
324 text: item.text,
325 callback: function() {
326 _this._sendRequest(port, {command: "notify-"+Web Inspector.extensionAPI.Events.ContextMenuClicked, id: item.id});
327 }
328 };
329 }).filter(function(i) {return i;}));
330 });
331 });
332 }
333
334 function handleCompletionsResponse(callback) {
335 return function(completions) {
336 if ((!completions) || !(completions instanceof Array)) {
337 return callback([]);
338 }
339 callback(completions.map(function(c){
340 if (typeof c.text !== "string") return;
341 if (!(typeof c.icon === "string" || typeof c.icon === "undef ined")) return;
342 if (typeof c.id !== "number") return;
343 return {
344 text: c.text,
345 icon: c.icon,
346 details: function() {
347 return new Promise(function(resolve, reject) {
348 _this._sendRequest(port, {command: "completionDe tails-"+message.name, id: c.id}, function(resp) {
349 if (!resp) reject();
350 if (typeof resp.detail !== "string") reject( );
351 if (typeof resp.description !== "string") re ject();
352 resolve(resp);
353 });
354 });
355 }
356 };
357 }).filter(function(i) {return i;}));
358 }
359 }
360
361 if (message.capabilities.indexOf(WebInspector.LanguageService.Capabiliti es.Completions) !== -1) {
362 service.appendActionHandler(WebInspector.LanguageService.Capabilitie s.Completions, function(location, prefix, callback) {
363 _this._sendRequest(port, {
364 command: WebInspector.LanguageService.Capabilities.Completio ns+"-"+message.name,
365 location: location,
366 prefix: prefix
367 }, handleCompletionsResponse(callback));
368 });
369 }
370
371 if (message.capabilities.indexOf(WebInspector.LanguageService.Capabiliti es.DebuggerCompletions) !== -1) {
372 service.appendActionHandler(WebInspector.LanguageService.Capabilitie s.DebuggerCompletions, function(content, cursor, prefix, context, callback) {
373 _this._sendRequest(port, {
374 command: WebInspector.LanguageService.Capabilities.DebuggerC ompletions+"-"+message.name,
375 content: content,
376 cursor: cursor,
377 prefix: prefix,
378 context: context
379 }, handleCompletionsResponse(callback));
380 });
381 }
382
383 WebInspector.languageService.register(message.mimes, service);
384 },
385
386 _onNewMimeType: function(message)
387 {
388 if (typeof message.mime !== "string") {
389 return this._status.E_BADARGTYPE("mime", typeof message.mime, "strin g");
390 }
391 if (typeof message.extensionOrName !== "string") {
392 return this._status.E_BADARGTYPE("match", typeof message.match, "str ing");
393 }
394 WebInspector.ResourceType.newMimeType(message.extensionOrName, message.m ime, message.byName);
395 },
396
397 _onDisplaySearchResults: function(message)
398 {
399 //FIXME: Search result highlighting should allow ranges to be highlighte d rather than regexes
400 var results = message.results || [];
401
402 var groupedResults = results.reduce(function(accum, item) { //group by s ource
403 var elem;
404 for (var index = 0; index < accum.length; index++) {
405 var element = accum[index];
406 if (element.source === item.source) {
407 elem = element;
408 break;
409 }
410 }
411 if (!elem) {
412 elem = [];
413 elem.source = item.source;
414 accum.push(elem);
415 }
416 elem.push(new WebInspector.SearchResult(item.line, item.lineContent || ''));
417 return accum;
418 }, []);
419 WebInspector.Revealer.reveal(new WebInspector.SearchResultsCollection(re sults.highlight || '', groupedResults));
420 },
421
422 /**
423 * @param {*} message
424 * @param {!MessagePort} port
425 */
426 _onSetResourceLineMessages: function(message, port)
427 {
428 var url = /** @type {string} */ (message.url);
429 var messages = /** @type {?Array.<{kind: string, text: string, location: {startLine: number, startColumn: number, endLine: number, endColumn: number}}>} */ (message.messages);
430 if ((!messages) || typeof messages !== "object")
431 return this._status.E_BADARGTYPE("messages", typeof messages, "Array <LineMessage>");
432 var uiSourceCode = WebInspector.networkMapping.uiSourceCodeForURLForAnyT arget(url) || WebInspector.workspace.uiSourceCodeForFilePath(url);
433 if (!uiSourceCode)
434 return this._status.E_NOTFOUND(url);
435 WebInspector.Revealer.reveal(new WebInspector.UISourceCodeMessages(uiSou rceCode, messages.map(function(m) {
436 return new WebInspector.UISourceCodeMessage(m.text, m.kind, m.locati on);
437 })))
438 this._dispatchCallback(message.requestId, port, this._status.OK());
439 },
440
441 /**
442 * @param {*} message
250 * @suppressGlobalPropertiesCheck 443 * @suppressGlobalPropertiesCheck
251 */ 444 */
252 _onApplyStyleSheet: function(message) 445 _onApplyStyleSheet: function(message)
253 { 446 {
254 if (!Runtime.experiments.isEnabled("applyCustomStylesheet")) 447 if (!Runtime.experiments.isEnabled("applyCustomStylesheet"))
255 return; 448 return;
256 var styleSheet = createElement("style"); 449 var styleSheet = createElement("style");
257 styleSheet.textContent = message.styleSheet; 450 styleSheet.textContent = message.styleSheet;
258 document.head.appendChild(styleSheet); 451 document.head.appendChild(styleSheet);
259 }, 452 },
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
360 _onSetSidebarPage: function(message, port) 553 _onSetSidebarPage: function(message, port)
361 { 554 {
362 var sidebar = this._clientObjects[message.id]; 555 var sidebar = this._clientObjects[message.id];
363 if (!sidebar) 556 if (!sidebar)
364 return this._status.E_NOTFOUND(message.id); 557 return this._status.E_NOTFOUND(message.id);
365 sidebar.setPage(this._expandResourcePath(port._extensionOrigin, message. page)); 558 sidebar.setPage(this._expandResourcePath(port._extensionOrigin, message. page));
366 }, 559 },
367 560
368 _onOpenResource: function(message) 561 _onOpenResource: function(message)
369 { 562 {
370 var uiSourceCode = WebInspector.networkMapping.uiSourceCodeForURLForAnyT arget(message.url); 563 var uiSourceCode = WebInspector.networkMapping.uiSourceCodeForURLForAnyT arget(message.url) || WebInspector.workspace.uiSourceCodeForFilePath(message.url );
371 if (uiSourceCode) { 564 if (uiSourceCode) {
372 WebInspector.Revealer.reveal(uiSourceCode.uiLocation(message.lineNum ber, 0)); 565 WebInspector.Revealer.reveal(uiSourceCode.uiLocation(message.lineNum ber, 0));
373 return this._status.OK(); 566 return this._status.OK();
374 } 567 }
375 568
376 var resource = WebInspector.resourceForURL(message.url); 569 var resource = WebInspector.resourceForURL(message.url);
377 if (resource) { 570 if (resource) {
378 WebInspector.Revealer.reveal(resource, message.lineNumber); 571 WebInspector.Revealer.reveal(resource, message.lineNumber);
379 return this._status.OK(); 572 return this._status.OK();
380 } 573 }
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
482 /** 675 /**
483 * @this {WebInspector.ExtensionServer} 676 * @this {WebInspector.ExtensionServer}
484 */ 677 */
485 function pushResourceData(contentProvider) 678 function pushResourceData(contentProvider)
486 { 679 {
487 if (!resources[contentProvider.contentURL()]) 680 if (!resources[contentProvider.contentURL()])
488 resources[contentProvider.contentURL()] = this._makeResource(con tentProvider); 681 resources[contentProvider.contentURL()] = this._makeResource(con tentProvider);
489 } 682 }
490 var uiSourceCodes = WebInspector.workspace.uiSourceCodesForProjectType(W ebInspector.projectTypes.Network); 683 var uiSourceCodes = WebInspector.workspace.uiSourceCodesForProjectType(W ebInspector.projectTypes.Network);
491 uiSourceCodes = uiSourceCodes.concat(WebInspector.workspace.uiSourceCode sForProjectType(WebInspector.projectTypes.ContentScripts)); 684 uiSourceCodes = uiSourceCodes.concat(WebInspector.workspace.uiSourceCode sForProjectType(WebInspector.projectTypes.ContentScripts));
685 uiSourceCodes = uiSourceCodes.concat(WebInspector.workspace.uiSourceCode sForProjectType(WebInspector.projectTypes.FileSystem));
492 uiSourceCodes.forEach(pushResourceData.bind(this)); 686 uiSourceCodes.forEach(pushResourceData.bind(this));
493 for (var target of WebInspector.targetManager.targets()) 687 for (var target of WebInspector.targetManager.targets())
494 target.resourceTreeModel.forAllResources(pushResourceData.bind(this) ); 688 target.resourceTreeModel.forAllResources(pushResourceData.bind(this) );
495 return Object.values(resources); 689 return Object.values(resources);
496 }, 690 },
497 691
498 /** 692 /**
499 * @param {!WebInspector.ContentProvider} contentProvider 693 * @param {!WebInspector.ContentProvider} contentProvider
500 * @param {!Object} message 694 * @param {!Object} message
501 * @param {!MessagePort} port 695 * @param {!MessagePort} port
(...skipping 25 matching lines...) Expand all
527 { 721 {
528 var request = this._requestById(message.id); 722 var request = this._requestById(message.id);
529 if (!request) 723 if (!request)
530 return this._status.E_NOTFOUND(message.id); 724 return this._status.E_NOTFOUND(message.id);
531 this._getResourceContent(request, message, port); 725 this._getResourceContent(request, message, port);
532 }, 726 },
533 727
534 _onGetResourceContent: function(message, port) 728 _onGetResourceContent: function(message, port)
535 { 729 {
536 var url = /** @type {string} */ (message.url); 730 var url = /** @type {string} */ (message.url);
537 var contentProvider = WebInspector.workspace.uiSourceCodeForOriginURL(ur l) || WebInspector.resourceForURL(url); 731 var contentProvider = WebInspector.networkMapping.uiSourceCodeForURLForA nyTarget(url) || WebInspector.workspace.uiSourceCodeForFilePath(url);
538 if (!contentProvider) 732 if (!contentProvider)
539 return this._status.E_NOTFOUND(url); 733 return this._status.E_NOTFOUND(url);
540 this._getResourceContent(contentProvider, message, port); 734 this._getResourceContent(contentProvider, message, port);
541 }, 735 },
542 736
543 _onSetResourceContent: function(message, port) 737 _onSetResourceContent: function(message, port)
544 { 738 {
545 /** 739 /**
546 * @param {?Protocol.Error} error 740 * @param {?Protocol.Error} error
547 * @this {WebInspector.ExtensionServer} 741 * @this {WebInspector.ExtensionServer}
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
664 return keyCode || 0; 858 return keyCode || 0;
665 } 859 }
666 }, 860 },
667 861
668 _dispatchCallback: function(requestId, port, result) 862 _dispatchCallback: function(requestId, port, result)
669 { 863 {
670 if (requestId) 864 if (requestId)
671 port.postMessage({ command: "callback", requestId: requestId, result : result }); 865 port.postMessage({ command: "callback", requestId: requestId, result : result });
672 }, 866 },
673 867
868 _onCallback: function(request, target)
869 {
870 if (request.requestId in this._callbacks) {
871 var callback = this._callbacks[request.requestId];
872 delete this._callbacks[request.requestId];
873 callback(request.result);
874 }
875 },
876
674 _initExtensions: function() 877 _initExtensions: function()
675 { 878 {
676 this._registerAutosubscriptionHandler(WebInspector.extensionAPI.Events.R esourceAdded, 879 this._registerAutosubscriptionHandler(WebInspector.extensionAPI.Events.R esourceAdded,
677 WebInspector.workspace, WebInspector.Workspace.Events.UISourceCodeAd ded, this._notifyResourceAdded); 880 WebInspector.workspace, WebInspector.Workspace.Events.UISourceCodeAd ded, this._notifyResourceAdded);
678 this._registerAutosubscriptionTargetManagerHandler(WebInspector.extensio nAPI.Events.NetworkRequestFinished, 881 this._registerAutosubscriptionTargetManagerHandler(WebInspector.extensio nAPI.Events.NetworkRequestFinished,
679 WebInspector.NetworkManager, WebInspector.NetworkManager.EventTypes. RequestFinished, this._notifyRequestFinished); 882 WebInspector.NetworkManager, WebInspector.NetworkManager.EventTypes. RequestFinished, this._notifyRequestFinished);
680 883
681 /** 884 /**
682 * @this {WebInspector.ExtensionServer} 885 * @this {WebInspector.ExtensionServer}
683 */ 886 */
684 function onElementsSubscriptionStarted() 887 function onElementsSubscriptionStarted()
685 { 888 {
686 WebInspector.notifications.addEventListener(WebInspector.Notificatio nService.Events.SelectedNodeChanged, this._notifyElementsSelectionChanged, this) ; 889 WebInspector.notifications.addEventListener(WebInspector.Notificatio nService.Events.SelectedNodeChanged, this._notifyElementsSelectionChanged, this) ;
687 } 890 }
688 891
689 /** 892 /**
690 * @this {WebInspector.ExtensionServer} 893 * @this {WebInspector.ExtensionServer}
691 */ 894 */
692 function onElementsSubscriptionStopped() 895 function onElementsSubscriptionStopped()
693 { 896 {
694 WebInspector.notifications.removeEventListener(WebInspector.Notifica tionService.Events.SelectedNodeChanged, this._notifyElementsSelectionChanged, th is); 897 WebInspector.notifications.removeEventListener(WebInspector.Notifica tionService.Events.SelectedNodeChanged, this._notifyElementsSelectionChanged, th is);
695 } 898 }
696 899
697 this._registerSubscriptionHandler(WebInspector.extensionAPI.Events.Panel ObjectSelected + "elements", 900 this._registerSubscriptionHandler(WebInspector.extensionAPI.Events.Panel ObjectSelected + "elements",
698 onElementsSubscriptionStarted.bind(this), onElementsSubscriptionStop ped.bind(this)); 901 onElementsSubscriptionStarted.bind(this), onElementsSubscriptionStop ped.bind(this));
699 this._registerResourceContentCommittedHandler(this._notifyUISourceCodeCo ntentCommitted); 902 this._registerResourceContentCommittedHandler(this._notifyUISourceCodeCo ntentCommitted);
903 this._registerResourceContentEditedHandler(this._notifyUISourceCodeConte ntEdited);
700 904
701 WebInspector.targetManager.addEventListener(WebInspector.TargetManager.E vents.InspectedURLChanged, 905 WebInspector.targetManager.addEventListener(WebInspector.TargetManager.E vents.InspectedURLChanged,
702 this._inspectedURLChanged, this); 906 this._inspectedURLChanged, this);
703 907
704 InspectorExtensionRegistry.getExtensionsAsync(); 908 InspectorExtensionRegistry.getExtensionsAsync();
705 }, 909 },
706 910
707 _notifyResourceAdded: function(event) 911 _notifyResourceAdded: function(event)
708 { 912 {
709 var uiSourceCode = /** @type {!WebInspector.UISourceCode} */ (event.data ); 913 var uiSourceCode = /** @type {!WebInspector.UISourceCode} */ (event.data );
710 this._postNotification(WebInspector.extensionAPI.Events.ResourceAdded, t his._makeResource(uiSourceCode)); 914 this._postNotification(WebInspector.extensionAPI.Events.ResourceAdded, t his._makeResource(uiSourceCode));
711 }, 915 },
712 916
713 _notifyUISourceCodeContentCommitted: function(event) 917 _notifyUISourceCodeContentCommitted: function(event)
714 { 918 {
715 var uiSourceCode = /** @type {!WebInspector.UISourceCode} */ (event.data .uiSourceCode); 919 var uiSourceCode = /** @type {!WebInspector.UISourceCode} */ (event.data .uiSourceCode);
716 var content = /** @type {string} */ (event.data.content); 920 var content = /** @type {string} */ (event.data.content);
717 this._postNotification(WebInspector.extensionAPI.Events.ResourceContentC ommitted, this._makeResource(uiSourceCode), content); 921 this._postNotification(WebInspector.extensionAPI.Events.ResourceContentC ommitted, this._makeResource(uiSourceCode), content);
718 }, 922 },
719 923
924 _notifyUISourceCodeContentEdited: function(event)
925 {
926 var data = /** @type {{uiSourceCode: !WebInspector.UISourceCode, replace ment: string, range: !WebInspector.TextRange}} */ (event.data);
927 this._postNotification(WebInspector.extensionAPI.Events.ResourceContentE dited, this._makeResource(data.uiSourceCode), data.range, data.replacement);
928 },
929
720 _notifyRequestFinished: function(event) 930 _notifyRequestFinished: function(event)
721 { 931 {
722 var request = /** @type {!WebInspector.NetworkRequest} */ (event.data); 932 var request = /** @type {!WebInspector.NetworkRequest} */ (event.data);
723 this._postNotification(WebInspector.extensionAPI.Events.NetworkRequestFi nished, this._requestId(request), (new WebInspector.HAREntry(request)).build()); 933 this._postNotification(WebInspector.extensionAPI.Events.NetworkRequestFi nished, this._requestId(request), (new WebInspector.HAREntry(request)).build());
724 }, 934 },
725 935
726 _notifyElementsSelectionChanged: function() 936 _notifyElementsSelectionChanged: function()
727 { 937 {
728 this._postNotification(WebInspector.extensionAPI.Events.PanelObjectSelec ted + "elements"); 938 this._postNotification(WebInspector.extensionAPI.Events.PanelObjectSelec ted + "elements");
729 }, 939 },
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
872 { 1082 {
873 WebInspector.workspace.setHasResourceContentTrackingExtensions(false ); 1083 WebInspector.workspace.setHasResourceContentTrackingExtensions(false );
874 WebInspector.workspace.removeEventListener(WebInspector.Workspace.Ev ents.UISourceCodeContentCommitted, handler, this); 1084 WebInspector.workspace.removeEventListener(WebInspector.Workspace.Ev ents.UISourceCodeContentCommitted, handler, this);
875 } 1085 }
876 1086
877 this._registerSubscriptionHandler(WebInspector.extensionAPI.Events.Resou rceContentCommitted, 1087 this._registerSubscriptionHandler(WebInspector.extensionAPI.Events.Resou rceContentCommitted,
878 addFirstEventListener.bind(this), 1088 addFirstEventListener.bind(this),
879 removeLastEventListener.bind(this)); 1089 removeLastEventListener.bind(this));
880 }, 1090 },
881 1091
1092 _registerResourceContentEditedHandler: function(handler)
1093 {
1094 /**
1095 * @this {WebInspector.ExtensionServer}
1096 */
1097 function addFirstEventListener()
1098 {
1099 WebInspector.workspace.addEventListener(WebInspector.Workspace.Event s.UISourceCodeEdited, handler, this);
1100 }
1101
1102 /**
1103 * @this {WebInspector.ExtensionServer}
1104 */
1105 function removeLastEventListener()
1106 {
1107 WebInspector.workspace.removeEventListener(WebInspector.Workspace.Ev ents.UISourceCodeEdited, handler, this);
1108 }
1109
1110 this._registerSubscriptionHandler(WebInspector.extensionAPI.Events.Resou rceContentEdited,
1111 addFirstEventListener.bind(this),
1112 removeLastEventListener.bind(this));
1113 },
1114
882 _expandResourcePath: function(extensionPath, resourcePath) 1115 _expandResourcePath: function(extensionPath, resourcePath)
883 { 1116 {
884 if (!resourcePath) 1117 if (!resourcePath)
885 return; 1118 return;
886 return extensionPath + this._normalizePath(resourcePath); 1119 return extensionPath + this._normalizePath(resourcePath);
887 }, 1120 },
888 1121
889 _normalizePath: function(path) 1122 _normalizePath: function(path)
890 { 1123 {
891 var source = path.split("/"); 1124 var source = path.split("/");
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
1074 this.E_FAILED = makeStatus.bind(null, "E_FAILED", "Operation failed: %s"); 1307 this.E_FAILED = makeStatus.bind(null, "E_FAILED", "Operation failed: %s");
1075 } 1308 }
1076 1309
1077 /** 1310 /**
1078 * @typedef {{code: string, description: string, details: !Array.<*>}} 1311 * @typedef {{code: string, description: string, details: !Array.<*>}}
1079 */ 1312 */
1080 WebInspector.ExtensionStatus.Record; 1313 WebInspector.ExtensionStatus.Record;
1081 1314
1082 WebInspector.extensionAPI = {}; 1315 WebInspector.extensionAPI = {};
1083 defineCommonExtensionSymbols(WebInspector.extensionAPI); 1316 defineCommonExtensionSymbols(WebInspector.extensionAPI);
1317
1318 /**
1319 * @typedef {Array<{line: number, lineContent: string}>}
1320 * @property {string} source
1321 */
1322 var SearchResultArray;
1323
1324 /**
1325 * @interface
1326 */
1327 WebInspector.ExtensionServer.UIDelegate = function() {}
1328 WebInspector.ExtensionServer.UIDelegate.prototype = {
1329
1330 /**
1331 * @param {!Array<string>} mimes
1332 * @param {?} mode
1333 */
1334 addSimpleCodeMirrorMode: function(mimes, mode){}
1335 }
OLDNEW
« no previous file with comments | « Source/devtools/front_end/extensions/ExtensionAPI.js ('k') | Source/devtools/front_end/extensions/module.json » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698