OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 "chrome/browser/tab_contents/navigation_controller.h" | 5 #include "chrome/browser/tab_contents/navigation_controller.h" |
6 | 6 |
7 #include "app/resource_bundle.h" | 7 #include "app/resource_bundle.h" |
8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 void SetContentStateIfEmpty(NavigationEntry* entry) { | 60 void SetContentStateIfEmpty(NavigationEntry* entry) { |
61 if (entry->content_state().empty()) { | 61 if (entry->content_state().empty()) { |
62 entry->set_content_state( | 62 entry->set_content_state( |
63 webkit_glue::CreateHistoryStateForURL(entry->url())); | 63 webkit_glue::CreateHistoryStateForURL(entry->url())); |
64 } | 64 } |
65 } | 65 } |
66 | 66 |
67 // Configure all the NavigationEntries in entries for restore. This resets | 67 // Configure all the NavigationEntries in entries for restore. This resets |
68 // the transition type to reload and makes sure the content state isn't empty. | 68 // the transition type to reload and makes sure the content state isn't empty. |
69 void ConfigureEntriesForRestore( | 69 void ConfigureEntriesForRestore( |
70 std::vector<linked_ptr<NavigationEntry> >* entries) { | 70 std::vector<linked_ptr<NavigationEntry> >* entries, |
| 71 bool from_last_session) { |
71 for (size_t i = 0; i < entries->size(); ++i) { | 72 for (size_t i = 0; i < entries->size(); ++i) { |
72 // Use a transition type of reload so that we don't incorrectly increase | 73 // Use a transition type of reload so that we don't incorrectly increase |
73 // the typed count. | 74 // the typed count. |
74 (*entries)[i]->set_transition_type(PageTransition::RELOAD); | 75 (*entries)[i]->set_transition_type(PageTransition::RELOAD); |
75 (*entries)[i]->set_restored(true); | 76 (*entries)[i]->set_restore_type(from_last_session ? |
| 77 NavigationEntry::RESTORE_LAST_SESSION : |
| 78 NavigationEntry::RESTORE_CURRENT_SESSION); |
76 // NOTE(darin): This code is only needed for backwards compat. | 79 // NOTE(darin): This code is only needed for backwards compat. |
77 SetContentStateIfEmpty((*entries)[i].get()); | 80 SetContentStateIfEmpty((*entries)[i].get()); |
78 } | 81 } |
79 } | 82 } |
80 | 83 |
81 // See NavigationController::IsURLInPageNavigation for how this works and why. | 84 // See NavigationController::IsURLInPageNavigation for how this works and why. |
82 bool AreURLsInPageNavigation(const GURL& existing_url, const GURL& new_url) { | 85 bool AreURLsInPageNavigation(const GURL& existing_url, const GURL& new_url) { |
83 if (existing_url == new_url || !new_url.has_ref()) | 86 if (existing_url == new_url || !new_url.has_ref()) |
84 return false; | 87 return false; |
85 | 88 |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 DiscardNonCommittedEntriesInternal(); | 141 DiscardNonCommittedEntriesInternal(); |
139 | 142 |
140 NotificationService::current()->Notify( | 143 NotificationService::current()->Notify( |
141 NotificationType::TAB_CLOSED, | 144 NotificationType::TAB_CLOSED, |
142 Source<NavigationController>(this), | 145 Source<NavigationController>(this), |
143 NotificationService::NoDetails()); | 146 NotificationService::NoDetails()); |
144 } | 147 } |
145 | 148 |
146 void NavigationController::RestoreFromState( | 149 void NavigationController::RestoreFromState( |
147 const std::vector<TabNavigation>& navigations, | 150 const std::vector<TabNavigation>& navigations, |
148 int selected_navigation) { | 151 int selected_navigation, |
| 152 bool from_last_session) { |
149 // Verify that this controller is unused and that the input is valid. | 153 // Verify that this controller is unused and that the input is valid. |
150 DCHECK(entry_count() == 0 && !pending_entry()); | 154 DCHECK(entry_count() == 0 && !pending_entry()); |
151 DCHECK(selected_navigation >= 0 && | 155 DCHECK(selected_navigation >= 0 && |
152 selected_navigation < static_cast<int>(navigations.size())); | 156 selected_navigation < static_cast<int>(navigations.size())); |
153 | 157 |
154 // Populate entries_ from the supplied TabNavigations. | 158 // Populate entries_ from the supplied TabNavigations. |
155 needs_reload_ = true; | 159 needs_reload_ = true; |
156 CreateNavigationEntriesFromTabNavigations(navigations, &entries_); | 160 CreateNavigationEntriesFromTabNavigations(navigations, &entries_); |
157 | 161 |
158 // And finish the restore. | 162 // And finish the restore. |
159 FinishRestore(selected_navigation); | 163 FinishRestore(selected_navigation, from_last_session); |
160 } | 164 } |
161 | 165 |
162 void NavigationController::Reload(bool check_for_repost) { | 166 void NavigationController::Reload(bool check_for_repost) { |
163 // Reloading a transient entry does nothing. | 167 // Reloading a transient entry does nothing. |
164 if (transient_entry_index_ != -1) | 168 if (transient_entry_index_ != -1) |
165 return; | 169 return; |
166 | 170 |
167 DiscardNonCommittedEntriesInternal(); | 171 DiscardNonCommittedEntriesInternal(); |
168 int current_index = GetCurrentEntryIndex(); | 172 int current_index = GetCurrentEntryIndex(); |
169 if (check_for_repost_ && check_for_repost && current_index != -1 && | 173 if (check_for_repost_ && check_for_repost && current_index != -1 && |
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
415 } | 419 } |
416 | 420 |
417 // Assign the current site instance to any pending entry, so we can find it | 421 // Assign the current site instance to any pending entry, so we can find it |
418 // later by calling GetEntryIndexWithPageID. We only care about this if the | 422 // later by calling GetEntryIndexWithPageID. We only care about this if the |
419 // pending entry is an existing navigation and not a new one (or else we | 423 // pending entry is an existing navigation and not a new one (or else we |
420 // wouldn't care about finding it with GetEntryIndexWithPageID). | 424 // wouldn't care about finding it with GetEntryIndexWithPageID). |
421 // | 425 // |
422 // TODO(brettw) this seems slightly bogus as we don't really know if the | 426 // TODO(brettw) this seems slightly bogus as we don't really know if the |
423 // pending entry is what this navigation is for. There is a similar TODO | 427 // pending entry is what this navigation is for. There is a similar TODO |
424 // w.r.t. the pending entry in RendererDidNavigateToNewPage. | 428 // w.r.t. the pending entry in RendererDidNavigateToNewPage. |
425 if (pending_entry_index_ >= 0) | 429 if (pending_entry_index_ >= 0) { |
426 pending_entry_->set_site_instance(tab_contents_->GetSiteInstance()); | 430 pending_entry_->set_site_instance(tab_contents_->GetSiteInstance()); |
| 431 pending_entry_->set_restore_type(NavigationEntry::RESTORE_NONE); |
| 432 } |
427 | 433 |
428 // Do navigation-type specific actions. These will make and commit an entry. | 434 // Do navigation-type specific actions. These will make and commit an entry. |
429 details->type = ClassifyNavigation(params); | 435 details->type = ClassifyNavigation(params); |
430 switch (details->type) { | 436 switch (details->type) { |
431 case NavigationType::NEW_PAGE: | 437 case NavigationType::NEW_PAGE: |
432 RendererDidNavigateToNewPage(params, &(details->did_replace_entry)); | 438 RendererDidNavigateToNewPage(params, &(details->did_replace_entry)); |
433 break; | 439 break; |
434 case NavigationType::EXISTING_PAGE: | 440 case NavigationType::EXISTING_PAGE: |
435 RendererDidNavigateToExistingPage(params); | 441 RendererDidNavigateToExistingPage(params); |
436 break; | 442 break; |
(...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
821 | 827 |
822 if (source.entry_count() == 0) | 828 if (source.entry_count() == 0) |
823 return; // Nothing new to do. | 829 return; // Nothing new to do. |
824 | 830 |
825 needs_reload_ = true; | 831 needs_reload_ = true; |
826 for (int i = 0; i < source.entry_count(); i++) { | 832 for (int i = 0; i < source.entry_count(); i++) { |
827 entries_.push_back(linked_ptr<NavigationEntry>( | 833 entries_.push_back(linked_ptr<NavigationEntry>( |
828 new NavigationEntry(*source.entries_[i]))); | 834 new NavigationEntry(*source.entries_[i]))); |
829 } | 835 } |
830 | 836 |
831 FinishRestore(source.last_committed_entry_index_); | 837 FinishRestore(source.last_committed_entry_index_, false); |
832 } | 838 } |
833 | 839 |
834 void NavigationController::DiscardNonCommittedEntries() { | 840 void NavigationController::DiscardNonCommittedEntries() { |
835 bool transient = transient_entry_index_ != -1; | 841 bool transient = transient_entry_index_ != -1; |
836 DiscardNonCommittedEntriesInternal(); | 842 DiscardNonCommittedEntriesInternal(); |
837 | 843 |
838 // If there was a transient entry, invalidate everything so the new active | 844 // If there was a transient entry, invalidate everything so the new active |
839 // entry state is shown. | 845 // entry state is shown. |
840 if (transient) { | 846 if (transient) { |
841 tab_contents_->NotifyNavigationStateChanged(kInvalidateAllButShelves); | 847 tab_contents_->NotifyNavigationStateChanged(kInvalidateAllButShelves); |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
951 void NavigationController::NotifyEntryChanged(const NavigationEntry* entry, | 957 void NavigationController::NotifyEntryChanged(const NavigationEntry* entry, |
952 int index) { | 958 int index) { |
953 EntryChangedDetails det; | 959 EntryChangedDetails det; |
954 det.changed_entry = entry; | 960 det.changed_entry = entry; |
955 det.index = index; | 961 det.index = index; |
956 NotificationService::current()->Notify(NotificationType::NAV_ENTRY_CHANGED, | 962 NotificationService::current()->Notify(NotificationType::NAV_ENTRY_CHANGED, |
957 Source<NavigationController>(this), | 963 Source<NavigationController>(this), |
958 Details<EntryChangedDetails>(&det)); | 964 Details<EntryChangedDetails>(&det)); |
959 } | 965 } |
960 | 966 |
961 void NavigationController::FinishRestore(int selected_index) { | 967 void NavigationController::FinishRestore(int selected_index, |
| 968 bool from_last_session) { |
962 DCHECK(selected_index >= 0 && selected_index < entry_count()); | 969 DCHECK(selected_index >= 0 && selected_index < entry_count()); |
963 ConfigureEntriesForRestore(&entries_); | 970 ConfigureEntriesForRestore(&entries_, from_last_session); |
964 | 971 |
965 set_max_restored_page_id(entry_count()); | 972 set_max_restored_page_id(entry_count()); |
966 | 973 |
967 last_committed_entry_index_ = selected_index; | 974 last_committed_entry_index_ = selected_index; |
968 } | 975 } |
969 | 976 |
970 void NavigationController::DiscardNonCommittedEntriesInternal() { | 977 void NavigationController::DiscardNonCommittedEntriesInternal() { |
971 if (pending_entry_index_ == -1) | 978 if (pending_entry_index_ == -1) |
972 delete pending_entry_; | 979 delete pending_entry_; |
973 pending_entry_ = NULL; | 980 pending_entry_ = NULL; |
(...skipping 19 matching lines...) Expand all Loading... |
993 return i; | 1000 return i; |
994 } | 1001 } |
995 return -1; | 1002 return -1; |
996 } | 1003 } |
997 | 1004 |
998 NavigationEntry* NavigationController::GetTransientEntry() const { | 1005 NavigationEntry* NavigationController::GetTransientEntry() const { |
999 if (transient_entry_index_ == -1) | 1006 if (transient_entry_index_ == -1) |
1000 return NULL; | 1007 return NULL; |
1001 return entries_[transient_entry_index_].get(); | 1008 return entries_[transient_entry_index_].get(); |
1002 } | 1009 } |
OLD | NEW |