| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/frame_host/render_frame_host_impl.h" | 5 #include "content/browser/frame_host/render_frame_host_impl.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/containers/hash_tables.h" | 9 #include "base/containers/hash_tables.h" |
| 10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 207 } else { | 207 } else { |
| 208 rfh_state_ = STATE_DEFAULT; | 208 rfh_state_ = STATE_DEFAULT; |
| 209 GetSiteInstance()->increment_active_frame_count(); | 209 GetSiteInstance()->increment_active_frame_count(); |
| 210 } | 210 } |
| 211 | 211 |
| 212 SetUpMojoIfNeeded(); | 212 SetUpMojoIfNeeded(); |
| 213 swapout_event_monitor_timeout_.reset(new TimeoutMonitor(base::Bind( | 213 swapout_event_monitor_timeout_.reset(new TimeoutMonitor(base::Bind( |
| 214 &RenderFrameHostImpl::OnSwappedOut, weak_ptr_factory_.GetWeakPtr()))); | 214 &RenderFrameHostImpl::OnSwappedOut, weak_ptr_factory_.GetWeakPtr()))); |
| 215 | 215 |
| 216 if (widget_routing_id != MSG_ROUTING_NONE) { | 216 if (widget_routing_id != MSG_ROUTING_NONE) { |
| 217 render_widget_host_ = new RenderWidgetHostImpl(rwh_delegate, GetProcess(), | 217 // TODO(avi): Once RenderViewHostImpl has-a RenderWidgetHostImpl, the main |
| 218 widget_routing_id, hidden); | 218 // render frame should probably start owning the RenderWidgetHostImpl, |
| 219 render_widget_host_->set_owned_by_render_frame_host(true); | 219 // so this logic checking for an already existing RWHI should be removed. |
| 220 // https://crbug.com/545684 |
| 221 render_widget_host_ = |
| 222 RenderWidgetHostImpl::FromID(GetProcess()->GetID(), widget_routing_id); |
| 223 if (!render_widget_host_) { |
| 224 DCHECK(frame_tree_node->parent()); |
| 225 render_widget_host_ = new RenderWidgetHostImpl(rwh_delegate, GetProcess(), |
| 226 widget_routing_id, hidden); |
| 227 render_widget_host_->set_owned_by_render_frame_host(true); |
| 228 } else { |
| 229 DCHECK(!render_widget_host_->owned_by_render_frame_host()); |
| 230 } |
| 220 } | 231 } |
| 221 } | 232 } |
| 222 | 233 |
| 223 RenderFrameHostImpl::~RenderFrameHostImpl() { | 234 RenderFrameHostImpl::~RenderFrameHostImpl() { |
| 224 GetProcess()->RemoveRoute(routing_id_); | 235 GetProcess()->RemoveRoute(routing_id_); |
| 225 g_routing_id_frame_map.Get().erase( | 236 g_routing_id_frame_map.Get().erase( |
| 226 RenderFrameHostID(GetProcess()->GetID(), routing_id_)); | 237 RenderFrameHostID(GetProcess()->GetID(), routing_id_)); |
| 227 | 238 |
| 228 if (delegate_ && render_frame_created_) | 239 if (delegate_ && render_frame_created_) |
| 229 delegate_->RenderFrameDeleted(this); | 240 delegate_->RenderFrameDeleted(this); |
| 230 | 241 |
| 231 // If this was swapped out, it already decremented the active frame count of | 242 // If this was swapped out, it already decremented the active frame count of |
| 232 // the SiteInstance it belongs to. | 243 // the SiteInstance it belongs to. |
| 233 if (IsRFHStateActive(rfh_state_)) | 244 if (IsRFHStateActive(rfh_state_)) |
| 234 GetSiteInstance()->decrement_active_frame_count(); | 245 GetSiteInstance()->decrement_active_frame_count(); |
| 235 | 246 |
| 236 // Notify the FrameTree that this RFH is going away, allowing it to shut down | |
| 237 // the corresponding RenderViewHost if it is no longer needed. | |
| 238 frame_tree_->ReleaseRenderViewHostRef(render_view_host_); | |
| 239 | |
| 240 // NULL out the swapout timer; in crash dumps this member will be null only if | 247 // NULL out the swapout timer; in crash dumps this member will be null only if |
| 241 // the dtor has run. | 248 // the dtor has run. |
| 242 swapout_event_monitor_timeout_.reset(); | 249 swapout_event_monitor_timeout_.reset(); |
| 243 | 250 |
| 244 for (const auto& iter: visual_state_callbacks_) { | 251 for (const auto& iter: visual_state_callbacks_) { |
| 245 iter.second.Run(false); | 252 iter.second.Run(false); |
| 246 } | 253 } |
| 247 | 254 |
| 248 if (render_widget_host_) { | 255 if (render_widget_host_ && |
| 256 render_widget_host_->owned_by_render_frame_host()) { |
| 249 // Shutdown causes the RenderWidgetHost to delete itself. | 257 // Shutdown causes the RenderWidgetHost to delete itself. |
| 250 render_widget_host_->Shutdown(); | 258 render_widget_host_->Shutdown(); |
| 251 } | 259 } |
| 260 |
| 261 // Notify the FrameTree that this RFH is going away, allowing it to shut down |
| 262 // the corresponding RenderViewHost if it is no longer needed. |
| 263 frame_tree_->ReleaseRenderViewHostRef(render_view_host_); |
| 252 } | 264 } |
| 253 | 265 |
| 254 int RenderFrameHostImpl::GetRoutingID() { | 266 int RenderFrameHostImpl::GetRoutingID() { |
| 255 return routing_id_; | 267 return routing_id_; |
| 256 } | 268 } |
| 257 | 269 |
| 258 AXTreeIDRegistry::AXTreeID RenderFrameHostImpl::GetAXTreeID() { | 270 AXTreeIDRegistry::AXTreeID RenderFrameHostImpl::GetAXTreeID() { |
| 259 return AXTreeIDRegistry::GetInstance()->GetOrCreateAXTreeID( | 271 return AXTreeIDRegistry::GetInstance()->GetOrCreateAXTreeID( |
| 260 GetProcess()->GetID(), routing_id_); | 272 GetProcess()->GetID(), routing_id_); |
| 261 } | 273 } |
| (...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 645 // MSG_ROUTING_NONE will prevent a new RenderWidget from being created in | 657 // MSG_ROUTING_NONE will prevent a new RenderWidget from being created in |
| 646 // the renderer process. | 658 // the renderer process. |
| 647 params.widget_params.routing_id = MSG_ROUTING_NONE; | 659 params.widget_params.routing_id = MSG_ROUTING_NONE; |
| 648 params.widget_params.hidden = true; | 660 params.widget_params.hidden = true; |
| 649 } | 661 } |
| 650 | 662 |
| 651 Send(new FrameMsg_NewFrame(params)); | 663 Send(new FrameMsg_NewFrame(params)); |
| 652 | 664 |
| 653 // The RenderWidgetHost takes ownership of its view. It is tied to the | 665 // The RenderWidgetHost takes ownership of its view. It is tied to the |
| 654 // lifetime of the current RenderProcessHost for this RenderFrameHost. | 666 // lifetime of the current RenderProcessHost for this RenderFrameHost. |
| 655 if (render_widget_host_) { | 667 // TODO(avi): This will need to change to initialize a |
| 668 // RenderWidgetHostViewAura for the main frame once RenderViewHostImpl has-a |
| 669 // RenderWidgetHostImpl. https://crbug.com/545684 |
| 670 if (parent_routing_id != MSG_ROUTING_NONE && render_widget_host_) { |
| 656 RenderWidgetHostView* rwhv = | 671 RenderWidgetHostView* rwhv = |
| 657 new RenderWidgetHostViewChildFrame(render_widget_host_); | 672 new RenderWidgetHostViewChildFrame(render_widget_host_); |
| 658 rwhv->Hide(); | 673 rwhv->Hide(); |
| 659 } | 674 } |
| 660 | 675 |
| 661 if (proxy_routing_id != MSG_ROUTING_NONE) { | 676 if (proxy_routing_id != MSG_ROUTING_NONE) { |
| 662 RenderFrameProxyHost* proxy = RenderFrameProxyHost::FromID( | 677 RenderFrameProxyHost* proxy = RenderFrameProxyHost::FromID( |
| 663 GetProcess()->GetID(), proxy_routing_id); | 678 GetProcess()->GetID(), proxy_routing_id); |
| 664 // We have also created a RenderFrameProxy in FrameMsg_NewFrame above, so | 679 // We have also created a RenderFrameProxy in FrameMsg_NewFrame above, so |
| 665 // remember that. | 680 // remember that. |
| (...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 947 void RenderFrameHostImpl::OnDidDropNavigation() { | 962 void RenderFrameHostImpl::OnDidDropNavigation() { |
| 948 // At the end of Navigate(), the FrameTreeNode's DidStartLoading is called to | 963 // At the end of Navigate(), the FrameTreeNode's DidStartLoading is called to |
| 949 // force the spinner to start, even if the renderer didn't yet begin the load. | 964 // force the spinner to start, even if the renderer didn't yet begin the load. |
| 950 // If it turns out that the renderer dropped the navigation, the spinner needs | 965 // If it turns out that the renderer dropped the navigation, the spinner needs |
| 951 // to be turned off. | 966 // to be turned off. |
| 952 frame_tree_node_->DidStopLoading(); | 967 frame_tree_node_->DidStopLoading(); |
| 953 navigation_handle_.reset(); | 968 navigation_handle_.reset(); |
| 954 } | 969 } |
| 955 | 970 |
| 956 RenderWidgetHostImpl* RenderFrameHostImpl::GetRenderWidgetHost() { | 971 RenderWidgetHostImpl* RenderFrameHostImpl::GetRenderWidgetHost() { |
| 957 if (render_widget_host_) | 972 return render_widget_host_; |
| 958 return render_widget_host_; | |
| 959 | |
| 960 // TODO(kenrb): Remove this fallback and have the top-level frame have a | |
| 961 // widget host just like all the other frames. | |
| 962 if (!GetParent()) | |
| 963 return render_view_host_->GetWidget(); | |
| 964 | |
| 965 return nullptr; | |
| 966 } | 973 } |
| 967 | 974 |
| 968 RenderWidgetHostView* RenderFrameHostImpl::GetView() { | 975 RenderWidgetHostView* RenderFrameHostImpl::GetView() { |
| 969 RenderFrameHostImpl* frame = this; | 976 RenderFrameHostImpl* frame = this; |
| 970 while (frame) { | 977 while (frame) { |
| 971 if (frame->render_widget_host_) | 978 if (frame->render_widget_host_) |
| 972 return frame->render_widget_host_->GetView(); | 979 return frame->render_widget_host_->GetView(); |
| 973 frame = static_cast<RenderFrameHostImpl*>(frame->GetParent()); | 980 frame = static_cast<RenderFrameHostImpl*>(frame->GetParent()); |
| 974 } | 981 } |
| 975 | 982 |
| 976 return render_view_host_->GetWidget()->GetView(); | 983 NOTREACHED(); |
| 984 return nullptr; |
| 977 } | 985 } |
| 978 | 986 |
| 979 int RenderFrameHostImpl::GetEnabledBindings() { | 987 int RenderFrameHostImpl::GetEnabledBindings() { |
| 980 return render_view_host_->GetEnabledBindings(); | 988 return render_view_host_->GetEnabledBindings(); |
| 981 } | 989 } |
| 982 | 990 |
| 983 void RenderFrameHostImpl::SetNavigationHandle( | 991 void RenderFrameHostImpl::SetNavigationHandle( |
| 984 scoped_ptr<NavigationHandleImpl> navigation_handle) { | 992 scoped_ptr<NavigationHandleImpl> navigation_handle) { |
| 985 navigation_handle_ = navigation_handle.Pass(); | 993 navigation_handle_ = navigation_handle.Pass(); |
| 986 } | 994 } |
| (...skipping 1298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2285 *dst = src; | 2293 *dst = src; |
| 2286 | 2294 |
| 2287 if (src.routing_id != -1) | 2295 if (src.routing_id != -1) |
| 2288 dst->tree_id = RoutingIDToAXTreeID(src.routing_id); | 2296 dst->tree_id = RoutingIDToAXTreeID(src.routing_id); |
| 2289 | 2297 |
| 2290 if (src.parent_routing_id != -1) | 2298 if (src.parent_routing_id != -1) |
| 2291 dst->parent_tree_id = RoutingIDToAXTreeID(src.parent_routing_id); | 2299 dst->parent_tree_id = RoutingIDToAXTreeID(src.parent_routing_id); |
| 2292 } | 2300 } |
| 2293 | 2301 |
| 2294 } // namespace content | 2302 } // namespace content |
| OLD | NEW |