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

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

Issue 105523006: Revert 241151 "Make RenderFrameHostManager swap RenderFrameHosts..." (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: Created 7 years 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 | Annotate | Revision Log
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 <utility> 7 #include <utility>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/debug/trace_event.h" 10 #include "base/debug/trace_event.h"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "content/browser/child_process_security_policy_impl.h" 12 #include "content/browser/child_process_security_policy_impl.h"
13 #include "content/browser/devtools/render_view_devtools_agent_host.h" 13 #include "content/browser/devtools/render_view_devtools_agent_host.h"
14 #include "content/browser/frame_host/interstitial_page_impl.h" 14 #include "content/browser/frame_host/interstitial_page_impl.h"
15 #include "content/browser/frame_host/navigation_controller_impl.h" 15 #include "content/browser/frame_host/navigation_controller_impl.h"
16 #include "content/browser/frame_host/navigation_entry_impl.h" 16 #include "content/browser/frame_host/navigation_entry_impl.h"
17 #include "content/browser/frame_host/render_frame_host_factory.h"
18 #include "content/browser/frame_host/render_frame_host_impl.h"
19 #include "content/browser/renderer_host/render_process_host_impl.h" 17 #include "content/browser/renderer_host/render_process_host_impl.h"
20 #include "content/browser/renderer_host/render_view_host_factory.h" 18 #include "content/browser/renderer_host/render_view_host_factory.h"
21 #include "content/browser/renderer_host/render_view_host_impl.h" 19 #include "content/browser/renderer_host/render_view_host_impl.h"
22 #include "content/browser/site_instance_impl.h" 20 #include "content/browser/site_instance_impl.h"
23 #include "content/browser/webui/web_ui_controller_factory_registry.h" 21 #include "content/browser/webui/web_ui_controller_factory_registry.h"
24 #include "content/browser/webui/web_ui_impl.h" 22 #include "content/browser/webui/web_ui_impl.h"
25 #include "content/common/view_messages.h" 23 #include "content/common/view_messages.h"
26 #include "content/port/browser/render_widget_host_view_port.h" 24 #include "content/port/browser/render_widget_host_view_port.h"
27 #include "content/public/browser/content_browser_client.h" 25 #include "content/public/browser/content_browser_client.h"
28 #include "content/public/browser/notification_service.h" 26 #include "content/public/browser/notification_service.h"
(...skipping 23 matching lines...) Expand all
52 transfer_url_chain(transfer_url_chain), 50 transfer_url_chain(transfer_url_chain),
53 referrer(referrer), 51 referrer(referrer),
54 page_transition(page_transition), 52 page_transition(page_transition),
55 frame_id(frame_id), 53 frame_id(frame_id),
56 should_replace_current_entry(should_replace_current_entry) { 54 should_replace_current_entry(should_replace_current_entry) {
57 } 55 }
58 56
59 RenderFrameHostManager::PendingNavigationParams::~PendingNavigationParams() {} 57 RenderFrameHostManager::PendingNavigationParams::~PendingNavigationParams() {}
60 58
61 RenderFrameHostManager::RenderFrameHostManager( 59 RenderFrameHostManager::RenderFrameHostManager(
62 FrameTreeNode* frame_tree_node,
63 RenderFrameHostDelegate* render_frame_delegate, 60 RenderFrameHostDelegate* render_frame_delegate,
64 RenderViewHostDelegate* render_view_delegate, 61 RenderViewHostDelegate* render_view_delegate,
65 RenderWidgetHostDelegate* render_widget_delegate, 62 RenderWidgetHostDelegate* render_widget_delegate,
66 Delegate* delegate) 63 Delegate* delegate)
67 : frame_tree_node_(frame_tree_node), 64 : delegate_(delegate),
68 delegate_(delegate),
69 cross_navigation_pending_(false), 65 cross_navigation_pending_(false),
70 render_frame_delegate_(render_frame_delegate), 66 render_frame_delegate_(render_frame_delegate),
71 render_view_delegate_(render_view_delegate), 67 render_view_delegate_(render_view_delegate),
72 render_widget_delegate_(render_widget_delegate), 68 render_widget_delegate_(render_widget_delegate),
73 render_frame_host_(NULL), 69 render_view_host_(NULL),
74 pending_render_frame_host_(NULL), 70 pending_render_view_host_(NULL),
75 interstitial_page_(NULL) { 71 interstitial_page_(NULL) {
76 } 72 }
77 73
78 RenderFrameHostManager::~RenderFrameHostManager() { 74 RenderFrameHostManager::~RenderFrameHostManager() {
79 if (pending_render_frame_host_) 75 if (pending_render_view_host_)
80 CancelPending(); 76 CancelPending();
81 77
82 // We should always have a current RenderFrameHost except in some tests. 78 // We should always have a main RenderViewHost except in some tests.
83 // TODO(creis): Now that we aren't using Shutdown, make render_frame_host_ and 79 RenderViewHostImpl* render_view_host = render_view_host_;
84 // RenderFrameHostMap use scoped_ptrs. 80 render_view_host_ = NULL;
85 RenderFrameHostImpl* render_frame_host = render_frame_host_; 81 if (render_view_host)
86 render_frame_host_ = NULL; 82 render_view_host->Shutdown();
87 if (render_frame_host)
88 delete render_frame_host;
89 83
90 // Delete any swapped out RenderFrameHosts. 84 // Shut down any swapped out RenderViewHosts.
91 for (RenderFrameHostMap::iterator iter = swapped_out_hosts_.begin(); 85 for (RenderViewHostMap::iterator iter = swapped_out_hosts_.begin();
92 iter != swapped_out_hosts_.end(); 86 iter != swapped_out_hosts_.end();
93 ++iter) { 87 ++iter) {
94 delete iter->second; 88 iter->second->Shutdown();
95 } 89 }
96 } 90 }
97 91
98 void RenderFrameHostManager::Init(BrowserContext* browser_context, 92 void RenderFrameHostManager::Init(BrowserContext* browser_context,
99 SiteInstance* site_instance, 93 SiteInstance* site_instance,
100 int view_routing_id, 94 int routing_id,
101 int frame_routing_id) { 95 int main_frame_routing_id) {
102 // Create a RenderViewHost and RenderFrameHost, once we have an instance. It 96 // Create a RenderViewHost, once we have an instance. It is important to
103 // is important to immediately give this SiteInstance to a RenderViewHost so 97 // immediately give this SiteInstance to a RenderViewHost so that it is
104 // that the SiteInstance is ref counted. 98 // ref counted.
105 if (!site_instance) 99 if (!site_instance)
106 site_instance = SiteInstance::Create(browser_context); 100 site_instance = SiteInstance::Create(browser_context);
107 101 render_view_host_ = static_cast<RenderViewHostImpl*>(
108 // TODO(creis): Make render_frame_host_ a scoped_ptr. 102 RenderViewHostFactory::Create(
109 render_frame_host_ = CreateRenderFrameHost(site_instance, view_routing_id, 103 site_instance, render_view_delegate_, render_frame_delegate_,
110 frame_routing_id, false, false); 104 render_widget_delegate_, routing_id, main_frame_routing_id, false,
105 delegate_->IsHidden()));
106 render_view_host_->AttachToFrameTree();
111 107
112 // Keep track of renderer processes as they start to shut down or are 108 // Keep track of renderer processes as they start to shut down or are
113 // crashed/killed. 109 // crashed/killed.
114 registrar_.Add(this, NOTIFICATION_RENDERER_PROCESS_CLOSED, 110 registrar_.Add(this, NOTIFICATION_RENDERER_PROCESS_CLOSED,
115 NotificationService::AllSources()); 111 NotificationService::AllSources());
116 registrar_.Add(this, NOTIFICATION_RENDERER_PROCESS_CLOSING, 112 registrar_.Add(this, NOTIFICATION_RENDERER_PROCESS_CLOSING,
117 NotificationService::AllSources()); 113 NotificationService::AllSources());
118 } 114 }
119 115
120 RenderViewHostImpl* RenderFrameHostManager::current_host() const { 116 RenderViewHostImpl* RenderFrameHostManager::current_host() const {
121 if (!render_frame_host_) 117 return render_view_host_;
122 return NULL;
123 return render_frame_host_->render_view_host();
124 } 118 }
125 119
126 RenderViewHostImpl* RenderFrameHostManager::pending_render_view_host() const { 120 RenderViewHostImpl* RenderFrameHostManager::pending_render_view_host() const {
127 if (!pending_render_frame_host_) 121 return pending_render_view_host_;
128 return NULL;
129 return pending_render_frame_host_->render_view_host();
130 } 122 }
131 123
132 RenderWidgetHostView* RenderFrameHostManager::GetRenderWidgetHostView() const { 124 RenderWidgetHostView* RenderFrameHostManager::GetRenderWidgetHostView() const {
133 if (interstitial_page_) 125 if (interstitial_page_)
134 return interstitial_page_->GetView(); 126 return interstitial_page_->GetView();
135 if (!render_frame_host_) 127 if (!render_view_host_)
136 return NULL; 128 return NULL;
137 return render_frame_host_->render_view_host()->GetView(); 129 return render_view_host_->GetView();
138 } 130 }
139 131
140 void RenderFrameHostManager::SetPendingWebUI(const NavigationEntryImpl& entry) { 132 void RenderFrameHostManager::SetPendingWebUI(const NavigationEntryImpl& entry) {
141 pending_web_ui_.reset( 133 pending_web_ui_.reset(
142 delegate_->CreateWebUIForRenderManager(entry.GetURL())); 134 delegate_->CreateWebUIForRenderManager(entry.GetURL()));
143 pending_and_current_web_ui_.reset(); 135 pending_and_current_web_ui_.reset();
144 136
145 // If we have assigned (zero or more) bindings to this NavigationEntry in the 137 // If we have assigned (zero or more) bindings to this NavigationEntry in the
146 // past, make sure we're not granting it different bindings than it had 138 // past, make sure we're not granting it different bindings than it had
147 // before. If so, note it and don't give it any bindings, to avoid a 139 // before. If so, note it and don't give it any bindings, to avoid a
148 // potential privilege escalation. 140 // potential privilege escalation.
149 if (pending_web_ui_.get() && 141 if (pending_web_ui_.get() &&
150 entry.bindings() != NavigationEntryImpl::kInvalidBindings && 142 entry.bindings() != NavigationEntryImpl::kInvalidBindings &&
151 pending_web_ui_->GetBindings() != entry.bindings()) { 143 pending_web_ui_->GetBindings() != entry.bindings()) {
152 RecordAction(UserMetricsAction("ProcessSwapBindingsMismatch_RVHM")); 144 RecordAction(UserMetricsAction("ProcessSwapBindingsMismatch_RVHM"));
153 pending_web_ui_.reset(); 145 pending_web_ui_.reset();
154 } 146 }
155 } 147 }
156 148
157 RenderViewHostImpl* RenderFrameHostManager::Navigate( 149 RenderViewHostImpl* RenderFrameHostManager::Navigate(
158 const NavigationEntryImpl& entry) { 150 const NavigationEntryImpl& entry) {
159 TRACE_EVENT0("browser", "RenderFrameHostManager:Navigate"); 151 TRACE_EVENT0("browser", "RenderFrameHostManager:Navigate");
160 // Create a pending RenderFrameHost to use for the navigation. 152 // Create a pending RenderViewHost. It will give us the one we should use
161 RenderFrameHostImpl* dest_render_frame_host = 153 RenderViewHostImpl* dest_render_view_host =
162 UpdateRendererStateForNavigate(entry); 154 static_cast<RenderViewHostImpl*>(UpdateRendererStateForNavigate(entry));
163 if (!dest_render_frame_host) 155 if (!dest_render_view_host)
164 return NULL; // We weren't able to create a pending render frame host. 156 return NULL; // We weren't able to create a pending render view host.
165 157
166 // If the current render_frame_host_ isn't live, we should create it so 158 // If the current render_view_host_ isn't live, we should create it so
167 // that we don't show a sad tab while the dest_render_frame_host fetches 159 // that we don't show a sad tab while the dest_render_view_host fetches
168 // its first page. (Bug 1145340) 160 // its first page. (Bug 1145340)
169 if (dest_render_frame_host != render_frame_host_ && 161 if (dest_render_view_host != render_view_host_ &&
170 !render_frame_host_->render_view_host()->IsRenderViewLive()) { 162 !render_view_host_->IsRenderViewLive()) {
171 // Note: we don't call InitRenderView here because we are navigating away 163 // Note: we don't call InitRenderView here because we are navigating away
172 // soon anyway, and we don't have the NavigationEntry for this host. 164 // soon anyway, and we don't have the NavigationEntry for this host.
173 delegate_->CreateRenderViewForRenderManager( 165 delegate_->CreateRenderViewForRenderManager(render_view_host_,
174 render_frame_host_->render_view_host(), MSG_ROUTING_NONE); 166 MSG_ROUTING_NONE);
175 } 167 }
176 168
177 // If the renderer crashed, then try to create a new one to satisfy this 169 // If the renderer crashed, then try to create a new one to satisfy this
178 // navigation request. 170 // navigation request.
179 if (!dest_render_frame_host->render_view_host()->IsRenderViewLive()) { 171 if (!dest_render_view_host->IsRenderViewLive()) {
180 // Recreate the opener chain. 172 // Recreate the opener chain.
181 int opener_route_id = delegate_->CreateOpenerRenderViewsForRenderManager( 173 int opener_route_id = delegate_->CreateOpenerRenderViewsForRenderManager(
182 dest_render_frame_host->render_view_host()->GetSiteInstance()); 174 dest_render_view_host->GetSiteInstance());
183 if (!InitRenderView(dest_render_frame_host->render_view_host(), 175 if (!InitRenderView(dest_render_view_host, opener_route_id))
184 opener_route_id))
185 return NULL; 176 return NULL;
186 177
187 // Now that we've created a new renderer, be sure to hide it if it isn't 178 // Now that we've created a new renderer, be sure to hide it if it isn't
188 // our primary one. Otherwise, we might crash if we try to call Show() 179 // our primary one. Otherwise, we might crash if we try to call Show()
189 // on it later. 180 // on it later.
190 if (dest_render_frame_host != render_frame_host_ && 181 if (dest_render_view_host != render_view_host_ &&
191 dest_render_frame_host->render_view_host()->GetView()) { 182 dest_render_view_host->GetView()) {
192 dest_render_frame_host->render_view_host()->GetView()->Hide(); 183 dest_render_view_host->GetView()->Hide();
193 } else { 184 } else {
194 // This is our primary renderer, notify here as we won't be calling 185 // This is our primary renderer, notify here as we won't be calling
195 // CommitPending (which does the notify). 186 // CommitPending (which does the notify).
196 delegate_->NotifySwappedFromRenderManager( 187 delegate_->NotifySwappedFromRenderManager(NULL, render_view_host_);
197 NULL, render_frame_host_->render_view_host());
198 } 188 }
199 } 189 }
200 190
201 // TODO(creis): Return the RFH instead, once we can navigate RFHs. 191 return dest_render_view_host;
202 return dest_render_frame_host->render_view_host();
203 } 192 }
204 193
205 void RenderFrameHostManager::Stop() { 194 void RenderFrameHostManager::Stop() {
206 render_frame_host_->render_view_host()->Stop(); 195 render_view_host_->Stop();
207 196
208 // If we are cross-navigating, we should stop the pending renderers. This 197 // If we are cross-navigating, we should stop the pending renderers. This
209 // will lead to a DidFailProvisionalLoad, which will properly destroy them. 198 // will lead to a DidFailProvisionalLoad, which will properly destroy them.
210 if (cross_navigation_pending_) { 199 if (cross_navigation_pending_) {
211 pending_render_frame_host_->render_view_host()->Send(new ViewMsg_Stop( 200 pending_render_view_host_->Send(
212 pending_render_frame_host_->render_view_host()->GetRoutingID())); 201 new ViewMsg_Stop(pending_render_view_host_->GetRoutingID()));
213 } 202 }
214 } 203 }
215 204
216 void RenderFrameHostManager::SetIsLoading(bool is_loading) { 205 void RenderFrameHostManager::SetIsLoading(bool is_loading) {
217 render_frame_host_->render_view_host()->SetIsLoading(is_loading); 206 render_view_host_->SetIsLoading(is_loading);
218 if (pending_render_frame_host_) 207 if (pending_render_view_host_)
219 pending_render_frame_host_->render_view_host()->SetIsLoading(is_loading); 208 pending_render_view_host_->SetIsLoading(is_loading);
220 } 209 }
221 210
222 bool RenderFrameHostManager::ShouldCloseTabOnUnresponsiveRenderer() { 211 bool RenderFrameHostManager::ShouldCloseTabOnUnresponsiveRenderer() {
223 if (!cross_navigation_pending_) 212 if (!cross_navigation_pending_)
224 return true; 213 return true;
225 214
226 // We should always have a pending RFH when there's a cross-process navigation 215 // We should always have a pending RVH when there's a cross-process navigation
227 // in progress. Sanity check this for http://crbug.com/276333. 216 // in progress. Sanity check this for http://crbug.com/276333.
228 CHECK(pending_render_frame_host_); 217 CHECK(pending_render_view_host_);
229 218
230 // If the tab becomes unresponsive during {before}unload while doing a 219 // If the tab becomes unresponsive during {before}unload while doing a
231 // cross-site navigation, proceed with the navigation. (This assumes that 220 // cross-site navigation, proceed with the navigation. (This assumes that
232 // the pending RenderFrameHost is still responsive.) 221 // the pending RenderViewHost is still responsive.)
233 if (render_frame_host_->render_view_host()->is_waiting_for_unload_ack()) { 222 if (render_view_host_->is_waiting_for_unload_ack()) {
234 // The request has been started and paused while we're waiting for the 223 // The request has been started and paused while we're waiting for the
235 // unload handler to finish. We'll pretend that it did. The pending 224 // unload handler to finish. We'll pretend that it did. The pending
236 // renderer will then be swapped in as part of the usual DidNavigate logic. 225 // renderer will then be swapped in as part of the usual DidNavigate logic.
237 // (If the unload handler later finishes, this call will be ignored because 226 // (If the unload handler later finishes, this call will be ignored because
238 // the pending_nav_params_ state will already be cleaned up.) 227 // the pending_nav_params_ state will already be cleaned up.)
239 current_host()->OnSwappedOut(true); 228 current_host()->OnSwappedOut(true);
240 } else if (render_frame_host_->render_view_host()-> 229 } else if (render_view_host_->is_waiting_for_beforeunload_ack()) {
241 is_waiting_for_beforeunload_ack()) {
242 // Haven't gotten around to starting the request, because we're still 230 // Haven't gotten around to starting the request, because we're still
243 // waiting for the beforeunload handler to finish. We'll pretend that it 231 // waiting for the beforeunload handler to finish. We'll pretend that it
244 // did finish, to let the navigation proceed. Note that there's a danger 232 // did finish, to let the navigation proceed. Note that there's a danger
245 // that the beforeunload handler will later finish and possibly return 233 // that the beforeunload handler will later finish and possibly return
246 // false (meaning the navigation should not proceed), but we'll ignore it 234 // false (meaning the navigation should not proceed), but we'll ignore it
247 // in this case because it took too long. 235 // in this case because it took too long.
248 if (pending_render_frame_host_->render_view_host()-> 236 if (pending_render_view_host_->are_navigations_suspended())
249 are_navigations_suspended()) { 237 pending_render_view_host_->SetNavigationsSuspended(
250 pending_render_frame_host_->render_view_host()->SetNavigationsSuspended(
251 false, base::TimeTicks::Now()); 238 false, base::TimeTicks::Now());
252 }
253 } 239 }
254 return false; 240 return false;
255 } 241 }
256 242
257 // TODO(creis): This should take in a RenderFrameHost.
258 void RenderFrameHostManager::SwappedOut(RenderViewHost* render_view_host) { 243 void RenderFrameHostManager::SwappedOut(RenderViewHost* render_view_host) {
259 // Make sure this is from our current RVH, and that we have a pending 244 // Make sure this is from our current RVH, and that we have a pending
260 // navigation from OnCrossSiteResponse. (There may be no pending navigation 245 // navigation from OnCrossSiteResponse. (There may be no pending navigation
261 // for data URLs that don't make network requests, for example.) If not, 246 // for data URLs that don't make network requests, for example.) If not,
262 // just return early and ignore. 247 // just return early and ignore.
263 if (render_view_host != render_frame_host_->render_view_host() || 248 if (render_view_host != render_view_host_ || !pending_nav_params_.get()) {
264 !pending_nav_params_.get()) {
265 pending_nav_params_.reset(); 249 pending_nav_params_.reset();
266 return; 250 return;
267 } 251 }
268 252
269 // Now that the unload handler has run, we need to either initiate the 253 // Now that the unload handler has run, we need to either initiate the
270 // pending transfer (if there is one) or resume the paused response (if not). 254 // pending transfer (if there is one) or resume the paused response (if not).
271 // TODO(creis): The blank swapped out page is visible during this time, but 255 // TODO(creis): The blank swapped out page is visible during this time, but
272 // we can shorten this by delivering the response directly, rather than 256 // we can shorten this by delivering the response directly, rather than
273 // forcing an identical request to be made. 257 // forcing an identical request to be made.
274 if (pending_nav_params_->is_transfer) { 258 if (pending_nav_params_->is_transfer) {
275 // Treat the last URL in the chain as the destination and the remainder as 259 // Treat the last URL in the chain as the destination and the remainder as
276 // the redirect chain. 260 // the redirect chain.
277 CHECK(pending_nav_params_->transfer_url_chain.size()); 261 CHECK(pending_nav_params_->transfer_url_chain.size());
278 GURL transfer_url = pending_nav_params_->transfer_url_chain.back(); 262 GURL transfer_url = pending_nav_params_->transfer_url_chain.back();
279 pending_nav_params_->transfer_url_chain.pop_back(); 263 pending_nav_params_->transfer_url_chain.pop_back();
280 264
281 // We don't know whether the original request had |user_action| set to true. 265 // We don't know whether the original request had |user_action| set to true.
282 // However, since we force the navigation to be in the current tab, it 266 // However, since we force the navigation to be in the current tab, it
283 // doesn't matter. 267 // doesn't matter.
284 render_view_host->GetDelegate()->RequestTransferURL( 268 render_view_host->GetDelegate()->RequestTransferURL(
285 transfer_url, 269 transfer_url,
286 pending_nav_params_->transfer_url_chain, 270 pending_nav_params_->transfer_url_chain,
287 pending_nav_params_->referrer, 271 pending_nav_params_->referrer,
288 pending_nav_params_->page_transition, 272 pending_nav_params_->page_transition,
289 CURRENT_TAB, 273 CURRENT_TAB,
290 pending_nav_params_->frame_id, 274 pending_nav_params_->frame_id,
291 pending_nav_params_->global_request_id, 275 pending_nav_params_->global_request_id,
292 pending_nav_params_->should_replace_current_entry, 276 pending_nav_params_->should_replace_current_entry,
293 true); 277 true);
294 } else if (pending_render_frame_host_) { 278 } else if (pending_render_view_host_) {
295 RenderProcessHostImpl* pending_process = 279 RenderProcessHostImpl* pending_process =
296 static_cast<RenderProcessHostImpl*>( 280 static_cast<RenderProcessHostImpl*>(
297 pending_render_frame_host_->GetProcess()); 281 pending_render_view_host_->GetProcess());
298 pending_process->ResumeDeferredNavigation( 282 pending_process->ResumeDeferredNavigation(
299 pending_nav_params_->global_request_id); 283 pending_nav_params_->global_request_id);
300 } 284 }
301 pending_nav_params_.reset(); 285 pending_nav_params_.reset();
302 } 286 }
303 287
304 // TODO(creis): This should take in a RenderFrameHost.
305 void RenderFrameHostManager::DidNavigateMainFrame( 288 void RenderFrameHostManager::DidNavigateMainFrame(
306 RenderViewHost* render_view_host) { 289 RenderViewHost* render_view_host) {
307 if (!cross_navigation_pending_) { 290 if (!cross_navigation_pending_) {
308 DCHECK(!pending_render_frame_host_); 291 DCHECK(!pending_render_view_host_);
309 292
310 // We should only hear this from our current renderer. 293 // We should only hear this from our current renderer.
311 DCHECK(render_view_host == render_frame_host_->render_view_host()); 294 DCHECK(render_view_host == render_view_host_);
312 295
313 // Even when there is no pending RVH, there may be a pending Web UI. 296 // Even when there is no pending RVH, there may be a pending Web UI.
314 if (pending_web_ui()) 297 if (pending_web_ui())
315 CommitPending(); 298 CommitPending();
316 return; 299 return;
317 } 300 }
318 301
319 if (render_view_host == pending_render_frame_host_->render_view_host()) { 302 if (render_view_host == pending_render_view_host_) {
320 // The pending cross-site navigation completed, so show the renderer. 303 // The pending cross-site navigation completed, so show the renderer.
321 // If it committed without sending network requests (e.g., data URLs), 304 // If it committed without sending network requests (e.g., data URLs),
322 // then we still need to swap out the old RFH first and run its unload 305 // then we still need to swap out the old RVH first and run its unload
323 // handler. OK for that to happen in the background. 306 // handler. OK for that to happen in the background.
324 if (pending_render_frame_host_->render_view_host()-> 307 if (pending_render_view_host_->HasPendingCrossSiteRequest())
325 HasPendingCrossSiteRequest())
326 SwapOutOldPage(); 308 SwapOutOldPage();
327 309
328 CommitPending(); 310 CommitPending();
329 cross_navigation_pending_ = false; 311 cross_navigation_pending_ = false;
330 } else if (render_view_host == render_frame_host_->render_view_host()) { 312 } else if (render_view_host == render_view_host_) {
331 // A navigation in the original page has taken place. Cancel the pending 313 // A navigation in the original page has taken place. Cancel the pending
332 // one. 314 // one.
333 CancelPending(); 315 CancelPending();
334 cross_navigation_pending_ = false; 316 cross_navigation_pending_ = false;
335 } else { 317 } else {
336 // No one else should be sending us DidNavigate in this state. 318 // No one else should be sending us DidNavigate in this state.
337 DCHECK(false); 319 DCHECK(false);
338 } 320 }
339 } 321 }
340 322
341 // TODO(creis): Take in RenderFrameHost instead, since frames can have openers.
342 void RenderFrameHostManager::DidDisownOpener(RenderViewHost* render_view_host) { 323 void RenderFrameHostManager::DidDisownOpener(RenderViewHost* render_view_host) {
343 // Notify all swapped out hosts, including the pending RVH. 324 // Notify all swapped out hosts, including the pending RVH.
344 for (RenderFrameHostMap::iterator iter = swapped_out_hosts_.begin(); 325 for (RenderViewHostMap::iterator iter = swapped_out_hosts_.begin();
345 iter != swapped_out_hosts_.end(); 326 iter != swapped_out_hosts_.end();
346 ++iter) { 327 ++iter) {
347 DCHECK_NE(iter->second->render_view_host()->GetSiteInstance(), 328 DCHECK_NE(iter->second->GetSiteInstance(),
348 current_host()->GetSiteInstance()); 329 current_host()->GetSiteInstance());
349 iter->second->render_view_host()->DisownOpener(); 330 iter->second->DisownOpener();
350 } 331 }
351 } 332 }
352 333
353 void RenderFrameHostManager::RendererAbortedProvisionalLoad( 334 void RenderFrameHostManager::RendererAbortedProvisionalLoad(
354 RenderViewHost* render_view_host) { 335 RenderViewHost* render_view_host) {
355 // We used to cancel the pending renderer here for cross-site downloads. 336 // We used to cancel the pending renderer here for cross-site downloads.
356 // However, it's not safe to do that because the download logic repeatedly 337 // However, it's not safe to do that because the download logic repeatedly
357 // looks for this WebContents based on a render view ID. Instead, we just 338 // looks for this WebContents based on a render view ID. Instead, we just
358 // leave the pending renderer around until the next navigation event 339 // leave the pending renderer around until the next navigation event
359 // (Navigate, DidNavigate, etc), which will clean it up properly. 340 // (Navigate, DidNavigate, etc), which will clean it up properly.
360 // TODO(creis): All of this will go away when we move the cross-site logic 341 // TODO(creis): All of this will go away when we move the cross-site logic
361 // to ResourceDispatcherHost, so that we intercept responses rather than 342 // to ResourceDispatcherHost, so that we intercept responses rather than
362 // navigation events. (That's necessary to support onunload anyway.) Once 343 // navigation events. (That's necessary to support onunload anyway.) Once
363 // we've made that change, we won't create a pending renderer until we know 344 // we've made that change, we won't create a pending renderer until we know
364 // the response is not a download. 345 // the response is not a download.
365 } 346 }
366 347
367 void RenderFrameHostManager::RendererProcessClosing( 348 void RenderFrameHostManager::RendererProcessClosing(
368 RenderProcessHost* render_process_host) { 349 RenderProcessHost* render_process_host) {
369 // Remove any swapped out RVHs from this process, so that we don't try to 350 // Remove any swapped out RVHs from this process, so that we don't try to
370 // swap them back in while the process is exiting. Start by finding them, 351 // swap them back in while the process is exiting. Start by finding them,
371 // since there could be more than one. 352 // since there could be more than one.
372 std::list<int> ids_to_remove; 353 std::list<int> ids_to_remove;
373 for (RenderFrameHostMap::iterator iter = swapped_out_hosts_.begin(); 354 for (RenderViewHostMap::iterator iter = swapped_out_hosts_.begin();
374 iter != swapped_out_hosts_.end(); 355 iter != swapped_out_hosts_.end();
375 ++iter) { 356 ++iter) {
376 if (iter->second->GetProcess() == render_process_host) 357 if (iter->second->GetProcess() == render_process_host)
377 ids_to_remove.push_back(iter->first); 358 ids_to_remove.push_back(iter->first);
378 } 359 }
379 360
380 // Now delete them. 361 // Now delete them.
381 while (!ids_to_remove.empty()) { 362 while (!ids_to_remove.empty()) {
382 delete swapped_out_hosts_[ids_to_remove.back()]; 363 swapped_out_hosts_[ids_to_remove.back()]->Shutdown();
383 swapped_out_hosts_.erase(ids_to_remove.back()); 364 swapped_out_hosts_.erase(ids_to_remove.back());
384 ids_to_remove.pop_back(); 365 ids_to_remove.pop_back();
385 } 366 }
386 } 367 }
387 368
388 void RenderFrameHostManager::ShouldClosePage( 369 void RenderFrameHostManager::ShouldClosePage(
389 bool for_cross_site_transition, 370 bool for_cross_site_transition,
390 bool proceed, 371 bool proceed,
391 const base::TimeTicks& proceed_time) { 372 const base::TimeTicks& proceed_time) {
392 if (for_cross_site_transition) { 373 if (for_cross_site_transition) {
393 // Ignore if we're not in a cross-site navigation. 374 // Ignore if we're not in a cross-site navigation.
394 if (!cross_navigation_pending_) 375 if (!cross_navigation_pending_)
395 return; 376 return;
396 377
397 if (proceed) { 378 if (proceed) {
398 // Ok to unload the current page, so proceed with the cross-site 379 // Ok to unload the current page, so proceed with the cross-site
399 // navigation. Note that if navigations are not currently suspended, it 380 // navigation. Note that if navigations are not currently suspended, it
400 // might be because the renderer was deemed unresponsive and this call was 381 // might be because the renderer was deemed unresponsive and this call was
401 // already made by ShouldCloseTabOnUnresponsiveRenderer. In that case, it 382 // already made by ShouldCloseTabOnUnresponsiveRenderer. In that case, it
402 // is ok to do nothing here. 383 // is ok to do nothing here.
403 if (pending_render_frame_host_ && 384 if (pending_render_view_host_ &&
404 pending_render_frame_host_->render_view_host()-> 385 pending_render_view_host_->are_navigations_suspended()) {
405 are_navigations_suspended()) { 386 pending_render_view_host_->SetNavigationsSuspended(false, proceed_time);
406 pending_render_frame_host_->render_view_host()->
407 SetNavigationsSuspended(false, proceed_time);
408 } 387 }
409 } else { 388 } else {
410 // Current page says to cancel. 389 // Current page says to cancel.
411 CancelPending(); 390 CancelPending();
412 cross_navigation_pending_ = false; 391 cross_navigation_pending_ = false;
413 } 392 }
414 } else { 393 } else {
415 // Non-cross site transition means closing the entire tab. 394 // Non-cross site transition means closing the entire tab.
416 bool proceed_to_fire_unload; 395 bool proceed_to_fire_unload;
417 delegate_->BeforeUnloadFiredFromRenderManager(proceed, proceed_time, 396 delegate_->BeforeUnloadFiredFromRenderManager(proceed, proceed_time,
418 &proceed_to_fire_unload); 397 &proceed_to_fire_unload);
419 398
420 if (proceed_to_fire_unload) { 399 if (proceed_to_fire_unload) {
421 // If we're about to close the tab and there's a pending RFH, cancel it. 400 // If we're about to close the tab and there's a pending RVH, cancel it.
422 // Otherwise, if the navigation in the pending RFH completes before the 401 // Otherwise, if the navigation in the pending RVH completes before the
423 // close in the current RFH, we'll lose the tab close. 402 // close in the current RVH, we'll lose the tab close.
424 if (pending_render_frame_host_) { 403 if (pending_render_view_host_) {
425 CancelPending(); 404 CancelPending();
426 cross_navigation_pending_ = false; 405 cross_navigation_pending_ = false;
427 } 406 }
428 407
429 // This is not a cross-site navigation, the tab is being closed. 408 // This is not a cross-site navigation, the tab is being closed.
430 render_frame_host_->render_view_host()->ClosePage(); 409 render_view_host_->ClosePage();
431 } 410 }
432 } 411 }
433 } 412 }
434 413
435 // TODO(creis): Take in a RenderFrameHost from CSRH.
436 void RenderFrameHostManager::OnCrossSiteResponse( 414 void RenderFrameHostManager::OnCrossSiteResponse(
437 RenderViewHost* pending_render_view_host, 415 RenderViewHost* pending_render_view_host,
438 const GlobalRequestID& global_request_id, 416 const GlobalRequestID& global_request_id,
439 bool is_transfer, 417 bool is_transfer,
440 const std::vector<GURL>& transfer_url_chain, 418 const std::vector<GURL>& transfer_url_chain,
441 const Referrer& referrer, 419 const Referrer& referrer,
442 PageTransition page_transition, 420 PageTransition page_transition,
443 int64 frame_id, 421 int64 frame_id,
444 bool should_replace_current_entry) { 422 bool should_replace_current_entry) {
445 // This should be called either when the pending RVH is ready to commit or 423 // This should be called either when the pending RVH is ready to commit or
446 // when we realize that the current RVH's request requires a transfer. 424 // when we realize that the current RVH's request requires a transfer.
447 DCHECK(pending_render_view_host == render_frame_host_->render_view_host() || 425 DCHECK(
448 pending_render_view_host == 426 pending_render_view_host == pending_render_view_host_ ||
449 pending_render_frame_host_->render_view_host()); 427 pending_render_view_host == render_view_host_);
450 428
451 // TODO(creis): Eventually we will want to check all navigation responses 429 // TODO(creis): Eventually we will want to check all navigation responses
452 // here, but currently we pass information for a transfer if 430 // here, but currently we pass information for a transfer if
453 // ShouldSwapProcessesForRedirect returned true in the network stack. 431 // ShouldSwapProcessesForRedirect returned true in the network stack.
454 // In that case, we should set up a transfer after the unload handler runs. 432 // In that case, we should set up a transfer after the unload handler runs.
455 // If is_transfer is false, we will just run the unload handler and resume. 433 // If is_transfer is false, we will just run the unload handler and resume.
456 pending_nav_params_.reset(new PendingNavigationParams( 434 pending_nav_params_.reset(new PendingNavigationParams(
457 global_request_id, is_transfer, transfer_url_chain, referrer, 435 global_request_id, is_transfer, transfer_url_chain, referrer,
458 page_transition, frame_id, should_replace_current_entry)); 436 page_transition, frame_id, should_replace_current_entry));
459 437
460 // Run the unload handler of the current page. 438 // Run the unload handler of the current page.
461 SwapOutOldPage(); 439 SwapOutOldPage();
462 } 440 }
463 441
464 void RenderFrameHostManager::SwapOutOldPage() { 442 void RenderFrameHostManager::SwapOutOldPage() {
465 // Should only see this while we have a pending renderer or transfer. 443 // Should only see this while we have a pending renderer or transfer.
466 CHECK(cross_navigation_pending_ || pending_nav_params_.get()); 444 CHECK(cross_navigation_pending_ || pending_nav_params_.get());
467 445
468 // Tell the renderer to suppress any further modal dialogs so that we can swap 446 // Tell the renderer to suppress any further modal dialogs so that we can swap
469 // it out. This must be done before canceling any current dialog, in case 447 // it out. This must be done before canceling any current dialog, in case
470 // there is a loop creating additional dialogs. 448 // there is a loop creating additional dialogs.
471 render_frame_host_->render_view_host()->SuppressDialogsUntilSwapOut(); 449 render_view_host_->SuppressDialogsUntilSwapOut();
472 450
473 // Now close any modal dialogs that would prevent us from swapping out. This 451 // Now close any modal dialogs that would prevent us from swapping out. This
474 // must be done separately from SwapOut, so that the PageGroupLoadDeferrer is 452 // must be done separately from SwapOut, so that the PageGroupLoadDeferrer is
475 // no longer on the stack when we send the SwapOut message. 453 // no longer on the stack when we send the SwapOut message.
476 delegate_->CancelModalDialogsForRenderManager(); 454 delegate_->CancelModalDialogsForRenderManager();
477 455
478 // Tell the old renderer it is being swapped out. This will fire the unload 456 // Tell the old renderer it is being swapped out. This will fire the unload
479 // handler (without firing the beforeunload handler a second time). When the 457 // handler (without firing the beforeunload handler a second time). When the
480 // unload handler finishes and the navigation completes, we will send a 458 // unload handler finishes and the navigation completes, we will send a
481 // message to the ResourceDispatcherHost, allowing the pending RVH's response 459 // message to the ResourceDispatcherHost, allowing the pending RVH's response
482 // to resume. 460 // to resume.
483 // TODO(creis): We should do this on the RFH or else we'll swap out the 461 render_view_host_->SwapOut();
484 // top-level page when subframes navigate.
485 render_frame_host_->render_view_host()->SwapOut();
486 462
487 // ResourceDispatcherHost has told us to run the onunload handler, which 463 // ResourceDispatcherHost has told us to run the onunload handler, which
488 // means it is not a download or unsafe page, and we are going to perform the 464 // means it is not a download or unsafe page, and we are going to perform the
489 // navigation. Thus, we no longer need to remember that the RenderViewHost 465 // navigation. Thus, we no longer need to remember that the RenderViewHost
490 // is part of a pending cross-site request. 466 // is part of a pending cross-site request.
491 if (pending_render_frame_host_) { 467 if (pending_render_view_host_)
492 pending_render_frame_host_->render_view_host()-> 468 pending_render_view_host_->SetHasPendingCrossSiteRequest(false);
493 SetHasPendingCrossSiteRequest(false);
494 }
495 } 469 }
496 470
497 void RenderFrameHostManager::Observe( 471 void RenderFrameHostManager::Observe(
498 int type, 472 int type,
499 const NotificationSource& source, 473 const NotificationSource& source,
500 const NotificationDetails& details) { 474 const NotificationDetails& details) {
501 switch (type) { 475 switch (type) {
502 case NOTIFICATION_RENDERER_PROCESS_CLOSED: 476 case NOTIFICATION_RENDERER_PROCESS_CLOSED:
503 case NOTIFICATION_RENDERER_PROCESS_CLOSING: 477 case NOTIFICATION_RENDERER_PROCESS_CLOSING:
504 RendererProcessClosing( 478 RendererProcessClosing(
505 Source<RenderProcessHost>(source).ptr()); 479 Source<RenderProcessHost>(source).ptr());
506 break; 480 break;
507 481
508 default: 482 default:
509 NOTREACHED(); 483 NOTREACHED();
510 } 484 }
511 } 485 }
512 486
513 bool RenderFrameHostManager::ClearSwappedOutRFHsInSiteInstance(
514 int32 site_instance_id,
515 FrameTreeNode* node) {
516 RenderFrameHostMap::iterator iter =
517 node->render_manager()->swapped_out_hosts_.find(site_instance_id);
518 if (iter != node->render_manager()->swapped_out_hosts_.end())
519 delete iter->second;
520
521 return true;
522 }
523
524 bool RenderFrameHostManager::ShouldTransitionCrossSite() { 487 bool RenderFrameHostManager::ShouldTransitionCrossSite() {
525 // False in the single-process mode, as it makes RVHs to accumulate 488 // False in the single-process mode, as it makes RVHs to accumulate
526 // in swapped_out_hosts_. 489 // in swapped_out_hosts_.
527 // True if we are using process-per-site-instance (default) or 490 // True if we are using process-per-site-instance (default) or
528 // process-per-site (kProcessPerSite). 491 // process-per-site (kProcessPerSite).
529 return 492 return
530 !CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess) && 493 !CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess) &&
531 !CommandLine::ForCurrentProcess()->HasSwitch(switches::kProcessPerTab); 494 !CommandLine::ForCurrentProcess()->HasSwitch(switches::kProcessPerTab);
532 } 495 }
533 496
(...skipping 12 matching lines...) Expand all
546 509
547 // We use the effective URL here, since that's what is used in the 510 // We use the effective URL here, since that's what is used in the
548 // SiteInstance's site and when we later call IsSameWebSite. If there is no 511 // SiteInstance's site and when we later call IsSameWebSite. If there is no
549 // current_entry, check the current SiteInstance's site, which might already 512 // current_entry, check the current SiteInstance's site, which might already
550 // be committed to a Web UI URL (such as the NTP). 513 // be committed to a Web UI URL (such as the NTP).
551 BrowserContext* browser_context = 514 BrowserContext* browser_context =
552 delegate_->GetControllerForRenderManager().GetBrowserContext(); 515 delegate_->GetControllerForRenderManager().GetBrowserContext();
553 const GURL& current_url = (current_entry) ? 516 const GURL& current_url = (current_entry) ?
554 SiteInstanceImpl::GetEffectiveURL(browser_context, 517 SiteInstanceImpl::GetEffectiveURL(browser_context,
555 current_entry->GetURL()) : 518 current_entry->GetURL()) :
556 render_frame_host_->render_view_host()->GetSiteInstance()->GetSiteURL(); 519 render_view_host_->GetSiteInstance()->GetSiteURL();
557 const GURL& new_url = SiteInstanceImpl::GetEffectiveURL(browser_context, 520 const GURL& new_url = SiteInstanceImpl::GetEffectiveURL(browser_context,
558 new_entry->GetURL()); 521 new_entry->GetURL());
559 522
560 // For security, we should transition between processes when one is a Web UI 523 // For security, we should transition between processes when one is a Web UI
561 // page and one isn't. 524 // page and one isn't.
562 if (WebUIControllerFactoryRegistry::GetInstance()->UseWebUIForURL( 525 if (WebUIControllerFactoryRegistry::GetInstance()->UseWebUIForURL(
563 browser_context, current_url)) { 526 browser_context, current_url)) {
564 // If so, force a swap if destination is not an acceptable URL for Web UI. 527 // If so, force a swap if destination is not an acceptable URL for Web UI.
565 // Here, data URLs are never allowed. 528 // Here, data URLs are never allowed.
566 if (!WebUIControllerFactoryRegistry::GetInstance()->IsURLAcceptableForWebUI( 529 if (!WebUIControllerFactoryRegistry::GetInstance()->IsURLAcceptableForWebUI(
567 browser_context, new_url, false)) { 530 browser_context, new_url, false)) {
568 return true; 531 return true;
569 } 532 }
570 } else { 533 } else {
571 // Force a swap if it's a Web UI URL. 534 // Force a swap if it's a Web UI URL.
572 if (WebUIControllerFactoryRegistry::GetInstance()->UseWebUIForURL( 535 if (WebUIControllerFactoryRegistry::GetInstance()->UseWebUIForURL(
573 browser_context, new_url)) { 536 browser_context, new_url)) {
574 return true; 537 return true;
575 } 538 }
576 } 539 }
577 540
578 // Check with the content client as well. Important to pass current_url here, 541 // Check with the content client as well. Important to pass current_url here,
579 // which uses the SiteInstance's site if there is no current_entry. 542 // which uses the SiteInstance's site if there is no current_entry.
580 if (GetContentClient()->browser()->ShouldSwapBrowsingInstancesForNavigation( 543 if (GetContentClient()->browser()->ShouldSwapBrowsingInstancesForNavigation(
581 render_frame_host_->render_view_host()->GetSiteInstance(), 544 render_view_host_->GetSiteInstance(), current_url, new_url)) {
582 current_url, new_url)) {
583 return true; 545 return true;
584 } 546 }
585 547
586 // We can't switch a RenderView between view source and non-view source mode 548 // We can't switch a RenderView between view source and non-view source mode
587 // without screwing up the session history sometimes (when navigating between 549 // without screwing up the session history sometimes (when navigating between
588 // "view-source:http://foo.com/" and "http://foo.com/", Blink doesn't treat 550 // "view-source:http://foo.com/" and "http://foo.com/", Blink doesn't treat
589 // it as a new navigation). So require a BrowsingInstance switch. 551 // it as a new navigation). So require a BrowsingInstance switch.
590 if (current_entry && 552 if (current_entry &&
591 current_entry->IsViewSourceMode() != new_entry->IsViewSourceMode()) 553 current_entry->IsViewSourceMode() != new_entry->IsViewSourceMode())
592 return true; 554 return true;
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
752 } 714 }
753 715
754 // Start the new renderer in a new SiteInstance, but in the current 716 // Start the new renderer in a new SiteInstance, but in the current
755 // BrowsingInstance. It is important to immediately give this new 717 // BrowsingInstance. It is important to immediately give this new
756 // SiteInstance to a RenderViewHost (if it is different than our current 718 // SiteInstance to a RenderViewHost (if it is different than our current
757 // SiteInstance), so that it is ref counted. This will happen in 719 // SiteInstance), so that it is ref counted. This will happen in
758 // CreateRenderView. 720 // CreateRenderView.
759 return current_instance->GetRelatedSiteInstance(dest_url); 721 return current_instance->GetRelatedSiteInstance(dest_url);
760 } 722 }
761 723
762 RenderFrameHostImpl* RenderFrameHostManager::CreateRenderFrameHost( 724 int RenderFrameHostManager::CreateRenderView(
763 SiteInstance* site_instance,
764 int view_routing_id,
765 int frame_routing_id,
766 bool swapped_out,
767 bool hidden) {
768 if (frame_routing_id == MSG_ROUTING_NONE)
769 frame_routing_id = site_instance->GetProcess()->GetNextRoutingID();
770
771 // Create a RVH for main frames, or find the existing one for subframes.
772 FrameTree* frame_tree = frame_tree_node_->frame_tree();
773 RenderViewHostImpl* render_view_host = NULL;
774 if (frame_tree_node_->IsMainFrame()) {
775 render_view_host = frame_tree->CreateRenderViewHostForMainFrame(
776 site_instance, view_routing_id, frame_routing_id, swapped_out, hidden);
777 } else {
778 render_view_host = frame_tree->GetRenderViewHostForSubFrame(site_instance);
779 }
780
781 // TODO(creis): Make render_frame_host a scoped_ptr.
782 // TODO(creis): Pass hidden to RFH.
783 RenderFrameHostImpl* render_frame_host =
784 RenderFrameHostFactory::Create(render_view_host,
785 render_frame_delegate_,
786 frame_tree,
787 frame_tree_node_,
788 frame_routing_id,
789 swapped_out).release();
790 return render_frame_host;
791 }
792
793 int RenderFrameHostManager::CreateRenderFrame(
794 SiteInstance* instance, 725 SiteInstance* instance,
795 int opener_route_id, 726 int opener_route_id,
796 bool swapped_out, 727 bool swapped_out,
797 bool hidden) { 728 bool hidden) {
798 CHECK(instance); 729 CHECK(instance);
799 DCHECK(!swapped_out || hidden); // Swapped out views should always be hidden. 730 DCHECK(!swapped_out || hidden); // Swapped out views should always be hidden.
800 731
801 // We are creating a pending or swapped out RFH here. We should never create 732 // We are creating a pending or swapped out RVH here. We should never create
802 // it in the same SiteInstance as our current RFH. 733 // it in the same SiteInstance as our current RVH.
803 CHECK_NE(render_frame_host_->render_view_host()->GetSiteInstance(), instance); 734 CHECK_NE(render_view_host_->GetSiteInstance(), instance);
804 735
805 // Check if we've already created an RFH for this SiteInstance. If so, try 736 // Check if we've already created an RVH for this SiteInstance. If so, try
806 // to re-use the existing one, which has already been initialized. We'll 737 // to re-use the existing one, which has already been initialized. We'll
807 // remove it from the list of swapped out hosts if it commits. 738 // remove it from the list of swapped out hosts if it commits.
808 RenderFrameHostImpl* new_render_frame_host = 739 RenderViewHostImpl* new_render_view_host = static_cast<RenderViewHostImpl*>(
809 GetSwappedOutRenderFrameHost(instance); 740 GetSwappedOutRenderViewHost(instance));
810 if (new_render_frame_host) { 741 if (new_render_view_host) {
811 // Prevent the process from exiting while we're trying to use it. 742 // Prevent the process from exiting while we're trying to use it.
812 if (!swapped_out) 743 if (!swapped_out)
813 new_render_frame_host->GetProcess()->AddPendingView(); 744 new_render_view_host->GetProcess()->AddPendingView();
814 } else { 745 } else {
815 // Create a new RenderFrameHost if we don't find an existing one. 746 // Create a new RenderViewHost if we don't find an existing one.
816 // TODO(creis): Make new_render_frame_host a scoped_ptr. 747 new_render_view_host = static_cast<RenderViewHostImpl*>(
817 new_render_frame_host = CreateRenderFrameHost(instance, MSG_ROUTING_NONE, 748 RenderViewHostFactory::Create(instance,
818 MSG_ROUTING_NONE, swapped_out, 749 render_view_delegate_,
819 hidden); 750 render_frame_delegate_,
751 render_widget_delegate_,
752 MSG_ROUTING_NONE,
753 MSG_ROUTING_NONE,
754 swapped_out,
755 hidden));
820 756
821 // If the new RFH is swapped out already, store it. Otherwise prevent the 757 // If the new RVH is swapped out already, store it. Otherwise prevent the
822 // process from exiting while we're trying to navigate in it. 758 // process from exiting while we're trying to navigate in it.
823 if (swapped_out) { 759 if (swapped_out) {
824 swapped_out_hosts_[instance->GetId()] = new_render_frame_host; 760 swapped_out_hosts_[instance->GetId()] = new_render_view_host;
825 } else { 761 } else {
826 new_render_frame_host->GetProcess()->AddPendingView(); 762 new_render_view_host->GetProcess()->AddPendingView();
827 } 763 }
828 764
829 RenderViewHostImpl* render_view_host = 765 bool success = InitRenderView(new_render_view_host, opener_route_id);
830 new_render_frame_host->render_view_host(); 766 if (success) {
831 bool success = InitRenderView(render_view_host, opener_route_id); 767 // Don't show the view until we get a DidNavigate from it.
832 if (success && frame_tree_node_->IsMainFrame()) { 768 new_render_view_host->GetView()->Hide();
833 // Don't show the main frame's view until we get a DidNavigate from it.
834 render_view_host->GetView()->Hide();
835 } else if (!swapped_out) { 769 } else if (!swapped_out) {
836 CancelPending(); 770 CancelPending();
837 } 771 }
838 } 772 }
839 773
840 // Use this as our new pending RFH if it isn't swapped out. 774 // Use this as our new pending RVH if it isn't swapped out.
841 if (!swapped_out) 775 if (!swapped_out)
842 pending_render_frame_host_ = new_render_frame_host; 776 pending_render_view_host_ = new_render_view_host;
843 777
844 return new_render_frame_host->render_view_host()->GetRoutingID(); 778 return new_render_view_host->GetRoutingID();
845 } 779 }
846 780
847 bool RenderFrameHostManager::InitRenderView(RenderViewHost* render_view_host, 781 bool RenderFrameHostManager::InitRenderView(RenderViewHost* render_view_host,
848 int opener_route_id) { 782 int opener_route_id) {
849 // We may have initialized this RenderViewHost for another RenderFrameHost.
850 if (render_view_host->IsRenderViewLive())
851 return true;
852
853 // If the pending navigation is to a WebUI and the RenderView is not in a 783 // If the pending navigation is to a WebUI and the RenderView is not in a
854 // guest process, tell the RenderViewHost about any bindings it will need 784 // guest process, tell the RenderView about any bindings it will need enabled.
855 // enabled.
856 if (pending_web_ui() && !render_view_host->GetProcess()->IsGuest()) { 785 if (pending_web_ui() && !render_view_host->GetProcess()->IsGuest()) {
857 render_view_host->AllowBindings(pending_web_ui()->GetBindings()); 786 render_view_host->AllowBindings(pending_web_ui()->GetBindings());
858 } else { 787 } else {
859 // Ensure that we don't create an unprivileged RenderView in a WebUI-enabled 788 // Ensure that we don't create an unprivileged RenderView in a WebUI-enabled
860 // process unless it's swapped out. 789 // process unless it's swapped out.
861 RenderViewHostImpl* rvh_impl = 790 RenderViewHostImpl* rvh_impl =
862 static_cast<RenderViewHostImpl*>(render_view_host); 791 static_cast<RenderViewHostImpl*>(render_view_host);
863 if (!rvh_impl->is_swapped_out()) { 792 if (!rvh_impl->is_swapped_out()) {
864 CHECK(!ChildProcessSecurityPolicyImpl::GetInstance()->HasWebUIBindings( 793 CHECK(!ChildProcessSecurityPolicyImpl::GetInstance()->HasWebUIBindings(
865 render_view_host->GetProcess()->GetID())); 794 render_view_host->GetProcess()->GetID()));
(...skipping 20 matching lines...) Expand all
886 815
887 // Next commit the Web UI, if any. Either replace |web_ui_| with 816 // Next commit the Web UI, if any. Either replace |web_ui_| with
888 // |pending_web_ui_|, or clear |web_ui_| if there is no pending WebUI, or 817 // |pending_web_ui_|, or clear |web_ui_| if there is no pending WebUI, or
889 // leave |web_ui_| as is if reusing it. 818 // leave |web_ui_| as is if reusing it.
890 DCHECK(!(pending_web_ui_.get() && pending_and_current_web_ui_.get())); 819 DCHECK(!(pending_web_ui_.get() && pending_and_current_web_ui_.get()));
891 if (pending_web_ui_) 820 if (pending_web_ui_)
892 web_ui_.reset(pending_web_ui_.release()); 821 web_ui_.reset(pending_web_ui_.release());
893 else if (!pending_and_current_web_ui_.get()) 822 else if (!pending_and_current_web_ui_.get())
894 web_ui_.reset(); 823 web_ui_.reset();
895 824
896 // It's possible for the pending_render_frame_host_ to be NULL when we aren't 825 // It's possible for the pending_render_view_host_ to be NULL when we aren't
897 // crossing process boundaries. If so, we just needed to handle the Web UI 826 // crossing process boundaries. If so, we just needed to handle the Web UI
898 // committing above and we're done. 827 // committing above and we're done.
899 if (!pending_render_frame_host_) { 828 if (!pending_render_view_host_) {
900 if (will_focus_location_bar) 829 if (will_focus_location_bar)
901 delegate_->SetFocusToLocationBar(false); 830 delegate_->SetFocusToLocationBar(false);
902 return; 831 return;
903 } 832 }
904 833
905 // Remember if the page was focused so we can focus the new renderer in 834 // Remember if the page was focused so we can focus the new renderer in
906 // that case. 835 // that case.
907 bool focus_render_view = !will_focus_location_bar && 836 bool focus_render_view = !will_focus_location_bar &&
908 render_frame_host_->render_view_host()->GetView() && 837 render_view_host_->GetView() && render_view_host_->GetView()->HasFocus();
909 render_frame_host_->render_view_host()->GetView()->HasFocus();
910 838
911 // Swap in the pending frame and make it active. Also ensure the FrameTree 839 // Swap in the pending view and make it active. Also ensure the FrameTree
912 // stays in sync. 840 // stays in sync.
913 RenderFrameHostImpl* old_render_frame_host = render_frame_host_; 841 RenderViewHostImpl* old_render_view_host = render_view_host_;
914 render_frame_host_ = pending_render_frame_host_; 842 render_view_host_ = pending_render_view_host_;
915 pending_render_frame_host_ = NULL; 843 pending_render_view_host_ = NULL;
916 render_frame_host_->render_view_host()->AttachToFrameTree(); 844 render_view_host_->AttachToFrameTree();
917 845
918 // The process will no longer try to exit, so we can decrement the count. 846 // The process will no longer try to exit, so we can decrement the count.
919 render_frame_host_->GetProcess()->RemovePendingView(); 847 render_view_host_->GetProcess()->RemovePendingView();
920
921 // TODO(creis): As long as show/hide are on RVH, we don't want to do them for
922 // subframe navigations or they'll interfere with the top-level page.
923 bool is_main_frame = frame_tree_node_->IsMainFrame();
924 848
925 // If the view is gone, then this RenderViewHost died while it was hidden. 849 // If the view is gone, then this RenderViewHost died while it was hidden.
926 // We ignored the RenderProcessGone call at the time, so we should send it now 850 // We ignored the RenderProcessGone call at the time, so we should send it now
927 // to make sure the sad tab shows up, etc. 851 // to make sure the sad tab shows up, etc.
928 if (!render_frame_host_->render_view_host()->GetView()) { 852 if (!render_view_host_->GetView())
929 delegate_->RenderProcessGoneFromRenderManager( 853 delegate_->RenderProcessGoneFromRenderManager(render_view_host_);
930 render_frame_host_->render_view_host()); 854 else if (!delegate_->IsHidden())
931 } else if (!delegate_->IsHidden() && is_main_frame) { 855 render_view_host_->GetView()->Show();
932 render_frame_host_->render_view_host()->GetView()->Show();
933 }
934 856
935 // Hide the old view now that the new one is visible. 857 // Hide the old view now that the new one is visible.
936 if (old_render_frame_host->render_view_host()->GetView()) { 858 if (old_render_view_host->GetView()) {
937 old_render_frame_host->render_view_host()->GetView()->Hide(); 859 old_render_view_host->GetView()->Hide();
938 old_render_frame_host->render_view_host()->WasSwappedOut(); 860 old_render_view_host->WasSwappedOut();
939 } 861 }
940 862
941 // Make sure the size is up to date. (Fix for bug 1079768.) 863 // Make sure the size is up to date. (Fix for bug 1079768.)
942 delegate_->UpdateRenderViewSizeForRenderManager(); 864 delegate_->UpdateRenderViewSizeForRenderManager();
943 865
944 if (will_focus_location_bar) { 866 if (will_focus_location_bar)
945 delegate_->SetFocusToLocationBar(false); 867 delegate_->SetFocusToLocationBar(false);
946 } else if (focus_render_view && 868 else if (focus_render_view && render_view_host_->GetView())
947 render_frame_host_->render_view_host()->GetView()) { 869 RenderWidgetHostViewPort::FromRWHV(render_view_host_->GetView())->Focus();
948 RenderWidgetHostViewPort::FromRWHV(
949 render_frame_host_->render_view_host()->GetView())->Focus();
950 }
951 870
952 // Notify that we've swapped RenderFrameHosts. We do this before shutting down 871 // Notify that we've swapped RenderViewHosts. We do this
953 // the RFH so that we can clean up RendererResources related to the RFH first. 872 // before shutting down the RVH so that we can clean up
954 // TODO(creis): Only do this on top-level RFHs for now, and later update it to 873 // RendererResources related to the RVH first.
955 // pass the RFHs. 874 delegate_->NotifySwappedFromRenderManager(old_render_view_host,
956 if (is_main_frame) { 875 render_view_host_);
957 delegate_->NotifySwappedFromRenderManager(
958 old_render_frame_host->render_view_host(),
959 render_frame_host_->render_view_host());
960 }
961 876
962 // If the pending frame was on the swapped out list, we can remove it. 877 // If the pending view was on the swapped out list, we can remove it.
963 swapped_out_hosts_.erase(render_frame_host_->render_view_host()-> 878 swapped_out_hosts_.erase(render_view_host_->GetSiteInstance()->GetId());
964 GetSiteInstance()->GetId());
965 879
966 if (old_render_frame_host->render_view_host()->IsRenderViewLive()) { 880 // If there are no active RVHs in this SiteInstance, it means that
967 // If the old RFH is live, we are swapping it out and should keep track of 881 // this RVH was the last active one in the SiteInstance. Now that we
882 // know that all RVHs are swapped out, we can delete all the RVHs in
883 // this SiteInstance.
884 if (!static_cast<SiteInstanceImpl*>(old_render_view_host->GetSiteInstance())->
885 active_view_count()) {
886 ShutdownRenderViewHostsInSiteInstance(
887 old_render_view_host->GetSiteInstance()->GetId());
888 // This is deleted while cleaning up the SitaInstance's views.
889 old_render_view_host = NULL;
890 } else if (old_render_view_host->IsRenderViewLive()) {
891 // If the old RVH is live, we are swapping it out and should keep track of
968 // it in case we navigate back to it. 892 // it in case we navigate back to it.
969 DCHECK(old_render_frame_host->render_view_host()->is_swapped_out()); 893 DCHECK(old_render_view_host->is_swapped_out());
970 // Temp fix for http://crbug.com/90867 until we do a better cleanup to make 894 // Temp fix for http://crbug.com/90867 until we do a better cleanup to make
971 // sure we don't get different rvh instances for the same site instance 895 // sure we don't get different rvh instances for the same site instance
972 // in the same rvhmgr. 896 // in the same rvhmgr.
973 // TODO(creis): Clean this up. 897 // TODO(creis): Clean this up.
974 int32 old_site_instance_id = 898 int32 old_site_instance_id =
975 old_render_frame_host->render_view_host()->GetSiteInstance()->GetId(); 899 old_render_view_host->GetSiteInstance()->GetId();
976 RenderFrameHostMap::iterator iter = 900 RenderViewHostMap::iterator iter =
977 swapped_out_hosts_.find(old_site_instance_id); 901 swapped_out_hosts_.find(old_site_instance_id);
978 if (iter != swapped_out_hosts_.end() && 902 if (iter != swapped_out_hosts_.end() &&
979 iter->second != old_render_frame_host) { 903 iter->second != old_render_view_host) {
980 // Delete the RFH that will be replaced in the map to avoid a leak. 904 // Shutdown the RVH that will be replaced in the map to avoid a leak.
981 delete iter->second; 905 iter->second->Shutdown();
982 } 906 }
983 swapped_out_hosts_[old_site_instance_id] = old_render_frame_host; 907 swapped_out_hosts_[old_site_instance_id] = old_render_view_host;
984
985 // If there are no active views in this SiteInstance, it means that
986 // this RFH was the last active one in the SiteInstance. Now that we
987 // know that all RFHs are swapped out, we can delete all the RFHs and RVHs
988 // in this SiteInstance. We do this after ensuring the RFH is on the
989 // swapped out list to simplify the deletion.
990 if (!static_cast<SiteInstanceImpl*>(
991 old_render_frame_host->render_view_host()->GetSiteInstance())->
992 active_view_count()) {
993 ShutdownRenderFrameHostsInSiteInstance(old_site_instance_id);
994 // This is deleted while cleaning up the SiteInstance's views.
995 old_render_frame_host = NULL;
996 }
997 } else { 908 } else {
998 delete old_render_frame_host; 909 old_render_view_host->Shutdown();
910 old_render_view_host = NULL; // Shutdown() deletes it.
999 } 911 }
1000 } 912 }
1001 913
1002 void RenderFrameHostManager::ShutdownRenderFrameHostsInSiteInstance( 914 void RenderFrameHostManager::ShutdownRenderViewHostsInSiteInstance(
1003 int32 site_instance_id) { 915 int32 site_instance_id) {
1004 // First remove any swapped out RFH for this SiteInstance from our own list. 916 // First remove any swapped out RVH for this SiteInstance from our
1005 ClearSwappedOutRFHsInSiteInstance(site_instance_id, frame_tree_node_); 917 // list.
918 swapped_out_hosts_.erase(site_instance_id);
1006 919
1007 // Use the safe RenderWidgetHost iterator for now to find all RenderViewHosts
1008 // in the SiteInstance, then tell their respective FrameTrees to remove all
1009 // swapped out RenderFrameHosts corresponding to them.
1010 // TODO(creis): Replace this with a RenderFrameHostIterator that protects
1011 // against use-after-frees if a later element is deleted before getting to it.
1012 scoped_ptr<RenderWidgetHostIterator> widgets( 920 scoped_ptr<RenderWidgetHostIterator> widgets(
1013 RenderWidgetHostImpl::GetAllRenderWidgetHosts()); 921 RenderWidgetHostImpl::GetAllRenderWidgetHosts());
1014 while (RenderWidgetHost* widget = widgets->GetNextHost()) { 922 while (RenderWidgetHost* widget = widgets->GetNextHost()) {
1015 if (!widget->IsRenderView()) 923 if (!widget->IsRenderView())
1016 continue; 924 continue;
1017 RenderViewHostImpl* rvh = 925 RenderViewHostImpl* rvh =
1018 static_cast<RenderViewHostImpl*>(RenderViewHost::From(widget)); 926 static_cast<RenderViewHostImpl*>(RenderViewHost::From(widget));
1019 if (site_instance_id == rvh->GetSiteInstance()->GetId()) { 927 if (site_instance_id == rvh->GetSiteInstance()->GetId())
1020 // This deletes all RenderFrameHosts using the |rvh|, which then causes 928 rvh->Shutdown();
1021 // |rvh| to Shutdown.
1022 FrameTree* tree = rvh->GetDelegate()->GetFrameTree();
1023 tree->ForEach(base::Bind(
1024 &RenderFrameHostManager::ClearSwappedOutRFHsInSiteInstance,
1025 site_instance_id));
1026 // rvh is now deleted.
1027 }
1028 } 929 }
1029 } 930 }
1030 931
1031 RenderFrameHostImpl* RenderFrameHostManager::UpdateRendererStateForNavigate( 932 RenderViewHostImpl* RenderFrameHostManager::UpdateRendererStateForNavigate(
1032 const NavigationEntryImpl& entry) { 933 const NavigationEntryImpl& entry) {
1033 // If we are currently navigating cross-process, we want to get back to normal 934 // If we are currently navigating cross-process, we want to get back to normal
1034 // and then navigate as usual. 935 // and then navigate as usual.
1035 if (cross_navigation_pending_) { 936 if (cross_navigation_pending_) {
1036 if (pending_render_frame_host_) 937 if (pending_render_view_host_)
1037 CancelPending(); 938 CancelPending();
1038 cross_navigation_pending_ = false; 939 cross_navigation_pending_ = false;
1039 } 940 }
1040 941
1041 // render_frame_host_'s SiteInstance and new_instance will not be deleted 942 // render_view_host_'s SiteInstance and new_instance will not be deleted
1042 // before the end of this method, so we don't have to worry about their ref 943 // before the end of this method, so we don't have to worry about their ref
1043 // counts dropping to zero. 944 // counts dropping to zero.
1044 SiteInstance* current_instance = 945 SiteInstance* current_instance = render_view_host_->GetSiteInstance();
1045 render_frame_host_->render_view_host()->GetSiteInstance();
1046 SiteInstance* new_instance = current_instance; 946 SiteInstance* new_instance = current_instance;
1047 947
1048 // We do not currently swap processes for navigations in webview tag guests. 948 // We do not currently swap processes for navigations in webview tag guests.
1049 bool is_guest_scheme = current_instance->GetSiteURL().SchemeIs(kGuestScheme); 949 bool is_guest_scheme = current_instance->GetSiteURL().SchemeIs(kGuestScheme);
1050 950
1051 // Determine if we need a new BrowsingInstance for this entry. If true, this 951 // Determine if we need a new BrowsingInstance for this entry. If true, this
1052 // implies that it will get a new SiteInstance (and likely process), and that 952 // implies that it will get a new SiteInstance (and likely process), and that
1053 // other tabs in the current BrowsingInstance will be unable to script it. 953 // other tabs in the current BrosingInstance will be unalbe to script it.
1054 // This is used for cases that require a process swap even in the 954 // This is used for cases that require a process swap even in the
1055 // process-per-tab model, such as WebUI pages. 955 // process-per-tab model, such as WebUI pages.
1056 const NavigationEntry* current_entry = 956 const NavigationEntry* current_entry =
1057 delegate_->GetLastCommittedNavigationEntryForRenderManager(); 957 delegate_->GetLastCommittedNavigationEntryForRenderManager();
1058 bool force_swap = !is_guest_scheme && 958 bool force_swap = !is_guest_scheme &&
1059 ShouldSwapBrowsingInstancesForNavigation(current_entry, &entry); 959 ShouldSwapBrowsingInstancesForNavigation(current_entry, &entry);
1060 if (!is_guest_scheme && (ShouldTransitionCrossSite() || force_swap)) 960 if (!is_guest_scheme && (ShouldTransitionCrossSite() || force_swap))
1061 new_instance = GetSiteInstanceForEntry(entry, current_instance, force_swap); 961 new_instance = GetSiteInstanceForEntry(entry, current_instance, force_swap);
1062 962
1063 // If force_swap is true, we must use a different SiteInstance. If we didn't, 963 // If force_swap is true, we must use a different SiteInstance. If we didn't,
1064 // we would have two RenderFrameHosts in the same SiteInstance and the same 964 // we would have two RenderViewHosts in the same SiteInstance and the same
1065 // frame, resulting in page_id conflicts for their NavigationEntries. 965 // tab, resulting in page_id conflicts for their NavigationEntries.
1066 if (force_swap) 966 if (force_swap)
1067 CHECK_NE(new_instance, current_instance); 967 CHECK_NE(new_instance, current_instance);
1068 968
1069 if (new_instance != current_instance) { 969 if (new_instance != current_instance) {
1070 // New SiteInstance: create a pending RFH to navigate. 970 // New SiteInstance: create a pending RVH to navigate.
1071 DCHECK(!cross_navigation_pending_); 971 DCHECK(!cross_navigation_pending_);
1072 972
1073 // This will possibly create (set to NULL) a Web UI object for the pending 973 // This will possibly create (set to NULL) a Web UI object for the pending
1074 // page. We'll use this later to give the page special access. This must 974 // page. We'll use this later to give the page special access. This must
1075 // happen before the new renderer is created below so it will get bindings. 975 // happen before the new renderer is created below so it will get bindings.
1076 // It must also happen after the above conditional call to CancelPending(), 976 // It must also happen after the above conditional call to CancelPending(),
1077 // otherwise CancelPending may clear the pending_web_ui_ and the page will 977 // otherwise CancelPending may clear the pending_web_ui_ and the page will
1078 // not have its bindings set appropriately. 978 // not have its bindings set appropriately.
1079 SetPendingWebUI(entry); 979 SetPendingWebUI(entry);
1080 980
1081 // Ensure that we have created RFHs for the new RFH's opener chain if 981 // Ensure that we have created RVHs for the new RVH's opener chain if
1082 // we are staying in the same BrowsingInstance. This allows the pending RFH 982 // we are staying in the same BrowsingInstance. This allows the pending RVH
1083 // to send cross-process script calls to its opener(s). 983 // to send cross-process script calls to its opener(s).
1084 int opener_route_id = MSG_ROUTING_NONE; 984 int opener_route_id = MSG_ROUTING_NONE;
1085 if (new_instance->IsRelatedSiteInstance(current_instance)) { 985 if (new_instance->IsRelatedSiteInstance(current_instance)) {
1086 opener_route_id = 986 opener_route_id =
1087 delegate_->CreateOpenerRenderViewsForRenderManager(new_instance); 987 delegate_->CreateOpenerRenderViewsForRenderManager(new_instance);
1088 } 988 }
1089 989
1090 // Create a non-swapped-out pending RFH with the given opener and navigate 990 // Create a non-swapped-out pending RVH with the given opener and navigate
1091 // it. 991 // it.
1092 int route_id = CreateRenderFrame(new_instance, opener_route_id, false, 992 int route_id = CreateRenderView(new_instance, opener_route_id, false,
1093 delegate_->IsHidden()); 993 delegate_->IsHidden());
1094 if (route_id == MSG_ROUTING_NONE) 994 if (route_id == MSG_ROUTING_NONE)
1095 return NULL; 995 return NULL;
1096 996
1097 // Check if our current RFH is live before we set up a transition. 997 // Check if our current RVH is live before we set up a transition.
1098 if (!render_frame_host_->render_view_host()->IsRenderViewLive()) { 998 if (!render_view_host_->IsRenderViewLive()) {
1099 if (!cross_navigation_pending_) { 999 if (!cross_navigation_pending_) {
1100 // The current RFH is not live. There's no reason to sit around with a 1000 // The current RVH is not live. There's no reason to sit around with a
1101 // sad tab or a newly created RFH while we wait for the pending RFH to 1001 // sad tab or a newly created RVH while we wait for the pending RVH to
1102 // navigate. Just switch to the pending RFH now and go back to non 1002 // navigate. Just switch to the pending RVH now and go back to non
1103 // cross-navigating (Note that we don't care about on{before}unload 1003 // cross-navigating (Note that we don't care about on{before}unload
1104 // handlers if the current RFH isn't live.) 1004 // handlers if the current RVH isn't live.)
1105 CommitPending(); 1005 CommitPending();
1106 return render_frame_host_; 1006 return render_view_host_;
1107 } else { 1007 } else {
1108 NOTREACHED(); 1008 NOTREACHED();
1109 return render_frame_host_; 1009 return render_view_host_;
1110 } 1010 }
1111 } 1011 }
1112 // Otherwise, it's safe to treat this as a pending cross-site transition. 1012 // Otherwise, it's safe to treat this as a pending cross-site transition.
1113 1013
1114 // We need to wait until the beforeunload handler has run, unless we are 1014 // We need to wait until the beforeunload handler has run, unless we are
1115 // transferring an existing request (in which case it has already run). 1015 // transferring an existing request (in which case it has already run).
1116 // Suspend the new render view (i.e., don't let it send the cross-site 1016 // Suspend the new render view (i.e., don't let it send the cross-site
1117 // Navigate message) until we hear back from the old renderer's 1017 // Navigate message) until we hear back from the old renderer's
1118 // beforeunload handler. If the handler returns false, we'll have to 1018 // beforeunload handler. If the handler returns false, we'll have to
1119 // cancel the request. 1019 // cancel the request.
1120 DCHECK(!pending_render_frame_host_->render_view_host()-> 1020 DCHECK(!pending_render_view_host_->are_navigations_suspended());
1121 are_navigations_suspended());
1122 bool is_transfer = 1021 bool is_transfer =
1123 entry.transferred_global_request_id() != GlobalRequestID(); 1022 entry.transferred_global_request_id() != GlobalRequestID();
1124 if (is_transfer) { 1023 if (is_transfer) {
1125 // We don't need to stop the old renderer or run beforeunload/unload 1024 // We don't need to stop the old renderer or run beforeunload/unload
1126 // handlers, because those have already been done. 1025 // handlers, because those have already been done.
1127 DCHECK(pending_nav_params_->global_request_id == 1026 DCHECK(pending_nav_params_->global_request_id ==
1128 entry.transferred_global_request_id()); 1027 entry.transferred_global_request_id());
1129 } else { 1028 } else {
1130 // Also make sure the old render view stops, in case a load is in 1029 // Also make sure the old render view stops, in case a load is in
1131 // progress. (We don't want to do this for transfers, since it will 1030 // progress. (We don't want to do this for transfers, since it will
1132 // interrupt the transfer with an unexpected DidStopLoading.) 1031 // interrupt the transfer with an unexpected DidStopLoading.)
1133 render_frame_host_->render_view_host()->Send(new ViewMsg_Stop( 1032 render_view_host_->Send(
1134 render_frame_host_->render_view_host()->GetRoutingID())); 1033 new ViewMsg_Stop(render_view_host_->GetRoutingID()));
1135 1034
1136 pending_render_frame_host_->render_view_host()->SetNavigationsSuspended( 1035 pending_render_view_host_->SetNavigationsSuspended(true,
1137 true, base::TimeTicks()); 1036 base::TimeTicks());
1138 1037
1139 // Tell the CrossSiteRequestManager that this RVH has a pending cross-site 1038 // Tell the CrossSiteRequestManager that this RVH has a pending cross-site
1140 // request, so that ResourceDispatcherHost will know to tell us to run the 1039 // request, so that ResourceDispatcherHost will know to tell us to run the
1141 // old page's unload handler before it sends the response. 1040 // old page's unload handler before it sends the response.
1142 // TODO(creis): This needs to be on the RFH. 1041 pending_render_view_host_->SetHasPendingCrossSiteRequest(true);
1143 pending_render_frame_host_->render_view_host()->
1144 SetHasPendingCrossSiteRequest(true);
1145 } 1042 }
1146 1043
1147 // We now have a pending RFH. 1044 // We now have a pending RVH.
1148 DCHECK(!cross_navigation_pending_); 1045 DCHECK(!cross_navigation_pending_);
1149 cross_navigation_pending_ = true; 1046 cross_navigation_pending_ = true;
1150 1047
1151 // Unless we are transferring an existing request, we should now 1048 // Unless we are transferring an existing request, we should now
1152 // tell the old render view to run its beforeunload handler, since it 1049 // tell the old render view to run its beforeunload handler, since it
1153 // doesn't otherwise know that the cross-site request is happening. This 1050 // doesn't otherwise know that the cross-site request is happening. This
1154 // will trigger a call to ShouldClosePage with the reply. 1051 // will trigger a call to ShouldClosePage with the reply.
1155 if (!is_transfer) 1052 if (!is_transfer)
1156 render_frame_host_->render_view_host()->FirePageBeforeUnload(true); 1053 render_view_host_->FirePageBeforeUnload(true);
1157 1054
1158 return pending_render_frame_host_; 1055 return pending_render_view_host_;
1159 } 1056 }
1160 1057
1161 // Otherwise the same SiteInstance can be used. Navigate render_frame_host_. 1058 // Otherwise the same SiteInstance can be used. Navigate render_view_host_.
1162 DCHECK(!cross_navigation_pending_); 1059 DCHECK(!cross_navigation_pending_);
1163 if (ShouldReuseWebUI(current_entry, &entry)) { 1060 if (ShouldReuseWebUI(current_entry, &entry)) {
1164 pending_web_ui_.reset(); 1061 pending_web_ui_.reset();
1165 pending_and_current_web_ui_ = web_ui_->AsWeakPtr(); 1062 pending_and_current_web_ui_ = web_ui_->AsWeakPtr();
1166 } else { 1063 } else {
1167 SetPendingWebUI(entry); 1064 SetPendingWebUI(entry);
1168 1065
1169 // Make sure the new RenderViewHost has the right bindings. 1066 // Make sure the new RenderViewHost has the right bindings.
1170 if (pending_web_ui() && !render_frame_host_->GetProcess()->IsGuest()) { 1067 if (pending_web_ui() && !render_view_host_->GetProcess()->IsGuest())
1171 render_frame_host_->render_view_host()->AllowBindings( 1068 render_view_host_->AllowBindings(pending_web_ui()->GetBindings());
1172 pending_web_ui()->GetBindings());
1173 }
1174 } 1069 }
1175 1070
1176 if (pending_web_ui() && 1071 if (pending_web_ui() && render_view_host_->IsRenderViewLive())
1177 render_frame_host_->render_view_host()->IsRenderViewLive()) { 1072 pending_web_ui()->GetController()->RenderViewReused(render_view_host_);
1178 pending_web_ui()->GetController()->RenderViewReused(
1179 render_frame_host_->render_view_host());
1180 }
1181 1073
1182 // The renderer can exit view source mode when any error or cancellation 1074 // The renderer can exit view source mode when any error or cancellation
1183 // happen. We must overwrite to recover the mode. 1075 // happen. We must overwrite to recover the mode.
1184 if (entry.IsViewSourceMode()) { 1076 if (entry.IsViewSourceMode()) {
1185 render_frame_host_->render_view_host()->Send( 1077 render_view_host_->Send(
1186 new ViewMsg_EnableViewSourceMode( 1078 new ViewMsg_EnableViewSourceMode(render_view_host_->GetRoutingID()));
1187 render_frame_host_->render_view_host()->GetRoutingID()));
1188 } 1079 }
1189 1080
1190 return render_frame_host_; 1081 return render_view_host_;
1191 } 1082 }
1192 1083
1193 void RenderFrameHostManager::CancelPending() { 1084 void RenderFrameHostManager::CancelPending() {
1194 RenderFrameHostImpl* pending_render_frame_host = pending_render_frame_host_; 1085 RenderViewHostImpl* pending_render_view_host = pending_render_view_host_;
1195 pending_render_frame_host_ = NULL; 1086 pending_render_view_host_ = NULL;
1196 1087
1197 RenderViewDevToolsAgentHost::OnCancelPendingNavigation( 1088 RenderViewDevToolsAgentHost::OnCancelPendingNavigation(
1198 pending_render_frame_host->render_view_host(), 1089 pending_render_view_host,
1199 render_frame_host_->render_view_host()); 1090 render_view_host_);
1200 1091
1201 // We no longer need to prevent the process from exiting. 1092 // We no longer need to prevent the process from exiting.
1202 pending_render_frame_host->GetProcess()->RemovePendingView(); 1093 pending_render_view_host->GetProcess()->RemovePendingView();
1203 1094
1204 // The pending RFH may already be on the swapped out list if we started to 1095 // The pending RVH may already be on the swapped out list if we started to
1205 // swap it back in and then canceled. If so, make sure it gets swapped out 1096 // swap it back in and then canceled. If so, make sure it gets swapped out
1206 // again. If it's not on the swapped out list (e.g., aborting a pending 1097 // again. If it's not on the swapped out list (e.g., aborting a pending
1207 // load), then it's safe to shut down. 1098 // load), then it's safe to shut down.
1208 if (IsOnSwappedOutList(pending_render_frame_host)) { 1099 if (IsOnSwappedOutList(pending_render_view_host)) {
1209 // Any currently suspended navigations are no longer needed. 1100 // Any currently suspended navigations are no longer needed.
1210 pending_render_frame_host->render_view_host()->CancelSuspendedNavigations(); 1101 pending_render_view_host->CancelSuspendedNavigations();
1211 1102
1212 // TODO(creis): We need to swap out the RFH. 1103 pending_render_view_host->SwapOut();
1213 pending_render_frame_host->render_view_host()->SwapOut();
1214 } else { 1104 } else {
1215 // We won't be coming back, so shut this one down. 1105 // We won't be coming back, so shut this one down.
1216 delete pending_render_frame_host; 1106 pending_render_view_host->Shutdown();
1217 } 1107 }
1218 1108
1219 pending_web_ui_.reset(); 1109 pending_web_ui_.reset();
1220 pending_and_current_web_ui_.reset(); 1110 pending_and_current_web_ui_.reset();
1221 } 1111 }
1222 1112
1223 void RenderFrameHostManager::RenderViewDeleted(RenderViewHost* rvh) { 1113 void RenderFrameHostManager::RenderViewDeleted(RenderViewHost* rvh) {
1224 // We are doing this in order to work around and to track a crasher 1114 // We are doing this in order to work around and to track a crasher
1225 // (http://crbug.com/23411) where it seems that pending_render_frame_host_ is 1115 // (http://crbug.com/23411) where it seems that pending_render_view_host_ is
1226 // deleted (not sure from where) but not NULLed. 1116 // deleted (not sure from where) but not NULLed.
1227 if (pending_render_frame_host_ && 1117 if (rvh == pending_render_view_host_) {
1228 rvh == pending_render_frame_host_->render_view_host()) {
1229 // If you hit this NOTREACHED, please report it in the following bug 1118 // If you hit this NOTREACHED, please report it in the following bug
1230 // http://crbug.com/23411 Make sure to include what you were doing when it 1119 // http://crbug.com/23411 Make sure to include what you were doing when it
1231 // happened (navigating to a new page, closing a tab...) and if you can 1120 // happened (navigating to a new page, closing a tab...) and if you can
1232 // reproduce. 1121 // reproduce.
1233 NOTREACHED(); 1122 NOTREACHED();
1234 pending_render_frame_host_ = NULL; 1123 pending_render_view_host_ = NULL;
1235 } 1124 }
1236 1125
1237 // Make sure deleted RVHs are not kept in the swapped out list while we are 1126 // Make sure deleted RVHs are not kept in the swapped out list while we are
1238 // still alive. (If render_frame_host_ is null, we're already being deleted.) 1127 // still alive. (If render_view_host_ is null, we're already being deleted.)
1239 if (!render_frame_host_) 1128 if (!render_view_host_)
1240 return; 1129 return;
1241
1242 // We can't look it up by SiteInstance ID, which may no longer be valid. 1130 // We can't look it up by SiteInstance ID, which may no longer be valid.
1243 for (RenderFrameHostMap::iterator iter = swapped_out_hosts_.begin(); 1131 for (RenderViewHostMap::iterator iter = swapped_out_hosts_.begin();
1244 iter != swapped_out_hosts_.end(); 1132 iter != swapped_out_hosts_.end();
1245 ++iter) { 1133 ++iter) {
1246 if (iter->second->render_view_host() == rvh) { 1134 if (iter->second == rvh) {
1247 swapped_out_hosts_.erase(iter); 1135 swapped_out_hosts_.erase(iter);
1248 break; 1136 break;
1249 } 1137 }
1250 } 1138 }
1251 } 1139 }
1252 1140
1253 bool RenderFrameHostManager::IsRVHOnSwappedOutList( 1141 bool RenderFrameHostManager::IsOnSwappedOutList(RenderViewHost* rvh) const {
1254 RenderViewHostImpl* rvh) const { 1142 if (!rvh->GetSiteInstance())
1255 RenderFrameHostImpl* render_frame_host = GetSwappedOutRenderFrameHost(
1256 rvh->GetSiteInstance());
1257 if (!render_frame_host)
1258 return false;
1259 return IsOnSwappedOutList(render_frame_host);
1260 }
1261
1262 bool RenderFrameHostManager::IsOnSwappedOutList(
1263 RenderFrameHostImpl* rfh) const {
1264 if (!rfh->render_view_host()->GetSiteInstance())
1265 return false; 1143 return false;
1266 1144
1267 RenderFrameHostMap::const_iterator iter = swapped_out_hosts_.find( 1145 RenderViewHostMap::const_iterator iter = swapped_out_hosts_.find(
1268 rfh->render_view_host()->GetSiteInstance()->GetId()); 1146 rvh->GetSiteInstance()->GetId());
1269 if (iter == swapped_out_hosts_.end()) 1147 if (iter == swapped_out_hosts_.end())
1270 return false; 1148 return false;
1271 1149
1272 return iter->second == rfh; 1150 return iter->second == rvh;
1273 } 1151 }
1274 1152
1275 RenderViewHostImpl* RenderFrameHostManager::GetSwappedOutRenderViewHost( 1153 RenderViewHostImpl* RenderFrameHostManager::GetSwappedOutRenderViewHost(
1276 SiteInstance* instance) const { 1154 SiteInstance* instance) {
1277 RenderFrameHostImpl* render_frame_host = 1155 RenderViewHostMap::iterator iter = swapped_out_hosts_.find(instance->GetId());
1278 GetSwappedOutRenderFrameHost(instance);
1279 if (render_frame_host)
1280 return render_frame_host->render_view_host();
1281 return NULL;
1282 }
1283
1284 RenderFrameHostImpl* RenderFrameHostManager::GetSwappedOutRenderFrameHost(
1285 SiteInstance* instance) const {
1286 RenderFrameHostMap::const_iterator iter =
1287 swapped_out_hosts_.find(instance->GetId());
1288 if (iter != swapped_out_hosts_.end()) 1156 if (iter != swapped_out_hosts_.end())
1289 return iter->second; 1157 return iter->second;
1290 1158
1291 return NULL; 1159 return NULL;
1292 } 1160 }
1293 1161
1294 } // namespace content 1162 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698