| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 "chrome/browser/tab_contents/render_view_host_manager.h" | 5 #include "chrome/browser/tab_contents/render_view_host_manager.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "chrome/browser/renderer_host/render_view_host.h" | 9 #include "chrome/browser/renderer_host/render_view_host.h" |
| 10 #include "chrome/browser/renderer_host/render_view_host_delegate.h" | 10 #include "chrome/browser/renderer_host/render_view_host_delegate.h" |
| 11 #include "chrome/browser/renderer_host/render_widget_host_view.h" | 11 #include "chrome/browser/renderer_host/render_widget_host_view.h" |
| 12 #include "chrome/browser/tab_contents/navigation_controller.h" | 12 #include "chrome/browser/tab_contents/navigation_controller.h" |
| 13 #include "chrome/browser/tab_contents/navigation_entry.h" | 13 #include "chrome/browser/tab_contents/navigation_entry.h" |
| 14 #include "chrome/browser/tab_contents/site_instance.h" | 14 #include "chrome/browser/tab_contents/site_instance.h" |
| 15 #include "chrome/common/chrome_switches.h" | 15 #include "chrome/common/chrome_switches.h" |
| 16 #include "chrome/common/notification_service.h" | 16 #include "chrome/common/notification_service.h" |
| 17 #include "chrome/common/notification_type.h" |
| 17 | 18 |
| 18 namespace base { | 19 namespace base { |
| 19 class WaitableEvent; | 20 class WaitableEvent; |
| 20 } | 21 } |
| 21 | 22 |
| 22 RenderViewHostManager::RenderViewHostManager( | 23 RenderViewHostManager::RenderViewHostManager( |
| 23 RenderViewHostFactory* render_view_factory, | 24 RenderViewHostFactory* render_view_factory, |
| 24 RenderViewHostDelegate* render_view_delegate, | 25 RenderViewHostDelegate* render_view_delegate, |
| 25 Delegate* delegate) | 26 Delegate* delegate) |
| 26 : delegate_(delegate), | 27 : delegate_(delegate), |
| 27 cross_navigation_pending_(false), | 28 cross_navigation_pending_(false), |
| 28 render_view_factory_(render_view_factory), | 29 render_view_factory_(render_view_factory), |
| 29 render_view_delegate_(render_view_delegate), | 30 render_view_delegate_(render_view_delegate), |
| 30 render_view_host_(NULL), | 31 render_view_host_(NULL), |
| 31 pending_render_view_host_(NULL), | 32 pending_render_view_host_(NULL), |
| 32 interstitial_page_(NULL) { | 33 interstitial_page_(NULL) { |
| 34 registrar_.Add(this, NotificationType::RENDER_VIEW_HOST_DELETED, |
| 35 NotificationService::AllSources()); |
| 33 } | 36 } |
| 34 | 37 |
| 35 RenderViewHostManager::~RenderViewHostManager() { | 38 RenderViewHostManager::~RenderViewHostManager() { |
| 36 // Shutdown should have been called which should have cleaned these up. | 39 // Shutdown should have been called which should have cleaned these up. |
| 37 DCHECK(!render_view_host_); | 40 DCHECK(!render_view_host_); |
| 38 DCHECK(!pending_render_view_host_); | 41 DCHECK(!pending_render_view_host_); |
| 39 } | 42 } |
| 40 | 43 |
| 41 void RenderViewHostManager::Init(Profile* profile, | 44 void RenderViewHostManager::Init(Profile* profile, |
| 42 SiteInstance* site_instance, | 45 SiteInstance* site_instance, |
| 43 int routing_id, | 46 int routing_id, |
| 44 base::WaitableEvent* modal_dialog_event) { | 47 base::WaitableEvent* modal_dialog_event) { |
| 45 // Create a RenderViewHost, once we have an instance. It is important to | 48 // Create a RenderViewHost, once we have an instance. It is important to |
| 46 // immediately give this SiteInstance to a RenderViewHost so that it is | 49 // immediately give this SiteInstance to a RenderViewHost so that it is |
| 47 // ref counted. | 50 // ref counted. |
| 48 if (!site_instance) | 51 if (!site_instance) |
| 49 site_instance = SiteInstance::CreateSiteInstance(profile); | 52 site_instance = SiteInstance::CreateSiteInstance(profile); |
| 50 render_view_host_ = CreateRenderViewHost( | 53 render_view_host_ = CreateRenderViewHost( |
| 51 site_instance, routing_id, modal_dialog_event); | 54 site_instance, routing_id, modal_dialog_event); |
| 52 } | 55 } |
| 53 | 56 |
| 54 void RenderViewHostManager::Shutdown() { | 57 void RenderViewHostManager::Shutdown() { |
| 55 if (pending_render_view_host_) | 58 if (pending_render_view_host_) |
| 56 CancelPendingRenderView(); | 59 CancelPendingRenderView(); |
| 57 | 60 |
| 58 // We should always have a main RenderViewHost. | 61 // We should always have a main RenderViewHost. |
| 59 render_view_host_->Shutdown(); | 62 RenderViewHost* render_view_host = render_view_host_; |
| 60 render_view_host_ = NULL; | 63 render_view_host_ = NULL; |
| 64 render_view_host->Shutdown(); |
| 61 } | 65 } |
| 62 | 66 |
| 63 RenderViewHost* RenderViewHostManager::Navigate(const NavigationEntry& entry) { | 67 RenderViewHost* RenderViewHostManager::Navigate(const NavigationEntry& entry) { |
| 64 RenderViewHost* dest_render_view_host = UpdateRendererStateNavigate(entry); | 68 RenderViewHost* dest_render_view_host = UpdateRendererStateNavigate(entry); |
| 65 if (!dest_render_view_host) | 69 if (!dest_render_view_host) |
| 66 return NULL; // We weren't able to create a pending render view host. | 70 return NULL; // We weren't able to create a pending render view host. |
| 67 | 71 |
| 68 // If the current render_view_host_ isn't live, we should create it so | 72 // If the current render_view_host_ isn't live, we should create it so |
| 69 // that we don't show a sad tab while the dest_render_view_host fetches | 73 // that we don't show a sad tab while the dest_render_view_host fetches |
| 70 // its first page. (Bug 1145340) | 74 // its first page. (Bug 1145340) |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 238 } | 242 } |
| 239 } | 243 } |
| 240 | 244 |
| 241 void RenderViewHostManager::OnJavaScriptMessageBoxClosed( | 245 void RenderViewHostManager::OnJavaScriptMessageBoxClosed( |
| 242 IPC::Message* reply_msg, | 246 IPC::Message* reply_msg, |
| 243 bool success, | 247 bool success, |
| 244 const std::wstring& prompt) { | 248 const std::wstring& prompt) { |
| 245 render_view_host_->JavaScriptMessageBoxClosed(reply_msg, success, prompt); | 249 render_view_host_->JavaScriptMessageBoxClosed(reply_msg, success, prompt); |
| 246 } | 250 } |
| 247 | 251 |
| 252 void RenderViewHostManager::Observe(NotificationType type, |
| 253 const NotificationSource& source, |
| 254 const NotificationDetails& details) { |
| 255 // Debugging code to help isolate |
| 256 // http://code.google.com/p/chromium/issues/detail?id=6316 . We should never |
| 257 // reference a RVH that is about to be deleted. |
| 258 RenderViewHost* deleted_rvh = Source<RenderViewHost>(source).ptr(); |
| 259 CHECK(deleted_rvh); |
| 260 CHECK(render_view_host_ != deleted_rvh); |
| 261 CHECK(pending_render_view_host_ != deleted_rvh); |
| 262 } |
| 248 | 263 |
| 249 bool RenderViewHostManager::ShouldTransitionCrossSite() { | 264 bool RenderViewHostManager::ShouldTransitionCrossSite() { |
| 250 // True if we are using process-per-site-instance (default) or | 265 // True if we are using process-per-site-instance (default) or |
| 251 // process-per-site (kProcessPerSite). | 266 // process-per-site (kProcessPerSite). |
| 252 return !CommandLine::ForCurrentProcess()->HasSwitch(switches::kProcessPerTab); | 267 return !CommandLine::ForCurrentProcess()->HasSwitch(switches::kProcessPerTab); |
| 253 } | 268 } |
| 254 | 269 |
| 255 SiteInstance* RenderViewHostManager::GetSiteInstanceForEntry( | 270 SiteInstance* RenderViewHostManager::GetSiteInstanceForEntry( |
| 256 const NavigationEntry& entry, | 271 const NavigationEntry& entry, |
| 257 SiteInstance* curr_instance) { | 272 SiteInstance* curr_instance) { |
| (...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 501 return pending_render_view_host_; | 516 return pending_render_view_host_; |
| 502 } | 517 } |
| 503 | 518 |
| 504 // Same SiteInstance can be used. Navigate render_view_host_ if we are not | 519 // Same SiteInstance can be used. Navigate render_view_host_ if we are not |
| 505 // cross navigating. | 520 // cross navigating. |
| 506 DCHECK(!cross_navigation_pending_); | 521 DCHECK(!cross_navigation_pending_); |
| 507 return render_view_host_; | 522 return render_view_host_; |
| 508 } | 523 } |
| 509 | 524 |
| 510 void RenderViewHostManager::CancelPendingRenderView() { | 525 void RenderViewHostManager::CancelPendingRenderView() { |
| 511 pending_render_view_host_->Shutdown(); | 526 RenderViewHost* pending_render_view_host = pending_render_view_host_; |
| 512 pending_render_view_host_ = NULL; | 527 pending_render_view_host_ = NULL; |
| 528 pending_render_view_host->Shutdown(); |
| 513 } | 529 } |
| 514 | 530 |
| 515 void RenderViewHostManager::CrossSiteNavigationCanceled() { | 531 void RenderViewHostManager::CrossSiteNavigationCanceled() { |
| 516 DCHECK(cross_navigation_pending_); | 532 DCHECK(cross_navigation_pending_); |
| 517 cross_navigation_pending_ = false; | 533 cross_navigation_pending_ = false; |
| 518 if (pending_render_view_host_) | 534 if (pending_render_view_host_) |
| 519 CancelPendingRenderView(); | 535 CancelPendingRenderView(); |
| 520 } | 536 } |
| 521 | 537 |
| OLD | NEW |