Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(70)

Side by Side Diff: chrome/browser/extensions/extension_icon_image.cc

Issue 10868003: chromeos: Fix pixelated icons in app list and launcher (part 3) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 16 matching lines...) Expand all
27 return ExtensionResource(); 27 return ExtensionResource();
28 28
29 return extension->GetResource(path); 29 return extension->GetResource(path);
30 } 30 }
31 31
32 } // namespace 32 } // namespace
33 33
34 namespace extensions { 34 namespace extensions {
35 35
36 //////////////////////////////////////////////////////////////////////////////// 36 ////////////////////////////////////////////////////////////////////////////////
37 // ExtensionIconImage::Source 37 // IconImage::Source
38 38
39 class IconImage::Source : public gfx::ImageSkiaSource { 39 class IconImage::Source : public gfx::ImageSkiaSource {
40 public: 40 public:
41 explicit Source(IconImage* host); 41 explicit Source(IconImage* host);
42 virtual ~Source(); 42 virtual ~Source();
43 43
44 void ResetHost(); 44 void ResetHost();
45 45
46 private: 46 private:
47 // gfx::ImageSkiaSource overrides: 47 // gfx::ImageSkiaSource overrides:
(...skipping 16 matching lines...) Expand all
64 } 64 }
65 65
66 gfx::ImageSkiaRep IconImage::Source::GetImageForScale( 66 gfx::ImageSkiaRep IconImage::Source::GetImageForScale(
67 ui::ScaleFactor scale_factor) { 67 ui::ScaleFactor scale_factor) {
68 if (host_) 68 if (host_)
69 host_->LoadImageForScaleFactor(scale_factor); 69 host_->LoadImageForScaleFactor(scale_factor);
70 return gfx::ImageSkiaRep(); 70 return gfx::ImageSkiaRep();
71 } 71 }
72 72
73 //////////////////////////////////////////////////////////////////////////////// 73 ////////////////////////////////////////////////////////////////////////////////
74 // ExtensionIconImage 74 // IconImage
75 75
76 IconImage::IconImage( 76 IconImage::IconImage(
77 const Extension* extension, 77 const Extension* extension,
78 const ExtensionIconSet& icon_set, 78 const ExtensionIconSet& icon_set,
79 int resource_size_in_dip, 79 int resource_size_in_dip,
80 Observer* observer) 80 Observer* observer)
81 : extension_(extension), 81 : extension_(extension),
82 icon_set_(icon_set), 82 icon_set_(icon_set),
83 resource_size_in_dip_(resource_size_in_dip), 83 resource_size_in_dip_(resource_size_in_dip),
84 desired_size_in_dip_(resource_size_in_dip, resource_size_in_dip), 84 desired_size_in_dip_(resource_size_in_dip, resource_size_in_dip),
85 observer_(observer), 85 observer_(observer),
86 source_(NULL), 86 source_(NULL),
87 ALLOW_THIS_IN_INITIALIZER_LIST(tracker_(this)) { 87 ALLOW_THIS_IN_INITIALIZER_LIST(tracker_(this)) {
88 source_ = new Source(this); 88 source_ = new Source(this);
89 image_skia_ = gfx::ImageSkia(source_, desired_size_in_dip_); 89 image_skia_ = gfx::ImageSkia(source_, desired_size_in_dip_);
90 90
91 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, 91 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED,
92 content::NotificationService::AllSources()); 92 content::NotificationService::AllSources());
93 } 93 }
94 94
95 IconImage::~IconImage() { 95 IconImage::~IconImage() {
96 // |source_| could be NULL if resource does not exist. 96 // |source_| could be NULL if resource does not exist.
97 if (source_) 97 if (source_)
98 source_->ResetHost(); 98 source_->ResetHost();
99 } 99 }
100 100
101 void IconImage::SetRepresentation(const gfx::ImageSkiaRep& rep) {
102 image_skia_.AddRepresentation(rep);
103 if (observer_)
104 observer_->OnExtensionIconImageChanged(this);
105 }
106
101 void IconImage::LoadImageForScaleFactor(ui::ScaleFactor scale_factor) { 107 void IconImage::LoadImageForScaleFactor(ui::ScaleFactor scale_factor) {
102 // Do nothing if extension is unloaded. 108 // Do nothing if extension is unloaded.
103 if (!extension_) 109 if (!extension_)
104 return; 110 return;
105 111
106 const float scale = ui::GetScaleFactorScale(scale_factor); 112 const float scale = ui::GetScaleFactorScale(scale_factor);
107 const int resource_size_in_pixel = 113 const int resource_size_in_pixel =
108 static_cast<int>(resource_size_in_dip_ * scale); 114 static_cast<int>(resource_size_in_dip_ * scale);
109 115
110 ExtensionResource resource; 116 ExtensionResource resource;
111 // We try loading bigger image only if resource size is >= 32.
112 if (resource_size_in_pixel >= kMatchBiggerTreshold) {
113 resource = GetExtensionIconResource(extension_, icon_set_,
114 resource_size_in_pixel, ExtensionIconSet::MATCH_BIGGER);
115 }
116 117
117 // If resource is not found by now, try matching smaller one. 118 // Find extension resource for non bundled component extensions.
118 if (resource.empty()) { 119 if (!ImageLoadingTracker::IsSpecialBundledExtensionId(extension_->id())) {
Aaron Boodman 2012/08/30 06:09:20 I hate this hack so much. It's probably a differen
119 resource = GetExtensionIconResource(extension_, icon_set_, 120 // We try loading bigger image only if resource size is >= 32.
120 resource_size_in_pixel, ExtensionIconSet::MATCH_SMALLER); 121 if (resource_size_in_pixel >= kMatchBiggerTreshold) {
121 } 122 resource = GetExtensionIconResource(extension_, icon_set_,
123 resource_size_in_pixel, ExtensionIconSet::MATCH_BIGGER);
124 }
122 125
123 // If there is no resource found, bail out and notify observer of failure. 126 // If resource is not found by now, try matching smaller one.
124 if (resource.empty()) { 127 if (resource.empty()) {
125 if (observer_) 128 resource = GetExtensionIconResource(extension_, icon_set_,
126 observer_->OnIconImageLoadFailed(this, scale_factor); 129 resource_size_in_pixel, ExtensionIconSet::MATCH_SMALLER);
127 return; 130 }
131
132 // If there is no resource found, bail out and notify observer of failure.
133 if (resource.empty()) {
134 if (observer_)
135 observer_->OnIconImageLoadFailed(this, scale_factor);
136 return;
137 }
128 } 138 }
129 139
130 int id = tracker_.next_id(); 140 int id = tracker_.next_id();
131 load_map_[id] = scale_factor; 141 load_map_[id] = scale_factor;
132 142
133 std::vector<ImageLoadingTracker::ImageRepresentation> info_list; 143 std::vector<ImageLoadingTracker::ImageRepresentation> info_list;
134 info_list.push_back(ImageLoadingTracker::ImageRepresentation( 144 info_list.push_back(ImageLoadingTracker::ImageRepresentation(
135 resource, 145 resource,
136 ImageLoadingTracker::ImageRepresentation::RESIZE_WHEN_LARGER, 146 ImageLoadingTracker::ImageRepresentation::RESIZE_WHEN_LARGER,
137 desired_size_in_dip_.Scale(scale), 147 desired_size_in_dip_.Scale(scale),
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 DCHECK_EQ(type, chrome::NOTIFICATION_EXTENSION_UNLOADED); 181 DCHECK_EQ(type, chrome::NOTIFICATION_EXTENSION_UNLOADED);
172 182
173 const Extension* extension = 183 const Extension* extension =
174 content::Details<extensions::UnloadedExtensionInfo>(details)->extension; 184 content::Details<extensions::UnloadedExtensionInfo>(details)->extension;
175 185
176 if (extension_ == extension) 186 if (extension_ == extension)
177 extension_ = NULL; 187 extension_ = NULL;
178 } 188 }
179 189
180 } // namespace extensions 190 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698