| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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/navigation_controller.h" | 5 #include "chrome/browser/navigation_controller.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.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 for (std::vector<TabNavigation>::const_iterator i = | 139 for (std::vector<TabNavigation>::const_iterator i = |
| 140 navigations.begin(); i != navigations.end(); ++i) { | 140 navigations.begin(); i != navigations.end(); ++i) { |
| 141 const TabNavigation& navigation = *i; | 141 const TabNavigation& navigation = *i; |
| 142 | 142 |
| 143 GURL real_url = navigation.url; | 143 GURL real_url = navigation.url; |
| 144 TabContentsType type = TabContents::TypeForURL(&real_url); | 144 TabContentsType type = TabContents::TypeForURL(&real_url); |
| 145 DCHECK(type != TAB_CONTENTS_UNKNOWN_TYPE); | 145 DCHECK(type != TAB_CONTENTS_UNKNOWN_TYPE); |
| 146 | 146 |
| 147 NavigationEntry* entry = new NavigationEntry( | 147 NavigationEntry* entry = new NavigationEntry( |
| 148 type, | 148 type, |
| 149 NULL, // The site instance for restored tabs is sent on naviagion | 149 NULL, // The site instance for restored tabs is sent on naviagtion |
| 150 // (WebContents::GetSiteInstanceForEntry). | 150 // (WebContents::GetSiteInstanceForEntry). |
| 151 static_cast<int>(i - navigations.begin()), | 151 static_cast<int>(i - navigations.begin()), |
| 152 real_url, | 152 real_url, |
| 153 GURL(), // TODO(eroman): should pass actual referrer. |
| 153 navigation.title, | 154 navigation.title, |
| 154 // Use a transition type of reload so that we don't incorrectly | 155 // Use a transition type of reload so that we don't incorrectly |
| 155 // increase the typed count. | 156 // increase the typed count. |
| 156 PageTransition::RELOAD); | 157 PageTransition::RELOAD); |
| 157 entry->set_display_url(navigation.url); | 158 entry->set_display_url(navigation.url); |
| 158 entry->set_content_state(navigation.state); | 159 entry->set_content_state(navigation.state); |
| 159 entry->set_has_post_data( | 160 entry->set_has_post_data( |
| 160 navigation.type_mask & TabNavigation::HAS_POST_DATA); | 161 navigation.type_mask & TabNavigation::HAS_POST_DATA); |
| 161 entries->push_back(linked_ptr<NavigationEntry>(entry)); | 162 entries->push_back(linked_ptr<NavigationEntry>(entry)); |
| 162 } | 163 } |
| (...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 401 | 402 |
| 402 if (last_committed_entry_index_ == index) { | 403 if (last_committed_entry_index_ == index) { |
| 403 last_committed_entry_index_--; | 404 last_committed_entry_index_--; |
| 404 // We removed the currently shown entry, so we have to load something else. | 405 // We removed the currently shown entry, so we have to load something else. |
| 405 if (last_committed_entry_index_ != -1) { | 406 if (last_committed_entry_index_ != -1) { |
| 406 pending_entry_index_ = last_committed_entry_index_; | 407 pending_entry_index_ = last_committed_entry_index_; |
| 407 NavigateToPendingEntry(false); | 408 NavigateToPendingEntry(false); |
| 408 } else { | 409 } else { |
| 409 // If there is nothing to show, show a default page. | 410 // If there is nothing to show, show a default page. |
| 410 LoadURL(default_url.is_empty() ? GURL("about:blank") : default_url, | 411 LoadURL(default_url.is_empty() ? GURL("about:blank") : default_url, |
| 411 PageTransition::START_PAGE); | 412 GURL(), PageTransition::START_PAGE); |
| 412 } | 413 } |
| 413 } else if (last_committed_entry_index_ > index) { | 414 } else if (last_committed_entry_index_ > index) { |
| 414 last_committed_entry_index_--; | 415 last_committed_entry_index_--; |
| 415 } | 416 } |
| 416 } | 417 } |
| 417 | 418 |
| 418 void NavigationController::Destroy() { | 419 void NavigationController::Destroy() { |
| 419 // Close all tab contents owned by this controller. We make a list on the | 420 // Close all tab contents owned by this controller. We make a list on the |
| 420 // stack because they are removed from the map as they are Destroyed | 421 // stack because they are removed from the map as they are Destroyed |
| 421 // (invalidating the iterators), which may or may not occur synchronously. | 422 // (invalidating the iterators), which may or may not occur synchronously. |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 470 | 471 |
| 471 // Make sure we cancel any collector for that TabContents. | 472 // Make sure we cancel any collector for that TabContents. |
| 472 CancelTabContentsCollection(type); | 473 CancelTabContentsCollection(type); |
| 473 | 474 |
| 474 // If that was the last tab to be destroyed, delete ourselves. | 475 // If that was the last tab to be destroyed, delete ourselves. |
| 475 if (tab_contents_map_.empty()) | 476 if (tab_contents_map_.empty()) |
| 476 delete this; | 477 delete this; |
| 477 } | 478 } |
| 478 | 479 |
| 479 NavigationEntry* NavigationController::CreateNavigationEntry( | 480 NavigationEntry* NavigationController::CreateNavigationEntry( |
| 480 const GURL& url, PageTransition::Type transition) { | 481 const GURL& url, const GURL& referrer, PageTransition::Type transition) { |
| 481 GURL real_url = url; | 482 GURL real_url = url; |
| 482 TabContentsType type; | 483 TabContentsType type; |
| 483 | 484 |
| 484 // If the active contents supports |url|, use it. | 485 // If the active contents supports |url|, use it. |
| 485 // Note: in both cases, we give TabContents a chance to rewrite the URL. | 486 // Note: in both cases, we give TabContents a chance to rewrite the URL. |
| 486 TabContents* active = active_contents(); | 487 TabContents* active = active_contents(); |
| 487 if (active && active->SupportsURL(&real_url)) | 488 if (active && active->SupportsURL(&real_url)) |
| 488 type = active->type(); | 489 type = active->type(); |
| 489 else | 490 else |
| 490 type = TabContents::TypeForURL(&real_url); | 491 type = TabContents::TypeForURL(&real_url); |
| 491 | 492 |
| 492 NavigationEntry* entry = new NavigationEntry(type, NULL, -1, real_url, | 493 NavigationEntry* entry = new NavigationEntry(type, NULL, -1, real_url, |
| 494 referrer, |
| 493 std::wstring(), transition); | 495 std::wstring(), transition); |
| 494 entry->set_display_url(url); | 496 entry->set_display_url(url); |
| 495 entry->set_user_typed_url(url); | 497 entry->set_user_typed_url(url); |
| 496 if (url.SchemeIsFile()) { | 498 if (url.SchemeIsFile()) { |
| 497 entry->set_title(file_util::GetFilenameFromPath(UTF8ToWide(url.host() + | 499 entry->set_title(file_util::GetFilenameFromPath(UTF8ToWide(url.host() + |
| 498 url.path()))); | 500 url.path()))); |
| 499 } | 501 } |
| 500 return entry; | 502 return entry; |
| 501 } | 503 } |
| 502 | 504 |
| 503 void NavigationController::AddTransientEntry(NavigationEntry* entry) { | 505 void NavigationController::AddTransientEntry(NavigationEntry* entry) { |
| 504 // Discard any current transient entry, we can only have one at a time. | 506 // Discard any current transient entry, we can only have one at a time. |
| 505 int index = 0; | 507 int index = 0; |
| 506 if (last_committed_entry_index_ != -1) | 508 if (last_committed_entry_index_ != -1) |
| 507 index = last_committed_entry_index_ + 1; | 509 index = last_committed_entry_index_ + 1; |
| 508 DiscardTransientEntry(); | 510 DiscardTransientEntry(); |
| 509 entries_.insert(entries_.begin() + index, linked_ptr<NavigationEntry>(entry)); | 511 entries_.insert(entries_.begin() + index, linked_ptr<NavigationEntry>(entry)); |
| 510 transient_entry_index_ = index; | 512 transient_entry_index_ = index; |
| 511 active_contents_->NotifyNavigationStateChanged( | 513 active_contents_->NotifyNavigationStateChanged( |
| 512 TabContents::INVALIDATE_EVERYTHING); | 514 TabContents::INVALIDATE_EVERYTHING); |
| 513 } | 515 } |
| 514 | 516 |
| 515 void NavigationController::LoadURL(const GURL& url, | 517 void NavigationController::LoadURL(const GURL& url, const GURL& referrer, |
| 516 PageTransition::Type transition) { | 518 PageTransition::Type transition) { |
| 517 // The user initiated a load, we don't need to reload anymore. | 519 // The user initiated a load, we don't need to reload anymore. |
| 518 needs_reload_ = false; | 520 needs_reload_ = false; |
| 519 | 521 |
| 520 NavigationEntry* entry = CreateNavigationEntry(url, transition); | 522 NavigationEntry* entry = CreateNavigationEntry(url, referrer, transition); |
| 521 | 523 |
| 522 LoadEntry(entry); | 524 LoadEntry(entry); |
| 523 } | 525 } |
| 524 | 526 |
| 525 void NavigationController::LoadURLLazily(const GURL& url, | 527 void NavigationController::LoadURLLazily(const GURL& url, |
| 528 const GURL& referrer, |
| 526 PageTransition::Type type, | 529 PageTransition::Type type, |
| 527 const std::wstring& title, | 530 const std::wstring& title, |
| 528 SkBitmap* icon) { | 531 SkBitmap* icon) { |
| 529 NavigationEntry* entry = CreateNavigationEntry(url, type); | 532 NavigationEntry* entry = CreateNavigationEntry(url, referrer, type); |
| 530 entry->set_title(title); | 533 entry->set_title(title); |
| 531 if (icon) | 534 if (icon) |
| 532 entry->favicon().set_bitmap(*icon); | 535 entry->favicon().set_bitmap(*icon); |
| 533 | 536 |
| 534 DiscardNonCommittedEntriesInternal(); | 537 DiscardNonCommittedEntriesInternal(); |
| 535 pending_entry_ = entry; | 538 pending_entry_ = entry; |
| 536 load_pending_entry_when_active_ = true; | 539 load_pending_entry_when_active_ = true; |
| 537 } | 540 } |
| 538 | 541 |
| 539 bool NavigationController::LoadingURLLazily() { | 542 bool NavigationController::LoadingURLLazily() { |
| (...skipping 701 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1241 return i; | 1244 return i; |
| 1242 } | 1245 } |
| 1243 return -1; | 1246 return -1; |
| 1244 } | 1247 } |
| 1245 | 1248 |
| 1246 NavigationEntry* NavigationController::GetTransientEntry() const { | 1249 NavigationEntry* NavigationController::GetTransientEntry() const { |
| 1247 if (transient_entry_index_ == -1) | 1250 if (transient_entry_index_ == -1) |
| 1248 return NULL; | 1251 return NULL; |
| 1249 return entries_[transient_entry_index_].get(); | 1252 return entries_[transient_entry_index_].get(); |
| 1250 } | 1253 } |
| OLD | NEW |