Commit aec643b6 authored by Francois Doray's avatar Francois Doray Committed by Commit Bot

aura: Make WebContents VISIBLE when shown in Alt-Tab view on ChromeOS.

Today, WebContents::GetVisibility() returns HIDDEN for a tab that is in
a minimized window shown in the Alt-Tab view on ChromeOS. This is
because content::WebContents::GetVisibility() indicates the visibility
of the aura::Window, and isn't affected by the mirroring functionnality
used by the Alt-Tab view.

Unfortunately, the fact that WebContents::GetVisibility() returns
HIDDEN makes TabManager think that the tab is eligible for freezing and
discarding (freezing or discarding a tab in Alt-Tab breaks the live
view functionnality). TabManager could check by itself whether the
WebContents IsBeingCaptured(), but instead of requiring that every
call to WebContents::GetVisibility() be accompanied to a check to
IsBeingCaptured(), we believe it's better to return VISIBLE from
GetVisibility() when a tab is displayed in Alt-Tab view.

Bug: 876103
Change-Id: I01c07858bcae3038577bac1408c67eb72fe08e0c
Reviewed-on: https://chromium-review.googlesource.com/1191862Reviewed-by: default avatarSadrul Chowdhury <sadrul@chromium.org>
Commit-Queue: François Doray <fdoray@chromium.org>
Cr-Commit-Position: refs/heads/master@{#587711}
parent d99f8467
...@@ -422,12 +422,8 @@ class WebContentsViewAura::WindowObserver ...@@ -422,12 +422,8 @@ class WebContentsViewAura::WindowObserver
void OnWindowPropertyChanged(aura::Window* window, void OnWindowPropertyChanged(aura::Window* window,
const void* key, const void* key,
intptr_t old) override { intptr_t old) override {
if (key != aura::client::kMirroringEnabledKey) if (key == aura::client::kMirroringEnabledKey)
return; view_->UpdateWebContentsVisibility();
if (window->GetProperty(aura::client::kMirroringEnabledKey))
view_->web_contents_->IncrementCapturerCount(gfx::Size());
else
view_->web_contents_->DecrementCapturerCount();
} }
// Overridden WindowTreeHostObserver: // Overridden WindowTreeHostObserver:
...@@ -761,6 +757,25 @@ void WebContentsViewAura::CreateAuraWindow(aura::Window* context) { ...@@ -761,6 +757,25 @@ void WebContentsViewAura::CreateAuraWindow(aura::Window* context) {
window_observer_.reset(new WindowObserver(this)); window_observer_.reset(new WindowObserver(this));
} }
void WebContentsViewAura::UpdateWebContentsVisibility() {
web_contents_->UpdateWebContentsVisibility(GetVisibility());
}
Visibility WebContentsViewAura::GetVisibility() const {
// aura::client::kMirroringEnabledKey indicates that the window is displayed
// in Alt-Tab view on ChromeOS.
if (window_->occlusion_state() == aura::Window::OcclusionState::VISIBLE ||
window_->GetProperty(aura::client::kMirroringEnabledKey)) {
return Visibility::VISIBLE;
}
if (window_->occlusion_state() == aura::Window::OcclusionState::OCCLUDED)
return Visibility::OCCLUDED;
DCHECK_EQ(window_->occlusion_state(), aura::Window::OcclusionState::HIDDEN);
return Visibility::HIDDEN;
}
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// WebContentsViewAura, WebContentsView implementation: // WebContentsViewAura, WebContentsView implementation:
...@@ -1100,12 +1115,7 @@ void WebContentsViewAura::OnWindowTargetVisibilityChanged(bool visible) { ...@@ -1100,12 +1115,7 @@ void WebContentsViewAura::OnWindowTargetVisibilityChanged(bool visible) {
void WebContentsViewAura::OnWindowOcclusionChanged( void WebContentsViewAura::OnWindowOcclusionChanged(
aura::Window::OcclusionState occlusion_state) { aura::Window::OcclusionState occlusion_state) {
web_contents_->UpdateWebContentsVisibility( UpdateWebContentsVisibility();
occlusion_state == aura::Window::OcclusionState::VISIBLE
? content::Visibility::VISIBLE
: (occlusion_state == aura::Window::OcclusionState::OCCLUDED
? content::Visibility::OCCLUDED
: content::Visibility::HIDDEN));
} }
bool WebContentsViewAura::HasHitTestMask() const { bool WebContentsViewAura::HasHitTestMask() const {
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
#include "content/common/buildflags.h" #include "content/common/buildflags.h"
#include "content/common/content_export.h" #include "content/common/content_export.h"
#include "content/public/browser/global_routing_id.h" #include "content/public/browser/global_routing_id.h"
#include "content/public/browser/visibility.h"
#include "ui/aura/client/drag_drop_delegate.h" #include "ui/aura/client/drag_drop_delegate.h"
#include "ui/aura/window.h" #include "ui/aura/window.h"
#include "ui/aura/window_delegate.h" #include "ui/aura/window_delegate.h"
...@@ -97,6 +98,12 @@ class CONTENT_EXPORT WebContentsViewAura ...@@ -97,6 +98,12 @@ class CONTENT_EXPORT WebContentsViewAura
// Called from CreateView() to create |window_|. // Called from CreateView() to create |window_|.
void CreateAuraWindow(aura::Window* context); void CreateAuraWindow(aura::Window* context);
// Computes the view's visibility updates the WebContents accordingly.
void UpdateWebContentsVisibility();
// Computes the view's visibility.
Visibility GetVisibility() const;
// Overridden from WebContentsView: // Overridden from WebContentsView:
gfx::NativeView GetNativeView() const override; gfx::NativeView GetNativeView() const override;
gfx::NativeView GetContentNativeView() const override; gfx::NativeView GetContentNativeView() const override;
......
...@@ -7,12 +7,14 @@ ...@@ -7,12 +7,14 @@
#include <memory> #include <memory>
#include "base/command_line.h" #include "base/command_line.h"
#include "base/macros.h"
#include "base/test/scoped_command_line.h" #include "base/test/scoped_command_line.h"
#include "base/test/scoped_feature_list.h" #include "base/test/scoped_feature_list.h"
#include "content/browser/web_contents/web_contents_impl.h" #include "content/browser/web_contents/web_contents_impl.h"
#include "content/public/common/content_features.h" #include "content/public/common/content_features.h"
#include "content/public/test/test_renderer_host.h" #include "content/public/test/test_renderer_host.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
#include "ui/aura/client/aura_constants.h"
#include "ui/aura/test/test_windows.h" #include "ui/aura/test/test_windows.h"
#include "ui/aura/window.h" #include "ui/aura/window.h"
#include "ui/display/display_switches.h" #include "ui/display/display_switches.h"
...@@ -25,22 +27,38 @@ constexpr gfx::Rect kBounds = gfx::Rect(0, 0, 20, 20); ...@@ -25,22 +27,38 @@ constexpr gfx::Rect kBounds = gfx::Rect(0, 0, 20, 20);
} // namespace } // namespace
class WebContentsViewAuraTest : public RenderViewHostTestHarness { class WebContentsViewAuraTest : public RenderViewHostTestHarness {
public: protected:
WebContentsViewAuraTest() = default; WebContentsViewAuraTest() = default;
~WebContentsViewAuraTest() override = default; ~WebContentsViewAuraTest() override = default;
void SetUp() override { void SetUp() override {
RenderViewHostTestHarness::SetUp(); RenderViewHostTestHarness::SetUp();
root_window()->SetBounds(kBounds); root_window()->SetBounds(kBounds);
web_contents()->GetNativeView()->SetBounds(kBounds); GetNativeView()->SetBounds(kBounds);
web_contents()->GetNativeView()->Show(); GetNativeView()->Show();
root_window()->AddChild(web_contents()->GetNativeView()); root_window()->AddChild(GetNativeView());
other_window_.reset(aura::test::CreateTestWindowWithDelegateAndType(
nullptr, aura::client::WINDOW_TYPE_NORMAL, 0, kBounds, root_window(),
false));
}
void TearDown() override {
other_window_.reset();
RenderViewHostTestHarness::TearDown();
} }
WebContentsViewAura* view() { WebContentsViewAura* view() {
WebContentsImpl* contents = static_cast<WebContentsImpl*>(web_contents()); WebContentsImpl* contents = static_cast<WebContentsImpl*>(web_contents());
return static_cast<WebContentsViewAura*>(contents->GetView()); return static_cast<WebContentsViewAura*>(contents->GetView());
} }
aura::Window* GetNativeView() { return web_contents()->GetNativeView(); }
// |other_window| occludes |web_contents()| when it's shown.
std::unique_ptr<aura::Window> other_window_;
private:
DISALLOW_COPY_AND_ASSIGN(WebContentsViewAuraTest);
}; };
TEST_F(WebContentsViewAuraTest, EnableDisableOverscroll) { TEST_F(WebContentsViewAuraTest, EnableDisableOverscroll) {
...@@ -63,17 +81,40 @@ TEST_F(WebContentsViewAuraTest, OccludeView) { ...@@ -63,17 +81,40 @@ TEST_F(WebContentsViewAuraTest, OccludeView) {
base::test::ScopedFeatureList scoped_feature_list; base::test::ScopedFeatureList scoped_feature_list;
scoped_feature_list.InitAndEnableFeature(features::kWebContentsOcclusion); scoped_feature_list.InitAndEnableFeature(features::kWebContentsOcclusion);
// |other_window| occludes |web_contents()| when it's shown.
std::unique_ptr<aura::Window> other_window(
aura::test::CreateTestWindowWithDelegateAndType(
nullptr, aura::client::WINDOW_TYPE_NORMAL, 0, kBounds, root_window(),
false));
EXPECT_EQ(web_contents()->GetVisibility(), Visibility::VISIBLE); EXPECT_EQ(web_contents()->GetVisibility(), Visibility::VISIBLE);
other_window->Show(); other_window_->Show();
EXPECT_EQ(web_contents()->GetVisibility(), Visibility::OCCLUDED); EXPECT_EQ(web_contents()->GetVisibility(), Visibility::OCCLUDED);
other_window->Hide(); other_window_->Hide();
EXPECT_EQ(web_contents()->GetVisibility(), Visibility::VISIBLE); EXPECT_EQ(web_contents()->GetVisibility(), Visibility::VISIBLE);
} }
TEST_F(WebContentsViewAuraTest, MirroringEnabledForHiddenView) {
EXPECT_EQ(web_contents()->GetVisibility(), content::Visibility::VISIBLE);
root_window()->Hide();
EXPECT_EQ(web_contents()->GetVisibility(), content::Visibility::HIDDEN);
GetNativeView()->SetProperty(aura::client::kMirroringEnabledKey, true);
EXPECT_EQ(web_contents()->GetVisibility(), content::Visibility::VISIBLE);
GetNativeView()->SetProperty(aura::client::kMirroringEnabledKey, false);
EXPECT_EQ(web_contents()->GetVisibility(), content::Visibility::HIDDEN);
root_window()->Show();
EXPECT_EQ(web_contents()->GetVisibility(), content::Visibility::VISIBLE);
GetNativeView()->SetProperty(aura::client::kMirroringEnabledKey, true);
EXPECT_EQ(web_contents()->GetVisibility(), content::Visibility::VISIBLE);
GetNativeView()->SetProperty(aura::client::kMirroringEnabledKey, false);
EXPECT_EQ(web_contents()->GetVisibility(), content::Visibility::VISIBLE);
}
TEST_F(WebContentsViewAuraTest, MirroringEnabledForOccludedView) {
base::test::ScopedFeatureList scoped_feature_list;
scoped_feature_list.InitAndEnableFeature(features::kWebContentsOcclusion);
EXPECT_EQ(web_contents()->GetVisibility(), content::Visibility::VISIBLE);
other_window_->Show();
EXPECT_EQ(web_contents()->GetVisibility(), content::Visibility::OCCLUDED);
GetNativeView()->SetProperty(aura::client::kMirroringEnabledKey, true);
EXPECT_EQ(web_contents()->GetVisibility(), content::Visibility::VISIBLE);
GetNativeView()->SetProperty(aura::client::kMirroringEnabledKey, false);
EXPECT_EQ(web_contents()->GetVisibility(), content::Visibility::OCCLUDED);
}
} // namespace content } // namespace content
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