| 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" |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 } | 71 } |
| 72 | 72 |
| 73 DISALLOW_COPY_AND_ASSIGN(BlankImageSource); | 73 DISALLOW_COPY_AND_ASSIGN(BlankImageSource); |
| 74 }; | 74 }; |
| 75 | 75 |
| 76 } // namespace | 76 } // namespace |
| 77 | 77 |
| 78 namespace extensions { | 78 namespace extensions { |
| 79 | 79 |
| 80 //////////////////////////////////////////////////////////////////////////////// | 80 //////////////////////////////////////////////////////////////////////////////// |
| 81 // ExtensionIconImage::Source | 81 // IconImage::Source |
| 82 | 82 |
| 83 class IconImage::Source : public gfx::ImageSkiaSource { | 83 class IconImage::Source : public gfx::ImageSkiaSource { |
| 84 public: | 84 public: |
| 85 Source(IconImage* host, const gfx::Size& size_in_dip); | 85 Source(IconImage* host, const gfx::Size& size_in_dip); |
| 86 virtual ~Source(); | 86 virtual ~Source(); |
| 87 | 87 |
| 88 void ResetHost(); | 88 void ResetHost(); |
| 89 | 89 |
| 90 private: | 90 private: |
| 91 // gfx::ImageSkiaSource overrides: | 91 // gfx::ImageSkiaSource overrides: |
| (...skipping 29 matching lines...) Expand all Loading... |
| 121 if (host_) | 121 if (host_) |
| 122 representation = host_->LoadImageForScaleFactor(scale_factor); | 122 representation = host_->LoadImageForScaleFactor(scale_factor); |
| 123 | 123 |
| 124 if (!representation.is_null()) | 124 if (!representation.is_null()) |
| 125 return representation; | 125 return representation; |
| 126 | 126 |
| 127 return blank_image_.GetRepresentation(scale_factor); | 127 return blank_image_.GetRepresentation(scale_factor); |
| 128 } | 128 } |
| 129 | 129 |
| 130 //////////////////////////////////////////////////////////////////////////////// | 130 //////////////////////////////////////////////////////////////////////////////// |
| 131 // ExtensionIconImage | 131 // IconImage |
| 132 | 132 |
| 133 IconImage::IconImage( | 133 IconImage::IconImage( |
| 134 const Extension* extension, | 134 const Extension* extension, |
| 135 const ExtensionIconSet& icon_set, | 135 const ExtensionIconSet& icon_set, |
| 136 int resource_size_in_dip, | 136 int resource_size_in_dip, |
| 137 const gfx::ImageSkia& default_icon, | 137 const gfx::ImageSkia& default_icon, |
| 138 Observer* observer) | 138 Observer* observer) |
| 139 : extension_(extension), | 139 : extension_(extension), |
| 140 icon_set_(icon_set), | 140 icon_set_(icon_set), |
| 141 resource_size_in_dip_(resource_size_in_dip), | 141 resource_size_in_dip_(resource_size_in_dip), |
| (...skipping 17 matching lines...) Expand all Loading... |
| 159 ui::ScaleFactor scale_factor) { | 159 ui::ScaleFactor scale_factor) { |
| 160 // Do nothing if extension is unloaded. | 160 // Do nothing if extension is unloaded. |
| 161 if (!extension_) | 161 if (!extension_) |
| 162 return gfx::ImageSkiaRep(); | 162 return gfx::ImageSkiaRep(); |
| 163 | 163 |
| 164 const float scale = ui::GetScaleFactorScale(scale_factor); | 164 const float scale = ui::GetScaleFactorScale(scale_factor); |
| 165 const int resource_size_in_pixel = | 165 const int resource_size_in_pixel = |
| 166 static_cast<int>(resource_size_in_dip_ * scale); | 166 static_cast<int>(resource_size_in_dip_ * scale); |
| 167 | 167 |
| 168 ExtensionResource resource; | 168 ExtensionResource resource; |
| 169 // We try loading bigger image only if resource size is >= 32. | 169 |
| 170 if (resource_size_in_pixel >= kMatchBiggerTreshold) { | 170 // Find extension resource for non bundled component extensions. |
| 171 resource = GetExtensionIconResource(extension_, icon_set_, | 171 if (!ImageLoadingTracker::IsSpecialBundledExtensionId(extension_->id())) { |
| 172 resource_size_in_pixel, ExtensionIconSet::MATCH_BIGGER); | 172 // We try loading bigger image only if resource size is >= 32. |
| 173 if (resource_size_in_pixel >= kMatchBiggerTreshold) { |
| 174 resource = GetExtensionIconResource(extension_, icon_set_, |
| 175 resource_size_in_pixel, ExtensionIconSet::MATCH_BIGGER); |
| 176 } |
| 177 |
| 178 // If resource is not found by now, try matching smaller one. |
| 179 if (resource.empty()) { |
| 180 resource = GetExtensionIconResource(extension_, icon_set_, |
| 181 resource_size_in_pixel, ExtensionIconSet::MATCH_SMALLER); |
| 182 } |
| 183 |
| 184 // If there is no resource found, return default icon. |
| 185 if (resource.empty()) |
| 186 return default_icon_.GetRepresentation(scale_factor); |
| 173 } | 187 } |
| 174 | 188 |
| 175 // If resource is not found by now, try matching smaller one. | |
| 176 if (resource.empty()) { | |
| 177 resource = GetExtensionIconResource(extension_, icon_set_, | |
| 178 resource_size_in_pixel, ExtensionIconSet::MATCH_SMALLER); | |
| 179 } | |
| 180 | |
| 181 // If there is no resource found, return default icon. | |
| 182 if (resource.empty()) | |
| 183 return default_icon_.GetRepresentation(scale_factor); | |
| 184 | |
| 185 int id = tracker_.next_id(); | 189 int id = tracker_.next_id(); |
| 186 load_map_[id].scale_factor = scale_factor; | 190 load_map_[id].scale_factor = scale_factor; |
| 187 load_map_[id].is_async = false; | 191 load_map_[id].is_async = false; |
| 188 | 192 |
| 189 std::vector<ImageLoadingTracker::ImageRepresentation> info_list; | 193 std::vector<ImageLoadingTracker::ImageRepresentation> info_list; |
| 190 info_list.push_back(ImageLoadingTracker::ImageRepresentation( | 194 info_list.push_back(ImageLoadingTracker::ImageRepresentation( |
| 191 resource, | 195 resource, |
| 192 ImageLoadingTracker::ImageRepresentation::RESIZE_WHEN_LARGER, | 196 ImageLoadingTracker::ImageRepresentation::RESIZE_WHEN_LARGER, |
| 193 gfx::Size(resource_size_in_dip_, resource_size_in_dip_).Scale(scale), | 197 gfx::Size(resource_size_in_dip_, resource_size_in_dip_).Scale(scale), |
| 194 scale_factor)); | 198 scale_factor)); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 246 DCHECK_EQ(type, chrome::NOTIFICATION_EXTENSION_UNLOADED); | 250 DCHECK_EQ(type, chrome::NOTIFICATION_EXTENSION_UNLOADED); |
| 247 | 251 |
| 248 const Extension* extension = | 252 const Extension* extension = |
| 249 content::Details<extensions::UnloadedExtensionInfo>(details)->extension; | 253 content::Details<extensions::UnloadedExtensionInfo>(details)->extension; |
| 250 | 254 |
| 251 if (extension_ == extension) | 255 if (extension_ == extension) |
| 252 extension_ = NULL; | 256 extension_ = NULL; |
| 253 } | 257 } |
| 254 | 258 |
| 255 } // namespace extensions | 259 } // namespace extensions |
| OLD | NEW |