| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/instant/instant_controller.h" | 5 #include "chrome/browser/instant/instant_controller.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/i18n/case_conversion.h" | 8 #include "base/i18n/case_conversion.h" |
| 9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
| 10 #include "base/time.h" |
| 10 #include "base/utf_string_conversions.h" | 11 #include "base/utf_string_conversions.h" |
| 11 #include "chrome/browser/autocomplete/autocomplete_provider.h" | 12 #include "chrome/browser/autocomplete/autocomplete_provider.h" |
| 12 #include "chrome/browser/favicon/favicon_service_factory.h" | 13 #include "chrome/browser/favicon/favicon_service_factory.h" |
| 13 #include "chrome/browser/history/history.h" | 14 #include "chrome/browser/history/history.h" |
| 14 #include "chrome/browser/history/history_service_factory.h" | 15 #include "chrome/browser/history/history_service_factory.h" |
| 15 #include "chrome/browser/history/history_tab_helper.h" | 16 #include "chrome/browser/history/history_tab_helper.h" |
| 16 #include "chrome/browser/instant/instant_controller_delegate.h" | 17 #include "chrome/browser/instant/instant_controller_delegate.h" |
| 17 #include "chrome/browser/instant/instant_loader.h" | 18 #include "chrome/browser/instant/instant_loader.h" |
| 18 #include "chrome/browser/platform_util.h" | 19 #include "chrome/browser/platform_util.h" |
| 19 #include "chrome/browser/prefs/pref_service.h" | 20 #include "chrome/browser/prefs/pref_service.h" |
| (...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 339 | 340 |
| 340 return preview; | 341 return preview; |
| 341 } | 342 } |
| 342 | 343 |
| 343 TabContents* InstantController::ReleasePreviewContents(InstantCommitType type) { | 344 TabContents* InstantController::ReleasePreviewContents(InstantCommitType type) { |
| 344 TabContents* preview = loader_->ReleasePreviewContents(type, last_full_text_); | 345 TabContents* preview = loader_->ReleasePreviewContents(type, last_full_text_); |
| 345 | 346 |
| 346 // If the preview page has navigated since the last Update(), we need to add | 347 // If the preview page has navigated since the last Update(), we need to add |
| 347 // the navigation to history ourselves. Else, the page will navigate after | 348 // the navigation to history ourselves. Else, the page will navigate after |
| 348 // commit, and it will be added to history in the usual manner. | 349 // commit, and it will be added to history in the usual manner. |
| 349 scoped_refptr<history::HistoryAddPageArgs> last_navigation = | 350 const history::HistoryAddPageArgs& last_navigation = |
| 350 loader_->last_navigation(); | 351 loader_->last_navigation(); |
| 351 if (last_navigation != NULL) { | 352 if (!last_navigation.url.is_empty()) { |
| 352 content::NavigationEntry* entry = | 353 content::NavigationEntry* entry = |
| 353 preview->web_contents()->GetController().GetActiveEntry(); | 354 preview->web_contents()->GetController().GetActiveEntry(); |
| 354 DCHECK_EQ(last_navigation->url, entry->GetURL()); | 355 DCHECK_EQ(last_navigation.url, entry->GetURL()); |
| 355 | 356 |
| 356 // Add the page to history. | 357 // Add the page to history. |
| 357 preview->history_tab_helper()->UpdateHistoryForNavigation(last_navigation); | 358 preview->history_tab_helper()->UpdateHistoryForNavigation(last_navigation); |
| 358 | 359 |
| 359 // Update the page title. | 360 // Update the page title. |
| 360 preview->history_tab_helper()->UpdateHistoryPageTitle(*entry); | 361 preview->history_tab_helper()->UpdateHistoryPageTitle(*entry); |
| 361 | 362 |
| 362 // Update the favicon. | 363 // Update the favicon. |
| 363 FaviconService* favicon_service = FaviconServiceFactory::GetForProfile( | 364 FaviconService* favicon_service = FaviconServiceFactory::GetForProfile( |
| 364 preview->profile(), Profile::EXPLICIT_ACCESS); | 365 preview->profile(), Profile::EXPLICIT_ACCESS); |
| 365 if (favicon_service && entry->GetFavicon().valid && | 366 if (favicon_service && entry->GetFavicon().valid && |
| 366 entry->GetFavicon().image.IsEmpty()) { | 367 entry->GetFavicon().image.IsEmpty()) { |
| 367 favicon_service->SetFavicons(entry->GetURL(), entry->GetFavicon().url, | 368 favicon_service->SetFavicons(entry->GetURL(), entry->GetFavicon().url, |
| 368 history::FAVICON, entry->GetFavicon().image); | 369 history::FAVICON, entry->GetFavicon().image); |
| 369 } | 370 } |
| 370 } | 371 } |
| 371 | 372 |
| 372 // Add a fake history entry with a non-Instant search URL, so that search | 373 // Add a fake history entry with a non-Instant search URL, so that search |
| 373 // terms extraction (for autocomplete history matches) works. | 374 // terms extraction (for autocomplete history matches) works. |
| 374 HistoryService* history = HistoryServiceFactory::GetForProfile( | 375 HistoryService* history = HistoryServiceFactory::GetForProfile( |
| 375 preview->profile(), Profile::EXPLICIT_ACCESS); | 376 preview->profile(), Profile::EXPLICIT_ACCESS); |
| 376 if (history) { | 377 if (history) { |
| 377 history->AddPage(url_for_history_, NULL, 0, GURL(), last_transition_type_, | 378 history->AddPage(url_for_history_, base::Time::Now(), NULL, 0, GURL(), |
| 378 history::RedirectList(), history::SOURCE_BROWSED, false); | 379 history::RedirectList(), last_transition_type_, |
| 380 history::SOURCE_BROWSED, false); |
| 379 } | 381 } |
| 380 | 382 |
| 381 AddPreviewUsageForHistogram(mode_, PREVIEW_COMMITTED); | 383 AddPreviewUsageForHistogram(mode_, PREVIEW_COMMITTED); |
| 382 | 384 |
| 383 // We may have gotten here from CommitInstant(), which means the loader may | 385 // We may have gotten here from CommitInstant(), which means the loader may |
| 384 // still be on the stack. So, schedule a destruction for later. | 386 // still be on the stack. So, schedule a destruction for later. |
| 385 MessageLoop::current()->DeleteSoon(FROM_HERE, loader_.release()); | 387 MessageLoop::current()->DeleteSoon(FROM_HERE, loader_.release()); |
| 386 | 388 |
| 387 // This call is here to hide the preview and reset view state. It won't | 389 // This call is here to hide the preview and reset view state. It won't |
| 388 // actually delete |loader_| because it was just released to DeleteSoon(). | 390 // actually delete |loader_| because it was just released to DeleteSoon(). |
| (...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 784 DCHECK(url_obj.is_valid()); | 786 DCHECK(url_obj.is_valid()); |
| 785 *instant_url = url_obj.spec(); | 787 *instant_url = url_obj.spec(); |
| 786 } | 788 } |
| 787 } | 789 } |
| 788 } | 790 } |
| 789 | 791 |
| 790 bool InstantController::IsOutOfDate() const { | 792 bool InstantController::IsOutOfDate() const { |
| 791 return !last_active_tab_ || | 793 return !last_active_tab_ || |
| 792 last_active_tab_ != delegate_->GetActiveTabContents(); | 794 last_active_tab_ != delegate_->GetActiveTabContents(); |
| 793 } | 795 } |
| OLD | NEW |