| 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" |
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 216 image_in.IsEmpty() ? &default_icon_ : image_in.ToImageSkia(); | 216 image_in.IsEmpty() ? &default_icon_ : image_in.ToImageSkia(); |
| 217 | 217 |
| 218 // Maybe default icon was not set. | 218 // Maybe default icon was not set. |
| 219 if (image->isNull()) | 219 if (image->isNull()) |
| 220 return; | 220 return; |
| 221 | 221 |
| 222 gfx::ImageSkiaRep rep = image->GetRepresentation(scale); | 222 gfx::ImageSkiaRep rep = image->GetRepresentation(scale); |
| 223 DCHECK(!rep.is_null()); | 223 DCHECK(!rep.is_null()); |
| 224 DCHECK_EQ(scale, rep.scale()); | 224 DCHECK_EQ(scale, rep.scale()); |
| 225 | 225 |
| 226 // Remove old representation if there is one. | 226 // Remove fractional scale image representations as they may have become |
| 227 // stale here. These images are generated by ImageSkia on request from |
| 228 // supported scales like 1x, 2x, etc. |
| 229 // TODO(oshima) |
| 230 // A better approach might be to set the |image_| member using the ImageSkia |
| 231 // copy from the image passed in and set the |image_skia_| member using |
| 232 // image_.ToImageSkia(). However that does not work correctly as the |
| 233 // ImageSkia from the image does not contain a source which breaks requests |
| 234 // for scaled images. |
| 235 std::vector<gfx::ImageSkiaRep> reps = image_skia_.image_reps(); |
| 236 for (const auto rep : reps) { |
| 237 if (!gfx::ImageSkia::IsSupportedScale(rep.scale())) |
| 238 image_skia_.RemoveRepresentation(rep.scale()); |
| 239 } |
| 240 |
| 227 image_skia_.RemoveRepresentation(scale); | 241 image_skia_.RemoveRepresentation(scale); |
| 228 image_skia_.AddRepresentation(rep); | 242 image_skia_.AddRepresentation(rep); |
| 229 | 243 |
| 230 // Update the image to use the updated image skia. | 244 // 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 | 245 // 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 | 246 // representations stored on |image_| will be deleted, but unfortunately |
| 233 // there's no way to combine the storage of two images. | 247 // there's no way to combine the storage of two images. |
| 234 image_ = gfx::Image(image_skia_); | 248 image_ = gfx::Image(image_skia_); |
| 235 | 249 |
| 236 FOR_EACH_OBSERVER(Observer, observers_, OnExtensionIconImageChanged(this)); | 250 FOR_EACH_OBSERVER(Observer, observers_, OnExtensionIconImageChanged(this)); |
| 237 } | 251 } |
| 238 | 252 |
| 239 void IconImage::Observe(int type, | 253 void IconImage::Observe(int type, |
| 240 const content::NotificationSource& source, | 254 const content::NotificationSource& source, |
| 241 const content::NotificationDetails& details) { | 255 const content::NotificationDetails& details) { |
| 242 DCHECK_EQ(type, extensions::NOTIFICATION_EXTENSION_REMOVED); | 256 DCHECK_EQ(type, extensions::NOTIFICATION_EXTENSION_REMOVED); |
| 243 | 257 |
| 244 const Extension* extension = content::Details<const Extension>(details).ptr(); | 258 const Extension* extension = content::Details<const Extension>(details).ptr(); |
| 245 | 259 |
| 246 if (extension_ == extension) | 260 if (extension_ == extension) |
| 247 extension_ = NULL; | 261 extension_ = NULL; |
| 248 } | 262 } |
| 249 | 263 |
| 250 } // namespace extensions | 264 } // namespace extensions |
| OLD | NEW |