| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/ui/webui/large_icon_source.h" | 5 #include "chrome/browser/ui/webui/large_icon_source.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/memory/ref_counted_memory.h" | 9 #include "base/memory/ref_counted_memory.h" |
| 10 #include "chrome/browser/search/instant_io_context.h" | 10 #include "chrome/browser/search/instant_io_context.h" |
| 11 #include "chrome/common/url_constants.h" | 11 #include "chrome/common/url_constants.h" |
| 12 #include "components/favicon/core/fallback_icon_service.h" | |
| 13 #include "components/favicon/core/large_icon_service.h" | 12 #include "components/favicon/core/large_icon_service.h" |
| 14 #include "components/favicon_base/fallback_icon_style.h" | 13 #include "components/favicon_base/fallback_icon_style.h" |
| 15 #include "components/favicon_base/favicon_types.h" | 14 #include "components/favicon_base/favicon_types.h" |
| 16 #include "components/favicon_base/large_icon_url_parser.h" | 15 #include "components/favicon_base/large_icon_url_parser.h" |
| 17 #include "net/url_request/url_request.h" | 16 #include "net/url_request/url_request.h" |
| 18 #include "third_party/skia/include/core/SkBitmap.h" | 17 #include "third_party/skia/include/core/SkBitmap.h" |
| 19 #include "ui/gfx/codec/png_codec.h" | 18 #include "ui/gfx/codec/png_codec.h" |
| 20 | 19 |
| 21 namespace { | 20 namespace { |
| 22 | 21 |
| 23 const int kMaxLargeIconSize = 192; // Arbitrary bound to safeguard endpoint. | 22 const int kMaxLargeIconSize = 192; // Arbitrary bound to safeguard endpoint. |
| 24 | 23 |
| 25 } // namespace | 24 } // namespace |
| 26 | 25 |
| 27 LargeIconSource::LargeIconSource( | 26 LargeIconSource::LargeIconSource(favicon::LargeIconService* large_icon_service) |
| 28 favicon::FallbackIconService* fallback_icon_service, | 27 : large_icon_service_(large_icon_service) {} |
| 29 favicon::LargeIconService* large_icon_service) | |
| 30 : fallback_icon_service_(fallback_icon_service), | |
| 31 large_icon_service_(large_icon_service) { | |
| 32 } | |
| 33 | 28 |
| 34 LargeIconSource::~LargeIconSource() { | 29 LargeIconSource::~LargeIconSource() { |
| 35 } | 30 } |
| 36 | 31 |
| 37 std::string LargeIconSource::GetSource() const { | 32 std::string LargeIconSource::GetSource() const { |
| 38 return chrome::kChromeUILargeIconHost; | 33 return chrome::kChromeUILargeIconHost; |
| 39 } | 34 } |
| 40 | 35 |
| 41 void LargeIconSource::StartDataRequest( | 36 void LargeIconSource::StartDataRequest( |
| 42 const std::string& path, | 37 const std::string& path, |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 void LargeIconSource::OnLargeIconDataAvailable( | 99 void LargeIconSource::OnLargeIconDataAvailable( |
| 105 const content::URLDataSource::GotDataCallback& callback, | 100 const content::URLDataSource::GotDataCallback& callback, |
| 106 const GURL& url, | 101 const GURL& url, |
| 107 int size, | 102 int size, |
| 108 const favicon_base::LargeIconResult& result) { | 103 const favicon_base::LargeIconResult& result) { |
| 109 if (result.bitmap.is_valid()) { | 104 if (result.bitmap.is_valid()) { |
| 110 callback.Run(result.bitmap.bitmap_data.get()); | 105 callback.Run(result.bitmap.bitmap_data.get()); |
| 111 return; | 106 return; |
| 112 } | 107 } |
| 113 | 108 |
| 114 // Bitmap is invalid, use the fallback if service is available. | 109 if (!result.fallback_icon_style) { |
| 115 if (!fallback_icon_service_ || !result.fallback_icon_style) { | |
| 116 SendNotFoundResponse(callback); | 110 SendNotFoundResponse(callback); |
| 117 return; | 111 return; |
| 118 } | 112 } |
| 119 | 113 |
| 120 #if defined(OS_ANDROID) | |
| 121 // RenderFallbackIconBitmap() cannot draw fallback icons on Android. See | 114 // RenderFallbackIconBitmap() cannot draw fallback icons on Android. See |
| 122 // crbug.com/580922 for details. Return a 1x1 bitmap so that JavaScript can | 115 // crbug.com/580922 for details. Return a 1x1 bitmap so that JavaScript can |
| 123 // detect that it needs to generate a fallback icon. | 116 // detect that it needs to generate a fallback icon. |
| 124 SkBitmap bitmap; | 117 SkBitmap bitmap; |
| 125 bitmap.allocN32Pixels(1, 1); | 118 bitmap.allocN32Pixels(1, 1); |
| 126 bitmap.eraseColor(result.fallback_icon_style->background_color); | 119 bitmap.eraseColor(result.fallback_icon_style->background_color); |
| 127 std::vector<unsigned char> bitmap_data; | 120 std::vector<unsigned char> bitmap_data; |
| 128 if (!gfx::PNGCodec::EncodeBGRASkBitmap(bitmap, false, &bitmap_data)) | 121 if (!gfx::PNGCodec::EncodeBGRASkBitmap(bitmap, false, &bitmap_data)) |
| 129 bitmap_data.clear(); | 122 bitmap_data.clear(); |
| 130 #else | |
| 131 std::vector<unsigned char> bitmap_data = | |
| 132 fallback_icon_service_->RenderFallbackIconBitmap( | |
| 133 url, size, *result.fallback_icon_style); | |
| 134 #endif | |
| 135 | 123 |
| 136 callback.Run(base::RefCountedBytes::TakeVector(&bitmap_data)); | 124 callback.Run(base::RefCountedBytes::TakeVector(&bitmap_data)); |
| 137 } | 125 } |
| 138 | 126 |
| 139 void LargeIconSource::SendNotFoundResponse( | 127 void LargeIconSource::SendNotFoundResponse( |
| 140 const content::URLDataSource::GotDataCallback& callback) { | 128 const content::URLDataSource::GotDataCallback& callback) { |
| 141 callback.Run(nullptr); | 129 callback.Run(nullptr); |
| 142 } | 130 } |
| OLD | NEW |