refactor: remove guestInstanceId from WebPreferences (#30280)
* refactor: remove guestInstanceId from WebPreferences * refactor: remove WebViewManager::GetEmbedder
This commit is contained in:
parent
c3abbdefdd
commit
c5ad7ed0cd
15 changed files with 53 additions and 71 deletions
|
@ -28,7 +28,7 @@ function sanitizeOptionsForGuest (options: Record<string, any>) {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
function makeWebPreferences (embedder: Electron.WebContents, params: Record<string, any>, guestInstanceId: number) {
|
function makeWebPreferences (embedder: Electron.WebContents, params: Record<string, any>) {
|
||||||
// parse the 'webpreferences' attribute string, if set
|
// parse the 'webpreferences' attribute string, if set
|
||||||
// this uses the same parsing rules as window.open uses for its features
|
// this uses the same parsing rules as window.open uses for its features
|
||||||
const parsedWebPreferences =
|
const parsedWebPreferences =
|
||||||
|
@ -37,7 +37,6 @@ function makeWebPreferences (embedder: Electron.WebContents, params: Record<stri
|
||||||
: null;
|
: null;
|
||||||
|
|
||||||
const webPreferences: Electron.WebPreferences = {
|
const webPreferences: Electron.WebPreferences = {
|
||||||
guestInstanceId,
|
|
||||||
nodeIntegration: params.nodeintegration != null ? params.nodeintegration : false,
|
nodeIntegration: params.nodeintegration != null ? params.nodeintegration : false,
|
||||||
nodeIntegrationInSubFrames: params.nodeintegrationinsubframes != null ? params.nodeintegrationinsubframes : false,
|
nodeIntegrationInSubFrames: params.nodeintegrationinsubframes != null ? params.nodeintegrationinsubframes : false,
|
||||||
plugins: params.plugins,
|
plugins: params.plugins,
|
||||||
|
@ -204,7 +203,7 @@ const attachGuest = function (event: Electron.IpcMainInvokeEvent,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const webPreferences = makeWebPreferences(embedder, params, guestInstanceId);
|
const webPreferences = makeWebPreferences(embedder, params);
|
||||||
|
|
||||||
embedder.emit('will-attach-webview', event, webPreferences, params);
|
embedder.emit('will-attach-webview', event, webPreferences, params);
|
||||||
if (event.defaultPrevented) {
|
if (event.defaultPrevented) {
|
||||||
|
|
|
@ -74,7 +74,7 @@ const isHiddenPage = mainFrame.getWebPreference('hiddenPage');
|
||||||
const usesNativeWindowOpen = mainFrame.getWebPreference('nativeWindowOpen');
|
const usesNativeWindowOpen = mainFrame.getWebPreference('nativeWindowOpen');
|
||||||
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');
|
const isWebView = mainFrame.getWebPreference('isWebView');
|
||||||
const openerId = mainFrame.getWebPreference('openerId');
|
const openerId = mainFrame.getWebPreference('openerId');
|
||||||
const appPath = hasSwitch('app-path') ? getSwitchValue('app-path') : null;
|
const appPath = hasSwitch('app-path') ? getSwitchValue('app-path') : null;
|
||||||
|
|
||||||
|
@ -98,14 +98,14 @@ switch (window.location.protocol) {
|
||||||
default: {
|
default: {
|
||||||
// Override default web functions.
|
// Override default web functions.
|
||||||
const { windowSetup } = require('@electron/internal/renderer/window-setup') as typeof windowSetupModule;
|
const { windowSetup } = require('@electron/internal/renderer/window-setup') as typeof windowSetupModule;
|
||||||
windowSetup(guestInstanceId, openerId, isHiddenPage, usesNativeWindowOpen);
|
windowSetup(isWebView, openerId, isHiddenPage, usesNativeWindowOpen);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load webview tag implementation.
|
// Load webview tag implementation.
|
||||||
if (process.isMainFrame) {
|
if (process.isMainFrame) {
|
||||||
const { webViewInit } = require('@electron/internal/renderer/web-view/web-view-init') as typeof webViewInitModule;
|
const { webViewInit } = require('@electron/internal/renderer/web-view/web-view-init') as typeof webViewInitModule;
|
||||||
webViewInit(contextIsolation, webviewTag, guestInstanceId);
|
webViewInit(contextIsolation, webviewTag, isWebView);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (nodeIntegration) {
|
if (nodeIntegration) {
|
||||||
|
|
|
@ -20,9 +20,9 @@ function handleFocusBlur () {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export function webViewInit (contextIsolation: boolean, webviewTag: boolean, guestInstanceId: number) {
|
export function webViewInit (contextIsolation: boolean, webviewTag: boolean, isWebView: boolean) {
|
||||||
// Don't allow recursive `<webview>`.
|
// Don't allow recursive `<webview>`.
|
||||||
if (webviewTag && !guestInstanceId) {
|
if (webviewTag && !isWebView) {
|
||||||
const guestViewInternal = require('@electron/internal/renderer/web-view/guest-view-internal') as typeof guestViewInternalModule;
|
const guestViewInternal = require('@electron/internal/renderer/web-view/guest-view-internal') as typeof guestViewInternalModule;
|
||||||
if (contextIsolation) {
|
if (contextIsolation) {
|
||||||
v8Util.setHiddenValue(window, 'guestViewInternal', guestViewInternal);
|
v8Util.setHiddenValue(window, 'guestViewInternal', guestViewInternal);
|
||||||
|
@ -36,7 +36,7 @@ export function webViewInit (contextIsolation: boolean, webviewTag: boolean, gue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (guestInstanceId) {
|
if (isWebView) {
|
||||||
// Report focus/blur events of webview to browser.
|
// Report focus/blur events of webview to browser.
|
||||||
handleFocusBlur();
|
handleFocusBlur();
|
||||||
}
|
}
|
||||||
|
|
|
@ -243,8 +243,8 @@ class BrowserWindowProxy {
|
||||||
}
|
}
|
||||||
|
|
||||||
export const windowSetup = (
|
export const windowSetup = (
|
||||||
guestInstanceId: number, openerId: number, isHiddenPage: boolean, usesNativeWindowOpen: boolean) => {
|
isWebView: boolean, openerId: number, isHiddenPage: boolean, usesNativeWindowOpen: boolean) => {
|
||||||
if (!process.sandboxed && !guestInstanceId) {
|
if (!process.sandboxed && !isWebView) {
|
||||||
// Override default window.close.
|
// Override default window.close.
|
||||||
window.close = function () {
|
window.close = function () {
|
||||||
ipcRendererInternal.send(IPC_MESSAGES.BROWSER_WINDOW_CLOSE);
|
ipcRendererInternal.send(IPC_MESSAGES.BROWSER_WINDOW_CLOSE);
|
||||||
|
@ -318,7 +318,7 @@ export const windowSetup = (
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (guestInstanceId) {
|
if (isWebView) {
|
||||||
// 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.
|
||||||
// See discussion in #9178.
|
// See discussion in #9178.
|
||||||
|
|
|
@ -127,7 +127,7 @@ 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 usesNativeWindowOpen = true;
|
const usesNativeWindowOpen = true;
|
||||||
const guestInstanceId = mainFrame.getWebPreference('guestInstanceId');
|
const isWebView = mainFrame.getWebPreference('isWebView');
|
||||||
const openerId = mainFrame.getWebPreference('openerId');
|
const openerId = mainFrame.getWebPreference('openerId');
|
||||||
|
|
||||||
switch (window.location.protocol) {
|
switch (window.location.protocol) {
|
||||||
|
@ -145,14 +145,14 @@ switch (window.location.protocol) {
|
||||||
default: {
|
default: {
|
||||||
// Override default web functions.
|
// Override default web functions.
|
||||||
const { windowSetup } = require('@electron/internal/renderer/window-setup') as typeof windowSetupModule;
|
const { windowSetup } = require('@electron/internal/renderer/window-setup') as typeof windowSetupModule;
|
||||||
windowSetup(guestInstanceId, openerId, isHiddenPage, usesNativeWindowOpen);
|
windowSetup(isWebView, openerId, isHiddenPage, usesNativeWindowOpen);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load webview tag implementation.
|
// Load webview tag implementation.
|
||||||
if (process.isMainFrame) {
|
if (process.isMainFrame) {
|
||||||
const { webViewInit } = require('@electron/internal/renderer/web-view/web-view-init') as typeof webViewInitModule;
|
const { webViewInit } = require('@electron/internal/renderer/web-view/web-view-init') as typeof webViewInitModule;
|
||||||
webViewInit(contextIsolation, webviewTag, guestInstanceId);
|
webViewInit(contextIsolation, webviewTag, isWebView);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Wrap the script into a function executed in global scope. It won't have
|
// Wrap the script into a function executed in global scope. It won't have
|
||||||
|
|
|
@ -8,7 +8,7 @@ WebPreferences of in-process child windows, rather than relying on
|
||||||
process-level command line switches, as before.
|
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
|
diff --git a/third_party/blink/common/web_preferences/web_preferences.cc b/third_party/blink/common/web_preferences/web_preferences.cc
|
||||||
index 8a1315f7f89588bb21c6d3c21a7de7c07fed9679..51cc790f7e1ba1440a6ffaa56c9e01687fc35c06 100644
|
index 8a1315f7f89588bb21c6d3c21a7de7c07fed9679..c23443c7816e38836b2f4233ca3a742693888f39 100644
|
||||||
--- a/third_party/blink/common/web_preferences/web_preferences.cc
|
--- a/third_party/blink/common/web_preferences/web_preferences.cc
|
||||||
+++ b/third_party/blink/common/web_preferences/web_preferences.cc
|
+++ b/third_party/blink/common/web_preferences/web_preferences.cc
|
||||||
@@ -148,6 +148,22 @@ WebPreferences::WebPreferences()
|
@@ -148,6 +148,22 @@ WebPreferences::WebPreferences()
|
||||||
|
@ -18,7 +18,7 @@ index 8a1315f7f89588bb21c6d3c21a7de7c07fed9679..51cc790f7e1ba1440a6ffaa56c9e0168
|
||||||
+ // Begin Electron-specific WebPreferences.
|
+ // Begin Electron-specific WebPreferences.
|
||||||
+ opener_id(0),
|
+ opener_id(0),
|
||||||
+ context_isolation(false),
|
+ context_isolation(false),
|
||||||
+ guest_instance_id(0),
|
+ is_webview(false),
|
||||||
+ hidden_page(false),
|
+ hidden_page(false),
|
||||||
+ offscreen(false),
|
+ offscreen(false),
|
||||||
+ preload(base::FilePath::StringType()),
|
+ preload(base::FilePath::StringType()),
|
||||||
|
@ -35,7 +35,7 @@ index 8a1315f7f89588bb21c6d3c21a7de7c07fed9679..51cc790f7e1ba1440a6ffaa56c9e0168
|
||||||
accelerated_video_decode_enabled(false),
|
accelerated_video_decode_enabled(false),
|
||||||
animation_policy(
|
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
|
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 a264ef99beb81dd6b1f55c1b0f57f6055b4ab771..ff4d5c5245ba0641b4ef02cdaf5d50be537b709e 100644
|
index a264ef99beb81dd6b1f55c1b0f57f6055b4ab771..16b734cb371d22dbe99b4ae397126f240b9f686c 100644
|
||||||
--- a/third_party/blink/common/web_preferences/web_preferences_mojom_traits.cc
|
--- a/third_party/blink/common/web_preferences/web_preferences_mojom_traits.cc
|
||||||
+++ b/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 StructTraits<blink::mojom::WebPreferencesDataView,
|
@@ -23,6 +23,10 @@ bool StructTraits<blink::mojom::WebPreferencesDataView,
|
||||||
|
@ -56,7 +56,7 @@ index a264ef99beb81dd6b1f55c1b0f57f6055b4ab771..ff4d5c5245ba0641b4ef02cdaf5d50be
|
||||||
+ // Begin Electron-specific WebPreferences.
|
+ // Begin Electron-specific WebPreferences.
|
||||||
+ out->opener_id = data.opener_id();
|
+ out->opener_id = data.opener_id();
|
||||||
+ out->context_isolation = data.context_isolation();
|
+ out->context_isolation = data.context_isolation();
|
||||||
+ out->guest_instance_id = data.guest_instance_id();
|
+ out->is_webview = data.is_webview();
|
||||||
+ out->hidden_page = data.hidden_page();
|
+ out->hidden_page = data.hidden_page();
|
||||||
+ out->offscreen = data.offscreen();
|
+ out->offscreen = data.offscreen();
|
||||||
+ out->native_window_open = data.native_window_open();
|
+ out->native_window_open = data.native_window_open();
|
||||||
|
@ -72,7 +72,7 @@ index a264ef99beb81dd6b1f55c1b0f57f6055b4ab771..ff4d5c5245ba0641b4ef02cdaf5d50be
|
||||||
out->accelerated_video_decode_enabled =
|
out->accelerated_video_decode_enabled =
|
||||||
data.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
|
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 4517bf43c1b80f1aa0f3ba8e67e78b8b91e19f8a..492f6c948af74bb925826a1075e6343f147f0eb2 100644
|
index 4517bf43c1b80f1aa0f3ba8e67e78b8b91e19f8a..5dc73459f424ad0a01b4ea18e4de196e20d24ae5 100644
|
||||||
--- a/third_party/blink/public/common/web_preferences/web_preferences.h
|
--- a/third_party/blink/public/common/web_preferences/web_preferences.h
|
||||||
+++ b/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 @@
|
@@ -10,6 +10,7 @@
|
||||||
|
@ -91,7 +91,7 @@ index 4517bf43c1b80f1aa0f3ba8e67e78b8b91e19f8a..492f6c948af74bb925826a1075e6343f
|
||||||
+ std::vector<base::FilePath> preloads;
|
+ std::vector<base::FilePath> preloads;
|
||||||
+ int opener_id;
|
+ int opener_id;
|
||||||
+ bool context_isolation;
|
+ bool context_isolation;
|
||||||
+ int guest_instance_id;
|
+ bool is_webview;
|
||||||
+ bool hidden_page;
|
+ bool hidden_page;
|
||||||
+ bool offscreen;
|
+ bool offscreen;
|
||||||
+ base::FilePath preload;
|
+ base::FilePath preload;
|
||||||
|
@ -109,7 +109,7 @@ index 4517bf43c1b80f1aa0f3ba8e67e78b8b91e19f8a..492f6c948af74bb925826a1075e6343f
|
||||||
// only controls whether or not the "document.cookie" field is properly
|
// 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
|
// 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
|
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 9dbbb581a8876430c3e0a39df1ff655d3ddc6d2d..fd6cbcfa1992a75bf660fb9eb47a9099acb3834f 100644
|
index 9dbbb581a8876430c3e0a39df1ff655d3ddc6d2d..98c5c4ac5ee3130581c8576e5ef810a78939f50e 100644
|
||||||
--- a/third_party/blink/public/common/web_preferences/web_preferences_mojom_traits.h
|
--- 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
|
+++ b/third_party/blink/public/common/web_preferences/web_preferences_mojom_traits.h
|
||||||
@@ -6,6 +6,7 @@
|
@@ -6,6 +6,7 @@
|
||||||
|
@ -137,8 +137,8 @@ index 9dbbb581a8876430c3e0a39df1ff655d3ddc6d2d..fd6cbcfa1992a75bf660fb9eb47a9099
|
||||||
+ return r.context_isolation;
|
+ return r.context_isolation;
|
||||||
+ }
|
+ }
|
||||||
+
|
+
|
||||||
+ static int guest_instance_id(const blink::web_pref::WebPreferences& r) {
|
+ static int is_webview(const blink::web_pref::WebPreferences& r) {
|
||||||
+ return r.guest_instance_id;
|
+ return r.is_webview;
|
||||||
+ }
|
+ }
|
||||||
+
|
+
|
||||||
+ static bool hidden_page(const blink::web_pref::WebPreferences& r) {
|
+ static bool hidden_page(const blink::web_pref::WebPreferences& r) {
|
||||||
|
@ -190,7 +190,7 @@ index 9dbbb581a8876430c3e0a39df1ff655d3ddc6d2d..fd6cbcfa1992a75bf660fb9eb47a9099
|
||||||
return r.cookie_enabled;
|
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
|
diff --git a/third_party/blink/public/mojom/webpreferences/web_preferences.mojom b/third_party/blink/public/mojom/webpreferences/web_preferences.mojom
|
||||||
index eaecb8c2b7dadaf7650bc8ac85cbad4383035e67..7863c865df17fa95965b5a4e543579bac22af90b 100644
|
index eaecb8c2b7dadaf7650bc8ac85cbad4383035e67..64d83af36d384d2eb7fdd89a3a0d3665a40354a1 100644
|
||||||
--- a/third_party/blink/public/mojom/webpreferences/web_preferences.mojom
|
--- a/third_party/blink/public/mojom/webpreferences/web_preferences.mojom
|
||||||
+++ b/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";
|
@@ -10,6 +10,7 @@ import "third_party/blink/public/mojom/v8_cache_options.mojom";
|
||||||
|
@ -209,7 +209,7 @@ index eaecb8c2b7dadaf7650bc8ac85cbad4383035e67..7863c865df17fa95965b5a4e543579ba
|
||||||
+ array<mojo_base.mojom.FilePath> preloads;
|
+ array<mojo_base.mojom.FilePath> preloads;
|
||||||
+ int32 opener_id;
|
+ int32 opener_id;
|
||||||
+ bool context_isolation;
|
+ bool context_isolation;
|
||||||
+ int32 guest_instance_id;
|
+ bool is_webview;
|
||||||
+ bool hidden_page;
|
+ bool hidden_page;
|
||||||
+ bool offscreen;
|
+ bool offscreen;
|
||||||
+ mojo_base.mojom.FilePath preload;
|
+ mojo_base.mojom.FilePath preload;
|
||||||
|
|
|
@ -19,8 +19,8 @@
|
||||||
#include "content/public/common/content_switches.h"
|
#include "content/public/common/content_switches.h"
|
||||||
#include "net/base/filename_util.h"
|
#include "net/base/filename_util.h"
|
||||||
#include "sandbox/policy/switches.h"
|
#include "sandbox/policy/switches.h"
|
||||||
|
#include "shell/browser/api/electron_api_web_contents.h"
|
||||||
#include "shell/browser/native_window.h"
|
#include "shell/browser/native_window.h"
|
||||||
#include "shell/browser/web_view_manager.h"
|
|
||||||
#include "shell/common/gin_converters/value_converter.h"
|
#include "shell/common/gin_converters/value_converter.h"
|
||||||
#include "shell/common/gin_helper/dictionary.h"
|
#include "shell/common/gin_helper/dictionary.h"
|
||||||
#include "shell/common/options_switches.h"
|
#include "shell/common/options_switches.h"
|
||||||
|
@ -103,19 +103,16 @@ WebContentsPreferences::WebContentsPreferences(
|
||||||
|
|
||||||
// If this is a <webview> tag, and the embedder is offscreen-rendered, then
|
// If this is a <webview> tag, and the embedder is offscreen-rendered, then
|
||||||
// this WebContents is also offscreen-rendered.
|
// this WebContents is also offscreen-rendered.
|
||||||
if (guest_instance_id_) {
|
if (auto* api_web_contents = api::WebContents::From(web_contents_)) {
|
||||||
auto* manager = WebViewManager::GetWebViewManager(web_contents);
|
if (electron::api::WebContents* embedder = api_web_contents->embedder()) {
|
||||||
if (manager) {
|
auto* embedder_preferences =
|
||||||
auto* embedder = manager->GetEmbedder(guest_instance_id_);
|
WebContentsPreferences::From(embedder->web_contents());
|
||||||
if (embedder) {
|
|
||||||
auto* embedder_preferences = WebContentsPreferences::From(embedder);
|
|
||||||
if (embedder_preferences && embedder_preferences->IsOffscreen()) {
|
if (embedder_preferences && embedder_preferences->IsOffscreen()) {
|
||||||
offscreen_ = true;
|
offscreen_ = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
WebContentsPreferences::~WebContentsPreferences() {
|
WebContentsPreferences::~WebContentsPreferences() {
|
||||||
Instances().erase(std::remove(Instances().begin(), Instances().end(), this),
|
Instances().erase(std::remove(Instances().begin(), Instances().end(), this),
|
||||||
|
@ -150,7 +147,7 @@ void WebContentsPreferences::Clear() {
|
||||||
minimum_font_size_ = absl::nullopt;
|
minimum_font_size_ = absl::nullopt;
|
||||||
default_encoding_ = absl::nullopt;
|
default_encoding_ = absl::nullopt;
|
||||||
opener_id_ = 0;
|
opener_id_ = 0;
|
||||||
guest_instance_id_ = 0;
|
is_webview_ = false;
|
||||||
custom_args_.clear();
|
custom_args_.clear();
|
||||||
custom_switches_.clear();
|
custom_switches_.clear();
|
||||||
enable_blink_features_ = absl::nullopt;
|
enable_blink_features_ = absl::nullopt;
|
||||||
|
@ -223,7 +220,6 @@ void WebContentsPreferences::Merge(
|
||||||
if (web_preferences.Get("defaultEncoding", &encoding))
|
if (web_preferences.Get("defaultEncoding", &encoding))
|
||||||
default_encoding_ = encoding;
|
default_encoding_ = encoding;
|
||||||
web_preferences.Get(options::kOpenerID, &opener_id_);
|
web_preferences.Get(options::kOpenerID, &opener_id_);
|
||||||
web_preferences.Get(options::kGuestInstanceID, &guest_instance_id_);
|
|
||||||
web_preferences.Get(options::kCustomArgs, &custom_args_);
|
web_preferences.Get(options::kCustomArgs, &custom_args_);
|
||||||
web_preferences.Get("commandLineSwitches", &custom_switches_);
|
web_preferences.Get("commandLineSwitches", &custom_switches_);
|
||||||
web_preferences.Get("disablePopups", &disable_popups_);
|
web_preferences.Get("disablePopups", &disable_popups_);
|
||||||
|
@ -263,6 +259,11 @@ void WebContentsPreferences::Merge(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string type;
|
||||||
|
if (web_preferences.Get(options::kType, &type)) {
|
||||||
|
is_webview_ = type == "webview";
|
||||||
|
}
|
||||||
|
|
||||||
web_preferences.Get("v8CacheOptions", &v8_cache_options_);
|
web_preferences.Get("v8CacheOptions", &v8_cache_options_);
|
||||||
|
|
||||||
#if defined(OS_MAC)
|
#if defined(OS_MAC)
|
||||||
|
@ -459,20 +460,16 @@ void WebContentsPreferences::OverrideWebkitPrefs(
|
||||||
|
|
||||||
// Run Electron APIs and preload script in isolated world
|
// Run Electron APIs and preload script in isolated world
|
||||||
prefs->context_isolation = context_isolation_;
|
prefs->context_isolation = context_isolation_;
|
||||||
prefs->guest_instance_id = guest_instance_id_;
|
prefs->is_webview = is_webview_;
|
||||||
|
|
||||||
prefs->hidden_page = false;
|
prefs->hidden_page = false;
|
||||||
if (guest_instance_id_) {
|
|
||||||
// Webview `document.visibilityState` tracks window visibility so we need
|
// Webview `document.visibilityState` tracks window visibility so we need
|
||||||
// to let it know if the window happens to be hidden right now.
|
// to let it know if the window happens to be hidden right now.
|
||||||
auto* manager = WebViewManager::GetWebViewManager(web_contents_);
|
if (auto* api_web_contents = api::WebContents::From(web_contents_)) {
|
||||||
if (manager) {
|
if (electron::api::WebContents* embedder = api_web_contents->embedder()) {
|
||||||
auto* embedder = manager->GetEmbedder(guest_instance_id_);
|
if (auto* relay =
|
||||||
if (embedder) {
|
NativeWindowRelay::FromWebContents(embedder->web_contents())) {
|
||||||
auto* relay = NativeWindowRelay::FromWebContents(embedder);
|
if (auto* window = relay->GetNativeWindow()) {
|
||||||
if (relay) {
|
|
||||||
auto* window = relay->GetNativeWindow();
|
|
||||||
if (window) {
|
|
||||||
const bool visible = window->IsVisible() && !window->IsMinimized();
|
const bool visible = window->IsVisible() && !window->IsMinimized();
|
||||||
if (!visible) {
|
if (!visible) {
|
||||||
prefs->hidden_page = true;
|
prefs->hidden_page = true;
|
||||||
|
@ -481,7 +478,6 @@ void WebContentsPreferences::OverrideWebkitPrefs(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
prefs->offscreen = offscreen_;
|
prefs->offscreen = offscreen_;
|
||||||
|
|
||||||
|
|
|
@ -110,7 +110,7 @@ class WebContentsPreferences
|
||||||
absl::optional<int> minimum_font_size_;
|
absl::optional<int> minimum_font_size_;
|
||||||
absl::optional<std::string> default_encoding_;
|
absl::optional<std::string> default_encoding_;
|
||||||
int opener_id_;
|
int opener_id_;
|
||||||
int guest_instance_id_;
|
bool is_webview_;
|
||||||
std::vector<std::string> custom_args_;
|
std::vector<std::string> custom_args_;
|
||||||
std::vector<std::string> custom_switches_;
|
std::vector<std::string> custom_switches_;
|
||||||
absl::optional<std::string> enable_blink_features_;
|
absl::optional<std::string> enable_blink_features_;
|
||||||
|
|
|
@ -23,12 +23,6 @@ void WebViewManager::RemoveGuest(int guest_instance_id) {
|
||||||
web_contents_embedder_map_.erase(guest_instance_id);
|
web_contents_embedder_map_.erase(guest_instance_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
content::WebContents* WebViewManager::GetEmbedder(int guest_instance_id) {
|
|
||||||
const auto iter = web_contents_embedder_map_.find(guest_instance_id);
|
|
||||||
return iter == std::end(web_contents_embedder_map_) ? nullptr
|
|
||||||
: iter->second.embedder;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool WebViewManager::ForEachGuest(content::WebContents* embedder_web_contents,
|
bool WebViewManager::ForEachGuest(content::WebContents* embedder_web_contents,
|
||||||
const GuestCallback& callback) {
|
const GuestCallback& callback) {
|
||||||
for (auto& item : web_contents_embedder_map_) {
|
for (auto& item : web_contents_embedder_map_) {
|
||||||
|
|
|
@ -20,7 +20,6 @@ class WebViewManager : public content::BrowserPluginGuestManager {
|
||||||
content::WebContents* embedder,
|
content::WebContents* embedder,
|
||||||
content::WebContents* web_contents);
|
content::WebContents* web_contents);
|
||||||
void RemoveGuest(int guest_instance_id);
|
void RemoveGuest(int guest_instance_id);
|
||||||
content::WebContents* GetEmbedder(int guest_instance_id);
|
|
||||||
|
|
||||||
static WebViewManager* GetWebViewManager(content::WebContents* web_contents);
|
static WebViewManager* GetWebViewManager(content::WebContents* web_contents);
|
||||||
|
|
||||||
|
|
|
@ -121,9 +121,6 @@ const char kNodeIntegration[] = "nodeIntegration";
|
||||||
// Enable context isolation of Electron APIs and preload script
|
// Enable context isolation of Electron APIs and preload script
|
||||||
const char kContextIsolation[] = "contextIsolation";
|
const char kContextIsolation[] = "contextIsolation";
|
||||||
|
|
||||||
// Instance ID of guest WebContents.
|
|
||||||
const char kGuestInstanceID[] = "guestInstanceId";
|
|
||||||
|
|
||||||
// Web runtime features.
|
// Web runtime features.
|
||||||
const char kExperimentalFeatures[] = "experimentalFeatures";
|
const char kExperimentalFeatures[] = "experimentalFeatures";
|
||||||
|
|
||||||
|
|
|
@ -66,7 +66,6 @@ extern const char kPreloadScripts[];
|
||||||
extern const char kPreloadURL[];
|
extern const char kPreloadURL[];
|
||||||
extern const char kNodeIntegration[];
|
extern const char kNodeIntegration[];
|
||||||
extern const char kContextIsolation[];
|
extern const char kContextIsolation[];
|
||||||
extern const char kGuestInstanceID[];
|
|
||||||
extern const char kExperimentalFeatures[];
|
extern const char kExperimentalFeatures[];
|
||||||
extern const char kOpenerID[];
|
extern const char kOpenerID[];
|
||||||
extern const char kScrollBounce[];
|
extern const char kScrollBounce[];
|
||||||
|
|
|
@ -493,9 +493,8 @@ class WebFrameRenderer : public gin::Wrappable<WebFrameRenderer>,
|
||||||
return gin::ConvertToV8(isolate, prefs.opener_id);
|
return gin::ConvertToV8(isolate, prefs.opener_id);
|
||||||
} else if (pref_name == options::kContextIsolation) {
|
} else if (pref_name == options::kContextIsolation) {
|
||||||
return gin::ConvertToV8(isolate, prefs.context_isolation);
|
return gin::ConvertToV8(isolate, prefs.context_isolation);
|
||||||
} else if (pref_name == options::kGuestInstanceID) {
|
} else if (pref_name == "isWebView") {
|
||||||
// NOTE: guestInstanceId is internal-only.
|
return gin::ConvertToV8(isolate, prefs.is_webview);
|
||||||
return gin::ConvertToV8(isolate, prefs.guest_instance_id);
|
|
||||||
} else if (pref_name == options::kHiddenPage) {
|
} else if (pref_name == options::kHiddenPage) {
|
||||||
// NOTE: hiddenPage is internal-only.
|
// NOTE: hiddenPage is internal-only.
|
||||||
return gin::ConvertToV8(isolate, prefs.hidden_page);
|
return gin::ConvertToV8(isolate, prefs.hidden_page);
|
||||||
|
|
2
typings/internal-ambient.d.ts
vendored
2
typings/internal-ambient.d.ts
vendored
|
@ -108,7 +108,7 @@ declare namespace NodeJS {
|
||||||
|
|
||||||
interface InternalWebPreferences {
|
interface InternalWebPreferences {
|
||||||
contextIsolation: boolean;
|
contextIsolation: boolean;
|
||||||
guestInstanceId: number;
|
isWebView: boolean;
|
||||||
hiddenPage: boolean;
|
hiddenPage: boolean;
|
||||||
nativeWindowOpen: boolean;
|
nativeWindowOpen: boolean;
|
||||||
nodeIntegration: boolean;
|
nodeIntegration: boolean;
|
||||||
|
|
1
typings/internal-electron.d.ts
vendored
1
typings/internal-electron.d.ts
vendored
|
@ -90,7 +90,6 @@ declare namespace Electron {
|
||||||
}
|
}
|
||||||
|
|
||||||
interface WebPreferences {
|
interface WebPreferences {
|
||||||
guestInstanceId?: number;
|
|
||||||
openerId?: number | null;
|
openerId?: number | null;
|
||||||
disablePopups?: boolean;
|
disablePopups?: boolean;
|
||||||
preloadURL?: string;
|
preloadURL?: string;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue