| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/dom_ui/dom_ui.h" | 9 #include "chrome/browser/dom_ui/dom_ui.h" |
| 10 #include "chrome/browser/dom_ui/dom_ui_factory.h" | 10 #include "chrome/browser/dom_ui/dom_ui_factory.h" |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 } | 26 } |
| 27 | 27 |
| 28 RenderViewHostManager::RenderViewHostManager( | 28 RenderViewHostManager::RenderViewHostManager( |
| 29 RenderViewHostDelegate* render_view_delegate, | 29 RenderViewHostDelegate* render_view_delegate, |
| 30 Delegate* delegate) | 30 Delegate* delegate) |
| 31 : delegate_(delegate), | 31 : delegate_(delegate), |
| 32 cross_navigation_pending_(false), | 32 cross_navigation_pending_(false), |
| 33 render_view_delegate_(render_view_delegate), | 33 render_view_delegate_(render_view_delegate), |
| 34 render_view_host_(NULL), | 34 render_view_host_(NULL), |
| 35 pending_render_view_host_(NULL), | 35 pending_render_view_host_(NULL), |
| 36 pending_renderer_aborted_(false), | |
| 37 interstitial_page_(NULL) { | 36 interstitial_page_(NULL) { |
| 38 registrar_.Add(this, NotificationType::RENDER_VIEW_HOST_DELETED, | 37 registrar_.Add(this, NotificationType::RENDER_VIEW_HOST_DELETED, |
| 39 NotificationService::AllSources()); | 38 NotificationService::AllSources()); |
| 40 } | 39 } |
| 41 | 40 |
| 42 RenderViewHostManager::~RenderViewHostManager() { | 41 RenderViewHostManager::~RenderViewHostManager() { |
| 43 if (pending_render_view_host_) | 42 if (pending_render_view_host_) |
| 44 CancelPending(); | 43 CancelPending(); |
| 45 | 44 |
| 46 // We should always have a main RenderViewHost. | 45 // We should always have a main RenderViewHost. |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 209 // We used to cancel the pending renderer here for cross-site downloads. | 208 // We used to cancel the pending renderer here for cross-site downloads. |
| 210 // However, it's not safe to do that because the download logic repeatedly | 209 // However, it's not safe to do that because the download logic repeatedly |
| 211 // looks for this TabContents based on a render view ID. Instead, we just | 210 // looks for this TabContents based on a render view ID. Instead, we just |
| 212 // leave the pending renderer around until the next navigation event | 211 // leave the pending renderer around until the next navigation event |
| 213 // (Navigate, DidNavigate, etc), which will clean it up properly. | 212 // (Navigate, DidNavigate, etc), which will clean it up properly. |
| 214 // TODO(creis): All of this will go away when we move the cross-site logic | 213 // TODO(creis): All of this will go away when we move the cross-site logic |
| 215 // to ResourceDispatcherHost, so that we intercept responses rather than | 214 // to ResourceDispatcherHost, so that we intercept responses rather than |
| 216 // navigation events. (That's necessary to support onunload anyway.) Once | 215 // navigation events. (That's necessary to support onunload anyway.) Once |
| 217 // we've made that change, we won't create a pending renderer until we know | 216 // we've made that change, we won't create a pending renderer until we know |
| 218 // the response is not a download. | 217 // the response is not a download. |
| 219 | |
| 220 // There is one instance where we must be able to pre-emptively clean up a | |
| 221 // pending renderer: If a cross-site download is initiated from a chrome:// | |
| 222 // url, and the browser then wants to close. | |
| 223 if (pending_render_view_host_) { | |
| 224 pending_renderer_aborted_ = true; | |
| 225 } | |
| 226 } | 218 } |
| 227 | 219 |
| 228 void RenderViewHostManager::ShouldClosePage(bool proceed) { | 220 void RenderViewHostManager::ShouldClosePage(bool proceed) { |
| 229 // Should only see this while we have a pending renderer. Otherwise, we | 221 // Should only see this while we have a pending renderer. Otherwise, we |
| 230 // should ignore. | 222 // should ignore. |
| 231 if (pending_render_view_host_ && pending_renderer_aborted_) | |
| 232 CancelPending(); | |
| 233 | |
| 234 if (!pending_render_view_host_) { | 223 if (!pending_render_view_host_) { |
| 235 bool proceed_to_fire_unload; | 224 bool proceed_to_fire_unload; |
| 236 delegate_->BeforeUnloadFiredFromRenderManager(proceed, | 225 delegate_->BeforeUnloadFiredFromRenderManager(proceed, |
| 237 &proceed_to_fire_unload); | 226 &proceed_to_fire_unload); |
| 238 | 227 |
| 239 if (proceed_to_fire_unload) { | 228 if (proceed_to_fire_unload) { |
| 240 // This is not a cross-site navigation, the tab is being closed. | 229 // This is not a cross-site navigation, the tab is being closed. |
| 241 render_view_host_->FirePageUnload(); | 230 render_view_host_->FirePageUnload(); |
| 242 } | 231 } |
| 243 return; | 232 return; |
| (...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 593 // Same SiteInstance can be used. Navigate render_view_host_ if we are not | 582 // Same SiteInstance can be used. Navigate render_view_host_ if we are not |
| 594 // cross navigating. | 583 // cross navigating. |
| 595 DCHECK(!cross_navigation_pending_); | 584 DCHECK(!cross_navigation_pending_); |
| 596 return render_view_host_; | 585 return render_view_host_; |
| 597 } | 586 } |
| 598 | 587 |
| 599 void RenderViewHostManager::CancelPending() { | 588 void RenderViewHostManager::CancelPending() { |
| 600 RenderViewHost* pending_render_view_host = pending_render_view_host_; | 589 RenderViewHost* pending_render_view_host = pending_render_view_host_; |
| 601 pending_render_view_host_ = NULL; | 590 pending_render_view_host_ = NULL; |
| 602 pending_render_view_host->Shutdown(); | 591 pending_render_view_host->Shutdown(); |
| 603 pending_renderer_aborted_ = false; | 592 |
| 604 pending_dom_ui_.reset(); | 593 pending_dom_ui_.reset(); |
| 605 } | 594 } |
| 606 | 595 |
| 607 void RenderViewHostManager::CrossSiteNavigationCanceled() { | 596 void RenderViewHostManager::CrossSiteNavigationCanceled() { |
| 608 DCHECK(cross_navigation_pending_); | 597 DCHECK(cross_navigation_pending_); |
| 609 cross_navigation_pending_ = false; | 598 cross_navigation_pending_ = false; |
| 610 if (pending_render_view_host_) | 599 if (pending_render_view_host_) |
| 611 CancelPending(); | 600 CancelPending(); |
| 612 } | 601 } |
| OLD | NEW |