refactor: use separate ipc-renderer-internal / ipc-main-internal APIs for Electron internals (#13940)

This commit is contained in:
Milan Burda 2018-10-06 13:48:00 +02:00 committed by Samuel Attard
parent f7122610cc
commit b50f86ef43
49 changed files with 322 additions and 133 deletions

View file

@ -8,8 +8,9 @@ const os = require('os')
const path = require('path')
const v8Util = process.atomBinding('v8_util')
const { ipcMain, isPromise } = electron
const { isPromise } = electron
const ipcMain = require('@electron/internal/browser/ipc-main-internal')
const objectsRegistry = require('@electron/internal/browser/objects-registry')
const bufferUtils = require('@electron/internal/common/buffer-utils')
const errorUtils = require('@electron/internal/common/error-utils')
@ -215,7 +216,7 @@ const unwrapArgs = function (sender, contextId, args) {
const processId = sender.getProcessId()
const callIntoRenderer = function (...args) {
if (!sender.isDestroyed() && processId === sender.getProcessId()) {
sender.send('ELECTRON_RENDERER_CALLBACK', contextId, meta.id, valueToMeta(sender, contextId, args))
sender._sendInternal('ELECTRON_RENDERER_CALLBACK', contextId, meta.id, valueToMeta(sender, contextId, args))
} else {
removeRemoteListenersAndLogWarning(this, meta, callIntoRenderer)
}
@ -390,7 +391,7 @@ ipcMain.on('ELECTRON_BROWSER_ASYNC_CALL_TO_GUEST_VIEW', function (event, request
}, error => {
return [errorUtils.serialize(error)]
}).then(responseArgs => {
event.sender.send(`ELECTRON_RENDERER_ASYNC_CALL_TO_GUEST_VIEW_RESPONSE_${requestId}`, ...responseArgs)
event.sender._sendInternal(`ELECTRON_RENDERER_ASYNC_CALL_TO_GUEST_VIEW_RESPONSE_${requestId}`, ...responseArgs)
})
})
@ -424,7 +425,7 @@ const getTempDirectory = function () {
}
}
ipcMain.on('ELECTRON_CRASH_REPORTER_INIT', function (event, options) {
const crashReporterInit = function (options) {
const productName = options.productName || electron.app.getName()
const crashesDirectory = path.join(getTempDirectory(), `${productName} Crashes`)
@ -445,11 +446,19 @@ ipcMain.on('ELECTRON_CRASH_REPORTER_INIT', function (event, options) {
})
}
event.returnValue = {
return {
productName,
crashesDirectory,
appVersion: electron.app.getVersion()
}
}
ipcMain.on('ELECTRON_CRASH_REPORTER_INIT', function (event, options) {
try {
event.returnValue = [null, crashReporterInit(options)]
} catch (error) {
event.returnValue = [errorUtils.serialize(error)]
}
})
ipcMain.on('ELECTRON_BROWSER_SANDBOX_LOAD', function (event) {