web-frame-main.ts 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import { IpcMainImpl } from '@electron/internal/browser/ipc-main-impl';
  2. import { MessagePortMain } from '@electron/internal/browser/message-port-main';
  3. const { WebFrameMain, fromId } = process._linkedBinding('electron_browser_web_frame_main');
  4. Object.defineProperty(WebFrameMain.prototype, 'ipc', {
  5. get () {
  6. const ipc = new IpcMainImpl();
  7. Object.defineProperty(this, 'ipc', { value: ipc });
  8. return ipc;
  9. }
  10. });
  11. WebFrameMain.prototype.send = function (channel, ...args) {
  12. if (typeof channel !== 'string') {
  13. throw new TypeError('Missing required channel argument');
  14. }
  15. try {
  16. return this._send(false /* internal */, channel, args);
  17. } catch (e) {
  18. console.error('Error sending from webFrameMain: ', e);
  19. }
  20. };
  21. WebFrameMain.prototype._sendInternal = function (channel, ...args) {
  22. if (typeof channel !== 'string') {
  23. throw new TypeError('Missing required channel argument');
  24. }
  25. try {
  26. return this._send(true /* internal */, channel, args);
  27. } catch (e) {
  28. console.error('Error sending from webFrameMain: ', e);
  29. }
  30. };
  31. WebFrameMain.prototype.postMessage = function (...args) {
  32. if (Array.isArray(args[2])) {
  33. args[2] = args[2].map(o => o instanceof MessagePortMain ? o._internalPort : o);
  34. }
  35. this._postMessage(...args);
  36. };
  37. export default {
  38. fromId
  39. };