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 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 default_icon_(gfx::ImageSkiaOperations::CreateResizedImage( | 138 default_icon_(gfx::ImageSkiaOperations::CreateResizedImage( |
139 default_icon, | 139 default_icon, |
140 skia::ImageOperations::RESIZE_BEST, | 140 skia::ImageOperations::RESIZE_BEST, |
141 gfx::Size(resource_size_in_dip, resource_size_in_dip))), | 141 gfx::Size(resource_size_in_dip, resource_size_in_dip))), |
142 weak_ptr_factory_(this) { | 142 weak_ptr_factory_(this) { |
143 if (observer) | 143 if (observer) |
144 AddObserver(observer); | 144 AddObserver(observer); |
145 gfx::Size resource_size(resource_size_in_dip, resource_size_in_dip); | 145 gfx::Size resource_size(resource_size_in_dip, resource_size_in_dip); |
146 source_ = new Source(this, resource_size); | 146 source_ = new Source(this, resource_size); |
147 image_skia_ = gfx::ImageSkia(source_, resource_size); | 147 image_skia_ = gfx::ImageSkia(source_, resource_size); |
| 148 image_ = gfx::Image(image_skia_); |
148 | 149 |
149 registrar_.Add(this, | 150 registrar_.Add(this, |
150 extensions::NOTIFICATION_EXTENSION_REMOVED, | 151 extensions::NOTIFICATION_EXTENSION_REMOVED, |
151 content::NotificationService::AllSources()); | 152 content::NotificationService::AllSources()); |
152 } | 153 } |
153 | 154 |
154 void IconImage::AddObserver(Observer* observer) { | 155 void IconImage::AddObserver(Observer* observer) { |
155 observers_.AddObserver(observer); | 156 observers_.AddObserver(observer); |
156 } | 157 } |
157 | 158 |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
219 return; | 220 return; |
220 | 221 |
221 gfx::ImageSkiaRep rep = image->GetRepresentation(scale); | 222 gfx::ImageSkiaRep rep = image->GetRepresentation(scale); |
222 DCHECK(!rep.is_null()); | 223 DCHECK(!rep.is_null()); |
223 DCHECK_EQ(scale, rep.scale()); | 224 DCHECK_EQ(scale, rep.scale()); |
224 | 225 |
225 // Remove old representation if there is one. | 226 // Remove old representation if there is one. |
226 image_skia_.RemoveRepresentation(scale); | 227 image_skia_.RemoveRepresentation(scale); |
227 image_skia_.AddRepresentation(rep); | 228 image_skia_.AddRepresentation(rep); |
228 | 229 |
| 230 // 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 |
| 232 // representations stored on |image_| will be deleted, but unfortunately |
| 233 // there's no way to combine the storage of two images. |
| 234 image_ = gfx::Image(image_skia_); |
| 235 |
229 FOR_EACH_OBSERVER(Observer, observers_, OnExtensionIconImageChanged(this)); | 236 FOR_EACH_OBSERVER(Observer, observers_, OnExtensionIconImageChanged(this)); |
230 } | 237 } |
231 | 238 |
232 void IconImage::Observe(int type, | 239 void IconImage::Observe(int type, |
233 const content::NotificationSource& source, | 240 const content::NotificationSource& source, |
234 const content::NotificationDetails& details) { | 241 const content::NotificationDetails& details) { |
235 DCHECK_EQ(type, extensions::NOTIFICATION_EXTENSION_REMOVED); | 242 DCHECK_EQ(type, extensions::NOTIFICATION_EXTENSION_REMOVED); |
236 | 243 |
237 const Extension* extension = content::Details<const Extension>(details).ptr(); | 244 const Extension* extension = content::Details<const Extension>(details).ptr(); |
238 | 245 |
239 if (extension_ == extension) | 246 if (extension_ == extension) |
240 extension_ = NULL; | 247 extension_ = NULL; |
241 } | 248 } |
242 | 249 |
243 } // namespace extensions | 250 } // namespace extensions |
OLD | NEW |