Refactor sandbox preload initialization. (#12877)

Use a single synchronous IPC call to retrieve data required by early
sandbox scripts. This has two purposes:

- Optimize preload script initialization by:
  - Using one synchronous IPC call to retrieve preload script,
  webContentsId (more on that later), process.{platform,execPath,env}
  - Lazy loading as many modules as possible.
- Fix #12316 for sandbox. @MarshallOfSound addressed the issue in
  #12342, but it was still present in sandbox mode. By loading
  webContentsId very early and skipping remote module at early
  startup, we fix it for sandbox.
This commit is contained in:
Thiago de Arruda 2018-05-21 09:56:05 -03:00 committed by Samuel Attard
parent ef7947d176
commit 6f076f7433
3 changed files with 62 additions and 21 deletions

View file

@ -306,10 +306,13 @@ exports.getCurrentWebContents = () => {
const CONTEXT_ARG = '--context-id='
let initialContext = process.argv.find(arg => arg.startsWith(CONTEXT_ARG))
if (initialContext) {
if (process.webContentsId) {
// set by sandbox renderer init script
initialContext = process.webContentsId
} else if (initialContext) {
initialContext = parseInt(initialContext.substr(CONTEXT_ARG.length), 10)
} else {
// In sandbox we need to pull this from remote
// if not available, pull from remote
initialContext = exports.getCurrentWebContents().getId()
}