| OLD | NEW |
| 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/file_util.h" | 7 #include "base/file_util.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/string_number_conversions.h" // Temporary | 9 #include "base/string_number_conversions.h" // Temporary |
| 10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 (*entries)[i]->SetTransitionType(content::PAGE_TRANSITION_RELOAD); | 96 (*entries)[i]->SetTransitionType(content::PAGE_TRANSITION_RELOAD); |
| 97 (*entries)[i]->set_restore_type(from_last_session ? | 97 (*entries)[i]->set_restore_type(from_last_session ? |
| 98 NavigationEntryImpl::RESTORE_LAST_SESSION : | 98 NavigationEntryImpl::RESTORE_LAST_SESSION : |
| 99 NavigationEntryImpl::RESTORE_CURRENT_SESSION); | 99 NavigationEntryImpl::RESTORE_CURRENT_SESSION); |
| 100 // NOTE(darin): This code is only needed for backwards compat. | 100 // NOTE(darin): This code is only needed for backwards compat. |
| 101 SetContentStateIfEmpty((*entries)[i].get()); | 101 SetContentStateIfEmpty((*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, const GURL& new_url) { | 106 bool AreURLsInPageNavigation(const GURL& existing_url, |
| 107 if (existing_url == new_url || !new_url.has_ref()) { | 107 const GURL& new_url, |
| 108 bool renderer_says_in_page) { |
| 109 if (existing_url == new_url) |
| 110 return renderer_says_in_page; |
| 111 |
| 112 if (!new_url.has_ref()) { |
| 108 // TODO(jcampan): what about when navigating back from a ref URL to the top | 113 // TODO(jcampan): what about when navigating back from a ref URL to the top |
| 109 // non ref URL? Nothing is loaded in that case but we return false here. | 114 // non ref URL? Nothing is loaded in that case but we return false here. |
| 110 // The user could also navigate from the ref URL to the non ref URL by | 115 // The user could also navigate from the ref URL to the non ref URL by |
| 111 // entering the non ref URL in the location bar or through a bookmark, in | 116 // entering the non ref URL in the location bar or through a bookmark, in |
| 112 // which case there would be a load. I am not sure if the non-load/load | 117 // which case there would be a load. I am not sure if the non-load/load |
| 113 // scenarios can be differentiated with the TransitionType. | 118 // scenarios can be differentiated with the TransitionType. |
| 114 return false; | 119 return false; |
| 115 } | 120 } |
| 116 | 121 |
| 117 url_canon::Replacements<char> replacements; | 122 url_canon::Replacements<char> replacements; |
| (...skipping 559 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 677 DCHECK(pending_entry_index_ == -1 || pending_entry_->site_instance()); | 682 DCHECK(pending_entry_index_ == -1 || pending_entry_->site_instance()); |
| 678 | 683 |
| 679 // If we are doing a cross-site reload, we need to replace the existing | 684 // If we are doing a cross-site reload, we need to replace the existing |
| 680 // navigation entry, not add another entry to the history. This has the side | 685 // navigation entry, not add another entry to the history. This has the side |
| 681 // effect of removing forward browsing history, if such existed. | 686 // effect of removing forward browsing history, if such existed. |
| 682 if (pending_entry_ != NULL) { | 687 if (pending_entry_ != NULL) { |
| 683 details->did_replace_entry = pending_entry_->is_cross_site_reload(); | 688 details->did_replace_entry = pending_entry_->is_cross_site_reload(); |
| 684 } | 689 } |
| 685 | 690 |
| 686 // is_in_page must be computed before the entry gets committed. | 691 // is_in_page must be computed before the entry gets committed. |
| 687 details->is_in_page = IsURLInPageNavigation(params.url); | 692 details->is_in_page = IsURLInPageNavigation( |
| 693 params.url, params.was_within_same_page); |
| 688 | 694 |
| 689 // Do navigation-type specific actions. These will make and commit an entry. | 695 // Do navigation-type specific actions. These will make and commit an entry. |
| 690 details->type = ClassifyNavigation(params); | 696 details->type = ClassifyNavigation(params); |
| 691 | 697 |
| 692 switch (details->type) { | 698 switch (details->type) { |
| 693 case content::NAVIGATION_TYPE_NEW_PAGE: | 699 case content::NAVIGATION_TYPE_NEW_PAGE: |
| 694 RendererDidNavigateToNewPage(params, &(details->did_replace_entry)); | 700 RendererDidNavigateToNewPage(params, &(details->did_replace_entry)); |
| 695 break; | 701 break; |
| 696 case content::NAVIGATION_TYPE_EXISTING_PAGE: | 702 case content::NAVIGATION_TYPE_EXISTING_PAGE: |
| 697 RendererDidNavigateToExistingPage(params); | 703 RendererDidNavigateToExistingPage(params); |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 864 // this). If this matches the last committed entry, we want to just ignore | 870 // this). If this matches the last committed entry, we want to just ignore |
| 865 // the pending entry and go back to where we were (the "existing entry"). | 871 // the pending entry and go back to where we were (the "existing entry"). |
| 866 return content::NAVIGATION_TYPE_SAME_PAGE; | 872 return content::NAVIGATION_TYPE_SAME_PAGE; |
| 867 } | 873 } |
| 868 | 874 |
| 869 // Any toplevel navigations with the same base (minus the reference fragment) | 875 // Any toplevel navigations with the same base (minus the reference fragment) |
| 870 // are in-page navigations. We weeded out subframe navigations above. Most of | 876 // are in-page navigations. We weeded out subframe navigations above. Most of |
| 871 // the time this doesn't matter since WebKit doesn't tell us about subframe | 877 // the time this doesn't matter since WebKit doesn't tell us about subframe |
| 872 // navigations that don't actually navigate, but it can happen when there is | 878 // navigations that don't actually navigate, but it can happen when there is |
| 873 // an encoding override (it always sends a navigation request). | 879 // an encoding override (it always sends a navigation request). |
| 874 if (AreURLsInPageNavigation(existing_entry->GetURL(), params.url)) | 880 if (AreURLsInPageNavigation(existing_entry->GetURL(), params.url, false)) |
| 875 return content::NAVIGATION_TYPE_IN_PAGE; | 881 return content::NAVIGATION_TYPE_IN_PAGE; |
| 876 | 882 |
| 877 // Since we weeded out "new" navigations above, we know this is an existing | 883 // Since we weeded out "new" navigations above, we know this is an existing |
| 878 // (back/forward) navigation. | 884 // (back/forward) navigation. |
| 879 return content::NAVIGATION_TYPE_EXISTING_PAGE; | 885 return content::NAVIGATION_TYPE_EXISTING_PAGE; |
| 880 } | 886 } |
| 881 | 887 |
| 882 bool NavigationControllerImpl::IsRedirect( | 888 bool NavigationControllerImpl::IsRedirect( |
| 883 const ViewHostMsg_FrameNavigate_Params& params) { | 889 const ViewHostMsg_FrameNavigate_Params& params) { |
| 884 // For main frame transition, we judge by params.transition. | 890 // For main frame transition, we judge by params.transition. |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1072 | 1078 |
| 1073 int NavigationControllerImpl::GetIndexOfEntry( | 1079 int NavigationControllerImpl::GetIndexOfEntry( |
| 1074 const NavigationEntryImpl* entry) const { | 1080 const NavigationEntryImpl* entry) const { |
| 1075 const NavigationEntries::const_iterator i(std::find( | 1081 const NavigationEntries::const_iterator i(std::find( |
| 1076 entries_.begin(), | 1082 entries_.begin(), |
| 1077 entries_.end(), | 1083 entries_.end(), |
| 1078 entry)); | 1084 entry)); |
| 1079 return (i == entries_.end()) ? -1 : static_cast<int>(i - entries_.begin()); | 1085 return (i == entries_.end()) ? -1 : static_cast<int>(i - entries_.begin()); |
| 1080 } | 1086 } |
| 1081 | 1087 |
| 1082 bool NavigationControllerImpl::IsURLInPageNavigation(const GURL& url) const { | 1088 bool NavigationControllerImpl::IsURLInPageNavigation( |
| 1089 const GURL& url, bool renderer_says_in_page) const { |
| 1083 NavigationEntry* last_committed = GetLastCommittedEntry(); | 1090 NavigationEntry* last_committed = GetLastCommittedEntry(); |
| 1084 if (!last_committed) | 1091 return last_committed && AreURLsInPageNavigation( |
| 1085 return false; | 1092 last_committed->GetURL(), url, renderer_says_in_page); |
| 1086 return AreURLsInPageNavigation(last_committed->GetURL(), url); | |
| 1087 } | 1093 } |
| 1088 | 1094 |
| 1089 void NavigationControllerImpl::CopyStateFrom( | 1095 void NavigationControllerImpl::CopyStateFrom( |
| 1090 const NavigationController& temp) { | 1096 const NavigationController& temp) { |
| 1091 const NavigationControllerImpl& source = | 1097 const NavigationControllerImpl& source = |
| 1092 static_cast<const NavigationControllerImpl&>(temp); | 1098 static_cast<const NavigationControllerImpl&>(temp); |
| 1093 // Verify that we look new. | 1099 // Verify that we look new. |
| 1094 DCHECK(GetEntryCount() == 0 && !GetPendingEntry()); | 1100 DCHECK(GetEntryCount() == 0 && !GetPendingEntry()); |
| 1095 | 1101 |
| 1096 if (source.GetEntryCount() == 0) | 1102 if (source.GetEntryCount() == 0) |
| (...skipping 450 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1547 for (int i = 0; i < max_index; i++) { | 1553 for (int i = 0; i < max_index; i++) { |
| 1548 // When cloning a tab, copy all entries except interstitial pages | 1554 // When cloning a tab, copy all entries except interstitial pages |
| 1549 if (source.entries_[i].get()->GetPageType() != | 1555 if (source.entries_[i].get()->GetPageType() != |
| 1550 content::PAGE_TYPE_INTERSTITIAL) { | 1556 content::PAGE_TYPE_INTERSTITIAL) { |
| 1551 entries_.insert(entries_.begin() + insert_index++, | 1557 entries_.insert(entries_.begin() + insert_index++, |
| 1552 linked_ptr<NavigationEntryImpl>( | 1558 linked_ptr<NavigationEntryImpl>( |
| 1553 new NavigationEntryImpl(*source.entries_[i]))); | 1559 new NavigationEntryImpl(*source.entries_[i]))); |
| 1554 } | 1560 } |
| 1555 } | 1561 } |
| 1556 } | 1562 } |
| OLD | NEW |