mirror of
https://github.com/electron/electron.git
synced 2026-01-10 07:58:08 -05:00
fix: offscreen mode under window.open creation
This commit is contained in:
@@ -21,23 +21,34 @@ index 775a132ea523c509433a3a9560fe3a5419dfaa3f..2b99d0b584760ab3f51561c030ca1990
|
||||
&no_javascript_access);
|
||||
|
||||
diff --git a/content/browser/web_contents/web_contents_impl.cc b/content/browser/web_contents/web_contents_impl.cc
|
||||
index 2896b2b15d9c22e27c37719867c20213b9983984..83c5918c1bc0417ed3c744828b9f93e7c00d22c3 100644
|
||||
index 2896b2b15d9c22e27c37719867c20213b9983984..572dfd03c9e76a0a71e511dade83f1877ae85b4a 100644
|
||||
--- a/content/browser/web_contents/web_contents_impl.cc
|
||||
+++ b/content/browser/web_contents/web_contents_impl.cc
|
||||
@@ -5101,6 +5101,12 @@ FrameTree* WebContentsImpl::CreateNewWindow(
|
||||
@@ -5049,6 +5049,10 @@ FrameTree* WebContentsImpl::CreateNewWindow(
|
||||
create_params.initially_hidden = renderer_started_hidden;
|
||||
create_params.initial_popup_url = params.target_url;
|
||||
|
||||
+ // Potentially allow the delegate to override the create_params.
|
||||
+ if (delegate_)
|
||||
+ delegate_->MaybeOverrideCreateParamsForNewWindow(&create_params);
|
||||
+
|
||||
// Even though all codepaths leading here are in response to a renderer
|
||||
// trying to open a new window, if the new window ends up in a different
|
||||
// browsing instance, then the RenderViewHost, RenderWidgetHost,
|
||||
@@ -5101,6 +5105,12 @@ FrameTree* WebContentsImpl::CreateNewWindow(
|
||||
SetPartitionedPopinOpenerOnNewWindowIfNeeded(new_contents_impl, params,
|
||||
opener);
|
||||
|
||||
+ if (delegate_) {
|
||||
+ delegate_->WebContentsCreatedWithFullParams(this, render_process_id,
|
||||
+ opener->GetRoutingID(),
|
||||
+ params, new_contents_impl);
|
||||
+ delegate_->WebContentsCreated(this, render_process_id,
|
||||
+ opener->GetRoutingID(), params.frame_name,
|
||||
+ params.target_url, new_contents_impl);
|
||||
+ }
|
||||
+
|
||||
// If the new frame has a name, make sure any SiteInstances that can find
|
||||
// this named frame have proxies for it. Must be called after
|
||||
// SetSessionStorageNamespace, since this calls CreateRenderView, which uses
|
||||
@@ -5142,12 +5148,6 @@ FrameTree* WebContentsImpl::CreateNewWindow(
|
||||
@@ -5142,12 +5152,6 @@ FrameTree* WebContentsImpl::CreateNewWindow(
|
||||
AddWebContentsDestructionObserver(new_contents_impl);
|
||||
}
|
||||
|
||||
@@ -122,7 +133,7 @@ index b390356721fa226c348923f33601c4a1a2d9702d..97a3ea6f292563a41fd41f812ac72526
|
||||
WebContents* source,
|
||||
const OpenURLParams& params,
|
||||
diff --git a/content/public/browser/web_contents_delegate.h b/content/public/browser/web_contents_delegate.h
|
||||
index da319cb20733150366d85bee95609f0f2d9def7f..8a18958035cc1dd26be558349f64f7727570c4ba 100644
|
||||
index da319cb20733150366d85bee95609f0f2d9def7f..a5e731806c4c8418a36ee89d4689f43b41d2d7eb 100644
|
||||
--- a/content/public/browser/web_contents_delegate.h
|
||||
+++ b/content/public/browser/web_contents_delegate.h
|
||||
@@ -18,6 +18,7 @@
|
||||
@@ -133,7 +144,7 @@ index da319cb20733150366d85bee95609f0f2d9def7f..8a18958035cc1dd26be558349f64f772
|
||||
#include "content/public/browser/eye_dropper.h"
|
||||
#include "content/public/browser/fullscreen_types.h"
|
||||
#include "content/public/browser/invalidate_type.h"
|
||||
@@ -376,6 +377,13 @@ class CONTENT_EXPORT WebContentsDelegate {
|
||||
@@ -376,6 +377,16 @@ class CONTENT_EXPORT WebContentsDelegate {
|
||||
const StoragePartitionConfig& partition_config,
|
||||
SessionStorageNamespace* session_storage_namespace);
|
||||
|
||||
@@ -143,6 +154,9 @@ index da319cb20733150366d85bee95609f0f2d9def7f..8a18958035cc1dd26be558349f64f772
|
||||
+ int opener_render_frame_id,
|
||||
+ const mojom::CreateNewWindowParams& params,
|
||||
+ WebContents* new_contents);
|
||||
+
|
||||
+ virtual void MaybeOverrideCreateParamsForNewWindow(
|
||||
+ content::WebContents::CreateParams* create_params) {}
|
||||
+
|
||||
// Notifies the delegate about the creation of a new WebContents. This
|
||||
// typically happens when popups are created.
|
||||
|
||||
@@ -14,7 +14,7 @@ track down the source of this problem & figure out if we can fix it
|
||||
by changing something in Electron.
|
||||
|
||||
diff --git a/content/browser/web_contents/web_contents_impl.cc b/content/browser/web_contents/web_contents_impl.cc
|
||||
index 5465e9d42a5c4eed3b6f819418a7b0ab92c7eae2..54ff9675fef009c5bb79becb59146436508ad835 100644
|
||||
index dfe9ab128729d0f26c99679f8840138d654c9b59..002a8a352af6bd4acf69c5a8308e50b9a571b18d 100644
|
||||
--- a/content/browser/web_contents/web_contents_impl.cc
|
||||
+++ b/content/browser/web_contents/web_contents_impl.cc
|
||||
@@ -5020,7 +5020,7 @@ FrameTree* WebContentsImpl::CreateNewWindow(
|
||||
|
||||
@@ -218,7 +218,7 @@ index c6838c83ef971b88769b1f3fba8095025ae25464..2da6a4e08340e72ba7de5d03444c2f17
|
||||
content::WebContents* AddNewContents(
|
||||
content::WebContents* source,
|
||||
diff --git a/content/browser/web_contents/web_contents_impl.cc b/content/browser/web_contents/web_contents_impl.cc
|
||||
index d13c38de7a2e69565020ab92c874bf1289d63833..d7ec62c6761bcc8d4bb5889e873e22c4a27e7f17 100644
|
||||
index f85609c193d2f1c709f5c1beafd43f8bb82ef8c1..77b16f8c5f2aa564d4dba8f17646c516b28963dc 100644
|
||||
--- a/content/browser/web_contents/web_contents_impl.cc
|
||||
+++ b/content/browser/web_contents/web_contents_impl.cc
|
||||
@@ -4983,8 +4983,7 @@ FrameTree* WebContentsImpl::CreateNewWindow(
|
||||
@@ -246,7 +246,7 @@ index 97a3ea6f292563a41fd41f812ac72526a96d8471..b299dd5659100d317a3574e902bf2c29
|
||||
}
|
||||
|
||||
diff --git a/content/public/browser/web_contents_delegate.h b/content/public/browser/web_contents_delegate.h
|
||||
index 8a18958035cc1dd26be558349f64f7727570c4ba..7d9c9b06bcc57ef5eb0a2ca74ee20632a1393f9e 100644
|
||||
index a5e731806c4c8418a36ee89d4689f43b41d2d7eb..e53b4ff7f98c87c1da838f44f07fbc7ee09198e9 100644
|
||||
--- a/content/public/browser/web_contents_delegate.h
|
||||
+++ b/content/public/browser/web_contents_delegate.h
|
||||
@@ -355,8 +355,7 @@ class CONTENT_EXPORT WebContentsDelegate {
|
||||
|
||||
@@ -87,10 +87,10 @@ index 75df43e3cd2721a92c90c18154d53d5c203e2465..ce42c75c8face36d21f53f44c0201ac4
|
||||
// The view with active text input state, i.e., a focused <input> element.
|
||||
// It will be nullptr if no such view exists. Note that the active view
|
||||
diff --git a/content/browser/web_contents/web_contents_impl.cc b/content/browser/web_contents/web_contents_impl.cc
|
||||
index 26f41d34766899e81e32c319aad00172ffdc5fca..5465e9d42a5c4eed3b6f819418a7b0ab92c7eae2 100644
|
||||
index 52539a51fb6c180020dea20a36482e6020be1b0f..dfe9ab128729d0f26c99679f8840138d654c9b59 100644
|
||||
--- a/content/browser/web_contents/web_contents_impl.cc
|
||||
+++ b/content/browser/web_contents/web_contents_impl.cc
|
||||
@@ -9856,7 +9856,7 @@ void WebContentsImpl::OnFocusedElementChangedInFrame(
|
||||
@@ -9860,7 +9860,7 @@ void WebContentsImpl::OnFocusedElementChangedInFrame(
|
||||
"WebContentsImpl::OnFocusedElementChangedInFrame",
|
||||
"render_frame_host", frame);
|
||||
RenderWidgetHostViewBase* root_view =
|
||||
|
||||
@@ -44,10 +44,10 @@ index 20fcda4eb20459b69247003c51c2a3ed37c7b1e8..9bcab4e1e8a0fa429488555f4f7bd1c5
|
||||
|
||||
void RenderWidgetHostImpl::ShowContextMenuAtPoint(
|
||||
diff --git a/content/browser/web_contents/web_contents_impl.cc b/content/browser/web_contents/web_contents_impl.cc
|
||||
index 83c5918c1bc0417ed3c744828b9f93e7c00d22c3..d13c38de7a2e69565020ab92c874bf1289d63833 100644
|
||||
index 572dfd03c9e76a0a71e511dade83f1877ae85b4a..f85609c193d2f1c709f5c1beafd43f8bb82ef8c1 100644
|
||||
--- a/content/browser/web_contents/web_contents_impl.cc
|
||||
+++ b/content/browser/web_contents/web_contents_impl.cc
|
||||
@@ -5853,6 +5853,11 @@ TextInputManager* WebContentsImpl::GetTextInputManager() {
|
||||
@@ -5857,6 +5857,11 @@ TextInputManager* WebContentsImpl::GetTextInputManager() {
|
||||
return text_input_manager_.get();
|
||||
}
|
||||
|
||||
|
||||
@@ -15,10 +15,10 @@ This CL removes these filters so the unresponsive event can still be
|
||||
accessed from our JS event. The filtering is moved into Electron's code.
|
||||
|
||||
diff --git a/content/browser/web_contents/web_contents_impl.cc b/content/browser/web_contents/web_contents_impl.cc
|
||||
index 54ff9675fef009c5bb79becb59146436508ad835..aebd3b4fd597db7b02214dd61708711dc4ad75f3 100644
|
||||
index 002a8a352af6bd4acf69c5a8308e50b9a571b18d..cd146c716a9cd8ab593812944778674c0084c046 100644
|
||||
--- a/content/browser/web_contents/web_contents_impl.cc
|
||||
+++ b/content/browser/web_contents/web_contents_impl.cc
|
||||
@@ -9993,25 +9993,13 @@ void WebContentsImpl::RendererUnresponsive(
|
||||
@@ -9997,25 +9997,13 @@ void WebContentsImpl::RendererUnresponsive(
|
||||
base::RepeatingClosure hang_monitor_restarter) {
|
||||
OPTIONAL_TRACE_EVENT1("content", "WebContentsImpl::RendererUnresponsive",
|
||||
"render_widget_host", render_widget_host);
|
||||
|
||||
@@ -9,7 +9,7 @@ is needed for OSR.
|
||||
Originally landed in https://github.com/electron/libchromiumcontent/pull/226.
|
||||
|
||||
diff --git a/content/browser/web_contents/web_contents_impl.cc b/content/browser/web_contents/web_contents_impl.cc
|
||||
index d7ec62c6761bcc8d4bb5889e873e22c4a27e7f17..ac8aa81e213689a612d322fa75e81798ae1010e6 100644
|
||||
index 77b16f8c5f2aa564d4dba8f17646c516b28963dc..44989cbf81699e0d5f8b69bbb9e22b90930f6c6b 100644
|
||||
--- a/content/browser/web_contents/web_contents_impl.cc
|
||||
+++ b/content/browser/web_contents/web_contents_impl.cc
|
||||
@@ -3922,6 +3922,13 @@ void WebContentsImpl::Init(const WebContents::CreateParams& params,
|
||||
|
||||
@@ -37,7 +37,7 @@ index 2b99d0b584760ab3f51561c030ca199055bacd26..9d7b8758cb8f115e5c83f3913c7172f2
|
||||
if (had_fullscreen_token && !GetView()->HasFocus())
|
||||
GetView()->Focus();
|
||||
diff --git a/content/browser/web_contents/web_contents_impl.cc b/content/browser/web_contents/web_contents_impl.cc
|
||||
index ac8aa81e213689a612d322fa75e81798ae1010e6..26f41d34766899e81e32c319aad00172ffdc5fca 100644
|
||||
index 44989cbf81699e0d5f8b69bbb9e22b90930f6c6b..52539a51fb6c180020dea20a36482e6020be1b0f 100644
|
||||
--- a/content/browser/web_contents/web_contents_impl.cc
|
||||
+++ b/content/browser/web_contents/web_contents_impl.cc
|
||||
@@ -4197,21 +4197,25 @@ KeyboardEventProcessingResult WebContentsImpl::PreHandleKeyboardEvent(
|
||||
|
||||
@@ -1208,6 +1208,31 @@ content::WebContents* WebContents::CreateCustomWebContents(
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void WebContents::MaybeOverrideCreateParamsForNewWindow(
|
||||
content::WebContents::CreateParams* create_params) {
|
||||
v8::Isolate* isolate = JavascriptEnvironment::GetIsolate();
|
||||
v8::HandleScope handle_scope(isolate);
|
||||
gin_helper::Dictionary dict;
|
||||
gin::ConvertFromV8(isolate, pending_child_web_preferences_.Get(isolate),
|
||||
&dict);
|
||||
|
||||
v8::Local<v8::Value> use_offscreen;
|
||||
if (dict.Get(options::kOffscreen, &use_offscreen)) {
|
||||
bool is_offscreen =
|
||||
use_offscreen->IsObject() ||
|
||||
(use_offscreen->IsBoolean() &&
|
||||
dict.Get(options::kOffscreen, &is_offscreen) && is_offscreen);
|
||||
|
||||
if (is_offscreen) {
|
||||
auto* view = new OffScreenWebContentsView(
|
||||
false, offscreen_use_shared_texture_,
|
||||
base::BindRepeating(&WebContents::OnPaint, base::Unretained(this)));
|
||||
create_params->view = view;
|
||||
create_params->delegate_view = view;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
content::WebContents* WebContents::AddNewContents(
|
||||
content::WebContents* source,
|
||||
std::unique_ptr<content::WebContents> new_contents,
|
||||
@@ -1221,9 +1246,13 @@ content::WebContents* WebContents::AddNewContents(
|
||||
|
||||
v8::Isolate* isolate = JavascriptEnvironment::GetIsolate();
|
||||
|
||||
Type type = Type::kBrowserWindow;
|
||||
auto* web_preferences = WebContentsPreferences::From(new_contents.get());
|
||||
if (web_preferences && web_preferences->IsOffscreen())
|
||||
type = Type::kOffScreen;
|
||||
|
||||
v8::HandleScope handle_scope(isolate);
|
||||
auto api_web_contents =
|
||||
CreateAndTake(isolate, std::move(new_contents), Type::kBrowserWindow);
|
||||
auto api_web_contents = CreateAndTake(isolate, std::move(new_contents), type);
|
||||
|
||||
// We call RenderFrameCreated here as at this point the empty "about:blank"
|
||||
// render frame has already been created. If the window never navigates again
|
||||
|
||||
@@ -508,6 +508,8 @@ class WebContents final : public ExclusiveAccessContext,
|
||||
int opener_render_frame_id,
|
||||
const content::mojom::CreateNewWindowParams& params,
|
||||
content::WebContents* new_contents) override;
|
||||
void MaybeOverrideCreateParamsForNewWindow(
|
||||
content::WebContents::CreateParams* create_params) override;
|
||||
content::WebContents* AddNewContents(
|
||||
content::WebContents* source,
|
||||
std::unique_ptr<content::WebContents> new_contents,
|
||||
|
||||
@@ -4,6 +4,7 @@ import { expect, assert } from 'chai';
|
||||
|
||||
import { once } from 'node:events';
|
||||
import * as http from 'node:http';
|
||||
import * as nodePath from 'node:path';
|
||||
|
||||
import { HexColors, ScreenCapture, hasCapturableScreen } from './lib/screen-helpers';
|
||||
import { ifit, listen } from './lib/spec-helpers';
|
||||
@@ -203,6 +204,66 @@ describe('webContents.setWindowOpenHandler', () => {
|
||||
expect(await browserWindow.webContents.executeJavaScript('42')).to.equal(42);
|
||||
});
|
||||
|
||||
it('can open an offscreen child window from an onscreen parent', async () => {
|
||||
browserWindow.webContents.setWindowOpenHandler(() => ({
|
||||
action: 'allow',
|
||||
overrideBrowserWindowOptions: {
|
||||
webPreferences: {
|
||||
offscreen: true
|
||||
}
|
||||
}
|
||||
}));
|
||||
|
||||
const didCreateWindow = once(browserWindow.webContents, 'did-create-window');
|
||||
const url = `file://${nodePath.join('fixtures', 'pages', 'content.html')}`;
|
||||
browserWindow.webContents.executeJavaScript(`window.open('${JSON.stringify(url)}') && true`);
|
||||
const [childWindow] = await didCreateWindow;
|
||||
expect(childWindow.webContents.isOffscreen()).to.be.true('Child window should be offscreen');
|
||||
});
|
||||
|
||||
it('can open an onscreen child window from an offscreen parent', async () => {
|
||||
const obw = new BrowserWindow({
|
||||
show: false,
|
||||
webPreferences: {
|
||||
offscreen: true
|
||||
}
|
||||
});
|
||||
|
||||
await obw.loadURL('about:blank');
|
||||
obw.webContents.setWindowOpenHandler(() => ({ action: 'allow' }));
|
||||
|
||||
const didCreateWindow = once(obw.webContents, 'did-create-window');
|
||||
const url = `file://${nodePath.join('fixtures', 'pages', 'content.html')}`;
|
||||
obw.webContents.executeJavaScript(`window.open('${JSON.stringify(url)}') && true`);
|
||||
const [childWindow] = await didCreateWindow;
|
||||
expect(childWindow.webContents.isOffscreen()).to.be.false('Child window should not be offscreen');
|
||||
});
|
||||
|
||||
it('can open an offscreen child window from an offscreen parent', async () => {
|
||||
const obw = new BrowserWindow({
|
||||
show: false,
|
||||
webPreferences: {
|
||||
offscreen: true
|
||||
}
|
||||
});
|
||||
|
||||
await obw.loadURL('about:blank');
|
||||
obw.webContents.setWindowOpenHandler(() => ({
|
||||
action: 'allow',
|
||||
overrideBrowserWindowOptions: {
|
||||
webPreferences: {
|
||||
offscreen: true
|
||||
}
|
||||
}
|
||||
}));
|
||||
|
||||
const didCreateWindow = once(obw.webContents, 'did-create-window');
|
||||
const url = `file://${nodePath.join('fixtures', 'pages', 'content.html')}`;
|
||||
obw.webContents.executeJavaScript(`window.open('${JSON.stringify(url)}') && true`);
|
||||
const [childWindow] = await didCreateWindow;
|
||||
expect(childWindow.webContents.isOffscreen()).to.be.true('Child window should be offscreen');
|
||||
});
|
||||
|
||||
ifit(hasCapturableScreen())('should not make child window background transparent', async () => {
|
||||
browserWindow.webContents.setWindowOpenHandler(() => ({ action: 'allow' }));
|
||||
const didCreateWindow = once(browserWindow.webContents, 'did-create-window');
|
||||
|
||||
Reference in New Issue
Block a user