Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(33)

Side by Side Diff: content/browser/frame_host/render_frame_host_manager.cc

Issue 1245903004: Switch RenderFrameHostManager to use RenderProcessHostObserver, remove NOTIFICATION_RENDERER_PROCES… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: comments Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/frame_host/render_frame_host_manager.h" 5 #include "content/browser/frame_host/render_frame_host_manager.h"
6 6
7 #include <algorithm>
7 #include <utility> 8 #include <utility>
8 9
9 #include "base/command_line.h" 10 #include "base/command_line.h"
10 #include "base/logging.h" 11 #include "base/logging.h"
11 #include "base/stl_util.h" 12 #include "base/stl_util.h"
12 #include "base/trace_event/trace_event.h" 13 #include "base/trace_event/trace_event.h"
13 #include "content/browser/child_process_security_policy_impl.h" 14 #include "content/browser/child_process_security_policy_impl.h"
14 #include "content/browser/devtools/render_frame_devtools_agent_host.h" 15 #include "content/browser/devtools/render_frame_devtools_agent_host.h"
15 #include "content/browser/frame_host/cross_site_transferring_request.h" 16 #include "content/browser/frame_host/cross_site_transferring_request.h"
16 #include "content/browser/frame_host/debug_urls.h" 17 #include "content/browser/frame_host/debug_urls.h"
17 #include "content/browser/frame_host/frame_navigation_entry.h" 18 #include "content/browser/frame_host/frame_navigation_entry.h"
18 #include "content/browser/frame_host/interstitial_page_impl.h" 19 #include "content/browser/frame_host/interstitial_page_impl.h"
19 #include "content/browser/frame_host/navigation_controller_impl.h" 20 #include "content/browser/frame_host/navigation_controller_impl.h"
20 #include "content/browser/frame_host/navigation_entry_impl.h" 21 #include "content/browser/frame_host/navigation_entry_impl.h"
21 #include "content/browser/frame_host/navigation_request.h" 22 #include "content/browser/frame_host/navigation_request.h"
22 #include "content/browser/frame_host/navigator.h" 23 #include "content/browser/frame_host/navigator.h"
23 #include "content/browser/frame_host/render_frame_host_factory.h" 24 #include "content/browser/frame_host/render_frame_host_factory.h"
24 #include "content/browser/frame_host/render_frame_host_impl.h" 25 #include "content/browser/frame_host/render_frame_host_impl.h"
25 #include "content/browser/frame_host/render_frame_proxy_host.h" 26 #include "content/browser/frame_host/render_frame_proxy_host.h"
26 #include "content/browser/renderer_host/render_process_host_impl.h" 27 #include "content/browser/renderer_host/render_process_host_impl.h"
27 #include "content/browser/renderer_host/render_view_host_factory.h" 28 #include "content/browser/renderer_host/render_view_host_factory.h"
28 #include "content/browser/renderer_host/render_view_host_impl.h" 29 #include "content/browser/renderer_host/render_view_host_impl.h"
29 #include "content/browser/site_instance_impl.h" 30 #include "content/browser/site_instance_impl.h"
30 #include "content/browser/webui/web_ui_controller_factory_registry.h" 31 #include "content/browser/webui/web_ui_controller_factory_registry.h"
31 #include "content/browser/webui/web_ui_impl.h" 32 #include "content/browser/webui/web_ui_impl.h"
32 #include "content/common/frame_messages.h" 33 #include "content/common/frame_messages.h"
33 #include "content/common/view_messages.h" 34 #include "content/common/view_messages.h"
34 #include "content/public/browser/content_browser_client.h" 35 #include "content/public/browser/content_browser_client.h"
35 #include "content/public/browser/notification_service.h" 36 #include "content/public/browser/render_process_host_observer.h"
36 #include "content/public/browser/notification_types.h"
37 #include "content/public/browser/render_widget_host_iterator.h" 37 #include "content/public/browser/render_widget_host_iterator.h"
38 #include "content/public/browser/render_widget_host_view.h" 38 #include "content/public/browser/render_widget_host_view.h"
39 #include "content/public/browser/user_metrics.h" 39 #include "content/public/browser/user_metrics.h"
40 #include "content/public/browser/web_ui_controller.h" 40 #include "content/public/browser/web_ui_controller.h"
41 #include "content/public/common/content_switches.h" 41 #include "content/public/common/content_switches.h"
42 #include "content/public/common/referrer.h" 42 #include "content/public/common/referrer.h"
43 #include "content/public/common/url_constants.h" 43 #include "content/public/common/url_constants.h"
44 44
45 namespace content { 45 namespace content {
46 46
47 // A helper class to hold all frame proxies and register as a
48 // RenderProcessHostObserver for them.
49 class RenderFrameHostManager::RenderFrameProxyHostMap
50 : public RenderProcessHostObserver {
51 public:
52 using MapType = base::hash_map<int32, RenderFrameProxyHost*>;
53
54 RenderFrameProxyHostMap(RenderFrameHostManager* manager);
55 ~RenderFrameProxyHostMap() override;
56
57 // Read-only access to the underlying map of site instance ID to
58 // RenderFrameProxyHosts.
59 MapType::const_iterator begin() const { return map_.begin(); }
60 MapType::const_iterator end() const { return map_.end(); }
61 bool empty() const { return map_.empty(); }
62
63 // Returns the proxy with the specified ID, or nullptr if there is no such
64 // one.
65 RenderFrameProxyHost* Get(int32 id);
66
67 // Adds the specified proxy with the specified ID. It is an error (and fatal)
68 // to add more than one proxy with the specified ID.
69 void Add(int32 id, scoped_ptr<RenderFrameProxyHost> proxy);
70
71 // Removes the proxy with the specified site instance ID.
72 void Remove(int32 id);
73
74 // Removes all proxies.
75 void Clear();
76
77 // RenderProcessHostObserver implementation.
78 void RenderProcessWillExit(RenderProcessHost* host) override;
79 void RenderProcessExited(RenderProcessHost* host,
80 base::TerminationStatus status,
81 int exit_code) override;
82
83 private:
84 RenderFrameHostManager* manager_;
85 MapType map_;
86 };
87
88 RenderFrameHostManager::RenderFrameProxyHostMap::RenderFrameProxyHostMap(
89 RenderFrameHostManager* manager)
90 : manager_(manager) {}
91
92 RenderFrameHostManager::RenderFrameProxyHostMap::~RenderFrameProxyHostMap() {
93 Clear();
94 }
95
96 RenderFrameProxyHost* RenderFrameHostManager::RenderFrameProxyHostMap::Get(
97 int32 id) {
98 auto it = map_.find(id);
99 if (it != map_.end())
100 return it->second;
101 return nullptr;
102 }
103
104 void RenderFrameHostManager::RenderFrameProxyHostMap::Add(
105 int32 id,
106 scoped_ptr<RenderFrameProxyHost> proxy) {
107 CHECK_EQ(0u, map_.count(id)) << "Inserting a duplicate item.";
108
109 // If this is the first proxy that has this process host, observe the
110 // process host.
111 RenderProcessHost* host = proxy->GetProcess();
112 size_t count =
113 std::count_if(begin(), end(), [host](MapType::value_type item) {
114 return item.second->GetProcess() == host;
115 });
116 if (count == 0)
117 host->AddObserver(this);
118
119 map_[id] = proxy.release();
120 }
121
122 void RenderFrameHostManager::RenderFrameProxyHostMap::Remove(int32 id) {
123 auto it = map_.find(id);
124 if (it == map_.end())
125 return;
126
127 // If this is the last proxy that has this process host, stop observing the
128 // process host.
129 RenderProcessHost* host = it->second->GetProcess();
130 size_t count =
131 std::count_if(begin(), end(), [host](MapType::value_type item) {
132 return item.second->GetProcess() == host;
133 });
134 if (count == 1)
135 host->RemoveObserver(this);
136
137 delete it->second;
138 map_.erase(it);
139 }
140
141 void RenderFrameHostManager::RenderFrameProxyHostMap::Clear() {
142 std::set<RenderProcessHost*> hosts;
143 for (const auto& pair : map_)
144 hosts.insert(pair.second->GetProcess());
145 for (auto host : hosts)
146 host->RemoveObserver(this);
147
148 STLDeleteValues(&map_);
149 }
150
151 void RenderFrameHostManager::RenderFrameProxyHostMap::RenderProcessWillExit(
152 RenderProcessHost* host) {
153 manager_->RendererProcessClosing(host);
154 }
155
156 void RenderFrameHostManager::RenderFrameProxyHostMap::RenderProcessExited(
157 RenderProcessHost* host,
158 base::TerminationStatus status,
159 int exit_code) {
160 manager_->RendererProcessClosing(host);
161 }
162
47 // static 163 // static
48 bool RenderFrameHostManager::ClearRFHsPendingShutdown(FrameTreeNode* node) { 164 bool RenderFrameHostManager::ClearRFHsPendingShutdown(FrameTreeNode* node) {
49 node->render_manager()->pending_delete_hosts_.clear(); 165 node->render_manager()->pending_delete_hosts_.clear();
50 return true; 166 return true;
51 } 167 }
52 168
53 // static 169 // static
54 bool RenderFrameHostManager::IsSwappedOutStateForbidden() { 170 bool RenderFrameHostManager::IsSwappedOutStateForbidden() {
55 return base::CommandLine::ForCurrentProcess()->HasSwitch( 171 return base::CommandLine::ForCurrentProcess()->HasSwitch(
56 switches::kSitePerProcess); 172 switches::kSitePerProcess);
57 } 173 }
58 174
59 RenderFrameHostManager::RenderFrameHostManager( 175 RenderFrameHostManager::RenderFrameHostManager(
60 FrameTreeNode* frame_tree_node, 176 FrameTreeNode* frame_tree_node,
61 RenderFrameHostDelegate* render_frame_delegate, 177 RenderFrameHostDelegate* render_frame_delegate,
62 RenderViewHostDelegate* render_view_delegate, 178 RenderViewHostDelegate* render_view_delegate,
63 RenderWidgetHostDelegate* render_widget_delegate, 179 RenderWidgetHostDelegate* render_widget_delegate,
64 Delegate* delegate) 180 Delegate* delegate)
65 : frame_tree_node_(frame_tree_node), 181 : frame_tree_node_(frame_tree_node),
66 delegate_(delegate), 182 delegate_(delegate),
67 render_frame_delegate_(render_frame_delegate), 183 render_frame_delegate_(render_frame_delegate),
68 render_view_delegate_(render_view_delegate), 184 render_view_delegate_(render_view_delegate),
69 render_widget_delegate_(render_widget_delegate), 185 render_widget_delegate_(render_widget_delegate),
186 proxy_hosts_(new RenderFrameProxyHostMap(this)),
70 interstitial_page_(nullptr), 187 interstitial_page_(nullptr),
71 should_reuse_web_ui_(false), 188 should_reuse_web_ui_(false),
72 weak_factory_(this) { 189 weak_factory_(this) {
73 DCHECK(frame_tree_node_); 190 DCHECK(frame_tree_node_);
74 } 191 }
75 192
76 RenderFrameHostManager::~RenderFrameHostManager() { 193 RenderFrameHostManager::~RenderFrameHostManager() {
77 if (pending_render_frame_host_) { 194 if (pending_render_frame_host_) {
78 scoped_ptr<RenderFrameHostImpl> relic = UnsetPendingRenderFrameHost(); 195 scoped_ptr<RenderFrameHostImpl> relic = UnsetPendingRenderFrameHost();
79 ShutdownProxiesIfLastActiveFrameInSiteInstance(relic.get()); 196 ShutdownProxiesIfLastActiveFrameInSiteInstance(relic.get());
80 } 197 }
81 198
82 if (speculative_render_frame_host_) { 199 if (speculative_render_frame_host_) {
83 scoped_ptr<RenderFrameHostImpl> relic = UnsetSpeculativeRenderFrameHost(); 200 scoped_ptr<RenderFrameHostImpl> relic = UnsetSpeculativeRenderFrameHost();
84 ShutdownProxiesIfLastActiveFrameInSiteInstance(relic.get()); 201 ShutdownProxiesIfLastActiveFrameInSiteInstance(relic.get());
85 } 202 }
86 203
87 ShutdownProxiesIfLastActiveFrameInSiteInstance(render_frame_host_.get()); 204 ShutdownProxiesIfLastActiveFrameInSiteInstance(render_frame_host_.get());
88 205
89 // Delete any RenderFrameProxyHosts and swapped out RenderFrameHosts. 206 // Delete any RenderFrameProxyHosts and swapped out RenderFrameHosts.
90 // It is important to delete those prior to deleting the current 207 // It is important to delete those prior to deleting the current
91 // RenderFrameHost, since the CrossProcessFrameConnector (owned by 208 // RenderFrameHost, since the CrossProcessFrameConnector (owned by
92 // RenderFrameProxyHost) points to the RenderWidgetHostView associated with 209 // RenderFrameProxyHost) points to the RenderWidgetHostView associated with
93 // the current RenderFrameHost and uses it during its destructor. 210 // the current RenderFrameHost and uses it during its destructor.
94 STLDeleteValues(&proxy_hosts_); 211 ResetProxyHosts();
95 212
96 // Release the WebUI prior to resetting the current RenderFrameHost, as the 213 // Release the WebUI prior to resetting the current RenderFrameHost, as the
97 // WebUI accesses the RenderFrameHost during cleanup. 214 // WebUI accesses the RenderFrameHost during cleanup.
98 web_ui_.reset(); 215 web_ui_.reset();
99 216
100 // We should always have a current RenderFrameHost except in some tests. 217 // We should always have a current RenderFrameHost except in some tests.
101 SetRenderFrameHost(scoped_ptr<RenderFrameHostImpl>()); 218 SetRenderFrameHost(scoped_ptr<RenderFrameHostImpl>());
102 } 219 }
103 220
104 void RenderFrameHostManager::Init(BrowserContext* browser_context, 221 void RenderFrameHostManager::Init(BrowserContext* browser_context,
(...skipping 10 matching lines...) Expand all
115 SetRenderFrameHost(CreateRenderFrameHost(site_instance, view_routing_id, 232 SetRenderFrameHost(CreateRenderFrameHost(site_instance, view_routing_id,
116 frame_routing_id, flags)); 233 frame_routing_id, flags));
117 234
118 // Notify the delegate of the creation of the current RenderFrameHost. 235 // Notify the delegate of the creation of the current RenderFrameHost.
119 // Do this only for subframes, as the main frame case is taken care of by 236 // Do this only for subframes, as the main frame case is taken care of by
120 // WebContentsImpl::Init. 237 // WebContentsImpl::Init.
121 if (!frame_tree_node_->IsMainFrame()) { 238 if (!frame_tree_node_->IsMainFrame()) {
122 delegate_->NotifySwappedFromRenderManager( 239 delegate_->NotifySwappedFromRenderManager(
123 nullptr, render_frame_host_.get(), false); 240 nullptr, render_frame_host_.get(), false);
124 } 241 }
125
126 // Keep track of renderer processes as they start to shut down or are
127 // crashed/killed.
128 registrar_.Add(this, NOTIFICATION_RENDERER_PROCESS_CLOSED,
129 NotificationService::AllSources());
130 registrar_.Add(this, NOTIFICATION_RENDERER_PROCESS_CLOSING,
131 NotificationService::AllSources());
132 } 242 }
133 243
134 RenderViewHostImpl* RenderFrameHostManager::current_host() const { 244 RenderViewHostImpl* RenderFrameHostManager::current_host() const {
135 if (!render_frame_host_) 245 if (!render_frame_host_)
136 return NULL; 246 return nullptr;
137 return render_frame_host_->render_view_host(); 247 return render_frame_host_->render_view_host();
138 } 248 }
139 249
140 RenderViewHostImpl* RenderFrameHostManager::pending_render_view_host() const { 250 RenderViewHostImpl* RenderFrameHostManager::pending_render_view_host() const {
141 if (!pending_render_frame_host_) 251 if (!pending_render_frame_host_)
142 return NULL; 252 return nullptr;
143 return pending_render_frame_host_->render_view_host(); 253 return pending_render_frame_host_->render_view_host();
144 } 254 }
145 255
146 RenderWidgetHostView* RenderFrameHostManager::GetRenderWidgetHostView() const { 256 RenderWidgetHostView* RenderFrameHostManager::GetRenderWidgetHostView() const {
147 if (interstitial_page_) 257 if (interstitial_page_)
148 return interstitial_page_->GetView(); 258 return interstitial_page_->GetView();
149 if (render_frame_host_) 259 if (render_frame_host_)
150 return render_frame_host_->GetView(); 260 return render_frame_host_->GetView();
151 return nullptr; 261 return nullptr;
152 } 262 }
(...skipping 15 matching lines...) Expand all
168 FrameTreeNode* outer_contents_frame_tree_node = 278 FrameTreeNode* outer_contents_frame_tree_node =
169 FrameTreeNode::GloballyFindByID( 279 FrameTreeNode::GloballyFindByID(
170 delegate_->GetOuterDelegateFrameTreeNodeID()); 280 delegate_->GetOuterDelegateFrameTreeNodeID());
171 return outer_contents_frame_tree_node->parent() 281 return outer_contents_frame_tree_node->parent()
172 ->current_frame_host() 282 ->current_frame_host()
173 ->render_view_host(); 283 ->render_view_host();
174 } 284 }
175 285
176 RenderFrameProxyHost* RenderFrameHostManager::GetProxyToParent() { 286 RenderFrameProxyHost* RenderFrameHostManager::GetProxyToParent() {
177 if (frame_tree_node_->IsMainFrame()) 287 if (frame_tree_node_->IsMainFrame())
178 return NULL; 288 return nullptr;
179 289
180 RenderFrameProxyHostMap::iterator iter = 290 return proxy_hosts_->Get(frame_tree_node_->parent()
181 proxy_hosts_.find(frame_tree_node_->parent() 291 ->render_manager()
182 ->render_manager() 292 ->current_frame_host()
183 ->current_frame_host() 293 ->GetSiteInstance()
184 ->GetSiteInstance() 294 ->GetId());
185 ->GetId());
186 if (iter == proxy_hosts_.end())
187 return NULL;
188
189 return iter->second;
190 } 295 }
191 296
192 RenderFrameProxyHost* RenderFrameHostManager::GetProxyToOuterDelegate() { 297 RenderFrameProxyHost* RenderFrameHostManager::GetProxyToOuterDelegate() {
193 int outer_contents_frame_tree_node_id = 298 int outer_contents_frame_tree_node_id =
194 delegate_->GetOuterDelegateFrameTreeNodeID(); 299 delegate_->GetOuterDelegateFrameTreeNodeID();
195 FrameTreeNode* outer_contents_frame_tree_node = 300 FrameTreeNode* outer_contents_frame_tree_node =
196 FrameTreeNode::GloballyFindByID(outer_contents_frame_tree_node_id); 301 FrameTreeNode::GloballyFindByID(outer_contents_frame_tree_node_id);
197 if (!outer_contents_frame_tree_node || 302 if (!outer_contents_frame_tree_node ||
198 !outer_contents_frame_tree_node->parent()) { 303 !outer_contents_frame_tree_node->parent()) {
199 return nullptr; 304 return nullptr;
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 // Create a pending RenderFrameHost to use for the navigation. 348 // Create a pending RenderFrameHost to use for the navigation.
244 RenderFrameHostImpl* dest_render_frame_host = UpdateStateForNavigate( 349 RenderFrameHostImpl* dest_render_frame_host = UpdateStateForNavigate(
245 dest_url, 350 dest_url,
246 // TODO(creis): Move source_site_instance to FNE. 351 // TODO(creis): Move source_site_instance to FNE.
247 entry.source_site_instance(), frame_entry.site_instance(), 352 entry.source_site_instance(), frame_entry.site_instance(),
248 entry.GetTransitionType(), 353 entry.GetTransitionType(),
249 entry.restore_type() != NavigationEntryImpl::RESTORE_NONE, 354 entry.restore_type() != NavigationEntryImpl::RESTORE_NONE,
250 entry.IsViewSourceMode(), entry.transferred_global_request_id(), 355 entry.IsViewSourceMode(), entry.transferred_global_request_id(),
251 entry.bindings()); 356 entry.bindings());
252 if (!dest_render_frame_host) 357 if (!dest_render_frame_host)
253 return NULL; // We weren't able to create a pending render frame host. 358 return nullptr; // We weren't able to create a pending render frame host.
254 359
255 // If the current render_frame_host_ isn't live, we should create it so 360 // If the current render_frame_host_ isn't live, we should create it so
256 // that we don't show a sad tab while the dest_render_frame_host fetches 361 // that we don't show a sad tab while the dest_render_frame_host fetches
257 // its first page. (Bug 1145340) 362 // its first page. (Bug 1145340)
258 if (dest_render_frame_host != render_frame_host_ && 363 if (dest_render_frame_host != render_frame_host_ &&
259 !render_frame_host_->IsRenderFrameLive()) { 364 !render_frame_host_->IsRenderFrameLive()) {
260 // Note: we don't call InitRenderView here because we are navigating away 365 // Note: we don't call InitRenderView here because we are navigating away
261 // soon anyway, and we don't have the NavigationEntry for this host. 366 // soon anyway, and we don't have the NavigationEntry for this host.
262 delegate_->CreateRenderViewForRenderManager( 367 delegate_->CreateRenderViewForRenderManager(
263 render_frame_host_->render_view_host(), MSG_ROUTING_NONE, 368 render_frame_host_->render_view_host(), MSG_ROUTING_NONE,
(...skipping 11 matching lines...) Expand all
275 // RFH's ServiceRegistry to be initialized (e.g., if the site is a WebUI 380 // RFH's ServiceRegistry to be initialized (e.g., if the site is a WebUI
276 // site that is handled via Mojo, then Mojo WebUI code in //chrome will 381 // site that is handled via Mojo, then Mojo WebUI code in //chrome will
277 // add a service to this RFH's ServiceRegistry). 382 // add a service to this RFH's ServiceRegistry).
278 dest_render_frame_host->SetUpMojoIfNeeded(); 383 dest_render_frame_host->SetUpMojoIfNeeded();
279 384
280 // Recreate the opener chain. 385 // Recreate the opener chain.
281 CreateOpenerProxiesIfNeeded(dest_render_frame_host->GetSiteInstance()); 386 CreateOpenerProxiesIfNeeded(dest_render_frame_host->GetSiteInstance());
282 if (!InitRenderView(dest_render_frame_host->render_view_host(), 387 if (!InitRenderView(dest_render_frame_host->render_view_host(),
283 MSG_ROUTING_NONE, 388 MSG_ROUTING_NONE,
284 frame_tree_node_->IsMainFrame())) 389 frame_tree_node_->IsMainFrame()))
285 return NULL; 390 return nullptr;
286 391
287 // Now that we've created a new renderer, be sure to hide it if it isn't 392 // Now that we've created a new renderer, be sure to hide it if it isn't
288 // our primary one. Otherwise, we might crash if we try to call Show() 393 // our primary one. Otherwise, we might crash if we try to call Show()
289 // on it later. 394 // on it later.
290 if (dest_render_frame_host != render_frame_host_) { 395 if (dest_render_frame_host != render_frame_host_) {
291 if (dest_render_frame_host->GetView()) 396 if (dest_render_frame_host->GetView())
292 dest_render_frame_host->GetView()->Hide(); 397 dest_render_frame_host->GetView()->Hide();
293 } else { 398 } else {
294 // TODO(nasko): This is a very ugly hack. The Chrome extensions process 399 // TODO(nasko): This is a very ugly hack. The Chrome extensions process
295 // manager still uses NotificationService and expects to see a 400 // manager still uses NotificationService and expects to see a
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
534 } else { 639 } else {
535 // No one else should be sending us DidNavigate in this state. 640 // No one else should be sending us DidNavigate in this state.
536 DCHECK(false); 641 DCHECK(false);
537 } 642 }
538 } 643 }
539 644
540 void RenderFrameHostManager::DidDisownOpener( 645 void RenderFrameHostManager::DidDisownOpener(
541 RenderFrameHost* render_frame_host) { 646 RenderFrameHost* render_frame_host) {
542 // Notify all RenderFrameHosts but the one that notified us. This is necessary 647 // Notify all RenderFrameHosts but the one that notified us. This is necessary
543 // in case a process swap has occurred while the message was in flight. 648 // in case a process swap has occurred while the message was in flight.
544 for (RenderFrameProxyHostMap::iterator iter = proxy_hosts_.begin(); 649 for (const auto& pair : *proxy_hosts_) {
545 iter != proxy_hosts_.end(); 650 DCHECK_NE(pair.second->GetSiteInstance(),
546 ++iter) {
547 DCHECK_NE(iter->second->GetSiteInstance(),
548 current_frame_host()->GetSiteInstance()); 651 current_frame_host()->GetSiteInstance());
549 iter->second->DisownOpener(); 652 pair.second->DisownOpener();
550 } 653 }
551 654
552 if (render_frame_host_.get() != render_frame_host) 655 if (render_frame_host_.get() != render_frame_host)
553 render_frame_host_->DisownOpener(); 656 render_frame_host_->DisownOpener();
554 657
555 if (pending_render_frame_host_ && 658 if (pending_render_frame_host_ &&
556 pending_render_frame_host_.get() != render_frame_host) { 659 pending_render_frame_host_.get() != render_frame_host) {
557 pending_render_frame_host_->DisownOpener(); 660 pending_render_frame_host_->DisownOpener();
558 } 661 }
559 } 662 }
560 663
561 void RenderFrameHostManager::CommitPendingSandboxFlags() { 664 void RenderFrameHostManager::CommitPendingSandboxFlags() {
562 // Return early if there were no pending sandbox flags updates. 665 // Return early if there were no pending sandbox flags updates.
563 if (!frame_tree_node_->CommitPendingSandboxFlags()) 666 if (!frame_tree_node_->CommitPendingSandboxFlags())
564 return; 667 return;
565 668
566 // Sandbox flags updates can only happen when the frame has a parent. 669 // Sandbox flags updates can only happen when the frame has a parent.
567 CHECK(frame_tree_node_->parent()); 670 CHECK(frame_tree_node_->parent());
568 671
569 // Notify all of the frame's proxies about updated sandbox flags, excluding 672 // Notify all of the frame's proxies about updated sandbox flags, excluding
570 // the parent process since it already knows the latest flags. 673 // the parent process since it already knows the latest flags.
571 SiteInstance* parent_site_instance = 674 SiteInstance* parent_site_instance =
572 frame_tree_node_->parent()->current_frame_host()->GetSiteInstance(); 675 frame_tree_node_->parent()->current_frame_host()->GetSiteInstance();
573 for (const auto& pair : proxy_hosts_) { 676 for (const auto& pair : *proxy_hosts_) {
574 if (pair.second->GetSiteInstance() != parent_site_instance) { 677 if (pair.second->GetSiteInstance() != parent_site_instance) {
575 pair.second->Send(new FrameMsg_DidUpdateSandboxFlags( 678 pair.second->Send(new FrameMsg_DidUpdateSandboxFlags(
576 pair.second->GetRoutingID(), 679 pair.second->GetRoutingID(),
577 frame_tree_node_->current_replication_state().sandbox_flags)); 680 frame_tree_node_->current_replication_state().sandbox_flags));
578 } 681 }
579 } 682 }
580 } 683 }
581 684
582 void RenderFrameHostManager::RendererProcessClosing( 685 void RenderFrameHostManager::RendererProcessClosing(
583 RenderProcessHost* render_process_host) { 686 RenderProcessHost* render_process_host) {
584 // Remove any swapped out RVHs from this process, so that we don't try to 687 // Remove any swapped out RVHs from this process, so that we don't try to
585 // swap them back in while the process is exiting. Start by finding them, 688 // swap them back in while the process is exiting. Start by finding them,
586 // since there could be more than one. 689 // since there could be more than one.
587 std::list<int> ids_to_remove; 690 std::list<int> ids_to_remove;
588 // Do not remove proxies in the dead process that still have active frame 691 // Do not remove proxies in the dead process that still have active frame
589 // count though, we just reset them to be uninitialized. 692 // count though, we just reset them to be uninitialized.
590 std::list<int> ids_to_keep; 693 std::list<int> ids_to_keep;
591 for (RenderFrameProxyHostMap::iterator iter = proxy_hosts_.begin(); 694 for (const auto& pair : *proxy_hosts_) {
592 iter != proxy_hosts_.end(); 695 RenderFrameProxyHost* proxy = pair.second;
593 ++iter) {
594 RenderFrameProxyHost* proxy = iter->second;
595 if (proxy->GetProcess() != render_process_host) 696 if (proxy->GetProcess() != render_process_host)
596 continue; 697 continue;
597 698
598 if (static_cast<SiteInstanceImpl*>(proxy->GetSiteInstance()) 699 if (static_cast<SiteInstanceImpl*>(proxy->GetSiteInstance())
599 ->active_frame_count() >= 1U) { 700 ->active_frame_count() >= 1U) {
600 ids_to_keep.push_back(iter->first); 701 ids_to_keep.push_back(pair.first);
601 } else { 702 } else {
602 ids_to_remove.push_back(iter->first); 703 ids_to_remove.push_back(pair.first);
603 } 704 }
604 } 705 }
605 706
606 // Now delete them. 707 // Now delete them.
607 while (!ids_to_remove.empty()) { 708 while (!ids_to_remove.empty()) {
608 delete proxy_hosts_[ids_to_remove.back()]; 709 proxy_hosts_->Remove(ids_to_remove.back());
609 proxy_hosts_.erase(ids_to_remove.back());
610 ids_to_remove.pop_back(); 710 ids_to_remove.pop_back();
611 } 711 }
612 712
613 while (!ids_to_keep.empty()) { 713 while (!ids_to_keep.empty()) {
614 frame_tree_node_->frame_tree()->ForEach( 714 frame_tree_node_->frame_tree()->ForEach(
615 base::Bind( 715 base::Bind(
616 &RenderFrameHostManager::ResetProxiesInSiteInstance, 716 &RenderFrameHostManager::ResetProxiesInSiteInstance,
617 ids_to_keep.back())); 717 ids_to_keep.back()));
618 ids_to_keep.pop_back(); 718 ids_to_keep.pop_back();
619 } 719 }
(...skipping 28 matching lines...) Expand all
648 // RenderFrameHost once it runs its unload handler, without replacing it with 748 // RenderFrameHost once it runs its unload handler, without replacing it with
649 // a proxy. 749 // a proxy.
650 size_t active_frame_count = 750 size_t active_frame_count =
651 old_render_frame_host->GetSiteInstance()->active_frame_count(); 751 old_render_frame_host->GetSiteInstance()->active_frame_count();
652 if (active_frame_count <= 1) { 752 if (active_frame_count <= 1) {
653 // Clear out any proxies from this SiteInstance, in case this was the 753 // Clear out any proxies from this SiteInstance, in case this was the
654 // last one keeping other proxies alive. 754 // last one keeping other proxies alive.
655 ShutdownProxiesIfLastActiveFrameInSiteInstance(old_render_frame_host.get()); 755 ShutdownProxiesIfLastActiveFrameInSiteInstance(old_render_frame_host.get());
656 756
657 // Tell the old RenderFrameHost to swap out, with no proxy to replace it. 757 // Tell the old RenderFrameHost to swap out, with no proxy to replace it.
658 old_render_frame_host->SwapOut(NULL, true); 758 old_render_frame_host->SwapOut(nullptr, true);
659 MoveToPendingDeleteHosts(old_render_frame_host.Pass()); 759 MoveToPendingDeleteHosts(old_render_frame_host.Pass());
660 return; 760 return;
661 } 761 }
662 762
663 // Otherwise there are active views and we need a proxy for the old RFH. 763 // Otherwise there are active views and we need a proxy for the old RFH.
664 // (There should not be one yet.) 764 // (There should not be one yet.)
665 CHECK(!GetRenderFrameProxyHost(old_render_frame_host->GetSiteInstance()));
666 RenderFrameProxyHost* proxy = new RenderFrameProxyHost( 765 RenderFrameProxyHost* proxy = new RenderFrameProxyHost(
667 old_render_frame_host->GetSiteInstance(), 766 old_render_frame_host->GetSiteInstance(),
668 old_render_frame_host->render_view_host(), frame_tree_node_); 767 old_render_frame_host->render_view_host(), frame_tree_node_);
669 CHECK(proxy_hosts_.insert(std::make_pair(old_site_instance_id, proxy)).second) 768 proxy_hosts_->Add(old_site_instance_id, make_scoped_ptr(proxy));
670 << "Inserting a duplicate item.";
671 769
672 // Tell the old RenderFrameHost to swap out and be replaced by the proxy. 770 // Tell the old RenderFrameHost to swap out and be replaced by the proxy.
673 old_render_frame_host->SwapOut(proxy, true); 771 old_render_frame_host->SwapOut(proxy, true);
674 772
675 // SwapOut creates a RenderFrameProxy, so set the proxy to be initialized. 773 // SwapOut creates a RenderFrameProxy, so set the proxy to be initialized.
676 proxy->set_render_frame_proxy_created(true); 774 proxy->set_render_frame_proxy_created(true);
677 775
678 if (RenderFrameHostManager::IsSwappedOutStateForbidden()) { 776 if (RenderFrameHostManager::IsSwappedOutStateForbidden()) {
679 // In --site-per-process, frames delete their RFH rather than storing it 777 // In --site-per-process, frames delete their RFH rather than storing it
680 // in the proxy. Schedule it for deletion once the SwapOutACK comes in. 778 // in the proxy. Schedule it for deletion once the SwapOutACK comes in.
(...skipping 17 matching lines...) Expand all
698 796
699 // If the SiteInstance for the pending RFH is being used by others don't 797 // If the SiteInstance for the pending RFH is being used by others don't
700 // delete the RFH. Just swap it out and it can be reused at a later point. 798 // delete the RFH. Just swap it out and it can be reused at a later point.
701 // In --site-per-process, RenderFrameHosts are not kept around and are 799 // In --site-per-process, RenderFrameHosts are not kept around and are
702 // deleted when not used, replaced by RenderFrameProxyHosts. 800 // deleted when not used, replaced by RenderFrameProxyHosts.
703 SiteInstanceImpl* site_instance = render_frame_host->GetSiteInstance(); 801 SiteInstanceImpl* site_instance = render_frame_host->GetSiteInstance();
704 if (site_instance->HasSite() && site_instance->active_frame_count() > 1) { 802 if (site_instance->HasSite() && site_instance->active_frame_count() > 1) {
705 // Any currently suspended navigations are no longer needed. 803 // Any currently suspended navigations are no longer needed.
706 render_frame_host->CancelSuspendedNavigations(); 804 render_frame_host->CancelSuspendedNavigations();
707 805
708 CHECK(!GetRenderFrameProxyHost(site_instance));
709 RenderFrameProxyHost* proxy = new RenderFrameProxyHost( 806 RenderFrameProxyHost* proxy = new RenderFrameProxyHost(
710 site_instance, render_frame_host->render_view_host(), frame_tree_node_); 807 site_instance, render_frame_host->render_view_host(), frame_tree_node_);
711 proxy_hosts_[site_instance->GetId()] = proxy; 808 proxy_hosts_->Add(site_instance->GetId(), make_scoped_ptr(proxy));
712 809
713 // Check if the RenderFrameHost is already swapped out, to avoid swapping it 810 // Check if the RenderFrameHost is already swapped out, to avoid swapping it
714 // out again. 811 // out again.
715 if (!render_frame_host->is_swapped_out()) 812 if (!render_frame_host->is_swapped_out())
716 render_frame_host->SwapOut(proxy, false); 813 render_frame_host->SwapOut(proxy, false);
717 814
718 if (!RenderFrameHostManager::IsSwappedOutStateForbidden()) { 815 if (!RenderFrameHostManager::IsSwappedOutStateForbidden()) {
719 DCHECK(frame_tree_node_->IsMainFrame()); 816 DCHECK(frame_tree_node_->IsMainFrame());
720 proxy->TakeFrameHostOwnership(render_frame_host.Pass()); 817 proxy->TakeFrameHostOwnership(render_frame_host.Pass());
721 } 818 }
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
753 iter++) { 850 iter++) {
754 if (*iter == render_frame_host) { 851 if (*iter == render_frame_host) {
755 pending_delete_hosts_.erase(iter); 852 pending_delete_hosts_.erase(iter);
756 return true; 853 return true;
757 } 854 }
758 } 855 }
759 return false; 856 return false;
760 } 857 }
761 858
762 void RenderFrameHostManager::ResetProxyHosts() { 859 void RenderFrameHostManager::ResetProxyHosts() {
763 STLDeleteValues(&proxy_hosts_); 860 proxy_hosts_->Clear();
764 } 861 }
765 862
766 // PlzNavigate 863 // PlzNavigate
767 void RenderFrameHostManager::DidCreateNavigationRequest( 864 void RenderFrameHostManager::DidCreateNavigationRequest(
768 const NavigationRequest& request) { 865 const NavigationRequest& request) {
769 CHECK(base::CommandLine::ForCurrentProcess()->HasSwitch( 866 CHECK(base::CommandLine::ForCurrentProcess()->HasSwitch(
770 switches::kEnableBrowserSideNavigation)); 867 switches::kEnableBrowserSideNavigation));
771 // Clean up any state in case there's an ongoing navigation. 868 // Clean up any state in case there's an ongoing navigation.
772 // TODO(carlosk): remove this cleanup here once we properly cancel ongoing 869 // TODO(carlosk): remove this cleanup here once we properly cancel ongoing
773 // navigations. 870 // navigations.
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
906 // PlzNavigate 1003 // PlzNavigate
907 scoped_ptr<RenderFrameHostImpl> 1004 scoped_ptr<RenderFrameHostImpl>
908 RenderFrameHostManager::UnsetSpeculativeRenderFrameHost() { 1005 RenderFrameHostManager::UnsetSpeculativeRenderFrameHost() {
909 CHECK(base::CommandLine::ForCurrentProcess()->HasSwitch( 1006 CHECK(base::CommandLine::ForCurrentProcess()->HasSwitch(
910 switches::kEnableBrowserSideNavigation)); 1007 switches::kEnableBrowserSideNavigation));
911 speculative_render_frame_host_->GetProcess()->RemovePendingView(); 1008 speculative_render_frame_host_->GetProcess()->RemovePendingView();
912 return speculative_render_frame_host_.Pass(); 1009 return speculative_render_frame_host_.Pass();
913 } 1010 }
914 1011
915 void RenderFrameHostManager::OnDidStartLoading() { 1012 void RenderFrameHostManager::OnDidStartLoading() {
916 for (const auto& pair : proxy_hosts_) { 1013 for (const auto& pair : *proxy_hosts_) {
917 pair.second->Send( 1014 pair.second->Send(
918 new FrameMsg_DidStartLoading(pair.second->GetRoutingID())); 1015 new FrameMsg_DidStartLoading(pair.second->GetRoutingID()));
919 } 1016 }
920 } 1017 }
921 1018
922 void RenderFrameHostManager::OnDidStopLoading() { 1019 void RenderFrameHostManager::OnDidStopLoading() {
923 for (const auto& pair : proxy_hosts_) { 1020 for (const auto& pair : *proxy_hosts_) {
924 pair.second->Send(new FrameMsg_DidStopLoading(pair.second->GetRoutingID())); 1021 pair.second->Send(new FrameMsg_DidStopLoading(pair.second->GetRoutingID()));
925 } 1022 }
926 } 1023 }
927 1024
928 void RenderFrameHostManager::OnDidUpdateName(const std::string& name) { 1025 void RenderFrameHostManager::OnDidUpdateName(const std::string& name) {
929 // The window.name message may be sent outside of --site-per-process when 1026 // The window.name message may be sent outside of --site-per-process when
930 // report_frame_name_changes renderer preference is set (used by 1027 // report_frame_name_changes renderer preference is set (used by
931 // WebView). Don't send the update to proxies in those cases. 1028 // WebView). Don't send the update to proxies in those cases.
932 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( 1029 if (!base::CommandLine::ForCurrentProcess()->HasSwitch(
933 switches::kSitePerProcess)) 1030 switches::kSitePerProcess))
934 return; 1031 return;
935 1032
936 for (const auto& pair : proxy_hosts_) { 1033 for (const auto& pair : *proxy_hosts_) {
937 pair.second->Send( 1034 pair.second->Send(
938 new FrameMsg_DidUpdateName(pair.second->GetRoutingID(), name)); 1035 new FrameMsg_DidUpdateName(pair.second->GetRoutingID(), name));
939 } 1036 }
940 } 1037 }
941 1038
942 void RenderFrameHostManager::OnDidUpdateOrigin( 1039 void RenderFrameHostManager::OnDidUpdateOrigin(
943 const url::DeprecatedSerializedOrigin& origin) { 1040 const url::DeprecatedSerializedOrigin& origin) {
944 if (!IsSwappedOutStateForbidden()) 1041 if (!IsSwappedOutStateForbidden())
945 return; 1042 return;
946 1043
947 for (const auto& pair : proxy_hosts_) { 1044 for (const auto& pair : *proxy_hosts_) {
948 pair.second->Send( 1045 pair.second->Send(
949 new FrameMsg_DidUpdateOrigin(pair.second->GetRoutingID(), origin)); 1046 new FrameMsg_DidUpdateOrigin(pair.second->GetRoutingID(), origin));
950 } 1047 }
951 } 1048 }
952 1049
953 void RenderFrameHostManager::Observe(
954 int type,
955 const NotificationSource& source,
956 const NotificationDetails& details) {
957 switch (type) {
958 case NOTIFICATION_RENDERER_PROCESS_CLOSED:
959 case NOTIFICATION_RENDERER_PROCESS_CLOSING:
960 RendererProcessClosing(
961 Source<RenderProcessHost>(source).ptr());
962 break;
963
964 default:
965 NOTREACHED();
966 }
967 }
968
969 RenderFrameHostManager::SiteInstanceDescriptor::SiteInstanceDescriptor( 1050 RenderFrameHostManager::SiteInstanceDescriptor::SiteInstanceDescriptor(
970 BrowserContext* browser_context, 1051 BrowserContext* browser_context,
971 GURL dest_url, 1052 GURL dest_url,
972 bool related_to_current) 1053 bool related_to_current)
973 : existing_site_instance(nullptr), 1054 : existing_site_instance(nullptr),
974 new_is_related_to_current(related_to_current) { 1055 new_is_related_to_current(related_to_current) {
975 new_site_url = SiteInstance::GetSiteForURL(browser_context, dest_url); 1056 new_site_url = SiteInstance::GetSiteForURL(browser_context, dest_url);
976 } 1057 }
977 1058
978 // static 1059 // static
979 bool RenderFrameHostManager::ClearProxiesInSiteInstance( 1060 bool RenderFrameHostManager::ClearProxiesInSiteInstance(
980 int32 site_instance_id, 1061 int32 site_instance_id,
981 FrameTreeNode* node) { 1062 FrameTreeNode* node) {
982 RenderFrameProxyHostMap::iterator iter = 1063 RenderFrameProxyHost* proxy =
983 node->render_manager()->proxy_hosts_.find(site_instance_id); 1064 node->render_manager()->proxy_hosts_->Get(site_instance_id);
984 if (iter != node->render_manager()->proxy_hosts_.end()) { 1065 if (proxy) {
985 RenderFrameProxyHost* proxy = iter->second;
986 // Delete the proxy. If it is for a main frame (and thus the RFH is stored 1066 // Delete the proxy. If it is for a main frame (and thus the RFH is stored
987 // in the proxy) and it was still pending swap out, move the RFH to the 1067 // in the proxy) and it was still pending swap out, move the RFH to the
988 // pending deletion list first. 1068 // pending deletion list first.
989 if (node->IsMainFrame() && 1069 if (node->IsMainFrame() &&
990 proxy->render_frame_host() && 1070 proxy->render_frame_host() &&
991 proxy->render_frame_host()->rfh_state() == 1071 proxy->render_frame_host()->rfh_state() ==
992 RenderFrameHostImpl::STATE_PENDING_SWAP_OUT) { 1072 RenderFrameHostImpl::STATE_PENDING_SWAP_OUT) {
993 DCHECK(!RenderFrameHostManager::IsSwappedOutStateForbidden()); 1073 DCHECK(!RenderFrameHostManager::IsSwappedOutStateForbidden());
994 scoped_ptr<RenderFrameHostImpl> swapped_out_rfh = 1074 scoped_ptr<RenderFrameHostImpl> swapped_out_rfh =
995 proxy->PassFrameHostOwnership(); 1075 proxy->PassFrameHostOwnership();
996 node->render_manager()->MoveToPendingDeleteHosts(swapped_out_rfh.Pass()); 1076 node->render_manager()->MoveToPendingDeleteHosts(swapped_out_rfh.Pass());
997 } 1077 }
998 delete proxy; 1078 node->render_manager()->proxy_hosts_->Remove(site_instance_id);
999 node->render_manager()->proxy_hosts_.erase(site_instance_id);
1000 } 1079 }
1001 1080
1002 return true; 1081 return true;
1003 } 1082 }
1004 1083
1005 // static. 1084 // static.
1006 bool RenderFrameHostManager::ResetProxiesInSiteInstance(int32 site_instance_id, 1085 bool RenderFrameHostManager::ResetProxiesInSiteInstance(int32 site_instance_id,
1007 FrameTreeNode* node) { 1086 FrameTreeNode* node) {
1008 RenderFrameProxyHostMap::iterator iter = 1087 RenderFrameProxyHost* proxy =
1009 node->render_manager()->proxy_hosts_.find(site_instance_id); 1088 node->render_manager()->proxy_hosts_->Get(site_instance_id);
1010 if (iter != node->render_manager()->proxy_hosts_.end()) 1089 if (proxy)
1011 iter->second->set_render_frame_proxy_created(false); 1090 proxy->set_render_frame_proxy_created(false);
1012 1091
1013 return true; 1092 return true;
1014 } 1093 }
1015 1094
1016 bool RenderFrameHostManager::ShouldTransitionCrossSite() { 1095 bool RenderFrameHostManager::ShouldTransitionCrossSite() {
1017 // True for --site-per-process, which overrides both kSingleProcess and 1096 // True for --site-per-process, which overrides both kSingleProcess and
1018 // kProcessPerTab. 1097 // kProcessPerTab.
1019 if (base::CommandLine::ForCurrentProcess()->HasSwitch( 1098 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
1020 switches::kSitePerProcess)) 1099 switches::kSitePerProcess))
1021 return true; 1100 return true;
(...skipping 526 matching lines...) Expand 10 before | Expand all | Expand 10 after
1548 if (proxy && proxy->render_frame_host()) { 1627 if (proxy && proxy->render_frame_host()) {
1549 CHECK(!swapped_out_forbidden); 1628 CHECK(!swapped_out_forbidden);
1550 if (view_routing_id_ptr) 1629 if (view_routing_id_ptr)
1551 *view_routing_id_ptr = proxy->GetRenderViewHost()->GetRoutingID(); 1630 *view_routing_id_ptr = proxy->GetRenderViewHost()->GetRoutingID();
1552 // Delete the existing RenderFrameProxyHost, but reuse the RenderFrameHost. 1631 // Delete the existing RenderFrameProxyHost, but reuse the RenderFrameHost.
1553 // Prevent the process from exiting while we're trying to use it. 1632 // Prevent the process from exiting while we're trying to use it.
1554 if (!swapped_out) { 1633 if (!swapped_out) {
1555 new_render_frame_host = proxy->PassFrameHostOwnership(); 1634 new_render_frame_host = proxy->PassFrameHostOwnership();
1556 new_render_frame_host->GetProcess()->AddPendingView(); 1635 new_render_frame_host->GetProcess()->AddPendingView();
1557 1636
1558 proxy_hosts_.erase(instance->GetId()); 1637 proxy_hosts_->Remove(instance->GetId());
1559 delete proxy; 1638 // NB |proxy| is deleted at this point.
1560 } 1639 }
1561 } else { 1640 } else {
1562 // Create a new RenderFrameHost if we don't find an existing one. 1641 // Create a new RenderFrameHost if we don't find an existing one.
1563 new_render_frame_host = CreateRenderFrameHost(instance, MSG_ROUTING_NONE, 1642 new_render_frame_host = CreateRenderFrameHost(instance, MSG_ROUTING_NONE,
1564 MSG_ROUTING_NONE, flags); 1643 MSG_ROUTING_NONE, flags);
1565 RenderViewHostImpl* render_view_host = 1644 RenderViewHostImpl* render_view_host =
1566 new_render_frame_host->render_view_host(); 1645 new_render_frame_host->render_view_host();
1567 int proxy_routing_id = MSG_ROUTING_NONE; 1646 int proxy_routing_id = MSG_ROUTING_NONE;
1568 1647
1569 // Prevent the process from exiting while we're trying to navigate in it. 1648 // Prevent the process from exiting while we're trying to navigate in it.
1570 // Otherwise, if the new RFH is swapped out already, store it. 1649 // Otherwise, if the new RFH is swapped out already, store it.
1571 if (!swapped_out) { 1650 if (!swapped_out) {
1572 new_render_frame_host->GetProcess()->AddPendingView(); 1651 new_render_frame_host->GetProcess()->AddPendingView();
1573 } else { 1652 } else {
1574 proxy = new RenderFrameProxyHost( 1653 proxy = new RenderFrameProxyHost(
1575 new_render_frame_host->GetSiteInstance(), 1654 new_render_frame_host->GetSiteInstance(),
1576 new_render_frame_host->render_view_host(), frame_tree_node_); 1655 new_render_frame_host->render_view_host(), frame_tree_node_);
1577 proxy_hosts_[instance->GetId()] = proxy; 1656 proxy_hosts_->Add(instance->GetId(), make_scoped_ptr(proxy));
1578 proxy_routing_id = proxy->GetRoutingID(); 1657 proxy_routing_id = proxy->GetRoutingID();
1579 proxy->TakeFrameHostOwnership(new_render_frame_host.Pass()); 1658 proxy->TakeFrameHostOwnership(new_render_frame_host.Pass());
1580 } 1659 }
1581 1660
1582 success = InitRenderView(render_view_host, proxy_routing_id, 1661 success = InitRenderView(render_view_host, proxy_routing_id,
1583 !!(flags & CREATE_RF_FOR_MAIN_FRAME_NAVIGATION)); 1662 !!(flags & CREATE_RF_FOR_MAIN_FRAME_NAVIGATION));
1584 if (success) { 1663 if (success) {
1585 // Remember that InitRenderView also created the RenderFrameProxy. 1664 // Remember that InitRenderView also created the RenderFrameProxy.
1586 if (swapped_out) 1665 if (swapped_out)
1587 proxy->set_render_frame_proxy_created(true); 1666 proxy->set_render_frame_proxy_created(true);
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
1651 render_view_host = frame_tree_node_->frame_tree()->CreateRenderViewHost( 1730 render_view_host = frame_tree_node_->frame_tree()->CreateRenderViewHost(
1652 instance, MSG_ROUTING_NONE, MSG_ROUTING_NONE, true, true); 1731 instance, MSG_ROUTING_NONE, MSG_ROUTING_NONE, true, true);
1653 } 1732 }
1654 } 1733 }
1655 1734
1656 RenderFrameProxyHost* proxy = GetRenderFrameProxyHost(instance); 1735 RenderFrameProxyHost* proxy = GetRenderFrameProxyHost(instance);
1657 if (proxy && proxy->is_render_frame_proxy_live()) 1736 if (proxy && proxy->is_render_frame_proxy_live())
1658 return proxy->GetRoutingID(); 1737 return proxy->GetRoutingID();
1659 1738
1660 if (!proxy) { 1739 if (!proxy) {
1661 proxy = new RenderFrameProxyHost( 1740 proxy =
1662 instance, render_view_host, frame_tree_node_); 1741 new RenderFrameProxyHost(instance, render_view_host, frame_tree_node_);
1663 proxy_hosts_[instance->GetId()] = proxy; 1742 proxy_hosts_->Add(instance->GetId(), make_scoped_ptr(proxy));
1664 } 1743 }
1665 1744
1666 if (RenderFrameHostManager::IsSwappedOutStateForbidden() && 1745 if (RenderFrameHostManager::IsSwappedOutStateForbidden() &&
1667 frame_tree_node_->IsMainFrame()) { 1746 frame_tree_node_->IsMainFrame()) {
1668 InitRenderView(render_view_host, proxy->GetRoutingID(), true); 1747 InitRenderView(render_view_host, proxy->GetRoutingID(), true);
1669 proxy->set_render_frame_proxy_created(true); 1748 proxy->set_render_frame_proxy_created(true);
1670 } else { 1749 } else {
1671 proxy->InitRenderFrameProxy(); 1750 proxy->InitRenderFrameProxy();
1672 } 1751 }
1673 1752
1674 return proxy->GetRoutingID(); 1753 return proxy->GetRoutingID();
1675 } 1754 }
1676 1755
1677 void RenderFrameHostManager::CreateProxiesForChildFrame(FrameTreeNode* child) { 1756 void RenderFrameHostManager::CreateProxiesForChildFrame(FrameTreeNode* child) {
1678 for (const auto& pair : proxy_hosts_) { 1757 for (const auto& pair : *proxy_hosts_) {
1679 child->render_manager()->CreateRenderFrameProxy( 1758 child->render_manager()->CreateRenderFrameProxy(
1680 pair.second->GetSiteInstance()); 1759 pair.second->GetSiteInstance());
1681 } 1760 }
1682 } 1761 }
1683 1762
1684 void RenderFrameHostManager::EnsureRenderViewInitialized( 1763 void RenderFrameHostManager::EnsureRenderViewInitialized(
1685 RenderViewHostImpl* render_view_host, 1764 RenderViewHostImpl* render_view_host,
1686 SiteInstance* instance) { 1765 SiteInstance* instance) {
1687 DCHECK(frame_tree_node_->IsMainFrame()); 1766 DCHECK(frame_tree_node_->IsMainFrame());
1688 1767
(...skipping 13 matching lines...) Expand all
1702 proxy->set_render_frame_proxy_created(true); 1781 proxy->set_render_frame_proxy_created(true);
1703 } 1782 }
1704 1783
1705 void RenderFrameHostManager::CreateOuterDelegateProxy( 1784 void RenderFrameHostManager::CreateOuterDelegateProxy(
1706 SiteInstance* outer_contents_site_instance, 1785 SiteInstance* outer_contents_site_instance,
1707 RenderFrameHostImpl* render_frame_host) { 1786 RenderFrameHostImpl* render_frame_host) {
1708 CHECK(base::CommandLine::ForCurrentProcess()->HasSwitch( 1787 CHECK(base::CommandLine::ForCurrentProcess()->HasSwitch(
1709 switches::kSitePerProcess)); 1788 switches::kSitePerProcess));
1710 RenderFrameProxyHost* proxy = new RenderFrameProxyHost( 1789 RenderFrameProxyHost* proxy = new RenderFrameProxyHost(
1711 outer_contents_site_instance, nullptr, frame_tree_node_); 1790 outer_contents_site_instance, nullptr, frame_tree_node_);
1712 proxy_hosts_[outer_contents_site_instance->GetId()] = proxy; 1791 proxy_hosts_->Add(outer_contents_site_instance->GetId(),
1792 make_scoped_ptr(proxy));
1713 1793
1714 // Swap the outer WebContents's frame with the proxy to inner WebContents. 1794 // Swap the outer WebContents's frame with the proxy to inner WebContents.
1715 // 1795 //
1716 // We are in the outer WebContents, and its FrameTree would never see 1796 // We are in the outer WebContents, and its FrameTree would never see
1717 // a load start for any of its inner WebContents. Eventually, that also makes 1797 // a load start for any of its inner WebContents. Eventually, that also makes
1718 // the FrameTree never see the matching load stop. Therefore, we always pass 1798 // the FrameTree never see the matching load stop. Therefore, we always pass
1719 // false to |is_loading| below. 1799 // false to |is_loading| below.
1720 // TODO(lazyboy): This |is_loading| behavior might not be what we want, 1800 // TODO(lazyboy): This |is_loading| behavior might not be what we want,
1721 // investigate and fix. 1801 // investigate and fix.
1722 render_frame_host->Send(new FrameMsg_SwapOut( 1802 render_frame_host->Send(new FrameMsg_SwapOut(
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after
1965 // This will swap it out and then put it on the proxy list (if there are other 2045 // This will swap it out and then put it on the proxy list (if there are other
1966 // active views in its SiteInstance) or schedule it for deletion when the swap 2046 // active views in its SiteInstance) or schedule it for deletion when the swap
1967 // out ack arrives (or immediately if the process isn't live). 2047 // out ack arrives (or immediately if the process isn't live).
1968 // In the --site-per-process case, old subframe RFHs are not kept alive inside 2048 // In the --site-per-process case, old subframe RFHs are not kept alive inside
1969 // the proxy. 2049 // the proxy.
1970 SwapOutOldFrame(old_render_frame_host.Pass()); 2050 SwapOutOldFrame(old_render_frame_host.Pass());
1971 2051
1972 if (RenderFrameHostManager::IsSwappedOutStateForbidden()) { 2052 if (RenderFrameHostManager::IsSwappedOutStateForbidden()) {
1973 // Since the new RenderFrameHost is now committed, there must be no proxies 2053 // Since the new RenderFrameHost is now committed, there must be no proxies
1974 // for its SiteInstance. Delete any existing ones. 2054 // for its SiteInstance. Delete any existing ones.
1975 RenderFrameProxyHostMap::iterator iter = 2055 proxy_hosts_->Remove(render_frame_host_->GetSiteInstance()->GetId());
1976 proxy_hosts_.find(render_frame_host_->GetSiteInstance()->GetId());
1977 if (iter != proxy_hosts_.end()) {
1978 delete iter->second;
1979 proxy_hosts_.erase(iter);
1980 }
1981 } 2056 }
1982 2057
1983 if (base::CommandLine::ForCurrentProcess()->HasSwitch( 2058 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
1984 switches::kSitePerProcess)) { 2059 switches::kSitePerProcess)) {
1985 // If this is a subframe, it should have a CrossProcessFrameConnector 2060 // If this is a subframe, it should have a CrossProcessFrameConnector
1986 // created already. Use it to link the new RFH's view to the proxy that 2061 // created already. Use it to link the new RFH's view to the proxy that
1987 // belongs to the parent frame's SiteInstance. If this navigation causes 2062 // belongs to the parent frame's SiteInstance. If this navigation causes
1988 // an out-of-process frame to return to the same process as its parent, the 2063 // an out-of-process frame to return to the same process as its parent, the
1989 // proxy would have been removed from proxy_hosts_ above. 2064 // proxy would have been removed from proxy_hosts_ above.
1990 // Note: We do this after swapping out the old RFH because that may create 2065 // Note: We do this after swapping out the old RFH because that may create
1991 // the proxy we're looking for. 2066 // the proxy we're looking for.
1992 RenderFrameProxyHost* proxy_to_parent = GetProxyToParent(); 2067 RenderFrameProxyHost* proxy_to_parent = GetProxyToParent();
1993 if (proxy_to_parent) 2068 if (proxy_to_parent)
1994 proxy_to_parent->SetChildRWHView(render_frame_host_->GetView()); 2069 proxy_to_parent->SetChildRWHView(render_frame_host_->GetView());
1995 } 2070 }
1996 2071
1997 // After all is done, there must never be a proxy in the list which has the 2072 // After all is done, there must never be a proxy in the list which has the
1998 // same SiteInstance as the current RenderFrameHost. 2073 // same SiteInstance as the current RenderFrameHost.
1999 CHECK(proxy_hosts_.find(render_frame_host_->GetSiteInstance()->GetId()) == 2074 CHECK(!proxy_hosts_->Get(render_frame_host_->GetSiteInstance()->GetId()));
2000 proxy_hosts_.end());
2001 } 2075 }
2002 2076
2003 void RenderFrameHostManager::ShutdownProxiesIfLastActiveFrameInSiteInstance( 2077 void RenderFrameHostManager::ShutdownProxiesIfLastActiveFrameInSiteInstance(
2004 RenderFrameHostImpl* render_frame_host) { 2078 RenderFrameHostImpl* render_frame_host) {
2005 if (!render_frame_host) 2079 if (!render_frame_host)
2006 return; 2080 return;
2007 if (!RenderFrameHostImpl::IsRFHStateActive(render_frame_host->rfh_state())) 2081 if (!RenderFrameHostImpl::IsRFHStateActive(render_frame_host->rfh_state()))
2008 return; 2082 return;
2009 if (render_frame_host->GetSiteInstance()->active_frame_count() > 1U) 2083 if (render_frame_host->GetSiteInstance()->active_frame_count() > 1U)
2010 return; 2084 return;
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
2140 return pending_render_frame_host_.get(); 2214 return pending_render_frame_host_.get();
2141 } 2215 }
2142 2216
2143 // Otherwise the same SiteInstance can be used. Navigate render_frame_host_. 2217 // Otherwise the same SiteInstance can be used. Navigate render_frame_host_.
2144 2218
2145 // It's possible to swap out the current RFH and then decide to navigate in it 2219 // It's possible to swap out the current RFH and then decide to navigate in it
2146 // anyway (e.g., a cross-process navigation that redirects back to the 2220 // anyway (e.g., a cross-process navigation that redirects back to the
2147 // original site). In that case, we have a proxy for the current RFH but 2221 // original site). In that case, we have a proxy for the current RFH but
2148 // haven't deleted it yet. The new navigation will swap it back in, so we can 2222 // haven't deleted it yet. The new navigation will swap it back in, so we can
2149 // delete the proxy. 2223 // delete the proxy.
2150 DeleteRenderFrameProxyHost(new_instance.get()); 2224 proxy_hosts_->Remove(new_instance.get()->GetId());
2151 2225
2152 if (ShouldReuseWebUI(current_entry, dest_url)) { 2226 if (ShouldReuseWebUI(current_entry, dest_url)) {
2153 pending_web_ui_.reset(); 2227 pending_web_ui_.reset();
2154 pending_and_current_web_ui_ = web_ui_->AsWeakPtr(); 2228 pending_and_current_web_ui_ = web_ui_->AsWeakPtr();
2155 } else { 2229 } else {
2156 SetPendingWebUI(dest_url, bindings); 2230 SetPendingWebUI(dest_url, bindings);
2157 // Make sure the new RenderViewHost has the right bindings. 2231 // Make sure the new RenderViewHost has the right bindings.
2158 if (pending_web_ui() && 2232 if (pending_web_ui() &&
2159 !render_frame_host_->GetProcess()->IsForGuestsOnly()) { 2233 !render_frame_host_->GetProcess()->IsForGuestsOnly()) {
2160 render_frame_host_->render_view_host()->AllowBindings( 2234 render_frame_host_->render_view_host()->AllowBindings(
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
2238 if (!proxy->render_frame_host()) 2312 if (!proxy->render_frame_host())
2239 return false; 2313 return false;
2240 return IsOnSwappedOutList(proxy->render_frame_host()); 2314 return IsOnSwappedOutList(proxy->render_frame_host());
2241 } 2315 }
2242 2316
2243 bool RenderFrameHostManager::IsOnSwappedOutList( 2317 bool RenderFrameHostManager::IsOnSwappedOutList(
2244 RenderFrameHostImpl* rfh) const { 2318 RenderFrameHostImpl* rfh) const {
2245 if (!rfh->GetSiteInstance()) 2319 if (!rfh->GetSiteInstance())
2246 return false; 2320 return false;
2247 2321
2248 RenderFrameProxyHostMap::const_iterator iter = proxy_hosts_.find( 2322 RenderFrameProxyHost* host =
2249 rfh->GetSiteInstance()->GetId()); 2323 proxy_hosts_->Get(rfh->GetSiteInstance()->GetId());
2250 if (iter == proxy_hosts_.end()) 2324 if (!host)
2251 return false; 2325 return false;
2252 2326
2253 return iter->second->render_frame_host() == rfh; 2327 return host->render_frame_host() == rfh;
2254 } 2328 }
2255 2329
2256 RenderViewHostImpl* RenderFrameHostManager::GetSwappedOutRenderViewHost( 2330 RenderViewHostImpl* RenderFrameHostManager::GetSwappedOutRenderViewHost(
2257 SiteInstance* instance) const { 2331 SiteInstance* instance) const {
2258 RenderFrameProxyHost* proxy = GetRenderFrameProxyHost(instance); 2332 RenderFrameProxyHost* proxy = GetRenderFrameProxyHost(instance);
2259 if (proxy) 2333 if (proxy)
2260 return proxy->GetRenderViewHost(); 2334 return proxy->GetRenderViewHost();
2261 return NULL; 2335 return nullptr;
2262 } 2336 }
2263 2337
2264 RenderFrameProxyHost* RenderFrameHostManager::GetRenderFrameProxyHost( 2338 RenderFrameProxyHost* RenderFrameHostManager::GetRenderFrameProxyHost(
2265 SiteInstance* instance) const { 2339 SiteInstance* instance) const {
2266 RenderFrameProxyHostMap::const_iterator iter = 2340 return proxy_hosts_->Get(instance->GetId());
2267 proxy_hosts_.find(instance->GetId());
2268 if (iter != proxy_hosts_.end())
2269 return iter->second;
2270
2271 return NULL;
2272 } 2341 }
2273 2342
2274 void RenderFrameHostManager::DeleteRenderFrameProxyHost( 2343 std::map<int, RenderFrameProxyHost*>
2275 SiteInstance* instance) { 2344 RenderFrameHostManager::GetAllProxyHostsForTesting() {
2276 RenderFrameProxyHostMap::iterator iter = proxy_hosts_.find(instance->GetId()); 2345 std::map<int, RenderFrameProxyHost*> result;
2277 if (iter != proxy_hosts_.end()) { 2346 result.insert(proxy_hosts_->begin(), proxy_hosts_->end());
2278 delete iter->second; 2347 return result;
2279 proxy_hosts_.erase(iter);
2280 }
2281 } 2348 }
2282 2349
2283 void RenderFrameHostManager::CreateOpenerProxiesIfNeeded( 2350 void RenderFrameHostManager::CreateOpenerProxiesIfNeeded(
2284 SiteInstance* instance) { 2351 SiteInstance* instance) {
2285 FrameTreeNode* opener = frame_tree_node_->opener(); 2352 FrameTreeNode* opener = frame_tree_node_->opener();
2286 if (!opener) 2353 if (!opener)
2287 return; 2354 return;
2288 2355
2289 // Create proxies for the opener chain. 2356 // Create proxies for the opener chain.
2290 opener->render_manager()->CreateOpenerProxies(instance); 2357 opener->render_manager()->CreateOpenerProxies(instance);
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
2339 int RenderFrameHostManager::GetOpenerRoutingID(SiteInstance* instance) { 2406 int RenderFrameHostManager::GetOpenerRoutingID(SiteInstance* instance) {
2340 if (!frame_tree_node_->opener()) 2407 if (!frame_tree_node_->opener())
2341 return MSG_ROUTING_NONE; 2408 return MSG_ROUTING_NONE;
2342 2409
2343 return frame_tree_node_->opener() 2410 return frame_tree_node_->opener()
2344 ->render_manager() 2411 ->render_manager()
2345 ->GetRoutingIdForSiteInstance(instance); 2412 ->GetRoutingIdForSiteInstance(instance);
2346 } 2413 }
2347 2414
2348 } // namespace content 2415 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698