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