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

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

Powered by Google App Engine
This is Rietveld 408576698