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

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

Issue 21544005: Take the navigation type into account when checking if the navigation is in page. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Dropping content::, comment & fix in the test. Created 7 years, 4 months 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/web_contents/navigation_controller_impl.h" 5 #include "content/browser/web_contents/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 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 (*entries)[i]->SetTransitionType(PAGE_TRANSITION_RELOAD); 98 (*entries)[i]->SetTransitionType(PAGE_TRANSITION_RELOAD);
99 (*entries)[i]->set_restore_type(ControllerRestoreTypeToEntryType(type)); 99 (*entries)[i]->set_restore_type(ControllerRestoreTypeToEntryType(type));
100 // NOTE(darin): This code is only needed for backwards compat. 100 // NOTE(darin): This code is only needed for backwards compat.
101 SetPageStateIfEmpty((*entries)[i].get()); 101 SetPageStateIfEmpty((*entries)[i].get());
102 } 102 }
103 } 103 }
104 104
105 // See NavigationController::IsURLInPageNavigation for how this works and why. 105 // See NavigationController::IsURLInPageNavigation for how this works and why.
106 bool AreURLsInPageNavigation(const GURL& existing_url, 106 bool AreURLsInPageNavigation(const GURL& existing_url,
107 const GURL& new_url, 107 const GURL& new_url,
108 bool renderer_says_in_page) { 108 bool renderer_says_in_page,
109 NavigationType navigation_type) {
109 if (existing_url == new_url) 110 if (existing_url == new_url)
110 return renderer_says_in_page; 111 return renderer_says_in_page;
111 112
112 if (!new_url.has_ref()) { 113 if (!new_url.has_ref()) {
113 // TODO(jcampan): what about when navigating back from a ref URL to the top 114 // When going back from the ref URL to the non ref one the navigation type
114 // non ref URL? Nothing is loaded in that case but we return false here. 115 // is IN_PAGE.
115 // The user could also navigate from the ref URL to the non ref URL by 116 return navigation_type == NAVIGATION_TYPE_IN_PAGE;
116 // entering the non ref URL in the location bar or through a bookmark, in
117 // which case there would be a load. I am not sure if the non-load/load
118 // scenarios can be differentiated with the TransitionType.
119 return false;
120 } 117 }
121 118
122 url_canon::Replacements<char> replacements; 119 url_canon::Replacements<char> replacements;
123 replacements.ClearRef(); 120 replacements.ClearRef();
124 return existing_url.ReplaceComponents(replacements) == 121 return existing_url.ReplaceComponents(replacements) ==
125 new_url.ReplaceComponents(replacements); 122 new_url.ReplaceComponents(replacements);
126 } 123 }
127 124
128 // Determines whether or not we should be carrying over a user agent override 125 // Determines whether or not we should be carrying over a user agent override
129 // between two NavigationEntries. 126 // between two NavigationEntries.
(...skipping 603 matching lines...) Expand 10 before | Expand all | Expand 10 after
733 DCHECK(pending_entry_index_ == -1 || pending_entry_->site_instance()); 730 DCHECK(pending_entry_index_ == -1 || pending_entry_->site_instance());
734 731
735 // If we are doing a cross-site reload, we need to replace the existing 732 // If we are doing a cross-site reload, we need to replace the existing
736 // navigation entry, not add another entry to the history. This has the side 733 // navigation entry, not add another entry to the history. This has the side
737 // effect of removing forward browsing history, if such existed. 734 // effect of removing forward browsing history, if such existed.
738 // Or if we are doing a cross-site redirect navigation, 735 // Or if we are doing a cross-site redirect navigation,
739 // we will do a similar thing. 736 // we will do a similar thing.
740 details->did_replace_entry = 737 details->did_replace_entry =
741 pending_entry_ && pending_entry_->should_replace_entry(); 738 pending_entry_ && pending_entry_->should_replace_entry();
742 739
743 // is_in_page must be computed before the entry gets committed.
744 details->is_in_page = IsURLInPageNavigation(
745 params.url, params.was_within_same_page);
746
747 // Do navigation-type specific actions. These will make and commit an entry. 740 // Do navigation-type specific actions. These will make and commit an entry.
748 details->type = ClassifyNavigation(params); 741 details->type = ClassifyNavigation(params);
749 742
743 // is_in_page must be computed before the entry gets committed.
744 details->is_in_page = IsURLInPageNavigation(params.url,
Charlie Reis 2013/08/07 17:49:56 Style nit: This is fine, but might as well move pa
pstanek 2013/08/07 18:05:56 Done.
745 params.was_within_same_page, details->type);
746
750 switch (details->type) { 747 switch (details->type) {
751 case NAVIGATION_TYPE_NEW_PAGE: 748 case NAVIGATION_TYPE_NEW_PAGE:
752 RendererDidNavigateToNewPage(params, details->did_replace_entry); 749 RendererDidNavigateToNewPage(params, details->did_replace_entry);
753 break; 750 break;
754 case NAVIGATION_TYPE_EXISTING_PAGE: 751 case NAVIGATION_TYPE_EXISTING_PAGE:
755 RendererDidNavigateToExistingPage(params); 752 RendererDidNavigateToExistingPage(params);
756 break; 753 break;
757 case NAVIGATION_TYPE_SAME_PAGE: 754 case NAVIGATION_TYPE_SAME_PAGE:
758 RendererDidNavigateToSamePage(params); 755 RendererDidNavigateToSamePage(params);
759 break; 756 break;
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
949 // the pending entry and go back to where we were (the "existing entry"). 946 // the pending entry and go back to where we were (the "existing entry").
950 return NAVIGATION_TYPE_SAME_PAGE; 947 return NAVIGATION_TYPE_SAME_PAGE;
951 } 948 }
952 949
953 // Any toplevel navigations with the same base (minus the reference fragment) 950 // Any toplevel navigations with the same base (minus the reference fragment)
954 // are in-page navigations. We weeded out subframe navigations above. Most of 951 // are in-page navigations. We weeded out subframe navigations above. Most of
955 // the time this doesn't matter since WebKit doesn't tell us about subframe 952 // the time this doesn't matter since WebKit doesn't tell us about subframe
956 // navigations that don't actually navigate, but it can happen when there is 953 // navigations that don't actually navigate, but it can happen when there is
957 // an encoding override (it always sends a navigation request). 954 // an encoding override (it always sends a navigation request).
958 if (AreURLsInPageNavigation(existing_entry->GetURL(), params.url, 955 if (AreURLsInPageNavigation(existing_entry->GetURL(), params.url,
959 params.was_within_same_page)) { 956 params.was_within_same_page,
957 NAVIGATION_TYPE_UNKNOWN)) {
960 return NAVIGATION_TYPE_IN_PAGE; 958 return NAVIGATION_TYPE_IN_PAGE;
961 } 959 }
962 960
963 // Since we weeded out "new" navigations above, we know this is an existing 961 // Since we weeded out "new" navigations above, we know this is an existing
964 // (back/forward) navigation. 962 // (back/forward) navigation.
965 return NAVIGATION_TYPE_EXISTING_PAGE; 963 return NAVIGATION_TYPE_EXISTING_PAGE;
966 } 964 }
967 965
968 bool NavigationControllerImpl::IsRedirect( 966 bool NavigationControllerImpl::IsRedirect(
969 const ViewHostMsg_FrameNavigate_Params& params) { 967 const ViewHostMsg_FrameNavigate_Params& params) {
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
1190 int NavigationControllerImpl::GetIndexOfEntry( 1188 int NavigationControllerImpl::GetIndexOfEntry(
1191 const NavigationEntryImpl* entry) const { 1189 const NavigationEntryImpl* entry) const {
1192 const NavigationEntries::const_iterator i(std::find( 1190 const NavigationEntries::const_iterator i(std::find(
1193 entries_.begin(), 1191 entries_.begin(),
1194 entries_.end(), 1192 entries_.end(),
1195 entry)); 1193 entry));
1196 return (i == entries_.end()) ? -1 : static_cast<int>(i - entries_.begin()); 1194 return (i == entries_.end()) ? -1 : static_cast<int>(i - entries_.begin());
1197 } 1195 }
1198 1196
1199 bool NavigationControllerImpl::IsURLInPageNavigation( 1197 bool NavigationControllerImpl::IsURLInPageNavigation(
1200 const GURL& url, bool renderer_says_in_page) const { 1198 const GURL& url,
1199 bool renderer_says_in_page,
1200 NavigationType navigation_type) const {
1201 NavigationEntry* last_committed = GetLastCommittedEntry(); 1201 NavigationEntry* last_committed = GetLastCommittedEntry();
1202 return last_committed && AreURLsInPageNavigation( 1202 return last_committed && AreURLsInPageNavigation(
1203 last_committed->GetURL(), url, renderer_says_in_page); 1203 last_committed->GetURL(), url, renderer_says_in_page, navigation_type);
1204 } 1204 }
1205 1205
1206 void NavigationControllerImpl::CopyStateFrom( 1206 void NavigationControllerImpl::CopyStateFrom(
1207 const NavigationController& temp) { 1207 const NavigationController& temp) {
1208 const NavigationControllerImpl& source = 1208 const NavigationControllerImpl& source =
1209 static_cast<const NavigationControllerImpl&>(temp); 1209 static_cast<const NavigationControllerImpl&>(temp);
1210 // Verify that we look new. 1210 // Verify that we look new.
1211 DCHECK(GetEntryCount() == 0 && !GetPendingEntry()); 1211 DCHECK(GetEntryCount() == 0 && !GetPendingEntry());
1212 1212
1213 if (source.GetEntryCount() == 0) 1213 if (source.GetEntryCount() == 0)
(...skipping 470 matching lines...) Expand 10 before | Expand all | Expand 10 after
1684 } 1684 }
1685 } 1685 }
1686 } 1686 }
1687 1687
1688 void NavigationControllerImpl::SetGetTimestampCallbackForTest( 1688 void NavigationControllerImpl::SetGetTimestampCallbackForTest(
1689 const base::Callback<base::Time()>& get_timestamp_callback) { 1689 const base::Callback<base::Time()>& get_timestamp_callback) {
1690 get_timestamp_callback_ = get_timestamp_callback; 1690 get_timestamp_callback_ = get_timestamp_callback;
1691 } 1691 }
1692 1692
1693 } // namespace content 1693 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698