| 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 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 pending_entry_(NULL), | 139 pending_entry_(NULL), |
| 140 last_committed_entry_index_(-1), | 140 last_committed_entry_index_(-1), |
| 141 pending_entry_index_(-1), | 141 pending_entry_index_(-1), |
| 142 transient_entry_index_(-1), | 142 transient_entry_index_(-1), |
| 143 tab_contents_(contents), | 143 tab_contents_(contents), |
| 144 max_restored_page_id_(-1), | 144 max_restored_page_id_(-1), |
| 145 ALLOW_THIS_IN_INITIALIZER_LIST(ssl_manager_(this)), | 145 ALLOW_THIS_IN_INITIALIZER_LIST(ssl_manager_(this)), |
| 146 needs_reload_(false), | 146 needs_reload_(false), |
| 147 user_gesture_observed_(false), | 147 user_gesture_observed_(false), |
| 148 session_storage_namespace_id_(profile->GetWebKitContext()-> | 148 session_storage_namespace_id_(profile->GetWebKitContext()-> |
| 149 dom_storage_context()->AllocateSessionStorageNamespaceId()) { | 149 dom_storage_context()->AllocateSessionStorageNamespaceId()), |
| 150 pending_reload_(NO_RELOAD) { |
| 150 DCHECK(profile_); | 151 DCHECK(profile_); |
| 151 } | 152 } |
| 152 | 153 |
| 153 NavigationController::~NavigationController() { | 154 NavigationController::~NavigationController() { |
| 154 DiscardNonCommittedEntriesInternal(); | 155 DiscardNonCommittedEntriesInternal(); |
| 155 | 156 |
| 156 NotificationService::current()->Notify( | 157 NotificationService::current()->Notify( |
| 157 NotificationType::TAB_CLOSED, | 158 NotificationType::TAB_CLOSED, |
| 158 Source<NavigationController>(this), | 159 Source<NavigationController>(this), |
| 159 NotificationService::NoDetails()); | 160 NotificationService::NoDetails()); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 188 } | 189 } |
| 189 | 190 |
| 190 void NavigationController::ReloadInternal(bool check_for_repost, | 191 void NavigationController::ReloadInternal(bool check_for_repost, |
| 191 ReloadType reload_type) { | 192 ReloadType reload_type) { |
| 192 // Reloading a transient entry does nothing. | 193 // Reloading a transient entry does nothing. |
| 193 if (transient_entry_index_ != -1) | 194 if (transient_entry_index_ != -1) |
| 194 return; | 195 return; |
| 195 | 196 |
| 196 DiscardNonCommittedEntriesInternal(); | 197 DiscardNonCommittedEntriesInternal(); |
| 197 int current_index = GetCurrentEntryIndex(); | 198 int current_index = GetCurrentEntryIndex(); |
| 198 if (check_for_repost_ && check_for_repost && current_index != -1 && | 199 // If we are no where, then we can't reload. TODO(darin): We should add a |
| 200 // CanReload method. |
| 201 if (current_index == -1) { |
| 202 return; |
| 203 } |
| 204 |
| 205 NotificationService::current()->Notify(NotificationType::RELOADING, |
| 206 Source<NavigationController>(this), |
| 207 NotificationService::NoDetails()); |
| 208 |
| 209 if (check_for_repost_ && check_for_repost && |
| 199 GetEntryAtIndex(current_index)->has_post_data()) { | 210 GetEntryAtIndex(current_index)->has_post_data()) { |
| 200 // The user is asking to reload a page with POST data. Prompt to make sure | 211 // The user is asking to reload a page with POST data. Prompt to make sure |
| 201 // they really want to do this. If they do, the dialog will call us back | 212 // they really want to do this. If they do, the dialog will call us back |
| 202 // with check_for_repost = false. | 213 // with check_for_repost = false. |
| 214 pending_reload_ = reload_type; |
| 203 tab_contents_->Activate(); | 215 tab_contents_->Activate(); |
| 204 tab_contents_->delegate()->ShowRepostFormWarningDialog(tab_contents_); | 216 tab_contents_->delegate()->ShowRepostFormWarningDialog(tab_contents_); |
| 205 } else { | 217 } else { |
| 206 // Base the navigation on where we are now... | |
| 207 int current_index = GetCurrentEntryIndex(); | |
| 208 | |
| 209 // If we are no where, then we can't reload. TODO(darin): We should add a | |
| 210 // CanReload method. | |
| 211 if (current_index == -1) | |
| 212 return; | |
| 213 | |
| 214 DiscardNonCommittedEntriesInternal(); | 218 DiscardNonCommittedEntriesInternal(); |
| 215 | 219 |
| 216 pending_entry_index_ = current_index; | 220 pending_entry_index_ = current_index; |
| 217 entries_[pending_entry_index_]->set_transition_type(PageTransition::RELOAD); | 221 entries_[pending_entry_index_]->set_transition_type(PageTransition::RELOAD); |
| 218 NavigateToPendingEntry(reload_type); | 222 NavigateToPendingEntry(reload_type); |
| 219 } | 223 } |
| 220 } | 224 } |
| 221 | 225 |
| 226 void NavigationController::CancelPendingReload() { |
| 227 DCHECK(pending_reload_ != NO_RELOAD); |
| 228 pending_reload_ = NO_RELOAD; |
| 229 } |
| 230 |
| 231 void NavigationController::ContinuePendingReload() { |
| 232 if (pending_reload_ == NO_RELOAD) { |
| 233 NOTREACHED(); |
| 234 } else { |
| 235 ReloadInternal(false, pending_reload_); |
| 236 CancelPendingReload(); |
| 237 } |
| 238 } |
| 239 |
| 222 NavigationEntry* NavigationController::GetEntryWithPageID( | 240 NavigationEntry* NavigationController::GetEntryWithPageID( |
| 223 SiteInstance* instance, int32 page_id) const { | 241 SiteInstance* instance, int32 page_id) const { |
| 224 int index = GetEntryIndexWithPageID(instance, page_id); | 242 int index = GetEntryIndexWithPageID(instance, page_id); |
| 225 return (index != -1) ? entries_[index].get() : NULL; | 243 return (index != -1) ? entries_[index].get() : NULL; |
| 226 } | 244 } |
| 227 | 245 |
| 228 void NavigationController::LoadEntry(NavigationEntry* entry) { | 246 void NavigationController::LoadEntry(NavigationEntry* entry) { |
| 229 // Handle non-navigational URLs that popup dialogs and such, these should not | 247 // Handle non-navigational URLs that popup dialogs and such, these should not |
| 230 // actually navigate. | 248 // actually navigate. |
| 231 if (HandleNonNavigationAboutURL(entry->url())) | 249 if (HandleNonNavigationAboutURL(entry->url())) |
| (...skipping 864 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1096 return i; | 1114 return i; |
| 1097 } | 1115 } |
| 1098 return -1; | 1116 return -1; |
| 1099 } | 1117 } |
| 1100 | 1118 |
| 1101 NavigationEntry* NavigationController::GetTransientEntry() const { | 1119 NavigationEntry* NavigationController::GetTransientEntry() const { |
| 1102 if (transient_entry_index_ == -1) | 1120 if (transient_entry_index_ == -1) |
| 1103 return NULL; | 1121 return NULL; |
| 1104 return entries_[transient_entry_index_].get(); | 1122 return entries_[transient_entry_index_].get(); |
| 1105 } | 1123 } |
| OLD | NEW |