refactor: remove more dead code post render process reuse (#28983)
* Overrides for window.history.* * Node environment cleanup / creation logic * Options and switches that are now static values
This commit is contained in:
parent
38c877e9d3
commit
e5e8ab4eea
12 changed files with 10 additions and 92 deletions
|
@ -100,22 +100,6 @@ ipcMainUtils.handleSync(IPC_MESSAGES.BROWSER_SANDBOX_LOAD, async function (event
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
ipcMainInternal.on(IPC_MESSAGES.NAVIGATION_CONTROLLER_GO_BACK, function (event) {
|
|
||||||
event.sender.goBack();
|
|
||||||
});
|
|
||||||
|
|
||||||
ipcMainInternal.on(IPC_MESSAGES.NAVIGATION_CONTROLLER_GO_FORWARD, function (event) {
|
|
||||||
event.sender.goForward();
|
|
||||||
});
|
|
||||||
|
|
||||||
ipcMainInternal.on(IPC_MESSAGES.NAVIGATION_CONTROLLER_GO_TO_OFFSET, function (event, offset) {
|
|
||||||
event.sender.goToOffset(offset);
|
|
||||||
});
|
|
||||||
|
|
||||||
ipcMainInternal.on(IPC_MESSAGES.NAVIGATION_CONTROLLER_LENGTH, function (event) {
|
|
||||||
event.returnValue = event.sender.length();
|
|
||||||
});
|
|
||||||
|
|
||||||
ipcMainInternal.on(IPC_MESSAGES.BROWSER_PRELOAD_ERROR, function (event, preloadPath: string, error: Error) {
|
ipcMainInternal.on(IPC_MESSAGES.BROWSER_PRELOAD_ERROR, function (event, preloadPath: string, error: Error) {
|
||||||
event.sender.emit('preload-error', event, preloadPath, error);
|
event.sender.emit('preload-error', event, preloadPath, error);
|
||||||
});
|
});
|
||||||
|
|
|
@ -29,11 +29,6 @@ export const enum IPC_MESSAGES {
|
||||||
|
|
||||||
RENDERER_WEB_FRAME_METHOD = 'RENDERER_WEB_FRAME_METHOD',
|
RENDERER_WEB_FRAME_METHOD = 'RENDERER_WEB_FRAME_METHOD',
|
||||||
|
|
||||||
NAVIGATION_CONTROLLER_GO_BACK = 'NAVIGATION_CONTROLLER_GO_BACK',
|
|
||||||
NAVIGATION_CONTROLLER_GO_FORWARD = 'NAVIGATION_CONTROLLER_GO_FORWARD',
|
|
||||||
NAVIGATION_CONTROLLER_GO_TO_OFFSET = 'NAVIGATION_CONTROLLER_GO_TO_OFFSET',
|
|
||||||
NAVIGATION_CONTROLLER_LENGTH = 'NAVIGATION_CONTROLLER_LENGTH',
|
|
||||||
|
|
||||||
INSPECTOR_CONFIRM = 'INSPECTOR_CONFIRM',
|
INSPECTOR_CONFIRM = 'INSPECTOR_CONFIRM',
|
||||||
INSPECTOR_CONTEXT_MENU = 'INSPECTOR_CONTEXT_MENU',
|
INSPECTOR_CONTEXT_MENU = 'INSPECTOR_CONTEXT_MENU',
|
||||||
INSPECTOR_SELECT_FILE = 'INSPECTOR_SELECT_FILE',
|
INSPECTOR_SELECT_FILE = 'INSPECTOR_SELECT_FILE',
|
||||||
|
|
|
@ -70,7 +70,6 @@ const nodeIntegration = mainFrame.getWebPreference('nodeIntegration');
|
||||||
const webviewTag = mainFrame.getWebPreference('webviewTag');
|
const webviewTag = mainFrame.getWebPreference('webviewTag');
|
||||||
const isHiddenPage = mainFrame.getWebPreference('hiddenPage');
|
const isHiddenPage = mainFrame.getWebPreference('hiddenPage');
|
||||||
const usesNativeWindowOpen = mainFrame.getWebPreference('nativeWindowOpen');
|
const usesNativeWindowOpen = mainFrame.getWebPreference('nativeWindowOpen');
|
||||||
const rendererProcessReuseEnabled = mainFrame.getWebPreference('disableElectronSiteInstanceOverrides');
|
|
||||||
const preloadScript = mainFrame.getWebPreference('preload');
|
const preloadScript = mainFrame.getWebPreference('preload');
|
||||||
const preloadScripts = mainFrame.getWebPreference('preloadScripts');
|
const preloadScripts = mainFrame.getWebPreference('preloadScripts');
|
||||||
const guestInstanceId = mainFrame.getWebPreference('guestInstanceId') || null;
|
const guestInstanceId = mainFrame.getWebPreference('guestInstanceId') || null;
|
||||||
|
@ -97,7 +96,7 @@ switch (window.location.protocol) {
|
||||||
default: {
|
default: {
|
||||||
// Override default web functions.
|
// Override default web functions.
|
||||||
const { windowSetup } = require('@electron/internal/renderer/window-setup');
|
const { windowSetup } = require('@electron/internal/renderer/window-setup');
|
||||||
windowSetup(guestInstanceId, openerId, isHiddenPage, usesNativeWindowOpen, rendererProcessReuseEnabled);
|
windowSetup(guestInstanceId, openerId, isHiddenPage, usesNativeWindowOpen);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -243,8 +243,7 @@ class BrowserWindowProxy {
|
||||||
}
|
}
|
||||||
|
|
||||||
export const windowSetup = (
|
export const windowSetup = (
|
||||||
guestInstanceId: number, openerId: number, isHiddenPage: boolean, usesNativeWindowOpen: boolean, rendererProcessReuseEnabled: boolean
|
guestInstanceId: number, openerId: number, isHiddenPage: boolean, usesNativeWindowOpen: boolean) => {
|
||||||
) => {
|
|
||||||
if (!process.sandboxed && guestInstanceId == null) {
|
if (!process.sandboxed && guestInstanceId == null) {
|
||||||
// Override default window.close.
|
// Override default window.close.
|
||||||
window.close = function () {
|
window.close = function () {
|
||||||
|
@ -319,30 +318,6 @@ export const windowSetup = (
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!process.sandboxed && !rendererProcessReuseEnabled) {
|
|
||||||
window.history.back = function () {
|
|
||||||
ipcRendererInternal.send(IPC_MESSAGES.NAVIGATION_CONTROLLER_GO_BACK);
|
|
||||||
};
|
|
||||||
if (contextIsolationEnabled) internalContextBridge.overrideGlobalValueFromIsolatedWorld(['history', 'back'], window.history.back);
|
|
||||||
|
|
||||||
window.history.forward = function () {
|
|
||||||
ipcRendererInternal.send(IPC_MESSAGES.NAVIGATION_CONTROLLER_GO_FORWARD);
|
|
||||||
};
|
|
||||||
if (contextIsolationEnabled) internalContextBridge.overrideGlobalValueFromIsolatedWorld(['history', 'forward'], window.history.forward);
|
|
||||||
|
|
||||||
window.history.go = function (offset: number) {
|
|
||||||
ipcRendererInternal.send(IPC_MESSAGES.NAVIGATION_CONTROLLER_GO_TO_OFFSET, +offset);
|
|
||||||
};
|
|
||||||
if (contextIsolationEnabled) internalContextBridge.overrideGlobalValueFromIsolatedWorld(['history', 'go'], window.history.go);
|
|
||||||
|
|
||||||
const getHistoryLength = () => ipcRendererInternal.sendSync(IPC_MESSAGES.NAVIGATION_CONTROLLER_LENGTH);
|
|
||||||
Object.defineProperty(window.history, 'length', {
|
|
||||||
get: getHistoryLength,
|
|
||||||
set () {}
|
|
||||||
});
|
|
||||||
if (contextIsolationEnabled) internalContextBridge.overrideGlobalPropertyFromIsolatedWorld(['history', 'length'], getHistoryLength);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (guestInstanceId != null) {
|
if (guestInstanceId != null) {
|
||||||
// Webview `document.visibilityState` tracks window visibility (and ignores
|
// Webview `document.visibilityState` tracks window visibility (and ignores
|
||||||
// the actual <webview> element visibility) for backwards compatibility.
|
// the actual <webview> element visibility) for backwards compatibility.
|
||||||
|
|
|
@ -124,7 +124,6 @@ if (hasSwitch('unsafely-expose-electron-internals-for-testing')) {
|
||||||
const contextIsolation = mainFrame.getWebPreference('contextIsolation');
|
const contextIsolation = mainFrame.getWebPreference('contextIsolation');
|
||||||
const webviewTag = mainFrame.getWebPreference('webviewTag');
|
const webviewTag = mainFrame.getWebPreference('webviewTag');
|
||||||
const isHiddenPage = mainFrame.getWebPreference('hiddenPage');
|
const isHiddenPage = mainFrame.getWebPreference('hiddenPage');
|
||||||
const rendererProcessReuseEnabled = mainFrame.getWebPreference('disableElectronSiteInstanceOverrides');
|
|
||||||
const usesNativeWindowOpen = true;
|
const usesNativeWindowOpen = true;
|
||||||
const guestInstanceId = mainFrame.getWebPreference('guestInstanceId') || null;
|
const guestInstanceId = mainFrame.getWebPreference('guestInstanceId') || null;
|
||||||
const openerId = mainFrame.getWebPreference('openerId') || null;
|
const openerId = mainFrame.getWebPreference('openerId') || null;
|
||||||
|
@ -144,7 +143,7 @@ switch (window.location.protocol) {
|
||||||
default: {
|
default: {
|
||||||
// Override default web functions.
|
// Override default web functions.
|
||||||
const { windowSetup } = require('@electron/internal/renderer/window-setup');
|
const { windowSetup } = require('@electron/internal/renderer/window-setup');
|
||||||
windowSetup(guestInstanceId, openerId, isHiddenPage, usesNativeWindowOpen, rendererProcessReuseEnabled);
|
windowSetup(guestInstanceId, openerId, isHiddenPage, usesNativeWindowOpen);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -445,7 +445,6 @@ void ElectronBrowserClient::OverrideWebkitPrefs(
|
||||||
SessionPreferences::GetValidPreloads(web_contents->GetBrowserContext());
|
SessionPreferences::GetValidPreloads(web_contents->GetBrowserContext());
|
||||||
if (!preloads.empty())
|
if (!preloads.empty())
|
||||||
prefs->preloads = preloads;
|
prefs->preloads = preloads;
|
||||||
prefs->disable_electron_site_instance_overrides = true;
|
|
||||||
|
|
||||||
SetFontDefaults(prefs);
|
SetFontDefaults(prefs);
|
||||||
|
|
||||||
|
|
|
@ -181,9 +181,6 @@ const char kWebGL[] = "webgl";
|
||||||
// navigation.
|
// navigation.
|
||||||
const char kNavigateOnDragDrop[] = "navigateOnDragDrop";
|
const char kNavigateOnDragDrop[] = "navigateOnDragDrop";
|
||||||
|
|
||||||
const char kDisableElectronSiteInstanceOverrides[] =
|
|
||||||
"disableElectronSiteInstanceOverrides";
|
|
||||||
const char kEnableNodeLeakageInRenderers[] = "enableNodeLeakageInRenderers";
|
|
||||||
const char kHiddenPage[] = "hiddenPage";
|
const char kHiddenPage[] = "hiddenPage";
|
||||||
|
|
||||||
#if BUILDFLAG(ENABLE_BUILTIN_SPELLCHECKER)
|
#if BUILDFLAG(ENABLE_BUILTIN_SPELLCHECKER)
|
||||||
|
|
|
@ -90,8 +90,6 @@ extern const char kNavigateOnDragDrop[];
|
||||||
extern const char kEnableWebSQL[];
|
extern const char kEnableWebSQL[];
|
||||||
extern const char kEnablePreferredSizeMode[];
|
extern const char kEnablePreferredSizeMode[];
|
||||||
|
|
||||||
extern const char kDisableElectronSiteInstanceOverrides[];
|
|
||||||
extern const char kEnableNodeLeakageInRenderers[];
|
|
||||||
extern const char kHiddenPage[];
|
extern const char kHiddenPage[];
|
||||||
|
|
||||||
#if BUILDFLAG(ENABLE_BUILTIN_SPELLCHECKER)
|
#if BUILDFLAG(ENABLE_BUILTIN_SPELLCHECKER)
|
||||||
|
|
|
@ -491,9 +491,6 @@ class WebFrameRenderer : public gin::Wrappable<WebFrameRenderer>,
|
||||||
|
|
||||||
if (pref_name == options::kPreloadScripts) {
|
if (pref_name == options::kPreloadScripts) {
|
||||||
return gin::ConvertToV8(isolate, prefs.preloads);
|
return gin::ConvertToV8(isolate, prefs.preloads);
|
||||||
} else if (pref_name == options::kDisableElectronSiteInstanceOverrides) {
|
|
||||||
return gin::ConvertToV8(isolate,
|
|
||||||
prefs.disable_electron_site_instance_overrides);
|
|
||||||
} else if (pref_name == options::kBackgroundColor) {
|
} else if (pref_name == options::kBackgroundColor) {
|
||||||
return gin::ConvertToV8(isolate, prefs.background_color);
|
return gin::ConvertToV8(isolate, prefs.background_color);
|
||||||
} else if (pref_name == options::kOpenerID) {
|
} else if (pref_name == options::kOpenerID) {
|
||||||
|
@ -517,9 +514,6 @@ class WebFrameRenderer : public gin::Wrappable<WebFrameRenderer>,
|
||||||
return gin::ConvertToV8(isolate, prefs.node_integration);
|
return gin::ConvertToV8(isolate, prefs.node_integration);
|
||||||
} else if (pref_name == options::kNodeIntegrationInWorker) {
|
} else if (pref_name == options::kNodeIntegrationInWorker) {
|
||||||
return gin::ConvertToV8(isolate, prefs.node_integration_in_worker);
|
return gin::ConvertToV8(isolate, prefs.node_integration_in_worker);
|
||||||
} else if (pref_name == options::kEnableNodeLeakageInRenderers) {
|
|
||||||
// NOTE: enableNodeLeakageInRenderers is internal-only.
|
|
||||||
return gin::ConvertToV8(isolate, prefs.node_leakage_in_renderers);
|
|
||||||
} else if (pref_name == options::kNodeIntegrationInSubFrames) {
|
} else if (pref_name == options::kNodeIntegrationInSubFrames) {
|
||||||
return gin::ConvertToV8(isolate, true);
|
return gin::ConvertToV8(isolate, true);
|
||||||
#if BUILDFLAG(ENABLE_BUILTIN_SPELLCHECKER)
|
#if BUILDFLAG(ENABLE_BUILTIN_SPELLCHECKER)
|
||||||
|
|
|
@ -73,15 +73,10 @@ void ElectronRenderFrameObserver::DidInstallConditionalFeatures(
|
||||||
// DidCreateScriptContext();
|
// DidCreateScriptContext();
|
||||||
bool is_main_world = IsMainWorld(world_id);
|
bool is_main_world = IsMainWorld(world_id);
|
||||||
bool is_main_frame = render_frame_->IsMainFrame();
|
bool is_main_frame = render_frame_->IsMainFrame();
|
||||||
bool reuse_renderer_processes_enabled =
|
|
||||||
prefs.disable_electron_site_instance_overrides;
|
|
||||||
bool is_not_opened = !render_frame_->GetWebFrame()->Opener() ||
|
|
||||||
prefs.node_leakage_in_renderers;
|
|
||||||
bool allow_node_in_sub_frames = prefs.node_integration_in_sub_frames;
|
bool allow_node_in_sub_frames = prefs.node_integration_in_sub_frames;
|
||||||
bool should_create_isolated_context =
|
bool should_create_isolated_context =
|
||||||
use_context_isolation && is_main_world &&
|
use_context_isolation && is_main_world &&
|
||||||
(is_main_frame || allow_node_in_sub_frames) &&
|
(is_main_frame || allow_node_in_sub_frames);
|
||||||
(is_not_opened || reuse_renderer_processes_enabled);
|
|
||||||
|
|
||||||
if (should_create_isolated_context) {
|
if (should_create_isolated_context) {
|
||||||
CreateIsolatedWorldContext();
|
CreateIsolatedWorldContext();
|
||||||
|
|
|
@ -95,18 +95,7 @@ void ElectronRendererClient::DidCreateScriptContext(
|
||||||
// Only load node if we are a main frame or a devtools extension
|
// Only load node if we are a main frame or a devtools extension
|
||||||
// unless node support has been explicitly enabled for sub frames
|
// unless node support has been explicitly enabled for sub frames
|
||||||
auto prefs = render_frame->GetBlinkPreferences();
|
auto prefs = render_frame->GetBlinkPreferences();
|
||||||
bool reuse_renderer_processes_enabled =
|
bool is_main_frame = render_frame->IsMainFrame();
|
||||||
prefs.disable_electron_site_instance_overrides;
|
|
||||||
// Consider the window not "opened" if it does not have an Opener, or if a
|
|
||||||
// user has manually opted in to leaking node in the renderer
|
|
||||||
bool is_not_opened =
|
|
||||||
!render_frame->GetWebFrame()->Opener() || prefs.node_leakage_in_renderers;
|
|
||||||
// Consider this the main frame if it is both a Main Frame and it wasn't
|
|
||||||
// opened. We allow an opened main frame to have node if renderer process
|
|
||||||
// reuse is enabled as that will correctly free node environments prevent a
|
|
||||||
// leak in child windows.
|
|
||||||
bool is_main_frame = render_frame->IsMainFrame() &&
|
|
||||||
(is_not_opened || reuse_renderer_processes_enabled);
|
|
||||||
bool is_devtools = IsDevToolsExtension(render_frame);
|
bool is_devtools = IsDevToolsExtension(render_frame);
|
||||||
bool allow_node_in_subframes = prefs.node_integration_in_sub_frames;
|
bool allow_node_in_subframes = prefs.node_integration_in_sub_frames;
|
||||||
bool should_load_node =
|
bool should_load_node =
|
||||||
|
@ -121,7 +110,7 @@ void ElectronRendererClient::DidCreateScriptContext(
|
||||||
node_integration_initialized_ = true;
|
node_integration_initialized_ = true;
|
||||||
node_bindings_->Initialize();
|
node_bindings_->Initialize();
|
||||||
node_bindings_->PrepareMessageLoop();
|
node_bindings_->PrepareMessageLoop();
|
||||||
} else if (reuse_renderer_processes_enabled) {
|
} else {
|
||||||
node_bindings_->PrepareMessageLoop();
|
node_bindings_->PrepareMessageLoop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -138,9 +127,7 @@ void ElectronRendererClient::DidCreateScriptContext(
|
||||||
|
|
||||||
// If we have disabled the site instance overrides we should prevent loading
|
// If we have disabled the site instance overrides we should prevent loading
|
||||||
// any non-context aware native module
|
// any non-context aware native module
|
||||||
if (reuse_renderer_processes_enabled)
|
env->set_force_context_aware(true);
|
||||||
env->set_force_context_aware(true);
|
|
||||||
env->set_warn_context_aware(true);
|
|
||||||
|
|
||||||
environments_.insert(env);
|
environments_.insert(env);
|
||||||
|
|
||||||
|
@ -183,12 +170,9 @@ void ElectronRendererClient::WillReleaseScriptContext(
|
||||||
// We also do this if we have disable electron site instance overrides to
|
// We also do this if we have disable electron site instance overrides to
|
||||||
// avoid memory leaks
|
// avoid memory leaks
|
||||||
auto prefs = render_frame->GetBlinkPreferences();
|
auto prefs = render_frame->GetBlinkPreferences();
|
||||||
if (prefs.node_integration_in_sub_frames ||
|
node::FreeEnvironment(env);
|
||||||
prefs.disable_electron_site_instance_overrides) {
|
if (env == node_bindings_->uv_env())
|
||||||
node::FreeEnvironment(env);
|
node::FreeIsolateData(node_bindings_->isolate_data());
|
||||||
if (env == node_bindings_->uv_env())
|
|
||||||
node::FreeIsolateData(node_bindings_->isolate_data());
|
|
||||||
}
|
|
||||||
|
|
||||||
// ElectronBindings is tracking node environments.
|
// ElectronBindings is tracking node environments.
|
||||||
electron_bindings_->EnvironmentDestroyed(env);
|
electron_bindings_->EnvironmentDestroyed(env);
|
||||||
|
|
1
typings/internal-ambient.d.ts
vendored
1
typings/internal-ambient.d.ts
vendored
|
@ -103,7 +103,6 @@ declare namespace NodeJS {
|
||||||
|
|
||||||
interface InternalWebPreferences {
|
interface InternalWebPreferences {
|
||||||
contextIsolation: boolean;
|
contextIsolation: boolean;
|
||||||
disableElectronSiteInstanceOverrides: boolean;
|
|
||||||
guestInstanceId: number;
|
guestInstanceId: number;
|
||||||
hiddenPage: boolean;
|
hiddenPage: boolean;
|
||||||
nativeWindowOpen: boolean;
|
nativeWindowOpen: boolean;
|
||||||
|
|
Loading…
Reference in a new issue