| 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" |
| 11 #include "base/utf_string_conversions.h" | 11 #include "base/utf_string_conversions.h" |
| 12 #include "chrome/browser/profiles/profile.h" | 12 #include "content/browser/browser_context.h" |
| 13 #include "content/browser/browser_url_handler.h" | 13 #include "content/browser/browser_url_handler.h" |
| 14 #include "content/browser/child_process_security_policy.h" | 14 #include "content/browser/child_process_security_policy.h" |
| 15 #include "content/browser/in_process_webkit/session_storage_namespace.h" | 15 #include "content/browser/in_process_webkit/session_storage_namespace.h" |
| 16 #include "content/browser/site_instance.h" | 16 #include "content/browser/site_instance.h" |
| 17 #include "content/browser/tab_contents/interstitial_page.h" | 17 #include "content/browser/tab_contents/interstitial_page.h" |
| 18 #include "content/browser/tab_contents/navigation_details.h" | 18 #include "content/browser/tab_contents/navigation_details.h" |
| 19 #include "content/browser/tab_contents/navigation_entry.h" | 19 #include "content/browser/tab_contents/navigation_entry.h" |
| 20 #include "content/browser/tab_contents/tab_contents.h" | 20 #include "content/browser/tab_contents/tab_contents.h" |
| 21 #include "content/browser/tab_contents/tab_contents_delegate.h" | 21 #include "content/browser/tab_contents/tab_contents_delegate.h" |
| 22 #include "content/common/content_constants.h" | 22 #include "content/common/content_constants.h" |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 | 102 |
| 103 // static | 103 // static |
| 104 size_t NavigationController::max_entry_count_ = | 104 size_t NavigationController::max_entry_count_ = |
| 105 content::kMaxSessionHistoryEntries; | 105 content::kMaxSessionHistoryEntries; |
| 106 | 106 |
| 107 // static | 107 // static |
| 108 bool NavigationController::check_for_repost_ = true; | 108 bool NavigationController::check_for_repost_ = true; |
| 109 | 109 |
| 110 NavigationController::NavigationController( | 110 NavigationController::NavigationController( |
| 111 TabContents* contents, | 111 TabContents* contents, |
| 112 Profile* profile, | 112 content::BrowserContext* browser_context, |
| 113 SessionStorageNamespace* session_storage_namespace) | 113 SessionStorageNamespace* session_storage_namespace) |
| 114 : profile_(profile), | 114 : browser_context_(browser_context), |
| 115 pending_entry_(NULL), | 115 pending_entry_(NULL), |
| 116 last_committed_entry_index_(-1), | 116 last_committed_entry_index_(-1), |
| 117 pending_entry_index_(-1), | 117 pending_entry_index_(-1), |
| 118 transient_entry_index_(-1), | 118 transient_entry_index_(-1), |
| 119 tab_contents_(contents), | 119 tab_contents_(contents), |
| 120 max_restored_page_id_(-1), | 120 max_restored_page_id_(-1), |
| 121 ALLOW_THIS_IN_INITIALIZER_LIST(ssl_manager_(this)), | 121 ALLOW_THIS_IN_INITIALIZER_LIST(ssl_manager_(this)), |
| 122 needs_reload_(false), | 122 needs_reload_(false), |
| 123 session_storage_namespace_(session_storage_namespace), | 123 session_storage_namespace_(session_storage_namespace), |
| 124 pending_reload_(NO_RELOAD) { | 124 pending_reload_(NO_RELOAD) { |
| 125 DCHECK(profile_); | 125 DCHECK(browser_context_); |
| 126 if (!session_storage_namespace_) { | 126 if (!session_storage_namespace_) { |
| 127 session_storage_namespace_ = new SessionStorageNamespace( | 127 session_storage_namespace_ = new SessionStorageNamespace( |
| 128 profile_->GetWebKitContext()); | 128 browser_context_->GetWebKitContext()); |
| 129 } | 129 } |
| 130 } | 130 } |
| 131 | 131 |
| 132 NavigationController::~NavigationController() { | 132 NavigationController::~NavigationController() { |
| 133 DiscardNonCommittedEntriesInternal(); | 133 DiscardNonCommittedEntriesInternal(); |
| 134 | 134 |
| 135 NotificationService::current()->Notify( | 135 NotificationService::current()->Notify( |
| 136 content::NOTIFICATION_TAB_CLOSED, | 136 content::NOTIFICATION_TAB_CLOSED, |
| 137 Source<NavigationController>(this), | 137 Source<NavigationController>(this), |
| 138 NotificationService::NoDetails()); | 138 NotificationService::NoDetails()); |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 213 } | 213 } |
| 214 } | 214 } |
| 215 | 215 |
| 216 bool NavigationController::IsInitialNavigation() { | 216 bool NavigationController::IsInitialNavigation() { |
| 217 return last_document_loaded_.is_null(); | 217 return last_document_loaded_.is_null(); |
| 218 } | 218 } |
| 219 | 219 |
| 220 // static | 220 // static |
| 221 NavigationEntry* NavigationController::CreateNavigationEntry( | 221 NavigationEntry* NavigationController::CreateNavigationEntry( |
| 222 const GURL& url, const GURL& referrer, PageTransition::Type transition, | 222 const GURL& url, const GURL& referrer, PageTransition::Type transition, |
| 223 Profile* profile) { | 223 content::BrowserContext* context) { |
| 224 // Allow the browser URL handler to rewrite the URL. This will, for example, | 224 // Allow the browser URL handler to rewrite the URL. This will, for example, |
| 225 // remove "view-source:" from the beginning of the URL to get the URL that | 225 // remove "view-source:" from the beginning of the URL to get the URL that |
| 226 // will actually be loaded. This real URL won't be shown to the user, just | 226 // will actually be loaded. This real URL won't be shown to the user, just |
| 227 // used internally. | 227 // used internally. |
| 228 GURL loaded_url(url); | 228 GURL loaded_url(url); |
| 229 bool reverse_on_redirect = false; | 229 bool reverse_on_redirect = false; |
| 230 BrowserURLHandler::GetInstance()->RewriteURLIfNecessary( | 230 BrowserURLHandler::GetInstance()->RewriteURLIfNecessary( |
| 231 &loaded_url, profile, &reverse_on_redirect); | 231 &loaded_url, context, &reverse_on_redirect); |
| 232 | 232 |
| 233 NavigationEntry* entry = new NavigationEntry( | 233 NavigationEntry* entry = new NavigationEntry( |
| 234 NULL, // The site instance for tabs is sent on navigation | 234 NULL, // The site instance for tabs is sent on navigation |
| 235 // (TabContents::GetSiteInstance). | 235 // (TabContents::GetSiteInstance). |
| 236 -1, | 236 -1, |
| 237 loaded_url, | 237 loaded_url, |
| 238 referrer, | 238 referrer, |
| 239 string16(), | 239 string16(), |
| 240 transition); | 240 transition); |
| 241 entry->set_virtual_url(url); | 241 entry->set_virtual_url(url); |
| (...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 448 LoadURL(default_url.is_empty() ? GURL("about:blank") : default_url, | 448 LoadURL(default_url.is_empty() ? GURL("about:blank") : default_url, |
| 449 GURL(), PageTransition::START_PAGE); | 449 GURL(), PageTransition::START_PAGE); |
| 450 } | 450 } |
| 451 } | 451 } |
| 452 } | 452 } |
| 453 | 453 |
| 454 void NavigationController::UpdateVirtualURLToURL( | 454 void NavigationController::UpdateVirtualURLToURL( |
| 455 NavigationEntry* entry, const GURL& new_url) { | 455 NavigationEntry* entry, const GURL& new_url) { |
| 456 GURL new_virtual_url(new_url); | 456 GURL new_virtual_url(new_url); |
| 457 if (BrowserURLHandler::GetInstance()->ReverseURLRewrite( | 457 if (BrowserURLHandler::GetInstance()->ReverseURLRewrite( |
| 458 &new_virtual_url, entry->virtual_url(), profile_)) { | 458 &new_virtual_url, entry->virtual_url(), browser_context_)) { |
| 459 entry->set_virtual_url(new_virtual_url); | 459 entry->set_virtual_url(new_virtual_url); |
| 460 } | 460 } |
| 461 } | 461 } |
| 462 | 462 |
| 463 void NavigationController::AddTransientEntry(NavigationEntry* entry) { | 463 void NavigationController::AddTransientEntry(NavigationEntry* entry) { |
| 464 // Discard any current transient entry, we can only have one at a time. | 464 // Discard any current transient entry, we can only have one at a time. |
| 465 int index = 0; | 465 int index = 0; |
| 466 if (last_committed_entry_index_ != -1) | 466 if (last_committed_entry_index_ != -1) |
| 467 index = last_committed_entry_index_ + 1; | 467 index = last_committed_entry_index_ + 1; |
| 468 DiscardTransientEntry(); | 468 DiscardTransientEntry(); |
| 469 entries_.insert(entries_.begin() + index, linked_ptr<NavigationEntry>(entry)); | 469 entries_.insert(entries_.begin() + index, linked_ptr<NavigationEntry>(entry)); |
| 470 transient_entry_index_ = index; | 470 transient_entry_index_ = index; |
| 471 tab_contents_->NotifyNavigationStateChanged(kInvalidateAll); | 471 tab_contents_->NotifyNavigationStateChanged(kInvalidateAll); |
| 472 } | 472 } |
| 473 | 473 |
| 474 void NavigationController::LoadURL(const GURL& url, const GURL& referrer, | 474 void NavigationController::LoadURL(const GURL& url, const GURL& referrer, |
| 475 PageTransition::Type transition) { | 475 PageTransition::Type transition) { |
| 476 // The user initiated a load, we don't need to reload anymore. | 476 // The user initiated a load, we don't need to reload anymore. |
| 477 needs_reload_ = false; | 477 needs_reload_ = false; |
| 478 | 478 |
| 479 NavigationEntry* entry = CreateNavigationEntry(url, referrer, transition, | 479 NavigationEntry* entry = CreateNavigationEntry(url, referrer, transition, |
| 480 profile_); | 480 browser_context_); |
| 481 | 481 |
| 482 LoadEntry(entry); | 482 LoadEntry(entry); |
| 483 } | 483 } |
| 484 | 484 |
| 485 void NavigationController::DocumentLoadedInFrame() { | 485 void NavigationController::DocumentLoadedInFrame() { |
| 486 last_document_loaded_ = base::TimeTicks::Now(); | 486 last_document_loaded_ = base::TimeTicks::Now(); |
| 487 } | 487 } |
| 488 | 488 |
| 489 bool NavigationController::RendererDidNavigate( | 489 bool NavigationController::RendererDidNavigate( |
| 490 const ViewHostMsg_FrameNavigate_Params& params, | 490 const ViewHostMsg_FrameNavigate_Params& params, |
| (...skipping 664 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1155 size_t insert_index = 0; | 1155 size_t insert_index = 0; |
| 1156 for (int i = 0; i < max_index; i++) { | 1156 for (int i = 0; i < max_index; i++) { |
| 1157 // When cloning a tab, copy all entries except interstitial pages | 1157 // When cloning a tab, copy all entries except interstitial pages |
| 1158 if (source.entries_[i].get()->page_type() != INTERSTITIAL_PAGE) { | 1158 if (source.entries_[i].get()->page_type() != INTERSTITIAL_PAGE) { |
| 1159 entries_.insert(entries_.begin() + insert_index++, | 1159 entries_.insert(entries_.begin() + insert_index++, |
| 1160 linked_ptr<NavigationEntry>( | 1160 linked_ptr<NavigationEntry>( |
| 1161 new NavigationEntry(*source.entries_[i]))); | 1161 new NavigationEntry(*source.entries_[i]))); |
| 1162 } | 1162 } |
| 1163 } | 1163 } |
| 1164 } | 1164 } |
| OLD | NEW |