Commit b67633af authored by Daniel Nicoara's avatar Daniel Nicoara Committed by Commit Bot

cast: webview: Use WebContents window size as the EXO surface size

Simplify the resizing logic. We're only supposed to be resized by the
embedder, so only resize when we're told to.

This way we no longer need to worry about the case when a WebContents is
embedded inside another WebContents as there's no size updates on the main
one.

Bug: b/147376354 b/148398442
Test: Verified resizes are applied to the EXO surface.
Change-Id: I70d2578bfe91018680b052af3dccf698c5303c72
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2032201Reviewed-by: default avatarAlbert Chaulk <achaulk@chromium.org>
Commit-Queue: Daniel Nicoara <dnicoara@chromium.org>
Cr-Commit-Position: refs/heads/master@{#737920}
parent ecae09f4
...@@ -145,8 +145,8 @@ void WebContentController::ProcessRequest( ...@@ -145,8 +145,8 @@ void WebContentController::ProcessRequest(
case webview::WebviewRequest::kResize: case webview::WebviewRequest::kResize:
if (request.has_resize()) { if (request.has_resize()) {
GetWebContents()->GetNativeView()->SetBounds( HandleResize(
gfx::Rect(request.resize().width(), request.resize().height())); gfx::Size(request.resize().width(), request.resize().height()));
} else { } else {
client_->OnError("resize() not supplied"); client_->OnError("resize() not supplied");
} }
...@@ -177,13 +177,7 @@ void WebContentController::AttachTo(aura::Window* window, int window_id) { ...@@ -177,13 +177,7 @@ void WebContentController::AttachTo(aura::Window* window, int window_id) {
// Unretained is safe because we unset this in the destructor. // Unretained is safe because we unset this in the destructor.
surface_->SetEmbeddedSurfaceId(base::BindRepeating( surface_->SetEmbeddedSurfaceId(base::BindRepeating(
&WebContentController::GetSurfaceId, base::Unretained(this))); &WebContentController::GetSurfaceId, base::Unretained(this)));
HandleResize(contents_window->bounds().size());
content::RenderFrameHost* rfh = GetWebContents()->GetMainFrame();
if (rfh) {
const base::Optional<gfx::Size>& size = rfh->GetFrameSize();
if (size.has_value())
surface_->SetEmbeddedSurfaceSize(*size);
}
} }
void WebContentController::ProcessInputEvent(const webview::InputEvent& ev) { void WebContentController::ProcessInputEvent(const webview::InputEvent& ev) {
...@@ -422,6 +416,15 @@ void WebContentController::HandleSetAutoMediaPlaybackPolicy( ...@@ -422,6 +416,15 @@ void WebContentController::HandleSetAutoMediaPlaybackPolicy(
contents->GetRenderViewHost()->UpdateWebkitPreferences(prefs); contents->GetRenderViewHost()->UpdateWebkitPreferences(prefs);
} }
void WebContentController::HandleResize(const gfx::Size& size) {
LOG(INFO) << "Sizing web content to " << size.ToString();
GetWebContents()->GetNativeView()->SetBounds(gfx::Rect(size));
if (surface_) {
surface_->SetEmbeddedSurfaceSize(size);
surface_->Commit();
}
}
viz::SurfaceId WebContentController::GetSurfaceId() { viz::SurfaceId WebContentController::GetSurfaceId() {
content::WebContents* web_contents = GetWebContents(); content::WebContents* web_contents = GetWebContents();
// Web contents are destroyed before controller for cast apps. // Web contents are destroyed before controller for cast apps.
...@@ -445,9 +448,9 @@ void WebContentController::OnSurfaceDestroying(exo::Surface* surface) { ...@@ -445,9 +448,9 @@ void WebContentController::OnSurfaceDestroying(exo::Surface* surface) {
void WebContentController::FrameSizeChanged( void WebContentController::FrameSizeChanged(
content::RenderFrameHost* render_frame_host, content::RenderFrameHost* render_frame_host,
const gfx::Size& frame_size) { const gfx::Size& frame_size) {
content::RenderFrameHost* rfh = GetWebContents()->GetMainFrame(); // The surface ID may have changed, so trigger a new commit to re-issue the
if (render_frame_host == rfh && surface_) { // draw quad.
surface_->SetEmbeddedSurfaceSize(frame_size); if (surface_) {
surface_->Commit(); surface_->Commit();
} }
} }
...@@ -474,13 +477,7 @@ void WebContentController::RenderFrameHostChanged( ...@@ -474,13 +477,7 @@ void WebContentController::RenderFrameHostChanged(
content::RenderFrameHost* new_host) { content::RenderFrameHost* new_host) {
// The surface ID may have changed, so trigger a new commit to re-issue the // The surface ID may have changed, so trigger a new commit to re-issue the
// draw quad. // draw quad.
content::RenderFrameHost* rfh = GetWebContents()->GetMainFrame(); if (surface_) {
if (new_host == rfh && surface_) {
if (new_host) {
auto size = new_host->GetFrameSize();
if (size.has_value())
surface_->SetEmbeddedSurfaceSize(*size);
}
surface_->Commit(); surface_->Commit();
} }
} }
......
...@@ -93,6 +93,7 @@ class WebContentController ...@@ -93,6 +93,7 @@ class WebContentController
void HandleUpdateSettings(const webview::UpdateSettingsRequest& request); void HandleUpdateSettings(const webview::UpdateSettingsRequest& request);
void HandleSetAutoMediaPlaybackPolicy( void HandleSetAutoMediaPlaybackPolicy(
const webview::SetAutoMediaPlaybackPolicyRequest& request); const webview::SetAutoMediaPlaybackPolicyRequest& request);
void HandleResize(const gfx::Size& size);
viz::SurfaceId GetSurfaceId(); viz::SurfaceId GetSurfaceId();
void ChannelModified(content::RenderFrameHost* frame, void ChannelModified(content::RenderFrameHost* frame,
const std::string& channel, const std::string& channel,
......
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