Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: content/browser/web_contents/web_contents_view_aura.cc

Issue 286943005: Reducing CPU cycles of hidden/minimized browser windows (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/browser/web_contents/web_contents_view_aura.h" 5 #include "content/browser/web_contents/web_contents_view_aura.h"
6 6
7 #include "base/auto_reset.h" 7 #include "base/auto_reset.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/file_util.h" 9 #include "base/file_util.h"
10 #include "base/metrics/histogram.h" 10 #include "base/metrics/histogram.h"
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 return mode == (base::i18n::IsRTL() ? OVERSCROLL_EAST : OVERSCROLL_WEST) && 91 return mode == (base::i18n::IsRTL() ? OVERSCROLL_EAST : OVERSCROLL_WEST) &&
92 controller.CanGoForward(); 92 controller.CanGoForward();
93 } 93 }
94 94
95 bool ShouldNavigateBack(const NavigationController& controller, 95 bool ShouldNavigateBack(const NavigationController& controller,
96 OverscrollMode mode) { 96 OverscrollMode mode) {
97 return mode == (base::i18n::IsRTL() ? OVERSCROLL_WEST : OVERSCROLL_EAST) && 97 return mode == (base::i18n::IsRTL() ? OVERSCROLL_WEST : OVERSCROLL_EAST) &&
98 controller.CanGoBack(); 98 controller.CanGoBack();
99 } 99 }
100 100
101 // Update the |web contents| to be |visible|.
102 void UpdateWebContentsVisibility(WebContentsImpl* web_contents,
103 bool visibile) {
104 if (visibile) {
ncarter (slow) 2014/05/21 21:11:03 visibile -> visible (extra i)
Mr4D (OOO till 08-26) 2014/05/21 21:25:25 Done.
105 if (!web_contents->should_normally_be_visible())
106 web_contents->WasShown();
107 } else {
108 if (web_contents->should_normally_be_visible())
109 web_contents->WasHidden();
110 }
111 }
112
101 RenderWidgetHostViewAura* ToRenderWidgetHostViewAura( 113 RenderWidgetHostViewAura* ToRenderWidgetHostViewAura(
102 RenderWidgetHostView* view) { 114 RenderWidgetHostView* view) {
103 if (!view || RenderViewHostFactory::has_factory()) 115 if (!view || RenderViewHostFactory::has_factory())
104 return NULL; // Can't cast to RenderWidgetHostViewAura in unit tests. 116 return NULL; // Can't cast to RenderWidgetHostViewAura in unit tests.
105 RenderProcessHostImpl* process = static_cast<RenderProcessHostImpl*>( 117 RenderProcessHostImpl* process = static_cast<RenderProcessHostImpl*>(
106 view->GetRenderWidgetHost()->GetProcess()); 118 view->GetRenderWidgetHost()->GetProcess());
107 if (process->IsGuest()) 119 if (process->IsGuest())
108 return NULL; 120 return NULL;
109 return static_cast<RenderWidgetHostViewAura*>(view); 121 return static_cast<RenderWidgetHostViewAura*>(view);
110 } 122 }
(...skipping 600 matching lines...) Expand 10 before | Expand all | Expand 10 after
711 } 723 }
712 724
713 //////////////////////////////////////////////////////////////////////////////// 725 ////////////////////////////////////////////////////////////////////////////////
714 // WebContentsViewAura, private: 726 // WebContentsViewAura, private:
715 727
716 WebContentsViewAura::~WebContentsViewAura() { 728 WebContentsViewAura::~WebContentsViewAura() {
717 if (!window_) 729 if (!window_)
718 return; 730 return;
719 731
720 window_observer_.reset(); 732 window_observer_.reset();
733 window_->RemoveObserver(this);
721 734
722 // Window needs a valid delegate during its destructor, so we explicitly 735 // Window needs a valid delegate during its destructor, so we explicitly
723 // delete it here. 736 // delete it here.
724 window_.reset(); 737 window_.reset();
725 } 738 }
726 739
727 void WebContentsViewAura::SetupOverlayWindowForTesting() { 740 void WebContentsViewAura::SetupOverlayWindowForTesting() {
728 if (navigation_overlay_) 741 if (navigation_overlay_)
729 navigation_overlay_->SetupForTesting(); 742 navigation_overlay_->SetupForTesting();
730 } 743 }
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after
1038 // NOTE: we ignore |initial_size| since in some cases it's wrong (such as 1051 // NOTE: we ignore |initial_size| since in some cases it's wrong (such as
1039 // if the bookmark bar is not shown and you create a new tab). The right 1052 // if the bookmark bar is not shown and you create a new tab). The right
1040 // value is set shortly after this, so its safe to ignore. 1053 // value is set shortly after this, so its safe to ignore.
1041 1054
1042 aura::Env::CreateInstance(true); 1055 aura::Env::CreateInstance(true);
1043 window_.reset(new aura::Window(this)); 1056 window_.reset(new aura::Window(this));
1044 window_->set_owned_by_parent(false); 1057 window_->set_owned_by_parent(false);
1045 window_->SetType(ui::wm::WINDOW_TYPE_CONTROL); 1058 window_->SetType(ui::wm::WINDOW_TYPE_CONTROL);
1046 window_->SetTransparent(false); 1059 window_->SetTransparent(false);
1047 window_->Init(aura::WINDOW_LAYER_NOT_DRAWN); 1060 window_->Init(aura::WINDOW_LAYER_NOT_DRAWN);
1061 window_->AddObserver(this);
1048 aura::Window* root_window = context ? context->GetRootWindow() : NULL; 1062 aura::Window* root_window = context ? context->GetRootWindow() : NULL;
1049 if (root_window) { 1063 if (root_window) {
1050 // There are places where there is no context currently because object 1064 // There are places where there is no context currently because object
1051 // hierarchies are built before they're attached to a Widget. (See 1065 // hierarchies are built before they're attached to a Widget. (See
1052 // views::WebView as an example; GetWidget() returns NULL at the point 1066 // views::WebView as an example; GetWidget() returns NULL at the point
1053 // where we are created.) 1067 // where we are created.)
1054 // 1068 //
1055 // It should be OK to not set a default parent since such users will 1069 // It should be OK to not set a default parent since such users will
1056 // explicitly add this WebContentsViewAura to their tree after they create 1070 // explicitly add this WebContentsViewAura to their tree after they create
1057 // us. 1071 // us.
(...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after
1420 // virtual functions to be called (e.g. OnImplicitAnimationsCompleted()). So 1434 // virtual functions to be called (e.g. OnImplicitAnimationsCompleted()). So
1421 // destroy the overscroll window here. 1435 // destroy the overscroll window here.
1422 navigation_overlay_.reset(); 1436 navigation_overlay_.reset();
1423 overscroll_window_.reset(); 1437 overscroll_window_.reset();
1424 } 1438 }
1425 1439
1426 void WebContentsViewAura::OnWindowDestroyed(aura::Window* window) { 1440 void WebContentsViewAura::OnWindowDestroyed(aura::Window* window) {
1427 } 1441 }
1428 1442
1429 void WebContentsViewAura::OnWindowTargetVisibilityChanged(bool visible) { 1443 void WebContentsViewAura::OnWindowTargetVisibilityChanged(bool visible) {
1430 if (visible)
1431 web_contents_->WasShown();
1432 else
1433 web_contents_->WasHidden();
1434 } 1444 }
1435 1445
1436 bool WebContentsViewAura::HasHitTestMask() const { 1446 bool WebContentsViewAura::HasHitTestMask() const {
1437 return false; 1447 return false;
1438 } 1448 }
1439 1449
1440 void WebContentsViewAura::GetHitTestMask(gfx::Path* mask) const { 1450 void WebContentsViewAura::GetHitTestMask(gfx::Path* mask) const {
1441 } 1451 }
1442 1452
1443 //////////////////////////////////////////////////////////////////////////////// 1453 ////////////////////////////////////////////////////////////////////////////////
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
1546 web_contents_->GetRenderViewHost()->DragTargetDrop( 1556 web_contents_->GetRenderViewHost()->DragTargetDrop(
1547 event.location(), 1557 event.location(),
1548 gfx::Screen::GetScreenFor(GetNativeView())->GetCursorScreenPoint(), 1558 gfx::Screen::GetScreenFor(GetNativeView())->GetCursorScreenPoint(),
1549 ConvertAuraEventFlagsToWebInputEventModifiers(event.flags())); 1559 ConvertAuraEventFlagsToWebInputEventModifiers(event.flags()));
1550 if (drag_dest_delegate_) 1560 if (drag_dest_delegate_)
1551 drag_dest_delegate_->OnDrop(); 1561 drag_dest_delegate_->OnDrop();
1552 current_drop_data_.reset(); 1562 current_drop_data_.reset();
1553 return ConvertFromWeb(current_drag_op_); 1563 return ConvertFromWeb(current_drag_op_);
1554 } 1564 }
1555 1565
1566 void WebContentsViewAura::OnWindowParentChanged(aura::Window* window,
1567 aura::Window* parent) {
1568 UpdateWebContentsVisibility(web_contents_, !parent || parent->IsVisible());
1569 }
1570
1571 void WebContentsViewAura::OnWindowVisibilityChanged(aura::Window* window,
1572 bool visible) {
1573 // Ignore any visibility changes in the hierarchy below.
1574 if (window != window_.get() && window_->Contains(window))
1575 return;
1576
1577 UpdateWebContentsVisibility(web_contents_, visible);
1578 }
1579
1556 } // namespace content 1580 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698