Skip to content

Commit beee373

Browse files
authored
fix: offscreen mode under window.open creation (#48070)
fix: offscreen mode under window.open creation
1 parent a11d4eb commit beee373

11 files changed

+124
-18
lines changed

patches/chromium/can_create_window.patch

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,21 @@ index 23cd457563d7d534e924428ac6da2b475e579326..d8698f9f37eefa50bf4e29a164b2cc30
2121
&no_javascript_access);
2222

2323
diff --git a/content/browser/web_contents/web_contents_impl.cc b/content/browser/web_contents/web_contents_impl.cc
24-
index f3204a39253652a906f8976c666395e8afa033a8..a45bf004f5096809b5fc7b70faa0b7fa7b257049 100644
24+
index f3204a39253652a906f8976c666395e8afa033a8..d9b5a70e0c7acfaac312663ba336580eb062fae4 100644
2525
--- a/content/browser/web_contents/web_contents_impl.cc
2626
+++ b/content/browser/web_contents/web_contents_impl.cc
27-
@@ -5293,6 +5293,12 @@ FrameTree* WebContentsImpl::CreateNewWindow(
27+
@@ -5238,6 +5238,10 @@ FrameTree* WebContentsImpl::CreateNewWindow(
28+
create_params.initially_hidden = renderer_started_hidden;
29+
create_params.initial_popup_url = params.target_url;
30+
31+
+ // Potentially allow the delegate to override the create_params.
32+
+ if (delegate_)
33+
+ delegate_->MaybeOverrideCreateParamsForNewWindow(&create_params);
34+
+
35+
// Even though all codepaths leading here are in response to a renderer
36+
// trying to open a new window, if the new window ends up in a different
37+
// browsing instance, then the RenderViewHost, RenderWidgetHost,
38+
@@ -5293,6 +5297,12 @@ FrameTree* WebContentsImpl::CreateNewWindow(
2839
// Sets the newly created WebContents WindowOpenDisposition.
2940
new_contents_impl->original_window_open_disposition_ = params.disposition;
3041

@@ -37,7 +48,7 @@ index f3204a39253652a906f8976c666395e8afa033a8..a45bf004f5096809b5fc7b70faa0b7fa
3748
// If the new frame has a name, make sure any SiteInstances that can find
3849
// this named frame have proxies for it. Must be called after
3950
// SetSessionStorageNamespace, since this calls CreateRenderView, which uses
40-
@@ -5334,12 +5340,6 @@ FrameTree* WebContentsImpl::CreateNewWindow(
51+
@@ -5334,12 +5344,6 @@ FrameTree* WebContentsImpl::CreateNewWindow(
4152
AddWebContentsDestructionObserver(new_contents_impl);
4253
}
4354

@@ -122,7 +133,7 @@ index f42be2a1cc5ba3ccb52e48985e0532a34675e826..f6ab6ab2b036c7621b429181c3ff89d9
122133
WebContents* source,
123134
const OpenURLParams& params,
124135
diff --git a/content/public/browser/web_contents_delegate.h b/content/public/browser/web_contents_delegate.h
125-
index d33274984bf6523beeb3ab5ee586499d224bff3c..83bdd195339eb7d61ac88e2994fd8dabe93f6ecc 100644
136+
index d33274984bf6523beeb3ab5ee586499d224bff3c..89c3f86bc828c5bf844bb103477c0772ba275dc5 100644
126137
--- a/content/public/browser/web_contents_delegate.h
127138
+++ b/content/public/browser/web_contents_delegate.h
128139
@@ -18,6 +18,7 @@
@@ -133,7 +144,7 @@ index d33274984bf6523beeb3ab5ee586499d224bff3c..83bdd195339eb7d61ac88e2994fd8dab
133144
#include "content/public/browser/eye_dropper.h"
134145
#include "content/public/browser/fullscreen_types.h"
135146
#include "content/public/browser/invalidate_type.h"
136-
@@ -380,6 +381,13 @@ class CONTENT_EXPORT WebContentsDelegate {
147+
@@ -380,6 +381,16 @@ class CONTENT_EXPORT WebContentsDelegate {
137148
const StoragePartitionConfig& partition_config,
138149
SessionStorageNamespace* session_storage_namespace);
139150

@@ -143,6 +154,9 @@ index d33274984bf6523beeb3ab5ee586499d224bff3c..83bdd195339eb7d61ac88e2994fd8dab
143154
+ int opener_render_frame_id,
144155
+ const mojom::CreateNewWindowParams& params,
145156
+ WebContents* new_contents);
157+
+
158+
+ virtual void MaybeOverrideCreateParamsForNewWindow(
159+
+ content::WebContents::CreateParams* create_params) {}
146160
+
147161
// Notifies the delegate about the creation of a new WebContents. This
148162
// typically happens when popups are created.

patches/chromium/chore_partial_revert_of.patch

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ track down the source of this problem & figure out if we can fix it
1414
by changing something in Electron.
1515

1616
diff --git a/content/browser/web_contents/web_contents_impl.cc b/content/browser/web_contents/web_contents_impl.cc
17-
index 0fba6e8b5f1f9ecde06b9d846b4ace984cdfc943..b50e3c2ecb6f9f3322cfd16fc7bcbd8935f863a2 100644
17+
index c2ce5a360607a304d8435d6e58a4f0895dd08056..71d85d2e3111457eca540e80bf8a68ebc548d440 100644
1818
--- a/content/browser/web_contents/web_contents_impl.cc
1919
+++ b/content/browser/web_contents/web_contents_impl.cc
2020
@@ -5209,7 +5209,7 @@ FrameTree* WebContentsImpl::CreateNewWindow(

patches/chromium/chore_provide_iswebcontentscreationoverridden_with_full_params.patch

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ index b969f1d97b7e3396119b579cfbe61e19ff7d2dd4..b8d6169652da28266a514938b45b39c5
222222
content::WebContents* AddNewContents(
223223
content::WebContents* source,
224224
diff --git a/content/browser/web_contents/web_contents_impl.cc b/content/browser/web_contents/web_contents_impl.cc
225-
index c034b546289ba069194ad65d3d3bc0703a3afe9c..e603c0fddbf4efaeb225686c1791ffb581e9e6c0 100644
225+
index d57f205ea7dd4737126ddd7f2284d72eddae9e8f..bf6a239f566ec39efdacce5b74014d2995ba868e 100644
226226
--- a/content/browser/web_contents/web_contents_impl.cc
227227
+++ b/content/browser/web_contents/web_contents_impl.cc
228228
@@ -5172,8 +5172,7 @@ FrameTree* WebContentsImpl::CreateNewWindow(
@@ -250,7 +250,7 @@ index f6ab6ab2b036c7621b429181c3ff89d9f1ff77f9..d151ba757ae81c6f023ee08328ab1554
250250
}
251251

252252
diff --git a/content/public/browser/web_contents_delegate.h b/content/public/browser/web_contents_delegate.h
253-
index 83bdd195339eb7d61ac88e2994fd8dabe93f6ecc..682e5eecb7ce514094f76253447aa7ac4b6f29b1 100644
253+
index 89c3f86bc828c5bf844bb103477c0772ba275dc5..c3eef892eef2c42c46926be223fe950823e6943d 100644
254254
--- a/content/public/browser/web_contents_delegate.h
255255
+++ b/content/public/browser/web_contents_delegate.h
256256
@@ -359,8 +359,7 @@ class CONTENT_EXPORT WebContentsDelegate {

patches/chromium/fix_on-screen-keyboard_hides_on_input_blur_in_webview.patch

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,10 @@ index 75df43e3cd2721a92c90c18154d53d5c203e2465..ce42c75c8face36d21f53f44c0201ac4
8787
// The view with active text input state, i.e., a focused <input> element.
8888
// It will be nullptr if no such view exists. Note that the active view
8989
diff --git a/content/browser/web_contents/web_contents_impl.cc b/content/browser/web_contents/web_contents_impl.cc
90-
index 374d5f1a1685229865d0f1f1032f36bbcd54e92e..0fba6e8b5f1f9ecde06b9d846b4ace984cdfc943 100644
90+
index 837913b6b82e473e8fa90209924b245d28e922e7..c2ce5a360607a304d8435d6e58a4f0895dd08056 100644
9191
--- a/content/browser/web_contents/web_contents_impl.cc
9292
+++ b/content/browser/web_contents/web_contents_impl.cc
93-
@@ -10071,7 +10071,7 @@ void WebContentsImpl::OnFocusedElementChangedInFrame(
93+
@@ -10075,7 +10075,7 @@ void WebContentsImpl::OnFocusedElementChangedInFrame(
9494
"WebContentsImpl::OnFocusedElementChangedInFrame",
9595
"render_frame_host", frame);
9696
RenderWidgetHostViewBase* root_view =

patches/chromium/refactor_expose_cursor_changes_to_the_webcontentsobserver.patch

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,10 @@ index 624094ba6459f3663a12f868c4cb47dfa9f8dce1..eed851d277c5efa2d5ca594e18eaf7df
4444

4545
void RenderWidgetHostImpl::ShowContextMenuAtPoint(
4646
diff --git a/content/browser/web_contents/web_contents_impl.cc b/content/browser/web_contents/web_contents_impl.cc
47-
index a45bf004f5096809b5fc7b70faa0b7fa7b257049..c034b546289ba069194ad65d3d3bc0703a3afe9c 100644
47+
index d9b5a70e0c7acfaac312663ba336580eb062fae4..d57f205ea7dd4737126ddd7f2284d72eddae9e8f 100644
4848
--- a/content/browser/web_contents/web_contents_impl.cc
4949
+++ b/content/browser/web_contents/web_contents_impl.cc
50-
@@ -6045,6 +6045,11 @@ TextInputManager* WebContentsImpl::GetTextInputManager() {
50+
@@ -6049,6 +6049,11 @@ TextInputManager* WebContentsImpl::GetTextInputManager() {
5151
return text_input_manager_.get();
5252
}
5353

patches/chromium/refactor_unfilter_unresponsive_events.patch

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ This CL removes these filters so the unresponsive event can still be
1515
accessed from our JS event. The filtering is moved into Electron's code.
1616

1717
diff --git a/content/browser/web_contents/web_contents_impl.cc b/content/browser/web_contents/web_contents_impl.cc
18-
index b50e3c2ecb6f9f3322cfd16fc7bcbd8935f863a2..d7afac20523d2900cbefa5ab3ea9f0863780b704 100644
18+
index 71d85d2e3111457eca540e80bf8a68ebc548d440..7be5466f9e81be22676d65bc04af6404c1da9f3b 100644
1919
--- a/content/browser/web_contents/web_contents_impl.cc
2020
+++ b/content/browser/web_contents/web_contents_impl.cc
21-
@@ -10208,25 +10208,13 @@ void WebContentsImpl::RendererUnresponsive(
21+
@@ -10212,25 +10212,13 @@ void WebContentsImpl::RendererUnresponsive(
2222
base::RepeatingClosure hang_monitor_restarter) {
2323
OPTIONAL_TRACE_EVENT1("content", "WebContentsImpl::RendererUnresponsive",
2424
"render_widget_host", render_widget_host);

patches/chromium/web_contents.patch

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ is needed for OSR.
99
Originally landed in https://github.com/electron/libchromiumcontent/pull/226.
1010

1111
diff --git a/content/browser/web_contents/web_contents_impl.cc b/content/browser/web_contents/web_contents_impl.cc
12-
index e603c0fddbf4efaeb225686c1791ffb581e9e6c0..88d7b948d57f53fcd681856587f79ece991ee8fa 100644
12+
index bf6a239f566ec39efdacce5b74014d2995ba868e..e233701dddea01dd727dcd02d096b331c8aeff97 100644
1313
--- a/content/browser/web_contents/web_contents_impl.cc
1414
+++ b/content/browser/web_contents/web_contents_impl.cc
1515
@@ -4079,6 +4079,13 @@ void WebContentsImpl::Init(const WebContents::CreateParams& params,

patches/chromium/webview_fullscreen.patch

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ index d8698f9f37eefa50bf4e29a164b2cc302c32ecdf..3a8dc82b882aa00e9a5430bc8b7ba409
3737
if (had_fullscreen_token && !GetView()->HasFocus())
3838
GetView()->Focus();
3939
diff --git a/content/browser/web_contents/web_contents_impl.cc b/content/browser/web_contents/web_contents_impl.cc
40-
index 88d7b948d57f53fcd681856587f79ece991ee8fa..374d5f1a1685229865d0f1f1032f36bbcd54e92e 100644
40+
index e233701dddea01dd727dcd02d096b331c8aeff97..837913b6b82e473e8fa90209924b245d28e922e7 100644
4141
--- a/content/browser/web_contents/web_contents_impl.cc
4242
+++ b/content/browser/web_contents/web_contents_impl.cc
4343
@@ -4369,21 +4369,25 @@ KeyboardEventProcessingResult WebContentsImpl::PreHandleKeyboardEvent(

shell/browser/api/electron_api_web_contents.cc

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1209,6 +1209,31 @@ content::WebContents* WebContents::CreateCustomWebContents(
12091209
return nullptr;
12101210
}
12111211

1212+
void WebContents::MaybeOverrideCreateParamsForNewWindow(
1213+
content::WebContents::CreateParams* create_params) {
1214+
v8::Isolate* isolate = JavascriptEnvironment::GetIsolate();
1215+
v8::HandleScope handle_scope(isolate);
1216+
gin_helper::Dictionary dict;
1217+
gin::ConvertFromV8(isolate, pending_child_web_preferences_.Get(isolate),
1218+
&dict);
1219+
1220+
v8::Local<v8::Value> use_offscreen;
1221+
if (dict.Get(options::kOffscreen, &use_offscreen)) {
1222+
bool is_offscreen =
1223+
use_offscreen->IsObject() ||
1224+
(use_offscreen->IsBoolean() &&
1225+
dict.Get(options::kOffscreen, &is_offscreen) && is_offscreen);
1226+
1227+
if (is_offscreen) {
1228+
auto* view = new OffScreenWebContentsView(
1229+
false, offscreen_use_shared_texture_,
1230+
base::BindRepeating(&WebContents::OnPaint, base::Unretained(this)));
1231+
create_params->view = view;
1232+
create_params->delegate_view = view;
1233+
}
1234+
}
1235+
}
1236+
12121237
content::WebContents* WebContents::AddNewContents(
12131238
content::WebContents* source,
12141239
std::unique_ptr<content::WebContents> new_contents,
@@ -1222,9 +1247,13 @@ content::WebContents* WebContents::AddNewContents(
12221247

12231248
v8::Isolate* isolate = JavascriptEnvironment::GetIsolate();
12241249

1250+
Type type = Type::kBrowserWindow;
1251+
auto* web_preferences = WebContentsPreferences::From(new_contents.get());
1252+
if (web_preferences && web_preferences->IsOffscreen())
1253+
type = Type::kOffScreen;
1254+
12251255
v8::HandleScope handle_scope(isolate);
1226-
auto api_web_contents =
1227-
CreateAndTake(isolate, std::move(new_contents), Type::kBrowserWindow);
1256+
auto api_web_contents = CreateAndTake(isolate, std::move(new_contents), type);
12281257

12291258
// We call RenderFrameCreated here as at this point the empty "about:blank"
12301259
// render frame has already been created. If the window never navigates again

shell/browser/api/electron_api_web_contents.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -508,6 +508,8 @@ class WebContents final : public ExclusiveAccessContext,
508508
int opener_render_frame_id,
509509
const content::mojom::CreateNewWindowParams& params,
510510
content::WebContents* new_contents) override;
511+
void MaybeOverrideCreateParamsForNewWindow(
512+
content::WebContents::CreateParams* create_params) override;
511513
content::WebContents* AddNewContents(
512514
content::WebContents* source,
513515
std::unique_ptr<content::WebContents> new_contents,

0 commit comments

Comments
 (0)