Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4)

Side by Side Diff: extensions/browser/image_loader.cc

Issue 2576833002: Make some updates to extension iconography. (Closed)
Patch Set: devlin review Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « extensions/browser/image_loader.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
30 using extensions::ExtensionsBrowserClient; 32 namespace extensions {
31 using extensions::ImageLoader;
32 using extensions::Manifest;
33 33
34 namespace { 34 namespace {
35 35
36 bool ShouldResizeImageRepresentation( 36 bool ShouldResizeImageRepresentation(
37 ImageLoader::ImageRepresentation::ResizeCondition resize_method, 37 ImageLoader::ImageRepresentation::ResizeCondition resize_method,
38 const gfx::Size& decoded_size, 38 const gfx::Size& decoded_size,
39 const gfx::Size& desired_size) { 39 const gfx::Size& desired_size) {
40 switch (resize_method) { 40 switch (resize_method) {
41 case ImageLoader::ImageRepresentation::ALWAYS_RESIZE: 41 case ImageLoader::ImageRepresentation::ALWAYS_RESIZE:
42 return decoded_size != desired_size; 42 return decoded_size != desired_size;
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 extension->path(), it->resource.relative_path(), &resource_id)) { 121 extension->path(), it->resource.relative_path(), &resource_id)) {
122 LoadResourceOnUIThread(resource_id, &bitmaps[i]); 122 LoadResourceOnUIThread(resource_id, &bitmaps[i]);
123 } 123 }
124 } 124 }
125 } 125 }
126 return bitmaps; 126 return bitmaps;
127 } 127 }
128 128
129 } // namespace 129 } // namespace
130 130
131 namespace extensions {
132
133 //////////////////////////////////////////////////////////////////////////////// 131 ////////////////////////////////////////////////////////////////////////////////
134 // ImageLoader::ImageRepresentation 132 // ImageLoader::ImageRepresentation
135 133
136 ImageLoader::ImageRepresentation::ImageRepresentation( 134 ImageLoader::ImageRepresentation::ImageRepresentation(
137 const ExtensionResource& resource, 135 const ExtensionResource& resource,
138 ResizeCondition resize_condition, 136 ResizeCondition resize_condition,
139 const gfx::Size& desired_size, 137 const gfx::Size& desired_size,
140 ui::ScaleFactor scale_factor) 138 ui::ScaleFactor scale_factor)
141 : resource(resource), 139 : resource(resource),
142 resize_condition(resize_condition), 140 resize_condition(resize_condition),
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 const ImageLoaderImageCallback& callback) { 230 const ImageLoaderImageCallback& callback) {
233 std::vector<ImageRepresentation> info_list; 231 std::vector<ImageRepresentation> info_list;
234 info_list.push_back(ImageRepresentation( 232 info_list.push_back(ImageRepresentation(
235 resource, 233 resource,
236 ImageRepresentation::RESIZE_WHEN_LARGER, 234 ImageRepresentation::RESIZE_WHEN_LARGER,
237 max_size, 235 max_size,
238 ui::SCALE_FACTOR_100P)); 236 ui::SCALE_FACTOR_100P));
239 LoadImagesAsync(extension, info_list, callback); 237 LoadImagesAsync(extension, info_list, callback);
240 } 238 }
241 239
240 void ImageLoader::LoadImageAtEveryScaleFactorAsync(
241 const Extension* extension,
242 const gfx::Size& dip_size,
243 const ImageLoaderImageCallback& callback) {
244 std::vector<ImageRepresentation> info_list;
245 for (auto scale : ui::GetSupportedScaleFactors()) {
246 const float scale_factor = ui::GetScaleForScaleFactor(scale);
247 const gfx::Size px_size = gfx::ScaleToFlooredSize(dip_size, scale_factor);
248 ExtensionResource image = IconsInfo::GetIconResource(
249 extension, px_size.width(), ExtensionIconSet::MATCH_BIGGER);
250 info_list.push_back(ImageRepresentation(
251 image, ImageRepresentation::ALWAYS_RESIZE, px_size, scale));
252 }
253 LoadImagesAsync(extension, info_list, callback);
254 }
255
242 void ImageLoader::LoadImagesAsync( 256 void ImageLoader::LoadImagesAsync(
243 const Extension* extension, 257 const Extension* extension,
244 const std::vector<ImageRepresentation>& info_list, 258 const std::vector<ImageRepresentation>& info_list,
245 const ImageLoaderImageCallback& callback) { 259 const ImageLoaderImageCallback& callback) {
246 DCHECK_CURRENTLY_ON(BrowserThread::UI); 260 DCHECK_CURRENTLY_ON(BrowserThread::UI);
247 DCHECK(!BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread()); 261 DCHECK(!BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread());
248 base::PostTaskAndReplyWithResult( 262 base::PostTaskAndReplyWithResult(
249 BrowserThread::GetBlockingPool(), 263 BrowserThread::GetBlockingPool(),
250 FROM_HERE, 264 FROM_HERE,
251 base::Bind(LoadImagesOnBlockingPool, 265 base::Bind(LoadImagesOnBlockingPool,
252 info_list, 266 info_list,
253 LoadResourceBitmaps(extension, info_list)), 267 LoadResourceBitmaps(extension, info_list)),
254 base::Bind( 268 base::Bind(
255 &ImageLoader::ReplyBack, weak_ptr_factory_.GetWeakPtr(), callback)); 269 &ImageLoader::ReplyBack, weak_ptr_factory_.GetWeakPtr(), callback));
256 } 270 }
257 271
258 void ImageLoader::LoadImageFamilyAsync( 272 void ImageLoader::LoadImageFamilyAsync(
259 const extensions::Extension* extension, 273 const Extension* extension,
260 const std::vector<ImageRepresentation>& info_list, 274 const std::vector<ImageRepresentation>& info_list,
261 const ImageLoaderImageFamilyCallback& callback) { 275 const ImageLoaderImageFamilyCallback& callback) {
262 DCHECK_CURRENTLY_ON(BrowserThread::UI); 276 DCHECK_CURRENTLY_ON(BrowserThread::UI);
263 DCHECK(!BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread()); 277 DCHECK(!BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread());
264 base::PostTaskAndReplyWithResult( 278 base::PostTaskAndReplyWithResult(
265 BrowserThread::GetBlockingPool(), 279 BrowserThread::GetBlockingPool(),
266 FROM_HERE, 280 FROM_HERE,
267 base::Bind(LoadImagesOnBlockingPool, 281 base::Bind(LoadImagesOnBlockingPool,
268 info_list, 282 info_list,
269 LoadResourceBitmaps(extension, info_list)), 283 LoadResourceBitmaps(extension, info_list)),
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
324 it != image_skia_map.end(); 338 it != image_skia_map.end();
325 ++it) { 339 ++it) {
326 it->second.MakeThreadSafe(); 340 it->second.MakeThreadSafe();
327 image_family.Add(it->second); 341 image_family.Add(it->second);
328 } 342 }
329 343
330 callback.Run(image_family); 344 callback.Run(image_family);
331 } 345 }
332 346
333 } // namespace extensions 347 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/browser/image_loader.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698