1 // Copyright 2014 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #include "content/browser/frame_host/render_frame_proxy_host.h" 6 7 #include "content/browser/frame_host/cross_process_frame_connector.h" 8 #include "content/browser/frame_host/frame_tree_node.h" 9 #include "content/browser/frame_host/render_frame_host_impl.h" 10 #include "content/browser/frame_host/render_widget_host_view_child_frame.h" 11 #include "content/browser/renderer_host/render_widget_host_view_base.h" 12 #include "content/browser/site_instance_impl.h" 13 #include "content/common/frame_messages.h" 14 #include "ipc/ipc_message.h" 15 16 namespace content { 17 18 RenderFrameProxyHost::RenderFrameProxyHost(SiteInstance* site_instance, 19 FrameTreeNode* frame_tree_node) 20 : routing_id_(site_instance->GetProcess()->GetNextRoutingID()), 21 site_instance_(site_instance), 22 frame_tree_node_(frame_tree_node) { 23 GetProcess()->AddRoute(routing_id_, this); 24 25 if (!frame_tree_node_->IsMainFrame() && 26 frame_tree_node_->parent() 27 ->render_manager() 28 ->current_frame_host() 29 ->GetSiteInstance() == site_instance) { 30 // The RenderFrameHost navigating cross-process is destroyed and a proxy for 31 // it is created in the parent's process. CrossProcessFrameConnector 32 // initialization only needs to happen on an initial cross-process 33 // navigation, when the RenderFrameHost leaves the same process as its 34 // parent. The same CrossProcessFrameConnector is used for subsequent cross- 35 // process navigations, but it will be destroyed if the frame is 36 // navigated back to the same SiteInstance as its parent. 37 cross_process_frame_connector_.reset(new CrossProcessFrameConnector(this)); 38 } 39 } 40 41 RenderFrameProxyHost::~RenderFrameProxyHost() { 42 if (GetProcess()->HasConnection()) 43 Send(new FrameMsg_DeleteProxy(routing_id_)); 44 45 GetProcess()->RemoveRoute(routing_id_); 46 } 47 48 void RenderFrameProxyHost::SetChildRWHView(RenderWidgetHostView* view) { 49 cross_process_frame_connector_->set_view( 50 static_cast<RenderWidgetHostViewChildFrame*>(view)); 51 } 52 53 RenderViewHostImpl* RenderFrameProxyHost::GetRenderViewHost() { 54 if (render_frame_host_.get()) 55 return render_frame_host_->render_view_host(); 56 return NULL; 57 } 58 59 scoped_ptr<RenderFrameHostImpl> RenderFrameProxyHost::PassFrameHostOwnership() { 60 render_frame_host_->set_render_frame_proxy_host(NULL); 61 return render_frame_host_.Pass(); 62 } 63 64 bool RenderFrameProxyHost::Send(IPC::Message *msg) { 65 // TODO(nasko): For now, RenderFrameHost uses this object to send IPC messages 66 // while swapped out. This can be removed once we don't have a swapped out 67 // state on RenderFrameHosts. See https://crbug.com/357747. 68 msg->set_routing_id(routing_id_); 69 return GetProcess()->Send(msg); 70 } 71 72 bool RenderFrameProxyHost::OnMessageReceived(const IPC::Message& msg) { 73 if (cross_process_frame_connector_.get() && 74 cross_process_frame_connector_->OnMessageReceived(msg)) 75 return true; 76 77 // TODO(nasko): This can be removed once we don't have a swapped out state on 78 // RenderFrameHosts. See https://crbug.com/357747. 79 if (render_frame_host_.get()) 80 return render_frame_host_->OnMessageReceived(msg); 81 82 return false; 83 } 84 85 } // namespace content 86