diff --git a/lib/browser/rpc-server.ts b/lib/browser/rpc-server.ts index d8a80802060b..48e6ca16b595 100644 --- a/lib/browser/rpc-server.ts +++ b/lib/browser/rpc-server.ts @@ -68,6 +68,10 @@ ipcMainUtils.handleSync(IPC_MESSAGES.BROWSER_SANDBOX_LOAD, async function (event }; }); +ipcMainUtils.handleSync(IPC_MESSAGES.BROWSER_NONSANDBOX_LOAD, function (event) { + return { preloadPaths: event.sender._getPreloadPaths() }; +}); + ipcMainInternal.on(IPC_MESSAGES.BROWSER_PRELOAD_ERROR, function (event, preloadPath: string, error: Error) { event.sender.emit('preload-error', event, preloadPath, error); }); diff --git a/lib/common/ipc-messages.ts b/lib/common/ipc-messages.ts index b920c79c48c5..c6a881c3c0a2 100644 --- a/lib/common/ipc-messages.ts +++ b/lib/common/ipc-messages.ts @@ -3,6 +3,7 @@ export const enum IPC_MESSAGES { BROWSER_GET_LAST_WEB_PREFERENCES = 'BROWSER_GET_LAST_WEB_PREFERENCES', BROWSER_PRELOAD_ERROR = 'BROWSER_PRELOAD_ERROR', BROWSER_SANDBOX_LOAD = 'BROWSER_SANDBOX_LOAD', + BROWSER_NONSANDBOX_LOAD = 'BROWSER_NONSANDBOX_LOAD', BROWSER_WINDOW_CLOSE = 'BROWSER_WINDOW_CLOSE', BROWSER_GET_PROCESS_MEMORY_INFO = 'BROWSER_GET_PROCESS_MEMORY_INFO', diff --git a/lib/renderer/init.ts b/lib/renderer/init.ts index 980734856897..7047c4ffea92 100644 --- a/lib/renderer/init.ts +++ b/lib/renderer/init.ts @@ -2,6 +2,7 @@ import * as path from 'path'; import { IPC_MESSAGES } from '@electron/internal/common/ipc-messages'; import type * as ipcRendererInternalModule from '@electron/internal/renderer/ipc-renderer-internal'; +import type * as ipcRendererUtilsModule from '@electron/internal/renderer/ipc-renderer-internal-utils'; const Module = require('module'); @@ -38,6 +39,7 @@ require('../common/reset-search-paths'); require('@electron/internal/common/init'); const { ipcRendererInternal } = require('@electron/internal/renderer/ipc-renderer-internal') as typeof ipcRendererInternalModule; +const ipcRendererUtils = require('@electron/internal/renderer/ipc-renderer-internal-utils') as typeof ipcRendererUtilsModule; process.getProcessMemoryInfo = () => { return ipcRendererInternal.invoke(IPC_MESSAGES.BROWSER_GET_PROCESS_MEMORY_INFO); @@ -48,15 +50,8 @@ const { hasSwitch, getSwitchValue } = process._linkedBinding('electron_common_co const { mainFrame } = process._linkedBinding('electron_renderer_web_frame'); const nodeIntegration = mainFrame.getWebPreference('nodeIntegration'); -const preloadScript = mainFrame.getWebPreference('preload'); -const preloadScripts = mainFrame.getWebPreference('preloadScripts'); const appPath = hasSwitch('app-path') ? getSwitchValue('app-path') : null; -// The webContents preload script is loaded after the session preload scripts. -if (preloadScript) { - preloadScripts.push(preloadScript); -} - // Common renderer initialization require('@electron/internal/renderer/common-init'); @@ -127,8 +122,9 @@ if (nodeIntegration) { } } +const { preloadPaths } = ipcRendererUtils.invokeSync(IPC_MESSAGES.BROWSER_NONSANDBOX_LOAD); // Load the preload scripts. -for (const preloadScript of preloadScripts) { +for (const preloadScript of preloadPaths) { try { Module._load(preloadScript); } catch (error) { diff --git a/patches/chromium/allow_in-process_windows_to_have_different_web_prefs.patch b/patches/chromium/allow_in-process_windows_to_have_different_web_prefs.patch index a5496a482837..2065bea3be2d 100644 --- a/patches/chromium/allow_in-process_windows_to_have_different_web_prefs.patch +++ b/patches/chromium/allow_in-process_windows_to_have_different_web_prefs.patch @@ -8,10 +8,10 @@ WebPreferences of in-process child windows, rather than relying on process-level command line switches, as before. diff --git a/third_party/blink/common/web_preferences/web_preferences.cc b/third_party/blink/common/web_preferences/web_preferences.cc -index 6d51f6a77c21b60ab756dbf8d4961b351a2e2b07..c6dc3cebfb32489a5e50b850ed02a066bf3f258e 100644 +index 6d51f6a77c21b60ab756dbf8d4961b351a2e2b07..26b820b3ce387e01900cec4227ff290113a833c3 100644 --- a/third_party/blink/common/web_preferences/web_preferences.cc +++ b/third_party/blink/common/web_preferences/web_preferences.cc -@@ -142,6 +142,20 @@ WebPreferences::WebPreferences() +@@ -142,6 +142,19 @@ WebPreferences::WebPreferences() fake_no_alloc_direct_call_for_testing_enabled(false), v8_cache_options(blink::mojom::V8CacheOptions::kDefault), record_whole_document(false), @@ -20,7 +20,6 @@ index 6d51f6a77c21b60ab756dbf8d4961b351a2e2b07..c6dc3cebfb32489a5e50b850ed02a066 + is_webview(false), + hidden_page(false), + offscreen(false), -+ preload(base::FilePath::StringType()), + node_integration(false), + node_integration_in_worker(false), + node_integration_in_sub_frames(false), @@ -33,21 +32,10 @@ index 6d51f6a77c21b60ab756dbf8d4961b351a2e2b07..c6dc3cebfb32489a5e50b850ed02a066 accelerated_video_decode_enabled(false), animation_policy( diff --git a/third_party/blink/common/web_preferences/web_preferences_mojom_traits.cc b/third_party/blink/common/web_preferences/web_preferences_mojom_traits.cc -index 187fd8d9818693262256d5cbddd5e02659ba903d..f166517f4e70ced310253539fb6197f6b3af559c 100644 +index 187fd8d9818693262256d5cbddd5e02659ba903d..28e5178361e03d1ac851fa74214931b2332dd9c2 100644 --- a/third_party/blink/common/web_preferences/web_preferences_mojom_traits.cc +++ b/third_party/blink/common/web_preferences/web_preferences_mojom_traits.cc -@@ -23,6 +23,10 @@ bool StructTraitscursive_font_family_map) || - !data.ReadFantasyFontFamilyMap(&out->fantasy_font_family_map) || - !data.ReadMathFontFamilyMap(&out->math_font_family_map) || -+ // Begin Electron-specific WebPreferences. -+ !data.ReadPreloads(&out->preloads) || -+ !data.ReadPreload(&out->preload) || -+ // End Electron-specific WebPreferences. - !data.ReadLazyFrameLoadingDistanceThresholdsPx( - &out->lazy_frame_loading_distance_thresholds_px) || - !data.ReadLazyImageLoadingDistanceThresholdsPx( -@@ -148,6 +152,19 @@ bool StructTraitsv8_cache_options = data.v8_cache_options(); out->record_whole_document = data.record_whole_document(); @@ -68,7 +56,7 @@ index 187fd8d9818693262256d5cbddd5e02659ba903d..f166517f4e70ced310253539fb6197f6 out->accelerated_video_decode_enabled = data.accelerated_video_decode_enabled(); diff --git a/third_party/blink/public/common/web_preferences/web_preferences.h b/third_party/blink/public/common/web_preferences/web_preferences.h -index 59947bfd3c042e5f7d3993967fece9b519f93472..368ec7fb398409cd6386269934eaffcce356793f 100644 +index 59947bfd3c042e5f7d3993967fece9b519f93472..cb2a53f6147767394585ed371744d8a140aace71 100644 --- a/third_party/blink/public/common/web_preferences/web_preferences.h +++ b/third_party/blink/public/common/web_preferences/web_preferences.h @@ -10,6 +10,7 @@ @@ -79,17 +67,15 @@ index 59947bfd3c042e5f7d3993967fece9b519f93472..368ec7fb398409cd6386269934eaffcc #include "net/nqe/effective_connection_type.h" #include "third_party/blink/public/common/common_export.h" #include "third_party/blink/public/mojom/css/preferred_color_scheme.mojom-shared.h" -@@ -154,6 +155,22 @@ struct BLINK_COMMON_EXPORT WebPreferences { +@@ -154,6 +155,20 @@ struct BLINK_COMMON_EXPORT WebPreferences { blink::mojom::V8CacheOptions v8_cache_options; bool record_whole_document; + // Begin Electron-specific WebPreferences. -+ std::vector preloads; + bool context_isolation; + bool is_webview; + bool hidden_page; + bool offscreen; -+ base::FilePath preload; + bool node_integration; + bool node_integration_in_worker; + bool node_integration_in_sub_frames; @@ -103,7 +89,7 @@ index 59947bfd3c042e5f7d3993967fece9b519f93472..368ec7fb398409cd6386269934eaffcc // only controls whether or not the "document.cookie" field is properly // connected to the backing store, for instance if you wanted to be able to diff --git a/third_party/blink/public/common/web_preferences/web_preferences_mojom_traits.h b/third_party/blink/public/common/web_preferences/web_preferences_mojom_traits.h -index bd425a5869477de9095c6a41c683609d065b08c0..3a5d7450aa40e8a7614e83f316d3d0fb59583381 100644 +index bd425a5869477de9095c6a41c683609d065b08c0..c7ba3ff52c9de01028c9e2be214e20cd91cbf309 100644 --- a/third_party/blink/public/common/web_preferences/web_preferences_mojom_traits.h +++ b/third_party/blink/public/common/web_preferences/web_preferences_mojom_traits.h @@ -6,6 +6,7 @@ @@ -114,15 +100,11 @@ index bd425a5869477de9095c6a41c683609d065b08c0..3a5d7450aa40e8a7614e83f316d3d0fb #include "mojo/public/cpp/bindings/struct_traits.h" #include "net/nqe/effective_connection_type.h" #include "third_party/blink/public/common/common_export.h" -@@ -428,6 +429,60 @@ struct BLINK_COMMON_EXPORT StructTraits& preloads(const blink::web_pref::WebPreferences& r) { -+ return r.preloads; -+ } -+ + static bool context_isolation(const blink::web_pref::WebPreferences& r) { + return r.context_isolation; + } @@ -139,10 +121,6 @@ index bd425a5869477de9095c6a41c683609d065b08c0..3a5d7450aa40e8a7614e83f316d3d0fb + return r.offscreen; + } + -+ static const base::FilePath& preload(const blink::web_pref::WebPreferences& r) { -+ return r.preload; -+ } -+ + static bool node_integration(const blink::web_pref::WebPreferences& r) { + return r.node_integration; + } @@ -176,7 +154,7 @@ index bd425a5869477de9095c6a41c683609d065b08c0..3a5d7450aa40e8a7614e83f316d3d0fb return r.cookie_enabled; } diff --git a/third_party/blink/public/mojom/webpreferences/web_preferences.mojom b/third_party/blink/public/mojom/webpreferences/web_preferences.mojom -index 738ac646e075f7a37ba2a263c7799a755e63d3fb..80d6ae17d34ef5c7fd14e21c4e1ee3ed4ef9c5fe 100644 +index 738ac646e075f7a37ba2a263c7799a755e63d3fb..40ab2a4b9a1f9de5f201502adebc166a48fccd35 100644 --- a/third_party/blink/public/mojom/webpreferences/web_preferences.mojom +++ b/third_party/blink/public/mojom/webpreferences/web_preferences.mojom @@ -10,6 +10,7 @@ import "third_party/blink/public/mojom/v8_cache_options.mojom"; @@ -187,17 +165,15 @@ index 738ac646e075f7a37ba2a263c7799a755e63d3fb..80d6ae17d34ef5c7fd14e21c4e1ee3ed enum PointerType { kPointerNone = 1, // 1 << 0 -@@ -206,6 +207,22 @@ struct WebPreferences { +@@ -206,6 +207,20 @@ struct WebPreferences { V8CacheOptions v8_cache_options; bool record_whole_document; + // Begin Electron-specific WebPreferences. -+ array preloads; + bool context_isolation; + bool is_webview; + bool hidden_page; + bool offscreen; -+ mojo_base.mojom.FilePath preload; + bool node_integration; + bool node_integration_in_worker; + bool node_integration_in_sub_frames; diff --git a/shell/browser/electron_browser_client.cc b/shell/browser/electron_browser_client.cc index fe5a2da4a87a..91c597f20530 100644 --- a/shell/browser/electron_browser_client.cc +++ b/shell/browser/electron_browser_client.cc @@ -497,11 +497,6 @@ void ElectronBrowserClient::OverrideWebkitPrefs( ? blink::mojom::PreferredColorScheme::kDark : blink::mojom::PreferredColorScheme::kLight; - auto preloads = - SessionPreferences::GetValidPreloads(web_contents->GetBrowserContext()); - if (!preloads.empty()) - prefs->preloads = preloads; - SetFontDefaults(prefs); // Custom preferences of guest page. diff --git a/shell/browser/web_contents_preferences.cc b/shell/browser/web_contents_preferences.cc index 44030d1e6bfd..a635b991fc6d 100644 --- a/shell/browser/web_contents_preferences.cc +++ b/shell/browser/web_contents_preferences.cc @@ -486,10 +486,6 @@ void WebContentsPreferences::OverrideWebkitPrefs( prefs->offscreen = offscreen_; - // The preload script. - if (preload_path_) - prefs->preload = *preload_path_; - prefs->node_integration = node_integration_; prefs->node_integration_in_worker = node_integration_in_worker_; prefs->node_integration_in_sub_frames = node_integration_in_sub_frames_; diff --git a/shell/renderer/api/electron_api_web_frame.cc b/shell/renderer/api/electron_api_web_frame.cc index f48d2f4c73fe..ea40c368cee6 100644 --- a/shell/renderer/api/electron_api_web_frame.cc +++ b/shell/renderer/api/electron_api_web_frame.cc @@ -496,9 +496,7 @@ class WebFrameRenderer : public gin::Wrappable, const auto& prefs = render_frame->GetBlinkPreferences(); - if (pref_name == options::kPreloadScripts) { - return gin::ConvertToV8(isolate, prefs.preloads); - } else if (pref_name == "isWebView") { + if (pref_name == "isWebView") { // FIXME(zcbenz): For child windows opened with window.open('') from // webview, the WebPreferences is inherited from webview and the value // of |is_webview| is wrong. @@ -513,8 +511,6 @@ class WebFrameRenderer : public gin::Wrappable, return gin::ConvertToV8(isolate, prefs.hidden_page); } else if (pref_name == options::kOffscreen) { return gin::ConvertToV8(isolate, prefs.offscreen); - } else if (pref_name == options::kPreloadScript) { - return gin::ConvertToV8(isolate, prefs.preload.value()); } else if (pref_name == options::kNodeIntegration) { return gin::ConvertToV8(isolate, prefs.node_integration); } else if (pref_name == options::kNodeIntegrationInWorker) { diff --git a/spec-main/api-browser-window-spec.ts b/spec-main/api-browser-window-spec.ts index e68f47434582..3edd3becbe93 100644 --- a/spec-main/api-browser-window-spec.ts +++ b/spec-main/api-browser-window-spec.ts @@ -3263,7 +3263,15 @@ describe('BrowserWindow module', () => { }); w.webContents.setWindowOpenHandler(() => ({ action: 'allow', - overrideBrowserWindowOptions: { show: false, webPreferences: { contextIsolation: false, webviewTag: true, nodeIntegrationInSubFrames: true } } + overrideBrowserWindowOptions: { + show: false, + webPreferences: { + contextIsolation: false, + webviewTag: true, + nodeIntegrationInSubFrames: true, + preload + } + } })); const webviewLoaded = emittedOnce(ipcMain, 'webview-loaded'); diff --git a/typings/internal-ambient.d.ts b/typings/internal-ambient.d.ts index 2ac177b26315..c63b10acc6b1 100644 --- a/typings/internal-ambient.d.ts +++ b/typings/internal-ambient.d.ts @@ -107,8 +107,6 @@ declare namespace NodeJS { isWebView: boolean; hiddenPage: boolean; nodeIntegration: boolean; - preload: string - preloadScripts: string[]; webviewTag: boolean; }