refactor: use getWebPreference() for all options (#26531)
This commit is contained in:
parent
854d2b1574
commit
6932e02eb8
7 changed files with 20 additions and 51 deletions
|
@ -276,7 +276,7 @@ const watchEmbedder = function (embedder: Electron.WebContents) {
|
|||
|
||||
const isWebViewTagEnabledCache = new WeakMap();
|
||||
|
||||
export const isWebViewTagEnabled = function (contents: Electron.WebContents) {
|
||||
const isWebViewTagEnabled = function (contents: Electron.WebContents) {
|
||||
if (!isWebViewTagEnabledCache.has(contents)) {
|
||||
const webPreferences = contents.getLastWebPreferences() || {};
|
||||
isWebViewTagEnabledCache.set(contents, !!webPreferences.webviewTag);
|
||||
|
|
|
@ -4,7 +4,6 @@ import { clipboard, crashReporter, nativeImage } from 'electron/common';
|
|||
import * as fs from 'fs';
|
||||
import { ipcMainInternal } from '@electron/internal/browser/ipc-main-internal';
|
||||
import * as ipcMainUtils from '@electron/internal/browser/ipc-main-internal-utils';
|
||||
import * as guestViewManager from '@electron/internal/browser/guest-view-manager';
|
||||
import * as typeUtils from '@electron/internal/common/type-utils';
|
||||
import { IPC_MESSAGES } from '@electron/internal/common/ipc-messages';
|
||||
|
||||
|
@ -74,10 +73,6 @@ if (BUILDFLAG(ENABLE_DESKTOP_CAPTURER)) {
|
|||
});
|
||||
}
|
||||
|
||||
const isRemoteModuleEnabled = BUILDFLAG(ENABLE_REMOTE_MODULE)
|
||||
? require('@electron/internal/browser/remote/server').isRemoteModuleEnabled
|
||||
: () => false;
|
||||
|
||||
const getPreloadScript = async function (preloadPath: string) {
|
||||
let preloadSrc = null;
|
||||
let preloadError = null;
|
||||
|
@ -91,14 +86,9 @@ const getPreloadScript = async function (preloadPath: string) {
|
|||
|
||||
ipcMainUtils.handleSync(IPC_MESSAGES.BROWSER_SANDBOX_LOAD, async function (event) {
|
||||
const preloadPaths = event.sender._getPreloadPaths();
|
||||
const webPreferences = event.sender.getLastWebPreferences() || {};
|
||||
|
||||
return {
|
||||
preloadScripts: await Promise.all(preloadPaths.map(path => getPreloadScript(path))),
|
||||
isRemoteModuleEnabled: isRemoteModuleEnabled(event.sender),
|
||||
isWebViewTagEnabled: guestViewManager.isWebViewTagEnabled(event.sender),
|
||||
guestInstanceId: webPreferences.guestInstanceId,
|
||||
openerId: webPreferences.openerId,
|
||||
process: {
|
||||
arch: process.arch,
|
||||
platform: process.platform,
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
const v8Util = process._linkedBinding('electron_common_v8_util');
|
||||
const { getWebPreference } = process._linkedBinding('electron_renderer_web_frame');
|
||||
|
||||
const enableRemoteModule = v8Util.getHiddenValue<boolean>(global, 'enableRemoteModule');
|
||||
const enableRemoteModule = getWebPreference(window, 'enableRemoteModule');
|
||||
|
||||
// Renderer side modules, please sort alphabetically.
|
||||
export const rendererModuleList: ElectronInternal.ModuleEntry[] = [
|
||||
|
|
|
@ -57,30 +57,16 @@ webFrameInit();
|
|||
const { hasSwitch, getSwitchValue } = process._linkedBinding('electron_common_command_line');
|
||||
const { getWebPreference } = process._linkedBinding('electron_renderer_web_frame');
|
||||
|
||||
const parseOption = function<TDefault> (
|
||||
name: string, defaultValue: TDefault, converter?: (value: string) => any
|
||||
) {
|
||||
const value = getWebPreference(window, name);
|
||||
return value
|
||||
? (
|
||||
converter
|
||||
? converter(value)
|
||||
: value
|
||||
)
|
||||
: defaultValue;
|
||||
};
|
||||
|
||||
const contextIsolation = getWebPreference(window, 'contextIsolation');
|
||||
const nodeIntegration = getWebPreference(window, 'nodeIntegration');
|
||||
const webviewTag = getWebPreference(window, 'webviewTag');
|
||||
const isHiddenPage = getWebPreference(window, 'hiddenPage');
|
||||
const usesNativeWindowOpen = getWebPreference(window, 'nativeWindowOpen');
|
||||
const rendererProcessReuseEnabled = getWebPreference(window, 'disableElectronSiteInstanceOverrides');
|
||||
|
||||
const preloadScript = parseOption('preload', null);
|
||||
const preloadScripts = parseOption('preloadScripts', []);
|
||||
const guestInstanceId = parseOption('guestInstanceId', null, value => parseInt(value));
|
||||
const openerId = parseOption('openerId', null, value => parseInt(value));
|
||||
const preloadScript = getWebPreference(window, 'preload');
|
||||
const preloadScripts = getWebPreference(window, 'preloadScripts');
|
||||
const guestInstanceId = getWebPreference(window, 'guestInstanceId') || null;
|
||||
const openerId = getWebPreference(window, 'openerId') || null;
|
||||
const appPath = hasSwitch('app-path') ? getSwitchValue('app-path') : null;
|
||||
|
||||
// The webContents preload script is loaded after the session preload scripts.
|
||||
|
@ -97,8 +83,9 @@ switch (window.location.protocol) {
|
|||
case 'chrome-extension:': {
|
||||
break;
|
||||
}
|
||||
case 'chrome:':
|
||||
case 'chrome:': {
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
// Override default web functions.
|
||||
const { windowSetup } = require('@electron/internal/renderer/window-setup');
|
||||
|
|
|
@ -1,3 +1,7 @@
|
|||
const { getWebPreference } = process._linkedBinding('electron_renderer_web_frame');
|
||||
|
||||
const enableRemoteModule = getWebPreference(window, 'enableRemoteModule');
|
||||
|
||||
export const moduleList: ElectronInternal.ModuleEntry[] = [
|
||||
{
|
||||
name: 'contextBridge',
|
||||
|
@ -34,7 +38,7 @@ if (BUILDFLAG(ENABLE_DESKTOP_CAPTURER)) {
|
|||
});
|
||||
}
|
||||
|
||||
if (BUILDFLAG(ENABLE_REMOTE_MODULE) && process.isRemoteModuleEnabled) {
|
||||
if (BUILDFLAG(ENABLE_REMOTE_MODULE) && enableRemoteModule) {
|
||||
moduleList.push({
|
||||
name: 'remote',
|
||||
loader: () => require('@electron/internal/renderer/api/remote')
|
||||
|
|
|
@ -23,16 +23,7 @@ Object.setPrototypeOf(process, EventEmitter.prototype);
|
|||
const { ipcRendererInternal } = require('@electron/internal/renderer/ipc-renderer-internal');
|
||||
const ipcRendererUtils = require('@electron/internal/renderer/ipc-renderer-internal-utils');
|
||||
|
||||
const {
|
||||
preloadScripts,
|
||||
isRemoteModuleEnabled,
|
||||
isWebViewTagEnabled,
|
||||
guestInstanceId,
|
||||
openerId,
|
||||
process: processProps
|
||||
} = ipcRendererUtils.invokeSync(IPC_MESSAGES.BROWSER_SANDBOX_LOAD);
|
||||
|
||||
process.isRemoteModuleEnabled = isRemoteModuleEnabled;
|
||||
const { preloadScripts, process: processProps } = ipcRendererUtils.invokeSync(IPC_MESSAGES.BROWSER_SANDBOX_LOAD);
|
||||
|
||||
const electron = require('electron');
|
||||
|
||||
|
@ -123,9 +114,12 @@ if (hasSwitch('unsafely-expose-electron-internals-for-testing')) {
|
|||
}
|
||||
|
||||
const contextIsolation = getWebPreference(window, 'contextIsolation');
|
||||
const webviewTag = getWebPreference(window, 'webviewTag');
|
||||
const isHiddenPage = getWebPreference(window, 'hiddenPage');
|
||||
const rendererProcessReuseEnabled = getWebPreference(window, 'disableElectronSiteInstanceOverrides');
|
||||
const usesNativeWindowOpen = true;
|
||||
const guestInstanceId = getWebPreference(window, 'guestInstanceId') || null;
|
||||
const openerId = getWebPreference(window, 'openerId') || null;
|
||||
|
||||
switch (window.location.protocol) {
|
||||
case 'devtools:': {
|
||||
|
@ -136,7 +130,7 @@ switch (window.location.protocol) {
|
|||
case 'chrome-extension:': {
|
||||
break;
|
||||
}
|
||||
case 'chrome': {
|
||||
case 'chrome:': {
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
|
@ -149,7 +143,7 @@ switch (window.location.protocol) {
|
|||
// Load webview tag implementation.
|
||||
if (process.isMainFrame) {
|
||||
const { webViewInit } = require('@electron/internal/renderer/web-view/web-view-init');
|
||||
webViewInit(contextIsolation, isWebViewTagEnabled, guestInstanceId);
|
||||
webViewInit(contextIsolation, webviewTag, guestInstanceId);
|
||||
}
|
||||
|
||||
// Wrap the script into a function executed in global scope. It won't have
|
||||
|
|
|
@ -132,12 +132,6 @@ void RendererClientBase::DidCreateScriptContext(
|
|||
"%s-%" PRId64, renderer_client_id_.c_str(), ++next_context_id_);
|
||||
gin_helper::Dictionary global(context->GetIsolate(), context->Global());
|
||||
global.SetHidden("contextId", context_id);
|
||||
|
||||
#if BUILDFLAG(ENABLE_REMOTE_MODULE)
|
||||
bool enableRemoteModule =
|
||||
render_frame->GetBlinkPreferences().enable_remote_module;
|
||||
global.SetHidden("enableRemoteModule", enableRemoteModule);
|
||||
#endif
|
||||
}
|
||||
|
||||
void RendererClientBase::AddRenderBindings(
|
||||
|
|
Loading…
Reference in a new issue