| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/prerender/prerender_contents.h" | 5 #include "chrome/browser/prerender/prerender_contents.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/process_util.h" | 10 #include "base/process_util.h" |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 #include "content/browser/tab_contents/tab_contents_view.h" | 31 #include "content/browser/tab_contents/tab_contents_view.h" |
| 32 #include "content/public/browser/notification_service.h" | 32 #include "content/public/browser/notification_service.h" |
| 33 #include "content/public/browser/web_contents_delegate.h" | 33 #include "content/public/browser/web_contents_delegate.h" |
| 34 #include "ui/gfx/rect.h" | 34 #include "ui/gfx/rect.h" |
| 35 | 35 |
| 36 #if defined(OS_MACOSX) | 36 #if defined(OS_MACOSX) |
| 37 #include "content/browser/mach_broker_mac.h" | 37 #include "content/browser/mach_broker_mac.h" |
| 38 #endif | 38 #endif |
| 39 | 39 |
| 40 using content::DownloadItem; | 40 using content::DownloadItem; |
| 41 using content::WebContents; |
| 41 | 42 |
| 42 namespace prerender { | 43 namespace prerender { |
| 43 | 44 |
| 44 namespace { | 45 namespace { |
| 45 | 46 |
| 46 // Compares URLs ignoring any ref for the purposes of matching URLs when | 47 // Compares URLs ignoring any ref for the purposes of matching URLs when |
| 47 // prerendering. | 48 // prerendering. |
| 48 struct PrerenderURLPredicate { | 49 struct PrerenderURLPredicate { |
| 49 explicit PrerenderURLPredicate(const GURL& url) | 50 explicit PrerenderURLPredicate(const GURL& url) |
| 50 : url_(url) { | 51 : url_(url) { |
| (...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 323 content::Source<Profile>(profile_)); | 324 content::Source<Profile>(profile_)); |
| 324 | 325 |
| 325 // Register to inform new RenderViews that we're prerendering. | 326 // Register to inform new RenderViews that we're prerendering. |
| 326 notification_registrar_.Add( | 327 notification_registrar_.Add( |
| 327 this, content::NOTIFICATION_RENDER_VIEW_HOST_CREATED_FOR_TAB, | 328 this, content::NOTIFICATION_RENDER_VIEW_HOST_CREATED_FOR_TAB, |
| 328 content::Source<TabContents>(new_contents)); | 329 content::Source<TabContents>(new_contents)); |
| 329 | 330 |
| 330 // Register for redirect notifications sourced from |this|. | 331 // Register for redirect notifications sourced from |this|. |
| 331 notification_registrar_.Add( | 332 notification_registrar_.Add( |
| 332 this, content::NOTIFICATION_RESOURCE_RECEIVED_REDIRECT, | 333 this, content::NOTIFICATION_RESOURCE_RECEIVED_REDIRECT, |
| 333 content::Source<RenderViewHostDelegate>(GetRenderViewHostDelegate())); | 334 content::Source<WebContents>(GetWebContents())); |
| 334 | 335 |
| 335 // Register for new windows from any source. | 336 // Register for new windows from any source. |
| 336 notification_registrar_.Add( | 337 notification_registrar_.Add( |
| 337 this, content::NOTIFICATION_CREATING_NEW_WINDOW_CANCELLED, | 338 this, content::NOTIFICATION_CREATING_NEW_WINDOW_CANCELLED, |
| 338 content::Source<TabContents>(new_contents)); | 339 content::Source<TabContents>(new_contents)); |
| 339 | 340 |
| 340 DCHECK(load_start_time_.is_null()); | 341 DCHECK(load_start_time_.is_null()); |
| 341 load_start_time_ = base::TimeTicks::Now(); | 342 load_start_time_ = base::TimeTicks::Now(); |
| 342 | 343 |
| 343 content::PageTransition transition = content::PAGE_TRANSITION_LINK; | 344 content::PageTransition transition = content::PAGE_TRANSITION_LINK; |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 417 case content::NOTIFICATION_APP_TERMINATING: | 418 case content::NOTIFICATION_APP_TERMINATING: |
| 418 Destroy(FINAL_STATUS_APP_TERMINATING); | 419 Destroy(FINAL_STATUS_APP_TERMINATING); |
| 419 return; | 420 return; |
| 420 | 421 |
| 421 case content::NOTIFICATION_RESOURCE_RECEIVED_REDIRECT: { | 422 case content::NOTIFICATION_RESOURCE_RECEIVED_REDIRECT: { |
| 422 // RESOURCE_RECEIVED_REDIRECT can come for any resource on a page. | 423 // RESOURCE_RECEIVED_REDIRECT can come for any resource on a page. |
| 423 // If it's a redirect on the top-level resource, the name needs | 424 // If it's a redirect on the top-level resource, the name needs |
| 424 // to be remembered for future matching, and if it redirects to | 425 // to be remembered for future matching, and if it redirects to |
| 425 // an https resource, it needs to be canceled. If a subresource | 426 // an https resource, it needs to be canceled. If a subresource |
| 426 // is redirected, nothing changes. | 427 // is redirected, nothing changes. |
| 427 DCHECK(content::Source<RenderViewHostDelegate>(source).ptr() == | 428 DCHECK(content::Source<WebContents>(source).ptr() == GetWebContents()); |
| 428 GetRenderViewHostDelegate()); | |
| 429 ResourceRedirectDetails* resource_redirect_details = | 429 ResourceRedirectDetails* resource_redirect_details = |
| 430 content::Details<ResourceRedirectDetails>(details).ptr(); | 430 content::Details<ResourceRedirectDetails>(details).ptr(); |
| 431 CHECK(resource_redirect_details); | 431 CHECK(resource_redirect_details); |
| 432 if (resource_redirect_details->resource_type() == | 432 if (resource_redirect_details->resource_type() == |
| 433 ResourceType::MAIN_FRAME) { | 433 ResourceType::MAIN_FRAME) { |
| 434 if (!AddAliasURL(resource_redirect_details->new_url())) | 434 if (!AddAliasURL(resource_redirect_details->new_url())) |
| 435 return; | 435 return; |
| 436 } | 436 } |
| 437 break; | 437 break; |
| 438 } | 438 } |
| (...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 652 } | 652 } |
| 653 } | 653 } |
| 654 | 654 |
| 655 TabContentsWrapper* PrerenderContents::ReleasePrerenderContents() { | 655 TabContentsWrapper* PrerenderContents::ReleasePrerenderContents() { |
| 656 prerender_contents_->tab_contents()->SetDelegate(NULL); | 656 prerender_contents_->tab_contents()->SetDelegate(NULL); |
| 657 render_view_host_observer_.reset(); | 657 render_view_host_observer_.reset(); |
| 658 content::WebContentsObserver::Observe(NULL); | 658 content::WebContentsObserver::Observe(NULL); |
| 659 return prerender_contents_.release(); | 659 return prerender_contents_.release(); |
| 660 } | 660 } |
| 661 | 661 |
| 662 RenderViewHostDelegate* PrerenderContents::GetRenderViewHostDelegate() { | 662 WebContents* PrerenderContents::GetWebContents() { |
| 663 if (!prerender_contents_.get()) | 663 if (!prerender_contents_.get()) |
| 664 return NULL; | 664 return NULL; |
| 665 return prerender_contents_->tab_contents(); | 665 return prerender_contents_->tab_contents(); |
| 666 } | 666 } |
| 667 | 667 |
| 668 RenderViewHost* PrerenderContents::render_view_host_mutable() { | 668 RenderViewHost* PrerenderContents::render_view_host_mutable() { |
| 669 return const_cast<RenderViewHost*>(render_view_host()); | 669 return const_cast<RenderViewHost*>(render_view_host()); |
| 670 } | 670 } |
| 671 | 671 |
| 672 const RenderViewHost* PrerenderContents::render_view_host() const { | 672 const RenderViewHost* PrerenderContents::render_view_host() const { |
| (...skipping 21 matching lines...) Expand all Loading... |
| 694 bool PrerenderContents::IsCrossSiteNavigationPending() const { | 694 bool PrerenderContents::IsCrossSiteNavigationPending() const { |
| 695 if (!prerender_contents_.get() || !prerender_contents_->tab_contents()) | 695 if (!prerender_contents_.get() || !prerender_contents_->tab_contents()) |
| 696 return false; | 696 return false; |
| 697 const TabContents* tab_contents = prerender_contents_->tab_contents(); | 697 const TabContents* tab_contents = prerender_contents_->tab_contents(); |
| 698 return (tab_contents->GetSiteInstance() != | 698 return (tab_contents->GetSiteInstance() != |
| 699 tab_contents->GetPendingSiteInstance()); | 699 tab_contents->GetPendingSiteInstance()); |
| 700 } | 700 } |
| 701 | 701 |
| 702 | 702 |
| 703 } // namespace prerender | 703 } // namespace prerender |
| OLD | NEW |