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/extensions/image_loader.h" | 5 #include "chrome/browser/extensions/image_loader.h" |
6 | 6 |
7 #include "base/callback.h" | 7 #include "base/callback.h" |
8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
11 #include "base/string_number_conversions.h" | 11 #include "base/string_number_conversions.h" |
12 #include "base/threading/sequenced_worker_pool.h" | 12 #include "base/threading/sequenced_worker_pool.h" |
13 #include "chrome/browser/extensions/image_loader_factory.h" | 13 #include "chrome/browser/extensions/image_loader_factory.h" |
14 #include "chrome/common/chrome_paths.h" | 14 #include "chrome/common/chrome_paths.h" |
15 #include "chrome/common/extensions/extension.h" | 15 #include "chrome/common/extensions/extension.h" |
16 #include "content/public/browser/browser_thread.h" | 16 #include "content/public/browser/browser_thread.h" |
17 #include "grit/chrome_unscaled_resources.h" | 17 #include "grit/chrome_unscaled_resources.h" |
18 #include "grit/component_extension_resources_map.h" | 18 #include "grit/component_extension_resources_map.h" |
19 #include "grit/theme_resources.h" | 19 #include "grit/theme_resources.h" |
20 #include "skia/ext/image_operations.h" | 20 #include "skia/ext/image_operations.h" |
21 #include "ui/base/resource/resource_bundle.h" | 21 #include "ui/base/resource/resource_bundle.h" |
22 #include "ui/gfx/image/image_skia.h" | 22 #include "ui/gfx/image/image_skia.h" |
23 #include "webkit/glue/image_decoder.h" | 23 #include "webkit/glue/image_decoder.h" |
24 | 24 |
25 using content::BrowserThread; | 25 using content::BrowserThread; |
26 using extensions::Extension; | 26 using extensions::Extension; |
27 using extensions::ImageLoader; | 27 using extensions::ImageLoader; |
| 28 using extensions::Manifest; |
28 | 29 |
29 namespace { | 30 namespace { |
30 | 31 |
31 bool ShouldResizeImageRepresentation( | 32 bool ShouldResizeImageRepresentation( |
32 ImageLoader::ImageRepresentation::ResizeCondition resize_method, | 33 ImageLoader::ImageRepresentation::ResizeCondition resize_method, |
33 const gfx::Size& decoded_size, | 34 const gfx::Size& decoded_size, |
34 const gfx::Size& desired_size) { | 35 const gfx::Size& desired_size) { |
35 switch (resize_method) { | 36 switch (resize_method) { |
36 case ImageLoader::ImageRepresentation::ALWAYS_RESIZE: | 37 case ImageLoader::ImageRepresentation::ALWAYS_RESIZE: |
37 return decoded_size != desired_size; | 38 return decoded_size != desired_size; |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
236 std::vector<SkBitmap> bitmaps; | 237 std::vector<SkBitmap> bitmaps; |
237 bitmaps.resize(info_list.size()); | 238 bitmaps.resize(info_list.size()); |
238 | 239 |
239 int i = 0; | 240 int i = 0; |
240 for (std::vector<ImageRepresentation>::const_iterator it = info_list.begin(); | 241 for (std::vector<ImageRepresentation>::const_iterator it = info_list.begin(); |
241 it != info_list.end(); ++it, ++i) { | 242 it != info_list.end(); ++it, ++i) { |
242 DCHECK(it->resource.relative_path().empty() || | 243 DCHECK(it->resource.relative_path().empty() || |
243 extension->path() == it->resource.extension_root()); | 244 extension->path() == it->resource.extension_root()); |
244 | 245 |
245 int resource_id; | 246 int resource_id; |
246 if (extension->location() == Extension::COMPONENT && | 247 if (extension->location() == Manifest::COMPONENT && |
247 IsComponentExtensionResource(extension->path(), | 248 IsComponentExtensionResource(extension->path(), |
248 it->resource.relative_path(), | 249 it->resource.relative_path(), |
249 &resource_id)) { | 250 &resource_id)) { |
250 LoadResourceOnUIThread(resource_id, &bitmaps[i]); | 251 LoadResourceOnUIThread(resource_id, &bitmaps[i]); |
251 } | 252 } |
252 } | 253 } |
253 | 254 |
254 DCHECK(!BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread()); | 255 DCHECK(!BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread()); |
255 std::vector<LoadResult>* load_result = new std::vector<LoadResult>; | 256 std::vector<LoadResult>* load_result = new std::vector<LoadResult>; |
256 BrowserThread::PostBlockingPoolTaskAndReply( | 257 BrowserThread::PostBlockingPoolTaskAndReply( |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
311 gfx::Image image; | 312 gfx::Image image; |
312 if (!image_skia.isNull()) { | 313 if (!image_skia.isNull()) { |
313 image_skia.MakeThreadSafe(); | 314 image_skia.MakeThreadSafe(); |
314 image = gfx::Image(image_skia); | 315 image = gfx::Image(image_skia); |
315 } | 316 } |
316 | 317 |
317 callback.Run(image); | 318 callback.Run(image); |
318 } | 319 } |
319 | 320 |
320 } // namespace extensions | 321 } // namespace extensions |
OLD | NEW |