chore: remove unused sendToAll + related APIs (#26771) (#27354)

This commit is contained in:
Milan Burda
2021-01-19 07:49:54 +01:00
committed by GitHub
parent c74780117e
commit a6af3bd8df
14 changed files with 24 additions and 97 deletions

View File

@@ -131,10 +131,7 @@ WebContents.prototype.send = function (channel, ...args) {
throw new Error('Missing required channel argument');
}
const internal = false;
const sendToAll = false;
return this._send(internal, sendToAll, channel, args);
return this._send(false /* internal */, channel, args);
};
WebContents.prototype.postMessage = function (...args) {
@@ -149,20 +146,7 @@ WebContents.prototype._sendInternal = function (channel, ...args) {
throw new Error('Missing required channel argument');
}
const internal = true;
const sendToAll = false;
return this._send(internal, sendToAll, channel, args);
};
WebContents.prototype._sendInternalToAll = function (channel, ...args) {
if (typeof channel !== 'string') {
throw new Error('Missing required channel argument');
}
const internal = true;
const sendToAll = true;
return this._send(internal, sendToAll, channel, args);
return this._send(true /* internal */, channel, args);
};
WebContents.prototype.sendToFrame = function (frame, channel, ...args) {
if (typeof channel !== 'string') {
@@ -171,10 +155,7 @@ WebContents.prototype.sendToFrame = function (frame, channel, ...args) {
throw new Error('Missing required frame argument (must be number or array)');
}
const internal = false;
const sendToAll = false;
return this._sendToFrame(internal, sendToAll, frame, channel, args);
return this._sendToFrame(false /* internal */, frame, channel, args);
};
WebContents.prototype._sendToFrameInternal = function (frame, channel, ...args) {
if (typeof channel !== 'string') {
@@ -183,10 +164,7 @@ WebContents.prototype._sendToFrameInternal = function (frame, channel, ...args)
throw new Error('Missing required frame argument (must be number or array)');
}
const internal = true;
const sendToAll = false;
return this._sendToFrame(internal, sendToAll, frame, channel, args);
return this._sendToFrame(true /* internal */, frame, channel, args);
};
// Following methods are mapped to webFrame.
@@ -199,7 +177,7 @@ const webFrameMethods = [
for (const method of webFrameMethods) {
WebContents.prototype[method] = function (...args: any[]): Promise<any> {
return ipcMainUtils.invokeInWebContents(this, false, IPC_MESSAGES.RENDERER_WEB_FRAME_METHOD, method, ...args);
return ipcMainUtils.invokeInWebContents(this, IPC_MESSAGES.RENDERER_WEB_FRAME_METHOD, method, ...args);
};
}
@@ -217,11 +195,11 @@ const waitTillCanExecuteJavaScript = async (webContents: Electron.WebContents) =
// WebContents has been loaded.
WebContents.prototype.executeJavaScript = async function (code, hasUserGesture) {
await waitTillCanExecuteJavaScript(this);
return ipcMainUtils.invokeInWebContents(this, false, IPC_MESSAGES.RENDERER_WEB_FRAME_METHOD, 'executeJavaScript', String(code), !!hasUserGesture);
return ipcMainUtils.invokeInWebContents(this, IPC_MESSAGES.RENDERER_WEB_FRAME_METHOD, 'executeJavaScript', String(code), !!hasUserGesture);
};
WebContents.prototype.executeJavaScriptInIsolatedWorld = async function (worldId, code, hasUserGesture) {
await waitTillCanExecuteJavaScript(this);
return ipcMainUtils.invokeInWebContents(this, false, IPC_MESSAGES.RENDERER_WEB_FRAME_METHOD, 'executeJavaScriptInIsolatedWorld', worldId, code, !!hasUserGesture);
return ipcMainUtils.invokeInWebContents(this, IPC_MESSAGES.RENDERER_WEB_FRAME_METHOD, 'executeJavaScriptInIsolatedWorld', worldId, code, !!hasUserGesture);
};
// Translate the options of printToPDF.

View File

@@ -14,7 +14,7 @@ export const handleSync = function <T extends IPCHandler> (channel: string, hand
let nextId = 0;
export function invokeInWebContents<T> (sender: Electron.WebContents, sendToAll: boolean, command: string, ...args: any[]) {
export function invokeInWebContents<T> (sender: Electron.WebContents, command: string, ...args: any[]) {
return new Promise<T>((resolve, reject) => {
const requestId = ++nextId;
const channel = `${command}_RESPONSE_${requestId}`;
@@ -33,10 +33,6 @@ export function invokeInWebContents<T> (sender: Electron.WebContents, sendToAll:
}
});
if (sendToAll) {
sender._sendInternalToAll(command, requestId, ...args);
} else {
sender._sendInternal(command, requestId, ...args);
}
sender._sendInternal(command, requestId, ...args);
});
}

View File

@@ -18,7 +18,7 @@ ipcRenderer.sendToHost = function (channel, ...args) {
};
ipcRenderer.sendTo = function (webContentsId, channel, ...args) {
return ipc.sendTo(internal, false, webContentsId, channel, args);
return ipc.sendTo(internal, webContentsId, channel, args);
};
ipcRenderer.invoke = async function (channel, ...args) {

View File

@@ -14,11 +14,7 @@ ipcRendererInternal.sendSync = function (channel, ...args) {
};
ipcRendererInternal.sendTo = function (webContentsId, channel, ...args) {
return ipc.sendTo(internal, false, webContentsId, channel, args);
};
ipcRendererInternal.sendToAll = function (webContentsId, channel, ...args) {
return ipc.sendTo(internal, true, webContentsId, channel, args);
return ipc.sendTo(internal, webContentsId, channel, args);
};
ipcRendererInternal.invoke = async function<T> (channel: string, ...args: any[]) {