From 55c66e3e925fca7341368dc89880dac062b4e628 Mon Sep 17 00:00:00 2001 From: Milan Burda Date: Fri, 2 Apr 2021 23:34:28 +0200 Subject: [PATCH] chore: add types for electron_renderer_web_frame binding (#28455) * chore: add types for electron_renderer_web_frame binding * chore: use keyof for getWebPreference type Co-authored-by: Samuel Attard --- lib/renderer/api/web-frame.ts | 16 ++++++++-------- typings/internal-ambient.d.ts | 28 ++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 8 deletions(-) diff --git a/lib/renderer/api/web-frame.ts b/lib/renderer/api/web-frame.ts index 05faf2f9c187..46bf32ca5cb5 100644 --- a/lib/renderer/api/web-frame.ts +++ b/lib/renderer/api/web-frame.ts @@ -11,16 +11,16 @@ class WebFrame extends EventEmitter { this.setMaxListeners(0); } - findFrameByRoutingId (...args: Array) { - return getWebFrame(binding._findFrameByRoutingId(this.context, ...args)); + findFrameByRoutingId (routingId: number) { + return getWebFrame(binding._findFrameByRoutingId(this.context, routingId)); } - getFrameForSelector (...args: Array) { - return getWebFrame(binding._getFrameForSelector(this.context, ...args)); + getFrameForSelector (selector: string) { + return getWebFrame(binding._getFrameForSelector(this.context, selector)); } - findFrameByName (...args: Array) { - return getWebFrame(binding._findFrameByName(this.context, ...args)); + findFrameByName (name: string) { + return getWebFrame(binding._findFrameByName(this.context, name)); } get opener () { @@ -62,12 +62,12 @@ for (const name in binding) { if (!worldSafeJS && name.startsWith('executeJavaScript')) { deprecate.log(`Security Warning: webFrame.${name} was called without worldSafeExecuteJavaScript enabled. This is considered unsafe. worldSafeExecuteJavaScript will be enabled by default in Electron 12.`); } - return binding[name](this.context, ...args); + return (binding as any)[name](this.context, ...args); }; // TODO(MarshallOfSound): Remove once the above deprecation is removed if (name.startsWith('executeJavaScript')) { (WebFrame as any).prototype[`_${name}`] = function (...args: Array) { - return binding[name](this.context, ...args); + return (binding as any)[name](this.context, ...args); }; } } diff --git a/typings/internal-ambient.d.ts b/typings/internal-ambient.d.ts index c97d0864f165..debd09ca2489 100644 --- a/typings/internal-ambient.d.ts +++ b/typings/internal-ambient.d.ts @@ -101,6 +101,33 @@ declare namespace NodeJS { removeGuest(embedder: Electron.WebContents, guestInstanceId: number): void; } + interface InternalWebPreferences { + contextIsolation: boolean; + disableElectronSiteInstanceOverrides: boolean; + guestInstanceId: number; + hiddenPage: boolean; + nativeWindowOpen: boolean; + nodeIntegration: boolean; + openerId: number; + preload: string + preloadScripts: string[]; + webviewTag: boolean; + worldSafeExecuteJavaScript: boolean; + } + + interface WebFrameBinding { + _findFrameByRoutingId(window: Window, routingId: number): Window; + _getFrameForSelector(window: Window, selector: string): Window; + _findFrameByName(window: Window, name: string): Window; + _getOpener(window: Window): Window; + _getParent(window: Window): Window; + _getTop(window: Window): Window; + _getFirstChild(window: Window): Window; + _getNextSibling(window: Window): Window; + _getRoutingId(window: Window): number; + getWebPreference(window: Window, name: K): InternalWebPreferences[K]; + } + type DataPipe = { write: (buf: Uint8Array) => Promise; done: () => void; @@ -218,6 +245,7 @@ declare namespace NodeJS { } _linkedBinding(name: 'electron_renderer_crash_reporter'): Electron.CrashReporter; _linkedBinding(name: 'electron_renderer_ipc'): { ipc: IpcRendererBinding }; + _linkedBinding(name: 'electron_renderer_web_frame'): WebFrameBinding; log: NodeJS.WriteStream['write']; activateUvLoop(): void;