electron/lib/content_script/init.js

38 lines
1.5 KiB
JavaScript
Raw Normal View History

2020-03-20 20:28:31 +00:00
'use strict';
/* global nodeProcess, isolatedWorld, worldId */
2020-03-20 20:28:31 +00:00
const { EventEmitter } = require('events');
2020-03-20 20:28:31 +00:00
process.electronBinding = require('@electron/internal/common/electron-binding-setup').electronBindingSetup(nodeProcess._linkedBinding, 'renderer');
2020-03-20 20:28:31 +00:00
const v8Util = process.electronBinding('v8_util');
// The `lib/renderer/ipc-renderer-internal.js` module looks for the ipc object in the
// "ipc-internal" hidden value
2020-03-20 20:28:31 +00:00
v8Util.setHiddenValue(global, 'ipc-internal', v8Util.getHiddenValue(isolatedWorld, 'ipc-internal'));
2019-06-02 20:03:03 +00:00
// The process object created by webpack is not an event emitter, fix it so
// the API is more compatible with non-sandboxed renderers.
for (const prop of Object.keys(EventEmitter.prototype)) {
if (Object.prototype.hasOwnProperty.call(process, prop)) {
2020-03-20 20:28:31 +00:00
delete process[prop];
}
}
2020-03-20 20:28:31 +00:00
Object.setPrototypeOf(process, EventEmitter.prototype);
2020-03-20 20:28:31 +00:00
const isolatedWorldArgs = v8Util.getHiddenValue(isolatedWorld, 'isolated-world-args');
if (isolatedWorldArgs) {
2020-03-20 20:28:31 +00:00
const { guestInstanceId, isHiddenPage, openerId, usesNativeWindowOpen, rendererProcessReuseEnabled } = isolatedWorldArgs;
const { windowSetup } = require('@electron/internal/renderer/window-setup');
windowSetup(guestInstanceId, openerId, isHiddenPage, usesNativeWindowOpen, rendererProcessReuseEnabled);
}
2020-03-20 20:28:31 +00:00
const extensionId = v8Util.getHiddenValue(isolatedWorld, `extension-${worldId}`);
if (extensionId) {
2020-03-20 20:28:31 +00:00
const chromeAPI = require('@electron/internal/renderer/chrome-api');
chromeAPI.injectTo(extensionId, window);
}