| 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 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 // on it later. | 88 // on it later. |
| 89 if (dest_render_view_host != render_view_host_ && | 89 if (dest_render_view_host != render_view_host_ && |
| 90 dest_render_view_host->view()) { | 90 dest_render_view_host->view()) { |
| 91 dest_render_view_host->view()->Hide(); | 91 dest_render_view_host->view()->Hide(); |
| 92 } else { | 92 } else { |
| 93 // This is our primary renderer, notify here as we won't be calling | 93 // This is our primary renderer, notify here as we won't be calling |
| 94 // CommitPending (which does the notify). | 94 // CommitPending (which does the notify). |
| 95 RenderViewHostSwitchedDetails details; | 95 RenderViewHostSwitchedDetails details; |
| 96 details.new_host = render_view_host_; | 96 details.new_host = render_view_host_; |
| 97 details.old_host = NULL; | 97 details.old_host = NULL; |
| 98 NotificationService::current()->Notify( | 98 delegate_->NotifyRenderViewHostSwitchedFromRenderManager(&details); |
| 99 NotificationType::RENDER_VIEW_HOST_CHANGED, | |
| 100 Source<NavigationController>( | |
| 101 &delegate_->GetControllerForRenderManager()), | |
| 102 Details<RenderViewHostSwitchedDetails>(&details)); | |
| 103 } | 99 } |
| 104 } | 100 } |
| 105 | 101 |
| 106 return dest_render_view_host; | 102 return dest_render_view_host; |
| 107 } | 103 } |
| 108 | 104 |
| 109 void RenderViewHostManager::Stop() { | 105 void RenderViewHostManager::Stop() { |
| 110 render_view_host_->Stop(); | 106 render_view_host_->Stop(); |
| 111 | 107 |
| 112 // If we are cross-navigating, we should stop the pending renderers. This | 108 // If we are cross-navigating, we should stop the pending renderers. This |
| (...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 362 // Otherwise, only create a new SiteInstance for cross-site navigation. | 358 // Otherwise, only create a new SiteInstance for cross-site navigation. |
| 363 | 359 |
| 364 // TODO(creis): Once we intercept links and script-based navigations, we | 360 // TODO(creis): Once we intercept links and script-based navigations, we |
| 365 // will be able to enforce that all entries in a SiteInstance actually have | 361 // will be able to enforce that all entries in a SiteInstance actually have |
| 366 // the same site, and it will be safe to compare the URL against the | 362 // the same site, and it will be safe to compare the URL against the |
| 367 // SiteInstance's site, as follows: | 363 // SiteInstance's site, as follows: |
| 368 // const GURL& current_url = curr_instance->site(); | 364 // const GURL& current_url = curr_instance->site(); |
| 369 // For now, though, we're in a hybrid model where you only switch | 365 // For now, though, we're in a hybrid model where you only switch |
| 370 // SiteInstances if you type in a cross-site URL. This means we have to | 366 // SiteInstances if you type in a cross-site URL. This means we have to |
| 371 // compare the entry's URL to the last committed entry's URL. | 367 // compare the entry's URL to the last committed entry's URL. |
| 372 NavigationController& controller = delegate_->GetControllerForRenderManager(); | 368 |
| 373 NavigationEntry* curr_entry = controller.GetLastCommittedEntry(); | 369 NavigationEntry* curr_entry = |
| 370 delegate_->GetLastCommittedNavigationEntryForRenderManager(); |
| 371 |
| 374 if (interstitial_page_) { | 372 if (interstitial_page_) { |
| 375 // The interstitial is currently the last committed entry, but we want to | 373 // The interstitial is currently the last committed entry, but we want to |
| 376 // compare against the last non-interstitial entry. | 374 // compare against the last non-interstitial entry. |
| 377 curr_entry = controller.GetEntryAtOffset(-1); | 375 curr_entry = delegate_->GetEntryAtOffsetForRenderManager(-1); |
| 378 } | 376 } |
| 379 // If there is no last non-interstitial entry (and curr_instance already | 377 // If there is no last non-interstitial entry (and curr_instance already |
| 380 // has a site), then we must have been opened from another tab. We want | 378 // has a site), then we must have been opened from another tab. We want |
| 381 // to compare against the URL of the page that opened us, but we can't | 379 // to compare against the URL of the page that opened us, but we can't |
| 382 // get to it directly. The best we can do is check against the site of | 380 // get to it directly. The best we can do is check against the site of |
| 383 // the SiteInstance. This will be correct when we intercept links and | 381 // the SiteInstance. This will be correct when we intercept links and |
| 384 // script-based navigations, but for now, it could place some pages in a | 382 // script-based navigations, but for now, it could place some pages in a |
| 385 // new process unnecessarily. We should only hit this case if a page tries | 383 // new process unnecessarily. We should only hit this case if a page tries |
| 386 // to open a new tab to an interstitial-inducing URL, and then navigates | 384 // to open a new tab to an interstitial-inducing URL, and then navigates |
| 387 // the page to a different same-site URL. (This seems very unlikely in | 385 // the page to a different same-site URL. (This seems very unlikely in |
| 388 // practice.) | 386 // practice.) |
| 389 const GURL& current_url = (curr_entry) ? curr_entry->url() : | 387 const GURL& current_url = (curr_entry) ? curr_entry->url() : |
| 390 curr_instance->site(); | 388 curr_instance->site(); |
| 391 | 389 |
| 392 if (SiteInstance::IsSameWebSite(current_url, dest_url)) { | 390 if (SiteInstance::IsSameWebSite(current_url, dest_url)) { |
| 393 return curr_instance; | 391 return curr_instance; |
| 394 } else if (ShouldSwapProcessesForNavigation(curr_entry, &entry)) { | 392 } else if (ShouldSwapProcessesForNavigation(curr_entry, &entry)) { |
| 395 // When we're swapping, we need to force the site instance AND browsing | 393 // When we're swapping, we need to force the site instance AND browsing |
| 396 // instance to be different ones. This addresses special cases where we use | 394 // instance to be different ones. This addresses special cases where we use |
| 397 // a single BrowsingInstance for all pages of a certain type (e.g., New Tab | 395 // a single BrowsingInstance for all pages of a certain type (e.g., New Tab |
| 398 // Pages), keeping them in the same process. When you navigate away from | 396 // Pages), keeping them in the same process. When you navigate away from |
| 399 // that page, we want to explicity ignore that BrowsingInstance and group | 397 // that page, we want to explicity ignore that BrowsingInstance and group |
| 400 // this page into the appropriate SiteInstance for its URL. | 398 // this page into the appropriate SiteInstance for its URL. |
| 401 return SiteInstance::CreateSiteInstanceForURL( | 399 return SiteInstance::CreateSiteInstanceForURL( |
| 402 delegate_->GetControllerForRenderManager().profile(), dest_url); | 400 delegate_->GetProfileForRenderManager(), dest_url); |
| 403 } else { | 401 } else { |
| 404 // Start the new renderer in a new SiteInstance, but in the current | 402 // Start the new renderer in a new SiteInstance, but in the current |
| 405 // BrowsingInstance. It is important to immediately give this new | 403 // BrowsingInstance. It is important to immediately give this new |
| 406 // SiteInstance to a RenderViewHost (if it is different than our current | 404 // SiteInstance to a RenderViewHost (if it is different than our current |
| 407 // SiteInstance), so that it is ref counted. This will happen in | 405 // SiteInstance), so that it is ref counted. This will happen in |
| 408 // CreatePendingRenderView. | 406 // CreatePendingRenderView. |
| 409 return curr_instance->GetRelatedSiteInstance(dest_url); | 407 return curr_instance->GetRelatedSiteInstance(dest_url); |
| 410 } | 408 } |
| 411 } | 409 } |
| 412 | 410 |
| 413 bool RenderViewHostManager::CreatePendingRenderView(SiteInstance* instance) { | 411 bool RenderViewHostManager::CreatePendingRenderView(SiteInstance* instance) { |
| 414 NavigationEntry* curr_entry = | 412 NavigationEntry* curr_entry = |
| 415 delegate_->GetControllerForRenderManager().GetLastCommittedEntry(); | 413 delegate_->GetLastCommittedNavigationEntryForRenderManager(); |
| 416 if (curr_entry) { | 414 if (curr_entry) { |
| 417 DCHECK(!curr_entry->content_state().empty()); | 415 DCHECK(!curr_entry->content_state().empty()); |
| 418 // TODO(creis): Should send a message to the RenderView to let it know | 416 // TODO(creis): Should send a message to the RenderView to let it know |
| 419 // we're about to switch away, so that it sends an UpdateState message. | 417 // we're about to switch away, so that it sends an UpdateState message. |
| 420 } | 418 } |
| 421 | 419 |
| 422 pending_render_view_host_ = RenderViewHostFactory::Create( | 420 pending_render_view_host_ = RenderViewHostFactory::Create( |
| 423 instance, render_view_delegate_, MSG_ROUTING_NONE, NULL); | 421 instance, render_view_delegate_, MSG_ROUTING_NONE, NULL); |
| 424 NotificationService::current()->Notify( | 422 NotificationService::current()->Notify( |
| 425 NotificationType::RENDER_VIEW_HOST_CREATED_FOR_TAB, | 423 NotificationType::RENDER_VIEW_HOST_CREATED_FOR_TAB, |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 474 | 472 |
| 475 // Make sure the size is up to date. (Fix for bug 1079768.) | 473 // Make sure the size is up to date. (Fix for bug 1079768.) |
| 476 delegate_->UpdateRenderViewSizeForRenderManager(); | 474 delegate_->UpdateRenderViewSizeForRenderManager(); |
| 477 | 475 |
| 478 if (focus_render_view && render_view_host_->view()) | 476 if (focus_render_view && render_view_host_->view()) |
| 479 render_view_host_->view()->Focus(); | 477 render_view_host_->view()->Focus(); |
| 480 | 478 |
| 481 RenderViewHostSwitchedDetails details; | 479 RenderViewHostSwitchedDetails details; |
| 482 details.new_host = render_view_host_; | 480 details.new_host = render_view_host_; |
| 483 details.old_host = old_render_view_host; | 481 details.old_host = old_render_view_host; |
| 484 NotificationService::current()->Notify( | 482 delegate_->NotifyRenderViewHostSwitchedFromRenderManager(&details); |
| 485 NotificationType::RENDER_VIEW_HOST_CHANGED, | |
| 486 Source<NavigationController>(&delegate_->GetControllerForRenderManager()), | |
| 487 Details<RenderViewHostSwitchedDetails>(&details)); | |
| 488 | 483 |
| 489 old_render_view_host->Shutdown(); | 484 old_render_view_host->Shutdown(); |
| 490 | 485 |
| 491 // Let the task manager know that we've swapped RenderViewHosts, since it | 486 // Let the task manager know that we've swapped RenderViewHosts, since it |
| 492 // might need to update its process groupings. | 487 // might need to update its process groupings. |
| 493 delegate_->NotifySwappedFromRenderManager(); | 488 delegate_->NotifySwappedFromRenderManager(); |
| 494 } | 489 } |
| 495 | 490 |
| 496 RenderViewHost* RenderViewHostManager::UpdateRendererStateForNavigate( | 491 RenderViewHost* RenderViewHostManager::UpdateRendererStateForNavigate( |
| 497 const NavigationEntry& entry) { | 492 const NavigationEntry& entry) { |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 594 return render_view_host_; | 589 return render_view_host_; |
| 595 } | 590 } |
| 596 | 591 |
| 597 void RenderViewHostManager::CancelPending() { | 592 void RenderViewHostManager::CancelPending() { |
| 598 RenderViewHost* pending_render_view_host = pending_render_view_host_; | 593 RenderViewHost* pending_render_view_host = pending_render_view_host_; |
| 599 pending_render_view_host_ = NULL; | 594 pending_render_view_host_ = NULL; |
| 600 pending_render_view_host->Shutdown(); | 595 pending_render_view_host->Shutdown(); |
| 601 | 596 |
| 602 pending_dom_ui_.reset(); | 597 pending_dom_ui_.reset(); |
| 603 } | 598 } |
| OLD | NEW |