Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2012 Google Inc. All rights reserved. |
| 3 | * |
| 4 | * Redistribution and use in source and binary forms, with or without |
| 5 | * modification, are permitted provided that the following conditions are |
| 6 | * met: |
| 7 | * |
| 8 | * * Redistributions of source code must retain the above copyright |
| 9 | * notice, this list of conditions and the following disclaimer. |
| 10 | * * Redistributions in binary form must reproduce the above |
| 11 | * copyright notice, this list of conditions and the following disclaimer |
| 12 | * in the documentation and/or other materials provided with the |
| 13 | * distribution. |
| 14 | * * Neither the name of Google Inc. nor the names of its |
| 15 | * contributors may be used to endorse or promote products derived from |
| 16 | * this software without specific prior written permission. |
| 17 | * |
| 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 22 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 23 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 24 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 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. |
| 29 | */ |
| 30 | |
Philip Pfaffe | 7523faf | 2021-06-28 14:23:14 | [diff] [blame^] | 31 | import type * as PublicAPI from '../../../extension-api/ExtensionAPI'; // eslint-disable-line rulesdir/es_modules_import |
| 32 | |
| 33 | /* eslint-disable @typescript-eslint/no-explicit-any,@typescript-eslint/naming-convention,@typescript-eslint/no-non-null-assertion */ |
Philip Pfaffe | 939605d | 2021-06-25 12:20:04 | [diff] [blame] | 34 | export namespace PrivateAPI { |
| 35 | export namespace Panels { |
| 36 | export const enum SearchAction { |
| 37 | CancelSearch = 'cancelSearch', |
| 38 | PerformSearch = 'performSearch', |
| 39 | NextSearchResult = 'nextSearchResult', |
| 40 | PreviousSearchResult = 'previousSearchResult', |
| 41 | } |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 42 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 43 | |
Philip Pfaffe | 939605d | 2021-06-25 12:20:04 | [diff] [blame] | 44 | export const enum Events { |
| 45 | ButtonClicked = 'button-clicked-', |
| 46 | PanelObjectSelected = 'panel-objectSelected-', |
| 47 | InspectedURLChanged = 'inspected-url-changed', |
| 48 | NetworkRequestFinished = 'network-request-finished', |
| 49 | OpenResource = 'open-resource', |
| 50 | PanelSearch = 'panel-search-', |
| 51 | RecordingStarted = 'trace-recording-started-', |
| 52 | RecordingStopped = 'trace-recording-stopped-', |
| 53 | ResourceAdded = 'resource-added', |
| 54 | ResourceContentCommitted = 'resource-content-committed', |
| 55 | ViewShown = 'view-shown-', |
| 56 | ViewHidden = 'view-hidden,', |
| 57 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 58 | |
Philip Pfaffe | 939605d | 2021-06-25 12:20:04 | [diff] [blame] | 59 | export const enum Commands { |
| 60 | AddRequestHeaders = 'addRequestHeaders', |
| 61 | AddTraceProvider = 'addTraceProvider', |
| 62 | ApplyStyleSheet = 'applyStyleSheet', |
| 63 | CompleteTraceSession = 'completeTra.eSession', |
| 64 | CreatePanel = 'createPanel', |
| 65 | CreateSidebarPane = 'createSidebarPane', |
| 66 | CreateToolbarButton = 'createToolbarButton', |
| 67 | EvaluateOnInspectedPage = 'evaluateOnInspectedPage', |
| 68 | ForwardKeyboardEvent = '_forwardKeyboardEvent', |
| 69 | GetHAR = 'getHAR', |
| 70 | GetPageResources = 'getPageResources', |
| 71 | GetRequestContent = 'getRequestContent', |
| 72 | GetResourceContent = 'getResourceContent', |
| 73 | OpenResource = 'openResource', |
| 74 | Reload = 'Reload', |
| 75 | Subscribe = 'subscribe', |
| 76 | SetOpenResourceHandler = 'setOpenResourceHandler', |
| 77 | SetResourceContent = 'setResourceContent', |
| 78 | SetSidebarContent = 'setSidebarContent', |
| 79 | SetSidebarHeight = 'setSidebarHeight', |
| 80 | SetSidebarPage = 'setSidebarPage', |
| 81 | ShowPanel = 'showPanel', |
| 82 | Unsubscribe = 'unsubscribe', |
| 83 | UpdateButton = 'updateButton', |
| 84 | RegisterLanguageExtensionPlugin = 'registerLanguageExtensionPlugin', |
| 85 | } |
Philip Pfaffe | edad832 | 2020-07-20 10:24:25 | [diff] [blame] | 86 | |
Philip Pfaffe | 939605d | 2021-06-25 12:20:04 | [diff] [blame] | 87 | export const enum LanguageExtensionPluginCommands { |
| 88 | AddRawModule = 'addRawModule', |
| 89 | RemoveRawModule = 'removeRawModule', |
| 90 | SourceLocationToRawLocation = 'sourceLocationToRawLocation', |
| 91 | RawLocationToSourceLocation = 'rawLocationToSourceLocation', |
| 92 | GetScopeInfo = 'getScopeInfo', |
| 93 | ListVariablesInScope = 'listVariablesInScope', |
| 94 | GetTypeInfo = 'getTypeInfo', |
| 95 | GetFormatter = 'getFormatter', |
| 96 | GetInspectableAddress = 'getInspectableAddress', |
| 97 | GetFunctionInfo = 'getFunctionInfo', |
| 98 | GetInlinedFunctionRanges = 'getInlinedFunctionRanges', |
| 99 | GetInlinedCalleesRanges = 'getInlinedCalleesRanges', |
| 100 | GetMappedLines = 'getMappedLines', |
| 101 | } |
Benedikt Meurer | 929fc7c | 2020-11-20 14:21:06 | [diff] [blame] | 102 | |
Philip Pfaffe | 939605d | 2021-06-25 12:20:04 | [diff] [blame] | 103 | export const enum LanguageExtensionPluginEvents { |
| 104 | UnregisteredLanguageExtensionPlugin = 'unregisteredLanguageExtensionPlugin', |
| 105 | } |
Philip Pfaffe | d662bdf | 2021-06-25 13:30:32 | [diff] [blame] | 106 | |
| 107 | export interface EvaluateOptions { |
| 108 | frameURL?: string; |
| 109 | useContentScriptContext?: boolean; |
| 110 | scriptExecutionContext?: string; |
| 111 | } |
| 112 | |
Philip Pfaffe | d662bdf | 2021-06-25 13:30:32 | [diff] [blame] | 113 | type RegisterLanguageExtensionPluginRequest = { |
| 114 | command: Commands.RegisterLanguageExtensionPlugin, |
| 115 | pluginName: string, |
| 116 | port: MessagePort, |
Philip Pfaffe | 7523faf | 2021-06-28 14:23:14 | [diff] [blame^] | 117 | supportedScriptTypes: PublicAPI.Chrome.DevTools.SupportedScriptTypes, |
Philip Pfaffe | d662bdf | 2021-06-25 13:30:32 | [diff] [blame] | 118 | }; |
| 119 | type SubscribeRequest = {command: Commands.Subscribe, type: string}; |
| 120 | type UnsubscribeRequest = {command: Commands.Unsubscribe, type: string}; |
| 121 | type AddRequestHeadersRequest = { |
| 122 | command: Commands.AddRequestHeaders, |
| 123 | extensionId: string, |
| 124 | headers: {[key: string]: string}, |
| 125 | }; |
| 126 | type ApplyStyleSheetRequest = {command: Commands.ApplyStyleSheet, styleSheet: string}; |
| 127 | type CreatePanelRequest = {command: Commands.CreatePanel, id: string, title: string, page: string}; |
| 128 | type ShowPanelRequest = {command: Commands.ShowPanel, id: string}; |
| 129 | type CreateToolbarButtonRequest = { |
| 130 | command: Commands.CreateToolbarButton, |
| 131 | id: string, |
| 132 | icon: string, |
| 133 | panel: string, |
| 134 | tooltip?: string, |
| 135 | disabled?: boolean, |
| 136 | }; |
| 137 | type UpdateButtonRequest = |
| 138 | {command: Commands.UpdateButton, id: string, icon?: string, tooltip?: string, disabled?: boolean}; |
| 139 | type CompleteTraceSessionRequest = |
| 140 | {command: Commands.CompleteTraceSession, id: string, url: string, timeOffset: number}; |
| 141 | type CreateSidebarPaneRequest = {command: Commands.CreateSidebarPane, id: string, panel: string, title: string}; |
| 142 | type SetSidebarHeightRequest = {command: Commands.SetSidebarHeight, id: string, height: string}; |
| 143 | type SetSidebarContentRequest = { |
| 144 | command: Commands.SetSidebarContent, |
| 145 | id: string, |
| 146 | evaluateOnPage?: boolean, expression: string, |
| 147 | rootTitle?: string, |
| 148 | evaluateOptions?: EvaluateOptions, |
| 149 | }; |
| 150 | type SetSidebarPageRequest = {command: Commands.SetSidebarPage, id: string, page: string}; |
| 151 | type OpenResourceRequest = {command: Commands.OpenResource, url: string, lineNumber: number}; |
| 152 | type SetOpenResourceHandlerRequest = {command: Commands.SetOpenResourceHandler, handlerPresent: boolean}; |
| 153 | type ReloadRequest = { |
| 154 | command: Commands.Reload, |
| 155 | options: null|{ |
| 156 | userAgent?: string, |
| 157 | injectedScript?: string, |
| 158 | ignoreCache?: boolean, |
| 159 | }, |
| 160 | }; |
| 161 | type EvaluateOnInspectedPageRequest = { |
| 162 | command: Commands.EvaluateOnInspectedPage, |
| 163 | expression: string, |
| 164 | evaluateOptions?: EvaluateOptions, |
| 165 | }; |
| 166 | type GetRequestContentRequest = {command: Commands.GetRequestContent, id: number}; |
| 167 | type GetResourceContentRequest = {command: Commands.GetResourceContent, url: string}; |
| 168 | type SetResourceContentRequest = |
| 169 | {command: Commands.SetResourceContent, url: string, content: string, commit: boolean}; |
| 170 | type AddTraceProviderRequest = |
| 171 | {command: Commands.AddTraceProvider, id: string, categoryName: string, categoryTooltip: string}; |
| 172 | type ForwardKeyboardEventRequest = { |
| 173 | command: Commands.ForwardKeyboardEvent, |
| 174 | entries: Array<KeyboardEventInit&{eventType: string}>, |
| 175 | }; |
| 176 | type GetHARRequest = {command: Commands.GetHAR}; |
| 177 | type GetPageResourcesRequest = {command: Commands.GetPageResources}; |
| 178 | |
| 179 | export type ServerRequests = RegisterLanguageExtensionPluginRequest|SubscribeRequest|UnsubscribeRequest| |
| 180 | AddRequestHeadersRequest|ApplyStyleSheetRequest|CreatePanelRequest|ShowPanelRequest|CreateToolbarButtonRequest| |
| 181 | UpdateButtonRequest|CompleteTraceSessionRequest|CreateSidebarPaneRequest|SetSidebarHeightRequest| |
| 182 | SetSidebarContentRequest|SetSidebarPageRequest|OpenResourceRequest|SetOpenResourceHandlerRequest|ReloadRequest| |
| 183 | EvaluateOnInspectedPageRequest|GetRequestContentRequest|GetResourceContentRequest|SetResourceContentRequest| |
| 184 | AddTraceProviderRequest|ForwardKeyboardEventRequest|GetHARRequest|GetPageResourcesRequest; |
| 185 | export type ExtensionServerRequestMessage = PrivateAPI.ServerRequests&{requestId?: number}; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 186 | } |
| 187 | |
Philip Pfaffe | 939605d | 2021-06-25 12:20:04 | [diff] [blame] | 188 | declare global { |
| 189 | interface Window { |
| 190 | injectedExtensionAPI: |
| 191 | (extensionInfo: ExtensionDescriptor, inspectedTabId: string, themeName: string, keysToForward: number[], |
Philip Pfaffe | 7523faf | 2021-06-28 14:23:14 | [diff] [blame^] | 192 | testHook: |
| 193 | (extensionServer: APIImpl.ExtensionServerClient, extensionAPI: APIImpl.InspectorExtensionAPI) => unknown, |
| 194 | injectedScriptId: number) => void; |
Philip Pfaffe | 939605d | 2021-06-25 12:20:04 | [diff] [blame] | 195 | buildExtensionAPIInjectedScript( |
| 196 | extensionInfo: ExtensionDescriptor, inspectedTabId: string, themeName: string, keysToForward: number[], |
Philip Pfaffe | d662bdf | 2021-06-25 13:30:32 | [diff] [blame] | 197 | testHook: undefined|((extensionServer: unknown, extensionAPI: unknown) => unknown)): string; |
Philip Pfaffe | 7523faf | 2021-06-28 14:23:14 | [diff] [blame^] | 198 | chrome: PublicAPI.Chrome.DevTools.Chrome; |
| 199 | webInspector?: APIImpl.InspectorExtensionAPI; |
Philip Pfaffe | 939605d | 2021-06-25 12:20:04 | [diff] [blame] | 200 | } |
| 201 | } |
| 202 | |
| 203 | export type ExtensionDescriptor = { |
| 204 | startPage: string, |
| 205 | name: string, |
| 206 | exposeExperimentalAPIs: boolean, |
| 207 | exposeWebInspectorNamespace?: boolean, |
| 208 | }; |
| 209 | |
Philip Pfaffe | 7523faf | 2021-06-28 14:23:14 | [diff] [blame^] | 210 | namespace APIImpl { |
| 211 | export interface InspectorExtensionAPI { |
| 212 | languageServices: PublicAPI.Chrome.DevTools.LanguageExtensions; |
| 213 | network: PublicAPI.Chrome.DevTools.Network; |
| 214 | panels: PublicAPI.Chrome.DevTools.Panels; |
| 215 | inspectedWindow: PublicAPI.Chrome.DevTools.InspectedWindow; |
| 216 | } |
| 217 | |
| 218 | export interface ExtensionServerClient { |
| 219 | _callbacks: {[key: string]: (response: unknown) => unknown}; |
| 220 | _handlers: {[key: string]: (request: {arguments: unknown[]}) => unknown}; |
| 221 | _lastRequestId: number; |
| 222 | _lastObjectId: number; |
| 223 | _port: MessagePort; |
| 224 | |
| 225 | _onCallback(request: unknown): void; |
| 226 | _onMessage(event: MessageEvent<{command: string, requestId: number, arguments: unknown[]}>): void; |
| 227 | _registerCallback(callback: (response: unknown) => unknown): number; |
| 228 | registerHandler(command: string, handler: (request: {arguments: unknown[]}) => unknown): void; |
| 229 | unregisterHandler(command: string): void; |
| 230 | hasHandler(command: string): boolean; |
| 231 | sendRequest(request: PrivateAPI.ServerRequests, callback?: ((response: unknown) => unknown), transfers?: unknown[]): |
| 232 | void; |
| 233 | nextObjectId(): string; |
| 234 | } |
| 235 | |
| 236 | // We cannot use the stronger `unknown` type in place of `any` in the following type definition. The type is used as |
| 237 | // the right-hand side of `extends` in a few places, which doesn't narrow `unknown`. Without narrowing, overload |
| 238 | // resolution and meaningful type inference of arguments break, for example. |
| 239 | // eslint-disable-next-line @typescript-eslint/no-explicit-any |
| 240 | export type Callable = (...args: any) => any; |
| 241 | |
| 242 | export interface EventSink<ListenerT extends Callable> extends PublicAPI.Chrome.DevTools.EventSink<ListenerT> { |
| 243 | _type: string; |
| 244 | _listeners: ListenerT[]; |
| 245 | _customDispatch: undefined|((this: EventSink<ListenerT>, request: {arguments: unknown[]}) => unknown); |
| 246 | |
| 247 | _fire(..._vararg: Parameters<ListenerT>): void; |
| 248 | _dispatch(request: {arguments: unknown[]}): void; |
| 249 | } |
| 250 | } |
Philip Pfaffe | 939605d | 2021-06-25 12:20:04 | [diff] [blame] | 251 | |
Tim van der Lippe | 226fc22 | 2019-10-10 12:17:12 | [diff] [blame] | 252 | self.injectedExtensionAPI = function( |
Philip Pfaffe | 7523faf | 2021-06-28 14:23:14 | [diff] [blame^] | 253 | extensionInfo: ExtensionDescriptor, inspectedTabId: string, themeName: string, keysToForward: number[], |
| 254 | testHook: (extensionServer: APIImpl.ExtensionServerClient, extensionAPI: APIImpl.InspectorExtensionAPI) => unknown, |
| 255 | injectedScriptId: number): void { |
Jan Scheffler | d76b416 | 2021-03-29 07:52:16 | [diff] [blame] | 256 | const keysToForwardSet = new Set<number>(keysToForward); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 257 | const chrome = window.chrome || {}; |
Jan Scheffler | d76b416 | 2021-03-29 07:52:16 | [diff] [blame] | 258 | |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 259 | const devtools_descriptor = Object.getOwnPropertyDescriptor(chrome, 'devtools'); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 260 | if (devtools_descriptor) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 261 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 262 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 263 | let userAction = false; |
| 264 | |
| 265 | // Here and below, all constructors are private to API implementation. |
| 266 | // For a public type Foo, if internal fields are present, these are on |
| 267 | // a private FooImpl type, an instance of FooImpl is used in a closure |
| 268 | // by Foo consutrctor to re-bind publicly exported members to an instance |
| 269 | // of Foo. |
| 270 | |
Philip Pfaffe | 7523faf | 2021-06-28 14:23:14 | [diff] [blame^] | 271 | function EventSinkImpl<ListenerT extends APIImpl.Callable>( |
| 272 | this: APIImpl.EventSink<ListenerT>, type: string, |
| 273 | customDispatch?: (this: APIImpl.EventSink<ListenerT>, request: {arguments: unknown[]}) => unknown): void { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 274 | this._type = type; |
| 275 | this._listeners = []; |
| 276 | this._customDispatch = customDispatch; |
| 277 | } |
| 278 | |
| 279 | EventSinkImpl.prototype = { |
Philip Pfaffe | 7523faf | 2021-06-28 14:23:14 | [diff] [blame^] | 280 | addListener: function<ListenerT extends APIImpl.Callable>(this: APIImpl.EventSink<ListenerT>, callback: ListenerT): |
| 281 | void { |
| 282 | if (typeof callback !== 'function') { |
| 283 | throw 'addListener: callback is not a function'; |
| 284 | } |
| 285 | if (this._listeners.length === 0) { |
| 286 | extensionServer.sendRequest({command: PrivateAPI.Commands.Subscribe, type: this._type}); |
| 287 | } |
| 288 | this._listeners.push(callback); |
| 289 | extensionServer.registerHandler('notify-' + this._type, this._dispatch.bind(this)); |
| 290 | }, |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 291 | |
Jan Scheffler | d76b416 | 2021-03-29 07:52:16 | [diff] [blame] | 292 | |
Philip Pfaffe | 7523faf | 2021-06-28 14:23:14 | [diff] [blame^] | 293 | removeListener: function<ListenerT extends APIImpl.Callable>( |
| 294 | this: APIImpl.EventSink<ListenerT>, callback: ListenerT): void { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 295 | const listeners = this._listeners; |
| 296 | |
| 297 | for (let i = 0; i < listeners.length; ++i) { |
| 298 | if (listeners[i] === callback) { |
| 299 | listeners.splice(i, 1); |
| 300 | break; |
| 301 | } |
| 302 | } |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 303 | if (this._listeners.length === 0) { |
Philip Pfaffe | 939605d | 2021-06-25 12:20:04 | [diff] [blame] | 304 | extensionServer.sendRequest({command: PrivateAPI.Commands.Unsubscribe, type: this._type}); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 305 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 306 | }, |
| 307 | |
Jan Scheffler | d76b416 | 2021-03-29 07:52:16 | [diff] [blame] | 308 | |
Philip Pfaffe | 7523faf | 2021-06-28 14:23:14 | [diff] [blame^] | 309 | _fire: function<ListenerT extends APIImpl.Callable>( |
| 310 | this: APIImpl.EventSink<ListenerT>, ..._vararg: Parameters<ListenerT>): void { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 311 | const listeners = this._listeners.slice(); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 312 | for (let i = 0; i < listeners.length; ++i) { |
Philip Pfaffe | 7523faf | 2021-06-28 14:23:14 | [diff] [blame^] | 313 | listeners[i].apply(null, Array.from(arguments)); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 314 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 315 | }, |
| 316 | |
Jan Scheffler | d76b416 | 2021-03-29 07:52:16 | [diff] [blame] | 317 | |
Philip Pfaffe | 7523faf | 2021-06-28 14:23:14 | [diff] [blame^] | 318 | _dispatch: function<ListenerT extends APIImpl.Callable>( |
| 319 | this: APIImpl.EventSink<ListenerT>, request: {arguments: unknown[]}): void { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 320 | if (this._customDispatch) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 321 | this._customDispatch.call(this, request); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 322 | } else { |
Philip Pfaffe | 7523faf | 2021-06-28 14:23:14 | [diff] [blame^] | 323 | this._fire.apply(this, request.arguments as Parameters<ListenerT>); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 324 | } |
Jan Scheffler | d76b416 | 2021-03-29 07:52:16 | [diff] [blame] | 325 | }, |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 326 | }; |
| 327 | |
Philip Pfaffe | 7523faf | 2021-06-28 14:23:14 | [diff] [blame^] | 328 | function Constructor<NewT extends APIImpl.Callable>(ctor: NewT): new (...args: Parameters<NewT>) => |
| 329 | ThisParameterType<NewT> { |
| 330 | return ctor as unknown as new (...args: Parameters<NewT>) => ThisParameterType<NewT>; |
| 331 | } |
| 332 | |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 333 | /** |
| 334 | * @constructor |
| 335 | */ |
Jan Scheffler | d76b416 | 2021-03-29 07:52:16 | [diff] [blame] | 336 | |
Philip Pfaffe | 7523faf | 2021-06-28 14:23:14 | [diff] [blame^] | 337 | function InspectorExtensionAPI(this: APIImpl.InspectorExtensionAPI): void { |
Philip Pfaffe | 939605d | 2021-06-25 12:20:04 | [diff] [blame] | 338 | // @ts-ignore |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 339 | this.inspectedWindow = new InspectedWindow(); |
Philip Pfaffe | 939605d | 2021-06-25 12:20:04 | [diff] [blame] | 340 | // @ts-ignore |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 341 | this.panels = new Panels(); |
Philip Pfaffe | 939605d | 2021-06-25 12:20:04 | [diff] [blame] | 342 | // @ts-ignore |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 343 | this.network = new Network(); |
Philip Pfaffe | 939605d | 2021-06-25 12:20:04 | [diff] [blame] | 344 | // @ts-ignore |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 345 | this.timeline = new Timeline(); |
Philip Pfaffe | 939605d | 2021-06-25 12:20:04 | [diff] [blame] | 346 | // @ts-ignore |
Philip Pfaffe | edad832 | 2020-07-20 10:24:25 | [diff] [blame] | 347 | this.languageServices = new LanguageServicesAPI(); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 348 | defineDeprecatedProperty(this, 'webInspector', 'resources', 'network'); |
| 349 | } |
| 350 | |
| 351 | /** |
| 352 | * @constructor |
| 353 | */ |
Jan Scheffler | d76b416 | 2021-03-29 07:52:16 | [diff] [blame] | 354 | |
Philip Pfaffe | 939605d | 2021-06-25 12:20:04 | [diff] [blame] | 355 | function Network(this: any): void { |
| 356 | function dispatchRequestEvent(this: any, message: any): void { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 357 | const request = message.arguments[1]; |
Philip Pfaffe | 939605d | 2021-06-25 12:20:04 | [diff] [blame] | 358 | // @ts-ignore |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 359 | request.__proto__ = new Request(message.arguments[0]); |
| 360 | this._fire(request); |
| 361 | } |
Philip Pfaffe | 939605d | 2021-06-25 12:20:04 | [diff] [blame] | 362 | // @ts-ignore |
| 363 | this.onRequestFinished = new EventSink(PrivateAPI.Events.NetworkRequestFinished, dispatchRequestEvent); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 364 | defineDeprecatedProperty(this, 'network', 'onFinished', 'onRequestFinished'); |
Philip Pfaffe | 939605d | 2021-06-25 12:20:04 | [diff] [blame] | 365 | // @ts-ignore |
| 366 | this.onNavigated = new EventSink(PrivateAPI.Events.InspectedURLChanged); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 367 | } |
| 368 | |
| 369 | Network.prototype = { |
Jan Scheffler | d76b416 | 2021-03-29 07:52:16 | [diff] [blame] | 370 | getHAR: function(callback: any): void { |
| 371 | function callbackWrapper(result: any): void { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 372 | const entries = (result && result.entries) || []; |
| 373 | for (let i = 0; i < entries.length; ++i) { |
Philip Pfaffe | 939605d | 2021-06-25 12:20:04 | [diff] [blame] | 374 | // @ts-ignore |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 375 | entries[i].__proto__ = new Request(entries[i]._requestId); |
| 376 | delete entries[i]._requestId; |
| 377 | } |
| 378 | callback(result); |
| 379 | } |
Philip Pfaffe | 939605d | 2021-06-25 12:20:04 | [diff] [blame] | 380 | extensionServer.sendRequest({command: PrivateAPI.Commands.GetHAR}, callback && callbackWrapper); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 381 | }, |
| 382 | |
Jan Scheffler | d76b416 | 2021-03-29 07:52:16 | [diff] [blame] | 383 | addRequestHeaders: function(headers: any): void { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 384 | extensionServer.sendRequest( |
Philip Pfaffe | 939605d | 2021-06-25 12:20:04 | [diff] [blame] | 385 | {command: PrivateAPI.Commands.AddRequestHeaders, headers: headers, extensionId: window.location.hostname}); |
Jan Scheffler | d76b416 | 2021-03-29 07:52:16 | [diff] [blame] | 386 | }, |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 387 | }; |
| 388 | |
Philip Pfaffe | 939605d | 2021-06-25 12:20:04 | [diff] [blame] | 389 | function RequestImpl(this: any, id: any): void { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 390 | this._id = id; |
| 391 | } |
| 392 | |
| 393 | RequestImpl.prototype = { |
Jan Scheffler | d76b416 | 2021-03-29 07:52:16 | [diff] [blame] | 394 | getContent: function(callback: any): void { |
| 395 | function callbackWrapper(response: any): void { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 396 | callback(response.content, response.encoding); |
| 397 | } |
Philip Pfaffe | 939605d | 2021-06-25 12:20:04 | [diff] [blame] | 398 | extensionServer.sendRequest( |
| 399 | {command: PrivateAPI.Commands.GetRequestContent, id: this._id}, callback && callbackWrapper); |
Jan Scheffler | d76b416 | 2021-03-29 07:52:16 | [diff] [blame] | 400 | }, |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 401 | }; |
| 402 | |
| 403 | /** |
| 404 | * @constructor |
| 405 | */ |
Philip Pfaffe | 939605d | 2021-06-25 12:20:04 | [diff] [blame] | 406 | function Panels(this: any): void { |
| 407 | const panels: {[key: string]: any} = { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 408 | elements: new ElementsPanel(), |
| 409 | sources: new SourcesPanel(), |
| 410 | }; |
| 411 | |
Jan Scheffler | d76b416 | 2021-03-29 07:52:16 | [diff] [blame] | 412 | function panelGetter(name: any): any { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 413 | return panels[name]; |
| 414 | } |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 415 | for (const panel in panels) { |
Tim van der Lippe | ffa7862 | 2019-09-16 12:07:12 | [diff] [blame] | 416 | Object.defineProperty(this, panel, {get: panelGetter.bind(null, panel), enumerable: true}); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 417 | } |
Jan Scheffler | d76b416 | 2021-03-29 07:52:16 | [diff] [blame] | 418 | this.applyStyleSheet = function(styleSheet: any): void { |
Philip Pfaffe | 939605d | 2021-06-25 12:20:04 | [diff] [blame] | 419 | extensionServer.sendRequest({command: PrivateAPI.Commands.ApplyStyleSheet, styleSheet: styleSheet}); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 420 | }; |
| 421 | } |
| 422 | |
| 423 | Panels.prototype = { |
Jan Scheffler | d76b416 | 2021-03-29 07:52:16 | [diff] [blame] | 424 | create: function(title: any, icon: any, page: any, callback: any): void { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 425 | const id = 'extension-panel-' + extensionServer.nextObjectId(); |
Philip Pfaffe | 939605d | 2021-06-25 12:20:04 | [diff] [blame] | 426 | const request = {command: PrivateAPI.Commands.CreatePanel, id: id, title: title, icon: icon, page: page}; |
| 427 | // @ts-ignore |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 428 | extensionServer.sendRequest(request, callback && callback.bind(this, new ExtensionPanel(id))); |
| 429 | }, |
| 430 | |
Jan Scheffler | d76b416 | 2021-03-29 07:52:16 | [diff] [blame] | 431 | setOpenResourceHandler: function(callback: any): void { |
Philip Pfaffe | 939605d | 2021-06-25 12:20:04 | [diff] [blame] | 432 | const hadHandler = extensionServer.hasHandler(PrivateAPI.Events.OpenResource); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 433 | |
Jan Scheffler | d76b416 | 2021-03-29 07:52:16 | [diff] [blame] | 434 | function callbackWrapper(message: any): void { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 435 | // Allow the panel to show itself when handling the event. |
| 436 | userAction = true; |
| 437 | try { |
Philip Pfaffe | 939605d | 2021-06-25 12:20:04 | [diff] [blame] | 438 | // @ts-ignore |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 439 | callback.call(null, new Resource(message.resource), message.lineNumber); |
| 440 | } finally { |
| 441 | userAction = false; |
| 442 | } |
| 443 | } |
| 444 | |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 445 | if (!callback) { |
Philip Pfaffe | 939605d | 2021-06-25 12:20:04 | [diff] [blame] | 446 | extensionServer.unregisterHandler(PrivateAPI.Events.OpenResource); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 447 | } else { |
Philip Pfaffe | 939605d | 2021-06-25 12:20:04 | [diff] [blame] | 448 | extensionServer.registerHandler(PrivateAPI.Events.OpenResource, callbackWrapper); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 449 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 450 | |
| 451 | // Only send command if we either removed an existing handler or added handler and had none before. |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 452 | if (hadHandler === !callback) { |
Philip Pfaffe | 939605d | 2021-06-25 12:20:04 | [diff] [blame] | 453 | extensionServer.sendRequest( |
| 454 | {command: PrivateAPI.Commands.SetOpenResourceHandler, 'handlerPresent': Boolean(callback)}); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 455 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 456 | }, |
| 457 | |
Jan Scheffler | d76b416 | 2021-03-29 07:52:16 | [diff] [blame] | 458 | openResource: function(url: any, lineNumber: any, callback: any): void { |
Philip Pfaffe | 939605d | 2021-06-25 12:20:04 | [diff] [blame] | 459 | extensionServer.sendRequest( |
| 460 | {command: PrivateAPI.Commands.OpenResource, 'url': url, 'lineNumber': lineNumber}, callback); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 461 | }, |
| 462 | |
Jan Scheffler | d76b416 | 2021-03-29 07:52:16 | [diff] [blame] | 463 | get SearchAction(): any { |
Philip Pfaffe | 939605d | 2021-06-25 12:20:04 | [diff] [blame] | 464 | return { |
| 465 | CancelSearch: PrivateAPI.Panels.SearchAction.CancelSearch, |
| 466 | PerformSearch: PrivateAPI.Panels.SearchAction.PerformSearch, |
| 467 | NextSearchResult: PrivateAPI.Panels.SearchAction.NextSearchResult, |
| 468 | PreviousSearchResult: PrivateAPI.Panels.SearchAction.PreviousSearchResult, |
| 469 | }; |
Jan Scheffler | d76b416 | 2021-03-29 07:52:16 | [diff] [blame] | 470 | }, |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 471 | }; |
| 472 | |
| 473 | /** |
| 474 | * @constructor |
| 475 | */ |
Philip Pfaffe | 939605d | 2021-06-25 12:20:04 | [diff] [blame] | 476 | function ExtensionViewImpl(this: any, id: any): void { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 477 | this._id = id; |
| 478 | |
Philip Pfaffe | 939605d | 2021-06-25 12:20:04 | [diff] [blame] | 479 | function dispatchShowEvent(this: any, message: any): void { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 480 | const frameIndex = message.arguments[0]; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 481 | if (typeof frameIndex === 'number') { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 482 | this._fire(window.parent.frames[frameIndex]); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 483 | } else { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 484 | this._fire(); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 485 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 486 | } |
| 487 | |
| 488 | if (id) { |
Philip Pfaffe | 939605d | 2021-06-25 12:20:04 | [diff] [blame] | 489 | // @ts-ignore |
| 490 | this.onShown = new EventSink(PrivateAPI.Events.ViewShown + id, dispatchShowEvent); |
| 491 | // @ts-ignore |
| 492 | this.onHidden = new EventSink(PrivateAPI.Events.ViewHidden + id); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 493 | } |
| 494 | } |
| 495 | |
| 496 | /** |
| 497 | * @constructor |
| 498 | * @extends {ExtensionViewImpl} |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 499 | */ |
Philip Pfaffe | 939605d | 2021-06-25 12:20:04 | [diff] [blame] | 500 | function PanelWithSidebarImpl(this: any, hostPanelName: string): void { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 501 | ExtensionViewImpl.call(this, null); |
| 502 | this._hostPanelName = hostPanelName; |
Philip Pfaffe | 939605d | 2021-06-25 12:20:04 | [diff] [blame] | 503 | // @ts-ignore |
| 504 | this.onSelectionChanged = new EventSink(PrivateAPI.Events.PanelObjectSelected + hostPanelName); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 505 | } |
| 506 | |
| 507 | PanelWithSidebarImpl.prototype = { |
Jan Scheffler | d76b416 | 2021-03-29 07:52:16 | [diff] [blame] | 508 | createSidebarPane: function(title: any, callback: any): void { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 509 | const id = 'extension-sidebar-' + extensionServer.nextObjectId(); |
Jan Scheffler | d76b416 | 2021-03-29 07:52:16 | [diff] [blame] | 510 | function callbackWrapper(): void { |
Philip Pfaffe | 939605d | 2021-06-25 12:20:04 | [diff] [blame] | 511 | // @ts-ignore |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 512 | callback(new ExtensionSidebarPane(id)); |
| 513 | } |
Philip Pfaffe | 7523faf | 2021-06-28 14:23:14 | [diff] [blame^] | 514 | extensionServer.sendRequest( |
| 515 | {command: PrivateAPI.Commands.CreateSidebarPane, panel: this._hostPanelName, id: id, title: title}, |
| 516 | callback && callbackWrapper); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 517 | }, |
| 518 | |
Jan Scheffler | d76b416 | 2021-03-29 07:52:16 | [diff] [blame] | 519 | __proto__: ExtensionViewImpl.prototype, |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 520 | }; |
| 521 | |
Philip Pfaffe | edad832 | 2020-07-20 10:24:25 | [diff] [blame] | 522 | /** |
| 523 | * @constructor |
| 524 | */ |
Philip Pfaffe | 939605d | 2021-06-25 12:20:04 | [diff] [blame] | 525 | function LanguageServicesAPIImpl(this: any): void { |
Benedikt Meurer | 929fc7c | 2020-11-20 14:21:06 | [diff] [blame] | 526 | /** @type {!Map<*, !MessagePort>} */ |
Philip Pfaffe | edad832 | 2020-07-20 10:24:25 | [diff] [blame] | 527 | this._plugins = new Map(); |
| 528 | } |
| 529 | |
| 530 | LanguageServicesAPIImpl.prototype = { |
Philip Pfaffe | d662bdf | 2021-06-25 13:30:32 | [diff] [blame] | 531 | registerLanguageExtensionPlugin: async function( |
Philip Pfaffe | 7523faf | 2021-06-28 14:23:14 | [diff] [blame^] | 532 | plugin: any, pluginName: string, supportedScriptTypes: PublicAPI.Chrome.DevTools.SupportedScriptTypes): |
| 533 | Promise<void> { |
| 534 | if (this._plugins.has(plugin)) { |
| 535 | throw new Error(`Tried to register plugin '${pluginName}' twice`); |
| 536 | } |
| 537 | const channel = new MessageChannel(); |
| 538 | const port = channel.port1; |
| 539 | this._plugins.set(plugin, port); |
| 540 | port.onmessage = ({data: {requestId, method, parameters}}: MessageEvent<any>): void => { |
| 541 | console.time(`${requestId}: ${method}`); |
| 542 | dispatchMethodCall(method, parameters) |
| 543 | .then(result => port.postMessage({requestId, result})) |
| 544 | .catch(error => port.postMessage({requestId, error: {message: error.message}})) |
| 545 | .finally(() => console.timeEnd(`${requestId}: ${method}`)); |
| 546 | }; |
Philip Pfaffe | edad832 | 2020-07-20 10:24:25 | [diff] [blame] | 547 | |
Philip Pfaffe | 7523faf | 2021-06-28 14:23:14 | [diff] [blame^] | 548 | function dispatchMethodCall(method: string, parameters: any): Promise<any> { |
| 549 | switch (method) { |
| 550 | case PrivateAPI.LanguageExtensionPluginCommands.AddRawModule: |
| 551 | return plugin.addRawModule(parameters.rawModuleId, parameters.symbolsURL, parameters.rawModule); |
| 552 | case PrivateAPI.LanguageExtensionPluginCommands.RemoveRawModule: |
| 553 | return plugin.removeRawModule(parameters.rawModuleId); |
| 554 | case PrivateAPI.LanguageExtensionPluginCommands.SourceLocationToRawLocation: |
| 555 | return plugin.sourceLocationToRawLocation(parameters.sourceLocation); |
| 556 | case PrivateAPI.LanguageExtensionPluginCommands.RawLocationToSourceLocation: |
| 557 | return plugin.rawLocationToSourceLocation(parameters.rawLocation); |
| 558 | case PrivateAPI.LanguageExtensionPluginCommands.GetScopeInfo: |
| 559 | return plugin.getScopeInfo(parameters.type); |
| 560 | case PrivateAPI.LanguageExtensionPluginCommands.ListVariablesInScope: |
| 561 | return plugin.listVariablesInScope(parameters.rawLocation); |
| 562 | case PrivateAPI.LanguageExtensionPluginCommands.GetTypeInfo: |
| 563 | return plugin.getTypeInfo(parameters.expression, parameters.context); |
| 564 | case PrivateAPI.LanguageExtensionPluginCommands.GetFormatter: |
| 565 | return plugin.getFormatter(parameters.expressionOrField, parameters.context); |
| 566 | case PrivateAPI.LanguageExtensionPluginCommands.GetInspectableAddress: |
| 567 | if ('getInspectableAddress' in plugin) { |
| 568 | return plugin.getInspectableAddress(parameters.field); |
| 569 | } |
| 570 | return Promise.resolve({js: ''}); |
| 571 | case PrivateAPI.LanguageExtensionPluginCommands.GetFunctionInfo: |
| 572 | return plugin.getFunctionInfo(parameters.rawLocation); |
| 573 | case PrivateAPI.LanguageExtensionPluginCommands.GetInlinedFunctionRanges: |
| 574 | return plugin.getInlinedFunctionRanges(parameters.rawLocation); |
| 575 | case PrivateAPI.LanguageExtensionPluginCommands.GetInlinedCalleesRanges: |
| 576 | return plugin.getInlinedCalleesRanges(parameters.rawLocation); |
| 577 | case PrivateAPI.LanguageExtensionPluginCommands.GetMappedLines: |
| 578 | if ('getMappedLines' in plugin) { |
| 579 | return plugin.getMappedLines(parameters.rawModuleId, parameters.sourceFileURL); |
| 580 | } |
| 581 | return Promise.resolve(undefined); |
Kim-Anh Tran | 8fd7d6f | 2021-01-28 11:07:02 | [diff] [blame] | 582 | } |
Philip Pfaffe | 7523faf | 2021-06-28 14:23:14 | [diff] [blame^] | 583 | throw new Error(`Unknown language plugin method ${method}`); |
| 584 | } |
Philip Pfaffe | edad832 | 2020-07-20 10:24:25 | [diff] [blame] | 585 | |
Philip Pfaffe | 7523faf | 2021-06-28 14:23:14 | [diff] [blame^] | 586 | await new Promise<void>(resolve => { |
| 587 | extensionServer.sendRequest( |
| 588 | { |
| 589 | command: PrivateAPI.Commands.RegisterLanguageExtensionPlugin, |
| 590 | pluginName, |
| 591 | port: channel.port2, |
| 592 | supportedScriptTypes, |
| 593 | }, |
| 594 | () => resolve(), [channel.port2]); |
| 595 | }); |
| 596 | }, |
Benedikt Meurer | 929fc7c | 2020-11-20 14:21:06 | [diff] [blame] | 597 | |
Jan Scheffler | d76b416 | 2021-03-29 07:52:16 | [diff] [blame] | 598 | unregisterLanguageExtensionPlugin: async function(plugin: any): Promise<void> { |
Benedikt Meurer | 929fc7c | 2020-11-20 14:21:06 | [diff] [blame] | 599 | const port = this._plugins.get(plugin); |
| 600 | if (!port) { |
| 601 | throw new Error('Tried to unregister a plugin that was not previously registered'); |
| 602 | } |
| 603 | this._plugins.delete(plugin); |
Philip Pfaffe | 939605d | 2021-06-25 12:20:04 | [diff] [blame] | 604 | port.postMessage({event: PrivateAPI.LanguageExtensionPluginEvents.UnregisteredLanguageExtensionPlugin}); |
Benedikt Meurer | 929fc7c | 2020-11-20 14:21:06 | [diff] [blame] | 605 | port.close(); |
Jan Scheffler | d76b416 | 2021-03-29 07:52:16 | [diff] [blame] | 606 | }, |
Philip Pfaffe | edad832 | 2020-07-20 10:24:25 | [diff] [blame] | 607 | }; |
| 608 | |
Philip Pfaffe | 7523faf | 2021-06-28 14:23:14 | [diff] [blame^] | 609 | function declareInterfaceClass<ImplT extends APIImpl.Callable>(implConstructor: ImplT): ( |
| 610 | this: ThisParameterType<ImplT>, ...args: Parameters<ImplT>) => void { |
| 611 | return function(this: ThisParameterType<ImplT>, ...args: Parameters<ImplT>): void { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 612 | const impl = {__proto__: implConstructor.prototype}; |
Philip Pfaffe | 7523faf | 2021-06-28 14:23:14 | [diff] [blame^] | 613 | implConstructor.apply(impl, args); |
| 614 | populateInterfaceClass(this as {[key: string]: unknown}, impl); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 615 | }; |
| 616 | } |
| 617 | |
Philip Pfaffe | 7523faf | 2021-06-28 14:23:14 | [diff] [blame^] | 618 | // eslint-disable-next-line @typescript-eslint/no-explicit-any |
| 619 | function defineDeprecatedProperty(object: any, className: string, oldName: string, newName: string): void { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 620 | let warningGiven = false; |
Philip Pfaffe | 7523faf | 2021-06-28 14:23:14 | [diff] [blame^] | 621 | function getter(): unknown { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 622 | if (!warningGiven) { |
| 623 | console.warn(className + '.' + oldName + ' is deprecated. Use ' + className + '.' + newName + ' instead'); |
| 624 | warningGiven = true; |
| 625 | } |
| 626 | return object[newName]; |
| 627 | } |
| 628 | object.__defineGetter__(oldName, getter); |
| 629 | } |
| 630 | |
Philip Pfaffe | 7523faf | 2021-06-28 14:23:14 | [diff] [blame^] | 631 | function extractCallbackArgument(args: IArguments): ((...args: unknown[]) => unknown)|undefined { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 632 | const lastArgument = args[args.length - 1]; |
Philip Pfaffe | 7523faf | 2021-06-28 14:23:14 | [diff] [blame^] | 633 | return typeof lastArgument === 'function' ? lastArgument as (...args: unknown[]) => unknown : undefined; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 634 | } |
| 635 | |
Philip Pfaffe | edad832 | 2020-07-20 10:24:25 | [diff] [blame] | 636 | const LanguageServicesAPI = declareInterfaceClass(LanguageServicesAPIImpl); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 637 | const Button = declareInterfaceClass(ButtonImpl); |
| 638 | const EventSink = declareInterfaceClass(EventSinkImpl); |
| 639 | const ExtensionPanel = declareInterfaceClass(ExtensionPanelImpl); |
| 640 | const ExtensionSidebarPane = declareInterfaceClass(ExtensionSidebarPaneImpl); |
Tim van der Lippe | ffa7862 | 2019-09-16 12:07:12 | [diff] [blame] | 641 | /** |
| 642 | * @constructor |
| 643 | * @param {string} hostPanelName |
| 644 | */ |
| 645 | const PanelWithSidebarClass = declareInterfaceClass(PanelWithSidebarImpl); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 646 | const Request = declareInterfaceClass(RequestImpl); |
| 647 | const Resource = declareInterfaceClass(ResourceImpl); |
| 648 | const TraceSession = declareInterfaceClass(TraceSessionImpl); |
| 649 | |
Philip Pfaffe | 939605d | 2021-06-25 12:20:04 | [diff] [blame] | 650 | // @ts-ignore |
Tim van der Lippe | ffa7862 | 2019-09-16 12:07:12 | [diff] [blame] | 651 | class ElementsPanel extends PanelWithSidebarClass { |
| 652 | constructor() { |
| 653 | super('elements'); |
| 654 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 655 | } |
| 656 | |
Philip Pfaffe | 939605d | 2021-06-25 12:20:04 | [diff] [blame] | 657 | // @ts-ignore |
Tim van der Lippe | ffa7862 | 2019-09-16 12:07:12 | [diff] [blame] | 658 | class SourcesPanel extends PanelWithSidebarClass { |
| 659 | constructor() { |
| 660 | super('sources'); |
| 661 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 662 | } |
| 663 | |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 664 | /** |
| 665 | * @constructor |
| 666 | * @extends {ExtensionViewImpl} |
| 667 | */ |
Philip Pfaffe | 939605d | 2021-06-25 12:20:04 | [diff] [blame] | 668 | function ExtensionPanelImpl(this: any, id: any): void { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 669 | ExtensionViewImpl.call(this, id); |
Philip Pfaffe | 939605d | 2021-06-25 12:20:04 | [diff] [blame] | 670 | // @ts-ignore |
| 671 | this.onSearch = new EventSink(PrivateAPI.Events.PanelSearch + id); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 672 | } |
| 673 | |
| 674 | ExtensionPanelImpl.prototype = { |
Jan Scheffler | d76b416 | 2021-03-29 07:52:16 | [diff] [blame] | 675 | createStatusBarButton: function(iconPath: any, tooltipText: any, disabled: any): Object { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 676 | const id = 'button-' + extensionServer.nextObjectId(); |
Philip Pfaffe | 7523faf | 2021-06-28 14:23:14 | [diff] [blame^] | 677 | extensionServer.sendRequest({ |
Philip Pfaffe | 939605d | 2021-06-25 12:20:04 | [diff] [blame] | 678 | command: PrivateAPI.Commands.CreateToolbarButton, |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 679 | panel: this._id, |
| 680 | id: id, |
| 681 | icon: iconPath, |
| 682 | tooltip: tooltipText, |
Jan Scheffler | d76b416 | 2021-03-29 07:52:16 | [diff] [blame] | 683 | disabled: Boolean(disabled), |
Philip Pfaffe | 7523faf | 2021-06-28 14:23:14 | [diff] [blame^] | 684 | }); |
Philip Pfaffe | 939605d | 2021-06-25 12:20:04 | [diff] [blame] | 685 | // @ts-ignore |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 686 | return new Button(id); |
| 687 | }, |
| 688 | |
Jan Scheffler | d76b416 | 2021-03-29 07:52:16 | [diff] [blame] | 689 | show: function(): void { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 690 | if (!userAction) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 691 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 692 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 693 | |
Philip Pfaffe | 7523faf | 2021-06-28 14:23:14 | [diff] [blame^] | 694 | extensionServer.sendRequest({command: PrivateAPI.Commands.ShowPanel, id: this._id}); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 695 | }, |
| 696 | |
Jan Scheffler | d76b416 | 2021-03-29 07:52:16 | [diff] [blame] | 697 | __proto__: ExtensionViewImpl.prototype, |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 698 | }; |
| 699 | |
| 700 | /** |
| 701 | * @constructor |
| 702 | * @extends {ExtensionViewImpl} |
| 703 | */ |
Philip Pfaffe | 939605d | 2021-06-25 12:20:04 | [diff] [blame] | 704 | function ExtensionSidebarPaneImpl(this: any, id: any): void { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 705 | ExtensionViewImpl.call(this, id); |
| 706 | } |
| 707 | |
| 708 | ExtensionSidebarPaneImpl.prototype = { |
Jan Scheffler | d76b416 | 2021-03-29 07:52:16 | [diff] [blame] | 709 | setHeight: function(height: any): void { |
Philip Pfaffe | 939605d | 2021-06-25 12:20:04 | [diff] [blame] | 710 | extensionServer.sendRequest({command: PrivateAPI.Commands.SetSidebarHeight, id: this._id, height: height}); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 711 | }, |
| 712 | |
Jan Scheffler | d76b416 | 2021-03-29 07:52:16 | [diff] [blame] | 713 | setExpression: function(expression: any, rootTitle: any, evaluateOptions: any): void { |
Philip Pfaffe | 7523faf | 2021-06-28 14:23:14 | [diff] [blame^] | 714 | extensionServer.sendRequest( |
| 715 | { |
| 716 | command: PrivateAPI.Commands.SetSidebarContent, |
| 717 | id: this._id, |
| 718 | expression: expression, |
| 719 | rootTitle: rootTitle, |
| 720 | evaluateOnPage: true, |
| 721 | evaluateOptions: (typeof evaluateOptions === 'object' ? evaluateOptions : undefined), |
| 722 | }, |
| 723 | extractCallbackArgument(arguments)); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 724 | }, |
| 725 | |
Jan Scheffler | d76b416 | 2021-03-29 07:52:16 | [diff] [blame] | 726 | setObject: function(jsonObject: any, rootTitle: any, callback: any): void { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 727 | extensionServer.sendRequest( |
Philip Pfaffe | 939605d | 2021-06-25 12:20:04 | [diff] [blame] | 728 | {command: PrivateAPI.Commands.SetSidebarContent, id: this._id, expression: jsonObject, rootTitle: rootTitle}, |
| 729 | callback); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 730 | }, |
| 731 | |
Jan Scheffler | d76b416 | 2021-03-29 07:52:16 | [diff] [blame] | 732 | setPage: function(page: any): void { |
Philip Pfaffe | 939605d | 2021-06-25 12:20:04 | [diff] [blame] | 733 | extensionServer.sendRequest({command: PrivateAPI.Commands.SetSidebarPage, id: this._id, page: page}); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 734 | }, |
| 735 | |
Jan Scheffler | d76b416 | 2021-03-29 07:52:16 | [diff] [blame] | 736 | __proto__: ExtensionViewImpl.prototype, |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 737 | }; |
| 738 | |
| 739 | /** |
| 740 | * @constructor |
| 741 | */ |
Philip Pfaffe | 939605d | 2021-06-25 12:20:04 | [diff] [blame] | 742 | function ButtonImpl(this: any, id: any): void { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 743 | this._id = id; |
Philip Pfaffe | 939605d | 2021-06-25 12:20:04 | [diff] [blame] | 744 | // @ts-ignore |
| 745 | this.onClicked = new EventSink(PrivateAPI.Events.ButtonClicked + id); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 746 | } |
| 747 | |
| 748 | ButtonImpl.prototype = { |
Jan Scheffler | d76b416 | 2021-03-29 07:52:16 | [diff] [blame] | 749 | update: function(iconPath: any, tooltipText: any, disabled: any): void { |
Philip Pfaffe | 7523faf | 2021-06-28 14:23:14 | [diff] [blame^] | 750 | extensionServer.sendRequest({ |
Philip Pfaffe | 939605d | 2021-06-25 12:20:04 | [diff] [blame] | 751 | command: PrivateAPI.Commands.UpdateButton, |
Tim van der Lippe | d7cfd14 | 2021-01-07 12:17:24 | [diff] [blame] | 752 | id: this._id, |
| 753 | icon: iconPath, |
| 754 | tooltip: tooltipText, |
Jan Scheffler | d76b416 | 2021-03-29 07:52:16 | [diff] [blame] | 755 | disabled: Boolean(disabled), |
Philip Pfaffe | 7523faf | 2021-06-28 14:23:14 | [diff] [blame^] | 756 | }); |
Jan Scheffler | d76b416 | 2021-03-29 07:52:16 | [diff] [blame] | 757 | }, |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 758 | }; |
| 759 | |
| 760 | /** |
| 761 | * @constructor |
| 762 | */ |
Jan Scheffler | d76b416 | 2021-03-29 07:52:16 | [diff] [blame] | 763 | function Timeline(): void { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 764 | } |
| 765 | |
| 766 | Timeline.prototype = { |
Philip Pfaffe | 939605d | 2021-06-25 12:20:04 | [diff] [blame] | 767 | // @ts-ignore |
Jan Scheffler | d76b416 | 2021-03-29 07:52:16 | [diff] [blame] | 768 | addTraceProvider: function(categoryName: string, categoryTooltip: string): TraceProvider { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 769 | const id = 'extension-trace-provider-' + extensionServer.nextObjectId(); |
Philip Pfaffe | 939605d | 2021-06-25 12:20:04 | [diff] [blame] | 770 | extensionServer.sendRequest({ |
| 771 | command: PrivateAPI.Commands.AddTraceProvider, |
| 772 | id: id, |
| 773 | categoryName: categoryName, |
| 774 | categoryTooltip: categoryTooltip, |
| 775 | }); |
| 776 | // @ts-ignore |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 777 | return new TraceProvider(id); |
Jan Scheffler | d76b416 | 2021-03-29 07:52:16 | [diff] [blame] | 778 | }, |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 779 | }; |
| 780 | |
| 781 | /** |
| 782 | * @constructor |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 783 | */ |
Philip Pfaffe | 939605d | 2021-06-25 12:20:04 | [diff] [blame] | 784 | function TraceSessionImpl(this: any, id: string): void { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 785 | this._id = id; |
| 786 | } |
| 787 | |
| 788 | TraceSessionImpl.prototype = { |
Jan Scheffler | d76b416 | 2021-03-29 07:52:16 | [diff] [blame] | 789 | complete: function(url?: string, timeOffset?: number): void { |
Philip Pfaffe | 7523faf | 2021-06-28 14:23:14 | [diff] [blame^] | 790 | extensionServer.sendRequest({ |
Philip Pfaffe | 939605d | 2021-06-25 12:20:04 | [diff] [blame] | 791 | command: PrivateAPI.Commands.CompleteTraceSession, |
| 792 | id: this._id, |
| 793 | url: url || '', |
| 794 | timeOffset: timeOffset || 0, |
Philip Pfaffe | 7523faf | 2021-06-28 14:23:14 | [diff] [blame^] | 795 | }); |
Jan Scheffler | d76b416 | 2021-03-29 07:52:16 | [diff] [blame] | 796 | }, |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 797 | }; |
| 798 | |
| 799 | /** |
| 800 | * @constructor |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 801 | */ |
Jan Scheffler | d76b416 | 2021-03-29 07:52:16 | [diff] [blame] | 802 | function TraceProvider(id: string): void { |
Philip Pfaffe | 939605d | 2021-06-25 12:20:04 | [diff] [blame] | 803 | function dispatchRecordingStarted(this: any, message: any): void { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 804 | const sessionId = message.arguments[0]; |
Philip Pfaffe | 939605d | 2021-06-25 12:20:04 | [diff] [blame] | 805 | // @ts-ignore |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 806 | this._fire(new TraceSession(sessionId)); |
| 807 | } |
| 808 | |
Philip Pfaffe | 939605d | 2021-06-25 12:20:04 | [diff] [blame] | 809 | // @ts-ignore |
| 810 | this.onRecordingStarted = new EventSink(PrivateAPI.Events.RecordingStarted + id, dispatchRecordingStarted); |
| 811 | // @ts-ignore |
| 812 | this.onRecordingStopped = new EventSink(PrivateAPI.Events.RecordingStopped + id); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 813 | } |
| 814 | |
| 815 | /** |
| 816 | * @constructor |
| 817 | */ |
Philip Pfaffe | 939605d | 2021-06-25 12:20:04 | [diff] [blame] | 818 | function InspectedWindow(this: any): void { |
| 819 | function dispatchResourceEvent(this: any, message: any): void { |
| 820 | // @ts-ignore |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 821 | this._fire(new Resource(message.arguments[0])); |
| 822 | } |
| 823 | |
Philip Pfaffe | 939605d | 2021-06-25 12:20:04 | [diff] [blame] | 824 | function dispatchResourceContentEvent(this: any, message: any): void { |
| 825 | // @ts-ignore |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 826 | this._fire(new Resource(message.arguments[0]), message.arguments[1]); |
| 827 | } |
| 828 | |
Philip Pfaffe | 939605d | 2021-06-25 12:20:04 | [diff] [blame] | 829 | // @ts-ignore |
| 830 | this.onResourceAdded = new EventSink(PrivateAPI.Events.ResourceAdded, dispatchResourceEvent); |
| 831 | this.onResourceContentCommitted = |
| 832 | // @ts-ignore |
| 833 | new EventSink(PrivateAPI.Events.ResourceContentCommitted, dispatchResourceContentEvent); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 834 | } |
| 835 | |
| 836 | InspectedWindow.prototype = { |
Jan Scheffler | d76b416 | 2021-03-29 07:52:16 | [diff] [blame] | 837 | reload: function(optionsOrUserAgent: any): void { |
| 838 | let options: { |
| 839 | userAgent: string, |
| 840 | }|null = null; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 841 | if (typeof optionsOrUserAgent === 'object') { |
| 842 | options = optionsOrUserAgent; |
| 843 | } else if (typeof optionsOrUserAgent === 'string') { |
| 844 | options = {userAgent: optionsOrUserAgent}; |
| 845 | console.warn( |
| 846 | 'Passing userAgent as string parameter to inspectedWindow.reload() is deprecated. ' + |
| 847 | 'Use inspectedWindow.reload({ userAgent: value}) instead.'); |
| 848 | } |
Philip Pfaffe | 939605d | 2021-06-25 12:20:04 | [diff] [blame] | 849 | extensionServer.sendRequest({command: PrivateAPI.Commands.Reload, options: options}); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 850 | }, |
| 851 | |
Jan Scheffler | d76b416 | 2021-03-29 07:52:16 | [diff] [blame] | 852 | eval: function(expression: any, evaluateOptions: any): Object | |
| 853 | null { |
| 854 | const callback = extractCallbackArgument(arguments); |
| 855 | function callbackWrapper(result: any): void { |
| 856 | if (result.isError || result.isException) { |
Philip Pfaffe | 7523faf | 2021-06-28 14:23:14 | [diff] [blame^] | 857 | callback && callback(undefined, result); |
Jan Scheffler | d76b416 | 2021-03-29 07:52:16 | [diff] [blame] | 858 | } else { |
Philip Pfaffe | 7523faf | 2021-06-28 14:23:14 | [diff] [blame^] | 859 | callback && callback(result.value); |
Jan Scheffler | d76b416 | 2021-03-29 07:52:16 | [diff] [blame] | 860 | } |
| 861 | } |
Philip Pfaffe | 7523faf | 2021-06-28 14:23:14 | [diff] [blame^] | 862 | extensionServer.sendRequest( |
| 863 | { |
| 864 | command: PrivateAPI.Commands.EvaluateOnInspectedPage, |
| 865 | expression: expression, |
| 866 | evaluateOptions: (typeof evaluateOptions === 'object' ? evaluateOptions : undefined), |
| 867 | }, |
| 868 | callback && callbackWrapper); |
Jan Scheffler | d76b416 | 2021-03-29 07:52:16 | [diff] [blame] | 869 | return null; |
| 870 | }, |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 871 | |
Jan Scheffler | d76b416 | 2021-03-29 07:52:16 | [diff] [blame] | 872 | getResources: function(callback: any): void { |
| 873 | function wrapResource(resourceData: any): any { |
Philip Pfaffe | 939605d | 2021-06-25 12:20:04 | [diff] [blame] | 874 | // @ts-ignore |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 875 | return new Resource(resourceData); |
| 876 | } |
Jan Scheffler | d76b416 | 2021-03-29 07:52:16 | [diff] [blame] | 877 | function callbackWrapper(resources: any): void { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 878 | callback(resources.map(wrapResource)); |
| 879 | } |
Philip Pfaffe | 939605d | 2021-06-25 12:20:04 | [diff] [blame] | 880 | extensionServer.sendRequest({command: PrivateAPI.Commands.GetPageResources}, callback && callbackWrapper); |
Jan Scheffler | d76b416 | 2021-03-29 07:52:16 | [diff] [blame] | 881 | }, |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 882 | }; |
| 883 | |
| 884 | /** |
| 885 | * @constructor |
| 886 | */ |
Philip Pfaffe | 939605d | 2021-06-25 12:20:04 | [diff] [blame] | 887 | function ResourceImpl(this: any, resourceData: any): void { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 888 | this._url = resourceData.url; |
| 889 | this._type = resourceData.type; |
| 890 | } |
| 891 | |
| 892 | ResourceImpl.prototype = { |
Jan Scheffler | d76b416 | 2021-03-29 07:52:16 | [diff] [blame] | 893 | get url(): string { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 894 | return this._url; |
| 895 | }, |
| 896 | |
Jan Scheffler | d76b416 | 2021-03-29 07:52:16 | [diff] [blame] | 897 | get type(): string { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 898 | return this._type; |
| 899 | }, |
| 900 | |
Jan Scheffler | d76b416 | 2021-03-29 07:52:16 | [diff] [blame] | 901 | getContent: function(callback: any): void { |
| 902 | function callbackWrapper(response: any): void { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 903 | callback(response.content, response.encoding); |
| 904 | } |
| 905 | |
Philip Pfaffe | 939605d | 2021-06-25 12:20:04 | [diff] [blame] | 906 | extensionServer.sendRequest( |
| 907 | {command: PrivateAPI.Commands.GetResourceContent, url: this._url}, callback && callbackWrapper); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 908 | }, |
| 909 | |
Jan Scheffler | d76b416 | 2021-03-29 07:52:16 | [diff] [blame] | 910 | setContent: function(content: any, commit: any, callback: any): void { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 911 | extensionServer.sendRequest( |
Philip Pfaffe | 939605d | 2021-06-25 12:20:04 | [diff] [blame] | 912 | {command: PrivateAPI.Commands.SetResourceContent, url: this._url, content: content, commit: commit}, |
| 913 | callback); |
Jan Scheffler | d76b416 | 2021-03-29 07:52:16 | [diff] [blame] | 914 | }, |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 915 | }; |
| 916 | |
Jan Scheffler | d76b416 | 2021-03-29 07:52:16 | [diff] [blame] | 917 | function getTabId(): string { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 918 | return inspectedTabId; |
| 919 | } |
| 920 | |
Philip Pfaffe | 7523faf | 2021-06-28 14:23:14 | [diff] [blame^] | 921 | let keyboardEventRequestQueue: KeyboardEventInit&{eventType: string}[] = []; |
Jan Scheffler | d76b416 | 2021-03-29 07:52:16 | [diff] [blame] | 922 | let forwardTimer: number|null = null; |
Philip Pfaffe | 7523faf | 2021-06-28 14:23:14 | [diff] [blame^] | 923 | function forwardKeyboardEvent(event: KeyboardEvent): void { |
Jan Scheffler | e7d7bb1 | 2019-10-24 09:18:52 | [diff] [blame] | 924 | // Check if the event should be forwarded. |
| 925 | // This is a workaround for crbug.com/923338. |
| 926 | const focused = document.activeElement; |
| 927 | if (focused) { |
| 928 | const isInput = focused.nodeName === 'INPUT' || focused.nodeName === 'TEXTAREA'; |
| 929 | if (isInput && !(event.ctrlKey || event.altKey || event.metaKey)) { |
| 930 | return; |
| 931 | } |
| 932 | } |
| 933 | |
Joel Einbinder | 67f28fb | 2018-08-02 00:33:47 | [diff] [blame] | 934 | let modifiers = 0; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 935 | if (event.shiftKey) { |
Joel Einbinder | 67f28fb | 2018-08-02 00:33:47 | [diff] [blame] | 936 | modifiers |= 1; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 937 | } |
| 938 | if (event.ctrlKey) { |
Joel Einbinder | 67f28fb | 2018-08-02 00:33:47 | [diff] [blame] | 939 | modifiers |= 2; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 940 | } |
| 941 | if (event.altKey) { |
Joel Einbinder | 67f28fb | 2018-08-02 00:33:47 | [diff] [blame] | 942 | modifiers |= 4; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 943 | } |
| 944 | if (event.metaKey) { |
Joel Einbinder | 67f28fb | 2018-08-02 00:33:47 | [diff] [blame] | 945 | modifiers |= 8; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 946 | } |
Joel Einbinder | 67f28fb | 2018-08-02 00:33:47 | [diff] [blame] | 947 | const num = (event.keyCode & 255) | (modifiers << 8); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 948 | // We only care about global hotkeys, not about random text |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 949 | if (!keysToForwardSet.has(num)) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 950 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 951 | } |
Joel Einbinder | 67f28fb | 2018-08-02 00:33:47 | [diff] [blame] | 952 | event.preventDefault(); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 953 | const requestPayload = { |
| 954 | eventType: event.type, |
| 955 | ctrlKey: event.ctrlKey, |
| 956 | altKey: event.altKey, |
| 957 | metaKey: event.metaKey, |
Joel Einbinder | 67f28fb | 2018-08-02 00:33:47 | [diff] [blame] | 958 | shiftKey: event.shiftKey, |
Philip Pfaffe | 7523faf | 2021-06-28 14:23:14 | [diff] [blame^] | 959 | // @ts-expect-error keyIdentifier is a deprecated non-standard property that typescript doesn't know about. |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 960 | keyIdentifier: event.keyIdentifier, |
| 961 | key: event.key, |
| 962 | code: event.code, |
| 963 | location: event.location, |
Jan Scheffler | d76b416 | 2021-03-29 07:52:16 | [diff] [blame] | 964 | keyCode: event.keyCode, |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 965 | }; |
| 966 | keyboardEventRequestQueue.push(requestPayload); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 967 | if (!forwardTimer) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 968 | forwardTimer = setTimeout(forwardEventQueue, 0); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 969 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 970 | } |
| 971 | |
Jan Scheffler | d76b416 | 2021-03-29 07:52:16 | [diff] [blame] | 972 | function forwardEventQueue(): void { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 973 | forwardTimer = null; |
Philip Pfaffe | 7523faf | 2021-06-28 14:23:14 | [diff] [blame^] | 974 | extensionServer.sendRequest( |
| 975 | {command: PrivateAPI.Commands.ForwardKeyboardEvent, entries: keyboardEventRequestQueue}); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 976 | keyboardEventRequestQueue = []; |
| 977 | } |
| 978 | |
| 979 | document.addEventListener('keydown', forwardKeyboardEvent, false); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 980 | |
| 981 | /** |
| 982 | * @constructor |
| 983 | */ |
Philip Pfaffe | 7523faf | 2021-06-28 14:23:14 | [diff] [blame^] | 984 | function ExtensionServerClient(this: APIImpl.ExtensionServerClient): void { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 985 | this._callbacks = {}; |
| 986 | this._handlers = {}; |
| 987 | this._lastRequestId = 0; |
| 988 | this._lastObjectId = 0; |
| 989 | |
| 990 | this.registerHandler('callback', this._onCallback.bind(this)); |
| 991 | |
| 992 | const channel = new MessageChannel(); |
| 993 | this._port = channel.port1; |
| 994 | this._port.addEventListener('message', this._onMessage.bind(this), false); |
| 995 | this._port.start(); |
| 996 | |
| 997 | window.parent.postMessage('registerExtension', '*', [channel.port2]); |
| 998 | } |
| 999 | |
Philip Pfaffe | 7523faf | 2021-06-28 14:23:14 | [diff] [blame^] | 1000 | (ExtensionServerClient.prototype as Pick< |
| 1001 | APIImpl.ExtensionServerClient, |
| 1002 | 'sendRequest'|'hasHandler'|'registerHandler'|'unregisterHandler'|'nextObjectId'|'_registerCallback'| |
| 1003 | '_onCallback'|'_onMessage'>) = { |
| 1004 | sendRequest: function( |
| 1005 | this: APIImpl.ExtensionServerClient, message: PrivateAPI.ServerRequests, |
| 1006 | callback?: (response: unknown) => unknown, transfers?: Transferable[]): void { |
| 1007 | if (typeof callback === 'function') { |
| 1008 | (message as PrivateAPI.ExtensionServerRequestMessage).requestId = this._registerCallback(callback); |
| 1009 | } |
| 1010 | // @ts-expect-error |
| 1011 | this._port.postMessage(message, transfers); |
| 1012 | }, |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1013 | |
Philip Pfaffe | 7523faf | 2021-06-28 14:23:14 | [diff] [blame^] | 1014 | hasHandler: function(this: APIImpl.ExtensionServerClient, command: string): boolean { |
Tim van der Lippe | d7cfd14 | 2021-01-07 12:17:24 | [diff] [blame] | 1015 | return Boolean(this._handlers[command]); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1016 | }, |
| 1017 | |
Philip Pfaffe | 7523faf | 2021-06-28 14:23:14 | [diff] [blame^] | 1018 | registerHandler: function( |
| 1019 | this: APIImpl.ExtensionServerClient, command: string, handler: (request: {arguments: unknown[]}) => unknown): |
| 1020 | void { |
| 1021 | this._handlers[command] = handler; |
| 1022 | }, |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1023 | |
Philip Pfaffe | 7523faf | 2021-06-28 14:23:14 | [diff] [blame^] | 1024 | unregisterHandler: function(this: APIImpl.ExtensionServerClient, command: string): void { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1025 | delete this._handlers[command]; |
| 1026 | }, |
| 1027 | |
Philip Pfaffe | 7523faf | 2021-06-28 14:23:14 | [diff] [blame^] | 1028 | nextObjectId: function(this: APIImpl.ExtensionServerClient): string { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1029 | return injectedScriptId.toString() + '_' + ++this._lastObjectId; |
| 1030 | }, |
| 1031 | |
Philip Pfaffe | 7523faf | 2021-06-28 14:23:14 | [diff] [blame^] | 1032 | _registerCallback: function(this: APIImpl.ExtensionServerClient, callback: (response: unknown) => unknown): number { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1033 | const id = ++this._lastRequestId; |
| 1034 | this._callbacks[id] = callback; |
| 1035 | return id; |
| 1036 | }, |
| 1037 | |
Philip Pfaffe | 7523faf | 2021-06-28 14:23:14 | [diff] [blame^] | 1038 | _onCallback: function(this: APIImpl.ExtensionServerClient, request: {requestId: number, result: unknown}): void { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1039 | if (request.requestId in this._callbacks) { |
| 1040 | const callback = this._callbacks[request.requestId]; |
| 1041 | delete this._callbacks[request.requestId]; |
| 1042 | callback(request.result); |
| 1043 | } |
| 1044 | }, |
| 1045 | |
Philip Pfaffe | 7523faf | 2021-06-28 14:23:14 | [diff] [blame^] | 1046 | _onMessage: function( |
| 1047 | this: APIImpl.ExtensionServerClient, |
| 1048 | event: MessageEvent<{command: string, requestId: number, arguments: unknown[]}>): void { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1049 | const request = event.data; |
| 1050 | const handler = this._handlers[request.command]; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1051 | if (handler) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1052 | handler.call(this, request); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1053 | } |
Jan Scheffler | d76b416 | 2021-03-29 07:52:16 | [diff] [blame] | 1054 | }, |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1055 | }; |
| 1056 | |
Philip Pfaffe | 7523faf | 2021-06-28 14:23:14 | [diff] [blame^] | 1057 | function populateInterfaceClass(interfaze: {[key: string]: unknown}, implementation: {[key: string]: unknown}): void { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1058 | for (const member in implementation) { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1059 | if (member.charAt(0) === '_') { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1060 | continue; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1061 | } |
Jan Scheffler | d76b416 | 2021-03-29 07:52:16 | [diff] [blame] | 1062 | let descriptor: (PropertyDescriptor|undefined)|null = null; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1063 | // Traverse prototype chain until we find the owner. |
Philip Pfaffe | 7523faf | 2021-06-28 14:23:14 | [diff] [blame^] | 1064 | for (let owner = implementation; owner && !descriptor; owner = owner.__proto__ as {[key: string]: unknown}) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1065 | descriptor = Object.getOwnPropertyDescriptor(owner, member); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1066 | } |
| 1067 | if (!descriptor) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1068 | continue; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1069 | } |
| 1070 | if (typeof descriptor.value === 'function') { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1071 | interfaze[member] = descriptor.value.bind(implementation); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1072 | } else if (typeof descriptor.get === 'function') { |
Philip Pfaffe | 7523faf | 2021-06-28 14:23:14 | [diff] [blame^] | 1073 | // @ts-expect-error |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1074 | interfaze.__defineGetter__(member, descriptor.get.bind(implementation)); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1075 | } else { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1076 | Object.defineProperty(interfaze, member, descriptor); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1077 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1078 | } |
| 1079 | } |
| 1080 | |
Philip Pfaffe | 7523faf | 2021-06-28 14:23:14 | [diff] [blame^] | 1081 | |
| 1082 | const extensionServer = new (Constructor(ExtensionServerClient))(); |
| 1083 | |
| 1084 | const coreAPI = new (Constructor(InspectorExtensionAPI))(); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1085 | |
| 1086 | Object.defineProperty(chrome, 'devtools', {value: {}, enumerable: true}); |
| 1087 | |
| 1088 | // Only expose tabId on chrome.devtools.inspectedWindow, not webInspector.inspectedWindow. |
Philip Pfaffe | 7523faf | 2021-06-28 14:23:14 | [diff] [blame^] | 1089 | // @ts-expect-error |
| 1090 | chrome.devtools!.inspectedWindow = {}; |
| 1091 | Object.defineProperty(chrome.devtools!.inspectedWindow, 'tabId', {get: getTabId}); |
| 1092 | // @ts-expect-error |
| 1093 | chrome.devtools!.inspectedWindow.__proto__ = coreAPI.inspectedWindow; |
| 1094 | chrome.devtools!.network = coreAPI.network; |
| 1095 | chrome.devtools!.panels = coreAPI.panels; |
| 1096 | chrome.devtools!.panels.themeName = themeName; |
| 1097 | chrome.devtools!.languageServices = coreAPI.languageServices; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1098 | |
| 1099 | // default to expose experimental APIs for now. |
| 1100 | if (extensionInfo.exposeExperimentalAPIs !== false) { |
| 1101 | chrome.experimental = chrome.experimental || {}; |
| 1102 | chrome.experimental.devtools = chrome.experimental.devtools || {}; |
| 1103 | |
| 1104 | const properties = Object.getOwnPropertyNames(coreAPI); |
| 1105 | for (let i = 0; i < properties.length; ++i) { |
| 1106 | const descriptor = Object.getOwnPropertyDescriptor(coreAPI, properties[i]); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1107 | if (descriptor) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1108 | Object.defineProperty(chrome.experimental.devtools, properties[i], descriptor); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1109 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1110 | } |
| 1111 | chrome.experimental.devtools.inspectedWindow = chrome.devtools.inspectedWindow; |
| 1112 | } |
| 1113 | |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1114 | if (extensionInfo.exposeWebInspectorNamespace) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1115 | window.webInspector = coreAPI; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1116 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1117 | testHook(extensionServer, coreAPI); |
Tim van der Lippe | 226fc22 | 2019-10-10 12:17:12 | [diff] [blame] | 1118 | }; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1119 | |
Jan Scheffler | d76b416 | 2021-03-29 07:52:16 | [diff] [blame] | 1120 | self.buildExtensionAPIInjectedScript = function( |
| 1121 | extensionInfo: { |
| 1122 | startPage: string, |
| 1123 | name: string, |
| 1124 | exposeExperimentalAPIs: boolean, |
| 1125 | }, |
| 1126 | inspectedTabId: string, themeName: string, keysToForward: number[], |
Philip Pfaffe | 7523faf | 2021-06-28 14:23:14 | [diff] [blame^] | 1127 | testHook: |
| 1128 | ((extensionServer: APIImpl.ExtensionServerClient, extensionAPI: APIImpl.InspectorExtensionAPI) => unknown)| |
| 1129 | undefined): string { |
Philip Pfaffe | edad832 | 2020-07-20 10:24:25 | [diff] [blame] | 1130 | const argumentsJSON = |
| 1131 | [extensionInfo, inspectedTabId || null, themeName, keysToForward].map(_ => JSON.stringify(_)).join(','); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1132 | if (!testHook) { |
Jan Scheffler | d76b416 | 2021-03-29 07:52:16 | [diff] [blame] | 1133 | testHook = (): void => {}; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1134 | } |
Philip Pfaffe | 939605d | 2021-06-25 12:20:04 | [diff] [blame] | 1135 | return '(function(injectedScriptId){ ' + |
Tim van der Lippe | 226fc22 | 2019-10-10 12:17:12 | [diff] [blame] | 1136 | '(' + self.injectedExtensionAPI.toString() + ')(' + argumentsJSON + ',' + testHook + ', injectedScriptId);' + |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1137 | '})'; |
Tim van der Lippe | 29fab47 | 2019-08-15 14:46:48 | [diff] [blame] | 1138 | }; |