2021-01-15 00:00:37 +00:00
|
|
|
import { MessagePortMain } from '@electron/internal/browser/message-port-main';
|
2022-08-03 23:55:12 +00:00
|
|
|
import { IpcMainImpl } from '@electron/internal/browser/ipc-main-impl';
|
2021-01-15 00:00:37 +00:00
|
|
|
|
|
|
|
const { WebFrameMain, fromId } = process._linkedBinding('electron_browser_web_frame_main');
|
|
|
|
|
2022-08-03 23:55:12 +00:00
|
|
|
Object.defineProperty(WebFrameMain.prototype, 'ipc', {
|
|
|
|
get () {
|
|
|
|
const ipc = new IpcMainImpl();
|
|
|
|
Object.defineProperty(this, 'ipc', { value: ipc });
|
|
|
|
return ipc;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2021-01-15 00:00:37 +00:00
|
|
|
WebFrameMain.prototype.send = function (channel, ...args) {
|
|
|
|
if (typeof channel !== 'string') {
|
|
|
|
throw new Error('Missing required channel argument');
|
|
|
|
}
|
|
|
|
|
2021-10-14 16:44:44 +00:00
|
|
|
try {
|
|
|
|
return this._send(false /* internal */, channel, args);
|
|
|
|
} catch (e) {
|
|
|
|
console.error('Error sending from webFrameMain: ', e);
|
|
|
|
}
|
2021-01-15 00:00:37 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
WebFrameMain.prototype._sendInternal = function (channel, ...args) {
|
|
|
|
if (typeof channel !== 'string') {
|
|
|
|
throw new Error('Missing required channel argument');
|
|
|
|
}
|
|
|
|
|
2021-10-14 16:44:44 +00:00
|
|
|
try {
|
|
|
|
return this._send(true /* internal */, channel, args);
|
|
|
|
} catch (e) {
|
|
|
|
console.error('Error sending from webFrameMain: ', e);
|
|
|
|
}
|
2021-01-15 00:00:37 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
WebFrameMain.prototype.postMessage = function (...args) {
|
|
|
|
if (Array.isArray(args[2])) {
|
|
|
|
args[2] = args[2].map(o => o instanceof MessagePortMain ? o._internalPort : o);
|
|
|
|
}
|
|
|
|
this._postMessage(...args);
|
|
|
|
};
|
2020-10-09 16:50:46 +00:00
|
|
|
|
|
|
|
export default {
|
|
|
|
fromId
|
|
|
|
};
|