refactor: simplify process object initialization for sandboxed renderers (#14878)
Also fix `process.windowsStore`.
This commit is contained in:
parent
0127bbc8e8
commit
ce38be74df
5 changed files with 45 additions and 43 deletions
|
@ -3,6 +3,7 @@
|
|||
/* eslint no-eval: "off" */
|
||||
/* global binding, Buffer */
|
||||
const events = require('events')
|
||||
const { EventEmitter } = events
|
||||
|
||||
process.atomBinding = require('@electron/internal/common/atom-binding-setup')(binding.get, 'renderer')
|
||||
|
||||
|
@ -15,15 +16,15 @@ const v8Util = process.atomBinding('v8_util')
|
|||
v8Util.setHiddenValue(global, 'Buffer', Buffer)
|
||||
// The `lib/renderer/api/ipc-renderer.js` module looks for the ipc object in the
|
||||
// "ipc" hidden value
|
||||
v8Util.setHiddenValue(global, 'ipc', new events.EventEmitter())
|
||||
v8Util.setHiddenValue(global, 'ipc', new EventEmitter())
|
||||
// The process object created by browserify is not an event emitter, fix it so
|
||||
// the API is more compatible with non-sandboxed renderers.
|
||||
for (let prop of Object.keys(events.EventEmitter.prototype)) {
|
||||
for (let prop of Object.keys(EventEmitter.prototype)) {
|
||||
if (process.hasOwnProperty(prop)) {
|
||||
delete process[prop]
|
||||
}
|
||||
}
|
||||
Object.setPrototypeOf(process, events.EventEmitter.prototype)
|
||||
Object.setPrototypeOf(process, EventEmitter.prototype)
|
||||
|
||||
const remoteModules = new Set([
|
||||
'child_process',
|
||||
|
@ -47,24 +48,12 @@ require('@electron/internal/renderer/web-frame-init')()
|
|||
|
||||
// Pass different process object to the preload script(which should not have
|
||||
// access to things like `process.atomBinding`).
|
||||
const preloadProcess = new events.EventEmitter()
|
||||
preloadProcess.crash = () => binding.crash()
|
||||
preloadProcess.hang = () => binding.hang()
|
||||
preloadProcess.getHeapStatistics = () => binding.getHeapStatistics()
|
||||
preloadProcess.getSystemMemoryInfo = () => binding.getSystemMemoryInfo()
|
||||
preloadProcess.getCPUUsage = () => binding.getCPUUsage()
|
||||
preloadProcess.getIOCounters = () => binding.getIOCounters()
|
||||
|
||||
Object.assign(processProps, {
|
||||
argv: binding.getArgv(),
|
||||
execPath: binding.getExecPath(),
|
||||
pid: binding.getPid(),
|
||||
resourcesPath: binding.getResourcesPath(),
|
||||
sandboxed: true,
|
||||
type: 'renderer'
|
||||
})
|
||||
const preloadProcess = new EventEmitter()
|
||||
|
||||
Object.assign(preloadProcess, binding.process)
|
||||
Object.assign(preloadProcess, processProps)
|
||||
|
||||
Object.assign(process, binding.process)
|
||||
Object.assign(process, processProps)
|
||||
|
||||
process.on('exit', () => preloadProcess.emit('exit'))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue