| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/tab_contents/navigation_controller.h" | 5 #include "content/browser/tab_contents/navigation_controller.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_util.h" | 9 #include "base/string_util.h" |
| 10 #include "base/time.h" | 10 #include "base/time.h" |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 214 } | 214 } |
| 215 } | 215 } |
| 216 | 216 |
| 217 bool NavigationController::IsInitialNavigation() { | 217 bool NavigationController::IsInitialNavigation() { |
| 218 return last_document_loaded_.is_null(); | 218 return last_document_loaded_.is_null(); |
| 219 } | 219 } |
| 220 | 220 |
| 221 // static | 221 // static |
| 222 NavigationEntry* NavigationController::CreateNavigationEntry( | 222 NavigationEntry* NavigationController::CreateNavigationEntry( |
| 223 const GURL& url, const GURL& referrer, PageTransition::Type transition, | 223 const GURL& url, const GURL& referrer, PageTransition::Type transition, |
| 224 const std::string& extra_headers, |
| 224 content::BrowserContext* browser_context) { | 225 content::BrowserContext* browser_context) { |
| 225 // Allow the browser URL handler to rewrite the URL. This will, for example, | 226 // Allow the browser URL handler to rewrite the URL. This will, for example, |
| 226 // remove "view-source:" from the beginning of the URL to get the URL that | 227 // remove "view-source:" from the beginning of the URL to get the URL that |
| 227 // will actually be loaded. This real URL won't be shown to the user, just | 228 // will actually be loaded. This real URL won't be shown to the user, just |
| 228 // used internally. | 229 // used internally. |
| 229 GURL loaded_url(url); | 230 GURL loaded_url(url); |
| 230 bool reverse_on_redirect = false; | 231 bool reverse_on_redirect = false; |
| 231 BrowserURLHandler::GetInstance()->RewriteURLIfNecessary( | 232 BrowserURLHandler::GetInstance()->RewriteURLIfNecessary( |
| 232 &loaded_url, browser_context, &reverse_on_redirect); | 233 &loaded_url, browser_context, &reverse_on_redirect); |
| 233 | 234 |
| 234 NavigationEntry* entry = new NavigationEntry( | 235 NavigationEntry* entry = new NavigationEntry( |
| 235 NULL, // The site instance for tabs is sent on navigation | 236 NULL, // The site instance for tabs is sent on navigation |
| 236 // (TabContents::GetSiteInstance). | 237 // (TabContents::GetSiteInstance). |
| 237 -1, | 238 -1, |
| 238 loaded_url, | 239 loaded_url, |
| 239 referrer, | 240 referrer, |
| 240 string16(), | 241 string16(), |
| 241 transition); | 242 transition); |
| 242 entry->set_virtual_url(url); | 243 entry->set_virtual_url(url); |
| 243 entry->set_user_typed_url(url); | 244 entry->set_user_typed_url(url); |
| 244 entry->set_update_virtual_url_with_url(reverse_on_redirect); | 245 entry->set_update_virtual_url_with_url(reverse_on_redirect); |
| 246 entry->set_extra_headers(extra_headers); |
| 245 return entry; | 247 return entry; |
| 246 } | 248 } |
| 247 | 249 |
| 248 NavigationEntry* NavigationController::GetEntryWithPageID( | 250 NavigationEntry* NavigationController::GetEntryWithPageID( |
| 249 SiteInstance* instance, int32 page_id) const { | 251 SiteInstance* instance, int32 page_id) const { |
| 250 int index = GetEntryIndexWithPageID(instance, page_id); | 252 int index = GetEntryIndexWithPageID(instance, page_id); |
| 251 return (index != -1) ? entries_[index].get() : NULL; | 253 return (index != -1) ? entries_[index].get() : NULL; |
| 252 } | 254 } |
| 253 | 255 |
| 254 void NavigationController::LoadEntry(NavigationEntry* entry) { | 256 void NavigationController::LoadEntry(NavigationEntry* entry) { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 266 } | 268 } |
| 267 | 269 |
| 268 // When navigating to a new page, we don't know for sure if we will actually | 270 // When navigating to a new page, we don't know for sure if we will actually |
| 269 // end up leaving the current page. The new page load could for example | 271 // end up leaving the current page. The new page load could for example |
| 270 // result in a download or a 'no content' response (e.g., a mailto: URL). | 272 // result in a download or a 'no content' response (e.g., a mailto: URL). |
| 271 DiscardNonCommittedEntriesInternal(); | 273 DiscardNonCommittedEntriesInternal(); |
| 272 pending_entry_ = entry; | 274 pending_entry_ = entry; |
| 273 NotificationService::current()->Notify( | 275 NotificationService::current()->Notify( |
| 274 content::NOTIFICATION_NAV_ENTRY_PENDING, | 276 content::NOTIFICATION_NAV_ENTRY_PENDING, |
| 275 Source<NavigationController>(this), | 277 Source<NavigationController>(this), |
| 276 NotificationService::NoDetails()); | 278 Details<NavigationEntry>(entry)); |
| 277 NavigateToPendingEntry(NO_RELOAD); | 279 NavigateToPendingEntry(NO_RELOAD); |
| 278 } | 280 } |
| 279 | 281 |
| 280 NavigationEntry* NavigationController::GetActiveEntry() const { | 282 NavigationEntry* NavigationController::GetActiveEntry() const { |
| 281 if (transient_entry_index_ != -1) | 283 if (transient_entry_index_ != -1) |
| 282 return entries_[transient_entry_index_].get(); | 284 return entries_[transient_entry_index_].get(); |
| 283 if (pending_entry_) | 285 if (pending_entry_) |
| 284 return pending_entry_; | 286 return pending_entry_; |
| 285 return GetLastCommittedEntry(); | 287 return GetLastCommittedEntry(); |
| 286 } | 288 } |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 476 if (last_committed_entry_index_ != -1) | 478 if (last_committed_entry_index_ != -1) |
| 477 index = last_committed_entry_index_ + 1; | 479 index = last_committed_entry_index_ + 1; |
| 478 DiscardTransientEntry(); | 480 DiscardTransientEntry(); |
| 479 entries_.insert(entries_.begin() + index, linked_ptr<NavigationEntry>(entry)); | 481 entries_.insert(entries_.begin() + index, linked_ptr<NavigationEntry>(entry)); |
| 480 transient_entry_index_ = index; | 482 transient_entry_index_ = index; |
| 481 tab_contents_->NotifyNavigationStateChanged(kInvalidateAll); | 483 tab_contents_->NotifyNavigationStateChanged(kInvalidateAll); |
| 482 } | 484 } |
| 483 | 485 |
| 484 void NavigationController::LoadURL(const GURL& url, const GURL& referrer, | 486 void NavigationController::LoadURL(const GURL& url, const GURL& referrer, |
| 485 PageTransition::Type transition) { | 487 PageTransition::Type transition) { |
| 488 LoadURLWithHeaders(url, referrer, transition, std::string()); |
| 489 } |
| 490 |
| 491 // TODO(rogerta): Remove this call and put the extra_headers argument directly |
| 492 // in LoadURL(). |
| 493 void NavigationController::LoadURLWithHeaders( |
| 494 const GURL& url, |
| 495 const GURL& referrer, |
| 496 PageTransition::Type transition, |
| 497 const std::string& extra_headers) { |
| 486 // The user initiated a load, we don't need to reload anymore. | 498 // The user initiated a load, we don't need to reload anymore. |
| 487 needs_reload_ = false; | 499 needs_reload_ = false; |
| 488 | 500 |
| 489 NavigationEntry* entry = CreateNavigationEntry(url, referrer, transition, | 501 NavigationEntry* entry = CreateNavigationEntry(url, referrer, transition, |
| 502 extra_headers, |
| 490 browser_context_); | 503 browser_context_); |
| 491 | 504 |
| 492 LoadEntry(entry); | 505 LoadEntry(entry); |
| 493 } | 506 } |
| 494 | 507 |
| 495 void NavigationController::DocumentLoadedInFrame() { | 508 void NavigationController::DocumentLoadedInFrame() { |
| 496 last_document_loaded_ = base::TimeTicks::Now(); | 509 last_document_loaded_ = base::TimeTicks::Now(); |
| 497 } | 510 } |
| 498 | 511 |
| 499 bool NavigationController::RendererDidNavigate( | 512 bool NavigationController::RendererDidNavigate( |
| (...skipping 699 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1199 size_t insert_index = 0; | 1212 size_t insert_index = 0; |
| 1200 for (int i = 0; i < max_index; i++) { | 1213 for (int i = 0; i < max_index; i++) { |
| 1201 // When cloning a tab, copy all entries except interstitial pages | 1214 // When cloning a tab, copy all entries except interstitial pages |
| 1202 if (source.entries_[i].get()->page_type() != INTERSTITIAL_PAGE) { | 1215 if (source.entries_[i].get()->page_type() != INTERSTITIAL_PAGE) { |
| 1203 entries_.insert(entries_.begin() + insert_index++, | 1216 entries_.insert(entries_.begin() + insert_index++, |
| 1204 linked_ptr<NavigationEntry>( | 1217 linked_ptr<NavigationEntry>( |
| 1205 new NavigationEntry(*source.entries_[i]))); | 1218 new NavigationEntry(*source.entries_[i]))); |
| 1206 } | 1219 } |
| 1207 } | 1220 } |
| 1208 } | 1221 } |
| OLD | NEW |