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_manager.h" | 5 #include "chrome/browser/prerender/prerender_manager.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
(...skipping 591 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
602 // don't swap it in because there isn't a good way to merge histories. | 602 // don't swap it in because there isn't a good way to merge histories. |
603 if (prerender_contents->IsCrossSiteNavigationPending()) { | 603 if (prerender_contents->IsCrossSiteNavigationPending()) { |
604 prerender_contents.release()->Destroy( | 604 prerender_contents.release()->Destroy( |
605 FINAL_STATUS_CROSS_SITE_NAVIGATION_PENDING); | 605 FINAL_STATUS_CROSS_SITE_NAVIGATION_PENDING); |
606 return false; | 606 return false; |
607 } | 607 } |
608 | 608 |
609 // If the session storage namespaces don't match, cancel the prerender. | 609 // If the session storage namespaces don't match, cancel the prerender. |
610 RenderViewHost* old_render_view_host = tab_contents->render_view_host(); | 610 RenderViewHost* old_render_view_host = tab_contents->render_view_host(); |
611 RenderViewHost* new_render_view_host = | 611 RenderViewHost* new_render_view_host = |
612 prerender_contents->prerender_contents()->render_view_host(); | 612 prerender_contents->prerender_contents()->tab_contents()-> |
| 613 render_view_host(); |
613 DCHECK(old_render_view_host); | 614 DCHECK(old_render_view_host); |
614 DCHECK(new_render_view_host); | 615 DCHECK(new_render_view_host); |
615 if (old_render_view_host->session_storage_namespace() != | 616 if (old_render_view_host->session_storage_namespace() != |
616 new_render_view_host->session_storage_namespace()) { | 617 new_render_view_host->session_storage_namespace()) { |
617 prerender_contents.release()->Destroy( | 618 prerender_contents.release()->Destroy( |
618 FINAL_STATUS_SESSION_STORAGE_NAMESPACE_MISMATCH); | 619 FINAL_STATUS_SESSION_STORAGE_NAMESPACE_MISMATCH); |
619 return false; | 620 return false; |
620 } | 621 } |
621 | 622 |
622 // If we don't want to use prerenders at all, we are done. | 623 // If we don't want to use prerenders at all, we are done. |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
655 TabContentsWrapper* new_tab_contents = | 656 TabContentsWrapper* new_tab_contents = |
656 prerender_contents->ReleasePrerenderContents(); | 657 prerender_contents->ReleasePrerenderContents(); |
657 TabContentsWrapper* old_tab_contents = | 658 TabContentsWrapper* old_tab_contents = |
658 TabContentsWrapper::GetCurrentWrapperForContents(tab_contents); | 659 TabContentsWrapper::GetCurrentWrapperForContents(tab_contents); |
659 DCHECK(new_tab_contents); | 660 DCHECK(new_tab_contents); |
660 DCHECK(old_tab_contents); | 661 DCHECK(old_tab_contents); |
661 | 662 |
662 MarkTabContentsAsPrerendered(new_tab_contents->tab_contents()); | 663 MarkTabContentsAsPrerendered(new_tab_contents->tab_contents()); |
663 | 664 |
664 // Merge the browsing history. | 665 // Merge the browsing history. |
665 new_tab_contents->controller().CopyStateFromAndPrune( | 666 new_tab_contents->tab_contents()->controller().CopyStateFromAndPrune( |
666 &old_tab_contents->controller()); | 667 &old_tab_contents->tab_contents()->controller()); |
667 old_tab_contents->core_tab_helper()->delegate()-> | 668 old_tab_contents->core_tab_helper()->delegate()-> |
668 SwapTabContents(old_tab_contents, new_tab_contents); | 669 SwapTabContents(old_tab_contents, new_tab_contents); |
669 prerender_contents->CommitHistory(new_tab_contents); | 670 prerender_contents->CommitHistory(new_tab_contents); |
670 | 671 |
671 GURL icon_url = prerender_contents->icon_url(); | 672 GURL icon_url = prerender_contents->icon_url(); |
672 if (!icon_url.is_empty()) { | 673 if (!icon_url.is_empty()) { |
673 std::vector<FaviconURL> urls; | 674 std::vector<FaviconURL> urls; |
674 urls.push_back(FaviconURL(icon_url, FaviconURL::FAVICON)); | 675 urls.push_back(FaviconURL(icon_url, FaviconURL::FAVICON)); |
675 new_tab_contents->favicon_tab_helper()->OnUpdateFaviconURL( | 676 new_tab_contents->favicon_tab_helper()->OnUpdateFaviconURL( |
676 prerender_contents->page_id(), | 677 prerender_contents->page_id(), |
677 urls); | 678 urls); |
678 } | 679 } |
679 | 680 |
680 // Update PPLT metrics: | 681 // Update PPLT metrics: |
681 // If the tab has finished loading, record a PPLT of 0. | 682 // If the tab has finished loading, record a PPLT of 0. |
682 // If the tab is still loading, reset its start time to the current time. | 683 // If the tab is still loading, reset its start time to the current time. |
683 PrerenderTabHelper* prerender_tab_helper = | 684 PrerenderTabHelper* prerender_tab_helper = |
684 new_tab_contents->prerender_tab_helper(); | 685 new_tab_contents->prerender_tab_helper(); |
685 DCHECK(prerender_tab_helper != NULL); | 686 DCHECK(prerender_tab_helper != NULL); |
686 prerender_tab_helper->PrerenderSwappedIn(); | 687 prerender_tab_helper->PrerenderSwappedIn(); |
687 | 688 |
688 // Start pending prerender requests from the PrerenderContents, if there are | 689 // Start pending prerender requests from the PrerenderContents, if there are |
689 // any. | 690 // any. |
690 prerender_contents->StartPendingPrerenders(); | 691 prerender_contents->StartPendingPrerenders(); |
691 | 692 |
692 if (old_tab_contents->tab_contents()->NeedToFireBeforeUnload()) { | 693 if (old_tab_contents->tab_contents()->NeedToFireBeforeUnload()) { |
693 // Schedule the delete to occur after the tab has run its unload handlers. | 694 // Schedule the delete to occur after the tab has run its unload handlers. |
694 on_close_tab_contents_deleters_.push_back( | 695 on_close_tab_contents_deleters_.push_back( |
695 new OnCloseTabContentsDeleter(this, old_tab_contents)); | 696 new OnCloseTabContentsDeleter(this, old_tab_contents)); |
696 old_tab_contents->render_view_host()->FirePageBeforeUnload(false); | 697 old_tab_contents->tab_contents()->render_view_host()-> |
| 698 FirePageBeforeUnload(false); |
697 } else { | 699 } else { |
698 // No unload handler to run, so delete asap. | 700 // No unload handler to run, so delete asap. |
699 ScheduleDeleteOldTabContents(old_tab_contents, NULL); | 701 ScheduleDeleteOldTabContents(old_tab_contents, NULL); |
700 } | 702 } |
701 | 703 |
702 // TODO(cbentzel): Should prerender_contents move to the pending delete | 704 // TODO(cbentzel): Should prerender_contents move to the pending delete |
703 // list, instead of deleting directly here? | 705 // list, instead of deleting directly here? |
704 AddToHistory(prerender_contents.get()); | 706 AddToHistory(prerender_contents.get()); |
705 return true; | 707 return true; |
706 } | 708 } |
(...skipping 439 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1146 if (!render_process_host || !render_process_host->GetBrowserContext()) | 1148 if (!render_process_host || !render_process_host->GetBrowserContext()) |
1147 return NULL; | 1149 return NULL; |
1148 Profile* profile = Profile::FromBrowserContext( | 1150 Profile* profile = Profile::FromBrowserContext( |
1149 render_process_host->GetBrowserContext()); | 1151 render_process_host->GetBrowserContext()); |
1150 if (!profile) | 1152 if (!profile) |
1151 return NULL; | 1153 return NULL; |
1152 return PrerenderManagerFactory::GetInstance()->GetForProfile(profile); | 1154 return PrerenderManagerFactory::GetInstance()->GetForProfile(profile); |
1153 } | 1155 } |
1154 | 1156 |
1155 } // namespace prerender | 1157 } // namespace prerender |
OLD | NEW |