| 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/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 #include "chrome/browser/ui/tab_contents/tab_contents.h" | 23 #include "chrome/browser/ui/tab_contents/tab_contents.h" |
| 24 #include "chrome/common/chrome_notification_types.h" | 24 #include "chrome/common/chrome_notification_types.h" |
| 25 #include "chrome/common/chrome_switches.h" | 25 #include "chrome/common/chrome_switches.h" |
| 26 #include "chrome/common/pref_names.h" | 26 #include "chrome/common/pref_names.h" |
| 27 #include "content/public/browser/favicon_status.h" | 27 #include "content/public/browser/favicon_status.h" |
| 28 #include "content/public/browser/navigation_entry.h" | 28 #include "content/public/browser/navigation_entry.h" |
| 29 #include "content/public/browser/notification_service.h" | 29 #include "content/public/browser/notification_service.h" |
| 30 #include "content/public/browser/render_widget_host_view.h" | 30 #include "content/public/browser/render_widget_host_view.h" |
| 31 #include "content/public/browser/web_contents.h" | 31 #include "content/public/browser/web_contents.h" |
| 32 #include "ui/gfx/codec/png_codec.h" | 32 #include "ui/gfx/codec/png_codec.h" |
| 33 #include "ui/gfx/image/image_skia.h" |
| 33 | 34 |
| 34 #if defined(TOOLKIT_VIEWS) | 35 #if defined(TOOLKIT_VIEWS) |
| 35 #include "ui/views/widget/widget.h" | 36 #include "ui/views/widget/widget.h" |
| 36 #endif | 37 #endif |
| 37 | 38 |
| 38 namespace { | 39 namespace { |
| 39 | 40 |
| 40 enum PreviewUsageType { | 41 enum PreviewUsageType { |
| 41 PREVIEW_CREATED = 0, | 42 PREVIEW_CREATED = 0, |
| 42 PREVIEW_DELETED, | 43 PREVIEW_DELETED, |
| (...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 338 preview->history_tab_helper()->UpdateHistoryForNavigation(last_navigation); | 339 preview->history_tab_helper()->UpdateHistoryForNavigation(last_navigation); |
| 339 | 340 |
| 340 // Update the page title. | 341 // Update the page title. |
| 341 preview->history_tab_helper()->UpdateHistoryPageTitle(*entry); | 342 preview->history_tab_helper()->UpdateHistoryPageTitle(*entry); |
| 342 | 343 |
| 343 // Update the favicon. | 344 // Update the favicon. |
| 344 FaviconService* favicon_service = FaviconServiceFactory::GetForProfile( | 345 FaviconService* favicon_service = FaviconServiceFactory::GetForProfile( |
| 345 preview->profile(), Profile::EXPLICIT_ACCESS); | 346 preview->profile(), Profile::EXPLICIT_ACCESS); |
| 346 if (favicon_service && entry->GetFavicon().valid && | 347 if (favicon_service && entry->GetFavicon().valid && |
| 347 entry->GetFavicon().image.IsEmpty()) { | 348 entry->GetFavicon().image.IsEmpty()) { |
| 348 std::vector<unsigned char> image_data; | 349 favicon_service->SetFavicons(entry->GetURL(), entry->GetFavicon().url, |
| 349 // TODO: Add all variants once the history service supports it. | 350 history::FAVICON, entry->GetFavicon().image); |
| 350 gfx::PNGCodec::EncodeBGRASkBitmap( | |
| 351 entry->GetFavicon().image.AsBitmap(), false, &image_data); | |
| 352 favicon_service->SetFavicon(entry->GetURL(), | |
| 353 entry->GetFavicon().url, | |
| 354 image_data, | |
| 355 history::FAVICON); | |
| 356 } | 351 } |
| 357 } | 352 } |
| 358 | 353 |
| 359 // Add a fake history entry with a non-Instant search URL, so that search | 354 // Add a fake history entry with a non-Instant search URL, so that search |
| 360 // terms extraction (for autocomplete history matches) works. | 355 // terms extraction (for autocomplete history matches) works. |
| 361 HistoryService* history = HistoryServiceFactory::GetForProfile( | 356 HistoryService* history = HistoryServiceFactory::GetForProfile( |
| 362 preview->profile(), Profile::EXPLICIT_ACCESS); | 357 preview->profile(), Profile::EXPLICIT_ACCESS); |
| 363 if (history) { | 358 if (history) { |
| 364 history->AddPage(url_for_history_, NULL, 0, GURL(), last_transition_type_, | 359 history->AddPage(url_for_history_, NULL, 0, GURL(), last_transition_type_, |
| 365 history::RedirectList(), history::SOURCE_BROWSED, false); | 360 history::RedirectList(), history::SOURCE_BROWSED, false); |
| (...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 717 iter->second > kMaxInstantSupportFailures) | 712 iter->second > kMaxInstantSupportFailures) |
| 718 return false; | 713 return false; |
| 719 | 714 |
| 720 return true; | 715 return true; |
| 721 } | 716 } |
| 722 | 717 |
| 723 bool InstantController::IsOutOfDate() const { | 718 bool InstantController::IsOutOfDate() const { |
| 724 return !last_active_tab_ || | 719 return !last_active_tab_ || |
| 725 last_active_tab_ != delegate_->GetActiveTabContents(); | 720 last_active_tab_ != delegate_->GetActiveTabContents(); |
| 726 } | 721 } |
| OLD | NEW |