| OLD | NEW |
| 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/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/debug/trace_event.h" | 9 #include "base/debug/trace_event.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 736 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 747 default: | 747 default: |
| 748 NOTREACHED(); | 748 NOTREACHED(); |
| 749 break; | 749 break; |
| 750 }; | 750 }; |
| 751 | 751 |
| 752 LoadEntry(entry); | 752 LoadEntry(entry); |
| 753 } | 753 } |
| 754 | 754 |
| 755 bool NavigationControllerImpl::RendererDidNavigate( | 755 bool NavigationControllerImpl::RendererDidNavigate( |
| 756 RenderFrameHost* rfh, | 756 RenderFrameHost* rfh, |
| 757 int32 page_id, |
| 757 const FrameHostMsg_DidCommitProvisionalLoad_Params& params, | 758 const FrameHostMsg_DidCommitProvisionalLoad_Params& params, |
| 758 LoadCommittedDetails* details) { | 759 LoadCommittedDetails* details) { |
| 759 is_initial_navigation_ = false; | 760 is_initial_navigation_ = false; |
| 760 | 761 |
| 761 // Save the previous state before we clobber it. | 762 // Save the previous state before we clobber it. |
| 762 if (GetLastCommittedEntry()) { | 763 if (GetLastCommittedEntry()) { |
| 763 details->previous_url = GetLastCommittedEntry()->GetURL(); | 764 details->previous_url = GetLastCommittedEntry()->GetURL(); |
| 764 details->previous_entry_index = GetLastCommittedEntryIndex(); | 765 details->previous_entry_index = GetLastCommittedEntryIndex(); |
| 765 } else { | 766 } else { |
| 766 details->previous_url = GURL(); | 767 details->previous_url = GURL(); |
| 767 details->previous_entry_index = -1; | 768 details->previous_entry_index = -1; |
| 768 } | 769 } |
| 769 | 770 |
| 770 // If we have a pending entry at this point, it should have a SiteInstance. | 771 // If we have a pending entry at this point, it should have a SiteInstance. |
| 771 // Restored entries start out with a null SiteInstance, but we should have | 772 // Restored entries start out with a null SiteInstance, but we should have |
| 772 // assigned one in NavigateToPendingEntry. | 773 // assigned one in NavigateToPendingEntry. |
| 773 DCHECK(pending_entry_index_ == -1 || pending_entry_->site_instance()); | 774 DCHECK(pending_entry_index_ == -1 || pending_entry_->site_instance()); |
| 774 | 775 |
| 775 // If we are doing a cross-site reload, we need to replace the existing | 776 // If we are doing a cross-site reload, we need to replace the existing |
| 776 // navigation entry, not add another entry to the history. This has the side | 777 // navigation entry, not add another entry to the history. This has the side |
| 777 // effect of removing forward browsing history, if such existed. | 778 // effect of removing forward browsing history, if such existed. |
| 778 // Or if we are doing a cross-site redirect navigation, | 779 // Or if we are doing a cross-site redirect navigation, |
| 779 // we will do a similar thing. | 780 // we will do a similar thing. |
| 780 details->did_replace_entry = | 781 details->did_replace_entry = |
| 781 pending_entry_ && pending_entry_->should_replace_entry(); | 782 pending_entry_ && pending_entry_->should_replace_entry(); |
| 782 | 783 |
| 783 // Do navigation-type specific actions. These will make and commit an entry. | 784 // Do navigation-type specific actions. These will make and commit an entry. |
| 784 details->type = ClassifyNavigation(rfh, params); | 785 details->type = ClassifyNavigation(rfh, page_id, params); |
| 785 | 786 |
| 786 // is_in_page must be computed before the entry gets committed. | 787 // is_in_page must be computed before the entry gets committed. |
| 787 details->is_in_page = AreURLsInPageNavigation(rfh->GetLastCommittedURL(), | 788 details->is_in_page = AreURLsInPageNavigation(rfh->GetLastCommittedURL(), |
| 788 params.url, params.was_within_same_page, rfh); | 789 params.url, params.was_within_same_page, rfh); |
| 789 | 790 |
| 790 switch (details->type) { | 791 switch (details->type) { |
| 791 case NAVIGATION_TYPE_NEW_PAGE: | 792 case NAVIGATION_TYPE_NEW_PAGE: |
| 792 RendererDidNavigateToNewPage(rfh, params, details->did_replace_entry); | 793 RendererDidNavigateToNewPage(rfh, page_id, params, |
| 794 details->did_replace_entry); |
| 793 break; | 795 break; |
| 794 case NAVIGATION_TYPE_EXISTING_PAGE: | 796 case NAVIGATION_TYPE_EXISTING_PAGE: |
| 795 RendererDidNavigateToExistingPage(rfh, params); | 797 RendererDidNavigateToExistingPage(rfh, page_id, params); |
| 796 break; | 798 break; |
| 797 case NAVIGATION_TYPE_SAME_PAGE: | 799 case NAVIGATION_TYPE_SAME_PAGE: |
| 798 RendererDidNavigateToSamePage(rfh, params); | 800 RendererDidNavigateToSamePage(rfh, page_id, params); |
| 799 break; | 801 break; |
| 800 case NAVIGATION_TYPE_IN_PAGE: | 802 case NAVIGATION_TYPE_IN_PAGE: |
| 801 RendererDidNavigateInPage(rfh, params, &details->did_replace_entry); | 803 RendererDidNavigateInPage(rfh, page_id, params, |
| 804 &details->did_replace_entry); |
| 802 break; | 805 break; |
| 803 case NAVIGATION_TYPE_NEW_SUBFRAME: | 806 case NAVIGATION_TYPE_NEW_SUBFRAME: |
| 804 RendererDidNavigateNewSubframe(rfh, params); | 807 RendererDidNavigateNewSubframe(rfh, page_id, params); |
| 805 break; | 808 break; |
| 806 case NAVIGATION_TYPE_AUTO_SUBFRAME: | 809 case NAVIGATION_TYPE_AUTO_SUBFRAME: |
| 807 if (!RendererDidNavigateAutoSubframe(rfh, params)) | 810 if (!RendererDidNavigateAutoSubframe(rfh, page_id, params)) |
| 808 return false; | 811 return false; |
| 809 break; | 812 break; |
| 810 case NAVIGATION_TYPE_NAV_IGNORE: | 813 case NAVIGATION_TYPE_NAV_IGNORE: |
| 811 // If a pending navigation was in progress, this canceled it. We should | 814 // If a pending navigation was in progress, this canceled it. We should |
| 812 // discard it and make sure it is removed from the URL bar. After that, | 815 // discard it and make sure it is removed from the URL bar. After that, |
| 813 // there is nothing we can do with this navigation, so we just return to | 816 // there is nothing we can do with this navigation, so we just return to |
| 814 // the caller that nothing has happened. | 817 // the caller that nothing has happened. |
| 815 if (pending_entry_) { | 818 if (pending_entry_) { |
| 816 DiscardNonCommittedEntries(); | 819 DiscardNonCommittedEntries(); |
| 817 delegate_->NotifyNavigationStateChanged(INVALIDATE_TYPE_URL); | 820 delegate_->NotifyNavigationStateChanged(INVALIDATE_TYPE_URL); |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 874 PageTransitionIsMainFrame(params.transition); | 877 PageTransitionIsMainFrame(params.transition); |
| 875 details->serialized_security_info = params.security_info; | 878 details->serialized_security_info = params.security_info; |
| 876 details->http_status_code = params.http_status_code; | 879 details->http_status_code = params.http_status_code; |
| 877 NotifyNavigationEntryCommitted(details); | 880 NotifyNavigationEntryCommitted(details); |
| 878 | 881 |
| 879 return true; | 882 return true; |
| 880 } | 883 } |
| 881 | 884 |
| 882 NavigationType NavigationControllerImpl::ClassifyNavigation( | 885 NavigationType NavigationControllerImpl::ClassifyNavigation( |
| 883 RenderFrameHost* rfh, | 886 RenderFrameHost* rfh, |
| 887 int32 page_id, |
| 884 const FrameHostMsg_DidCommitProvisionalLoad_Params& params) const { | 888 const FrameHostMsg_DidCommitProvisionalLoad_Params& params) const { |
| 885 if (params.page_id == -1) { | 889 if (page_id == -1) { |
| 886 // TODO(nasko, creis): An out-of-process child frame has no way of | 890 // TODO(nasko, creis): An out-of-process child frame has no way of |
| 887 // knowing the page_id of its parent, so it is passing back -1. The | 891 // knowing the page_id of its parent, so it is passing back -1. The |
| 888 // semantics here should be re-evaluated during session history refactor | 892 // semantics here should be re-evaluated during session history refactor |
| 889 // (see http://crbug.com/236848). For now, we assume this means the | 893 // (see http://crbug.com/236848). For now, we assume this means the |
| 890 // child frame loaded and proceed. Note that this may do the wrong thing | 894 // child frame loaded and proceed. Note that this may do the wrong thing |
| 891 // for cross-process AUTO_SUBFRAME navigations. | 895 // for cross-process AUTO_SUBFRAME navigations. |
| 892 if (rfh->IsCrossProcessSubframe()) | 896 if (rfh->IsCrossProcessSubframe()) |
| 893 return NAVIGATION_TYPE_NEW_SUBFRAME; | 897 return NAVIGATION_TYPE_NEW_SUBFRAME; |
| 894 | 898 |
| 895 // The renderer generates the page IDs, and so if it gives us the invalid | 899 // The renderer generates the page IDs, and so if it gives us the invalid |
| (...skipping 10 matching lines...) Expand all Loading... |
| 906 // could be invalid. This can also happen for a cross-site transition | 910 // could be invalid. This can also happen for a cross-site transition |
| 907 // that causes us to swap processes. Then the error page load will be in | 911 // that causes us to swap processes. Then the error page load will be in |
| 908 // a new process with no page IDs ever assigned (and hence a -1 value), | 912 // a new process with no page IDs ever assigned (and hence a -1 value), |
| 909 // yet the navigation controller still might have previous pages in its | 913 // yet the navigation controller still might have previous pages in its |
| 910 // list. | 914 // list. |
| 911 // | 915 // |
| 912 // In these cases, there's nothing we can do with them, so ignore. | 916 // In these cases, there's nothing we can do with them, so ignore. |
| 913 return NAVIGATION_TYPE_NAV_IGNORE; | 917 return NAVIGATION_TYPE_NAV_IGNORE; |
| 914 } | 918 } |
| 915 | 919 |
| 916 if (params.page_id > delegate_->GetMaxPageIDForSiteInstance( | 920 if (page_id > delegate_->GetMaxPageIDForSiteInstance( |
| 917 rfh->GetSiteInstance())) { | 921 rfh->GetSiteInstance())) { |
| 918 // Greater page IDs than we've ever seen before are new pages. We may or may | 922 // Greater page IDs than we've ever seen before are new pages. We may or may |
| 919 // not have a pending entry for the page, and this may or may not be the | 923 // not have a pending entry for the page, and this may or may not be the |
| 920 // main frame. | 924 // main frame. |
| 921 if (PageTransitionIsMainFrame(params.transition)) | 925 if (PageTransitionIsMainFrame(params.transition)) |
| 922 return NAVIGATION_TYPE_NEW_PAGE; | 926 return NAVIGATION_TYPE_NEW_PAGE; |
| 923 | 927 |
| 924 // When this is a new subframe navigation, we should have a committed page | 928 // When this is a new subframe navigation, we should have a committed page |
| 925 // for which it's a suframe in. This may not be the case when an iframe is | 929 // for which it's a suframe in. This may not be the case when an iframe is |
| 926 // navigated on a popup navigated to about:blank (the iframe would be | 930 // navigated on a popup navigated to about:blank (the iframe would be |
| 927 // written into the popup by script on the main page). For these cases, | 931 // written into the popup by script on the main page). For these cases, |
| 928 // there isn't any navigation stuff we can do, so just ignore it. | 932 // there isn't any navigation stuff we can do, so just ignore it. |
| 929 if (!GetLastCommittedEntry()) | 933 if (!GetLastCommittedEntry()) |
| 930 return NAVIGATION_TYPE_NAV_IGNORE; | 934 return NAVIGATION_TYPE_NAV_IGNORE; |
| 931 | 935 |
| 932 // Valid subframe navigation. | 936 // Valid subframe navigation. |
| 933 return NAVIGATION_TYPE_NEW_SUBFRAME; | 937 return NAVIGATION_TYPE_NEW_SUBFRAME; |
| 934 } | 938 } |
| 935 | 939 |
| 936 // We only clear the session history when navigating to a new page. | 940 // We only clear the session history when navigating to a new page. |
| 937 DCHECK(!params.history_list_was_cleared); | 941 DCHECK(!params.history_list_was_cleared); |
| 938 | 942 |
| 939 // Now we know that the notification is for an existing page. Find that entry. | 943 // Now we know that the notification is for an existing page. Find that entry. |
| 940 int existing_entry_index = GetEntryIndexWithPageID( | 944 int existing_entry_index = GetEntryIndexWithPageID( |
| 941 rfh->GetSiteInstance(), | 945 rfh->GetSiteInstance(), |
| 942 params.page_id); | 946 page_id); |
| 943 if (existing_entry_index == -1) { | 947 if (existing_entry_index == -1) { |
| 944 // The page was not found. It could have been pruned because of the limit on | 948 // The page was not found. It could have been pruned because of the limit on |
| 945 // back/forward entries (not likely since we'll usually tell it to navigate | 949 // back/forward entries (not likely since we'll usually tell it to navigate |
| 946 // to such entries). It could also mean that the renderer is smoking crack. | 950 // to such entries). It could also mean that the renderer is smoking crack. |
| 947 NOTREACHED(); | 951 NOTREACHED(); |
| 948 | 952 |
| 949 // Because the unknown entry has committed, we risk showing the wrong URL in | 953 // Because the unknown entry has committed, we risk showing the wrong URL in |
| 950 // release builds. Instead, we'll kill the renderer process to be safe. | 954 // release builds. Instead, we'll kill the renderer process to be safe. |
| 951 LOG(ERROR) << "terminating renderer for bad navigation: " << params.url; | 955 LOG(ERROR) << "terminating renderer for bad navigation: " << params.url; |
| 952 RecordAction(base::UserMetricsAction("BadMessageTerminate_NC")); | 956 RecordAction(base::UserMetricsAction("BadMessageTerminate_NC")); |
| 953 | 957 |
| 954 // Temporary code so we can get more information. Format: | 958 // Temporary code so we can get more information. Format: |
| 955 // http://url/foo.html#page1#max3#frame1#ids:2_Nx,1_1x,3_2 | 959 // http://url/foo.html#page1#max3#frame1#ids:2_Nx,1_1x,3_2 |
| 956 std::string temp = params.url.spec(); | 960 std::string temp = params.url.spec(); |
| 957 temp.append("#page"); | 961 temp.append("#page"); |
| 958 temp.append(base::IntToString(params.page_id)); | 962 temp.append(base::IntToString(page_id)); |
| 959 temp.append("#max"); | 963 temp.append("#max"); |
| 960 temp.append(base::IntToString(delegate_->GetMaxPageID())); | 964 temp.append(base::IntToString(delegate_->GetMaxPageID())); |
| 961 temp.append("#frame"); | 965 temp.append("#frame"); |
| 962 temp.append(base::IntToString(rfh->GetRoutingID())); | 966 temp.append(base::IntToString(rfh->GetRoutingID())); |
| 963 temp.append("#ids"); | 967 temp.append("#ids"); |
| 964 for (int i = 0; i < static_cast<int>(entries_.size()); ++i) { | 968 for (int i = 0; i < static_cast<int>(entries_.size()); ++i) { |
| 965 // Append entry metadata (e.g., 3_7x): | 969 // Append entry metadata (e.g., 3_7x): |
| 966 // 3: page_id | 970 // 3: page_id |
| 967 // 7: SiteInstance ID, or N for null | 971 // 7: SiteInstance ID, or N for null |
| 968 // x: appended if not from the current SiteInstance | 972 // x: appended if not from the current SiteInstance |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1017 return NAVIGATION_TYPE_IN_PAGE; | 1021 return NAVIGATION_TYPE_IN_PAGE; |
| 1018 } | 1022 } |
| 1019 | 1023 |
| 1020 // Since we weeded out "new" navigations above, we know this is an existing | 1024 // Since we weeded out "new" navigations above, we know this is an existing |
| 1021 // (back/forward) navigation. | 1025 // (back/forward) navigation. |
| 1022 return NAVIGATION_TYPE_EXISTING_PAGE; | 1026 return NAVIGATION_TYPE_EXISTING_PAGE; |
| 1023 } | 1027 } |
| 1024 | 1028 |
| 1025 void NavigationControllerImpl::RendererDidNavigateToNewPage( | 1029 void NavigationControllerImpl::RendererDidNavigateToNewPage( |
| 1026 RenderFrameHost* rfh, | 1030 RenderFrameHost* rfh, |
| 1031 int32 page_id, |
| 1027 const FrameHostMsg_DidCommitProvisionalLoad_Params& params, | 1032 const FrameHostMsg_DidCommitProvisionalLoad_Params& params, |
| 1028 bool replace_entry) { | 1033 bool replace_entry) { |
| 1029 NavigationEntryImpl* new_entry; | 1034 NavigationEntryImpl* new_entry; |
| 1030 bool update_virtual_url; | 1035 bool update_virtual_url; |
| 1031 // Only make a copy of the pending entry if it is appropriate for the new page | 1036 // Only make a copy of the pending entry if it is appropriate for the new page |
| 1032 // that was just loaded. We verify this at a coarse grain by checking that | 1037 // that was just loaded. We verify this at a coarse grain by checking that |
| 1033 // the SiteInstance hasn't been assigned to something else. | 1038 // the SiteInstance hasn't been assigned to something else. |
| 1034 if (pending_entry_ && | 1039 if (pending_entry_ && |
| 1035 (!pending_entry_->site_instance() || | 1040 (!pending_entry_->site_instance() || |
| 1036 pending_entry_->site_instance() == rfh->GetSiteInstance())) { | 1041 pending_entry_->site_instance() == rfh->GetSiteInstance())) { |
| (...skipping 20 matching lines...) Expand all Loading... |
| 1057 // update the virtual URL based on the new URL. For example, this is needed | 1062 // update the virtual URL based on the new URL. For example, this is needed |
| 1058 // to show chrome://bookmarks/#1 when the bookmarks webui extension changes | 1063 // to show chrome://bookmarks/#1 when the bookmarks webui extension changes |
| 1059 // the URL. | 1064 // the URL. |
| 1060 update_virtual_url = needs_update; | 1065 update_virtual_url = needs_update; |
| 1061 } | 1066 } |
| 1062 | 1067 |
| 1063 new_entry->SetURL(params.url); | 1068 new_entry->SetURL(params.url); |
| 1064 if (update_virtual_url) | 1069 if (update_virtual_url) |
| 1065 UpdateVirtualURLToURL(new_entry, params.url); | 1070 UpdateVirtualURLToURL(new_entry, params.url); |
| 1066 new_entry->SetReferrer(params.referrer); | 1071 new_entry->SetReferrer(params.referrer); |
| 1067 new_entry->SetPageID(params.page_id); | 1072 new_entry->SetPageID(page_id); |
| 1068 new_entry->SetTransitionType(params.transition); | 1073 new_entry->SetTransitionType(params.transition); |
| 1069 new_entry->set_site_instance( | 1074 new_entry->set_site_instance( |
| 1070 static_cast<SiteInstanceImpl*>(rfh->GetSiteInstance())); | 1075 static_cast<SiteInstanceImpl*>(rfh->GetSiteInstance())); |
| 1071 new_entry->SetHasPostData(params.is_post); | 1076 new_entry->SetHasPostData(params.is_post); |
| 1072 new_entry->SetPostID(params.post_id); | 1077 new_entry->SetPostID(params.post_id); |
| 1073 new_entry->SetOriginalRequestURL(params.original_request_url); | 1078 new_entry->SetOriginalRequestURL(params.original_request_url); |
| 1074 new_entry->SetIsOverridingUserAgent(params.is_overriding_user_agent); | 1079 new_entry->SetIsOverridingUserAgent(params.is_overriding_user_agent); |
| 1075 | 1080 |
| 1076 // history.pushState() is classified as a navigation to a new page, but | 1081 // history.pushState() is classified as a navigation to a new page, but |
| 1077 // sets was_within_same_page to true. In this case, we already have the | 1082 // sets was_within_same_page to true. In this case, we already have the |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1089 DiscardNonCommittedEntriesInternal(); | 1094 DiscardNonCommittedEntriesInternal(); |
| 1090 entries_.clear(); | 1095 entries_.clear(); |
| 1091 last_committed_entry_index_ = -1; | 1096 last_committed_entry_index_ = -1; |
| 1092 } | 1097 } |
| 1093 | 1098 |
| 1094 InsertOrReplaceEntry(new_entry, replace_entry); | 1099 InsertOrReplaceEntry(new_entry, replace_entry); |
| 1095 } | 1100 } |
| 1096 | 1101 |
| 1097 void NavigationControllerImpl::RendererDidNavigateToExistingPage( | 1102 void NavigationControllerImpl::RendererDidNavigateToExistingPage( |
| 1098 RenderFrameHost* rfh, | 1103 RenderFrameHost* rfh, |
| 1104 int32 page_id, |
| 1099 const FrameHostMsg_DidCommitProvisionalLoad_Params& params) { | 1105 const FrameHostMsg_DidCommitProvisionalLoad_Params& params) { |
| 1100 // We should only get here for main frame navigations. | 1106 // We should only get here for main frame navigations. |
| 1101 DCHECK(PageTransitionIsMainFrame(params.transition)); | 1107 DCHECK(PageTransitionIsMainFrame(params.transition)); |
| 1102 | 1108 |
| 1103 // This is a back/forward navigation. The existing page for the ID is | 1109 // This is a back/forward navigation. The existing page for the ID is |
| 1104 // guaranteed to exist by ClassifyNavigation, and we just need to update it | 1110 // guaranteed to exist by ClassifyNavigation, and we just need to update it |
| 1105 // with new information from the renderer. | 1111 // with new information from the renderer. |
| 1106 int entry_index = GetEntryIndexWithPageID(rfh->GetSiteInstance(), | 1112 int entry_index = GetEntryIndexWithPageID(rfh->GetSiteInstance(), page_id); |
| 1107 params.page_id); | |
| 1108 DCHECK(entry_index >= 0 && | 1113 DCHECK(entry_index >= 0 && |
| 1109 entry_index < static_cast<int>(entries_.size())); | 1114 entry_index < static_cast<int>(entries_.size())); |
| 1110 NavigationEntryImpl* entry = entries_[entry_index].get(); | 1115 NavigationEntryImpl* entry = entries_[entry_index].get(); |
| 1111 | 1116 |
| 1112 // The URL may have changed due to redirects. | 1117 // The URL may have changed due to redirects. |
| 1113 entry->SetURL(params.url); | 1118 entry->SetURL(params.url); |
| 1114 entry->SetReferrer(params.referrer); | 1119 entry->SetReferrer(params.referrer); |
| 1115 if (entry->update_virtual_url_with_url()) | 1120 if (entry->update_virtual_url_with_url()) |
| 1116 UpdateVirtualURLToURL(entry, params.url); | 1121 UpdateVirtualURLToURL(entry, params.url); |
| 1117 | 1122 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 1137 // is now likely canceled. If it is not canceled, we will treat it as a new | 1142 // is now likely canceled. If it is not canceled, we will treat it as a new |
| 1138 // navigation when it arrives, which is also ok. | 1143 // navigation when it arrives, which is also ok. |
| 1139 // | 1144 // |
| 1140 // Note that we need to use the "internal" version since we don't want to | 1145 // Note that we need to use the "internal" version since we don't want to |
| 1141 // actually change any other state, just kill the pointer. | 1146 // actually change any other state, just kill the pointer. |
| 1142 DiscardNonCommittedEntriesInternal(); | 1147 DiscardNonCommittedEntriesInternal(); |
| 1143 | 1148 |
| 1144 // If a transient entry was removed, the indices might have changed, so we | 1149 // If a transient entry was removed, the indices might have changed, so we |
| 1145 // have to query the entry index again. | 1150 // have to query the entry index again. |
| 1146 last_committed_entry_index_ = | 1151 last_committed_entry_index_ = |
| 1147 GetEntryIndexWithPageID(rfh->GetSiteInstance(), params.page_id); | 1152 GetEntryIndexWithPageID(rfh->GetSiteInstance(), page_id); |
| 1148 } | 1153 } |
| 1149 | 1154 |
| 1150 void NavigationControllerImpl::RendererDidNavigateToSamePage( | 1155 void NavigationControllerImpl::RendererDidNavigateToSamePage( |
| 1151 RenderFrameHost* rfh, | 1156 RenderFrameHost* rfh, |
| 1157 int32 page_id, |
| 1152 const FrameHostMsg_DidCommitProvisionalLoad_Params& params) { | 1158 const FrameHostMsg_DidCommitProvisionalLoad_Params& params) { |
| 1153 // This mode implies we have a pending entry that's the same as an existing | 1159 // This mode implies we have a pending entry that's the same as an existing |
| 1154 // entry for this page ID. This entry is guaranteed to exist by | 1160 // entry for this page ID. This entry is guaranteed to exist by |
| 1155 // ClassifyNavigation. All we need to do is update the existing entry. | 1161 // ClassifyNavigation. All we need to do is update the existing entry. |
| 1156 NavigationEntryImpl* existing_entry = GetEntryWithPageID( | 1162 NavigationEntryImpl* existing_entry = GetEntryWithPageID( |
| 1157 rfh->GetSiteInstance(), params.page_id); | 1163 rfh->GetSiteInstance(), page_id); |
| 1158 | 1164 |
| 1159 // We assign the entry's unique ID to be that of the new one. Since this is | 1165 // We assign the entry's unique ID to be that of the new one. Since this is |
| 1160 // always the result of a user action, we want to dismiss infobars, etc. like | 1166 // always the result of a user action, we want to dismiss infobars, etc. like |
| 1161 // a regular user-initiated navigation. | 1167 // a regular user-initiated navigation. |
| 1162 existing_entry->set_unique_id(pending_entry_->GetUniqueID()); | 1168 existing_entry->set_unique_id(pending_entry_->GetUniqueID()); |
| 1163 | 1169 |
| 1164 // The URL may have changed due to redirects. | 1170 // The URL may have changed due to redirects. |
| 1165 if (existing_entry->update_virtual_url_with_url()) | 1171 if (existing_entry->update_virtual_url_with_url()) |
| 1166 UpdateVirtualURLToURL(existing_entry, params.url); | 1172 UpdateVirtualURLToURL(existing_entry, params.url); |
| 1167 existing_entry->SetURL(params.url); | 1173 existing_entry->SetURL(params.url); |
| 1168 existing_entry->SetReferrer(params.referrer); | 1174 existing_entry->SetReferrer(params.referrer); |
| 1169 | 1175 |
| 1170 // The page may have been requested with a different HTTP method. | 1176 // The page may have been requested with a different HTTP method. |
| 1171 existing_entry->SetHasPostData(params.is_post); | 1177 existing_entry->SetHasPostData(params.is_post); |
| 1172 existing_entry->SetPostID(params.post_id); | 1178 existing_entry->SetPostID(params.post_id); |
| 1173 | 1179 |
| 1174 DiscardNonCommittedEntries(); | 1180 DiscardNonCommittedEntries(); |
| 1175 } | 1181 } |
| 1176 | 1182 |
| 1177 void NavigationControllerImpl::RendererDidNavigateInPage( | 1183 void NavigationControllerImpl::RendererDidNavigateInPage( |
| 1178 RenderFrameHost* rfh, | 1184 RenderFrameHost* rfh, |
| 1185 int32 page_id, |
| 1179 const FrameHostMsg_DidCommitProvisionalLoad_Params& params, | 1186 const FrameHostMsg_DidCommitProvisionalLoad_Params& params, |
| 1180 bool* did_replace_entry) { | 1187 bool* did_replace_entry) { |
| 1181 DCHECK(PageTransitionIsMainFrame(params.transition)) << | 1188 DCHECK(PageTransitionIsMainFrame(params.transition)) << |
| 1182 "WebKit should only tell us about in-page navs for the main frame."; | 1189 "WebKit should only tell us about in-page navs for the main frame."; |
| 1183 // We're guaranteed to have an entry for this one. | 1190 // We're guaranteed to have an entry for this one. |
| 1184 NavigationEntryImpl* existing_entry = GetEntryWithPageID( | 1191 NavigationEntryImpl* existing_entry = GetEntryWithPageID( |
| 1185 rfh->GetSiteInstance(), params.page_id); | 1192 rfh->GetSiteInstance(), page_id); |
| 1186 | 1193 |
| 1187 // Reference fragment navigation. We're guaranteed to have the last_committed | 1194 // Reference fragment navigation. We're guaranteed to have the last_committed |
| 1188 // entry and it will be the same page as the new navigation (minus the | 1195 // entry and it will be the same page as the new navigation (minus the |
| 1189 // reference fragments, of course). We'll update the URL of the existing | 1196 // reference fragments, of course). We'll update the URL of the existing |
| 1190 // entry without pruning the forward history. | 1197 // entry without pruning the forward history. |
| 1191 existing_entry->SetURL(params.url); | 1198 existing_entry->SetURL(params.url); |
| 1192 if (existing_entry->update_virtual_url_with_url()) | 1199 if (existing_entry->update_virtual_url_with_url()) |
| 1193 UpdateVirtualURLToURL(existing_entry, params.url); | 1200 UpdateVirtualURLToURL(existing_entry, params.url); |
| 1194 | 1201 |
| 1195 existing_entry->SetHasPostData(params.is_post); | 1202 existing_entry->SetHasPostData(params.is_post); |
| 1196 existing_entry->SetPostID(params.post_id); | 1203 existing_entry->SetPostID(params.post_id); |
| 1197 | 1204 |
| 1198 // This replaces the existing entry since the page ID didn't change. | 1205 // This replaces the existing entry since the page ID didn't change. |
| 1199 *did_replace_entry = true; | 1206 *did_replace_entry = true; |
| 1200 | 1207 |
| 1201 DiscardNonCommittedEntriesInternal(); | 1208 DiscardNonCommittedEntriesInternal(); |
| 1202 | 1209 |
| 1203 // If a transient entry was removed, the indices might have changed, so we | 1210 // If a transient entry was removed, the indices might have changed, so we |
| 1204 // have to query the entry index again. | 1211 // have to query the entry index again. |
| 1205 last_committed_entry_index_ = | 1212 last_committed_entry_index_ = |
| 1206 GetEntryIndexWithPageID(rfh->GetSiteInstance(), params.page_id); | 1213 GetEntryIndexWithPageID(rfh->GetSiteInstance(), page_id); |
| 1207 } | 1214 } |
| 1208 | 1215 |
| 1209 void NavigationControllerImpl::RendererDidNavigateNewSubframe( | 1216 void NavigationControllerImpl::RendererDidNavigateNewSubframe( |
| 1210 RenderFrameHost* rfh, | 1217 RenderFrameHost* rfh, |
| 1218 int32 page_id, |
| 1211 const FrameHostMsg_DidCommitProvisionalLoad_Params& params) { | 1219 const FrameHostMsg_DidCommitProvisionalLoad_Params& params) { |
| 1212 if (PageTransitionCoreTypeIs(params.transition, | 1220 if (PageTransitionCoreTypeIs(params.transition, |
| 1213 PAGE_TRANSITION_AUTO_SUBFRAME)) { | 1221 PAGE_TRANSITION_AUTO_SUBFRAME)) { |
| 1214 // This is not user-initiated. Ignore. | 1222 // This is not user-initiated. Ignore. |
| 1215 DiscardNonCommittedEntriesInternal(); | 1223 DiscardNonCommittedEntriesInternal(); |
| 1216 return; | 1224 return; |
| 1217 } | 1225 } |
| 1218 | 1226 |
| 1219 // Manual subframe navigations just get the current entry cloned so the user | 1227 // Manual subframe navigations just get the current entry cloned so the user |
| 1220 // can go back or forward to it. The actual subframe information will be | 1228 // can go back or forward to it. The actual subframe information will be |
| 1221 // stored in the page state for each of those entries. This happens out of | 1229 // stored in the page state for each of those entries. This happens out of |
| 1222 // band with the actual navigations. | 1230 // band with the actual navigations. |
| 1223 DCHECK(GetLastCommittedEntry()) << "ClassifyNavigation should guarantee " | 1231 DCHECK(GetLastCommittedEntry()) << "ClassifyNavigation should guarantee " |
| 1224 << "that a last committed entry exists."; | 1232 << "that a last committed entry exists."; |
| 1225 NavigationEntryImpl* new_entry = new NavigationEntryImpl( | 1233 NavigationEntryImpl* new_entry = new NavigationEntryImpl( |
| 1226 *NavigationEntryImpl::FromNavigationEntry(GetLastCommittedEntry())); | 1234 *NavigationEntryImpl::FromNavigationEntry(GetLastCommittedEntry())); |
| 1227 new_entry->SetPageID(params.page_id); | 1235 new_entry->SetPageID(page_id); |
| 1228 InsertOrReplaceEntry(new_entry, false); | 1236 InsertOrReplaceEntry(new_entry, false); |
| 1229 } | 1237 } |
| 1230 | 1238 |
| 1231 bool NavigationControllerImpl::RendererDidNavigateAutoSubframe( | 1239 bool NavigationControllerImpl::RendererDidNavigateAutoSubframe( |
| 1232 RenderFrameHost* rfh, | 1240 RenderFrameHost* rfh, |
| 1241 int32 page_id, |
| 1233 const FrameHostMsg_DidCommitProvisionalLoad_Params& params) { | 1242 const FrameHostMsg_DidCommitProvisionalLoad_Params& params) { |
| 1234 // We're guaranteed to have a previously committed entry, and we now need to | 1243 // We're guaranteed to have a previously committed entry, and we now need to |
| 1235 // handle navigation inside of a subframe in it without creating a new entry. | 1244 // handle navigation inside of a subframe in it without creating a new entry. |
| 1236 DCHECK(GetLastCommittedEntry()); | 1245 DCHECK(GetLastCommittedEntry()); |
| 1237 | 1246 |
| 1238 // Handle the case where we're navigating back/forward to a previous subframe | 1247 // Handle the case where we're navigating back/forward to a previous subframe |
| 1239 // navigation entry. This is case "2." in NAV_AUTO_SUBFRAME comment in the | 1248 // navigation entry. This is case "2." in NAV_AUTO_SUBFRAME comment in the |
| 1240 // header file. In case "1." this will be a NOP. | 1249 // header file. In case "1." this will be a NOP. |
| 1241 int entry_index = GetEntryIndexWithPageID( | 1250 int entry_index = GetEntryIndexWithPageID(rfh->GetSiteInstance(), page_id); |
| 1242 rfh->GetSiteInstance(), | |
| 1243 params.page_id); | |
| 1244 if (entry_index < 0 || | 1251 if (entry_index < 0 || |
| 1245 entry_index >= static_cast<int>(entries_.size())) { | 1252 entry_index >= static_cast<int>(entries_.size())) { |
| 1246 NOTREACHED(); | 1253 NOTREACHED(); |
| 1247 return false; | 1254 return false; |
| 1248 } | 1255 } |
| 1249 | 1256 |
| 1250 // Update the current navigation entry in case we're going back/forward. | 1257 // Update the current navigation entry in case we're going back/forward. |
| 1251 if (entry_index != last_committed_entry_index_) { | 1258 if (entry_index != last_committed_entry_index_) { |
| 1252 last_committed_entry_index_ = entry_index; | 1259 last_committed_entry_index_ = entry_index; |
| 1253 DiscardNonCommittedEntriesInternal(); | 1260 DiscardNonCommittedEntriesInternal(); |
| (...skipping 534 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1788 } | 1795 } |
| 1789 } | 1796 } |
| 1790 } | 1797 } |
| 1791 | 1798 |
| 1792 void NavigationControllerImpl::SetGetTimestampCallbackForTest( | 1799 void NavigationControllerImpl::SetGetTimestampCallbackForTest( |
| 1793 const base::Callback<base::Time()>& get_timestamp_callback) { | 1800 const base::Callback<base::Time()>& get_timestamp_callback) { |
| 1794 get_timestamp_callback_ = get_timestamp_callback; | 1801 get_timestamp_callback_ = get_timestamp_callback; |
| 1795 } | 1802 } |
| 1796 | 1803 |
| 1797 } // namespace content | 1804 } // namespace content |
| OLD | NEW |