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 <sattard@slack-corp.com>
This commit is contained in:
Milan Burda 2021-04-02 23:34:28 +02:00 committed by GitHub
parent 9904438118
commit 55c66e3e92
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 36 additions and 8 deletions

View file

@ -11,16 +11,16 @@ class WebFrame extends EventEmitter {
this.setMaxListeners(0);
}
findFrameByRoutingId (...args: Array<any>) {
return getWebFrame(binding._findFrameByRoutingId(this.context, ...args));
findFrameByRoutingId (routingId: number) {
return getWebFrame(binding._findFrameByRoutingId(this.context, routingId));
}
getFrameForSelector (...args: Array<any>) {
return getWebFrame(binding._getFrameForSelector(this.context, ...args));
getFrameForSelector (selector: string) {
return getWebFrame(binding._getFrameForSelector(this.context, selector));
}
findFrameByName (...args: Array<any>) {
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<any>) {
return binding[name](this.context, ...args);
return (binding as any)[name](this.context, ...args);
};
}
}

View file

@ -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<K extends keyof InternalWebPreferences>(window: Window, name: K): InternalWebPreferences[K];
}
type DataPipe = {
write: (buf: Uint8Array) => Promise<void>;
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;