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 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 | 166 |
167 // Populate entries_ from the supplied TabNavigations. | 167 // Populate entries_ from the supplied TabNavigations. |
168 needs_reload_ = true; | 168 needs_reload_ = true; |
169 CreateNavigationEntriesFromTabNavigations(navigations, &entries_); | 169 CreateNavigationEntriesFromTabNavigations(navigations, &entries_); |
170 | 170 |
171 // And finish the restore. | 171 // And finish the restore. |
172 FinishRestore(selected_navigation, from_last_session); | 172 FinishRestore(selected_navigation, from_last_session); |
173 } | 173 } |
174 | 174 |
175 void NavigationController::Reload(bool check_for_repost) { | 175 void NavigationController::Reload(bool check_for_repost) { |
| 176 ReloadInternal(check_for_repost, RELOAD_VALIDATING_CACHE); |
| 177 } |
| 178 void NavigationController::ReloadIgnoringCache(bool check_for_repost) { |
| 179 ReloadInternal(check_for_repost, RELOAD_IGNORING_CACHE); |
| 180 } |
| 181 |
| 182 void NavigationController::ReloadInternal(bool check_for_repost, |
| 183 ReloadType reload_type) { |
176 // Reloading a transient entry does nothing. | 184 // Reloading a transient entry does nothing. |
177 if (transient_entry_index_ != -1) | 185 if (transient_entry_index_ != -1) |
178 return; | 186 return; |
179 | 187 |
180 DiscardNonCommittedEntriesInternal(); | 188 DiscardNonCommittedEntriesInternal(); |
181 int current_index = GetCurrentEntryIndex(); | 189 int current_index = GetCurrentEntryIndex(); |
182 if (check_for_repost_ && check_for_repost && current_index != -1 && | 190 if (check_for_repost_ && check_for_repost && current_index != -1 && |
183 GetEntryAtIndex(current_index)->has_post_data()) { | 191 GetEntryAtIndex(current_index)->has_post_data()) { |
184 // The user is asking to reload a page with POST data. Prompt to make sure | 192 // The user is asking to reload a page with POST data. Prompt to make sure |
185 // they really want to do this. If they do, the dialog will call us back | 193 // they really want to do this. If they do, the dialog will call us back |
186 // with check_for_repost = false. | 194 // with check_for_repost = false. |
187 tab_contents_->Activate(); | 195 tab_contents_->Activate(); |
188 tab_contents_->delegate()->ShowRepostFormWarningDialog(tab_contents_); | 196 tab_contents_->delegate()->ShowRepostFormWarningDialog(tab_contents_); |
189 } else { | 197 } else { |
190 // Base the navigation on where we are now... | 198 // Base the navigation on where we are now... |
191 int current_index = GetCurrentEntryIndex(); | 199 int current_index = GetCurrentEntryIndex(); |
192 | 200 |
193 // If we are no where, then we can't reload. TODO(darin): We should add a | 201 // If we are no where, then we can't reload. TODO(darin): We should add a |
194 // CanReload method. | 202 // CanReload method. |
195 if (current_index == -1) | 203 if (current_index == -1) |
196 return; | 204 return; |
197 | 205 |
198 DiscardNonCommittedEntriesInternal(); | 206 DiscardNonCommittedEntriesInternal(); |
199 | 207 |
200 pending_entry_index_ = current_index; | 208 pending_entry_index_ = current_index; |
201 entries_[pending_entry_index_]->set_transition_type(PageTransition::RELOAD); | 209 entries_[pending_entry_index_]->set_transition_type(PageTransition::RELOAD); |
202 NavigateToPendingEntry(true); | 210 NavigateToPendingEntry(reload_type); |
203 } | 211 } |
204 } | 212 } |
205 | 213 |
206 NavigationEntry* NavigationController::GetEntryWithPageID( | 214 NavigationEntry* NavigationController::GetEntryWithPageID( |
207 SiteInstance* instance, int32 page_id) const { | 215 SiteInstance* instance, int32 page_id) const { |
208 int index = GetEntryIndexWithPageID(instance, page_id); | 216 int index = GetEntryIndexWithPageID(instance, page_id); |
209 return (index != -1) ? entries_[index].get() : NULL; | 217 return (index != -1) ? entries_[index].get() : NULL; |
210 } | 218 } |
211 | 219 |
212 void NavigationController::LoadEntry(NavigationEntry* entry) { | 220 void NavigationController::LoadEntry(NavigationEntry* entry) { |
213 // Handle non-navigational URLs that popup dialogs and such, these should not | 221 // Handle non-navigational URLs that popup dialogs and such, these should not |
214 // actually navigate. | 222 // actually navigate. |
215 if (HandleNonNavigationAboutURL(entry->url())) | 223 if (HandleNonNavigationAboutURL(entry->url())) |
216 return; | 224 return; |
217 | 225 |
218 // When navigating to a new page, we don't know for sure if we will actually | 226 // When navigating to a new page, we don't know for sure if we will actually |
219 // end up leaving the current page. The new page load could for example | 227 // end up leaving the current page. The new page load could for example |
220 // result in a download or a 'no content' response (e.g., a mailto: URL). | 228 // result in a download or a 'no content' response (e.g., a mailto: URL). |
221 DiscardNonCommittedEntriesInternal(); | 229 DiscardNonCommittedEntriesInternal(); |
222 pending_entry_ = entry; | 230 pending_entry_ = entry; |
223 NotificationService::current()->Notify( | 231 NotificationService::current()->Notify( |
224 NotificationType::NAV_ENTRY_PENDING, | 232 NotificationType::NAV_ENTRY_PENDING, |
225 Source<NavigationController>(this), | 233 Source<NavigationController>(this), |
226 NotificationService::NoDetails()); | 234 NotificationService::NoDetails()); |
227 NavigateToPendingEntry(false); | 235 NavigateToPendingEntry(NO_RELOAD); |
228 } | 236 } |
229 | 237 |
230 NavigationEntry* NavigationController::GetActiveEntry() const { | 238 NavigationEntry* NavigationController::GetActiveEntry() const { |
231 if (transient_entry_index_ != -1) | 239 if (transient_entry_index_ != -1) |
232 return entries_[transient_entry_index_].get(); | 240 return entries_[transient_entry_index_].get(); |
233 if (pending_entry_) | 241 if (pending_entry_) |
234 return pending_entry_; | 242 return pending_entry_; |
235 return GetLastCommittedEntry(); | 243 return GetLastCommittedEntry(); |
236 } | 244 } |
237 | 245 |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
281 NOTREACHED(); | 289 NOTREACHED(); |
282 return; | 290 return; |
283 } | 291 } |
284 | 292 |
285 // Base the navigation on where we are now... | 293 // Base the navigation on where we are now... |
286 int current_index = GetCurrentEntryIndex(); | 294 int current_index = GetCurrentEntryIndex(); |
287 | 295 |
288 DiscardNonCommittedEntries(); | 296 DiscardNonCommittedEntries(); |
289 | 297 |
290 pending_entry_index_ = current_index - 1; | 298 pending_entry_index_ = current_index - 1; |
291 NavigateToPendingEntry(false); | 299 NavigateToPendingEntry(NO_RELOAD); |
292 } | 300 } |
293 | 301 |
294 void NavigationController::GoForward() { | 302 void NavigationController::GoForward() { |
295 if (!CanGoForward()) { | 303 if (!CanGoForward()) { |
296 NOTREACHED(); | 304 NOTREACHED(); |
297 return; | 305 return; |
298 } | 306 } |
299 | 307 |
300 bool transient = (transient_entry_index_ != -1); | 308 bool transient = (transient_entry_index_ != -1); |
301 | 309 |
302 // Base the navigation on where we are now... | 310 // Base the navigation on where we are now... |
303 int current_index = GetCurrentEntryIndex(); | 311 int current_index = GetCurrentEntryIndex(); |
304 | 312 |
305 DiscardNonCommittedEntries(); | 313 DiscardNonCommittedEntries(); |
306 | 314 |
307 pending_entry_index_ = current_index; | 315 pending_entry_index_ = current_index; |
308 // If there was a transient entry, we removed it making the current index | 316 // If there was a transient entry, we removed it making the current index |
309 // the next page. | 317 // the next page. |
310 if (!transient) | 318 if (!transient) |
311 pending_entry_index_++; | 319 pending_entry_index_++; |
312 | 320 |
313 NavigateToPendingEntry(false); | 321 NavigateToPendingEntry(NO_RELOAD); |
314 } | 322 } |
315 | 323 |
316 void NavigationController::GoToIndex(int index) { | 324 void NavigationController::GoToIndex(int index) { |
317 if (index < 0 || index >= static_cast<int>(entries_.size())) { | 325 if (index < 0 || index >= static_cast<int>(entries_.size())) { |
318 NOTREACHED(); | 326 NOTREACHED(); |
319 return; | 327 return; |
320 } | 328 } |
321 | 329 |
322 if (transient_entry_index_ != -1) { | 330 if (transient_entry_index_ != -1) { |
323 if (index == transient_entry_index_) { | 331 if (index == transient_entry_index_) { |
324 // Nothing to do when navigating to the transient. | 332 // Nothing to do when navigating to the transient. |
325 return; | 333 return; |
326 } | 334 } |
327 if (index > transient_entry_index_) { | 335 if (index > transient_entry_index_) { |
328 // Removing the transient is goint to shift all entries by 1. | 336 // Removing the transient is goint to shift all entries by 1. |
329 index--; | 337 index--; |
330 } | 338 } |
331 } | 339 } |
332 | 340 |
333 DiscardNonCommittedEntries(); | 341 DiscardNonCommittedEntries(); |
334 | 342 |
335 pending_entry_index_ = index; | 343 pending_entry_index_ = index; |
336 NavigateToPendingEntry(false); | 344 NavigateToPendingEntry(NO_RELOAD); |
337 } | 345 } |
338 | 346 |
339 void NavigationController::GoToOffset(int offset) { | 347 void NavigationController::GoToOffset(int offset) { |
340 int index = (transient_entry_index_ != -1) ? | 348 int index = (transient_entry_index_ != -1) ? |
341 transient_entry_index_ + offset : | 349 transient_entry_index_ + offset : |
342 last_committed_entry_index_ + offset; | 350 last_committed_entry_index_ + offset; |
343 if (index < 0 || index >= entry_count()) | 351 if (index < 0 || index >= entry_count()) |
344 return; | 352 return; |
345 | 353 |
346 GoToIndex(index); | 354 GoToIndex(index); |
347 } | 355 } |
348 | 356 |
349 void NavigationController::RemoveEntryAtIndex(int index, | 357 void NavigationController::RemoveEntryAtIndex(int index, |
350 const GURL& default_url) { | 358 const GURL& default_url) { |
351 int size = static_cast<int>(entries_.size()); | 359 int size = static_cast<int>(entries_.size()); |
352 DCHECK(index < size); | 360 DCHECK(index < size); |
353 | 361 |
354 DiscardNonCommittedEntries(); | 362 DiscardNonCommittedEntries(); |
355 | 363 |
356 entries_.erase(entries_.begin() + index); | 364 entries_.erase(entries_.begin() + index); |
357 | 365 |
358 if (last_committed_entry_index_ == index) { | 366 if (last_committed_entry_index_ == index) { |
359 last_committed_entry_index_--; | 367 last_committed_entry_index_--; |
360 // We removed the currently shown entry, so we have to load something else. | 368 // We removed the currently shown entry, so we have to load something else. |
361 if (last_committed_entry_index_ != -1) { | 369 if (last_committed_entry_index_ != -1) { |
362 pending_entry_index_ = last_committed_entry_index_; | 370 pending_entry_index_ = last_committed_entry_index_; |
363 NavigateToPendingEntry(false); | 371 NavigateToPendingEntry(NO_RELOAD); |
364 } else { | 372 } else { |
365 // If there is nothing to show, show a default page. | 373 // If there is nothing to show, show a default page. |
366 LoadURL(default_url.is_empty() ? GURL("about:blank") : default_url, | 374 LoadURL(default_url.is_empty() ? GURL("about:blank") : default_url, |
367 GURL(), PageTransition::START_PAGE); | 375 GURL(), PageTransition::START_PAGE); |
368 } | 376 } |
369 } else if (last_committed_entry_index_ > index) { | 377 } else if (last_committed_entry_index_ > index) { |
370 last_committed_entry_index_--; | 378 last_committed_entry_index_--; |
371 } | 379 } |
372 } | 380 } |
373 | 381 |
(...skipping 559 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
933 tab_contents_->UpdateMaxPageID(entry->page_id()); | 941 tab_contents_->UpdateMaxPageID(entry->page_id()); |
934 } | 942 } |
935 | 943 |
936 void NavigationController::SetWindowID(const SessionID& id) { | 944 void NavigationController::SetWindowID(const SessionID& id) { |
937 window_id_ = id; | 945 window_id_ = id; |
938 NotificationService::current()->Notify(NotificationType::TAB_PARENTED, | 946 NotificationService::current()->Notify(NotificationType::TAB_PARENTED, |
939 Source<NavigationController>(this), | 947 Source<NavigationController>(this), |
940 NotificationService::NoDetails()); | 948 NotificationService::NoDetails()); |
941 } | 949 } |
942 | 950 |
943 void NavigationController::NavigateToPendingEntry(bool reload) { | 951 void NavigationController::NavigateToPendingEntry(ReloadType reload_type) { |
944 needs_reload_ = false; | 952 needs_reload_ = false; |
945 | 953 |
946 // For session history navigations only the pending_entry_index_ is set. | 954 // For session history navigations only the pending_entry_index_ is set. |
947 if (!pending_entry_) { | 955 if (!pending_entry_) { |
948 DCHECK(pending_entry_index_ != -1); | 956 DCHECK(pending_entry_index_ != -1); |
949 pending_entry_ = entries_[pending_entry_index_].get(); | 957 pending_entry_ = entries_[pending_entry_index_].get(); |
950 } | 958 } |
951 | 959 |
952 if (!tab_contents_->NavigateToPendingEntry(reload)) | 960 if (!tab_contents_->NavigateToPendingEntry(reload_type)) |
953 DiscardNonCommittedEntries(); | 961 DiscardNonCommittedEntries(); |
954 } | 962 } |
955 | 963 |
956 void NavigationController::NotifyNavigationEntryCommitted( | 964 void NavigationController::NotifyNavigationEntryCommitted( |
957 LoadCommittedDetails* details, | 965 LoadCommittedDetails* details, |
958 int extra_invalidate_flags) { | 966 int extra_invalidate_flags) { |
959 details->entry = GetActiveEntry(); | 967 details->entry = GetActiveEntry(); |
960 NotificationDetails notification_details = | 968 NotificationDetails notification_details = |
961 Details<LoadCommittedDetails>(details); | 969 Details<LoadCommittedDetails>(details); |
962 | 970 |
(...skipping 25 matching lines...) Expand all Loading... |
988 } | 996 } |
989 | 997 |
990 void NavigationController::LoadIfNecessary() { | 998 void NavigationController::LoadIfNecessary() { |
991 if (!needs_reload_) | 999 if (!needs_reload_) |
992 return; | 1000 return; |
993 | 1001 |
994 // Calling Reload() results in ignoring state, and not loading. | 1002 // Calling Reload() results in ignoring state, and not loading. |
995 // Explicitly use NavigateToPendingEntry so that the renderer uses the | 1003 // Explicitly use NavigateToPendingEntry so that the renderer uses the |
996 // cached state. | 1004 // cached state. |
997 pending_entry_index_ = last_committed_entry_index_; | 1005 pending_entry_index_ = last_committed_entry_index_; |
998 NavigateToPendingEntry(false); | 1006 NavigateToPendingEntry(NO_RELOAD); |
999 } | 1007 } |
1000 | 1008 |
1001 void NavigationController::NotifyEntryChanged(const NavigationEntry* entry, | 1009 void NavigationController::NotifyEntryChanged(const NavigationEntry* entry, |
1002 int index) { | 1010 int index) { |
1003 EntryChangedDetails det; | 1011 EntryChangedDetails det; |
1004 det.changed_entry = entry; | 1012 det.changed_entry = entry; |
1005 det.index = index; | 1013 det.index = index; |
1006 NotificationService::current()->Notify(NotificationType::NAV_ENTRY_CHANGED, | 1014 NotificationService::current()->Notify(NotificationType::NAV_ENTRY_CHANGED, |
1007 Source<NavigationController>(this), | 1015 Source<NavigationController>(this), |
1008 Details<EntryChangedDetails>(&det)); | 1016 Details<EntryChangedDetails>(&det)); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1044 return i; | 1052 return i; |
1045 } | 1053 } |
1046 return -1; | 1054 return -1; |
1047 } | 1055 } |
1048 | 1056 |
1049 NavigationEntry* NavigationController::GetTransientEntry() const { | 1057 NavigationEntry* NavigationController::GetTransientEntry() const { |
1050 if (transient_entry_index_ == -1) | 1058 if (transient_entry_index_ == -1) |
1051 return NULL; | 1059 return NULL; |
1052 return entries_[transient_entry_index_].get(); | 1060 return entries_[transient_entry_index_].get(); |
1053 } | 1061 } |
OLD | NEW |