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

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

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

Powered by Google App Engine
This is Rietveld 408576698