| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2012 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 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 listeners[i].apply(null, arguments); | 168 listeners[i].apply(null, arguments); |
| 169 }, | 169 }, |
| 170 | 170 |
| 171 _dispatch: function(request) | 171 _dispatch: function(request) |
| 172 { | 172 { |
| 173 if (this._customDispatch) | 173 if (this._customDispatch) |
| 174 this._customDispatch.call(this, request); | 174 this._customDispatch.call(this, request); |
| 175 else | 175 else |
| 176 this._fire.apply(this, request.arguments); | 176 this._fire.apply(this, request.arguments); |
| 177 } | 177 } |
| 178 } | 178 }; |
| 179 | 179 |
| 180 /** | 180 /** |
| 181 * @constructor | 181 * @constructor |
| 182 */ | 182 */ |
| 183 function InspectorExtensionAPI() | 183 function InspectorExtensionAPI() |
| 184 { | 184 { |
| 185 this.audits = new Audits(); | 185 this.audits = new Audits(); |
| 186 this.inspectedWindow = new InspectedWindow(); | 186 this.inspectedWindow = new InspectedWindow(); |
| 187 this.panels = new Panels(); | 187 this.panels = new Panels(); |
| 188 this.network = new Network(); | 188 this.network = new Network(); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 221 } | 221 } |
| 222 callback(result); | 222 callback(result); |
| 223 } | 223 } |
| 224 extensionServer.sendRequest({ command: commands.GetHAR }, callback && ca
llbackWrapper); | 224 extensionServer.sendRequest({ command: commands.GetHAR }, callback && ca
llbackWrapper); |
| 225 }, | 225 }, |
| 226 | 226 |
| 227 addRequestHeaders: function(headers) | 227 addRequestHeaders: function(headers) |
| 228 { | 228 { |
| 229 extensionServer.sendRequest({ command: commands.AddRequestHeaders, heade
rs: headers, extensionId: window.location.hostname }); | 229 extensionServer.sendRequest({ command: commands.AddRequestHeaders, heade
rs: headers, extensionId: window.location.hostname }); |
| 230 } | 230 } |
| 231 } | 231 }; |
| 232 | 232 |
| 233 /** | 233 /** |
| 234 * @constructor | 234 * @constructor |
| 235 */ | 235 */ |
| 236 function RequestImpl(id) | 236 function RequestImpl(id) |
| 237 { | 237 { |
| 238 this._id = id; | 238 this._id = id; |
| 239 } | 239 } |
| 240 | 240 |
| 241 RequestImpl.prototype = { | 241 RequestImpl.prototype = { |
| 242 getContent: function(callback) | 242 getContent: function(callback) |
| 243 { | 243 { |
| 244 function callbackWrapper(response) | 244 function callbackWrapper(response) |
| 245 { | 245 { |
| 246 callback(response.content, response.encoding); | 246 callback(response.content, response.encoding); |
| 247 } | 247 } |
| 248 extensionServer.sendRequest({ command: commands.GetRequestContent, id: t
his._id }, callback && callbackWrapper); | 248 extensionServer.sendRequest({ command: commands.GetRequestContent, id: t
his._id }, callback && callbackWrapper); |
| 249 } | 249 } |
| 250 } | 250 }; |
| 251 | 251 |
| 252 /** | 252 /** |
| 253 * @constructor | 253 * @constructor |
| 254 */ | 254 */ |
| 255 function Panels() | 255 function Panels() |
| 256 { | 256 { |
| 257 var panels = { | 257 var panels = { |
| 258 elements: new ElementsPanel(), | 258 elements: new ElementsPanel(), |
| 259 sources: new SourcesPanel(), | 259 sources: new SourcesPanel(), |
| 260 }; | 260 }; |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 309 | 309 |
| 310 openResource: function(url, lineNumber, callback) | 310 openResource: function(url, lineNumber, callback) |
| 311 { | 311 { |
| 312 extensionServer.sendRequest({ command: commands.OpenResource, "url": url
, "lineNumber": lineNumber }, callback); | 312 extensionServer.sendRequest({ command: commands.OpenResource, "url": url
, "lineNumber": lineNumber }, callback); |
| 313 }, | 313 }, |
| 314 | 314 |
| 315 get SearchAction() | 315 get SearchAction() |
| 316 { | 316 { |
| 317 return apiPrivate.panels.SearchAction; | 317 return apiPrivate.panels.SearchAction; |
| 318 } | 318 } |
| 319 } | 319 }; |
| 320 | 320 |
| 321 /** | 321 /** |
| 322 * @constructor | 322 * @constructor |
| 323 */ | 323 */ |
| 324 function ExtensionViewImpl(id) | 324 function ExtensionViewImpl(id) |
| 325 { | 325 { |
| 326 this._id = id; | 326 this._id = id; |
| 327 | 327 |
| 328 /** | 328 /** |
| 329 * @this {EventSinkImpl} | 329 * @this {EventSinkImpl} |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 366 title: title | 366 title: title |
| 367 }; | 367 }; |
| 368 function callbackWrapper() | 368 function callbackWrapper() |
| 369 { | 369 { |
| 370 callback(new ExtensionSidebarPane(id)); | 370 callback(new ExtensionSidebarPane(id)); |
| 371 } | 371 } |
| 372 extensionServer.sendRequest(request, callback && callbackWrapper); | 372 extensionServer.sendRequest(request, callback && callbackWrapper); |
| 373 }, | 373 }, |
| 374 | 374 |
| 375 __proto__: ExtensionViewImpl.prototype | 375 __proto__: ExtensionViewImpl.prototype |
| 376 } | 376 }; |
| 377 | 377 |
| 378 function declareInterfaceClass(implConstructor) | 378 function declareInterfaceClass(implConstructor) |
| 379 { | 379 { |
| 380 return function() | 380 return function() |
| 381 { | 381 { |
| 382 var impl = { __proto__: implConstructor.prototype }; | 382 var impl = { __proto__: implConstructor.prototype }; |
| 383 implConstructor.apply(impl, arguments); | 383 implConstructor.apply(impl, arguments); |
| 384 populateInterfaceClass(this, impl); | 384 populateInterfaceClass(this, impl); |
| 385 }; | 385 }; |
| 386 } | 386 } |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 419 * @constructor | 419 * @constructor |
| 420 * @extends {PanelWithSidebar} | 420 * @extends {PanelWithSidebar} |
| 421 */ | 421 */ |
| 422 function ElementsPanel() | 422 function ElementsPanel() |
| 423 { | 423 { |
| 424 PanelWithSidebar.call(this, "elements"); | 424 PanelWithSidebar.call(this, "elements"); |
| 425 } | 425 } |
| 426 | 426 |
| 427 ElementsPanel.prototype = { | 427 ElementsPanel.prototype = { |
| 428 __proto__: PanelWithSidebar.prototype | 428 __proto__: PanelWithSidebar.prototype |
| 429 } | 429 }; |
| 430 | 430 |
| 431 /** | 431 /** |
| 432 * @constructor | 432 * @constructor |
| 433 * @extends {PanelWithSidebar} | 433 * @extends {PanelWithSidebar} |
| 434 */ | 434 */ |
| 435 function SourcesPanel() | 435 function SourcesPanel() |
| 436 { | 436 { |
| 437 PanelWithSidebar.call(this, "sources"); | 437 PanelWithSidebar.call(this, "sources"); |
| 438 } | 438 } |
| 439 | 439 |
| 440 SourcesPanel.prototype = { | 440 SourcesPanel.prototype = { |
| 441 __proto__: PanelWithSidebar.prototype | 441 __proto__: PanelWithSidebar.prototype |
| 442 } | 442 }; |
| 443 | 443 |
| 444 /** | 444 /** |
| 445 * @constructor | 445 * @constructor |
| 446 * @extends {ExtensionViewImpl} | 446 * @extends {ExtensionViewImpl} |
| 447 */ | 447 */ |
| 448 function ExtensionPanelImpl(id) | 448 function ExtensionPanelImpl(id) |
| 449 { | 449 { |
| 450 ExtensionViewImpl.call(this, id); | 450 ExtensionViewImpl.call(this, id); |
| 451 this.onSearch = new EventSink(events.PanelSearch + id); | 451 this.onSearch = new EventSink(events.PanelSearch + id); |
| 452 } | 452 } |
| (...skipping 23 matching lines...) Expand all Loading... |
| 476 return; | 476 return; |
| 477 | 477 |
| 478 var request = { | 478 var request = { |
| 479 command: commands.ShowPanel, | 479 command: commands.ShowPanel, |
| 480 id: this._id | 480 id: this._id |
| 481 }; | 481 }; |
| 482 extensionServer.sendRequest(request); | 482 extensionServer.sendRequest(request); |
| 483 }, | 483 }, |
| 484 | 484 |
| 485 __proto__: ExtensionViewImpl.prototype | 485 __proto__: ExtensionViewImpl.prototype |
| 486 } | 486 }; |
| 487 | 487 |
| 488 /** | 488 /** |
| 489 * @constructor | 489 * @constructor |
| 490 * @extends {ExtensionViewImpl} | 490 * @extends {ExtensionViewImpl} |
| 491 */ | 491 */ |
| 492 function ExtensionSidebarPaneImpl(id) | 492 function ExtensionSidebarPaneImpl(id) |
| 493 { | 493 { |
| 494 ExtensionViewImpl.call(this, id); | 494 ExtensionViewImpl.call(this, id); |
| 495 } | 495 } |
| 496 | 496 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 518 { | 518 { |
| 519 extensionServer.sendRequest({ command: commands.SetSidebarContent, id: t
his._id, expression: jsonObject, rootTitle: rootTitle }, callback); | 519 extensionServer.sendRequest({ command: commands.SetSidebarContent, id: t
his._id, expression: jsonObject, rootTitle: rootTitle }, callback); |
| 520 }, | 520 }, |
| 521 | 521 |
| 522 setPage: function(page) | 522 setPage: function(page) |
| 523 { | 523 { |
| 524 extensionServer.sendRequest({ command: commands.SetSidebarPage, id: this
._id, page: page }); | 524 extensionServer.sendRequest({ command: commands.SetSidebarPage, id: this
._id, page: page }); |
| 525 }, | 525 }, |
| 526 | 526 |
| 527 __proto__: ExtensionViewImpl.prototype | 527 __proto__: ExtensionViewImpl.prototype |
| 528 } | 528 }; |
| 529 | 529 |
| 530 /** | 530 /** |
| 531 * @constructor | 531 * @constructor |
| 532 */ | 532 */ |
| 533 function ButtonImpl(id) | 533 function ButtonImpl(id) |
| 534 { | 534 { |
| 535 this._id = id; | 535 this._id = id; |
| 536 this.onClicked = new EventSink(events.ButtonClicked + id); | 536 this.onClicked = new EventSink(events.ButtonClicked + id); |
| 537 } | 537 } |
| 538 | 538 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 562 * @param {string} categoryName | 562 * @param {string} categoryName |
| 563 * @param {string} categoryTooltip | 563 * @param {string} categoryTooltip |
| 564 * @return {!TraceProvider} | 564 * @return {!TraceProvider} |
| 565 */ | 565 */ |
| 566 addTraceProvider: function(categoryName, categoryTooltip) | 566 addTraceProvider: function(categoryName, categoryTooltip) |
| 567 { | 567 { |
| 568 var id = "extension-trace-provider-" + extensionServer.nextObjectId(); | 568 var id = "extension-trace-provider-" + extensionServer.nextObjectId(); |
| 569 extensionServer.sendRequest({ command: commands.AddTraceProvider, id: id
, categoryName: categoryName, categoryTooltip: categoryTooltip}); | 569 extensionServer.sendRequest({ command: commands.AddTraceProvider, id: id
, categoryName: categoryName, categoryTooltip: categoryTooltip}); |
| 570 return new TraceProvider(id); | 570 return new TraceProvider(id); |
| 571 } | 571 } |
| 572 } | 572 }; |
| 573 | 573 |
| 574 /** | 574 /** |
| 575 * @constructor | 575 * @constructor |
| 576 * @param {string} id | 576 * @param {string} id |
| 577 */ | 577 */ |
| 578 function TraceProvider(id) | 578 function TraceProvider(id) |
| 579 { | 579 { |
| 580 this.onRecordingStarted = new EventSink(events.RecordingStarted + id); | 580 this.onRecordingStarted = new EventSink(events.RecordingStarted + id); |
| 581 this.onRecordingStopped = new EventSink(events.RecordingStopped + id); | 581 this.onRecordingStopped = new EventSink(events.RecordingStopped + id); |
| 582 } | 582 } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 593 * @return {!AuditCategory} | 593 * @return {!AuditCategory} |
| 594 */ | 594 */ |
| 595 addCategory: function(displayName, resultCount) | 595 addCategory: function(displayName, resultCount) |
| 596 { | 596 { |
| 597 var id = "extension-audit-category-" + extensionServer.nextObjectId(); | 597 var id = "extension-audit-category-" + extensionServer.nextObjectId(); |
| 598 if (typeof resultCount !== "undefined") | 598 if (typeof resultCount !== "undefined") |
| 599 console.warn("Passing resultCount to audits.addCategory() is depreca
ted. Use AuditResult.updateProgress() instead."); | 599 console.warn("Passing resultCount to audits.addCategory() is depreca
ted. Use AuditResult.updateProgress() instead."); |
| 600 extensionServer.sendRequest({ command: commands.AddAuditCategory, id: id
, displayName: displayName, resultCount: resultCount }); | 600 extensionServer.sendRequest({ command: commands.AddAuditCategory, id: id
, displayName: displayName, resultCount: resultCount }); |
| 601 return new AuditCategory(id); | 601 return new AuditCategory(id); |
| 602 } | 602 } |
| 603 } | 603 }; |
| 604 | 604 |
| 605 /** | 605 /** |
| 606 * @constructor | 606 * @constructor |
| 607 */ | 607 */ |
| 608 function AuditCategoryImpl(id) | 608 function AuditCategoryImpl(id) |
| 609 { | 609 { |
| 610 /** | 610 /** |
| 611 * @this {EventSinkImpl} | 611 * @this {EventSinkImpl} |
| 612 */ | 612 */ |
| 613 function dispatchAuditEvent(request) | 613 function dispatchAuditEvent(request) |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 696 /** | 696 /** |
| 697 * @return {!{type: string, arguments: !Array.<string|number>}} | 697 * @return {!{type: string, arguments: !Array.<string|number>}} |
| 698 */ | 698 */ |
| 699 _nodeFactory: function(type) | 699 _nodeFactory: function(type) |
| 700 { | 700 { |
| 701 return { | 701 return { |
| 702 type: type, | 702 type: type, |
| 703 arguments: Array.prototype.slice.call(arguments, 1) | 703 arguments: Array.prototype.slice.call(arguments, 1) |
| 704 }; | 704 }; |
| 705 } | 705 } |
| 706 } | 706 }; |
| 707 | 707 |
| 708 /** | 708 /** |
| 709 * @constructor | 709 * @constructor |
| 710 */ | 710 */ |
| 711 function AuditResultNode(contents) | 711 function AuditResultNode(contents) |
| 712 { | 712 { |
| 713 this.contents = contents; | 713 this.contents = contents; |
| 714 this.children = []; | 714 this.children = []; |
| 715 this.expanded = false; | 715 this.expanded = false; |
| 716 } | 716 } |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 794 function wrapResource(resourceData) | 794 function wrapResource(resourceData) |
| 795 { | 795 { |
| 796 return new Resource(resourceData); | 796 return new Resource(resourceData); |
| 797 } | 797 } |
| 798 function callbackWrapper(resources) | 798 function callbackWrapper(resources) |
| 799 { | 799 { |
| 800 callback(resources.map(wrapResource)); | 800 callback(resources.map(wrapResource)); |
| 801 } | 801 } |
| 802 extensionServer.sendRequest({ command: commands.GetPageResources }, call
back && callbackWrapper); | 802 extensionServer.sendRequest({ command: commands.GetPageResources }, call
back && callbackWrapper); |
| 803 } | 803 } |
| 804 } | 804 }; |
| 805 | 805 |
| 806 /** | 806 /** |
| 807 * @constructor | 807 * @constructor |
| 808 */ | 808 */ |
| 809 function ResourceImpl(resourceData) | 809 function ResourceImpl(resourceData) |
| 810 { | 810 { |
| 811 this._url = resourceData.url; | 811 this._url = resourceData.url; |
| 812 this._type = resourceData.type; | 812 this._type = resourceData.type; |
| 813 } | 813 } |
| 814 | 814 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 830 callback(response.content, response.encoding); | 830 callback(response.content, response.encoding); |
| 831 } | 831 } |
| 832 | 832 |
| 833 extensionServer.sendRequest({ command: commands.GetResourceContent, url:
this._url }, callback && callbackWrapper); | 833 extensionServer.sendRequest({ command: commands.GetResourceContent, url:
this._url }, callback && callbackWrapper); |
| 834 }, | 834 }, |
| 835 | 835 |
| 836 setContent: function(content, commit, callback) | 836 setContent: function(content, commit, callback) |
| 837 { | 837 { |
| 838 extensionServer.sendRequest({ command: commands.SetResourceContent, url:
this._url, content: content, commit: commit }, callback); | 838 extensionServer.sendRequest({ command: commands.SetResourceContent, url:
this._url, content: content, commit: commit }, callback); |
| 839 } | 839 } |
| 840 } | 840 }; |
| 841 | 841 |
| 842 function getTabId() | 842 function getTabId() |
| 843 { | 843 { |
| 844 return inspectedTabId; | 844 return inspectedTabId; |
| 845 } | 845 } |
| 846 | 846 |
| 847 var keyboardEventRequestQueue = []; | 847 var keyboardEventRequestQueue = []; |
| 848 var forwardTimer = null; | 848 var forwardTimer = null; |
| 849 | 849 |
| 850 function forwardKeyboardEvent(event) | 850 function forwardKeyboardEvent(event) |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 956 } | 956 } |
| 957 }, | 957 }, |
| 958 | 958 |
| 959 _onMessage: function(event) | 959 _onMessage: function(event) |
| 960 { | 960 { |
| 961 var request = event.data; | 961 var request = event.data; |
| 962 var handler = this._handlers[request.command]; | 962 var handler = this._handlers[request.command]; |
| 963 if (handler) | 963 if (handler) |
| 964 handler.call(this, request); | 964 handler.call(this, request); |
| 965 } | 965 } |
| 966 } | 966 }; |
| 967 | 967 |
| 968 function populateInterfaceClass(interfaze, implementation) | 968 function populateInterfaceClass(interfaze, implementation) |
| 969 { | 969 { |
| 970 for (var member in implementation) { | 970 for (var member in implementation) { |
| 971 if (member.charAt(0) === "_") | 971 if (member.charAt(0) === "_") |
| 972 continue; | 972 continue; |
| 973 var descriptor = null; | 973 var descriptor = null; |
| 974 // Traverse prototype chain until we find the owner. | 974 // Traverse prototype chain until we find the owner. |
| 975 for (var owner = implementation; owner && !descriptor; owner = owner.__p
roto__) | 975 for (var owner = implementation; owner && !descriptor; owner = owner.__p
roto__) |
| 976 descriptor = Object.getOwnPropertyDescriptor(owner, member); | 976 descriptor = Object.getOwnPropertyDescriptor(owner, member); |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1033 function buildExtensionAPIInjectedScript(extensionInfo, inspectedTabId, themeNam
e, testHook) | 1033 function buildExtensionAPIInjectedScript(extensionInfo, inspectedTabId, themeNam
e, testHook) |
| 1034 { | 1034 { |
| 1035 var argumentsJSON = [extensionInfo, inspectedTabId || null, themeName].map(_
=> JSON.stringify(_)).join(","); | 1035 var argumentsJSON = [extensionInfo, inspectedTabId || null, themeName].map(_
=> JSON.stringify(_)).join(","); |
| 1036 if (!testHook) | 1036 if (!testHook) |
| 1037 testHook = () => {}; | 1037 testHook = () => {}; |
| 1038 return "(function(injectedScriptId){ " + | 1038 return "(function(injectedScriptId){ " + |
| 1039 defineCommonExtensionSymbols.toString() + ";" + | 1039 defineCommonExtensionSymbols.toString() + ";" + |
| 1040 "(" + injectedExtensionAPI.toString() + ")(" + argumentsJSON + "," + tes
tHook + ", injectedScriptId);" + | 1040 "(" + injectedExtensionAPI.toString() + ")(" + argumentsJSON + "," + tes
tHook + ", injectedScriptId);" + |
| 1041 "})"; | 1041 "})"; |
| 1042 } | 1042 } |
| OLD | NEW |