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

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: Modify override dropdown to apply to console completions & transpile 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.GetResourceLineMessages, this._onGetResourceL ineMessages.bind(this));
73 this._registerHandler(commands.RegisterLanguageService, this._onRegisterLang uageService.bind(this));
74 this._registerHandler(commands.RegisterMimeRecognizer, this._onRegisterMimeR ecognizer.bind(this));
68 this._registerHandler(commands.Reload, this._onReload.bind(this)); 75 this._registerHandler(commands.Reload, this._onReload.bind(this));
69 this._registerHandler(commands.SetOpenResourceHandler, this._onSetOpenResour ceHandler.bind(this)); 76 this._registerHandler(commands.SetOpenResourceHandler, this._onSetOpenResour ceHandler.bind(this));
70 this._registerHandler(commands.SetResourceContent, this._onSetResourceConten t.bind(this)); 77 this._registerHandler(commands.SetResourceContent, this._onSetResourceConten t.bind(this));
78 this._registerHandler(commands.SetResourceLineMessages, this._onSetResourceL ineMessages.bind(this));
71 this._registerHandler(commands.SetSidebarHeight, this._onSetSidebarHeight.bi nd(this)); 79 this._registerHandler(commands.SetSidebarHeight, this._onSetSidebarHeight.bi nd(this));
72 this._registerHandler(commands.SetSidebarContent, this._onSetSidebarContent. bind(this)); 80 this._registerHandler(commands.SetSidebarContent, this._onSetSidebarContent. bind(this));
73 this._registerHandler(commands.SetSidebarPage, this._onSetSidebarPage.bind(t his)); 81 this._registerHandler(commands.SetSidebarPage, this._onSetSidebarPage.bind(t his));
74 this._registerHandler(commands.ShowPanel, this._onShowPanel.bind(this)); 82 this._registerHandler(commands.ShowPanel, this._onShowPanel.bind(this));
75 this._registerHandler(commands.StopAuditCategoryRun, this._onStopAuditCatego ryRun.bind(this)); 83 this._registerHandler(commands.StopAuditCategoryRun, this._onStopAuditCatego ryRun.bind(this));
76 this._registerHandler(commands.Subscribe, this._onSubscribe.bind(this)); 84 this._registerHandler(commands.Subscribe, this._onSubscribe.bind(this));
77 this._registerHandler(commands.OpenResource, this._onOpenResource.bind(this) ); 85 this._registerHandler(commands.OpenResource, this._onOpenResource.bind(this) );
78 this._registerHandler(commands.Unsubscribe, this._onUnsubscribe.bind(this)); 86 this._registerHandler(commands.Unsubscribe, this._onUnsubscribe.bind(this));
79 this._registerHandler(commands.UpdateButton, this._onUpdateButton.bind(this) ); 87 this._registerHandler(commands.UpdateButton, this._onUpdateButton.bind(this) );
80 this._registerHandler(commands.UpdateAuditProgress, this._onUpdateAuditProgr ess.bind(this)); 88 this._registerHandler(commands.UpdateAuditProgress, this._onUpdateAuditProgr ess.bind(this));
89 this._registerHandler("callback", this._onCallback.bind(this));
81 window.addEventListener("message", this._onWindowMessage.bind(this), false); // Only for main window. 90 window.addEventListener("message", this._onWindowMessage.bind(this), false); // Only for main window.
82 91
83 InspectorFrontendHost.events.addEventListener(InspectorFrontendHostAPI.Event s.AddExtensions, this._addExtensions, this); 92 InspectorFrontendHost.events.addEventListener(InspectorFrontendHostAPI.Event s.AddExtensions, this._addExtensions, this);
84 InspectorFrontendHost.events.addEventListener(InspectorFrontendHostAPI.Event s.SetInspectedTabId, this._setInspectedTabId, this); 93 InspectorFrontendHost.events.addEventListener(InspectorFrontendHostAPI.Event s.SetInspectedTabId, this._setInspectedTabId, this);
85 94
86 this._initExtensions(); 95 this._initExtensions();
87 } 96 }
88 97
89 WebInspector.ExtensionServer.Events = { 98 WebInspector.ExtensionServer.Events = {
90 SidebarPaneAdded: "SidebarPaneAdded", 99 SidebarPaneAdded: "SidebarPaneAdded",
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 181
173 /** 182 /**
174 * @param {string} type 183 * @param {string} type
175 * @return {boolean} 184 * @return {boolean}
176 */ 185 */
177 hasSubscribers: function(type) 186 hasSubscribers: function(type)
178 { 187 {
179 return !!this._subscribers[type]; 188 return !!this._subscribers[type];
180 }, 189 },
181 190
191 _registerCallback: function(callback) {
192 var cbId = Math.random()*Number.MAX_VALUE;
193 if (this._callbacks[cbId]) {
194 return this._registerCallback(callback);
195 }
196 this._callbacks[cbId] = callback;
197 return cbId;
198 },
199
200 /**
201 * @param {!MessagePort} port
202 * @param {*} message
203 * @param {?Function=} callback
204 */
205 _sendRequest: function(port, message, callback) {
206 if (typeof callback === "function")
207 message.requestId = this._registerCallback(callback);
208 port.postMessage(message);
209 },
210
182 /** 211 /**
183 * @param {string} type 212 * @param {string} type
184 * @param {...*} vararg 213 * @param {...*} vararg
185 */ 214 */
186 _postNotification: function(type, vararg) 215 _postNotification: function(type, vararg)
187 { 216 {
188 var subscribers = this._subscribers[type]; 217 var subscribers = this._subscribers[type];
189 if (!subscribers) 218 if (!subscribers)
190 return; 219 return;
191 var message = { 220 var message = {
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 if (typeof headers[name] === "string") 269 if (typeof headers[name] === "string")
241 allHeaders[name] = headers[name]; 270 allHeaders[name] = headers[name];
242 } 271 }
243 } 272 }
244 273
245 WebInspector.multitargetNetworkManager.setExtraHTTPHeaders(allHeaders); 274 WebInspector.multitargetNetworkManager.setExtraHTTPHeaders(allHeaders);
246 }, 275 },
247 276
248 /** 277 /**
249 * @param {*} message 278 * @param {*} message
279 * @param {!MessagePort} port
280 */
281 _onRegisterLanguageService: function(message, port) {
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(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(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 _onRegisterMimeRecognizer: function(message) {
387 if (typeof message.mime !== "string") {
388 return this._status.E_BADARGTYPE("mime", typeof message.mime, "strin g");
389 }
390 if (typeof message.match !== "string") {
391 return this._status.E_BADARGTYPE("match", typeof message.match, "str ing");
392 }
393 WebInspector.ResourceType.registerMimeRecognizer(message.match, message. mime, message.matchName);
394 },
395
396 _onDisplaySearchResults: function(message) {
397 //FIXME: Search result highlighting should allow ranges to be highlighte d rather than regexes
398 var results = message.results || [];
399
400 var groupedResults = results.reduce(function(accum, item) { //group by s ource
401 var elem;
402 for (var index = 0; index < accum.length; index++) {
403 var element = accum[index];
404 if (element.source === item.source) {
405 elem = element;
406 break;
407 }
408 }
409 if (!elem) {
410 elem = [];
411 elem.source = item.source;
412 accum.push(elem);
413 }
414 elem.push({
415 line: item.line,
416 lineContent: item.lineContent || '',
417 startColumn: item.startColumn || 0,
418 endColumn: item.endColumn || 0
419 });
420 return accum;
421 }, []);
422 this._delegate.displaySearchResults(results.highlight || '', groupedResu lts);
423 },
424
425 /**
426 * @param {*} message
427 * @param {!MessagePort} port
428 */
429 _onGetResourceLineMessages: function(message, port) {
430 var url = /** @type {string} */ (message.url);
431 var uiSourceCode = WebInspector.networkMapping.uiSourceCodeFromURL(url);
432 if (!uiSourceCode)
433 return this._status.E_NOTFOUND(url);
434
435 this._delegate.getResourceLineMessages(uiSourceCode).then(arr => {
436 var result = arr.map(m => {
437 return {
438 text: m.messageText(),
439 kind: m.level(),
440 location: {
441 startLine: m.start().line,
442 startColumn: m.start().column,
443 endLine: m.end().line,
444 endColumn: m.end().column
445 }
446 };
447 });
448 this._dispatchCallback(message.requestId, port, result);
449 });
450 },
451
452 /**
453 * @param {*} message
454 * @param {!MessagePort} port
455 */
456 _onSetResourceLineMessages: function(message, port) {
457 var url = /** @type {string} */ (message.url);
458 var messages = /** @type {?Array.<{kind: string, text: string, location: {startLine: number, startColumn: number, endLine: number, endColumn: number}}>} */ (message.messages);
459 if ((!messages) || typeof messages !== "object")
460 return this._status.E_BADARGTYPE("messages", typeof messages, "Array <LineMessage>");
461 var uiSourceCode = WebInspector.networkMapping.uiSourceCodeFromURL(url);
462 if (!uiSourceCode)
463 return this._status.E_NOTFOUND(url);
464 this._delegate.setResourceLineMessages(uiSourceCode, messages);
465 this._dispatchCallback(message.requestId, port, this._status.OK());
466 },
467
468 /**
469 * @param {*} message
250 * @suppressGlobalPropertiesCheck 470 * @suppressGlobalPropertiesCheck
251 */ 471 */
252 _onApplyStyleSheet: function(message) 472 _onApplyStyleSheet: function(message)
253 { 473 {
254 if (!Runtime.experiments.isEnabled("applyCustomStylesheet")) 474 if (!Runtime.experiments.isEnabled("applyCustomStylesheet"))
255 return; 475 return;
256 var styleSheet = createElement("style"); 476 var styleSheet = createElement("style");
257 styleSheet.textContent = message.styleSheet; 477 styleSheet.textContent = message.styleSheet;
258 document.head.appendChild(styleSheet); 478 document.head.appendChild(styleSheet);
259 }, 479 },
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
360 _onSetSidebarPage: function(message, port) 580 _onSetSidebarPage: function(message, port)
361 { 581 {
362 var sidebar = this._clientObjects[message.id]; 582 var sidebar = this._clientObjects[message.id];
363 if (!sidebar) 583 if (!sidebar)
364 return this._status.E_NOTFOUND(message.id); 584 return this._status.E_NOTFOUND(message.id);
365 sidebar.setPage(this._expandResourcePath(port._extensionOrigin, message. page)); 585 sidebar.setPage(this._expandResourcePath(port._extensionOrigin, message. page));
366 }, 586 },
367 587
368 _onOpenResource: function(message) 588 _onOpenResource: function(message)
369 { 589 {
370 var uiSourceCode = WebInspector.networkMapping.uiSourceCodeForURLForAnyT arget(message.url); 590 var uiSourceCode = WebInspector.networkMapping.uiSourceCodeForURLForAnyT arget(message.url) || WebInspector.workspace.uiSourceCodeForFilePath(message.url );
wes 2015/08/14 01:13:32 Upon review, I see that this line is an alias to t
pfeldman 2015/08/17 21:15:51 Your message has a target, so you should get resou
wes 2015/08/25 18:13:18 The open resource message only has a url and a lin
371 if (uiSourceCode) { 591 if (uiSourceCode) {
372 WebInspector.Revealer.reveal(uiSourceCode.uiLocation(message.lineNum ber, 0)); 592 WebInspector.Revealer.reveal(uiSourceCode.uiLocation(message.lineNum ber, 0));
373 return this._status.OK(); 593 return this._status.OK();
374 } 594 }
375 595
376 var resource = WebInspector.resourceForURL(message.url); 596 var resource = WebInspector.resourceForURL(message.url);
377 if (resource) { 597 if (resource) {
378 WebInspector.Revealer.reveal(resource, message.lineNumber); 598 WebInspector.Revealer.reveal(resource, message.lineNumber);
379 return this._status.OK(); 599 return this._status.OK();
380 } 600 }
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
482 /** 702 /**
483 * @this {WebInspector.ExtensionServer} 703 * @this {WebInspector.ExtensionServer}
484 */ 704 */
485 function pushResourceData(contentProvider) 705 function pushResourceData(contentProvider)
486 { 706 {
487 if (!resources[contentProvider.contentURL()]) 707 if (!resources[contentProvider.contentURL()])
488 resources[contentProvider.contentURL()] = this._makeResource(con tentProvider); 708 resources[contentProvider.contentURL()] = this._makeResource(con tentProvider);
489 } 709 }
490 var uiSourceCodes = WebInspector.workspace.uiSourceCodesForProjectType(W ebInspector.projectTypes.Network); 710 var uiSourceCodes = WebInspector.workspace.uiSourceCodesForProjectType(W ebInspector.projectTypes.Network);
491 uiSourceCodes = uiSourceCodes.concat(WebInspector.workspace.uiSourceCode sForProjectType(WebInspector.projectTypes.ContentScripts)); 711 uiSourceCodes = uiSourceCodes.concat(WebInspector.workspace.uiSourceCode sForProjectType(WebInspector.projectTypes.ContentScripts));
712 uiSourceCodes = uiSourceCodes.concat(WebInspector.workspace.uiSourceCode sForProjectType(WebInspector.projectTypes.FileSystem));
492 uiSourceCodes.forEach(pushResourceData.bind(this)); 713 uiSourceCodes.forEach(pushResourceData.bind(this));
493 for (var target of WebInspector.targetManager.targets()) 714 for (var target of WebInspector.targetManager.targets())
494 target.resourceTreeModel.forAllResources(pushResourceData.bind(this) ); 715 target.resourceTreeModel.forAllResources(pushResourceData.bind(this) );
495 return Object.values(resources); 716 return Object.values(resources);
496 }, 717 },
497 718
498 /** 719 /**
499 * @param {!WebInspector.ContentProvider} contentProvider 720 * @param {!WebInspector.ContentProvider} contentProvider
500 * @param {!Object} message 721 * @param {!Object} message
501 * @param {!MessagePort} port 722 * @param {!MessagePort} port
(...skipping 25 matching lines...) Expand all
527 { 748 {
528 var request = this._requestById(message.id); 749 var request = this._requestById(message.id);
529 if (!request) 750 if (!request)
530 return this._status.E_NOTFOUND(message.id); 751 return this._status.E_NOTFOUND(message.id);
531 this._getResourceContent(request, message, port); 752 this._getResourceContent(request, message, port);
532 }, 753 },
533 754
534 _onGetResourceContent: function(message, port) 755 _onGetResourceContent: function(message, port)
535 { 756 {
536 var url = /** @type {string} */ (message.url); 757 var url = /** @type {string} */ (message.url);
537 var contentProvider = WebInspector.workspace.uiSourceCodeForOriginURL(ur l) || WebInspector.resourceForURL(url); 758 var contentProvider = WebInspector.networkMapping.uiSourceCodeFromURL(ur l);
538 if (!contentProvider) 759 if (!contentProvider)
539 return this._status.E_NOTFOUND(url); 760 return this._status.E_NOTFOUND(url);
540 this._getResourceContent(contentProvider, message, port); 761 this._getResourceContent(contentProvider, message, port);
541 }, 762 },
542 763
543 _onSetResourceContent: function(message, port) 764 _onSetResourceContent: function(message, port)
544 { 765 {
545 /** 766 /**
546 * @param {?Protocol.Error} error 767 * @param {?Protocol.Error} error
547 * @this {WebInspector.ExtensionServer} 768 * @this {WebInspector.ExtensionServer}
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
664 return keyCode || 0; 885 return keyCode || 0;
665 } 886 }
666 }, 887 },
667 888
668 _dispatchCallback: function(requestId, port, result) 889 _dispatchCallback: function(requestId, port, result)
669 { 890 {
670 if (requestId) 891 if (requestId)
671 port.postMessage({ command: "callback", requestId: requestId, result : result }); 892 port.postMessage({ command: "callback", requestId: requestId, result : result });
672 }, 893 },
673 894
895 _onCallback: function(request, target)
896 {
897 if (request.requestId in this._callbacks) {
898 var callback = this._callbacks[request.requestId];
899 delete this._callbacks[request.requestId];
900 callback(request.result);
901 }
902 },
903
674 _initExtensions: function() 904 _initExtensions: function()
675 { 905 {
676 this._registerAutosubscriptionHandler(WebInspector.extensionAPI.Events.R esourceAdded, 906 this._registerAutosubscriptionHandler(WebInspector.extensionAPI.Events.R esourceAdded,
677 WebInspector.workspace, WebInspector.Workspace.Events.UISourceCodeAd ded, this._notifyResourceAdded); 907 WebInspector.workspace, WebInspector.Workspace.Events.UISourceCodeAd ded, this._notifyResourceAdded);
678 this._registerAutosubscriptionTargetManagerHandler(WebInspector.extensio nAPI.Events.NetworkRequestFinished, 908 this._registerAutosubscriptionTargetManagerHandler(WebInspector.extensio nAPI.Events.NetworkRequestFinished,
679 WebInspector.NetworkManager, WebInspector.NetworkManager.EventTypes. RequestFinished, this._notifyRequestFinished); 909 WebInspector.NetworkManager, WebInspector.NetworkManager.EventTypes. RequestFinished, this._notifyRequestFinished);
680 910
681 /** 911 /**
682 * @this {WebInspector.ExtensionServer} 912 * @this {WebInspector.ExtensionServer}
683 */ 913 */
684 function onElementsSubscriptionStarted() 914 function onElementsSubscriptionStarted()
685 { 915 {
686 WebInspector.notifications.addEventListener(WebInspector.Notificatio nService.Events.SelectedNodeChanged, this._notifyElementsSelectionChanged, this) ; 916 WebInspector.notifications.addEventListener(WebInspector.Notificatio nService.Events.SelectedNodeChanged, this._notifyElementsSelectionChanged, this) ;
687 } 917 }
688 918
689 /** 919 /**
690 * @this {WebInspector.ExtensionServer} 920 * @this {WebInspector.ExtensionServer}
691 */ 921 */
692 function onElementsSubscriptionStopped() 922 function onElementsSubscriptionStopped()
693 { 923 {
694 WebInspector.notifications.removeEventListener(WebInspector.Notifica tionService.Events.SelectedNodeChanged, this._notifyElementsSelectionChanged, th is); 924 WebInspector.notifications.removeEventListener(WebInspector.Notifica tionService.Events.SelectedNodeChanged, this._notifyElementsSelectionChanged, th is);
695 } 925 }
696 926
697 this._registerSubscriptionHandler(WebInspector.extensionAPI.Events.Panel ObjectSelected + "elements", 927 this._registerSubscriptionHandler(WebInspector.extensionAPI.Events.Panel ObjectSelected + "elements",
698 onElementsSubscriptionStarted.bind(this), onElementsSubscriptionStop ped.bind(this)); 928 onElementsSubscriptionStarted.bind(this), onElementsSubscriptionStop ped.bind(this));
699 this._registerResourceContentCommittedHandler(this._notifyUISourceCodeCo ntentCommitted); 929 this._registerResourceContentCommittedHandler(this._notifyUISourceCodeCo ntentCommitted);
930 this._registerResourceContentEditedHandler(this._notifyUISourceCodeConte ntEdited);
700 931
701 WebInspector.targetManager.addEventListener(WebInspector.TargetManager.E vents.InspectedURLChanged, 932 WebInspector.targetManager.addEventListener(WebInspector.TargetManager.E vents.InspectedURLChanged,
702 this._inspectedURLChanged, this); 933 this._inspectedURLChanged, this);
703 934
704 InspectorExtensionRegistry.getExtensionsAsync(); 935 InspectorExtensionRegistry.getExtensionsAsync();
705 }, 936 },
706 937
707 _notifyResourceAdded: function(event) 938 _notifyResourceAdded: function(event)
708 { 939 {
709 var uiSourceCode = /** @type {!WebInspector.UISourceCode} */ (event.data ); 940 var uiSourceCode = /** @type {!WebInspector.UISourceCode} */ (event.data );
710 this._postNotification(WebInspector.extensionAPI.Events.ResourceAdded, t his._makeResource(uiSourceCode)); 941 this._postNotification(WebInspector.extensionAPI.Events.ResourceAdded, t his._makeResource(uiSourceCode));
711 }, 942 },
712 943
713 _notifyUISourceCodeContentCommitted: function(event) 944 _notifyUISourceCodeContentCommitted: function(event)
714 { 945 {
715 var uiSourceCode = /** @type {!WebInspector.UISourceCode} */ (event.data .uiSourceCode); 946 var uiSourceCode = /** @type {!WebInspector.UISourceCode} */ (event.data .uiSourceCode);
716 var content = /** @type {string} */ (event.data.content); 947 var content = /** @type {string} */ (event.data.content);
717 this._postNotification(WebInspector.extensionAPI.Events.ResourceContentC ommitted, this._makeResource(uiSourceCode), content); 948 this._postNotification(WebInspector.extensionAPI.Events.ResourceContentC ommitted, this._makeResource(uiSourceCode), content);
718 }, 949 },
719 950
951 _notifyUISourceCodeContentEdited: function(event)
952 {
953 var data = /** @type {{uiSourceCode: !WebInspector.UISourceCode, replace ment: string, range: !WebInspector.TextRange}} */ (event.data);
954 this._postNotification(WebInspector.extensionAPI.Events.ResourceContentE dited, this._makeResource(data.uiSourceCode), data.range, data.replacement);
955 },
956
720 _notifyRequestFinished: function(event) 957 _notifyRequestFinished: function(event)
721 { 958 {
722 var request = /** @type {!WebInspector.NetworkRequest} */ (event.data); 959 var request = /** @type {!WebInspector.NetworkRequest} */ (event.data);
723 this._postNotification(WebInspector.extensionAPI.Events.NetworkRequestFi nished, this._requestId(request), (new WebInspector.HAREntry(request)).build()); 960 this._postNotification(WebInspector.extensionAPI.Events.NetworkRequestFi nished, this._requestId(request), (new WebInspector.HAREntry(request)).build());
724 }, 961 },
725 962
726 _notifyElementsSelectionChanged: function() 963 _notifyElementsSelectionChanged: function()
727 { 964 {
728 this._postNotification(WebInspector.extensionAPI.Events.PanelObjectSelec ted + "elements"); 965 this._postNotification(WebInspector.extensionAPI.Events.PanelObjectSelec ted + "elements");
729 }, 966 },
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
872 { 1109 {
873 WebInspector.workspace.setHasResourceContentTrackingExtensions(false ); 1110 WebInspector.workspace.setHasResourceContentTrackingExtensions(false );
874 WebInspector.workspace.removeEventListener(WebInspector.Workspace.Ev ents.UISourceCodeContentCommitted, handler, this); 1111 WebInspector.workspace.removeEventListener(WebInspector.Workspace.Ev ents.UISourceCodeContentCommitted, handler, this);
875 } 1112 }
876 1113
877 this._registerSubscriptionHandler(WebInspector.extensionAPI.Events.Resou rceContentCommitted, 1114 this._registerSubscriptionHandler(WebInspector.extensionAPI.Events.Resou rceContentCommitted,
878 addFirstEventListener.bind(this), 1115 addFirstEventListener.bind(this),
879 removeLastEventListener.bind(this)); 1116 removeLastEventListener.bind(this));
880 }, 1117 },
881 1118
1119 _registerResourceContentEditedHandler: function(handler)
1120 {
1121 /**
1122 * @this {WebInspector.ExtensionServer}
1123 */
1124 function addFirstEventListener()
1125 {
1126 WebInspector.workspace.addEventListener(WebInspector.Workspace.Event s.UISourceCodeEdited, handler, this);
1127 }
1128
1129 /**
1130 * @this {WebInspector.ExtensionServer}
1131 */
1132 function removeLastEventListener()
1133 {
1134 WebInspector.workspace.removeEventListener(WebInspector.Workspace.Ev ents.UISourceCodeEdited, handler, this);
1135 }
1136
1137 this._registerSubscriptionHandler(WebInspector.extensionAPI.Events.Resou rceContentEdited,
1138 addFirstEventListener.bind(this),
1139 removeLastEventListener.bind(this));
1140 },
1141
882 _expandResourcePath: function(extensionPath, resourcePath) 1142 _expandResourcePath: function(extensionPath, resourcePath)
883 { 1143 {
884 if (!resourcePath) 1144 if (!resourcePath)
885 return; 1145 return;
886 return extensionPath + this._normalizePath(resourcePath); 1146 return extensionPath + this._normalizePath(resourcePath);
887 }, 1147 },
888 1148
889 _normalizePath: function(path) 1149 _normalizePath: function(path)
890 { 1150 {
891 var source = path.split("/"); 1151 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"); 1334 this.E_FAILED = makeStatus.bind(null, "E_FAILED", "Operation failed: %s");
1075 } 1335 }
1076 1336
1077 /** 1337 /**
1078 * @typedef {{code: string, description: string, details: !Array.<*>}} 1338 * @typedef {{code: string, description: string, details: !Array.<*>}}
1079 */ 1339 */
1080 WebInspector.ExtensionStatus.Record; 1340 WebInspector.ExtensionStatus.Record;
1081 1341
1082 WebInspector.extensionAPI = {}; 1342 WebInspector.extensionAPI = {};
1083 defineCommonExtensionSymbols(WebInspector.extensionAPI); 1343 defineCommonExtensionSymbols(WebInspector.extensionAPI);
1344
1345 /**
1346 * @typedef {Array<{line: number, lineContent: string}>}
1347 * @property {string} source
1348 */
1349 var SearchResultArray;
1350
1351 /**
1352 * @typedef {!Array<{messageText: function(): string, level: function(): string, start: function(): {line: number, column: number}, end: function(): {line: numb er, column: number}}>}
1353 */
1354 var SourceFrameMessageGetter;
1355
1356 /**
1357 * @interface
1358 */
1359 WebInspector.ExtensionServer.UIDelegate = function() {}
1360 WebInspector.ExtensionServer.UIDelegate.prototype = {
1361 /**
1362 * @param {!WebInspector.UISourceCode} code
1363 * @param {!Array<{kind: string, text: string, location: {startLine: number, startColumn: number, endLine: number, endColumn: number}}>} messages
1364 */
1365 setResourceLineMessages: function(code, messages) {},
1366
1367 /**
1368 * @param {!WebInspector.UISourceCode} code
1369 * @return {!Promise<!SourceFrameMessageGetter>}
1370 */
1371 getResourceLineMessages: function(code) { return Promise.reject(); },
1372
1373 /**
1374 * @param {string} highlightText
1375 * @param {!Array<!SearchResultArray>} groupedResults
1376 */
1377 displaySearchResults: function(highlightText, groupedResults) {},
1378
1379 /**
1380 * @param {!Array<string>} mimes
1381 * @param {?} mode
1382 */
1383 addSimpleCodeMirrorMode: function(mimes, mode){}
1384 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698