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

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

Issue 9473001: Extract minimal RenderViewHost interface for embedders, leaving (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merge to LKGR. Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/tab_contents/render_view_host_manager.h" 5 #include "content/browser/tab_contents/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/logging.h" 10 #include "base/logging.h"
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 render_view_host_(NULL), 44 render_view_host_(NULL),
45 pending_render_view_host_(NULL), 45 pending_render_view_host_(NULL),
46 interstitial_page_(NULL) { 46 interstitial_page_(NULL) {
47 } 47 }
48 48
49 RenderViewHostManager::~RenderViewHostManager() { 49 RenderViewHostManager::~RenderViewHostManager() {
50 if (pending_render_view_host_) 50 if (pending_render_view_host_)
51 CancelPending(); 51 CancelPending();
52 52
53 // We should always have a main RenderViewHost. 53 // We should always have a main RenderViewHost.
54 RenderViewHost* render_view_host = render_view_host_; 54 RenderViewHostImpl* render_view_host = render_view_host_;
55 render_view_host_ = NULL; 55 render_view_host_ = NULL;
56 render_view_host->Shutdown(); 56 render_view_host->Shutdown();
57 57
58 // Shut down any swapped out RenderViewHosts. 58 // Shut down any swapped out RenderViewHosts.
59 for (RenderViewHostMap::iterator iter = swapped_out_hosts_.begin(); 59 for (RenderViewHostMap::iterator iter = swapped_out_hosts_.begin();
60 iter != swapped_out_hosts_.end(); 60 iter != swapped_out_hosts_.end();
61 ++iter) { 61 ++iter) {
62 iter->second->Shutdown(); 62 iter->second->Shutdown();
63 } 63 }
64 } 64 }
65 65
66 void RenderViewHostManager::Init(content::BrowserContext* browser_context, 66 void RenderViewHostManager::Init(content::BrowserContext* browser_context,
67 SiteInstance* site_instance, 67 SiteInstance* site_instance,
68 int routing_id) { 68 int routing_id) {
69 // Create a RenderViewHost, once we have an instance. It is important to 69 // Create a RenderViewHost, once we have an instance. It is important to
70 // immediately give this SiteInstance to a RenderViewHost so that it is 70 // immediately give this SiteInstance to a RenderViewHost so that it is
71 // ref counted. 71 // ref counted.
72 if (!site_instance) 72 if (!site_instance)
73 site_instance = SiteInstance::Create(browser_context); 73 site_instance = SiteInstance::Create(browser_context);
74 render_view_host_ = RenderViewHostFactory::Create( 74 render_view_host_ = static_cast<RenderViewHostImpl*>(
75 site_instance, render_view_delegate_, routing_id, delegate_-> 75 RenderViewHostFactory::Create(
76 GetControllerForRenderManager().GetSessionStorageNamespace()); 76 site_instance, render_view_delegate_, routing_id, delegate_->
77 GetControllerForRenderManager().GetSessionStorageNamespace()));
77 78
78 // Keep track of renderer processes as they start to shut down. 79 // Keep track of renderer processes as they start to shut down.
79 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_CLOSING, 80 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_CLOSING,
80 content::NotificationService::AllSources()); 81 content::NotificationService::AllSources());
81 } 82 }
82 83
84 RenderViewHostImpl* RenderViewHostManager::current_host() const {
85 return render_view_host_;
86 }
87
88 RenderViewHostImpl* RenderViewHostManager::pending_render_view_host() const {
89 return pending_render_view_host_;
90 }
91
83 RenderWidgetHostView* RenderViewHostManager::GetRenderWidgetHostView() const { 92 RenderWidgetHostView* RenderViewHostManager::GetRenderWidgetHostView() const {
84 if (!render_view_host_) 93 if (!render_view_host_)
85 return NULL; 94 return NULL;
86 return render_view_host_->view(); 95 return render_view_host_->GetView();
87 } 96 }
88 97
89 RenderViewHost* RenderViewHostManager::Navigate( 98 RenderViewHostImpl* RenderViewHostManager::Navigate(
90 const NavigationEntryImpl& entry) { 99 const NavigationEntryImpl& entry) {
91 // Create a pending RenderViewHost. It will give us the one we should use 100 // Create a pending RenderViewHost. It will give us the one we should use
92 RenderViewHost* dest_render_view_host = UpdateRendererStateForNavigate(entry); 101 RenderViewHostImpl* dest_render_view_host =
102 static_cast<RenderViewHostImpl*>(UpdateRendererStateForNavigate(entry));
93 if (!dest_render_view_host) 103 if (!dest_render_view_host)
94 return NULL; // We weren't able to create a pending render view host. 104 return NULL; // We weren't able to create a pending render view host.
95 105
96 // If the current render_view_host_ isn't live, we should create it so 106 // If the current render_view_host_ isn't live, we should create it so
97 // that we don't show a sad tab while the dest_render_view_host fetches 107 // that we don't show a sad tab while the dest_render_view_host fetches
98 // its first page. (Bug 1145340) 108 // its first page. (Bug 1145340)
99 if (dest_render_view_host != render_view_host_ && 109 if (dest_render_view_host != render_view_host_ &&
100 !render_view_host_->IsRenderViewLive()) { 110 !render_view_host_->IsRenderViewLive()) {
101 // Note: we don't call InitRenderView here because we are navigating away 111 // Note: we don't call InitRenderView here because we are navigating away
102 // soon anyway, and we don't have the NavigationEntry for this host. 112 // soon anyway, and we don't have the NavigationEntry for this host.
103 delegate_->CreateRenderViewForRenderManager(render_view_host_); 113 delegate_->CreateRenderViewForRenderManager(render_view_host_);
104 } 114 }
105 115
106 // If the renderer crashed, then try to create a new one to satisfy this 116 // If the renderer crashed, then try to create a new one to satisfy this
107 // navigation request. 117 // navigation request.
108 if (!dest_render_view_host->IsRenderViewLive()) { 118 if (!dest_render_view_host->IsRenderViewLive()) {
109 if (!InitRenderView(dest_render_view_host, entry)) 119 if (!InitRenderView(dest_render_view_host, entry))
110 return NULL; 120 return NULL;
111 121
112 // Now that we've created a new renderer, be sure to hide it if it isn't 122 // Now that we've created a new renderer, be sure to hide it if it isn't
113 // our primary one. Otherwise, we might crash if we try to call Show() 123 // our primary one. Otherwise, we might crash if we try to call Show()
114 // on it later. 124 // on it later.
115 if (dest_render_view_host != render_view_host_ && 125 if (dest_render_view_host != render_view_host_ &&
116 dest_render_view_host->view()) { 126 dest_render_view_host->GetView()) {
117 dest_render_view_host->view()->Hide(); 127 dest_render_view_host->GetView()->Hide();
118 } else { 128 } else {
119 // This is our primary renderer, notify here as we won't be calling 129 // This is our primary renderer, notify here as we won't be calling
120 // CommitPending (which does the notify). 130 // CommitPending (which does the notify).
121 RenderViewHost* null_rvh = NULL; 131 RenderViewHost* null_rvh = NULL;
122 std::pair<RenderViewHost*, RenderViewHost*> details = 132 std::pair<RenderViewHost*, RenderViewHost*> details =
123 std::make_pair(null_rvh, render_view_host_); 133 std::make_pair(null_rvh, render_view_host_);
124 content::NotificationService::current()->Notify( 134 content::NotificationService::current()->Notify(
125 content::NOTIFICATION_RENDER_VIEW_HOST_CHANGED, 135 content::NOTIFICATION_RENDER_VIEW_HOST_CHANGED,
126 content::Source<NavigationController>( 136 content::Source<NavigationController>(
127 &delegate_->GetControllerForRenderManager()), 137 &delegate_->GetControllerForRenderManager()),
128 content::Details<std::pair<RenderViewHost*, RenderViewHost*> >( 138 content::Details<std::pair<RenderViewHost*, RenderViewHost*> >(
129 &details)); 139 &details));
130 } 140 }
131 } 141 }
132 142
133 return dest_render_view_host; 143 return dest_render_view_host;
134 } 144 }
135 145
136 void RenderViewHostManager::Stop() { 146 void RenderViewHostManager::Stop() {
137 render_view_host_->Stop(); 147 render_view_host_->Stop();
138 148
139 // If we are cross-navigating, we should stop the pending renderers. This 149 // If we are cross-navigating, we should stop the pending renderers. This
140 // will lead to a DidFailProvisionalLoad, which will properly destroy them. 150 // will lead to a DidFailProvisionalLoad, which will properly destroy them.
141 if (cross_navigation_pending_) { 151 if (cross_navigation_pending_) {
142 pending_render_view_host_->Send( 152 pending_render_view_host_->Send(
143 new ViewMsg_Stop(pending_render_view_host_->routing_id())); 153 new ViewMsg_Stop(pending_render_view_host_->GetRoutingID()));
144 } 154 }
145 } 155 }
146 156
147 void RenderViewHostManager::SetIsLoading(bool is_loading) { 157 void RenderViewHostManager::SetIsLoading(bool is_loading) {
148 render_view_host_->SetIsLoading(is_loading); 158 render_view_host_->SetIsLoading(is_loading);
149 if (pending_render_view_host_) 159 if (pending_render_view_host_)
150 pending_render_view_host_->SetIsLoading(is_loading); 160 pending_render_view_host_->SetIsLoading(is_loading);
151 } 161 }
152 162
153 bool RenderViewHostManager::ShouldCloseTabOnUnresponsiveRenderer() { 163 bool RenderViewHostManager::ShouldCloseTabOnUnresponsiveRenderer() {
(...skipping 15 matching lines...) Expand all
169 pending_render_view_host_->SetNavigationsSuspended(false); 179 pending_render_view_host_->SetNavigationsSuspended(false);
170 } else { 180 } else {
171 // The request has been started and paused while we're waiting for the 181 // The request has been started and paused while we're waiting for the
172 // unload handler to finish. We'll pretend that it did, by notifying the 182 // unload handler to finish. We'll pretend that it did, by notifying the
173 // IO thread to let the response continue. The pending renderer will then 183 // IO thread to let the response continue. The pending renderer will then
174 // be swapped in as part of the usual DidNavigate logic. (If the unload 184 // be swapped in as part of the usual DidNavigate logic. (If the unload
175 // handler later finishes, this call will be ignored because the state in 185 // handler later finishes, this call will be ignored because the state in
176 // CrossSiteResourceHandler will already be cleaned up.) 186 // CrossSiteResourceHandler will already be cleaned up.)
177 ViewMsg_SwapOut_Params params; 187 ViewMsg_SwapOut_Params params;
178 params.new_render_process_host_id = 188 params.new_render_process_host_id =
179 pending_render_view_host_->process()->GetID(); 189 pending_render_view_host_->GetProcess()->GetID();
180 params.new_request_id = pending_request_id; 190 params.new_request_id = pending_request_id;
181 current_host()->process()->CrossSiteSwapOutACK(params); 191 current_host()->GetProcess()->CrossSiteSwapOutACK(params);
182 } 192 }
183 return false; 193 return false;
184 } 194 }
185 195
186 void RenderViewHostManager::DidNavigateMainFrame( 196 void RenderViewHostManager::DidNavigateMainFrame(
187 RenderViewHost* render_view_host) { 197 RenderViewHost* render_view_host) {
188 if (!cross_navigation_pending_) { 198 if (!cross_navigation_pending_) {
189 DCHECK(!pending_render_view_host_); 199 DCHECK(!pending_render_view_host_);
190 200
191 // We should only hear this from our current renderer. 201 // We should only hear this from our current renderer.
192 DCHECK(render_view_host == render_view_host_); 202 DCHECK(render_view_host == render_view_host_);
193 203
194 // Even when there is no pending RVH, there may be a pending Web UI. 204 // Even when there is no pending RVH, there may be a pending Web UI.
195 if (pending_web_ui_.get()) 205 if (pending_web_ui_.get())
196 CommitPending(); 206 CommitPending();
197 return; 207 return;
198 } 208 }
199 209
200 if (render_view_host == pending_render_view_host_) { 210 if (render_view_host == pending_render_view_host_) {
201 // The pending cross-site navigation completed, so show the renderer. 211 // The pending cross-site navigation completed, so show the renderer.
202 // If it committed without sending network requests (e.g., data URLs), 212 // If it committed without sending network requests (e.g., data URLs),
203 // then we still need to swap out the old RVH first and run its unload 213 // then we still need to swap out the old RVH first and run its unload
204 // handler. OK for that to happen in the background. 214 // handler. OK for that to happen in the background.
205 if (pending_render_view_host_->GetPendingRequestId() == -1) { 215 if (pending_render_view_host_->GetPendingRequestId() == -1) {
206 OnCrossSiteResponse(pending_render_view_host_->process()->GetID(), 216 OnCrossSiteResponse(pending_render_view_host_->GetProcess()->GetID(),
207 pending_render_view_host_->routing_id()); 217 pending_render_view_host_->GetRoutingID());
208 } 218 }
209 219
210 CommitPending(); 220 CommitPending();
211 cross_navigation_pending_ = false; 221 cross_navigation_pending_ = false;
212 } else if (render_view_host == render_view_host_) { 222 } else if (render_view_host == render_view_host_) {
213 // A navigation in the original page has taken place. Cancel the pending 223 // A navigation in the original page has taken place. Cancel the pending
214 // one. 224 // one.
215 CancelPending(); 225 CancelPending();
216 cross_navigation_pending_ = false; 226 cross_navigation_pending_ = false;
217 } else { 227 } else {
(...skipping 23 matching lines...) Expand all
241 251
242 void RenderViewHostManager::RendererProcessClosing( 252 void RenderViewHostManager::RendererProcessClosing(
243 content::RenderProcessHost* render_process_host) { 253 content::RenderProcessHost* render_process_host) {
244 // Remove any swapped out RVHs from this process, so that we don't try to 254 // Remove any swapped out RVHs from this process, so that we don't try to
245 // swap them back in while the process is exiting. Start by finding them, 255 // swap them back in while the process is exiting. Start by finding them,
246 // since there could be more than one. 256 // since there could be more than one.
247 std::list<int> ids_to_remove; 257 std::list<int> ids_to_remove;
248 for (RenderViewHostMap::iterator iter = swapped_out_hosts_.begin(); 258 for (RenderViewHostMap::iterator iter = swapped_out_hosts_.begin();
249 iter != swapped_out_hosts_.end(); 259 iter != swapped_out_hosts_.end();
250 ++iter) { 260 ++iter) {
251 if (iter->second->process() == render_process_host) 261 if (iter->second->GetProcess() == render_process_host)
252 ids_to_remove.push_back(iter->first); 262 ids_to_remove.push_back(iter->first);
253 } 263 }
254 264
255 // Now delete them. 265 // Now delete them.
256 while (!ids_to_remove.empty()) { 266 while (!ids_to_remove.empty()) {
257 swapped_out_hosts_[ids_to_remove.back()]->Shutdown(); 267 swapped_out_hosts_[ids_to_remove.back()]->Shutdown();
258 swapped_out_hosts_.erase(ids_to_remove.back()); 268 swapped_out_hosts_.erase(ids_to_remove.back());
259 ids_to_remove.pop_back(); 269 ids_to_remove.pop_back();
260 } 270 }
261 } 271 }
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
342 const NavigationEntryImpl* new_entry) const { 352 const NavigationEntryImpl* new_entry) const {
343 DCHECK(new_entry); 353 DCHECK(new_entry);
344 354
345 // Check for reasons to swap processes even if we are in a process model that 355 // Check for reasons to swap processes even if we are in a process model that
346 // doesn't usually swap (e.g., process-per-tab). 356 // doesn't usually swap (e.g., process-per-tab).
347 357
348 // For security, we should transition between processes when one is a Web UI 358 // For security, we should transition between processes when one is a Web UI
349 // page and one isn't. If there's no cur_entry, check the current RVH's 359 // page and one isn't. If there's no cur_entry, check the current RVH's
350 // site, which might already be committed to a Web UI URL (such as the NTP). 360 // site, which might already be committed to a Web UI URL (such as the NTP).
351 const GURL& current_url = (cur_entry) ? cur_entry->GetURL() : 361 const GURL& current_url = (cur_entry) ? cur_entry->GetURL() :
352 render_view_host_->site_instance()->GetSite(); 362 render_view_host_->GetSiteInstance()->GetSite();
353 content::BrowserContext* browser_context = 363 content::BrowserContext* browser_context =
354 delegate_->GetControllerForRenderManager().GetBrowserContext(); 364 delegate_->GetControllerForRenderManager().GetBrowserContext();
355 const WebUIControllerFactory* web_ui_factory = 365 const WebUIControllerFactory* web_ui_factory =
356 content::GetContentClient()->browser()->GetWebUIControllerFactory(); 366 content::GetContentClient()->browser()->GetWebUIControllerFactory();
357 if (web_ui_factory) { 367 if (web_ui_factory) {
358 if (web_ui_factory->UseWebUIForURL(browser_context, current_url)) { 368 if (web_ui_factory->UseWebUIForURL(browser_context, current_url)) {
359 // Force swap if it's not an acceptable URL for Web UI. 369 // Force swap if it's not an acceptable URL for Web UI.
360 if (!web_ui_factory->IsURLAcceptableForWebUI(browser_context, 370 if (!web_ui_factory->IsURLAcceptableForWebUI(browser_context,
361 new_entry->GetURL())) 371 new_entry->GetURL()))
362 return true; 372 return true;
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
518 // Check if we've already created an RVH for this SiteInstance. 528 // Check if we've already created an RVH for this SiteInstance.
519 CHECK(instance); 529 CHECK(instance);
520 RenderViewHostMap::iterator iter = 530 RenderViewHostMap::iterator iter =
521 swapped_out_hosts_.find(instance->GetId()); 531 swapped_out_hosts_.find(instance->GetId());
522 if (iter != swapped_out_hosts_.end()) { 532 if (iter != swapped_out_hosts_.end()) {
523 // Re-use the existing RenderViewHost, which has already been initialized. 533 // Re-use the existing RenderViewHost, which has already been initialized.
524 // We'll remove it from the list of swapped out hosts if it commits. 534 // We'll remove it from the list of swapped out hosts if it commits.
525 pending_render_view_host_ = iter->second; 535 pending_render_view_host_ = iter->second;
526 536
527 // Prevent the process from exiting while we're trying to use it. 537 // Prevent the process from exiting while we're trying to use it.
528 pending_render_view_host_->process()->AddPendingView(); 538 pending_render_view_host_->GetProcess()->AddPendingView();
529 539
530 return true; 540 return true;
531 } 541 }
532 542
533 pending_render_view_host_ = RenderViewHostFactory::Create( 543 pending_render_view_host_ = static_cast<RenderViewHostImpl*>(
534 instance, render_view_delegate_, MSG_ROUTING_NONE, delegate_-> 544 RenderViewHostFactory::Create(
535 GetControllerForRenderManager().GetSessionStorageNamespace()); 545 instance, render_view_delegate_, MSG_ROUTING_NONE, delegate_->
546 GetControllerForRenderManager().GetSessionStorageNamespace()));
536 547
537 // Prevent the process from exiting while we're trying to use it. 548 // Prevent the process from exiting while we're trying to use it.
538 pending_render_view_host_->process()->AddPendingView(); 549 pending_render_view_host_->GetProcess()->AddPendingView();
539 550
540 bool success = InitRenderView(pending_render_view_host_, entry); 551 bool success = InitRenderView(pending_render_view_host_, entry);
541 if (success) { 552 if (success) {
542 // Don't show the view until we get a DidNavigate from it. 553 // Don't show the view until we get a DidNavigate from it.
543 pending_render_view_host_->view()->Hide(); 554 pending_render_view_host_->GetView()->Hide();
544 } else { 555 } else {
545 CancelPending(); 556 CancelPending();
546 } 557 }
547 return success; 558 return success;
548 } 559 }
549 560
550 bool RenderViewHostManager::InitRenderView(RenderViewHost* render_view_host, 561 bool RenderViewHostManager::InitRenderView(RenderViewHost* render_view_host,
551 const NavigationEntryImpl& entry) { 562 const NavigationEntryImpl& entry) {
552 // If the pending navigation is to a WebUI, tell the RenderView about any 563 // If the pending navigation is to a WebUI, tell the RenderView about any
553 // bindings it will need enabled. 564 // bindings it will need enabled.
(...skipping 21 matching lines...) Expand all
575 // committing above and we're done. 586 // committing above and we're done.
576 if (!pending_render_view_host_) { 587 if (!pending_render_view_host_) {
577 if (will_focus_location_bar) 588 if (will_focus_location_bar)
578 delegate_->SetFocusToLocationBar(false); 589 delegate_->SetFocusToLocationBar(false);
579 return; 590 return;
580 } 591 }
581 592
582 // Remember if the page was focused so we can focus the new renderer in 593 // Remember if the page was focused so we can focus the new renderer in
583 // that case. 594 // that case.
584 bool focus_render_view = !will_focus_location_bar && 595 bool focus_render_view = !will_focus_location_bar &&
585 render_view_host_->view() && render_view_host_->view()->HasFocus(); 596 render_view_host_->GetView() && render_view_host_->GetView()->HasFocus();
586 597
587 // Swap in the pending view and make it active. 598 // Swap in the pending view and make it active.
588 RenderViewHost* old_render_view_host = render_view_host_; 599 RenderViewHostImpl* old_render_view_host = render_view_host_;
589 render_view_host_ = pending_render_view_host_; 600 render_view_host_ = pending_render_view_host_;
590 pending_render_view_host_ = NULL; 601 pending_render_view_host_ = NULL;
591 602
592 // The process will no longer try to exit, so we can decrement the count. 603 // The process will no longer try to exit, so we can decrement the count.
593 render_view_host_->process()->RemovePendingView(); 604 render_view_host_->GetProcess()->RemovePendingView();
594 605
595 // If the view is gone, then this RenderViewHost died while it was hidden. 606 // If the view is gone, then this RenderViewHost died while it was hidden.
596 // We ignored the RenderViewGone call at the time, so we should send it now 607 // We ignored the RenderViewGone call at the time, so we should send it now
597 // to make sure the sad tab shows up, etc. 608 // to make sure the sad tab shows up, etc.
598 if (render_view_host_->view()) 609 if (render_view_host_->GetView())
599 render_view_host_->view()->Show(); 610 render_view_host_->GetView()->Show();
600 else 611 else
601 delegate_->RenderViewGoneFromRenderManager(render_view_host_); 612 delegate_->RenderViewGoneFromRenderManager(render_view_host_);
602 613
603 // Hide the old view now that the new one is visible. 614 // Hide the old view now that the new one is visible.
604 if (old_render_view_host->view()) { 615 if (old_render_view_host->GetView()) {
605 old_render_view_host->view()->Hide(); 616 old_render_view_host->GetView()->Hide();
606 old_render_view_host->WasSwappedOut(); 617 old_render_view_host->WasSwappedOut();
607 } 618 }
608 619
609 // Make sure the size is up to date. (Fix for bug 1079768.) 620 // Make sure the size is up to date. (Fix for bug 1079768.)
610 delegate_->UpdateRenderViewSizeForRenderManager(); 621 delegate_->UpdateRenderViewSizeForRenderManager();
611 622
612 if (will_focus_location_bar) 623 if (will_focus_location_bar)
613 delegate_->SetFocusToLocationBar(false); 624 delegate_->SetFocusToLocationBar(false);
614 else if (focus_render_view && render_view_host_->view()) 625 else if (focus_render_view && render_view_host_->GetView())
615 RenderWidgetHostViewPort::FromRWHV(render_view_host_->view())->Focus(); 626 RenderWidgetHostViewPort::FromRWHV(render_view_host_->GetView())->Focus();
616 627
617 std::pair<RenderViewHost*, RenderViewHost*> details = 628 std::pair<RenderViewHost*, RenderViewHost*> details =
618 std::make_pair(old_render_view_host, render_view_host_); 629 std::make_pair(old_render_view_host, render_view_host_);
619 content::NotificationService::current()->Notify( 630 content::NotificationService::current()->Notify(
620 content::NOTIFICATION_RENDER_VIEW_HOST_CHANGED, 631 content::NOTIFICATION_RENDER_VIEW_HOST_CHANGED,
621 content::Source<NavigationController>( 632 content::Source<NavigationController>(
622 &delegate_->GetControllerForRenderManager()), 633 &delegate_->GetControllerForRenderManager()),
623 content::Details<std::pair<RenderViewHost*, RenderViewHost*> >(&details)); 634 content::Details<std::pair<RenderViewHost*, RenderViewHost*> >(&details));
624 635
625 // If the pending view was on the swapped out list, we can remove it. 636 // If the pending view was on the swapped out list, we can remove it.
626 swapped_out_hosts_.erase(render_view_host_->site_instance()->GetId()); 637 swapped_out_hosts_.erase(render_view_host_->GetSiteInstance()->GetId());
627 638
628 // If the old RVH is live, we are swapping it out and should keep track of it 639 // If the old RVH is live, we are swapping it out and should keep track of it
629 // in case we navigate back to it. 640 // in case we navigate back to it.
630 if (old_render_view_host->IsRenderViewLive()) { 641 if (old_render_view_host->IsRenderViewLive()) {
631 DCHECK(old_render_view_host->is_swapped_out()); 642 DCHECK(old_render_view_host->is_swapped_out());
632 // Temp fix for http://crbug.com/90867 until we do a better cleanup to make 643 // Temp fix for http://crbug.com/90867 until we do a better cleanup to make
633 // sure we don't get different rvh instances for the same site instance 644 // sure we don't get different rvh instances for the same site instance
634 // in the same rvhmgr. 645 // in the same rvhmgr.
635 // TODO(creis): Clean this up. 646 // TODO(creis): Clean this up.
636 int32 old_site_instance_id = old_render_view_host->site_instance()->GetId(); 647 int32 old_site_instance_id =
648 old_render_view_host->GetSiteInstance()->GetId();
637 RenderViewHostMap::iterator iter = 649 RenderViewHostMap::iterator iter =
638 swapped_out_hosts_.find(old_site_instance_id); 650 swapped_out_hosts_.find(old_site_instance_id);
639 if (iter != swapped_out_hosts_.end() && 651 if (iter != swapped_out_hosts_.end() &&
640 iter->second != old_render_view_host) { 652 iter->second != old_render_view_host) {
641 // Shutdown the RVH that will be replaced in the map to avoid a leak. 653 // Shutdown the RVH that will be replaced in the map to avoid a leak.
642 iter->second->Shutdown(); 654 iter->second->Shutdown();
643 } 655 }
644 swapped_out_hosts_[old_site_instance_id] = old_render_view_host; 656 swapped_out_hosts_[old_site_instance_id] = old_render_view_host;
645 } else { 657 } else {
646 old_render_view_host->Shutdown(); 658 old_render_view_host->Shutdown();
647 } 659 }
648 660
649 // Let the task manager know that we've swapped RenderViewHosts, since it 661 // Let the task manager know that we've swapped RenderViewHosts, since it
650 // might need to update its process groupings. 662 // might need to update its process groupings.
651 delegate_->NotifySwappedFromRenderManager(); 663 delegate_->NotifySwappedFromRenderManager();
652 } 664 }
653 665
654 RenderViewHost* RenderViewHostManager::UpdateRendererStateForNavigate( 666 RenderViewHostImpl* RenderViewHostManager::UpdateRendererStateForNavigate(
655 const NavigationEntryImpl& entry) { 667 const NavigationEntryImpl& entry) {
656 // If we are cross-navigating, then we want to get back to normal and navigate 668 // If we are cross-navigating, then we want to get back to normal and navigate
657 // as usual. 669 // as usual.
658 if (cross_navigation_pending_) { 670 if (cross_navigation_pending_) {
659 if (pending_render_view_host_) 671 if (pending_render_view_host_)
660 CancelPending(); 672 CancelPending();
661 cross_navigation_pending_ = false; 673 cross_navigation_pending_ = false;
662 } 674 }
663 675
664 // This will possibly create (set to NULL) a Web UI object for the pending 676 // This will possibly create (set to NULL) a Web UI object for the pending
665 // page. We'll use this later to give the page special access. This must 677 // page. We'll use this later to give the page special access. This must
666 // happen before the new renderer is created below so it will get bindings. 678 // happen before the new renderer is created below so it will get bindings.
667 // It must also happen after the above conditional call to CancelPending(), 679 // It must also happen after the above conditional call to CancelPending(),
668 // otherwise CancelPending may clear the pending_web_ui_ and the page will 680 // otherwise CancelPending may clear the pending_web_ui_ and the page will
669 // not have it's bindings set appropriately. 681 // not have it's bindings set appropriately.
670 pending_web_ui_.reset(delegate_->CreateWebUIForRenderManager(entry.GetURL())); 682 pending_web_ui_.reset(delegate_->CreateWebUIForRenderManager(entry.GetURL()));
671 683
672 // render_view_host_ will not be deleted before the end of this method, so we 684 // render_view_host_ will not be deleted before the end of this method, so we
673 // don't have to worry about this SiteInstance's ref count dropping to zero. 685 // don't have to worry about this SiteInstance's ref count dropping to zero.
674 SiteInstance* curr_instance = render_view_host_->site_instance(); 686 SiteInstance* curr_instance = render_view_host_->GetSiteInstance();
675 687
676 // Determine if we need a new SiteInstance for this entry. 688 // Determine if we need a new SiteInstance for this entry.
677 // Again, new_instance won't be deleted before the end of this method, so it 689 // Again, new_instance won't be deleted before the end of this method, so it
678 // is safe to use a normal pointer here. 690 // is safe to use a normal pointer here.
679 SiteInstance* new_instance = curr_instance; 691 SiteInstance* new_instance = curr_instance;
680 bool force_swap = ShouldSwapProcessesForNavigation( 692 bool force_swap = ShouldSwapProcessesForNavigation(
681 delegate_->GetLastCommittedNavigationEntryForRenderManager(), &entry); 693 delegate_->GetLastCommittedNavigationEntryForRenderManager(), &entry);
682 if (ShouldTransitionCrossSite() || force_swap) 694 if (ShouldTransitionCrossSite() || force_swap)
683 new_instance = GetSiteInstanceForEntry(entry, curr_instance); 695 new_instance = GetSiteInstanceForEntry(entry, curr_instance);
684 696
(...skipping 17 matching lines...) Expand all
702 CommitPending(); 714 CommitPending();
703 return render_view_host_; 715 return render_view_host_;
704 } else { 716 } else {
705 NOTREACHED(); 717 NOTREACHED();
706 return render_view_host_; 718 return render_view_host_;
707 } 719 }
708 } 720 }
709 // Otherwise, it's safe to treat this as a pending cross-site transition. 721 // Otherwise, it's safe to treat this as a pending cross-site transition.
710 722
711 // Make sure the old render view stops, in case a load is in progress. 723 // Make sure the old render view stops, in case a load is in progress.
712 render_view_host_->Send(new ViewMsg_Stop(render_view_host_->routing_id())); 724 render_view_host_->Send(
725 new ViewMsg_Stop(render_view_host_->GetRoutingID()));
713 726
714 // Suspend the new render view (i.e., don't let it send the cross-site 727 // Suspend the new render view (i.e., don't let it send the cross-site
715 // Navigate message) until we hear back from the old renderer's 728 // Navigate message) until we hear back from the old renderer's
716 // onbeforeunload handler. If the handler returns false, we'll have to 729 // onbeforeunload handler. If the handler returns false, we'll have to
717 // cancel the request. 730 // cancel the request.
718 DCHECK(!pending_render_view_host_->are_navigations_suspended()); 731 DCHECK(!pending_render_view_host_->are_navigations_suspended());
719 pending_render_view_host_->SetNavigationsSuspended(true); 732 pending_render_view_host_->SetNavigationsSuspended(true);
720 733
721 // Tell the CrossSiteRequestManager that this RVH has a pending cross-site 734 // Tell the CrossSiteRequestManager that this RVH has a pending cross-site
722 // request, so that ResourceDispatcherHost will know to tell us to run the 735 // request, so that ResourceDispatcherHost will know to tell us to run the
(...skipping 11 matching lines...) Expand all
734 747
735 return pending_render_view_host_; 748 return pending_render_view_host_;
736 } else { 749 } else {
737 if (pending_web_ui_.get() && render_view_host_->IsRenderViewLive()) 750 if (pending_web_ui_.get() && render_view_host_->IsRenderViewLive())
738 pending_web_ui_->GetController()->RenderViewReused(render_view_host_); 751 pending_web_ui_->GetController()->RenderViewReused(render_view_host_);
739 752
740 // The renderer can exit view source mode when any error or cancellation 753 // The renderer can exit view source mode when any error or cancellation
741 // happen. We must overwrite to recover the mode. 754 // happen. We must overwrite to recover the mode.
742 if (entry.IsViewSourceMode()) { 755 if (entry.IsViewSourceMode()) {
743 render_view_host_->Send( 756 render_view_host_->Send(
744 new ViewMsg_EnableViewSourceMode(render_view_host_->routing_id())); 757 new ViewMsg_EnableViewSourceMode(render_view_host_->GetRoutingID()));
745 } 758 }
746 } 759 }
747 760
748 // Same SiteInstance can be used. Navigate render_view_host_ if we are not 761 // Same SiteInstance can be used. Navigate render_view_host_ if we are not
749 // cross navigating. 762 // cross navigating.
750 DCHECK(!cross_navigation_pending_); 763 DCHECK(!cross_navigation_pending_);
751 return render_view_host_; 764 return render_view_host_;
752 } 765 }
753 766
754 void RenderViewHostManager::CancelPending() { 767 void RenderViewHostManager::CancelPending() {
755 RenderViewHost* pending_render_view_host = pending_render_view_host_; 768 RenderViewHostImpl* pending_render_view_host = pending_render_view_host_;
756 pending_render_view_host_ = NULL; 769 pending_render_view_host_ = NULL;
757 770
758 content::DevToolsManagerImpl::GetInstance()->OnCancelPendingNavigation( 771 content::DevToolsManagerImpl::GetInstance()->OnCancelPendingNavigation(
759 pending_render_view_host, 772 pending_render_view_host,
760 render_view_host_); 773 render_view_host_);
761 774
762 // We no longer need to prevent the process from exiting. 775 // We no longer need to prevent the process from exiting.
763 pending_render_view_host->process()->RemovePendingView(); 776 pending_render_view_host->GetProcess()->RemovePendingView();
764 777
765 // The pending RVH may already be on the swapped out list if we started to 778 // The pending RVH may already be on the swapped out list if we started to
766 // swap it back in and then canceled. If so, make sure it gets swapped out 779 // swap it back in and then canceled. If so, make sure it gets swapped out
767 // again. If it's not on the swapped out list (e.g., aborting a pending 780 // again. If it's not on the swapped out list (e.g., aborting a pending
768 // load), then it's safe to shut down. 781 // load), then it's safe to shut down.
769 if (IsSwappedOut(pending_render_view_host)) { 782 if (IsSwappedOut(pending_render_view_host)) {
770 // Any currently suspended navigations are no longer needed. 783 // Any currently suspended navigations are no longer needed.
771 pending_render_view_host->CancelSuspendedNavigations(); 784 pending_render_view_host->CancelSuspendedNavigations();
772 785
773 // We can pass -1,-1 because there is no pending response in the 786 // We can pass -1,-1 because there is no pending response in the
(...skipping 29 matching lines...) Expand all
803 iter != swapped_out_hosts_.end(); 816 iter != swapped_out_hosts_.end();
804 ++iter) { 817 ++iter) {
805 if (iter->second == rvh) { 818 if (iter->second == rvh) {
806 swapped_out_hosts_.erase(iter); 819 swapped_out_hosts_.erase(iter);
807 break; 820 break;
808 } 821 }
809 } 822 }
810 } 823 }
811 824
812 bool RenderViewHostManager::IsSwappedOut(RenderViewHost* rvh) { 825 bool RenderViewHostManager::IsSwappedOut(RenderViewHost* rvh) {
813 if (!rvh->site_instance()) 826 if (!rvh->GetSiteInstance())
814 return false; 827 return false;
815 828
816 return swapped_out_hosts_.find(rvh->site_instance()->GetId()) != 829 return swapped_out_hosts_.find(rvh->GetSiteInstance()->GetId()) !=
817 swapped_out_hosts_.end(); 830 swapped_out_hosts_.end();
818 } 831 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698