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 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
210 on_frame.Run(node->current_frame_host()); | 210 on_frame.Run(node->current_frame_host()); |
211 return true; | 211 return true; |
212 } | 212 } |
213 | 213 |
214 void SendToAllFramesInternal(IPC::Message* message, RenderFrameHost* rfh) { | 214 void SendToAllFramesInternal(IPC::Message* message, RenderFrameHost* rfh) { |
215 IPC::Message* message_copy = new IPC::Message(*message); | 215 IPC::Message* message_copy = new IPC::Message(*message); |
216 message_copy->set_routing_id(rfh->GetRoutingID()); | 216 message_copy->set_routing_id(rfh->GetRoutingID()); |
217 rfh->Send(message_copy); | 217 rfh->Send(message_copy); |
218 } | 218 } |
219 | 219 |
| 220 void AddRenderWidgetHostToSet(std::set<RenderWidgetHostImpl*>* set, |
| 221 RenderFrameHost* rfh) { |
| 222 set->insert(static_cast<RenderFrameHostImpl*>(rfh)->GetRenderWidgetHost()); |
| 223 } |
| 224 |
220 } // namespace | 225 } // namespace |
221 | 226 |
222 WebContents* WebContents::Create(const WebContents::CreateParams& params) { | 227 WebContents* WebContents::Create(const WebContents::CreateParams& params) { |
223 return WebContentsImpl::CreateWithOpener( | 228 return WebContentsImpl::CreateWithOpener( |
224 params, static_cast<WebContentsImpl*>(params.opener)); | 229 params, static_cast<WebContentsImpl*>(params.opener)); |
225 } | 230 } |
226 | 231 |
227 WebContents* WebContents::CreateWithSessionStorage( | 232 WebContents* WebContents::CreateWithSessionStorage( |
228 const WebContents::CreateParams& params, | 233 const WebContents::CreateParams& params, |
229 const SessionStorageNamespaceMap& session_storage_namespace_map) { | 234 const SessionStorageNamespaceMap& session_storage_namespace_map) { |
(...skipping 701 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
931 if (delegate_) | 936 if (delegate_) |
932 delegate_->NavigationStateChanged(this, changed_flags); | 937 delegate_->NavigationStateChanged(this, changed_flags); |
933 } | 938 } |
934 | 939 |
935 base::TimeTicks WebContentsImpl::GetLastActiveTime() const { | 940 base::TimeTicks WebContentsImpl::GetLastActiveTime() const { |
936 return last_active_time_; | 941 return last_active_time_; |
937 } | 942 } |
938 | 943 |
939 void WebContentsImpl::WasShown() { | 944 void WebContentsImpl::WasShown() { |
940 controller_.SetActive(true); | 945 controller_.SetActive(true); |
941 RenderWidgetHostView* rwhv = GetRenderWidgetHostView(); | 946 |
942 if (rwhv) { | 947 std::set<RenderWidgetHostImpl*> widgets = GetRenderWidgetHostsInTree(); |
943 rwhv->Show(); | 948 for (std::set<RenderWidgetHostImpl*>::iterator iter = widgets.begin(); |
| 949 iter != widgets.end(); |
| 950 iter++) { |
| 951 RenderWidgetHostView* rwhv = (*iter)->GetView(); |
| 952 if (rwhv) { |
| 953 rwhv->Show(); |
944 #if defined(OS_MACOSX) | 954 #if defined(OS_MACOSX) |
945 rwhv->SetActive(true); | 955 rwhv->SetActive(true); |
946 #endif | 956 #endif |
| 957 } |
947 } | 958 } |
948 | 959 |
949 last_active_time_ = base::TimeTicks::Now(); | 960 last_active_time_ = base::TimeTicks::Now(); |
950 | 961 |
951 // The resize rect might have changed while this was inactive -- send the new | 962 // The resize rect might have changed while this was inactive -- send the new |
952 // one to make sure it's up to date. | 963 // one to make sure it's up to date. |
953 RenderViewHostImpl* rvh = | 964 RenderViewHostImpl* rvh = |
954 static_cast<RenderViewHostImpl*>(GetRenderViewHost()); | 965 static_cast<RenderViewHostImpl*>(GetRenderViewHost()); |
955 if (rvh) { | 966 if (rvh) { |
956 rvh->ResizeRectChanged(GetRootWindowResizerRect()); | 967 rvh->ResizeRectChanged(GetRootWindowResizerRect()); |
957 } | 968 } |
958 | 969 |
959 FOR_EACH_OBSERVER(WebContentsObserver, observers_, WasShown()); | 970 FOR_EACH_OBSERVER(WebContentsObserver, observers_, WasShown()); |
960 | 971 |
961 should_normally_be_visible_ = true; | 972 should_normally_be_visible_ = true; |
962 } | 973 } |
963 | 974 |
964 void WebContentsImpl::WasHidden() { | 975 void WebContentsImpl::WasHidden() { |
965 // If there are entities capturing screenshots or video (e.g., mirroring), | 976 // If there are entities capturing screenshots or video (e.g., mirroring), |
966 // don't activate the "disable rendering" optimization. | 977 // don't activate the "disable rendering" optimization. |
967 if (capturer_count_ == 0) { | 978 if (capturer_count_ == 0) { |
968 // |GetRenderViewHost()| can be NULL if the user middle clicks a link to | 979 // |GetRenderViewHost()| can be NULL if the user middle clicks a link to |
969 // open a tab in the background, then closes the tab before selecting it. | 980 // open a tab in the background, then closes the tab before selecting it. |
970 // This is because closing the tab calls WebContentsImpl::Destroy(), which | 981 // This is because closing the tab calls WebContentsImpl::Destroy(), which |
971 // removes the |GetRenderViewHost()|; then when we actually destroy the | 982 // removes the |GetRenderViewHost()|; then when we actually destroy the |
972 // window, OnWindowPosChanged() notices and calls WasHidden() (which | 983 // window, OnWindowPosChanged() notices and calls WasHidden() (which |
973 // calls us). | 984 // calls us). |
974 RenderWidgetHostView* rwhv = GetRenderWidgetHostView(); | 985 std::set<RenderWidgetHostImpl*> widgets = GetRenderWidgetHostsInTree(); |
975 if (rwhv) | 986 for (std::set<RenderWidgetHostImpl*>::iterator iter = widgets.begin(); |
976 rwhv->Hide(); | 987 iter != widgets.end(); |
| 988 iter++) { |
| 989 RenderWidgetHostView* rwhv = (*iter)->GetView(); |
| 990 if (rwhv) |
| 991 rwhv->Hide(); |
| 992 } |
977 } | 993 } |
978 | 994 |
979 FOR_EACH_OBSERVER(WebContentsObserver, observers_, WasHidden()); | 995 FOR_EACH_OBSERVER(WebContentsObserver, observers_, WasHidden()); |
980 | 996 |
981 should_normally_be_visible_ = false; | 997 should_normally_be_visible_ = false; |
982 } | 998 } |
983 | 999 |
984 bool WebContentsImpl::NeedToFireBeforeUnload() { | 1000 bool WebContentsImpl::NeedToFireBeforeUnload() { |
985 // TODO(creis): Should we fire even for interstitial pages? | 1001 // TODO(creis): Should we fire even for interstitial pages? |
986 return WillNotifyDisconnection() && | 1002 return WillNotifyDisconnection() && |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1122 } | 1138 } |
1123 | 1139 |
1124 void WebContentsImpl::AddObserver(WebContentsObserver* observer) { | 1140 void WebContentsImpl::AddObserver(WebContentsObserver* observer) { |
1125 observers_.AddObserver(observer); | 1141 observers_.AddObserver(observer); |
1126 } | 1142 } |
1127 | 1143 |
1128 void WebContentsImpl::RemoveObserver(WebContentsObserver* observer) { | 1144 void WebContentsImpl::RemoveObserver(WebContentsObserver* observer) { |
1129 observers_.RemoveObserver(observer); | 1145 observers_.RemoveObserver(observer); |
1130 } | 1146 } |
1131 | 1147 |
| 1148 std::set<RenderWidgetHostImpl*> WebContentsImpl::GetRenderWidgetHostsInTree() { |
| 1149 std::set<RenderWidgetHostImpl*> set; |
| 1150 ForEachFrame(base::Bind(&AddRenderWidgetHostToSet, base::Unretained(&set))); |
| 1151 return set; |
| 1152 } |
| 1153 |
1132 void WebContentsImpl::Activate() { | 1154 void WebContentsImpl::Activate() { |
1133 if (delegate_) | 1155 if (delegate_) |
1134 delegate_->ActivateContents(this); | 1156 delegate_->ActivateContents(this); |
1135 } | 1157 } |
1136 | 1158 |
1137 void WebContentsImpl::Deactivate() { | 1159 void WebContentsImpl::Deactivate() { |
1138 if (delegate_) | 1160 if (delegate_) |
1139 delegate_->DeactivateContents(this); | 1161 delegate_->DeactivateContents(this); |
1140 } | 1162 } |
1141 | 1163 |
(...skipping 2924 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4066 | 4088 |
4067 void WebContentsImpl::OnPreferredSizeChanged(const gfx::Size& old_size) { | 4089 void WebContentsImpl::OnPreferredSizeChanged(const gfx::Size& old_size) { |
4068 if (!delegate_) | 4090 if (!delegate_) |
4069 return; | 4091 return; |
4070 const gfx::Size new_size = GetPreferredSize(); | 4092 const gfx::Size new_size = GetPreferredSize(); |
4071 if (new_size != old_size) | 4093 if (new_size != old_size) |
4072 delegate_->UpdatePreferredSize(this, new_size); | 4094 delegate_->UpdatePreferredSize(this, new_size); |
4073 } | 4095 } |
4074 | 4096 |
4075 } // namespace content | 4097 } // namespace content |
OLD | NEW |