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

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

Powered by Google App Engine
This is Rietveld 408576698