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