mirror of
https://github.com/electron/electron.git
synced 2026-05-02 03:00:22 -04:00
refactor: pass internal flag via IPC message struct for consistency (#16490)
This commit is contained in:
committed by
Shelley Vohr
parent
0a5adfe365
commit
cc90919384
@@ -358,6 +358,13 @@ const addReplyInternalToEvent = (event) => {
|
||||
})
|
||||
}
|
||||
|
||||
const addReturnValueToEvent = (event) => {
|
||||
Object.defineProperty(event, 'returnValue', {
|
||||
set: (value) => event.sendReply([value]),
|
||||
get: () => {}
|
||||
})
|
||||
}
|
||||
|
||||
// Add JavaScript wrappers for WebContents class.
|
||||
WebContents.prototype._init = function () {
|
||||
// The navigation controller.
|
||||
@@ -370,38 +377,27 @@ WebContents.prototype._init = function () {
|
||||
this.capturePage = deprecate.promisify(this.capturePage, 2)
|
||||
|
||||
// Dispatch IPC messages to the ipc module.
|
||||
this.on('-ipc-message', function (event, [channel, ...args]) {
|
||||
addReplyToEvent(event)
|
||||
this.emit('ipc-message', event, channel, ...args)
|
||||
ipcMain.emit(channel, event, ...args)
|
||||
this.on('-ipc-message', function (event, internal, channel, args) {
|
||||
if (internal) {
|
||||
addReplyInternalToEvent(event)
|
||||
ipcMainInternal.emit(channel, event, ...args)
|
||||
} else {
|
||||
addReplyToEvent(event)
|
||||
this.emit('ipc-message', event, channel, ...args)
|
||||
ipcMain.emit(channel, event, ...args)
|
||||
}
|
||||
})
|
||||
|
||||
this.on('-ipc-message-sync', function (event, [channel, ...args]) {
|
||||
Object.defineProperty(event, 'returnValue', {
|
||||
set: function (value) {
|
||||
return event.sendReply([value])
|
||||
},
|
||||
get: function () {}
|
||||
})
|
||||
addReplyToEvent(event)
|
||||
this.emit('ipc-message-sync', event, channel, ...args)
|
||||
ipcMain.emit(channel, event, ...args)
|
||||
})
|
||||
|
||||
this.on('ipc-internal-message', function (event, [channel, ...args]) {
|
||||
addReplyInternalToEvent(event)
|
||||
ipcMainInternal.emit(channel, event, ...args)
|
||||
})
|
||||
|
||||
this.on('ipc-internal-message-sync', function (event, [channel, ...args]) {
|
||||
Object.defineProperty(event, 'returnValue', {
|
||||
set: function (value) {
|
||||
return event.sendReply([value])
|
||||
},
|
||||
get: function () {}
|
||||
})
|
||||
addReplyInternalToEvent(event)
|
||||
ipcMainInternal.emit(channel, event, ...args)
|
||||
this.on('-ipc-message-sync', function (event, internal, channel, args) {
|
||||
addReturnValueToEvent(event)
|
||||
if (internal) {
|
||||
addReplyInternalToEvent(event)
|
||||
ipcMainInternal.emit(channel, event, ...args)
|
||||
} else {
|
||||
addReplyToEvent(event)
|
||||
this.emit('ipc-message-sync', event, channel, ...args)
|
||||
ipcMain.emit(channel, event, ...args)
|
||||
}
|
||||
})
|
||||
|
||||
// Handle context menu action request from pepper plugin.
|
||||
|
||||
@@ -140,7 +140,7 @@ const createGuest = function (embedder, params) {
|
||||
}
|
||||
|
||||
// Dispatch guest's IPC messages to embedder.
|
||||
guest.on('ipc-message-host', function (_, [channel, ...args]) {
|
||||
guest.on('ipc-message-host', function (_, channel, args) {
|
||||
sendToEmbedder('ELECTRON_GUEST_VIEW_INTERNAL_IPC_MESSAGE', channel, ...args)
|
||||
})
|
||||
|
||||
|
||||
@@ -7,16 +7,16 @@ const v8Util = process.atomBinding('v8_util')
|
||||
const ipcRenderer = v8Util.getHiddenValue(global, 'ipc')
|
||||
const internal = false
|
||||
|
||||
ipcRenderer.send = function (...args) {
|
||||
return binding.send('-ipc-message', args)
|
||||
ipcRenderer.send = function (channel, ...args) {
|
||||
return binding.send(internal, channel, args)
|
||||
}
|
||||
|
||||
ipcRenderer.sendSync = function (...args) {
|
||||
return binding.sendSync('-ipc-message-sync', args)[0]
|
||||
ipcRenderer.sendSync = function (channel, ...args) {
|
||||
return binding.sendSync(internal, channel, args)[0]
|
||||
}
|
||||
|
||||
ipcRenderer.sendToHost = function (...args) {
|
||||
return binding.send('ipc-message-host', args)
|
||||
ipcRenderer.sendToHost = function (channel, ...args) {
|
||||
return binding.sendToHost(channel, args)
|
||||
}
|
||||
|
||||
ipcRenderer.sendTo = function (webContentsId, channel, ...args) {
|
||||
|
||||
@@ -7,12 +7,12 @@ const v8Util = process.atomBinding('v8_util')
|
||||
const ipcRenderer = v8Util.getHiddenValue(global, 'ipc-internal')
|
||||
const internal = true
|
||||
|
||||
ipcRenderer.send = function (...args) {
|
||||
return binding.send('ipc-internal-message', args)
|
||||
ipcRenderer.send = function (channel, ...args) {
|
||||
return binding.send(internal, channel, args)
|
||||
}
|
||||
|
||||
ipcRenderer.sendSync = function (...args) {
|
||||
return binding.sendSync('ipc-internal-message-sync', args)[0]
|
||||
ipcRenderer.sendSync = function (channel, ...args) {
|
||||
return binding.sendSync(internal, channel, args)[0]
|
||||
}
|
||||
|
||||
ipcRenderer.sendTo = function (webContentsId, channel, ...args) {
|
||||
|
||||
@@ -56,12 +56,12 @@ const loadedModules = new Map([
|
||||
const ipcNative = process.atomBinding('ipc')
|
||||
v8Util.setHiddenValue(global, 'ipcNative', ipcNative)
|
||||
|
||||
ipcNative.onInternalMessage = function (channel, args, senderId) {
|
||||
ipcRenderer.emit(channel, { sender: ipcRenderer, senderId }, ...args)
|
||||
}
|
||||
|
||||
ipcNative.onMessage = function (channel, args, senderId) {
|
||||
electron.ipcRenderer.emit(channel, { sender: electron.ipcRenderer, senderId }, ...args)
|
||||
ipcNative.onMessage = function (internal, channel, args, senderId) {
|
||||
if (internal) {
|
||||
ipcRenderer.emit(channel, { sender: ipcRenderer, senderId }, ...args)
|
||||
} else {
|
||||
electron.ipcRenderer.emit(channel, { sender: electron.ipcRenderer, senderId }, ...args)
|
||||
}
|
||||
}
|
||||
|
||||
ipcNative.onExit = function () {
|
||||
|
||||
Reference in New Issue
Block a user