OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "extensions/browser/image_loader.h" | 5 #include "extensions/browser/image_loader.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <map> | 9 #include <map> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/callback.h" | 12 #include "base/callback.h" |
13 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
14 #include "base/files/file_util.h" | 14 #include "base/files/file_util.h" |
15 #include "base/strings/string_number_conversions.h" | 15 #include "base/strings/string_number_conversions.h" |
16 #include "base/threading/sequenced_worker_pool.h" | 16 #include "base/threading/sequenced_worker_pool.h" |
17 #include "content/public/browser/browser_thread.h" | 17 #include "content/public/browser/browser_thread.h" |
18 #include "extensions/browser/component_extension_resource_manager.h" | 18 #include "extensions/browser/component_extension_resource_manager.h" |
19 #include "extensions/browser/extensions_browser_client.h" | 19 #include "extensions/browser/extensions_browser_client.h" |
20 #include "extensions/browser/image_loader_factory.h" | 20 #include "extensions/browser/image_loader_factory.h" |
21 #include "extensions/common/extension.h" | 21 #include "extensions/common/extension.h" |
22 #include "extensions/common/manifest_handlers/icons_handler.h" | |
22 #include "skia/ext/image_operations.h" | 23 #include "skia/ext/image_operations.h" |
24 #include "ui/base/layout.h" | |
23 #include "ui/base/resource/resource_bundle.h" | 25 #include "ui/base/resource/resource_bundle.h" |
24 #include "ui/gfx/codec/png_codec.h" | 26 #include "ui/gfx/codec/png_codec.h" |
25 #include "ui/gfx/image/image_family.h" | 27 #include "ui/gfx/image/image_family.h" |
26 #include "ui/gfx/image/image_skia.h" | 28 #include "ui/gfx/image/image_skia.h" |
27 | 29 |
28 using content::BrowserThread; | 30 using content::BrowserThread; |
29 using extensions::Extension; | 31 using extensions::Extension; |
30 using extensions::ExtensionsBrowserClient; | 32 using extensions::ExtensionsBrowserClient; |
31 using extensions::ImageLoader; | 33 using extensions::ImageLoader; |
32 using extensions::Manifest; | 34 using extensions::Manifest; |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
232 const ImageLoaderImageCallback& callback) { | 234 const ImageLoaderImageCallback& callback) { |
233 std::vector<ImageRepresentation> info_list; | 235 std::vector<ImageRepresentation> info_list; |
234 info_list.push_back(ImageRepresentation( | 236 info_list.push_back(ImageRepresentation( |
235 resource, | 237 resource, |
236 ImageRepresentation::RESIZE_WHEN_LARGER, | 238 ImageRepresentation::RESIZE_WHEN_LARGER, |
237 max_size, | 239 max_size, |
238 ui::SCALE_FACTOR_100P)); | 240 ui::SCALE_FACTOR_100P)); |
239 LoadImagesAsync(extension, info_list, callback); | 241 LoadImagesAsync(extension, info_list, callback); |
240 } | 242 } |
241 | 243 |
244 void ImageLoader::LoadImageAtEveryScaleFactorAsync( | |
245 const Extension* extension, | |
246 const gfx::Size& dip_size, | |
247 const ImageLoaderImageCallback& callback) { | |
248 std::vector<ImageRepresentation> info_list; | |
249 for (auto scale : ui::GetSupportedScaleFactors()) { | |
250 const float scale_factor = ui::GetScaleForScaleFactor(scale); | |
251 const gfx::Size px_size = gfx::ScaleToFlooredSize(dip_size, scale_factor); | |
252 extensions::ExtensionResource image = | |
Devlin
2016/12/15 17:14:41
no need for extensions:: prefix
Evan Stade
2016/12/15 23:49:02
Done.
| |
253 extensions::IconsInfo::GetIconResource(extension, px_size.width(), | |
254 ExtensionIconSet::MATCH_BIGGER); | |
255 info_list.push_back(ImageRepresentation( | |
256 image, ImageRepresentation::ALWAYS_RESIZE, px_size, scale)); | |
257 } | |
258 LoadImagesAsync(extension, info_list, callback); | |
259 } | |
260 | |
242 void ImageLoader::LoadImagesAsync( | 261 void ImageLoader::LoadImagesAsync( |
243 const Extension* extension, | 262 const Extension* extension, |
244 const std::vector<ImageRepresentation>& info_list, | 263 const std::vector<ImageRepresentation>& info_list, |
245 const ImageLoaderImageCallback& callback) { | 264 const ImageLoaderImageCallback& callback) { |
246 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 265 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
247 DCHECK(!BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread()); | 266 DCHECK(!BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread()); |
248 base::PostTaskAndReplyWithResult( | 267 base::PostTaskAndReplyWithResult( |
249 BrowserThread::GetBlockingPool(), | 268 BrowserThread::GetBlockingPool(), |
250 FROM_HERE, | 269 FROM_HERE, |
251 base::Bind(LoadImagesOnBlockingPool, | 270 base::Bind(LoadImagesOnBlockingPool, |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
324 it != image_skia_map.end(); | 343 it != image_skia_map.end(); |
325 ++it) { | 344 ++it) { |
326 it->second.MakeThreadSafe(); | 345 it->second.MakeThreadSafe(); |
327 image_family.Add(it->second); | 346 image_family.Add(it->second); |
328 } | 347 } |
329 | 348 |
330 callback.Run(image_family); | 349 callback.Run(image_family); |
331 } | 350 } |
332 | 351 |
333 } // namespace extensions | 352 } // namespace extensions |
OLD | NEW |