diff --git a/filenames.gypi b/filenames.gypi index e52caba89f03..351c59caa748 100644 --- a/filenames.gypi +++ b/filenames.gypi @@ -61,6 +61,7 @@ 'lib/renderer/api/desktop-capturer.js', 'lib/renderer/api/exports/electron.js', 'lib/renderer/api/ipc-renderer.js', + 'lib/renderer/api/ipc-renderer-setup.js', 'lib/renderer/api/remote.js', 'lib/renderer/api/screen.js', 'lib/renderer/api/web-frame.js', diff --git a/lib/renderer/api/ipc-renderer-setup.js b/lib/renderer/api/ipc-renderer-setup.js new file mode 100644 index 000000000000..c4459df2bf48 --- /dev/null +++ b/lib/renderer/api/ipc-renderer-setup.js @@ -0,0 +1,29 @@ +module.exports = function (ipcRenderer, binding) { + ipcRenderer.send = function (...args) { + return binding.send('ipc-message', args) + } + + ipcRenderer.sendSync = function (...args) { + return JSON.parse(binding.sendSync('ipc-message-sync', args)) + } + + ipcRenderer.sendToHost = function (...args) { + return binding.send('ipc-message-host', args) + } + + ipcRenderer.sendTo = function (webContentsId, channel, ...args) { + if (typeof webContentsId !== 'number') { + throw new TypeError('First argument has to be webContentsId') + } + + ipcRenderer.send('ELECTRON_BROWSER_SEND_TO', false, webContentsId, channel, ...args) + } + + ipcRenderer.sendToAll = function (webContentsId, channel, ...args) { + if (typeof webContentsId !== 'number') { + throw new TypeError('First argument has to be webContentsId') + } + + ipcRenderer.send('ELECTRON_BROWSER_SEND_TO', true, webContentsId, channel, ...args) + } +} diff --git a/lib/renderer/api/ipc-renderer.js b/lib/renderer/api/ipc-renderer.js index 66c40d311da2..0a84a0d8ba19 100644 --- a/lib/renderer/api/ipc-renderer.js +++ b/lib/renderer/api/ipc-renderer.js @@ -5,33 +5,6 @@ const v8Util = process.atomBinding('v8_util') // Created by init.js. const ipcRenderer = v8Util.getHiddenValue(global, 'ipc') - -ipcRenderer.send = function (...args) { - return binding.send('ipc-message', args) -} - -ipcRenderer.sendSync = function (...args) { - return JSON.parse(binding.sendSync('ipc-message-sync', args)) -} - -ipcRenderer.sendToHost = function (...args) { - return binding.send('ipc-message-host', args) -} - -ipcRenderer.sendTo = function (webContentsId, channel, ...args) { - if (typeof webContentsId !== 'number') { - throw new TypeError('First argument has to be webContentsId') - } - - ipcRenderer.send('ELECTRON_BROWSER_SEND_TO', false, webContentsId, channel, ...args) -} - -ipcRenderer.sendToAll = function (webContentsId, channel, ...args) { - if (typeof webContentsId !== 'number') { - throw new TypeError('First argument has to be webContentsId') - } - - ipcRenderer.send('ELECTRON_BROWSER_SEND_TO', true, webContentsId, channel, ...args) -} +require('./ipc-renderer-setup')(ipcRenderer, binding) module.exports = ipcRenderer