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