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 "base/bind.h" | 9 #include "base/bind.h" |
10 #include "chrome/browser/extensions/image_loader.h" | 10 #include "chrome/browser/extensions/image_loader.h" |
(...skipping 24 matching lines...) Expand all Loading... |
35 // the |ImageLoader| finishes. The image representation is chosen the same | 35 // the |ImageLoader| finishes. The image representation is chosen the same |
36 // way as in the synchronous case. The observer is notified of the image | 36 // way as in the synchronous case. The observer is notified of the image |
37 // change, unless the added image representation is transparent (in which | 37 // change, unless the added image representation is transparent (in which |
38 // case the image had already contained the appropriate image | 38 // case the image had already contained the appropriate image |
39 // representation). | 39 // representation). |
40 | 40 |
41 namespace { | 41 namespace { |
42 | 42 |
43 const int kMatchBiggerTreshold = 32; | 43 const int kMatchBiggerTreshold = 32; |
44 | 44 |
45 ExtensionResource GetExtensionIconResource( | 45 extensions::ExtensionResource GetExtensionIconResource( |
46 const extensions::Extension* extension, | 46 const extensions::Extension* extension, |
47 const ExtensionIconSet& icons, | 47 const ExtensionIconSet& icons, |
48 int size, | 48 int size, |
49 ExtensionIconSet::MatchType match_type) { | 49 ExtensionIconSet::MatchType match_type) { |
50 std::string path = icons.Get(size, match_type); | 50 std::string path = icons.Get(size, match_type); |
51 if (path.empty()) | 51 if (path.empty()) |
52 return ExtensionResource(); | 52 return extensions::ExtensionResource(); |
53 | 53 |
54 return extension->GetResource(path); | 54 return extension->GetResource(path); |
55 } | 55 } |
56 | 56 |
57 class BlankImageSource : public gfx::CanvasImageSource { | 57 class BlankImageSource : public gfx::CanvasImageSource { |
58 public: | 58 public: |
59 explicit BlankImageSource(const gfx::Size& size_in_dip) | 59 explicit BlankImageSource(const gfx::Size& size_in_dip) |
60 : CanvasImageSource(size_in_dip, /*is_opaque =*/ false) { | 60 : CanvasImageSource(size_in_dip, /*is_opaque =*/ false) { |
61 } | 61 } |
62 virtual ~BlankImageSource() {} | 62 virtual ~BlankImageSource() {} |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 gfx::ImageSkiaRep IconImage::LoadImageForScaleFactor( | 160 gfx::ImageSkiaRep IconImage::LoadImageForScaleFactor( |
161 ui::ScaleFactor scale_factor) { | 161 ui::ScaleFactor scale_factor) { |
162 // Do nothing if extension is unloaded. | 162 // Do nothing if extension is unloaded. |
163 if (!extension_) | 163 if (!extension_) |
164 return gfx::ImageSkiaRep(); | 164 return gfx::ImageSkiaRep(); |
165 | 165 |
166 const float scale = ui::GetScaleFactorScale(scale_factor); | 166 const float scale = ui::GetScaleFactorScale(scale_factor); |
167 const int resource_size_in_pixel = | 167 const int resource_size_in_pixel = |
168 static_cast<int>(resource_size_in_dip_ * scale); | 168 static_cast<int>(resource_size_in_dip_ * scale); |
169 | 169 |
170 ExtensionResource resource; | 170 extensions::ExtensionResource resource; |
171 | 171 |
172 // Find extension resource for non bundled component extensions. | 172 // Find extension resource for non bundled component extensions. |
173 // We try loading bigger image only if resource size is >= 32. | 173 // We try loading bigger image only if resource size is >= 32. |
174 if (resource_size_in_pixel >= kMatchBiggerTreshold) { | 174 if (resource_size_in_pixel >= kMatchBiggerTreshold) { |
175 resource = GetExtensionIconResource(extension_, icon_set_, | 175 resource = GetExtensionIconResource(extension_, icon_set_, |
176 resource_size_in_pixel, ExtensionIconSet::MATCH_BIGGER); | 176 resource_size_in_pixel, ExtensionIconSet::MATCH_BIGGER); |
177 } | 177 } |
178 | 178 |
179 // If resource is not found by now, try matching smaller one. | 179 // If resource is not found by now, try matching smaller one. |
180 if (resource.empty()) { | 180 if (resource.empty()) { |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
230 DCHECK_EQ(type, chrome::NOTIFICATION_EXTENSION_UNLOADED); | 230 DCHECK_EQ(type, chrome::NOTIFICATION_EXTENSION_UNLOADED); |
231 | 231 |
232 const Extension* extension = | 232 const Extension* extension = |
233 content::Details<extensions::UnloadedExtensionInfo>(details)->extension; | 233 content::Details<extensions::UnloadedExtensionInfo>(details)->extension; |
234 | 234 |
235 if (extension_ == extension) | 235 if (extension_ == extension) |
236 extension_ = NULL; | 236 extension_ = NULL; |
237 } | 237 } |
238 | 238 |
239 } // namespace extensions | 239 } // namespace extensions |
OLD | NEW |