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

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: Addressing review comments. 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 content::NavigationType navigation_type) {
Charlie Reis 2013/08/07 16:59:27 This whole file is in the content namespace, so yo
pstanek 2013/08/07 17:37:37 Done.
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 typically IN_PAGE which causes the correct value to be returned
Charlie Reis 2013/08/07 16:59:27 nit: drop "typically" (unless you can mention exam
pstanek 2013/08/07 17:37:37 Done.
115 // The user could also navigate from the ref URL to the non ref URL by 116 // for that case from this function as well.
116 // entering the non ref URL in the location bar or through a bookmark, in 117 return navigation_type == content::NAVIGATION_TYPE_IN_PAGE;
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 } 118 }
121 119
122 url_canon::Replacements<char> replacements; 120 url_canon::Replacements<char> replacements;
123 replacements.ClearRef(); 121 replacements.ClearRef();
124 return existing_url.ReplaceComponents(replacements) == 122 return existing_url.ReplaceComponents(replacements) ==
125 new_url.ReplaceComponents(replacements); 123 new_url.ReplaceComponents(replacements);
126 } 124 }
127 125
128 // Determines whether or not we should be carrying over a user agent override 126 // Determines whether or not we should be carrying over a user agent override
129 // between two NavigationEntries. 127 // 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()); 731 DCHECK(pending_entry_index_ == -1 || pending_entry_->site_instance());
734 732
735 // If we are doing a cross-site reload, we need to replace the existing 733 // 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 734 // navigation entry, not add another entry to the history. This has the side
737 // effect of removing forward browsing history, if such existed. 735 // effect of removing forward browsing history, if such existed.
738 // Or if we are doing a cross-site redirect navigation, 736 // Or if we are doing a cross-site redirect navigation,
739 // we will do a similar thing. 737 // we will do a similar thing.
740 details->did_replace_entry = 738 details->did_replace_entry =
741 pending_entry_ && pending_entry_->should_replace_entry(); 739 pending_entry_ && pending_entry_->should_replace_entry();
742 740
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. 741 // Do navigation-type specific actions. These will make and commit an entry.
748 details->type = ClassifyNavigation(params); 742 details->type = ClassifyNavigation(params);
749 743
744 // is_in_page must be computed before the entry gets committed.
745 details->is_in_page = IsURLInPageNavigation(params.url,
746 params.was_within_same_page, details->type);
747
750 switch (details->type) { 748 switch (details->type) {
751 case NAVIGATION_TYPE_NEW_PAGE: 749 case NAVIGATION_TYPE_NEW_PAGE:
752 RendererDidNavigateToNewPage(params, details->did_replace_entry); 750 RendererDidNavigateToNewPage(params, details->did_replace_entry);
753 break; 751 break;
754 case NAVIGATION_TYPE_EXISTING_PAGE: 752 case NAVIGATION_TYPE_EXISTING_PAGE:
755 RendererDidNavigateToExistingPage(params); 753 RendererDidNavigateToExistingPage(params);
756 break; 754 break;
757 case NAVIGATION_TYPE_SAME_PAGE: 755 case NAVIGATION_TYPE_SAME_PAGE:
758 RendererDidNavigateToSamePage(params); 756 RendererDidNavigateToSamePage(params);
759 break; 757 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"). 947 // the pending entry and go back to where we were (the "existing entry").
950 return NAVIGATION_TYPE_SAME_PAGE; 948 return NAVIGATION_TYPE_SAME_PAGE;
951 } 949 }
952 950
953 // Any toplevel navigations with the same base (minus the reference fragment) 951 // Any toplevel navigations with the same base (minus the reference fragment)
954 // are in-page navigations. We weeded out subframe navigations above. Most of 952 // 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 953 // 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 954 // navigations that don't actually navigate, but it can happen when there is
957 // an encoding override (it always sends a navigation request). 955 // an encoding override (it always sends a navigation request).
958 if (AreURLsInPageNavigation(existing_entry->GetURL(), params.url, 956 if (AreURLsInPageNavigation(existing_entry->GetURL(), params.url,
959 params.was_within_same_page)) { 957 params.was_within_same_page,
958 content::NAVIGATION_TYPE_UNKNOWN)) {
Charlie Reis 2013/08/07 16:59:27 No need for content::
pstanek 2013/08/07 17:37:37 Done.
960 return NAVIGATION_TYPE_IN_PAGE; 959 return NAVIGATION_TYPE_IN_PAGE;
961 } 960 }
962 961
963 // Since we weeded out "new" navigations above, we know this is an existing 962 // Since we weeded out "new" navigations above, we know this is an existing
964 // (back/forward) navigation. 963 // (back/forward) navigation.
965 return NAVIGATION_TYPE_EXISTING_PAGE; 964 return NAVIGATION_TYPE_EXISTING_PAGE;
966 } 965 }
967 966
968 bool NavigationControllerImpl::IsRedirect( 967 bool NavigationControllerImpl::IsRedirect(
969 const ViewHostMsg_FrameNavigate_Params& params) { 968 const ViewHostMsg_FrameNavigate_Params& params) {
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
1190 int NavigationControllerImpl::GetIndexOfEntry( 1189 int NavigationControllerImpl::GetIndexOfEntry(
1191 const NavigationEntryImpl* entry) const { 1190 const NavigationEntryImpl* entry) const {
1192 const NavigationEntries::const_iterator i(std::find( 1191 const NavigationEntries::const_iterator i(std::find(
1193 entries_.begin(), 1192 entries_.begin(),
1194 entries_.end(), 1193 entries_.end(),
1195 entry)); 1194 entry));
1196 return (i == entries_.end()) ? -1 : static_cast<int>(i - entries_.begin()); 1195 return (i == entries_.end()) ? -1 : static_cast<int>(i - entries_.begin());
1197 } 1196 }
1198 1197
1199 bool NavigationControllerImpl::IsURLInPageNavigation( 1198 bool NavigationControllerImpl::IsURLInPageNavigation(
1200 const GURL& url, bool renderer_says_in_page) const { 1199 const GURL& url,
1200 bool renderer_says_in_page,
1201 content::NavigationType navigation_type) const {
Charlie Reis 2013/08/07 16:59:27 No need for content::
pstanek 2013/08/07 17:37:37 Done.
1201 NavigationEntry* last_committed = GetLastCommittedEntry(); 1202 NavigationEntry* last_committed = GetLastCommittedEntry();
1202 return last_committed && AreURLsInPageNavigation( 1203 return last_committed && AreURLsInPageNavigation(
1203 last_committed->GetURL(), url, renderer_says_in_page); 1204 last_committed->GetURL(), url, renderer_says_in_page, navigation_type);
1204 } 1205 }
1205 1206
1206 void NavigationControllerImpl::CopyStateFrom( 1207 void NavigationControllerImpl::CopyStateFrom(
1207 const NavigationController& temp) { 1208 const NavigationController& temp) {
1208 const NavigationControllerImpl& source = 1209 const NavigationControllerImpl& source =
1209 static_cast<const NavigationControllerImpl&>(temp); 1210 static_cast<const NavigationControllerImpl&>(temp);
1210 // Verify that we look new. 1211 // Verify that we look new.
1211 DCHECK(GetEntryCount() == 0 && !GetPendingEntry()); 1212 DCHECK(GetEntryCount() == 0 && !GetPendingEntry());
1212 1213
1213 if (source.GetEntryCount() == 0) 1214 if (source.GetEntryCount() == 0)
(...skipping 470 matching lines...) Expand 10 before | Expand all | Expand 10 after
1684 } 1685 }
1685 } 1686 }
1686 } 1687 }
1687 1688
1688 void NavigationControllerImpl::SetGetTimestampCallbackForTest( 1689 void NavigationControllerImpl::SetGetTimestampCallbackForTest(
1689 const base::Callback<base::Time()>& get_timestamp_callback) { 1690 const base::Callback<base::Time()>& get_timestamp_callback) {
1690 get_timestamp_callback_ = get_timestamp_callback; 1691 get_timestamp_callback_ = get_timestamp_callback;
1691 } 1692 }
1692 1693
1693 } // namespace content 1694 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698