| 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/renderer_host/render_frame_host_impl.h" | 5 #include "content/browser/renderer_host/render_frame_host_impl.h" |
| 6 | 6 |
| 7 #include "base/containers/hash_tables.h" |
| 8 #include "base/lazy_instance.h" |
| 7 #include "content/browser/renderer_host/render_view_host_impl.h" | 9 #include "content/browser/renderer_host/render_view_host_impl.h" |
| 8 | 10 |
| 9 namespace content { | 11 namespace content { |
| 10 | 12 |
| 13 // The (process id, routing id) pair that identifies one RenderFrame. |
| 14 typedef std::pair<int32, int32> RenderFrameHostID; |
| 15 typedef base::hash_map<RenderFrameHostID, RenderFrameHostImpl*> |
| 16 RoutingIDFrameMap; |
| 17 static base::LazyInstance<RoutingIDFrameMap> g_routing_id_frame_map = |
| 18 LAZY_INSTANCE_INITIALIZER; |
| 19 |
| 20 // static |
| 21 RenderFrameHostImpl* RenderFrameHostImpl::FromID( |
| 22 int process_id, int routing_id) { |
| 23 RoutingIDFrameMap* frames = g_routing_id_frame_map.Pointer(); |
| 24 RoutingIDFrameMap::iterator it = frames->find( |
| 25 RenderFrameHostID(process_id, routing_id)); |
| 26 return it == frames->end() ? NULL : it->second; |
| 27 } |
| 28 |
| 11 RenderFrameHostImpl::RenderFrameHostImpl( | 29 RenderFrameHostImpl::RenderFrameHostImpl( |
| 12 RenderViewHostImpl* render_view_host, | 30 RenderViewHostImpl* render_view_host, |
| 13 int routing_id, | 31 int routing_id, |
| 14 bool swapped_out) | 32 bool is_swapped_out) |
| 15 : render_view_host_(render_view_host), | 33 : render_view_host_(render_view_host), |
| 16 routing_id_(routing_id) { | 34 routing_id_(routing_id), |
| 35 is_swapped_out_(is_swapped_out) { |
| 36 GetProcess()->AddRoute(routing_id_, this); |
| 37 g_routing_id_frame_map.Get().insert(std::make_pair( |
| 38 RenderFrameHostID(GetProcess()->GetID(), routing_id_), |
| 39 this)); |
| 17 } | 40 } |
| 18 | 41 |
| 19 RenderFrameHostImpl::~RenderFrameHostImpl() { | 42 RenderFrameHostImpl::~RenderFrameHostImpl() { |
| 43 GetProcess()->RemoveRoute(routing_id_); |
| 44 g_routing_id_frame_map.Get().erase( |
| 45 RenderFrameHostID(GetProcess()->GetID(), routing_id_)); |
| 46 |
| 20 } | 47 } |
| 21 | 48 |
| 22 bool RenderFrameHostImpl::Send(IPC::Message* message) { | 49 bool RenderFrameHostImpl::Send(IPC::Message* message) { |
| 23 // Use the RenderViewHost object to send the message. It inherits it from | 50 return GetProcess()->Send(message); |
| 24 // RenderWidgetHost, which ultimately uses the current process's |Send|. | |
| 25 return render_view_host_->Send(message); | |
| 26 } | 51 } |
| 27 | 52 |
| 28 bool RenderFrameHostImpl::OnMessageReceived(const IPC::Message &msg) { | 53 bool RenderFrameHostImpl::OnMessageReceived(const IPC::Message &msg) { |
| 29 // Pass the message up to the RenderViewHost, until we have enough | 54 return false; |
| 30 // infrastructure to start processing messages in this object. | 55 } |
| 31 return render_view_host_->OnMessageReceived(msg); | 56 |
| 57 void RenderFrameHostImpl::Init() { |
| 58 GetProcess()->ResumeRequestsForView(routing_id()); |
| 59 } |
| 60 |
| 61 RenderProcessHost* RenderFrameHostImpl::GetProcess() const { |
| 62 // TODO(ajwong): This should return its own process once cross-process |
| 63 // subframe navigations are supported. |
| 64 return render_view_host_->GetProcess(); |
| 32 } | 65 } |
| 33 | 66 |
| 34 } // namespace content | 67 } // namespace content |
| OLD | NEW |