| 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" | 7 #include "base/containers/hash_tables.h" |
| 8 #include "base/lazy_instance.h" | 8 #include "base/lazy_instance.h" |
| 9 #include "content/browser/renderer_host/frame_tree.h" |
| 9 #include "content/browser/renderer_host/render_view_host_impl.h" | 10 #include "content/browser/renderer_host/render_view_host_impl.h" |
| 11 #include "content/common/frame_messages.h" |
| 12 #include "content/public/browser/browser_thread.h" |
| 13 #include "content/public/browser/render_process_host.h" |
| 10 | 14 |
| 11 namespace content { | 15 namespace content { |
| 12 | 16 |
| 13 // The (process id, routing id) pair that identifies one RenderFrame. | 17 // The (process id, routing id) pair that identifies one RenderFrame. |
| 14 typedef std::pair<int32, int32> RenderFrameHostID; | 18 typedef std::pair<int32, int32> RenderFrameHostID; |
| 15 typedef base::hash_map<RenderFrameHostID, RenderFrameHostImpl*> | 19 typedef base::hash_map<RenderFrameHostID, RenderFrameHostImpl*> |
| 16 RoutingIDFrameMap; | 20 RoutingIDFrameMap; |
| 17 static base::LazyInstance<RoutingIDFrameMap> g_routing_id_frame_map = | 21 static base::LazyInstance<RoutingIDFrameMap> g_routing_id_frame_map = |
| 18 LAZY_INSTANCE_INITIALIZER; | 22 LAZY_INSTANCE_INITIALIZER; |
| 19 | 23 |
| 20 // static | 24 // static |
| 21 RenderFrameHostImpl* RenderFrameHostImpl::FromID( | 25 RenderFrameHostImpl* RenderFrameHostImpl::FromID( |
| 22 int process_id, int routing_id) { | 26 int process_id, int routing_id) { |
| 23 RoutingIDFrameMap* frames = g_routing_id_frame_map.Pointer(); | 27 RoutingIDFrameMap* frames = g_routing_id_frame_map.Pointer(); |
| 24 RoutingIDFrameMap::iterator it = frames->find( | 28 RoutingIDFrameMap::iterator it = frames->find( |
| 25 RenderFrameHostID(process_id, routing_id)); | 29 RenderFrameHostID(process_id, routing_id)); |
| 26 return it == frames->end() ? NULL : it->second; | 30 return it == frames->end() ? NULL : it->second; |
| 27 } | 31 } |
| 28 | 32 |
| 29 RenderFrameHostImpl::RenderFrameHostImpl( | 33 RenderFrameHostImpl::RenderFrameHostImpl( |
| 30 RenderViewHostImpl* render_view_host, | 34 RenderViewHostImpl* render_view_host, |
| 35 FrameTree* frame_tree, |
| 31 int routing_id, | 36 int routing_id, |
| 32 bool is_swapped_out) | 37 bool is_swapped_out) |
| 33 : render_view_host_(render_view_host), | 38 : render_view_host_(render_view_host), |
| 39 frame_tree_(frame_tree), |
| 34 routing_id_(routing_id), | 40 routing_id_(routing_id), |
| 35 is_swapped_out_(is_swapped_out) { | 41 is_swapped_out_(is_swapped_out) { |
| 36 GetProcess()->AddRoute(routing_id_, this); | 42 GetProcess()->AddRoute(routing_id_, this); |
| 37 g_routing_id_frame_map.Get().insert(std::make_pair( | 43 g_routing_id_frame_map.Get().insert(std::make_pair( |
| 38 RenderFrameHostID(GetProcess()->GetID(), routing_id_), | 44 RenderFrameHostID(GetProcess()->GetID(), routing_id_), |
| 39 this)); | 45 this)); |
| 40 } | 46 } |
| 41 | 47 |
| 42 RenderFrameHostImpl::~RenderFrameHostImpl() { | 48 RenderFrameHostImpl::~RenderFrameHostImpl() { |
| 43 GetProcess()->RemoveRoute(routing_id_); | 49 GetProcess()->RemoveRoute(routing_id_); |
| 44 g_routing_id_frame_map.Get().erase( | 50 g_routing_id_frame_map.Get().erase( |
| 45 RenderFrameHostID(GetProcess()->GetID(), routing_id_)); | 51 RenderFrameHostID(GetProcess()->GetID(), routing_id_)); |
| 46 | 52 |
| 47 } | 53 } |
| 48 | 54 |
| 49 bool RenderFrameHostImpl::Send(IPC::Message* message) { | 55 bool RenderFrameHostImpl::Send(IPC::Message* message) { |
| 50 return GetProcess()->Send(message); | 56 return GetProcess()->Send(message); |
| 51 } | 57 } |
| 52 | 58 |
| 53 bool RenderFrameHostImpl::OnMessageReceived(const IPC::Message &msg) { | 59 bool RenderFrameHostImpl::OnMessageReceived(const IPC::Message &msg) { |
| 54 return false; | 60 bool handled = true; |
| 61 bool msg_is_ok = true; |
| 62 IPC_BEGIN_MESSAGE_MAP_EX(RenderFrameHostImpl, msg, msg_is_ok) |
| 63 IPC_MESSAGE_HANDLER(FrameHostMsg_Detach, OnDetach) |
| 64 IPC_END_MESSAGE_MAP_EX() |
| 65 |
| 66 return handled; |
| 55 } | 67 } |
| 56 | 68 |
| 57 void RenderFrameHostImpl::Init() { | 69 void RenderFrameHostImpl::Init() { |
| 58 GetProcess()->ResumeRequestsForView(routing_id()); | 70 GetProcess()->ResumeRequestsForView(routing_id()); |
| 59 } | 71 } |
| 60 | 72 |
| 61 RenderProcessHost* RenderFrameHostImpl::GetProcess() const { | 73 RenderProcessHost* RenderFrameHostImpl::GetProcess() const { |
| 62 // TODO(ajwong): This should return its own process once cross-process | 74 // TODO(nasko): This should return its own process, once we have working |
| 63 // subframe navigations are supported. | 75 // cross-process navigation for subframes. |
| 64 return render_view_host_->GetProcess(); | 76 return render_view_host_->GetProcess(); |
| 65 } | 77 } |
| 66 | 78 |
| 79 void RenderFrameHostImpl::OnCreateChildFrame(int new_frame_routing_id, |
| 80 int64 parent_frame_id, |
| 81 int64 frame_id, |
| 82 const std::string& frame_name) { |
| 83 frame_tree_->AddFrame(new_frame_routing_id, parent_frame_id, frame_id, |
| 84 frame_name); |
| 85 } |
| 86 |
| 87 void RenderFrameHostImpl::OnDetach(int64 parent_frame_id, int64 frame_id) { |
| 88 frame_tree_->RemoveFrame(parent_frame_id, frame_id); |
| 89 } |
| 90 |
| 67 } // namespace content | 91 } // namespace content |
| OLD | NEW |