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/extension_icon_image.h" | 5 #include "extensions/browser/extension_icon_image.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "content/public/browser/notification_service.h" | 10 #include "content/public/browser/notification_service.h" |
11 #include "extensions/browser/image_loader.h" | 11 #include "extensions/browser/image_loader.h" |
12 #include "extensions/browser/notification_types.h" | 12 #include "extensions/browser/notification_types.h" |
13 #include "extensions/common/extension.h" | 13 #include "extensions/common/extension.h" |
14 #include "ui/base/layout.h" | |
14 #include "ui/gfx/canvas.h" | 15 #include "ui/gfx/canvas.h" |
15 #include "ui/gfx/geometry/size.h" | 16 #include "ui/gfx/geometry/size.h" |
16 #include "ui/gfx/geometry/size_conversions.h" | 17 #include "ui/gfx/geometry/size_conversions.h" |
17 #include "ui/gfx/image/canvas_image_source.h" | 18 #include "ui/gfx/image/canvas_image_source.h" |
18 #include "ui/gfx/image/image.h" | 19 #include "ui/gfx/image/image.h" |
19 #include "ui/gfx/image/image_skia_operations.h" | 20 #include "ui/gfx/image/image_skia_operations.h" |
20 #include "ui/gfx/image/image_skia_source.h" | 21 #include "ui/gfx/image/image_skia_source.h" |
21 | 22 |
22 // The ImageSkia provided by extensions::IconImage contains ImageSkiaReps that | 23 // The ImageSkia provided by extensions::IconImage contains ImageSkiaReps that |
23 // are computed and updated using the following algorithm (if no default icon | 24 // are computed and updated using the following algorithm (if no default icon |
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
216 image_in.IsEmpty() ? &default_icon_ : image_in.ToImageSkia(); | 217 image_in.IsEmpty() ? &default_icon_ : image_in.ToImageSkia(); |
217 | 218 |
218 // Maybe default icon was not set. | 219 // Maybe default icon was not set. |
219 if (image->isNull()) | 220 if (image->isNull()) |
220 return; | 221 return; |
221 | 222 |
222 gfx::ImageSkiaRep rep = image->GetRepresentation(scale); | 223 gfx::ImageSkiaRep rep = image->GetRepresentation(scale); |
223 DCHECK(!rep.is_null()); | 224 DCHECK(!rep.is_null()); |
224 DCHECK_EQ(scale, rep.scale()); | 225 DCHECK_EQ(scale, rep.scale()); |
225 | 226 |
226 // Remove old representation if there is one. | 227 // Remove fractional scale image representations as they may have become |
228 // stale here. These images are generated by ImageSkia on request from | |
229 // supported scales like 1x, 2x, etc. | |
230 // TODO(oshima) | |
231 // A better approach might be to set the |image_| member using the ImageSkia | |
232 // copy from the image passed in and set the |image_skia_| member using | |
233 // image_.ToImageSkia(). However that does not work correctly as the | |
234 // ImageSkia from the image does not contain a source which breaks requests | |
235 // for scaled images. | |
236 std::vector<gfx::ImageSkiaRep> reps = image_skia_.image_reps(); | |
237 for (const auto rep : reps) { | |
brucedawson
2015/03/26 18:44:37
The declaration of 'rep' should, I believe, be "co
ananta
2015/03/26 18:48:20
Will address these in a followup
Thanks
Ananta
| |
238 if (!ui::IsSupportedScale(rep.scale())) | |
239 image_skia_.RemoveRepresentation(rep.scale()); | |
240 } | |
241 | |
227 image_skia_.RemoveRepresentation(scale); | 242 image_skia_.RemoveRepresentation(scale); |
228 image_skia_.AddRepresentation(rep); | 243 image_skia_.AddRepresentation(rep); |
229 | 244 |
230 // Update the image to use the updated image skia. | 245 // Update the image to use the updated image skia. |
231 // It's a shame we have to do this because it means that all the other | 246 // It's a shame we have to do this because it means that all the other |
232 // representations stored on |image_| will be deleted, but unfortunately | 247 // representations stored on |image_| will be deleted, but unfortunately |
233 // there's no way to combine the storage of two images. | 248 // there's no way to combine the storage of two images. |
234 image_ = gfx::Image(image_skia_); | 249 image_ = gfx::Image(image_skia_); |
235 | 250 |
236 FOR_EACH_OBSERVER(Observer, observers_, OnExtensionIconImageChanged(this)); | 251 FOR_EACH_OBSERVER(Observer, observers_, OnExtensionIconImageChanged(this)); |
237 } | 252 } |
238 | 253 |
239 void IconImage::Observe(int type, | 254 void IconImage::Observe(int type, |
240 const content::NotificationSource& source, | 255 const content::NotificationSource& source, |
241 const content::NotificationDetails& details) { | 256 const content::NotificationDetails& details) { |
242 DCHECK_EQ(type, extensions::NOTIFICATION_EXTENSION_REMOVED); | 257 DCHECK_EQ(type, extensions::NOTIFICATION_EXTENSION_REMOVED); |
243 | 258 |
244 const Extension* extension = content::Details<const Extension>(details).ptr(); | 259 const Extension* extension = content::Details<const Extension>(details).ptr(); |
245 | 260 |
246 if (extension_ == extension) | 261 if (extension_ == extension) |
247 extension_ = NULL; | 262 extension_ = NULL; |
248 } | 263 } |
249 | 264 |
250 } // namespace extensions | 265 } // namespace extensions |
OLD | NEW |