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
|
@ -19,8 +19,8 @@
|
|||
#include "content/public/common/content_switches.h"
|
||||
#include "net/base/filename_util.h"
|
||||
#include "sandbox/policy/switches.h"
|
||||
#include "shell/browser/api/electron_api_web_contents.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_helper/dictionary.h"
|
||||
#include "shell/common/options_switches.h"
|
||||
|
@ -103,15 +103,12 @@ WebContentsPreferences::WebContentsPreferences(
|
|||
|
||||
// If this is a <webview> tag, and the embedder is offscreen-rendered, then
|
||||
// this WebContents is also offscreen-rendered.
|
||||
if (guest_instance_id_) {
|
||||
auto* manager = WebViewManager::GetWebViewManager(web_contents);
|
||||
if (manager) {
|
||||
auto* embedder = manager->GetEmbedder(guest_instance_id_);
|
||||
if (embedder) {
|
||||
auto* embedder_preferences = WebContentsPreferences::From(embedder);
|
||||
if (embedder_preferences && embedder_preferences->IsOffscreen()) {
|
||||
offscreen_ = true;
|
||||
}
|
||||
if (auto* api_web_contents = api::WebContents::From(web_contents_)) {
|
||||
if (electron::api::WebContents* embedder = api_web_contents->embedder()) {
|
||||
auto* embedder_preferences =
|
||||
WebContentsPreferences::From(embedder->web_contents());
|
||||
if (embedder_preferences && embedder_preferences->IsOffscreen()) {
|
||||
offscreen_ = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -150,7 +147,7 @@ void WebContentsPreferences::Clear() {
|
|||
minimum_font_size_ = absl::nullopt;
|
||||
default_encoding_ = absl::nullopt;
|
||||
opener_id_ = 0;
|
||||
guest_instance_id_ = 0;
|
||||
is_webview_ = false;
|
||||
custom_args_.clear();
|
||||
custom_switches_.clear();
|
||||
enable_blink_features_ = absl::nullopt;
|
||||
|
@ -223,7 +220,6 @@ void WebContentsPreferences::Merge(
|
|||
if (web_preferences.Get("defaultEncoding", &encoding))
|
||||
default_encoding_ = encoding;
|
||||
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("commandLineSwitches", &custom_switches_);
|
||||
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_);
|
||||
|
||||
#if defined(OS_MAC)
|
||||
|
@ -459,24 +460,19 @@ void WebContentsPreferences::OverrideWebkitPrefs(
|
|||
|
||||
// Run Electron APIs and preload script in isolated world
|
||||
prefs->context_isolation = context_isolation_;
|
||||
prefs->guest_instance_id = guest_instance_id_;
|
||||
prefs->is_webview = is_webview_;
|
||||
|
||||
prefs->hidden_page = false;
|
||||
if (guest_instance_id_) {
|
||||
// Webview `document.visibilityState` tracks window visibility so we need
|
||||
// to let it know if the window happens to be hidden right now.
|
||||
auto* manager = WebViewManager::GetWebViewManager(web_contents_);
|
||||
if (manager) {
|
||||
auto* embedder = manager->GetEmbedder(guest_instance_id_);
|
||||
if (embedder) {
|
||||
auto* relay = NativeWindowRelay::FromWebContents(embedder);
|
||||
if (relay) {
|
||||
auto* window = relay->GetNativeWindow();
|
||||
if (window) {
|
||||
const bool visible = window->IsVisible() && !window->IsMinimized();
|
||||
if (!visible) {
|
||||
prefs->hidden_page = true;
|
||||
}
|
||||
// Webview `document.visibilityState` tracks window visibility so we need
|
||||
// to let it know if the window happens to be hidden right now.
|
||||
if (auto* api_web_contents = api::WebContents::From(web_contents_)) {
|
||||
if (electron::api::WebContents* embedder = api_web_contents->embedder()) {
|
||||
if (auto* relay =
|
||||
NativeWindowRelay::FromWebContents(embedder->web_contents())) {
|
||||
if (auto* window = relay->GetNativeWindow()) {
|
||||
const bool visible = window->IsVisible() && !window->IsMinimized();
|
||||
if (!visible) {
|
||||
prefs->hidden_page = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -110,7 +110,7 @@ class WebContentsPreferences
|
|||
absl::optional<int> minimum_font_size_;
|
||||
absl::optional<std::string> default_encoding_;
|
||||
int opener_id_;
|
||||
int guest_instance_id_;
|
||||
bool is_webview_;
|
||||
std::vector<std::string> custom_args_;
|
||||
std::vector<std::string> custom_switches_;
|
||||
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);
|
||||
}
|
||||
|
||||
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,
|
||||
const GuestCallback& callback) {
|
||||
for (auto& item : web_contents_embedder_map_) {
|
||||
|
|
|
@ -20,7 +20,6 @@ class WebViewManager : public content::BrowserPluginGuestManager {
|
|||
content::WebContents* embedder,
|
||||
content::WebContents* web_contents);
|
||||
void RemoveGuest(int guest_instance_id);
|
||||
content::WebContents* GetEmbedder(int guest_instance_id);
|
||||
|
||||
static WebViewManager* GetWebViewManager(content::WebContents* web_contents);
|
||||
|
||||
|
|
|
@ -121,9 +121,6 @@ const char kNodeIntegration[] = "nodeIntegration";
|
|||
// Enable context isolation of Electron APIs and preload script
|
||||
const char kContextIsolation[] = "contextIsolation";
|
||||
|
||||
// Instance ID of guest WebContents.
|
||||
const char kGuestInstanceID[] = "guestInstanceId";
|
||||
|
||||
// Web runtime features.
|
||||
const char kExperimentalFeatures[] = "experimentalFeatures";
|
||||
|
||||
|
|
|
@ -66,7 +66,6 @@ extern const char kPreloadScripts[];
|
|||
extern const char kPreloadURL[];
|
||||
extern const char kNodeIntegration[];
|
||||
extern const char kContextIsolation[];
|
||||
extern const char kGuestInstanceID[];
|
||||
extern const char kExperimentalFeatures[];
|
||||
extern const char kOpenerID[];
|
||||
extern const char kScrollBounce[];
|
||||
|
|
|
@ -493,9 +493,8 @@ class WebFrameRenderer : public gin::Wrappable<WebFrameRenderer>,
|
|||
return gin::ConvertToV8(isolate, prefs.opener_id);
|
||||
} else if (pref_name == options::kContextIsolation) {
|
||||
return gin::ConvertToV8(isolate, prefs.context_isolation);
|
||||
} else if (pref_name == options::kGuestInstanceID) {
|
||||
// NOTE: guestInstanceId is internal-only.
|
||||
return gin::ConvertToV8(isolate, prefs.guest_instance_id);
|
||||
} else if (pref_name == "isWebView") {
|
||||
return gin::ConvertToV8(isolate, prefs.is_webview);
|
||||
} else if (pref_name == options::kHiddenPage) {
|
||||
// NOTE: hiddenPage is internal-only.
|
||||
return gin::ConvertToV8(isolate, prefs.hidden_page);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue