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

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

Issue 10855154: Update browserAction.setIcon and pageAction.setIcon for hidpi (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: nits 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/common/extensions/extension_action.h" 5 #include "chrome/common/extensions/extension_action.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "chrome/common/badge_util.h" 10 #include "chrome/common/badge_util.h"
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after
297 if (!icon.IsEmpty()) 297 if (!icon.IsEmpty())
298 path_to_icon_cache_.insert(std::make_pair(path, *icon.ToImageSkia())); 298 path_to_icon_cache_.insert(std::make_pair(path, *icon.ToImageSkia()));
299 } 299 }
300 300
301 void ExtensionAction::SetIcon(int tab_id, const gfx::Image& image) { 301 void ExtensionAction::SetIcon(int tab_id, const gfx::Image& image) {
302 SetValue(&icon_, tab_id, image.AsImageSkia()); 302 SetValue(&icon_, tab_id, image.AsImageSkia());
303 } 303 }
304 304
305 gfx::Image ExtensionAction::GetIcon(int tab_id) const { 305 gfx::Image ExtensionAction::GetIcon(int tab_id) const {
306 // Check if a specific icon is set for this tab. 306 // Check if a specific icon is set for this tab.
307 gfx::ImageSkia icon = GetValue(&icon_, tab_id); 307 gfx::ImageSkia icon = GetExplicitlySetIcon(tab_id);
308 if (icon.empty()) { 308 if (icon.empty()) {
309 // Need to find an icon from a path. 309 // Need to find an icon from a path.
310 const std::string* path = NULL; 310 const std::string* path = NULL;
311 // Check if one of the elements of icon_path() was selected. 311 // Check if one of the elements of icon_path() was selected.
312 int icon_index = GetIconIndex(tab_id); 312 int icon_index = GetIconIndex(tab_id);
313 if (icon_index >= 0) { 313 if (icon_index >= 0) {
314 path = &icon_paths()->at(icon_index); 314 path = &icon_paths()->at(icon_index);
315 } else { 315 } else {
316 // Otherwise, use the default icon. 316 // Otherwise, use the default icon.
317 path = &default_icon_path(); 317 path = &default_icon_path();
318 } 318 }
319 319
320 std::map<std::string, gfx::ImageSkia>::const_iterator cached_icon = 320 std::map<std::string, gfx::ImageSkia>::const_iterator cached_icon =
321 path_to_icon_cache_.find(*path); 321 path_to_icon_cache_.find(*path);
322 if (cached_icon != path_to_icon_cache_.end()) { 322 if (cached_icon != path_to_icon_cache_.end()) {
323 icon = cached_icon->second; 323 icon = cached_icon->second;
324 } else { 324 } else {
325 icon = *ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( 325 icon = *ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
326 IDR_EXTENSIONS_FAVICON); 326 IDR_EXTENSIONS_FAVICON);
327 } 327 }
328 } 328 }
329 329
330 if (GetValue(&appearance_, tab_id) == WANTS_ATTENTION) 330 if (GetValue(&appearance_, tab_id) == WANTS_ATTENTION)
331 icon = gfx::ImageSkia(new GetAttentionImageSource(icon), icon.size()); 331 icon = gfx::ImageSkia(new GetAttentionImageSource(icon), icon.size());
332 332
333 return gfx::Image(ApplyIconAnimation(tab_id, icon)); 333 return gfx::Image(ApplyIconAnimation(tab_id, icon));
334 } 334 }
335 335
336 gfx::ImageSkia ExtensionAction::GetExplicitlySetIcon(int tab_id) const {
337 return GetValue(&icon_, tab_id);
338 }
339
336 void ExtensionAction::SetIconIndex(int tab_id, int index) { 340 void ExtensionAction::SetIconIndex(int tab_id, int index) {
337 if (static_cast<size_t>(index) >= icon_paths_.size()) { 341 if (static_cast<size_t>(index) >= icon_paths_.size()) {
338 NOTREACHED(); 342 NOTREACHED();
339 return; 343 return;
340 } 344 }
341 SetValue(&icon_index_, tab_id, index); 345 SetValue(&icon_index_, tab_id, index);
342 } 346 }
343 347
344 bool ExtensionAction::SetAppearance(int tab_id, Appearance new_appearance) { 348 bool ExtensionAction::SetAppearance(int tab_id, Appearance new_appearance) {
345 const Appearance old_appearance = GetValue(&appearance_, tab_id); 349 const Appearance old_appearance = GetValue(&appearance_, tab_id);
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
521 new AnimatedIconImageSource(icon, animation_wrapper->animation()), 525 new AnimatedIconImageSource(icon, animation_wrapper->animation()),
522 icon.size()); 526 icon.size());
523 } 527 }
524 528
525 void ExtensionAction::RunIconAnimation(int tab_id) { 529 void ExtensionAction::RunIconAnimation(int tab_id) {
526 IconAnimationWrapper* icon_animation = 530 IconAnimationWrapper* icon_animation =
527 new IconAnimationWrapper(); 531 new IconAnimationWrapper();
528 icon_animation_[tab_id] = icon_animation->AsWeakPtr(); 532 icon_animation_[tab_id] = icon_animation->AsWeakPtr();
529 icon_animation->animation()->Start(); 533 icon_animation->animation()->Start();
530 } 534 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698