| 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_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" |
| 11 #include "chrome/common/badge_util.h" | |
| 12 #include "chrome/common/icon_with_badge_image_source.h" | |
| 13 #include "extensions/browser/extension_icon_image.h" | 11 #include "extensions/browser/extension_icon_image.h" |
| 14 #include "extensions/browser/extension_icon_placeholder.h" | 12 #include "extensions/browser/extension_icon_placeholder.h" |
| 15 #include "extensions/common/constants.h" | 13 #include "extensions/common/constants.h" |
| 16 #include "extensions/common/extension_icon_set.h" | 14 #include "extensions/common/extension_icon_set.h" |
| 17 #include "extensions/common/feature_switch.h" | 15 #include "extensions/common/feature_switch.h" |
| 18 #include "extensions/common/manifest_handlers/icons_handler.h" | 16 #include "extensions/common/manifest_handlers/icons_handler.h" |
| 19 #include "grit/theme_resources.h" | 17 #include "grit/theme_resources.h" |
| 20 #include "grit/ui_resources.h" | 18 #include "grit/ui_resources.h" |
| 21 #include "ipc/ipc_message.h" | 19 #include "ipc/ipc_message.h" |
| 22 #include "ipc/ipc_message_utils.h" | 20 #include "ipc/ipc_message_utils.h" |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 230 badge_text_.erase(tab_id); | 228 badge_text_.erase(tab_id); |
| 231 badge_text_color_.erase(tab_id); | 229 badge_text_color_.erase(tab_id); |
| 232 badge_background_color_.erase(tab_id); | 230 badge_background_color_.erase(tab_id); |
| 233 is_visible_.erase(tab_id); | 231 is_visible_.erase(tab_id); |
| 234 // TODO(jyasskin): Erase the element from declarative_show_count_ | 232 // TODO(jyasskin): Erase the element from declarative_show_count_ |
| 235 // when the tab's closed. There's a race between the | 233 // when the tab's closed. There's a race between the |
| 236 // LocationBarController and the ContentRulesRegistry on navigation, | 234 // LocationBarController and the ContentRulesRegistry on navigation, |
| 237 // which prevents me from cleaning everything up now. | 235 // which prevents me from cleaning everything up now. |
| 238 } | 236 } |
| 239 | 237 |
| 240 void ExtensionAction::PaintBadge(gfx::Canvas* canvas, | |
| 241 const gfx::Rect& bounds, | |
| 242 int tab_id) { | |
| 243 badge_util::PaintBadge( | |
| 244 canvas, | |
| 245 bounds, | |
| 246 GetBadgeText(tab_id), | |
| 247 GetBadgeTextColor(tab_id), | |
| 248 GetBadgeBackgroundColor(tab_id), | |
| 249 GetIconWidth(tab_id), | |
| 250 action_type()); | |
| 251 } | |
| 252 | |
| 253 gfx::ImageSkia ExtensionAction::GetIconWithBadge( | |
| 254 const gfx::ImageSkia& icon, | |
| 255 int tab_id, | |
| 256 const gfx::Size& spacing) const { | |
| 257 if (tab_id < 0) | |
| 258 return icon; | |
| 259 | |
| 260 return gfx::ImageSkia( | |
| 261 new IconWithBadgeImageSource(icon, | |
| 262 icon.size(), | |
| 263 spacing, | |
| 264 GetBadgeText(tab_id), | |
| 265 GetBadgeTextColor(tab_id), | |
| 266 GetBadgeBackgroundColor(tab_id), | |
| 267 action_type()), | |
| 268 icon.size()); | |
| 269 } | |
| 270 | |
| 271 extensions::IconImage* ExtensionAction::LoadDefaultIconImage( | 238 extensions::IconImage* ExtensionAction::LoadDefaultIconImage( |
| 272 const extensions::Extension& extension, | 239 const extensions::Extension& extension, |
| 273 content::BrowserContext* browser_context) { | 240 content::BrowserContext* browser_context) { |
| 274 if (default_icon_ && !default_icon_image_) { | 241 if (default_icon_ && !default_icon_image_) { |
| 275 default_icon_image_.reset(new extensions::IconImage( | 242 default_icon_image_.reset(new extensions::IconImage( |
| 276 browser_context, | 243 browser_context, |
| 277 &extension, | 244 &extension, |
| 278 *default_icon(), | 245 *default_icon(), |
| 279 GetIconSizeForType(action_type_), | 246 GetIconSizeForType(action_type_), |
| 280 *GetDefaultIcon().ToImageSkia(), | 247 *GetDefaultIcon().ToImageSkia(), |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 382 // If there is a default icon, the icon width will be set depending on our | 349 // If there is a default icon, the icon width will be set depending on our |
| 383 // action type. | 350 // action type. |
| 384 if (default_icon_) | 351 if (default_icon_) |
| 385 return GetIconSizeForType(action_type()); | 352 return GetIconSizeForType(action_type()); |
| 386 | 353 |
| 387 // If no icon has been set and there is no default icon, we need favicon | 354 // If no icon has been set and there is no default icon, we need favicon |
| 388 // width. | 355 // width. |
| 389 return ui::ResourceBundle::GetSharedInstance().GetImageNamed( | 356 return ui::ResourceBundle::GetSharedInstance().GetImageNamed( |
| 390 IDR_EXTENSIONS_FAVICON).Width(); | 357 IDR_EXTENSIONS_FAVICON).Width(); |
| 391 } | 358 } |
| OLD | NEW |