Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(148)

Side by Side Diff: content/browser/frame_host/navigation_controller_impl.cc

Issue 30323002: [DRAFT] Create RenderFrameHostManager. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Misc fixes Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "content/browser/frame_host/navigation_controller_impl.h" 5 #include "content/browser/frame_host/navigation_controller_impl.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/debug/trace_event.h" 8 #include "base/debug/trace_event.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/strings/string_number_conversions.h" // Temporary 10 #include "base/strings/string_number_conversions.h" // Temporary
(...skipping 706 matching lines...) Expand 10 before | Expand all | Expand 10 after
717 break; 717 break;
718 default: 718 default:
719 NOTREACHED(); 719 NOTREACHED();
720 break; 720 break;
721 }; 721 };
722 722
723 LoadEntry(entry); 723 LoadEntry(entry);
724 } 724 }
725 725
726 bool NavigationControllerImpl::RendererDidNavigate( 726 bool NavigationControllerImpl::RendererDidNavigate(
727 RenderViewHost* rvh,
727 const ViewHostMsg_FrameNavigate_Params& params, 728 const ViewHostMsg_FrameNavigate_Params& params,
728 LoadCommittedDetails* details) { 729 LoadCommittedDetails* details) {
729 is_initial_navigation_ = false; 730 is_initial_navigation_ = false;
730 731
731 // Save the previous state before we clobber it. 732 // Save the previous state before we clobber it.
732 if (GetLastCommittedEntry()) { 733 if (GetLastCommittedEntry()) {
733 details->previous_url = GetLastCommittedEntry()->GetURL(); 734 details->previous_url = GetLastCommittedEntry()->GetURL();
734 details->previous_entry_index = GetLastCommittedEntryIndex(); 735 details->previous_entry_index = GetLastCommittedEntryIndex();
735 } else { 736 } else {
736 details->previous_url = GURL(); 737 details->previous_url = GURL();
737 details->previous_entry_index = -1; 738 details->previous_entry_index = -1;
738 } 739 }
739 740
740 // If we have a pending entry at this point, it should have a SiteInstance. 741 // If we have a pending entry at this point, it should have a SiteInstance.
741 // Restored entries start out with a null SiteInstance, but we should have 742 // Restored entries start out with a null SiteInstance, but we should have
742 // assigned one in NavigateToPendingEntry. 743 // assigned one in NavigateToPendingEntry.
743 DCHECK(pending_entry_index_ == -1 || pending_entry_->site_instance()); 744 DCHECK(pending_entry_index_ == -1 || pending_entry_->site_instance());
744 745
745 // If we are doing a cross-site reload, we need to replace the existing 746 // If we are doing a cross-site reload, we need to replace the existing
746 // navigation entry, not add another entry to the history. This has the side 747 // navigation entry, not add another entry to the history. This has the side
747 // effect of removing forward browsing history, if such existed. 748 // effect of removing forward browsing history, if such existed.
748 // Or if we are doing a cross-site redirect navigation, 749 // Or if we are doing a cross-site redirect navigation,
749 // we will do a similar thing. 750 // we will do a similar thing.
750 details->did_replace_entry = 751 details->did_replace_entry =
751 pending_entry_ && pending_entry_->should_replace_entry(); 752 pending_entry_ && pending_entry_->should_replace_entry();
752 753
753 // Do navigation-type specific actions. These will make and commit an entry. 754 // Do navigation-type specific actions. These will make and commit an entry.
754 details->type = ClassifyNavigation(params); 755 details->type = ClassifyNavigation(rvh, params);
755 756
756 // is_in_page must be computed before the entry gets committed. 757 // is_in_page must be computed before the entry gets committed.
757 details->is_in_page = IsURLInPageNavigation( 758 details->is_in_page = IsURLInPageNavigation(
758 params.url, params.was_within_same_page, details->type); 759 params.url, params.was_within_same_page, details->type);
759 760
760 switch (details->type) { 761 switch (details->type) {
761 case NAVIGATION_TYPE_NEW_PAGE: 762 case NAVIGATION_TYPE_NEW_PAGE:
762 RendererDidNavigateToNewPage(params, details->did_replace_entry); 763 RendererDidNavigateToNewPage(rvh, params, details->did_replace_entry);
763 break; 764 break;
764 case NAVIGATION_TYPE_EXISTING_PAGE: 765 case NAVIGATION_TYPE_EXISTING_PAGE:
765 RendererDidNavigateToExistingPage(params); 766 RendererDidNavigateToExistingPage(rvh, params);
766 break; 767 break;
767 case NAVIGATION_TYPE_SAME_PAGE: 768 case NAVIGATION_TYPE_SAME_PAGE:
768 RendererDidNavigateToSamePage(params); 769 RendererDidNavigateToSamePage(rvh, params);
769 break; 770 break;
770 case NAVIGATION_TYPE_IN_PAGE: 771 case NAVIGATION_TYPE_IN_PAGE:
771 RendererDidNavigateInPage(params, &details->did_replace_entry); 772 RendererDidNavigateInPage(rvh, params, &details->did_replace_entry);
772 break; 773 break;
773 case NAVIGATION_TYPE_NEW_SUBFRAME: 774 case NAVIGATION_TYPE_NEW_SUBFRAME:
774 RendererDidNavigateNewSubframe(params); 775 RendererDidNavigateNewSubframe(rvh, params);
775 break; 776 break;
776 case NAVIGATION_TYPE_AUTO_SUBFRAME: 777 case NAVIGATION_TYPE_AUTO_SUBFRAME:
777 if (!RendererDidNavigateAutoSubframe(params)) 778 if (!RendererDidNavigateAutoSubframe(rvh, params))
778 return false; 779 return false;
779 break; 780 break;
780 case NAVIGATION_TYPE_NAV_IGNORE: 781 case NAVIGATION_TYPE_NAV_IGNORE:
781 // If a pending navigation was in progress, this canceled it. We should 782 // If a pending navigation was in progress, this canceled it. We should
782 // discard it and make sure it is removed from the URL bar. After that, 783 // discard it and make sure it is removed from the URL bar. After that,
783 // there is nothing we can do with this navigation, so we just return to 784 // there is nothing we can do with this navigation, so we just return to
784 // the caller that nothing has happened. 785 // the caller that nothing has happened.
785 if (pending_entry_) { 786 if (pending_entry_) {
786 DiscardNonCommittedEntries(); 787 DiscardNonCommittedEntries();
787 delegate_->NotifyNavigationStateChanged(INVALIDATE_TYPE_URL); 788 delegate_->NotifyNavigationStateChanged(INVALIDATE_TYPE_URL);
(...skipping 24 matching lines...) Expand all
812 NavigationEntryImpl::FromNavigationEntry(GetLastCommittedEntry()); 813 NavigationEntryImpl::FromNavigationEntry(GetLastCommittedEntry());
813 active_entry->SetTimestamp(timestamp); 814 active_entry->SetTimestamp(timestamp);
814 active_entry->SetHttpStatusCode(params.http_status_code); 815 active_entry->SetHttpStatusCode(params.http_status_code);
815 active_entry->SetPageState(params.page_state); 816 active_entry->SetPageState(params.page_state);
816 817
817 // Once it is committed, we no longer need to track several pieces of state on 818 // Once it is committed, we no longer need to track several pieces of state on
818 // the entry. 819 // the entry.
819 active_entry->ResetForCommit(); 820 active_entry->ResetForCommit();
820 821
821 // The active entry's SiteInstance should match our SiteInstance. 822 // The active entry's SiteInstance should match our SiteInstance.
822 CHECK(active_entry->site_instance() == delegate_->GetSiteInstance()); 823 // TODO(creis): This check won't pass for subframes until we create entries
824 // for subframe navigations.
825 if (PageTransitionIsMainFrame(params.transition))
826 CHECK(active_entry->site_instance() == rvh->GetSiteInstance());
823 827
824 // Remember the bindings the renderer process has at this point, so that 828 // Remember the bindings the renderer process has at this point, so that
825 // we do not grant this entry additional bindings if we come back to it. 829 // we do not grant this entry additional bindings if we come back to it.
826 active_entry->SetBindings( 830 active_entry->SetBindings(rvh->GetEnabledBindings());
827 delegate_->GetRenderViewHost()->GetEnabledBindings());
828 831
829 // Now prep the rest of the details for the notification and broadcast. 832 // Now prep the rest of the details for the notification and broadcast.
830 details->entry = active_entry; 833 details->entry = active_entry;
831 details->is_main_frame = 834 details->is_main_frame =
832 PageTransitionIsMainFrame(params.transition); 835 PageTransitionIsMainFrame(params.transition);
833 details->serialized_security_info = params.security_info; 836 details->serialized_security_info = params.security_info;
834 details->http_status_code = params.http_status_code; 837 details->http_status_code = params.http_status_code;
835 NotifyNavigationEntryCommitted(details); 838 NotifyNavigationEntryCommitted(details);
836 839
837 return true; 840 return true;
838 } 841 }
839 842
840 NavigationType NavigationControllerImpl::ClassifyNavigation( 843 NavigationType NavigationControllerImpl::ClassifyNavigation(
844 RenderViewHost* rvh,
841 const ViewHostMsg_FrameNavigate_Params& params) const { 845 const ViewHostMsg_FrameNavigate_Params& params) const {
842 if (params.page_id == -1) { 846 if (params.page_id == -1) {
843 // The renderer generates the page IDs, and so if it gives us the invalid 847 // The renderer generates the page IDs, and so if it gives us the invalid
844 // page ID (-1) we know it didn't actually navigate. This happens in a few 848 // page ID (-1) we know it didn't actually navigate. This happens in a few
845 // cases: 849 // cases:
846 // 850 //
847 // - If a page makes a popup navigated to about blank, and then writes 851 // - If a page makes a popup navigated to about blank, and then writes
848 // stuff like a subframe navigated to a real page. We'll get the commit 852 // stuff like a subframe navigated to a real page. We'll get the commit
849 // for the subframe, but there won't be any commit for the outer page. 853 // for the subframe, but there won't be any commit for the outer page.
850 // 854 //
851 // - We were also getting these for failed loads (for example, bug 21849). 855 // - We were also getting these for failed loads (for example, bug 21849).
852 // The guess is that we get a "load commit" for the alternate error page, 856 // The guess is that we get a "load commit" for the alternate error page,
853 // but that doesn't affect the page ID, so we get the "old" one, which 857 // but that doesn't affect the page ID, so we get the "old" one, which
854 // could be invalid. This can also happen for a cross-site transition 858 // could be invalid. This can also happen for a cross-site transition
855 // that causes us to swap processes. Then the error page load will be in 859 // that causes us to swap processes. Then the error page load will be in
856 // a new process with no page IDs ever assigned (and hence a -1 value), 860 // a new process with no page IDs ever assigned (and hence a -1 value),
857 // yet the navigation controller still might have previous pages in its 861 // yet the navigation controller still might have previous pages in its
858 // list. 862 // list.
859 // 863 //
860 // In these cases, there's nothing we can do with them, so ignore. 864 // In these cases, there's nothing we can do with them, so ignore.
861 return NAVIGATION_TYPE_NAV_IGNORE; 865 return NAVIGATION_TYPE_NAV_IGNORE;
862 } 866 }
863 867
864 if (params.page_id > delegate_->GetMaxPageID()) { 868 if (params.page_id > delegate_->GetMaxPageIDForSiteInstance(
869 rvh->GetSiteInstance())) {
865 // Greater page IDs than we've ever seen before are new pages. We may or may 870 // Greater page IDs than we've ever seen before are new pages. We may or may
866 // not have a pending entry for the page, and this may or may not be the 871 // not have a pending entry for the page, and this may or may not be the
867 // main frame. 872 // main frame.
868 if (PageTransitionIsMainFrame(params.transition)) 873 if (PageTransitionIsMainFrame(params.transition))
869 return NAVIGATION_TYPE_NEW_PAGE; 874 return NAVIGATION_TYPE_NEW_PAGE;
870 875
871 // When this is a new subframe navigation, we should have a committed page 876 // When this is a new subframe navigation, we should have a committed page
872 // for which it's a suframe in. This may not be the case when an iframe is 877 // for which it's a suframe in. This may not be the case when an iframe is
873 // navigated on a popup navigated to about:blank (the iframe would be 878 // navigated on a popup navigated to about:blank (the iframe would be
874 // written into the popup by script on the main page). For these cases, 879 // written into the popup by script on the main page). For these cases,
875 // there isn't any navigation stuff we can do, so just ignore it. 880 // there isn't any navigation stuff we can do, so just ignore it.
876 if (!GetLastCommittedEntry()) 881 if (!GetLastCommittedEntry())
877 return NAVIGATION_TYPE_NAV_IGNORE; 882 return NAVIGATION_TYPE_NAV_IGNORE;
878 883
879 // Valid subframe navigation. 884 // Valid subframe navigation.
880 return NAVIGATION_TYPE_NEW_SUBFRAME; 885 return NAVIGATION_TYPE_NEW_SUBFRAME;
881 } 886 }
882 887
883 // We only clear the session history when navigating to a new page. 888 // We only clear the session history when navigating to a new page.
884 DCHECK(!params.history_list_was_cleared); 889 DCHECK(!params.history_list_was_cleared);
885 890
886 // Now we know that the notification is for an existing page. Find that entry. 891 // Now we know that the notification is for an existing page. Find that entry.
887 int existing_entry_index = GetEntryIndexWithPageID( 892 int existing_entry_index = GetEntryIndexWithPageID(
888 delegate_->GetSiteInstance(), 893 rvh->GetSiteInstance(),
889 params.page_id); 894 params.page_id);
890 if (existing_entry_index == -1) { 895 if (existing_entry_index == -1) {
891 // The page was not found. It could have been pruned because of the limit on 896 // The page was not found. It could have been pruned because of the limit on
892 // back/forward entries (not likely since we'll usually tell it to navigate 897 // back/forward entries (not likely since we'll usually tell it to navigate
893 // to such entries). It could also mean that the renderer is smoking crack. 898 // to such entries). It could also mean that the renderer is smoking crack.
894 NOTREACHED(); 899 NOTREACHED();
895 900
896 // Because the unknown entry has committed, we risk showing the wrong URL in 901 // Because the unknown entry has committed, we risk showing the wrong URL in
897 // release builds. Instead, we'll kill the renderer process to be safe. 902 // release builds. Instead, we'll kill the renderer process to be safe.
898 LOG(ERROR) << "terminating renderer for bad navigation: " << params.url; 903 LOG(ERROR) << "terminating renderer for bad navigation: " << params.url;
(...skipping 13 matching lines...) Expand all
912 // Append entry metadata (e.g., 3_7x): 917 // Append entry metadata (e.g., 3_7x):
913 // 3: page_id 918 // 3: page_id
914 // 7: SiteInstance ID, or N for null 919 // 7: SiteInstance ID, or N for null
915 // x: appended if not from the current SiteInstance 920 // x: appended if not from the current SiteInstance
916 temp.append(base::IntToString(entries_[i]->GetPageID())); 921 temp.append(base::IntToString(entries_[i]->GetPageID()));
917 temp.append("_"); 922 temp.append("_");
918 if (entries_[i]->site_instance()) 923 if (entries_[i]->site_instance())
919 temp.append(base::IntToString(entries_[i]->site_instance()->GetId())); 924 temp.append(base::IntToString(entries_[i]->site_instance()->GetId()));
920 else 925 else
921 temp.append("N"); 926 temp.append("N");
922 if (entries_[i]->site_instance() != delegate_->GetSiteInstance()) 927 if (entries_[i]->site_instance() != rvh->GetSiteInstance())
923 temp.append("x"); 928 temp.append("x");
924 temp.append(","); 929 temp.append(",");
925 } 930 }
926 GURL url(temp); 931 GURL url(temp);
927 static_cast<RenderViewHostImpl*>( 932 static_cast<RenderViewHostImpl*>(rvh)->Send(
928 delegate_->GetRenderViewHost())->Send( 933 new ViewMsg_TempCrashWithData(url));
929 new ViewMsg_TempCrashWithData(url));
930 return NAVIGATION_TYPE_NAV_IGNORE; 934 return NAVIGATION_TYPE_NAV_IGNORE;
931 } 935 }
932 NavigationEntryImpl* existing_entry = entries_[existing_entry_index].get(); 936 NavigationEntryImpl* existing_entry = entries_[existing_entry_index].get();
933 937
934 if (!PageTransitionIsMainFrame(params.transition)) { 938 if (!PageTransitionIsMainFrame(params.transition)) {
935 // All manual subframes would get new IDs and were handled above, so we 939 // All manual subframes would get new IDs and were handled above, so we
936 // know this is auto. Since the current page was found in the navigation 940 // know this is auto. Since the current page was found in the navigation
937 // entry list, we're guaranteed to have a last committed entry. 941 // entry list, we're guaranteed to have a last committed entry.
938 DCHECK(GetLastCommittedEntry()); 942 DCHECK(GetLastCommittedEntry());
939 return NAVIGATION_TYPE_AUTO_SUBFRAME; 943 return NAVIGATION_TYPE_AUTO_SUBFRAME;
(...skipping 25 matching lines...) Expand all
965 NAVIGATION_TYPE_UNKNOWN)) { 969 NAVIGATION_TYPE_UNKNOWN)) {
966 return NAVIGATION_TYPE_IN_PAGE; 970 return NAVIGATION_TYPE_IN_PAGE;
967 } 971 }
968 972
969 // Since we weeded out "new" navigations above, we know this is an existing 973 // Since we weeded out "new" navigations above, we know this is an existing
970 // (back/forward) navigation. 974 // (back/forward) navigation.
971 return NAVIGATION_TYPE_EXISTING_PAGE; 975 return NAVIGATION_TYPE_EXISTING_PAGE;
972 } 976 }
973 977
974 void NavigationControllerImpl::RendererDidNavigateToNewPage( 978 void NavigationControllerImpl::RendererDidNavigateToNewPage(
975 const ViewHostMsg_FrameNavigate_Params& params, bool replace_entry) { 979 RenderViewHost* rvh,
980 const ViewHostMsg_FrameNavigate_Params& params,
981 bool replace_entry) {
976 NavigationEntryImpl* new_entry; 982 NavigationEntryImpl* new_entry;
977 bool update_virtual_url; 983 bool update_virtual_url;
978 // Only make a copy of the pending entry if it is appropriate for the new page 984 // Only make a copy of the pending entry if it is appropriate for the new page
979 // that was just loaded. We verify this at a coarse grain by checking that 985 // that was just loaded. We verify this at a coarse grain by checking that
980 // the SiteInstance hasn't been assigned to something else. 986 // the SiteInstance hasn't been assigned to something else.
981 if (pending_entry_ && 987 if (pending_entry_ &&
982 (!pending_entry_->site_instance() || 988 (!pending_entry_->site_instance() ||
983 pending_entry_->site_instance() == delegate_->GetSiteInstance())) { 989 pending_entry_->site_instance() == rvh->GetSiteInstance())) {
984 new_entry = new NavigationEntryImpl(*pending_entry_); 990 new_entry = new NavigationEntryImpl(*pending_entry_);
985 991
986 // Don't use the page type from the pending entry. Some interstitial page 992 // Don't use the page type from the pending entry. Some interstitial page
987 // may have set the type to interstitial. Once we commit, however, the page 993 // may have set the type to interstitial. Once we commit, however, the page
988 // type must always be normal. 994 // type must always be normal.
989 new_entry->set_page_type(PAGE_TYPE_NORMAL); 995 new_entry->set_page_type(PAGE_TYPE_NORMAL);
990 update_virtual_url = new_entry->update_virtual_url_with_url(); 996 update_virtual_url = new_entry->update_virtual_url_with_url();
991 } else { 997 } else {
992 new_entry = new NavigationEntryImpl; 998 new_entry = new NavigationEntryImpl;
993 999
(...skipping 13 matching lines...) Expand all
1007 update_virtual_url = needs_update; 1013 update_virtual_url = needs_update;
1008 } 1014 }
1009 1015
1010 new_entry->SetURL(params.url); 1016 new_entry->SetURL(params.url);
1011 if (update_virtual_url) 1017 if (update_virtual_url)
1012 UpdateVirtualURLToURL(new_entry, params.url); 1018 UpdateVirtualURLToURL(new_entry, params.url);
1013 new_entry->SetReferrer(params.referrer); 1019 new_entry->SetReferrer(params.referrer);
1014 new_entry->SetPageID(params.page_id); 1020 new_entry->SetPageID(params.page_id);
1015 new_entry->SetTransitionType(params.transition); 1021 new_entry->SetTransitionType(params.transition);
1016 new_entry->set_site_instance( 1022 new_entry->set_site_instance(
1017 static_cast<SiteInstanceImpl*>(delegate_->GetSiteInstance())); 1023 static_cast<SiteInstanceImpl*>(rvh->GetSiteInstance()));
1018 new_entry->SetHasPostData(params.is_post); 1024 new_entry->SetHasPostData(params.is_post);
1019 new_entry->SetPostID(params.post_id); 1025 new_entry->SetPostID(params.post_id);
1020 new_entry->SetOriginalRequestURL(params.original_request_url); 1026 new_entry->SetOriginalRequestURL(params.original_request_url);
1021 new_entry->SetIsOverridingUserAgent(params.is_overriding_user_agent); 1027 new_entry->SetIsOverridingUserAgent(params.is_overriding_user_agent);
1022 1028
1023 DCHECK(!params.history_list_was_cleared || !replace_entry); 1029 DCHECK(!params.history_list_was_cleared || !replace_entry);
1024 // The browser requested to clear the session history when it initiated the 1030 // The browser requested to clear the session history when it initiated the
1025 // navigation. Now we know that the renderer has updated its state accordingly 1031 // navigation. Now we know that the renderer has updated its state accordingly
1026 // and it is safe to also clear the browser side history. 1032 // and it is safe to also clear the browser side history.
1027 if (params.history_list_was_cleared) { 1033 if (params.history_list_was_cleared) {
1028 DiscardNonCommittedEntriesInternal(); 1034 DiscardNonCommittedEntriesInternal();
1029 entries_.clear(); 1035 entries_.clear();
1030 last_committed_entry_index_ = -1; 1036 last_committed_entry_index_ = -1;
1031 } 1037 }
1032 1038
1033 InsertOrReplaceEntry(new_entry, replace_entry); 1039 InsertOrReplaceEntry(new_entry, replace_entry);
1034 } 1040 }
1035 1041
1036 void NavigationControllerImpl::RendererDidNavigateToExistingPage( 1042 void NavigationControllerImpl::RendererDidNavigateToExistingPage(
1043 RenderViewHost* rvh,
1037 const ViewHostMsg_FrameNavigate_Params& params) { 1044 const ViewHostMsg_FrameNavigate_Params& params) {
1038 // We should only get here for main frame navigations. 1045 // We should only get here for main frame navigations.
1039 DCHECK(PageTransitionIsMainFrame(params.transition)); 1046 DCHECK(PageTransitionIsMainFrame(params.transition));
1040 1047
1041 // This is a back/forward navigation. The existing page for the ID is 1048 // This is a back/forward navigation. The existing page for the ID is
1042 // guaranteed to exist by ClassifyNavigation, and we just need to update it 1049 // guaranteed to exist by ClassifyNavigation, and we just need to update it
1043 // with new information from the renderer. 1050 // with new information from the renderer.
1044 int entry_index = GetEntryIndexWithPageID(delegate_->GetSiteInstance(), 1051 int entry_index = GetEntryIndexWithPageID(rvh->GetSiteInstance(),
1045 params.page_id); 1052 params.page_id);
1046 DCHECK(entry_index >= 0 && 1053 DCHECK(entry_index >= 0 &&
1047 entry_index < static_cast<int>(entries_.size())); 1054 entry_index < static_cast<int>(entries_.size()));
1048 NavigationEntryImpl* entry = entries_[entry_index].get(); 1055 NavigationEntryImpl* entry = entries_[entry_index].get();
1049 1056
1050 // The URL may have changed due to redirects. 1057 // The URL may have changed due to redirects.
1051 entry->SetURL(params.url); 1058 entry->SetURL(params.url);
1052 if (entry->update_virtual_url_with_url()) 1059 if (entry->update_virtual_url_with_url())
1053 UpdateVirtualURLToURL(entry, params.url); 1060 UpdateVirtualURLToURL(entry, params.url);
1054 1061
1055 // The redirected to page should not inherit the favicon from the previous 1062 // The redirected to page should not inherit the favicon from the previous
1056 // page. 1063 // page.
1057 if (PageTransitionIsRedirect(params.transition)) 1064 if (PageTransitionIsRedirect(params.transition))
1058 entry->GetFavicon() = FaviconStatus(); 1065 entry->GetFavicon() = FaviconStatus();
1059 1066
1060 // The site instance will normally be the same except during session restore, 1067 // The site instance will normally be the same except during session restore,
1061 // when no site instance will be assigned. 1068 // when no site instance will be assigned.
1062 DCHECK(entry->site_instance() == NULL || 1069 DCHECK(entry->site_instance() == NULL ||
1063 entry->site_instance() == delegate_->GetSiteInstance()); 1070 entry->site_instance() == rvh->GetSiteInstance());
1064 entry->set_site_instance( 1071 entry->set_site_instance(
1065 static_cast<SiteInstanceImpl*>(delegate_->GetSiteInstance())); 1072 static_cast<SiteInstanceImpl*>(rvh->GetSiteInstance()));
1066 1073
1067 entry->SetHasPostData(params.is_post); 1074 entry->SetHasPostData(params.is_post);
1068 entry->SetPostID(params.post_id); 1075 entry->SetPostID(params.post_id);
1069 1076
1070 // The entry we found in the list might be pending if the user hit 1077 // The entry we found in the list might be pending if the user hit
1071 // back/forward/reload. This load should commit it (since it's already in the 1078 // back/forward/reload. This load should commit it (since it's already in the
1072 // list, we can just discard the pending pointer). We should also discard the 1079 // list, we can just discard the pending pointer). We should also discard the
1073 // pending entry if it corresponds to a different navigation, since that one 1080 // pending entry if it corresponds to a different navigation, since that one
1074 // is now likely canceled. If it is not canceled, we will treat it as a new 1081 // is now likely canceled. If it is not canceled, we will treat it as a new
1075 // navigation when it arrives, which is also ok. 1082 // navigation when it arrives, which is also ok.
1076 // 1083 //
1077 // Note that we need to use the "internal" version since we don't want to 1084 // Note that we need to use the "internal" version since we don't want to
1078 // actually change any other state, just kill the pointer. 1085 // actually change any other state, just kill the pointer.
1079 DiscardNonCommittedEntriesInternal(); 1086 DiscardNonCommittedEntriesInternal();
1080 1087
1081 // If a transient entry was removed, the indices might have changed, so we 1088 // If a transient entry was removed, the indices might have changed, so we
1082 // have to query the entry index again. 1089 // have to query the entry index again.
1083 last_committed_entry_index_ = 1090 last_committed_entry_index_ =
1084 GetEntryIndexWithPageID(delegate_->GetSiteInstance(), params.page_id); 1091 GetEntryIndexWithPageID(rvh->GetSiteInstance(), params.page_id);
1085 } 1092 }
1086 1093
1087 void NavigationControllerImpl::RendererDidNavigateToSamePage( 1094 void NavigationControllerImpl::RendererDidNavigateToSamePage(
1095 RenderViewHost* rvh,
1088 const ViewHostMsg_FrameNavigate_Params& params) { 1096 const ViewHostMsg_FrameNavigate_Params& params) {
1089 // This mode implies we have a pending entry that's the same as an existing 1097 // This mode implies we have a pending entry that's the same as an existing
1090 // entry for this page ID. This entry is guaranteed to exist by 1098 // entry for this page ID. This entry is guaranteed to exist by
1091 // ClassifyNavigation. All we need to do is update the existing entry. 1099 // ClassifyNavigation. All we need to do is update the existing entry.
1092 NavigationEntryImpl* existing_entry = GetEntryWithPageID( 1100 NavigationEntryImpl* existing_entry = GetEntryWithPageID(
1093 delegate_->GetSiteInstance(), params.page_id); 1101 rvh->GetSiteInstance(), params.page_id);
1094 1102
1095 // We assign the entry's unique ID to be that of the new one. Since this is 1103 // We assign the entry's unique ID to be that of the new one. Since this is
1096 // always the result of a user action, we want to dismiss infobars, etc. like 1104 // always the result of a user action, we want to dismiss infobars, etc. like
1097 // a regular user-initiated navigation. 1105 // a regular user-initiated navigation.
1098 existing_entry->set_unique_id(pending_entry_->GetUniqueID()); 1106 existing_entry->set_unique_id(pending_entry_->GetUniqueID());
1099 1107
1100 // The URL may have changed due to redirects. 1108 // The URL may have changed due to redirects.
1101 if (existing_entry->update_virtual_url_with_url()) 1109 if (existing_entry->update_virtual_url_with_url())
1102 UpdateVirtualURLToURL(existing_entry, params.url); 1110 UpdateVirtualURLToURL(existing_entry, params.url);
1103 existing_entry->SetURL(params.url); 1111 existing_entry->SetURL(params.url);
1104 1112
1105 // The page may have been requested with a different HTTP method. 1113 // The page may have been requested with a different HTTP method.
1106 existing_entry->SetHasPostData(params.is_post); 1114 existing_entry->SetHasPostData(params.is_post);
1107 existing_entry->SetPostID(params.post_id); 1115 existing_entry->SetPostID(params.post_id);
1108 1116
1109 DiscardNonCommittedEntries(); 1117 DiscardNonCommittedEntries();
1110 } 1118 }
1111 1119
1112 void NavigationControllerImpl::RendererDidNavigateInPage( 1120 void NavigationControllerImpl::RendererDidNavigateInPage(
1113 const ViewHostMsg_FrameNavigate_Params& params, bool* did_replace_entry) { 1121 RenderViewHost* rvh,
1122 const ViewHostMsg_FrameNavigate_Params& params,
1123 bool* did_replace_entry) {
1114 DCHECK(PageTransitionIsMainFrame(params.transition)) << 1124 DCHECK(PageTransitionIsMainFrame(params.transition)) <<
1115 "WebKit should only tell us about in-page navs for the main frame."; 1125 "WebKit should only tell us about in-page navs for the main frame.";
1116 // We're guaranteed to have an entry for this one. 1126 // We're guaranteed to have an entry for this one.
1117 NavigationEntryImpl* existing_entry = GetEntryWithPageID( 1127 NavigationEntryImpl* existing_entry = GetEntryWithPageID(
1118 delegate_->GetSiteInstance(), params.page_id); 1128 rvh->GetSiteInstance(), params.page_id);
1119 1129
1120 // Reference fragment navigation. We're guaranteed to have the last_committed 1130 // Reference fragment navigation. We're guaranteed to have the last_committed
1121 // entry and it will be the same page as the new navigation (minus the 1131 // entry and it will be the same page as the new navigation (minus the
1122 // reference fragments, of course). We'll update the URL of the existing 1132 // reference fragments, of course). We'll update the URL of the existing
1123 // entry without pruning the forward history. 1133 // entry without pruning the forward history.
1124 existing_entry->SetURL(params.url); 1134 existing_entry->SetURL(params.url);
1125 if (existing_entry->update_virtual_url_with_url()) 1135 if (existing_entry->update_virtual_url_with_url())
1126 UpdateVirtualURLToURL(existing_entry, params.url); 1136 UpdateVirtualURLToURL(existing_entry, params.url);
1127 1137
1128 // This replaces the existing entry since the page ID didn't change. 1138 // This replaces the existing entry since the page ID didn't change.
1129 *did_replace_entry = true; 1139 *did_replace_entry = true;
1130 1140
1131 DiscardNonCommittedEntriesInternal(); 1141 DiscardNonCommittedEntriesInternal();
1132 1142
1133 // If a transient entry was removed, the indices might have changed, so we 1143 // If a transient entry was removed, the indices might have changed, so we
1134 // have to query the entry index again. 1144 // have to query the entry index again.
1135 last_committed_entry_index_ = 1145 last_committed_entry_index_ =
1136 GetEntryIndexWithPageID(delegate_->GetSiteInstance(), params.page_id); 1146 GetEntryIndexWithPageID(rvh->GetSiteInstance(), params.page_id);
1137 } 1147 }
1138 1148
1139 void NavigationControllerImpl::RendererDidNavigateNewSubframe( 1149 void NavigationControllerImpl::RendererDidNavigateNewSubframe(
1150 RenderViewHost* rvh,
1140 const ViewHostMsg_FrameNavigate_Params& params) { 1151 const ViewHostMsg_FrameNavigate_Params& params) {
1141 if (PageTransitionCoreTypeIs(params.transition, 1152 if (PageTransitionCoreTypeIs(params.transition,
1142 PAGE_TRANSITION_AUTO_SUBFRAME)) { 1153 PAGE_TRANSITION_AUTO_SUBFRAME)) {
1143 // This is not user-initiated. Ignore. 1154 // This is not user-initiated. Ignore.
1144 DiscardNonCommittedEntriesInternal(); 1155 DiscardNonCommittedEntriesInternal();
1145 return; 1156 return;
1146 } 1157 }
1147 1158
1148 // Manual subframe navigations just get the current entry cloned so the user 1159 // Manual subframe navigations just get the current entry cloned so the user
1149 // can go back or forward to it. The actual subframe information will be 1160 // can go back or forward to it. The actual subframe information will be
1150 // stored in the page state for each of those entries. This happens out of 1161 // stored in the page state for each of those entries. This happens out of
1151 // band with the actual navigations. 1162 // band with the actual navigations.
1152 DCHECK(GetLastCommittedEntry()) << "ClassifyNavigation should guarantee " 1163 DCHECK(GetLastCommittedEntry()) << "ClassifyNavigation should guarantee "
1153 << "that a last committed entry exists."; 1164 << "that a last committed entry exists.";
1154 NavigationEntryImpl* new_entry = new NavigationEntryImpl( 1165 NavigationEntryImpl* new_entry = new NavigationEntryImpl(
1155 *NavigationEntryImpl::FromNavigationEntry(GetLastCommittedEntry())); 1166 *NavigationEntryImpl::FromNavigationEntry(GetLastCommittedEntry()));
1156 new_entry->SetPageID(params.page_id); 1167 new_entry->SetPageID(params.page_id);
1157 InsertOrReplaceEntry(new_entry, false); 1168 InsertOrReplaceEntry(new_entry, false);
1158 } 1169 }
1159 1170
1160 bool NavigationControllerImpl::RendererDidNavigateAutoSubframe( 1171 bool NavigationControllerImpl::RendererDidNavigateAutoSubframe(
1172 RenderViewHost* rvh,
1161 const ViewHostMsg_FrameNavigate_Params& params) { 1173 const ViewHostMsg_FrameNavigate_Params& params) {
1162 // We're guaranteed to have a previously committed entry, and we now need to 1174 // We're guaranteed to have a previously committed entry, and we now need to
1163 // handle navigation inside of a subframe in it without creating a new entry. 1175 // handle navigation inside of a subframe in it without creating a new entry.
1164 DCHECK(GetLastCommittedEntry()); 1176 DCHECK(GetLastCommittedEntry());
1165 1177
1166 // Handle the case where we're navigating back/forward to a previous subframe 1178 // Handle the case where we're navigating back/forward to a previous subframe
1167 // navigation entry. This is case "2." in NAV_AUTO_SUBFRAME comment in the 1179 // navigation entry. This is case "2." in NAV_AUTO_SUBFRAME comment in the
1168 // header file. In case "1." this will be a NOP. 1180 // header file. In case "1." this will be a NOP.
1169 int entry_index = GetEntryIndexWithPageID( 1181 int entry_index = GetEntryIndexWithPageID(
1170 delegate_->GetSiteInstance(), 1182 rvh->GetSiteInstance(),
1171 params.page_id); 1183 params.page_id);
1172 if (entry_index < 0 || 1184 if (entry_index < 0 ||
1173 entry_index >= static_cast<int>(entries_.size())) { 1185 entry_index >= static_cast<int>(entries_.size())) {
1174 NOTREACHED(); 1186 NOTREACHED();
1175 return false; 1187 return false;
1176 } 1188 }
1177 1189
1178 // Update the current navigation entry in case we're going back/forward. 1190 // Update the current navigation entry in case we're going back/forward.
1179 if (entry_index != last_committed_entry_index_) { 1191 if (entry_index != last_committed_entry_index_) {
1180 last_committed_entry_index_ = entry_index; 1192 last_committed_entry_index_ = entry_index;
(...skipping 518 matching lines...) Expand 10 before | Expand all | Expand 10 after
1699 } 1711 }
1700 } 1712 }
1701 } 1713 }
1702 1714
1703 void NavigationControllerImpl::SetGetTimestampCallbackForTest( 1715 void NavigationControllerImpl::SetGetTimestampCallbackForTest(
1704 const base::Callback<base::Time()>& get_timestamp_callback) { 1716 const base::Callback<base::Time()>& get_timestamp_callback) {
1705 get_timestamp_callback_ = get_timestamp_callback; 1717 get_timestamp_callback_ = get_timestamp_callback;
1706 } 1718 }
1707 1719
1708 } // namespace content 1720 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/frame_host/navigation_controller_impl.h ('k') | content/browser/frame_host/navigation_entry_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698