Commit 882e0c26 authored by Yury Semikhatsky's avatar Yury Semikhatsky Committed by Commit Bot

DevTools: Browser.setWindowBounds should update window.outerWidth/Height

After calling Browser.setWindowBounds values of the window.outerWidth/outerHeight
are now updated to reflect new bounds. In headless browser WebContentsViewMac is
created with null WebContentsViewDelegate hence there is no top level native
window. In this change we pretend that there is such window and propagate its
using newly introduced SetWindowFrameInScreen method.

Bug: none
Change-Id: I3bb4338ed28c2d477736bc1cc5976b873a3061d9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2321409
Commit-Queue: Yury Semikhatsky <yurys@chromium.org>
Auto-Submit: Yury Semikhatsky <yurys@chromium.org>
Reviewed-by: default avatarccameron <ccameron@chromium.org>
Reviewed-by: default avatarAndrey Kosyakov <caseq@chromium.org>
Reviewed-by: default avatarDmitry Gozman <dgozman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#792540}
parent 5e4f3f95
...@@ -744,6 +744,9 @@ void RenderWidgetHostViewChildFrame::ShowDefinitionForSelection() { ...@@ -744,6 +744,9 @@ void RenderWidgetHostViewChildFrame::ShowDefinitionForSelection() {
} }
void RenderWidgetHostViewChildFrame::SpeakSelection() {} void RenderWidgetHostViewChildFrame::SpeakSelection() {}
void RenderWidgetHostViewChildFrame::SetWindowFrameInScreen(
const gfx::Rect& rect) {}
#endif // defined(OS_MACOSX) #endif // defined(OS_MACOSX)
void RenderWidgetHostViewChildFrame::CopyFromSurface( void RenderWidgetHostViewChildFrame::CopyFromSurface(
......
...@@ -149,6 +149,7 @@ class CONTENT_EXPORT RenderWidgetHostViewChildFrame ...@@ -149,6 +149,7 @@ class CONTENT_EXPORT RenderWidgetHostViewChildFrame
void SetActive(bool active) override; void SetActive(bool active) override;
void ShowDefinitionForSelection() override; void ShowDefinitionForSelection() override;
void SpeakSelection() override; void SpeakSelection() override;
void SetWindowFrameInScreen(const gfx::Rect& rect) override;
#endif // defined(OS_MACOSX) #endif // defined(OS_MACOSX)
blink::mojom::InputEventResultState FilterInputEvent( blink::mojom::InputEventResultState FilterInputEvent(
......
...@@ -115,6 +115,7 @@ class CONTENT_EXPORT RenderWidgetHostViewMac ...@@ -115,6 +115,7 @@ class CONTENT_EXPORT RenderWidgetHostViewMac
void SetActive(bool active) override; void SetActive(bool active) override;
void ShowDefinitionForSelection() override; void ShowDefinitionForSelection() override;
void SpeakSelection() override; void SpeakSelection() override;
void SetWindowFrameInScreen(const gfx::Rect& rect) override;
void GetScreenInfo(blink::ScreenInfo* screen_info) override; void GetScreenInfo(blink::ScreenInfo* screen_info) override;
void TakeFallbackContentFrom(RenderWidgetHostView* view) override; void TakeFallbackContentFrom(RenderWidgetHostView* view) override;
......
...@@ -816,6 +816,12 @@ void RenderWidgetHostViewMac::SpeakSelection() { ...@@ -816,6 +816,12 @@ void RenderWidgetHostViewMac::SpeakSelection() {
GetPageTextForSpeech(base::BindOnce(ui::TextServicesContextMenu::SpeakText)); GetPageTextForSpeech(base::BindOnce(ui::TextServicesContextMenu::SpeakText));
} }
void RenderWidgetHostViewMac::SetWindowFrameInScreen(const gfx::Rect& rect) {
DCHECK(GetInProcessNSView() && ![GetInProcessNSView() window])
<< "This method should only be called in headless browser!";
OnWindowFrameInScreenChanged(rect);
}
// //
// RenderWidgetHostViewCocoa uses the stored selection text, // RenderWidgetHostViewCocoa uses the stored selection text,
// which implements NSServicesRequests protocol. // which implements NSServicesRequests protocol.
......
...@@ -252,6 +252,10 @@ class CONTENT_EXPORT RenderWidgetHostView { ...@@ -252,6 +252,10 @@ class CONTENT_EXPORT RenderWidgetHostView {
// Tells the view to speak the currently selected text. // Tells the view to speak the currently selected text.
virtual void SpeakSelection() = 0; virtual void SpeakSelection() = 0;
// Allows to update the widget's screen rects when it is not attached to
// a window (e.g. in headless mode).
virtual void SetWindowFrameInScreen(const gfx::Rect& rect) = 0;
#endif // defined(OS_MACOSX) #endif // defined(OS_MACOSX)
// Indicates that this view should show the contents of |view| if it doesn't // Indicates that this view should show the contents of |view| if it doesn't
......
...@@ -144,10 +144,9 @@ void WebTestShellPlatformDelegate::ResizeWebContent( ...@@ -144,10 +144,9 @@ void WebTestShellPlatformDelegate::ResizeWebContent(
// the widget's screen rects, since the RenerWidgetHostView is not attached to // the widget's screen rects, since the RenerWidgetHostView is not attached to
// a window in headless mode. So this call causes them to be updated so they // a window in headless mode. So this call causes them to be updated so they
// are not left as 0x0. // are not left as 0x0.
auto* rwhv_mac = static_cast<RenderWidgetHostViewMac*>( auto* rwhv_mac = shell->web_contents()->GetMainFrame()->GetView();
shell->web_contents()->GetMainFrame()->GetView());
if (rwhv_mac) if (rwhv_mac)
rwhv_mac->OnWindowFrameInScreenChanged(gfx::Rect(content_size)); rwhv_mac->SetWindowFrameInScreen(gfx::Rect(content_size));
} }
void WebTestShellPlatformDelegate::ActivateContents(Shell* shell, void WebTestShellPlatformDelegate::ActivateContents(Shell* shell,
......
...@@ -161,6 +161,8 @@ void TestRenderWidgetHostView::SetActive(bool active) { ...@@ -161,6 +161,8 @@ void TestRenderWidgetHostView::SetActive(bool active) {
void TestRenderWidgetHostView::SpeakSelection() { void TestRenderWidgetHostView::SpeakSelection() {
} }
void TestRenderWidgetHostView::SetWindowFrameInScreen(const gfx::Rect& rect) {}
#endif #endif
gfx::Rect TestRenderWidgetHostView::GetBoundsInRootWindow() { gfx::Rect TestRenderWidgetHostView::GetBoundsInRootWindow() {
......
...@@ -84,6 +84,7 @@ class TestRenderWidgetHostView : public RenderWidgetHostViewBase, ...@@ -84,6 +84,7 @@ class TestRenderWidgetHostView : public RenderWidgetHostViewBase,
void SetActive(bool active) override; void SetActive(bool active) override;
void ShowDefinitionForSelection() override {} void ShowDefinitionForSelection() override {}
void SpeakSelection() override; void SpeakSelection() override;
void SetWindowFrameInScreen(const gfx::Rect& rect) override;
#endif // defined(OS_MACOSX) #endif // defined(OS_MACOSX)
// Advances the fallback surface to the first surface after navigation. This // Advances the fallback surface to the first surface after navigation. This
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#import "base/mac/scoped_objc_class_swizzler.h" #import "base/mac/scoped_objc_class_swizzler.h"
#include "base/no_destructor.h" #include "base/no_destructor.h"
#include "content/public/browser/render_widget_host_view.h"
#include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents.h"
#include "headless/lib/browser/headless_web_contents_impl.h" #include "headless/lib/browser/headless_web_contents_impl.h"
#import "ui/base/cocoa/base_view.h" #import "ui/base/cocoa/base_view.h"
...@@ -90,6 +91,11 @@ void HeadlessBrowserImpl::PlatformSetWebContentsBounds( ...@@ -90,6 +91,11 @@ void HeadlessBrowserImpl::PlatformSetWebContentsBounds(
web_contents->web_contents()->GetNativeView().GetNativeNSView(); web_contents->web_contents()->GetNativeView().GetNativeNSView();
NSRect frame = gfx::ScreenRectToNSRect(bounds); NSRect frame = gfx::ScreenRectToNSRect(bounds);
[web_view setFrame:frame]; [web_view setFrame:frame];
content::RenderWidgetHostView* host_view =
web_contents->web_contents()->GetRenderWidgetHostView();
if (host_view)
host_view->SetWindowFrameInScreen(bounds);
} }
ui::Compositor* HeadlessBrowserImpl::PlatformGetCompositor( ui::Compositor* HeadlessBrowserImpl::PlatformGetCompositor(
......
...@@ -187,6 +187,42 @@ DISABLED_HEADLESS_ASYNC_DEVTOOLED_TEST_F( ...@@ -187,6 +187,42 @@ DISABLED_HEADLESS_ASYNC_DEVTOOLED_TEST_F(
HEADLESS_ASYNC_DEVTOOLED_TEST_F(HeadlessDevToolsClientChangeWindowBoundsTest); HEADLESS_ASYNC_DEVTOOLED_TEST_F(HeadlessDevToolsClientChangeWindowBoundsTest);
#endif #endif
class HeadlessDevToolsClientOuterSizeTest
: public HeadlessDevToolsClientWindowManagementTest {
void RunDevTooledTest() override {
SetWindowBounds(
gfx::Rect(100, 200, 800, 600),
base::BindOnce(&HeadlessDevToolsClientOuterSizeTest::OnSetWindowBounds,
base::Unretained(this)));
}
void OnSetWindowBounds(
std::unique_ptr<browser::SetWindowBoundsResult> result) {
devtools_client_->GetRuntime()->Evaluate(
"window.outerWidth",
base::BindOnce(&HeadlessDevToolsClientOuterSizeTest::OnOuterWidthResult,
base::Unretained(this)));
devtools_client_->GetRuntime()->Evaluate(
"window.outerHeight",
base::BindOnce(
&HeadlessDevToolsClientOuterSizeTest::OnOuterHeightResult,
base::Unretained(this)));
}
void OnOuterWidthResult(std::unique_ptr<runtime::EvaluateResult> result) {
EXPECT_TRUE(result->GetResult()->HasValue());
EXPECT_EQ(800, result->GetResult()->GetValue()->GetInt());
}
void OnOuterHeightResult(std::unique_ptr<runtime::EvaluateResult> result) {
EXPECT_TRUE(result->GetResult()->HasValue());
EXPECT_EQ(600, result->GetResult()->GetValue()->GetInt());
FinishAsynchronousTest();
}
};
HEADLESS_ASYNC_DEVTOOLED_TEST_F(HeadlessDevToolsClientOuterSizeTest);
class HeadlessDevToolsClientChangeWindowStateTest class HeadlessDevToolsClientChangeWindowStateTest
: public HeadlessDevToolsClientWindowManagementTest { : public HeadlessDevToolsClientWindowManagementTest {
public: public:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment