From 5c250455ad5a89de3bce1495392240dc19d2a798 Mon Sep 17 00:00:00 2001 From: Milan Burda Date: Tue, 8 Jan 2019 10:12:34 +0100 Subject: [PATCH] refactor: pass isWebViewTagEnabled via ELECTRON_BROWSER_SANDBOX_LOAD (#16238) --- lib/browser/guest-view-manager.js | 5 +++-- lib/browser/rpc-server.js | 1 + lib/sandboxed_renderer/init.js | 4 ++-- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/browser/guest-view-manager.js b/lib/browser/guest-view-manager.js index e05229afc077..a9d014a9051b 100644 --- a/lib/browser/guest-view-manager.js +++ b/lib/browser/guest-view-manager.js @@ -328,8 +328,8 @@ const isWebViewTagEnabledCache = new WeakMap() const isWebViewTagEnabled = function (contents) { if (!isWebViewTagEnabledCache.has(contents)) { - const value = contents.getLastWebPreferences().webviewTag - isWebViewTagEnabledCache.set(contents, value) + const webPreferences = contents.getLastWebPreferences() || {} + isWebViewTagEnabledCache.set(contents, !!webPreferences.webviewTag) } return isWebViewTagEnabledCache.get(contents) @@ -437,3 +437,4 @@ const getEmbedder = function (guestInstanceId) { } exports.getGuestForWebContents = getGuestForWebContents +exports.isWebViewTagEnabled = isWebViewTagEnabled diff --git a/lib/browser/rpc-server.js b/lib/browser/rpc-server.js index d318ec7cf6d9..dbd9060e00a9 100644 --- a/lib/browser/rpc-server.js +++ b/lib/browser/rpc-server.js @@ -504,6 +504,7 @@ ipcMain.on('ELECTRON_BROWSER_SANDBOX_LOAD', function (event) { preloadSrc, preloadError, isRemoteModuleEnabled: event.sender._isRemoteModuleEnabled(), + isWebViewTagEnabled: guestViewManager.isWebViewTagEnabled(event.sender), process: { arch: process.arch, platform: process.platform, diff --git a/lib/sandboxed_renderer/init.js b/lib/sandboxed_renderer/init.js index c453357c216b..4f219ff59b66 100644 --- a/lib/sandboxed_renderer/init.js +++ b/lib/sandboxed_renderer/init.js @@ -29,7 +29,7 @@ Object.setPrototypeOf(process, EventEmitter.prototype) const ipcRenderer = require('@electron/internal/renderer/ipc-renderer-internal') const { - preloadSrc, preloadError, isRemoteModuleEnabled, process: processProps + preloadSrc, preloadError, isRemoteModuleEnabled, isWebViewTagEnabled, process: processProps } = ipcRenderer.sendSync('ELECTRON_BROWSER_SANDBOX_LOAD') process.isRemoteModuleEnabled = isRemoteModuleEnabled @@ -125,7 +125,7 @@ if (binding.guestInstanceId) { process.guestInstanceId = parseInt(binding.guestInstanceId) } -if (!process.guestInstanceId && hasSwitch('webview-tag')) { +if (!process.guestInstanceId && isWebViewTagEnabled) { // don't allow recursive `` require('@electron/internal/renderer/web-view/web-view').setupWebView(window) }