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/extension_icon_image.h" | 5 #include "chrome/browser/extensions/extension_icon_image.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "chrome/common/chrome_notification_types.h" | 9 #include "chrome/common/chrome_notification_types.h" |
10 #include "chrome/common/extensions/extension.h" | 10 #include "chrome/common/extensions/extension.h" |
11 #include "content/public/browser/notification_service.h" | 11 #include "content/public/browser/notification_service.h" |
12 #include "ui/gfx/canvas.h" | 12 #include "ui/gfx/canvas.h" |
13 #include "ui/gfx/image/canvas_image_source.h" | 13 #include "ui/gfx/image/canvas_image_source.h" |
14 #include "ui/gfx/image/image.h" | 14 #include "ui/gfx/image/image.h" |
15 #include "ui/gfx/image/image_skia_source.h" | 15 #include "ui/gfx/image/image_skia_source.h" |
16 #include "ui/gfx/size.h" | 16 #include "ui/gfx/size.h" |
| 17 #include "ui/gfx/size_conversions.h" |
17 | 18 |
18 // The ImageSkia provided by extensions::IconImage contains ImageSkiaReps that | 19 // The ImageSkia provided by extensions::IconImage contains ImageSkiaReps that |
19 // are computed and updated using the following algorithm (if no default icon | 20 // are computed and updated using the following algorithm (if no default icon |
20 // was supplied, transparent icon is considered the default): | 21 // was supplied, transparent icon is considered the default): |
21 // - |LoadImageForScaleFactors()| searches the extension for an icon of an | 22 // - |LoadImageForScaleFactors()| searches the extension for an icon of an |
22 // appropriate size. If the extension doesn't have a icon resource needed for | 23 // appropriate size. If the extension doesn't have a icon resource needed for |
23 // the image representation, the default icon's representation for the | 24 // the image representation, the default icon's representation for the |
24 // requested scale factor is returned by ImageSkiaSource. | 25 // requested scale factor is returned by ImageSkiaSource. |
25 // - If the extension has the resource, IconImage tries to load it using | 26 // - If the extension has the resource, IconImage tries to load it using |
26 // ImageLoadingTracker. | 27 // ImageLoadingTracker. |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
185 return default_icon_.GetRepresentation(scale_factor); | 186 return default_icon_.GetRepresentation(scale_factor); |
186 | 187 |
187 int id = tracker_.next_id(); | 188 int id = tracker_.next_id(); |
188 load_map_[id].scale_factor = scale_factor; | 189 load_map_[id].scale_factor = scale_factor; |
189 load_map_[id].is_async = false; | 190 load_map_[id].is_async = false; |
190 | 191 |
191 std::vector<ImageLoadingTracker::ImageRepresentation> info_list; | 192 std::vector<ImageLoadingTracker::ImageRepresentation> info_list; |
192 info_list.push_back(ImageLoadingTracker::ImageRepresentation( | 193 info_list.push_back(ImageLoadingTracker::ImageRepresentation( |
193 resource, | 194 resource, |
194 ImageLoadingTracker::ImageRepresentation::ALWAYS_RESIZE, | 195 ImageLoadingTracker::ImageRepresentation::ALWAYS_RESIZE, |
195 gfx::Size(resource_size_in_dip_, resource_size_in_dip_).Scale(scale), | 196 gfx::ToFlooredSize( |
| 197 gfx::Size(resource_size_in_dip_, resource_size_in_dip_).Scale(scale)), |
196 scale_factor)); | 198 scale_factor)); |
197 tracker_.LoadImages(extension_, info_list, ImageLoadingTracker::DONT_CACHE); | 199 tracker_.LoadImages(extension_, info_list, ImageLoadingTracker::DONT_CACHE); |
198 | 200 |
199 // If we have not received |OnImageLoaded|, image load request is | 201 // If we have not received |OnImageLoaded|, image load request is |
200 // asynchronous. | 202 // asynchronous. |
201 if (load_map_.find(id) != load_map_.end()) | 203 if (load_map_.find(id) != load_map_.end()) |
202 load_map_[id].is_async = true; | 204 load_map_[id].is_async = true; |
203 | 205 |
204 // If LoadImages returned synchronously and the requested image rep is cached | 206 // If LoadImages returned synchronously and the requested image rep is cached |
205 // in the extension, return the cached image rep. | 207 // in the extension, return the cached image rep. |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
248 DCHECK_EQ(type, chrome::NOTIFICATION_EXTENSION_UNLOADED); | 250 DCHECK_EQ(type, chrome::NOTIFICATION_EXTENSION_UNLOADED); |
249 | 251 |
250 const Extension* extension = | 252 const Extension* extension = |
251 content::Details<extensions::UnloadedExtensionInfo>(details)->extension; | 253 content::Details<extensions::UnloadedExtensionInfo>(details)->extension; |
252 | 254 |
253 if (extension_ == extension) | 255 if (extension_ == extension) |
254 extension_ = NULL; | 256 extension_ = NULL; |
255 } | 257 } |
256 | 258 |
257 } // namespace extensions | 259 } // namespace extensions |
OLD | NEW |