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