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" | 12 #include "components/favicon/core/fallback_icon_service.h" |
13 #include "components/favicon/core/large_icon_service.h" | 13 #include "components/favicon/core/large_icon_service.h" |
14 #include "components/favicon_base/fallback_icon_style.h" | 14 #include "components/favicon_base/fallback_icon_style.h" |
15 #include "components/favicon_base/favicon_types.h" | 15 #include "components/favicon_base/favicon_types.h" |
16 #include "components/favicon_base/large_icon_url_parser.h" | 16 #include "components/favicon_base/large_icon_url_parser.h" |
17 #include "net/url_request/url_request.h" | 17 #include "net/url_request/url_request.h" |
18 #include "third_party/skia/include/core/SkBitmap.h" | |
19 #include "ui/gfx/codec/png_codec.h" | |
18 | 20 |
19 namespace { | 21 namespace { |
20 | 22 |
21 const int kMaxLargeIconSize = 192; // Arbitrary bound to safeguard endpoint. | 23 const int kMaxLargeIconSize = 192; // Arbitrary bound to safeguard endpoint. |
22 | 24 |
23 } // namespace | 25 } // namespace |
24 | 26 |
25 LargeIconSource::LargeIconSource( | 27 LargeIconSource::LargeIconSource( |
26 favicon::FallbackIconService* fallback_icon_service, | 28 favicon::FallbackIconService* fallback_icon_service, |
27 favicon::LargeIconService* large_icon_service) | 29 favicon::LargeIconService* large_icon_service) |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
99 if (result.bitmap.is_valid()) { | 101 if (result.bitmap.is_valid()) { |
100 callback.Run(result.bitmap.bitmap_data.get()); | 102 callback.Run(result.bitmap.bitmap_data.get()); |
101 return; | 103 return; |
102 } | 104 } |
103 | 105 |
104 // Bitmap is invalid, use the fallback if service is available. | 106 // Bitmap is invalid, use the fallback if service is available. |
105 if (!fallback_icon_service_ || !result.fallback_icon_style) { | 107 if (!fallback_icon_service_ || !result.fallback_icon_style) { |
106 SendNotFoundResponse(callback); | 108 SendNotFoundResponse(callback); |
107 return; | 109 return; |
108 } | 110 } |
111 | |
112 #if defined(OS_ANDROID) | |
113 // RenderFallbackIconBitmap() cannot draw fallback icons on Android. See | |
newt (away)
2016/01/25 19:43:35
Instead of sending a 1x1 bitmap, could you send th
Dan Beam
2016/02/05 20:42:12
how would it be read?
| |
114 // crbug.com/580922 for details. Return a 1x1 bitmap so that JavaScript can | |
115 // detect that it needs to generate a fallback icon. | |
116 SkBitmap bitmap; | |
117 bitmap.allocN32Pixels(1, 1); | |
Dan Beam
2016/02/05 20:42:12
why not a 0x0?
pkotwicz
2016/02/06 02:59:55
See my other comment about sending the dominant co
| |
118 bitmap.eraseColor(result.fallback_icon_style->background_color); | |
119 std::vector<unsigned char> bitmap_data; | |
120 if (!gfx::PNGCodec::EncodeBGRASkBitmap(bitmap, false, &bitmap_data)) | |
121 bitmap_data.clear(); | |
122 #else | |
109 std::vector<unsigned char> bitmap_data = | 123 std::vector<unsigned char> bitmap_data = |
110 fallback_icon_service_->RenderFallbackIconBitmap( | 124 fallback_icon_service_->RenderFallbackIconBitmap( |
111 url, size, *result.fallback_icon_style); | 125 url, size, *result.fallback_icon_style); |
126 #endif | |
127 | |
112 callback.Run(base::RefCountedBytes::TakeVector(&bitmap_data)); | 128 callback.Run(base::RefCountedBytes::TakeVector(&bitmap_data)); |
113 } | 129 } |
114 | 130 |
115 void LargeIconSource::SendNotFoundResponse( | 131 void LargeIconSource::SendNotFoundResponse( |
116 const content::URLDataSource::GotDataCallback& callback) { | 132 const content::URLDataSource::GotDataCallback& callback) { |
117 callback.Run(nullptr); | 133 callback.Run(nullptr); |
118 } | 134 } |
OLD | NEW |