| // Copyright 2013 The Chromium Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| |
| #include "content/browser/renderer_host/render_frame_host_impl.h" |
| |
| #include "base/containers/hash_tables.h" |
| #include "base/lazy_instance.h" |
| #include "content/browser/renderer_host/render_view_host_impl.h" |
| |
| namespace content { |
| |
| // The (process id, routing id) pair that identifies one RenderFrame. |
| typedef std::pair<int32, int32> RenderFrameHostID; |
| typedef base::hash_map<RenderFrameHostID, RenderFrameHostImpl*> |
| RoutingIDFrameMap; |
| static base::LazyInstance<RoutingIDFrameMap> g_routing_id_frame_map = |
| LAZY_INSTANCE_INITIALIZER; |
| |
| // static |
| RenderFrameHostImpl* RenderFrameHostImpl::FromID( |
| int process_id, int routing_id) { |
| RoutingIDFrameMap* frames = g_routing_id_frame_map.Pointer(); |
| RoutingIDFrameMap::iterator it = frames->find( |
| RenderFrameHostID(process_id, routing_id)); |
| return it == frames->end() ? NULL : it->second; |
| } |
| |
| RenderFrameHostImpl::RenderFrameHostImpl( |
| RenderViewHostImpl* render_view_host, |
| int routing_id, |
| bool is_swapped_out) |
| : render_view_host_(render_view_host), |
| routing_id_(routing_id), |
| is_swapped_out_(is_swapped_out) { |
| GetProcess()->AddRoute(routing_id_, this); |
| g_routing_id_frame_map.Get().insert(std::make_pair( |
| RenderFrameHostID(GetProcess()->GetID(), routing_id_), |
| this)); |
| } |
| |
| RenderFrameHostImpl::~RenderFrameHostImpl() { |
| GetProcess()->RemoveRoute(routing_id_); |
| g_routing_id_frame_map.Get().erase( |
| RenderFrameHostID(GetProcess()->GetID(), routing_id_)); |
| |
| } |
| |
| bool RenderFrameHostImpl::Send(IPC::Message* message) { |
| return GetProcess()->Send(message); |
| } |
| |
| bool RenderFrameHostImpl::OnMessageReceived(const IPC::Message &msg) { |
| return false; |
| } |
| |
| void RenderFrameHostImpl::Init() { |
| GetProcess()->ResumeRequestsForView(routing_id()); |
| } |
| |
| RenderProcessHost* RenderFrameHostImpl::GetProcess() const { |
| // TODO(ajwong): This should return its own process once cross-process |
| // subframe navigations are supported. |
| return render_view_host_->GetProcess(); |
| } |
| |
| } // namespace content |