| OLD | NEW |
| 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_impl.h" | 5 #include "content/browser/web_contents/web_contents_impl.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/debug/trace_event.h" | 10 #include "base/debug/trace_event.h" |
| (...skipping 907 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 918 ++capturer_count_; | 918 ++capturer_count_; |
| 919 DVLOG(1) << "There are now " << capturer_count_ | 919 DVLOG(1) << "There are now " << capturer_count_ |
| 920 << " capturing(s) of WebContentsImpl@" << this; | 920 << " capturing(s) of WebContentsImpl@" << this; |
| 921 | 921 |
| 922 // Note: This provides a hint to upstream code to size the views optimally | 922 // Note: This provides a hint to upstream code to size the views optimally |
| 923 // for quality (e.g., to avoid scaling). | 923 // for quality (e.g., to avoid scaling). |
| 924 if (!capture_size.IsEmpty() && preferred_size_for_capture_.IsEmpty()) { | 924 if (!capture_size.IsEmpty() && preferred_size_for_capture_.IsEmpty()) { |
| 925 preferred_size_for_capture_ = capture_size; | 925 preferred_size_for_capture_ = capture_size; |
| 926 OnPreferredSizeChanged(preferred_size_); | 926 OnPreferredSizeChanged(preferred_size_); |
| 927 } | 927 } |
| 928 |
| 929 // Ensure that all views are un-occluded before capture begins. |
| 930 WasUnOccluded(); |
| 928 } | 931 } |
| 929 | 932 |
| 930 void WebContentsImpl::DecrementCapturerCount() { | 933 void WebContentsImpl::DecrementCapturerCount() { |
| 931 --capturer_count_; | 934 --capturer_count_; |
| 932 DVLOG(1) << "There are now " << capturer_count_ | 935 DVLOG(1) << "There are now " << capturer_count_ |
| 933 << " capturing(s) of WebContentsImpl@" << this; | 936 << " capturing(s) of WebContentsImpl@" << this; |
| 934 DCHECK_LE(0, capturer_count_); | 937 DCHECK_LE(0, capturer_count_); |
| 935 | 938 |
| 936 if (is_being_destroyed_) | 939 if (is_being_destroyed_) |
| 937 return; | 940 return; |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1018 delegate_->NavigationStateChanged(this, changed_flags); | 1021 delegate_->NavigationStateChanged(this, changed_flags); |
| 1019 } | 1022 } |
| 1020 | 1023 |
| 1021 base::TimeTicks WebContentsImpl::GetLastActiveTime() const { | 1024 base::TimeTicks WebContentsImpl::GetLastActiveTime() const { |
| 1022 return last_active_time_; | 1025 return last_active_time_; |
| 1023 } | 1026 } |
| 1024 | 1027 |
| 1025 void WebContentsImpl::WasShown() { | 1028 void WebContentsImpl::WasShown() { |
| 1026 controller_.SetActive(true); | 1029 controller_.SetActive(true); |
| 1027 | 1030 |
| 1028 std::set<RenderWidgetHostView*> widgets = GetRenderWidgetHostViewsInTree(); | 1031 for (RenderWidgetHostView* view : GetRenderWidgetHostViewsInTree()) { |
| 1029 for (std::set<RenderWidgetHostView*>::iterator iter = widgets.begin(); | 1032 if (view) { |
| 1030 iter != widgets.end(); | 1033 view->Show(); |
| 1031 iter++) { | |
| 1032 if (*iter) { | |
| 1033 (*iter)->Show(); | |
| 1034 #if defined(OS_MACOSX) | 1034 #if defined(OS_MACOSX) |
| 1035 (*iter)->SetActive(true); | 1035 view->SetActive(true); |
| 1036 #endif | 1036 #endif |
| 1037 } | 1037 } |
| 1038 } | 1038 } |
| 1039 | 1039 |
| 1040 last_active_time_ = base::TimeTicks::Now(); | 1040 last_active_time_ = base::TimeTicks::Now(); |
| 1041 | 1041 |
| 1042 // The resize rect might have changed while this was inactive -- send the new | 1042 // The resize rect might have changed while this was inactive -- send the new |
| 1043 // one to make sure it's up to date. | 1043 // one to make sure it's up to date. |
| 1044 RenderViewHostImpl* rvh = | 1044 RenderViewHostImpl* rvh = |
| 1045 static_cast<RenderViewHostImpl*>(GetRenderViewHost()); | 1045 static_cast<RenderViewHostImpl*>(GetRenderViewHost()); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1059 void WebContentsImpl::WasHidden() { | 1059 void WebContentsImpl::WasHidden() { |
| 1060 // If there are entities capturing screenshots or video (e.g., mirroring), | 1060 // If there are entities capturing screenshots or video (e.g., mirroring), |
| 1061 // don't activate the "disable rendering" optimization. | 1061 // don't activate the "disable rendering" optimization. |
| 1062 if (capturer_count_ == 0) { | 1062 if (capturer_count_ == 0) { |
| 1063 // |GetRenderViewHost()| can be NULL if the user middle clicks a link to | 1063 // |GetRenderViewHost()| can be NULL if the user middle clicks a link to |
| 1064 // open a tab in the background, then closes the tab before selecting it. | 1064 // open a tab in the background, then closes the tab before selecting it. |
| 1065 // This is because closing the tab calls WebContentsImpl::Destroy(), which | 1065 // This is because closing the tab calls WebContentsImpl::Destroy(), which |
| 1066 // removes the |GetRenderViewHost()|; then when we actually destroy the | 1066 // removes the |GetRenderViewHost()|; then when we actually destroy the |
| 1067 // window, OnWindowPosChanged() notices and calls WasHidden() (which | 1067 // window, OnWindowPosChanged() notices and calls WasHidden() (which |
| 1068 // calls us). | 1068 // calls us). |
| 1069 std::set<RenderWidgetHostView*> widgets = GetRenderWidgetHostViewsInTree(); | 1069 for (RenderWidgetHostView* view : GetRenderWidgetHostViewsInTree()) { |
| 1070 for (std::set<RenderWidgetHostView*>::iterator iter = widgets.begin(); | 1070 if (view) |
| 1071 iter != widgets.end(); | 1071 view->Hide(); |
| 1072 iter++) { | |
| 1073 if (*iter) | |
| 1074 (*iter)->Hide(); | |
| 1075 } | 1072 } |
| 1076 | 1073 |
| 1077 // Release any video power save blockers held as video is not visible. | 1074 // Release any video power save blockers held as video is not visible. |
| 1078 video_power_save_blocker_.reset(); | 1075 video_power_save_blocker_.reset(); |
| 1079 } | 1076 } |
| 1080 | 1077 |
| 1081 FOR_EACH_OBSERVER(WebContentsObserver, observers_, WasHidden()); | 1078 FOR_EACH_OBSERVER(WebContentsObserver, observers_, WasHidden()); |
| 1082 | 1079 |
| 1083 should_normally_be_visible_ = false; | 1080 should_normally_be_visible_ = false; |
| 1084 } | 1081 } |
| 1085 | 1082 |
| 1083 void WebContentsImpl::WasOccluded() { |
| 1084 if (capturer_count_ > 0) |
| 1085 return; |
| 1086 |
| 1087 for (RenderWidgetHostView* view : GetRenderWidgetHostViewsInTree()) { |
| 1088 if (view) |
| 1089 view->WasOccluded(); |
| 1090 } |
| 1091 } |
| 1092 |
| 1093 void WebContentsImpl::WasUnOccluded() { |
| 1094 for (RenderWidgetHostView* view : GetRenderWidgetHostViewsInTree()) { |
| 1095 if (view) |
| 1096 view->WasUnOccluded(); |
| 1097 } |
| 1098 } |
| 1099 |
| 1086 bool WebContentsImpl::NeedToFireBeforeUnload() { | 1100 bool WebContentsImpl::NeedToFireBeforeUnload() { |
| 1087 // TODO(creis): Should we fire even for interstitial pages? | 1101 // TODO(creis): Should we fire even for interstitial pages? |
| 1088 return WillNotifyDisconnection() && | 1102 return WillNotifyDisconnection() && |
| 1089 !ShowingInterstitialPage() && | 1103 !ShowingInterstitialPage() && |
| 1090 !static_cast<RenderViewHostImpl*>( | 1104 !static_cast<RenderViewHostImpl*>( |
| 1091 GetRenderViewHost())->SuddenTerminationAllowed(); | 1105 GetRenderViewHost())->SuddenTerminationAllowed(); |
| 1092 } | 1106 } |
| 1093 | 1107 |
| 1094 void WebContentsImpl::DispatchBeforeUnload(bool for_cross_site_transition) { | 1108 void WebContentsImpl::DispatchBeforeUnload(bool for_cross_site_transition) { |
| 1095 static_cast<RenderFrameHostImpl*>(GetMainFrame())->DispatchBeforeUnload( | 1109 static_cast<RenderFrameHostImpl*>(GetMainFrame())->DispatchBeforeUnload( |
| (...skipping 3306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4402 node->render_manager()->ResumeResponseDeferredAtStart(); | 4416 node->render_manager()->ResumeResponseDeferredAtStart(); |
| 4403 } | 4417 } |
| 4404 | 4418 |
| 4405 void WebContentsImpl::SetForceDisableOverscrollContent(bool force_disable) { | 4419 void WebContentsImpl::SetForceDisableOverscrollContent(bool force_disable) { |
| 4406 force_disable_overscroll_content_ = force_disable; | 4420 force_disable_overscroll_content_ = force_disable; |
| 4407 if (view_) | 4421 if (view_) |
| 4408 view_->SetOverscrollControllerEnabled(CanOverscrollContent()); | 4422 view_->SetOverscrollControllerEnabled(CanOverscrollContent()); |
| 4409 } | 4423 } |
| 4410 | 4424 |
| 4411 } // namespace content | 4425 } // namespace content |
| OLD | NEW |