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

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

Issue 882243002: [Extensions] Make extension actions use gfx::Image over gfx::ImageSkia. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Latest master Created 5 years, 10 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
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_action.h" 5 #include "chrome/browser/extensions/extension_action.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/base64.h" 9 #include "base/base64.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 125
126 bool ExtensionAction::HasPopup(int tab_id) const { 126 bool ExtensionAction::HasPopup(int tab_id) const {
127 return !GetPopupUrl(tab_id).is_empty(); 127 return !GetPopupUrl(tab_id).is_empty();
128 } 128 }
129 129
130 GURL ExtensionAction::GetPopupUrl(int tab_id) const { 130 GURL ExtensionAction::GetPopupUrl(int tab_id) const {
131 return GetValue(&popup_url_, tab_id); 131 return GetValue(&popup_url_, tab_id);
132 } 132 }
133 133
134 void ExtensionAction::SetIcon(int tab_id, const gfx::Image& image) { 134 void ExtensionAction::SetIcon(int tab_id, const gfx::Image& image) {
135 SetValue(&icon_, tab_id, image.AsImageSkia()); 135 SetValue(&icon_, tab_id, image);
136 } 136 }
137 137
138 bool ExtensionAction::ParseIconFromCanvasDictionary( 138 bool ExtensionAction::ParseIconFromCanvasDictionary(
139 const base::DictionaryValue& dict, 139 const base::DictionaryValue& dict,
140 gfx::ImageSkia* icon) { 140 gfx::ImageSkia* icon) {
141 // Try to extract an icon for each known scale. 141 // Try to extract an icon for each known scale.
142 for (size_t i = 0; i < arraysize(kIconSizes); i++) { 142 for (size_t i = 0; i < arraysize(kIconSizes); i++) {
143 const base::BinaryValue* image_data; 143 const base::BinaryValue* image_data;
144 std::string binary_string64; 144 std::string binary_string64;
145 IPC::Message pickle; 145 IPC::Message pickle;
(...skipping 11 matching lines...) Expand all
157 SkBitmap bitmap; 157 SkBitmap bitmap;
158 if (!IPC::ReadParam(&pickle, &iter, &bitmap)) 158 if (!IPC::ReadParam(&pickle, &iter, &bitmap))
159 return false; 159 return false;
160 CHECK(!bitmap.isNull()); 160 CHECK(!bitmap.isNull());
161 float scale = ui::GetScaleForScaleFactor(kIconSizes[i].scale); 161 float scale = ui::GetScaleForScaleFactor(kIconSizes[i].scale);
162 icon->AddRepresentation(gfx::ImageSkiaRep(bitmap, scale)); 162 icon->AddRepresentation(gfx::ImageSkiaRep(bitmap, scale));
163 } 163 }
164 return true; 164 return true;
165 } 165 }
166 166
167 gfx::ImageSkia ExtensionAction::GetExplicitlySetIcon(int tab_id) const { 167 gfx::Image ExtensionAction::GetExplicitlySetIcon(int tab_id) const {
168 return GetValue(&icon_, tab_id); 168 return GetValue(&icon_, tab_id);
169 } 169 }
170 170
171 bool ExtensionAction::SetIsVisible(int tab_id, bool new_visibility) { 171 bool ExtensionAction::SetIsVisible(int tab_id, bool new_visibility) {
172 const bool old_visibility = GetValue(&is_visible_, tab_id); 172 const bool old_visibility = GetValue(&is_visible_, tab_id);
173 173
174 if (old_visibility == new_visibility) 174 if (old_visibility == new_visibility)
175 return false; 175 return false;
176 176
177 SetValue(&is_visible_, tab_id, new_visibility); 177 SetValue(&is_visible_, tab_id, new_visibility);
(...skipping 26 matching lines...) Expand all
204 std::vector<gfx::Image>& icons = declarative_icon_[tab_id][priority]; 204 std::vector<gfx::Image>& icons = declarative_icon_[tab_id][priority];
205 for (std::vector<gfx::Image>::iterator it = icons.begin(); it != icons.end(); 205 for (std::vector<gfx::Image>::iterator it = icons.begin(); it != icons.end();
206 ++it) { 206 ++it) {
207 if (it->AsImageSkia().BackedBySameObjectAs(icon.AsImageSkia())) { 207 if (it->AsImageSkia().BackedBySameObjectAs(icon.AsImageSkia())) {
208 icons.erase(it); 208 icons.erase(it);
209 return; 209 return;
210 } 210 }
211 } 211 }
212 } 212 }
213 213
214 const gfx::ImageSkia ExtensionAction::GetDeclarativeIcon(int tab_id) const { 214 const gfx::Image ExtensionAction::GetDeclarativeIcon(int tab_id) const {
215 if (declarative_icon_.find(tab_id) != declarative_icon_.end() && 215 if (declarative_icon_.find(tab_id) != declarative_icon_.end() &&
216 !declarative_icon_.find(tab_id)->second.rbegin()->second.empty()) { 216 !declarative_icon_.find(tab_id)->second.rbegin()->second.empty()) {
217 return declarative_icon_.find(tab_id)->second.rbegin() 217 return declarative_icon_.find(tab_id)->second.rbegin()->second.back();
218 ->second.back().AsImageSkia();
219 } 218 }
220 return gfx::ImageSkia(); 219 return gfx::Image();
221 } 220 }
222 221
223 void ExtensionAction::ClearAllValuesForTab(int tab_id) { 222 void ExtensionAction::ClearAllValuesForTab(int tab_id) {
224 popup_url_.erase(tab_id); 223 popup_url_.erase(tab_id);
225 title_.erase(tab_id); 224 title_.erase(tab_id);
226 icon_.erase(tab_id); 225 icon_.erase(tab_id);
227 badge_text_.erase(tab_id); 226 badge_text_.erase(tab_id);
228 badge_text_color_.erase(tab_id); 227 badge_text_color_.erase(tab_id);
229 badge_background_color_.erase(tab_id); 228 badge_background_color_.erase(tab_id);
230 is_visible_.erase(tab_id); 229 is_visible_.erase(tab_id);
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 browser_context, 272 browser_context,
274 &extension, 273 &extension,
275 *default_icon(), 274 *default_icon(),
276 GetIconSizeForType(action_type_), 275 GetIconSizeForType(action_type_),
277 *GetDefaultIcon().ToImageSkia(), 276 *GetDefaultIcon().ToImageSkia(),
278 nullptr)); 277 nullptr));
279 } 278 }
280 return default_icon_image_.get(); 279 return default_icon_image_.get();
281 } 280 }
282 281
283 gfx::ImageSkia ExtensionAction::GetDefaultIconImage() const { 282 gfx::Image ExtensionAction::GetDefaultIconImage() const {
284 // If we have a default icon, it should be loaded before trying to use it. 283 // If we have a default icon, it should be loaded before trying to use it.
285 DCHECK(!default_icon_image_ == !default_icon_); 284 DCHECK(!default_icon_image_ == !default_icon_);
286 return default_icon_image_ ? default_icon_image_->image_skia() : 285 return default_icon_image_ ? default_icon_image_->image() : GetDefaultIcon();
287 *GetDefaultIcon().ToImageSkia();
288 } 286 }
289 287
290 bool ExtensionAction::HasPopupUrl(int tab_id) const { 288 bool ExtensionAction::HasPopupUrl(int tab_id) const {
291 return HasValue(popup_url_, tab_id); 289 return HasValue(popup_url_, tab_id);
292 } 290 }
293 291
294 bool ExtensionAction::HasTitle(int tab_id) const { 292 bool ExtensionAction::HasTitle(int tab_id) const {
295 return HasValue(title_, tab_id); 293 return HasValue(title_, tab_id);
296 } 294 }
297 295
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
331 set_id(manifest_data.id); 329 set_id(manifest_data.id);
332 330
333 // Initialize the specified icon set. 331 // Initialize the specified icon set.
334 if (!manifest_data.default_icon.empty()) 332 if (!manifest_data.default_icon.empty())
335 default_icon_.reset(new ExtensionIconSet(manifest_data.default_icon)); 333 default_icon_.reset(new ExtensionIconSet(manifest_data.default_icon));
336 334
337 const ExtensionIconSet& extension_icons = 335 const ExtensionIconSet& extension_icons =
338 extensions::IconsInfo::GetIcons(&extension); 336 extensions::IconsInfo::GetIcons(&extension);
339 // Look for any other icons. 337 // Look for any other icons.
340 std::string largest_icon = extension_icons.Get( 338 std::string largest_icon = extension_icons.Get(
341 extension_misc::EXTENSION_ICON_GIGANTOR, 339 extension_misc::EXTENSION_ICON_GIGANTOR, ExtensionIconSet::MATCH_SMALLER);
342 ExtensionIconSet::MATCH_SMALLER);
343 340
344 if (!largest_icon.empty()) { 341 if (!largest_icon.empty()) {
345 // We found an icon to use, so create an icon set if one doesn't exist. 342 // We found an icon to use, so create an icon set if one doesn't exist.
346 if (!default_icon_) 343 if (!default_icon_)
347 default_icon_.reset(new ExtensionIconSet()); 344 default_icon_.reset(new ExtensionIconSet());
348 int largest_icon_size = extension_icons.GetIconSizeFromPath(largest_icon); 345 int largest_icon_size = extension_icons.GetIconSizeFromPath(largest_icon);
349 // Replace any missing extension action icons with the largest icon 346 // Replace any missing extension action icons with the largest icon
350 // retrieved from |extension|'s manifest so long as the largest icon is 347 // retrieved from |extension|'s manifest so long as the largest icon is
351 // larger than the current key. 348 // larger than the current key.
352 for (int i = extension_misc::kNumExtensionActionIconSizes - 1; 349 for (int i = extension_misc::kNumExtensionActionIconSizes - 1; i >= 0;
353 i >= 0; --i) { 350 --i) {
354 int size = extension_misc::kExtensionActionIconSizes[i].size; 351 int size = extension_misc::kExtensionActionIconSizes[i].size;
355 if (default_icon_->Get(size, ExtensionIconSet::MATCH_BIGGER).empty() 352 if (default_icon_->Get(size, ExtensionIconSet::MATCH_BIGGER).empty() &&
356 && largest_icon_size > size) { 353 largest_icon_size > size) {
357 default_icon_->Add(size, largest_icon); 354 default_icon_->Add(size, largest_icon);
358 break; 355 break;
359 } 356 }
360 } 357 }
361 } 358 }
362 } 359 }
363 360
364 // Determines which icon would be returned by |GetIcon|, and returns its width. 361 // Determines which icon would be returned by |GetIcon|, and returns its width.
365 int ExtensionAction::GetIconWidth(int tab_id) const { 362 int ExtensionAction::GetIconWidth(int tab_id) const {
366 // If icon has been set, return its width. 363 // If icon has been set, return its width.
367 gfx::ImageSkia icon = GetValue(&icon_, tab_id); 364 gfx::Image icon = GetValue(&icon_, tab_id);
368 if (!icon.isNull()) 365 if (!icon.IsEmpty())
369 return icon.width(); 366 return icon.Width();
370 // If there is a default icon, the icon width will be set depending on our 367 // If there is a default icon, the icon width will be set depending on our
371 // action type. 368 // action type.
372 if (default_icon_) 369 if (default_icon_)
373 return GetIconSizeForType(action_type()); 370 return GetIconSizeForType(action_type());
374 371
375 // If no icon has been set and there is no default icon, we need favicon 372 // If no icon has been set and there is no default icon, we need favicon
376 // width. 373 // width.
377 return ui::ResourceBundle::GetSharedInstance().GetImageNamed( 374 return ui::ResourceBundle::GetSharedInstance().GetImageNamed(
378 IDR_EXTENSIONS_FAVICON).Width(); 375 IDR_EXTENSIONS_FAVICON).Width();
379 } 376 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_action.h ('k') | chrome/browser/extensions/extension_action_icon_factory.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698