Commit 16620a9e authored by skuhne@chromium.org's avatar skuhne@chromium.org

Releasing CPU resources of hidden/minimized browser windows

BUG=310365
TEST=browser_test & tested visually (taskamanger, running YouTube, deleting active&inactive hidden tabs, ..)

Review URL: https://codereview.chromium.org/286943005

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@272662 0039d316-1c4b-4281-b951-d872f2087c98
parent 6efb8d9c
...@@ -164,6 +164,8 @@ class CONTENT_EXPORT WebContentsImpl ...@@ -164,6 +164,8 @@ class CONTENT_EXPORT WebContentsImpl
return geolocation_dispatcher_host_.get(); return geolocation_dispatcher_host_.get();
} }
bool should_normally_be_visible() { return should_normally_be_visible_; }
// WebContents ------------------------------------------------------ // WebContents ------------------------------------------------------
virtual WebContentsDelegate* GetDelegate() OVERRIDE; virtual WebContentsDelegate* GetDelegate() OVERRIDE;
virtual void SetDelegate(WebContentsDelegate* delegate) OVERRIDE; virtual void SetDelegate(WebContentsDelegate* delegate) OVERRIDE;
......
...@@ -98,6 +98,17 @@ bool ShouldNavigateBack(const NavigationController& controller, ...@@ -98,6 +98,17 @@ bool ShouldNavigateBack(const NavigationController& controller,
controller.CanGoBack(); controller.CanGoBack();
} }
// Update the |web contents| to be |visible|.
void UpdateWebContentsVisibility(WebContentsImpl* web_contents, bool visible) {
if (visible) {
if (!web_contents->should_normally_be_visible())
web_contents->WasShown();
} else {
if (web_contents->should_normally_be_visible())
web_contents->WasHidden();
}
}
RenderWidgetHostViewAura* ToRenderWidgetHostViewAura( RenderWidgetHostViewAura* ToRenderWidgetHostViewAura(
RenderWidgetHostView* view) { RenderWidgetHostView* view) {
if (!view || RenderViewHostFactory::has_factory()) if (!view || RenderViewHostFactory::has_factory())
...@@ -717,6 +728,7 @@ WebContentsViewAura::~WebContentsViewAura() { ...@@ -717,6 +728,7 @@ WebContentsViewAura::~WebContentsViewAura() {
return; return;
window_observer_.reset(); window_observer_.reset();
window_->RemoveObserver(this);
// Window needs a valid delegate during its destructor, so we explicitly // Window needs a valid delegate during its destructor, so we explicitly
// delete it here. // delete it here.
...@@ -1044,6 +1056,7 @@ void WebContentsViewAura::CreateView( ...@@ -1044,6 +1056,7 @@ void WebContentsViewAura::CreateView(
window_->SetType(ui::wm::WINDOW_TYPE_CONTROL); window_->SetType(ui::wm::WINDOW_TYPE_CONTROL);
window_->SetTransparent(false); window_->SetTransparent(false);
window_->Init(aura::WINDOW_LAYER_NOT_DRAWN); window_->Init(aura::WINDOW_LAYER_NOT_DRAWN);
window_->AddObserver(this);
aura::Window* root_window = context ? context->GetRootWindow() : NULL; aura::Window* root_window = context ? context->GetRootWindow() : NULL;
if (root_window) { if (root_window) {
// There are places where there is no context currently because object // There are places where there is no context currently because object
...@@ -1426,10 +1439,6 @@ void WebContentsViewAura::OnWindowDestroyed(aura::Window* window) { ...@@ -1426,10 +1439,6 @@ void WebContentsViewAura::OnWindowDestroyed(aura::Window* window) {
} }
void WebContentsViewAura::OnWindowTargetVisibilityChanged(bool visible) { void WebContentsViewAura::OnWindowTargetVisibilityChanged(bool visible) {
if (visible)
web_contents_->WasShown();
else
web_contents_->WasHidden();
} }
bool WebContentsViewAura::HasHitTestMask() const { bool WebContentsViewAura::HasHitTestMask() const {
...@@ -1552,4 +1561,22 @@ int WebContentsViewAura::OnPerformDrop(const ui::DropTargetEvent& event) { ...@@ -1552,4 +1561,22 @@ int WebContentsViewAura::OnPerformDrop(const ui::DropTargetEvent& event) {
return ConvertFromWeb(current_drag_op_); return ConvertFromWeb(current_drag_op_);
} }
void WebContentsViewAura::OnWindowParentChanged(aura::Window* window,
aura::Window* parent) {
// On Windows we will get called with a parent of NULL as part of the shut
// down process. As such we do only change the visibility when a parent gets
// set.
if (parent)
UpdateWebContentsVisibility(web_contents_, window->IsVisible());
}
void WebContentsViewAura::OnWindowVisibilityChanged(aura::Window* window,
bool visible) {
// Ignore any visibility changes in the hierarchy below.
if (window != window_.get() && window_->Contains(window))
return;
UpdateWebContentsVisibility(web_contents_, visible);
}
} // namespace content } // namespace content
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include "content/browser/web_contents/web_contents_view.h" #include "content/browser/web_contents/web_contents_view.h"
#include "content/common/content_export.h" #include "content/common/content_export.h"
#include "ui/aura/window_delegate.h" #include "ui/aura/window_delegate.h"
#include "ui/aura/window_observer.h"
#include "ui/compositor/layer_animation_observer.h" #include "ui/compositor/layer_animation_observer.h"
#include "ui/wm/public/drag_drop_delegate.h" #include "ui/wm/public/drag_drop_delegate.h"
...@@ -41,7 +42,8 @@ class WebContentsViewAura ...@@ -41,7 +42,8 @@ class WebContentsViewAura
public OverscrollControllerDelegate, public OverscrollControllerDelegate,
public ui::ImplicitAnimationObserver, public ui::ImplicitAnimationObserver,
public aura::WindowDelegate, public aura::WindowDelegate,
public aura::client::DragDropDelegate { public aura::client::DragDropDelegate,
public aura::WindowObserver {
public: public:
WebContentsViewAura(WebContentsImpl* web_contents, WebContentsViewAura(WebContentsImpl* web_contents,
WebContentsViewDelegate* delegate); WebContentsViewDelegate* delegate);
...@@ -176,6 +178,12 @@ class WebContentsViewAura ...@@ -176,6 +178,12 @@ class WebContentsViewAura
virtual void OnDragExited() OVERRIDE; virtual void OnDragExited() OVERRIDE;
virtual int OnPerformDrop(const ui::DropTargetEvent& event) OVERRIDE; virtual int OnPerformDrop(const ui::DropTargetEvent& event) OVERRIDE;
// Overridden from aura::WindowObserver:
virtual void OnWindowParentChanged(aura::Window* window,
aura::Window* parent) OVERRIDE;
virtual void OnWindowVisibilityChanged(aura::Window* window,
bool visible) OVERRIDE;
scoped_ptr<aura::Window> window_; scoped_ptr<aura::Window> window_;
// The window that shows the screenshot of the history page during an // The window that shows the screenshot of the history page during an
......
...@@ -587,8 +587,7 @@ IN_PROC_BROWSER_TEST_F(WebContentsViewAuraTest, ...@@ -587,8 +587,7 @@ IN_PROC_BROWSER_TEST_F(WebContentsViewAuraTest,
window->AddChild(shell()->web_contents()->GetContentNativeView()); window->AddChild(shell()->web_contents()->GetContentNativeView());
} }
IN_PROC_BROWSER_TEST_F(WebContentsViewAuraTest, IN_PROC_BROWSER_TEST_F(WebContentsViewAuraTest, ContentWindowClose) {
ContentWindowClose) {
ASSERT_NO_FATAL_FAILURE( ASSERT_NO_FATAL_FAILURE(
StartTestWithPage("files/overscroll_navigation.html")); StartTestWithPage("files/overscroll_navigation.html"));
...@@ -677,4 +676,18 @@ IN_PROC_BROWSER_TEST_F(WebContentsViewAuraTest, ...@@ -677,4 +676,18 @@ IN_PROC_BROWSER_TEST_F(WebContentsViewAuraTest,
EXPECT_FALSE(controller.CanGoForward()); EXPECT_FALSE(controller.CanGoForward());
} }
// Verify that hiding a parent of the renderer will hide the content too.
IN_PROC_BROWSER_TEST_F(WebContentsViewAuraTest, HideContentOnParenHide) {
ASSERT_NO_FATAL_FAILURE(StartTestWithPage("files/title1.html"));
WebContentsImpl* web_contents =
static_cast<WebContentsImpl*>(shell()->web_contents());
aura::Window* content = web_contents->GetNativeView()->parent();
aura::Window* parent = content->parent();
EXPECT_TRUE(web_contents->should_normally_be_visible());
parent->Hide();
EXPECT_FALSE(web_contents->should_normally_be_visible());
parent->Show();
EXPECT_TRUE(web_contents->should_normally_be_visible());
}
} // 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