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

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 |visibility| of the |web contents|.
102 void UpdateWebContentsVisibility(WebContentsImpl* web_contents,
103 bool visibility) {
sky 2014/05/20 23:33:51 visibility->visible
Mr4D (OOO till 08-26) 2014/05/21 14:25:03 Done.
104 if (visibility) {
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 603 matching lines...) Expand 10 before | Expand all | Expand 10 after
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();
721 733
722 // Window needs a valid delegate during its destructor, so we explicitly 734 // Window needs a valid delegate during its destructor, so we explicitly
723 // delete it here. 735 // delete it here.
736 window_->RemoveObserver(this);
sky 2014/05/20 23:33:51 nit: move this above comment (since comment applie
Mr4D (OOO till 08-26) 2014/05/21 14:25:03 Done.
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 }
731 744
732 void WebContentsViewAura::SetTouchEditableForTest( 745 void WebContentsViewAura::SetTouchEditableForTest(
733 TouchEditableImplAura* touch_editable) { 746 TouchEditableImplAura* touch_editable) {
(...skipping 304 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 364 matching lines...) Expand 10 before | Expand all | Expand 10 after
1422 // virtual functions to be called (e.g. OnImplicitAnimationsCompleted()). So 1436 // virtual functions to be called (e.g. OnImplicitAnimationsCompleted()). So
1423 // destroy the overscroll window here. 1437 // destroy the overscroll window here.
1424 navigation_overlay_.reset(); 1438 navigation_overlay_.reset();
1425 overscroll_window_.reset(); 1439 overscroll_window_.reset();
1426 } 1440 }
1427 1441
1428 void WebContentsViewAura::OnWindowDestroyed(aura::Window* window) { 1442 void WebContentsViewAura::OnWindowDestroyed(aura::Window* window) {
1429 } 1443 }
1430 1444
1431 void WebContentsViewAura::OnWindowTargetVisibilityChanged(bool visible) { 1445 void WebContentsViewAura::OnWindowTargetVisibilityChanged(bool visible) {
1432 if (visible)
1433 web_contents_->WasShown();
1434 else
1435 web_contents_->WasHidden();
1436 } 1446 }
1437 1447
1438 bool WebContentsViewAura::HasHitTestMask() const { 1448 bool WebContentsViewAura::HasHitTestMask() const {
1439 return false; 1449 return false;
1440 } 1450 }
1441 1451
1442 void WebContentsViewAura::GetHitTestMask(gfx::Path* mask) const { 1452 void WebContentsViewAura::GetHitTestMask(gfx::Path* mask) const {
1443 } 1453 }
1444 1454
1445 //////////////////////////////////////////////////////////////////////////////// 1455 ////////////////////////////////////////////////////////////////////////////////
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
1548 web_contents_->GetRenderViewHost()->DragTargetDrop( 1558 web_contents_->GetRenderViewHost()->DragTargetDrop(
1549 event.location(), 1559 event.location(),
1550 gfx::Screen::GetScreenFor(GetNativeView())->GetCursorScreenPoint(), 1560 gfx::Screen::GetScreenFor(GetNativeView())->GetCursorScreenPoint(),
1551 ConvertAuraEventFlagsToWebInputEventModifiers(event.flags())); 1561 ConvertAuraEventFlagsToWebInputEventModifiers(event.flags()));
1552 if (drag_dest_delegate_) 1562 if (drag_dest_delegate_)
1553 drag_dest_delegate_->OnDrop(); 1563 drag_dest_delegate_->OnDrop();
1554 current_drop_data_.reset(); 1564 current_drop_data_.reset();
1555 return ConvertFromWeb(current_drag_op_); 1565 return ConvertFromWeb(current_drag_op_);
1556 } 1566 }
1557 1567
1568 void WebContentsViewAura::OnWindowParentChanged(aura::Window* window,
1569 aura::Window* parent) {
1570 UpdateWebContentsVisibility(web_contents_, !parent || parent->IsVisible());
1571 }
1572
1573 void WebContentsViewAura::OnWindowVisibilityChanged(aura::Window* window,
1574 bool visible) {
1575 // Ignore any visibility changes in the hierarchy below.
1576 if (window != window_.get() && window_->Contains(window))
1577 return;
1578
1579 UpdateWebContentsVisibility(web_contents_, visible);
1580 }
1581
1558 } // namespace content 1582 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698