Skip to content

Commit fe7f296

Browse files
authored
refactor: remove duplicate contextIsolation from getWebPreference() (electron#31730)
1 parent 4af21a1 commit fe7f296

File tree

7 files changed

+7
-16
lines changed

7 files changed

+7
-16
lines changed

lib/renderer/api/context-bridge.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
1-
const { mainFrame } = process._linkedBinding('electron_renderer_web_frame');
21
const binding = process._linkedBinding('electron_renderer_context_bridge');
32

4-
const contextIsolationEnabled = mainFrame.getWebPreference('contextIsolation');
5-
63
const checkContextIsolationEnabled = () => {
7-
if (!contextIsolationEnabled) throw new Error('contextBridge API can only be used when contextIsolation is enabled');
4+
if (!process.contextIsolated) throw new Error('contextBridge API can only be used when contextIsolation is enabled');
85
};
96

107
const contextBridge: Electron.ContextBridge = {
@@ -17,7 +14,7 @@ const contextBridge: Electron.ContextBridge = {
1714
export default contextBridge;
1815

1916
export const internalContextBridge = {
20-
contextIsolationEnabled,
17+
contextIsolationEnabled: process.contextIsolated,
2118
overrideGlobalValueFromIsolatedWorld: (keys: string[], value: any) => {
2219
return binding._overrideGlobalValueFromIsolatedWorld(keys, value, false);
2320
},

lib/renderer/init.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ webFrameInit();
7171
const { hasSwitch, getSwitchValue } = process._linkedBinding('electron_common_command_line');
7272
const { mainFrame } = process._linkedBinding('electron_renderer_web_frame');
7373

74-
const contextIsolation = mainFrame.getWebPreference('contextIsolation');
7574
const nodeIntegration = mainFrame.getWebPreference('nodeIntegration');
7675
const webviewTag = mainFrame.getWebPreference('webviewTag');
7776
const isHiddenPage = mainFrame.getWebPreference('hiddenPage');
@@ -109,7 +108,7 @@ switch (window.location.protocol) {
109108
// Load webview tag implementation.
110109
if (process.isMainFrame) {
111110
const { webViewInit } = require('@electron/internal/renderer/web-view/web-view-init') as typeof webViewInitModule;
112-
webViewInit(contextIsolation, webviewTag, isWebView);
111+
webViewInit(webviewTag, isWebView);
113112
}
114113

115114
if (nodeIntegration) {
@@ -166,7 +165,7 @@ if (nodeIntegration) {
166165
} else {
167166
// Delete Node's symbols after the Environment has been loaded in a
168167
// non context-isolated environment
169-
if (!contextIsolation) {
168+
if (!process.contextIsolated) {
170169
process.once('loaded', function () {
171170
delete (global as any).process;
172171
delete (global as any).Buffer;

lib/renderer/web-view/web-view-init.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ function handleFocusBlur () {
2020
});
2121
}
2222

23-
export function webViewInit (contextIsolation: boolean, webviewTag: boolean, isWebView: boolean) {
23+
export function webViewInit (webviewTag: boolean, isWebView: boolean) {
2424
// Don't allow recursive `<webview>`.
2525
if (webviewTag && !isWebView) {
2626
const guestViewInternal = require('@electron/internal/renderer/web-view/guest-view-internal') as typeof guestViewInternalModule;
27-
if (contextIsolation) {
27+
if (process.contextIsolated) {
2828
v8Util.setHiddenValue(window, 'guestViewInternal', guestViewInternal);
2929
} else {
3030
const { setupWebView } = require('@electron/internal/renderer/web-view/web-view-element') as typeof webViewElementModule;

lib/sandboxed_renderer/init.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,6 @@ if (hasSwitch('unsafely-expose-electron-internals-for-testing')) {
127127
preloadProcess._linkedBinding = process._linkedBinding;
128128
}
129129

130-
const contextIsolation = mainFrame.getWebPreference('contextIsolation');
131130
const webviewTag = mainFrame.getWebPreference('webviewTag');
132131
const isHiddenPage = mainFrame.getWebPreference('hiddenPage');
133132
const usesNativeWindowOpen = true;
@@ -156,7 +155,7 @@ switch (window.location.protocol) {
156155
// Load webview tag implementation.
157156
if (process.isMainFrame) {
158157
const { webViewInit } = require('@electron/internal/renderer/web-view/web-view-init') as typeof webViewInitModule;
159-
webViewInit(contextIsolation, webviewTag, isWebView);
158+
webViewInit(webviewTag, isWebView);
160159
}
161160

162161
// Wrap the script into a function executed in global scope. It won't have

shell/renderer/api/electron_api_web_frame.cc

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -499,8 +499,6 @@ class WebFrameRenderer : public gin::Wrappable<WebFrameRenderer>,
499499
} else if (pref_name == options::kOpenerID) {
500500
// NOTE: openerId is internal-only.
501501
return gin::ConvertToV8(isolate, prefs.opener_id);
502-
} else if (pref_name == options::kContextIsolation) {
503-
return gin::ConvertToV8(isolate, prefs.context_isolation);
504502
} else if (pref_name == "isWebView") {
505503
return gin::ConvertToV8(isolate, prefs.is_webview);
506504
} else if (pref_name == options::kHiddenPage) {

spec/fixtures/api/window-open-preload.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ setImmediate(function () {
66
ipcRenderer.send('answer', {
77
nativeWindowOpen: webFrame.getWebPreference('nativeWindowOpen'),
88
nodeIntegration: webFrame.getWebPreference('nodeIntegration'),
9-
sandbox: webFrame.getWebPreference('sandbox'),
109
typeofProcess: typeof global.process,
1110
windowOpenerIsNull
1211
});

typings/internal-ambient.d.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,6 @@ declare namespace NodeJS {
106106
}
107107

108108
interface InternalWebPreferences {
109-
contextIsolation: boolean;
110109
isWebView: boolean;
111110
hiddenPage: boolean;
112111
nativeWindowOpen: boolean;

0 commit comments

Comments
 (0)