Commit 5636d2b2 authored by James West's avatar James West Committed by Commit Bot

[Chromecast] Resize window to 1x1 pixel when hidden

Bug: internal b/118727323
Test: manual
Change-Id: I9623edf4e221d477d9e44b63357f86092b24f332
Reviewed-on: https://chromium-review.googlesource.com/c/1338112Reviewed-by: default avatarLuke Halliwell <halliwell@chromium.org>
Commit-Queue: James West <jameswest@chromium.org>
Cr-Commit-Position: refs/heads/master@{#609000}
parent 8f22187e
......@@ -6,10 +6,14 @@
#include <memory>
#include "base/logging.h"
#include "base/memory/ptr_util.h"
#include "chromecast/chromecast_buildflags.h"
#include "chromecast/graphics/cast_window_manager.h"
#include "content/public/browser/web_contents.h"
#include "ui/aura/window.h"
#include "ui/display/display.h"
#include "ui/display/screen.h"
namespace chromecast {
namespace shell {
......@@ -120,6 +124,11 @@ void CastContentWindowAura::CreateWindowForWebContents(
void CastContentWindowAura::GrantScreenAccess() {
has_screen_access_ = true;
if (window_) {
#if !BUILDFLAG(IS_CAST_AUDIO_ONLY)
gfx::Size display_size =
display::Screen::GetScreen()->GetPrimaryDisplay().size();
window_->SetBounds(gfx::Rect(display_size.width(), display_size.height()));
#endif
window_->Show();
}
}
......@@ -128,6 +137,10 @@ void CastContentWindowAura::RevokeScreenAccess() {
has_screen_access_ = false;
if (window_) {
window_->Hide();
// Because rendering a larger window may require more system resources,
// resize the window to one pixel while hidden.
LOG(INFO) << "Resizing window to 1x1 pixel while hidden";
window_->SetBounds(gfx::Rect(1, 1));
}
}
......
......@@ -68,7 +68,7 @@ CastWebViewDefault::CastWebViewDefault(
web_contents_.get(),
params.enabled_for_dev),
window_(shell::CastContentWindow::Create(params.window_params)),
did_start_navigation_(false) {
resize_window_when_navigation_starts_(true) {
DCHECK(delegate_);
DCHECK(web_contents_manager_);
DCHECK(browser_context_);
......@@ -154,6 +154,7 @@ void CastWebViewDefault::GrantScreenAccess() {
}
void CastWebViewDefault::RevokeScreenAccess() {
resize_window_when_navigation_starts_ = false;
window_->RevokeScreenAccess();
}
......@@ -290,10 +291,10 @@ void CastWebViewDefault::DidFirstVisuallyNonEmptyPaint() {
void CastWebViewDefault::DidStartNavigation(
content::NavigationHandle* navigation_handle) {
if (did_start_navigation_) {
if (!resize_window_when_navigation_starts_) {
return;
}
did_start_navigation_ = true;
resize_window_when_navigation_starts_ = false;
#if defined(USE_AURA)
// Resize window
......
......@@ -99,7 +99,7 @@ class CastWebViewDefault : public CastWebView,
std::unique_ptr<content::WebContents> web_contents_;
CastWebContentsImpl cast_web_contents_;
std::unique_ptr<shell::CastContentWindow> window_;
bool did_start_navigation_;
bool resize_window_when_navigation_starts_;
base::TimeDelta shutdown_delay_;
DISALLOW_COPY_AND_ASSIGN(CastWebViewDefault);
......
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