OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/frame_host/render_frame_proxy_host.h" | 5 #include "content/browser/frame_host/render_frame_proxy_host.h" |
6 | 6 |
7 #include "base/lazy_instance.h" | |
8 #include "content/browser/frame_host/cross_process_frame_connector.h" | 7 #include "content/browser/frame_host/cross_process_frame_connector.h" |
9 #include "content/browser/frame_host/frame_tree.h" | 8 #include "content/browser/frame_host/frame_tree.h" |
10 #include "content/browser/frame_host/frame_tree_node.h" | 9 #include "content/browser/frame_host/frame_tree_node.h" |
11 #include "content/browser/frame_host/render_frame_host_impl.h" | 10 #include "content/browser/frame_host/render_frame_host_impl.h" |
12 #include "content/browser/frame_host/render_widget_host_view_child_frame.h" | 11 #include "content/browser/frame_host/render_widget_host_view_child_frame.h" |
13 #include "content/browser/renderer_host/render_view_host_impl.h" | 12 #include "content/browser/renderer_host/render_view_host_impl.h" |
14 #include "content/browser/renderer_host/render_widget_host_view_base.h" | 13 #include "content/browser/renderer_host/render_widget_host_view_base.h" |
15 #include "content/browser/site_instance_impl.h" | 14 #include "content/browser/site_instance_impl.h" |
16 #include "content/common/frame_messages.h" | 15 #include "content/common/frame_messages.h" |
17 #include "content/public/browser/browser_thread.h" | |
18 #include "ipc/ipc_message.h" | 16 #include "ipc/ipc_message.h" |
19 | 17 |
20 namespace content { | 18 namespace content { |
21 | 19 |
22 namespace { | |
23 | |
24 // The (process id, routing id) pair that identifies one RenderFrameProxy. | |
25 typedef std::pair<int32, int32> RenderFrameProxyHostID; | |
26 typedef base::hash_map<RenderFrameProxyHostID, RenderFrameProxyHost*> | |
27 RoutingIDFrameProxyMap; | |
28 base::LazyInstance<RoutingIDFrameProxyMap> g_routing_id_frame_proxy_map = | |
29 LAZY_INSTANCE_INITIALIZER; | |
30 | |
31 } | |
32 | |
33 // static | |
34 RenderFrameProxyHost* RenderFrameProxyHost::FromID(int process_id, | |
35 int routing_id) { | |
36 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
37 RoutingIDFrameProxyMap* frames = g_routing_id_frame_proxy_map.Pointer(); | |
38 RoutingIDFrameProxyMap::iterator it = frames->find( | |
39 RenderFrameProxyHostID(process_id, routing_id)); | |
40 return it == frames->end() ? NULL : it->second; | |
41 } | |
42 | |
43 RenderFrameProxyHost::RenderFrameProxyHost(SiteInstance* site_instance, | 20 RenderFrameProxyHost::RenderFrameProxyHost(SiteInstance* site_instance, |
44 FrameTreeNode* frame_tree_node) | 21 FrameTreeNode* frame_tree_node) |
45 : routing_id_(site_instance->GetProcess()->GetNextRoutingID()), | 22 : routing_id_(site_instance->GetProcess()->GetNextRoutingID()), |
46 site_instance_(site_instance), | 23 site_instance_(site_instance), |
47 frame_tree_node_(frame_tree_node) { | 24 frame_tree_node_(frame_tree_node) { |
48 GetProcess()->AddRoute(routing_id_, this); | 25 GetProcess()->AddRoute(routing_id_, this); |
49 CHECK(g_routing_id_frame_proxy_map.Get().insert( | |
50 std::make_pair( | |
51 RenderFrameProxyHostID(GetProcess()->GetID(), routing_id_), | |
52 this)).second); | |
53 | 26 |
54 if (!frame_tree_node_->IsMainFrame() && | 27 if (!frame_tree_node_->IsMainFrame() && |
55 frame_tree_node_->parent() | 28 frame_tree_node_->parent() |
56 ->render_manager() | 29 ->render_manager() |
57 ->current_frame_host() | 30 ->current_frame_host() |
58 ->GetSiteInstance() == site_instance) { | 31 ->GetSiteInstance() == site_instance) { |
59 // The RenderFrameHost navigating cross-process is destroyed and a proxy for | 32 // The RenderFrameHost navigating cross-process is destroyed and a proxy for |
60 // it is created in the parent's process. CrossProcessFrameConnector | 33 // it is created in the parent's process. CrossProcessFrameConnector |
61 // initialization only needs to happen on an initial cross-process | 34 // initialization only needs to happen on an initial cross-process |
62 // navigation, when the RenderFrameHost leaves the same process as its | 35 // navigation, when the RenderFrameHost leaves the same process as its |
63 // parent. The same CrossProcessFrameConnector is used for subsequent cross- | 36 // parent. The same CrossProcessFrameConnector is used for subsequent cross- |
64 // process navigations, but it will be destroyed if the frame is | 37 // process navigations, but it will be destroyed if the frame is |
65 // navigated back to the same SiteInstance as its parent. | 38 // navigated back to the same SiteInstance as its parent. |
66 cross_process_frame_connector_.reset(new CrossProcessFrameConnector(this)); | 39 cross_process_frame_connector_.reset(new CrossProcessFrameConnector(this)); |
67 } | 40 } |
68 } | 41 } |
69 | 42 |
70 RenderFrameProxyHost::~RenderFrameProxyHost() { | 43 RenderFrameProxyHost::~RenderFrameProxyHost() { |
71 if (GetProcess()->HasConnection()) | 44 if (GetProcess()->HasConnection()) |
72 Send(new FrameMsg_DeleteProxy(routing_id_)); | 45 Send(new FrameMsg_DeleteProxy(routing_id_)); |
73 | 46 |
74 GetProcess()->RemoveRoute(routing_id_); | 47 GetProcess()->RemoveRoute(routing_id_); |
75 g_routing_id_frame_proxy_map.Get().erase( | |
76 RenderFrameProxyHostID(GetProcess()->GetID(), routing_id_)); | |
77 } | 48 } |
78 | 49 |
79 void RenderFrameProxyHost::SetChildRWHView(RenderWidgetHostView* view) { | 50 void RenderFrameProxyHost::SetChildRWHView(RenderWidgetHostView* view) { |
80 cross_process_frame_connector_->set_view( | 51 cross_process_frame_connector_->set_view( |
81 static_cast<RenderWidgetHostViewChildFrame*>(view)); | 52 static_cast<RenderWidgetHostViewChildFrame*>(view)); |
82 } | 53 } |
83 | 54 |
84 RenderViewHostImpl* RenderFrameProxyHost::GetRenderViewHost() { | 55 RenderViewHostImpl* RenderFrameProxyHost::GetRenderViewHost() { |
85 return frame_tree_node_->frame_tree()->GetRenderViewHost( | 56 return frame_tree_node_->frame_tree()->GetRenderViewHost( |
86 site_instance_.get()); | 57 site_instance_.get()); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 ->GetRenderViewHost(site_instance_.get()) | 107 ->GetRenderViewHost(site_instance_.get()) |
137 ->GetRoutingID())); | 108 ->GetRoutingID())); |
138 | 109 |
139 return true; | 110 return true; |
140 } | 111 } |
141 | 112 |
142 void RenderFrameProxyHost::DisownOpener() { | 113 void RenderFrameProxyHost::DisownOpener() { |
143 Send(new FrameMsg_DisownOpener(GetRoutingID())); | 114 Send(new FrameMsg_DisownOpener(GetRoutingID())); |
144 } | 115 } |
145 | 116 |
| 117 |
146 } // namespace content | 118 } // namespace content |
OLD | NEW |