Chromium Code Reviews| Index: chrome/browser/ui/webui/large_icon_source.cc |
| diff --git a/chrome/browser/ui/webui/large_icon_source.cc b/chrome/browser/ui/webui/large_icon_source.cc |
| index df1e285f6c307e717c86b2056980cffeed9f7785..dc48188f1fda3bce08d92e5fb23eccac76decddf 100644 |
| --- a/chrome/browser/ui/webui/large_icon_source.cc |
| +++ b/chrome/browser/ui/webui/large_icon_source.cc |
| @@ -4,6 +4,8 @@ |
| #include "chrome/browser/ui/webui/large_icon_source.h" |
| +#include <vector> |
| + |
| #include "base/memory/ref_counted_memory.h" |
| #include "chrome/browser/search/instant_io_context.h" |
| #include "chrome/common/favicon/large_icon_url_parser.h" |
| @@ -12,45 +14,18 @@ |
| #include "components/favicon/core/favicon_service.h" |
| #include "components/favicon_base/fallback_icon_style.h" |
| #include "net/url_request/url_request.h" |
| -#include "third_party/skia/include/core/SkColor.h" |
| -#include "ui/gfx/color_analysis.h" |
| -#include "ui/gfx/color_utils.h" |
| namespace { |
| -const int kDefaultLargeIconSize = 96; |
| const int kMaxLargeIconSize = 192; // Arbitrary bound to safeguard endpoint. |
| -const double kMaxBackgroundLuminance = 0.67; |
| -const SkColor kDarkGray = SkColorSetRGB(0x78, 0x78, 0x78); |
| -const SkColor kTextColor = SK_ColorWHITE; |
| -const SkColor kDefaultBackgroundColor = kDarkGray; |
| - |
| } // namespace |
| -LargeIconSource::IconRequest::IconRequest() : size(kDefaultLargeIconSize) { |
| -} |
| - |
| -LargeIconSource::IconRequest::IconRequest( |
| - const content::URLDataSource::GotDataCallback& callback_in, |
| - const GURL& url_in, |
| - int size_in) |
| - : callback(callback_in), |
| - url(url_in), |
| - size(size_in) { |
| -} |
| - |
| -LargeIconSource::IconRequest::~IconRequest() { |
| -} |
| - |
| LargeIconSource::LargeIconSource( |
| favicon::FaviconService* favicon_service, |
| favicon::FallbackIconService* fallback_icon_service) |
| : favicon_service_(favicon_service), |
| fallback_icon_service_(fallback_icon_service) { |
| - large_icon_types_.push_back(favicon_base::IconType::FAVICON); |
| - large_icon_types_.push_back(favicon_base::IconType::TOUCH_ICON); |
| - large_icon_types_.push_back(favicon_base::IconType::TOUCH_PRECOMPOSED_ICON); |
| } |
| LargeIconSource::~LargeIconSource() { |
| @@ -85,14 +60,11 @@ void LargeIconSource::StartDataRequest( |
| return; |
| } |
| - favicon_service_->GetLargestRawFaviconForPageURL( |
| + favicon_service_->GetLargeIconOrFallbackStyle( |
| url, |
| - large_icon_types_, |
| parser.size_in_pixels(), |
| - base::Bind( |
| - &LargeIconSource::OnIconDataAvailable, |
| - base::Unretained(this), |
| - IconRequest(callback, url, parser.size_in_pixels())), |
| + base::Bind(&LargeIconSource::OnIconDataAvailable, base::Unretained(this), |
| + callback, url, parser.size_in_pixels()), |
| &cancelable_task_tracker_); |
| } |
| @@ -116,53 +88,24 @@ bool LargeIconSource::ShouldServiceRequest( |
| } |
| void LargeIconSource::OnIconDataAvailable( |
| - const IconRequest& request, |
| - const favicon_base::FaviconRawBitmapResult& bitmap_result) { |
| - if (!bitmap_result.is_valid()) { |
| - SendDefaultFallbackIcon(request); |
| + const content::URLDataSource::GotDataCallback& callback, |
| + const GURL& url, |
| + int size, |
| + const favicon_base::LargeIconResult& result) { |
| + if (result.bitmap.is_valid()) { |
| + callback.Run(result.bitmap.bitmap_data.get()); |
| return; |
| } |
| - // If we found a bitmap, but it's smaller than the requested size, we |
| - // generate a fallback using the dominant color from the too-small bitmap. |
| - // We adjust the luminance of the background so we can put light text over it. |
| - if (bitmap_result.pixel_size.width() < request.size || |
| - bitmap_result.pixel_size.height() < request.size) { |
| - SkColor background = |
| - color_utils::CalculateKMeanColorOfPNG(bitmap_result.bitmap_data); |
| - color_utils::HSL background_hsl; |
| - color_utils::SkColorToHSL(background, &background_hsl); |
| - background_hsl.l = std::min(background_hsl.l, kMaxBackgroundLuminance); |
| - background = color_utils::HSLToSkColor(background_hsl, SK_AlphaOPAQUE); |
| - |
| - // Now we can construct the fallback icon. |
| - SendFallbackIcon(request, kTextColor, background); |
| - return; |
| - } |
| - |
| - request.callback.Run(bitmap_result.bitmap_data.get()); |
| -} |
| - |
| -void LargeIconSource::SendDefaultFallbackIcon(const IconRequest& request) { |
| - SendFallbackIcon(request, kTextColor, kDefaultBackgroundColor); |
| -} |
| - |
| -void LargeIconSource::SendFallbackIcon(const IconRequest& request, |
| - SkColor text_color, |
| - SkColor background_color) { |
| + // Bitmap is invalid, use the fallback. |
|
huangs
2015/04/17 15:30:47
NIT: "...use the fallback if service is available.
beaudoin
2015/04/17 20:29:05
Done.
|
| if (!fallback_icon_service_) { |
| - SendNotFoundResponse(request.callback); |
| + SendNotFoundResponse(callback); |
| return; |
| } |
| - favicon_base::FallbackIconStyle style; |
| - style.background_color = background_color; |
| - style.text_color = text_color; |
| - style.font_size_ratio = 0.44; |
| - style.roundness = 0; // Square. Round corners can be applied by JavaScript. |
| std::vector<unsigned char> bitmap_data = |
| fallback_icon_service_->RenderFallbackIconBitmap( |
| - request.url, request.size, style); |
| - request.callback.Run(base::RefCountedBytes::TakeVector(&bitmap_data)); |
| + url, size, result.fallback_icon_style); |
| + callback.Run(base::RefCountedBytes::TakeVector(&bitmap_data)); |
| } |
| void LargeIconSource::SendNotFoundResponse( |