| 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" | 11 #include "chrome/common/badge_util.h" |
| 12 #include "chrome/common/icon_with_badge_image_source.h" | 12 #include "chrome/common/icon_with_badge_image_source.h" |
| 13 #include "extensions/browser/extension_icon_image.h" | 13 #include "extensions/browser/extension_icon_image.h" |
| 14 #include "extensions/browser/extension_icon_placeholder.h" |
| 14 #include "extensions/common/constants.h" | 15 #include "extensions/common/constants.h" |
| 15 #include "extensions/common/extension_icon_set.h" | 16 #include "extensions/common/extension_icon_set.h" |
| 17 #include "extensions/common/feature_switch.h" |
| 16 #include "extensions/common/manifest_handlers/icons_handler.h" | 18 #include "extensions/common/manifest_handlers/icons_handler.h" |
| 17 #include "grit/theme_resources.h" | 19 #include "grit/theme_resources.h" |
| 18 #include "grit/ui_resources.h" | 20 #include "grit/ui_resources.h" |
| 19 #include "ipc/ipc_message.h" | 21 #include "ipc/ipc_message.h" |
| 20 #include "ipc/ipc_message_utils.h" | 22 #include "ipc/ipc_message_utils.h" |
| 21 #include "third_party/skia/include/core/SkBitmap.h" | 23 #include "third_party/skia/include/core/SkBitmap.h" |
| 22 #include "third_party/skia/include/core/SkCanvas.h" | 24 #include "third_party/skia/include/core/SkCanvas.h" |
| 23 #include "third_party/skia/include/core/SkPaint.h" | 25 #include "third_party/skia/include/core/SkPaint.h" |
| 24 #include "third_party/skia/include/effects/SkGradientShader.h" | 26 #include "third_party/skia/include/effects/SkGradientShader.h" |
| 25 #include "ui/base/resource/resource_bundle.h" | 27 #include "ui/base/resource/resource_bundle.h" |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 | 98 |
| 97 } // namespace | 99 } // namespace |
| 98 | 100 |
| 99 const int ExtensionAction::kDefaultTabId = -1; | 101 const int ExtensionAction::kDefaultTabId = -1; |
| 100 const int ExtensionAction::kPageActionIconMaxSize = | 102 const int ExtensionAction::kPageActionIconMaxSize = |
| 101 extension_misc::EXTENSION_ICON_ACTION; | 103 extension_misc::EXTENSION_ICON_ACTION; |
| 102 | 104 |
| 103 ExtensionAction::ExtensionAction(const extensions::Extension& extension, | 105 ExtensionAction::ExtensionAction(const extensions::Extension& extension, |
| 104 extensions::ActionInfo::Type action_type, | 106 extensions::ActionInfo::Type action_type, |
| 105 const extensions::ActionInfo& manifest_data) | 107 const extensions::ActionInfo& manifest_data) |
| 106 : extension_id_(extension.id()), action_type_(action_type) { | 108 : extension_id_(extension.id()), |
| 109 extension_name_(extension.name()), |
| 110 action_type_(action_type) { |
| 107 // Page/script actions are hidden/disabled by default, and browser actions are | 111 // Page/script actions are hidden/disabled by default, and browser actions are |
| 108 // visible/enabled by default. | 112 // visible/enabled by default. |
| 109 SetIsVisible(kDefaultTabId, | 113 SetIsVisible(kDefaultTabId, |
| 110 action_type == extensions::ActionInfo::TYPE_BROWSER); | 114 action_type == extensions::ActionInfo::TYPE_BROWSER); |
| 111 Populate(extension, manifest_data); | 115 Populate(extension, manifest_data); |
| 112 } | 116 } |
| 113 | 117 |
| 114 ExtensionAction::~ExtensionAction() { | 118 ExtensionAction::~ExtensionAction() { |
| 115 } | 119 } |
| 116 | 120 |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 275 GetIconSizeForType(action_type_), | 279 GetIconSizeForType(action_type_), |
| 276 *GetDefaultIcon().ToImageSkia(), | 280 *GetDefaultIcon().ToImageSkia(), |
| 277 nullptr)); | 281 nullptr)); |
| 278 } | 282 } |
| 279 return default_icon_image_.get(); | 283 return default_icon_image_.get(); |
| 280 } | 284 } |
| 281 | 285 |
| 282 gfx::Image ExtensionAction::GetDefaultIconImage() const { | 286 gfx::Image ExtensionAction::GetDefaultIconImage() const { |
| 283 // If we have a default icon, it should be loaded before trying to use it. | 287 // If we have a default icon, it should be loaded before trying to use it. |
| 284 DCHECK(!default_icon_image_ == !default_icon_); | 288 DCHECK(!default_icon_image_ == !default_icon_); |
| 285 return default_icon_image_ ? default_icon_image_->image() : GetDefaultIcon(); | 289 if (default_icon_image_) |
| 290 return default_icon_image_->image(); |
| 291 |
| 292 // If the extension action redesign is enabled, we use a special placeholder |
| 293 // icon (with the first letter of the extension name) rather than the default |
| 294 // (puzzle piece). |
| 295 if (extensions::FeatureSwitch::extension_action_redesign()->IsEnabled()) { |
| 296 return extensions::ExtensionIconPlaceholder::CreateImage( |
| 297 extension_misc::EXTENSION_ICON_ACTION, extension_name_); |
| 298 } |
| 299 |
| 300 return GetDefaultIcon(); |
| 286 } | 301 } |
| 287 | 302 |
| 288 bool ExtensionAction::HasPopupUrl(int tab_id) const { | 303 bool ExtensionAction::HasPopupUrl(int tab_id) const { |
| 289 return HasValue(popup_url_, tab_id); | 304 return HasValue(popup_url_, tab_id); |
| 290 } | 305 } |
| 291 | 306 |
| 292 bool ExtensionAction::HasTitle(int tab_id) const { | 307 bool ExtensionAction::HasTitle(int tab_id) const { |
| 293 return HasValue(title_, tab_id); | 308 return HasValue(title_, tab_id); |
| 294 } | 309 } |
| 295 | 310 |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 367 // If there is a default icon, the icon width will be set depending on our | 382 // If there is a default icon, the icon width will be set depending on our |
| 368 // action type. | 383 // action type. |
| 369 if (default_icon_) | 384 if (default_icon_) |
| 370 return GetIconSizeForType(action_type()); | 385 return GetIconSizeForType(action_type()); |
| 371 | 386 |
| 372 // If no icon has been set and there is no default icon, we need favicon | 387 // If no icon has been set and there is no default icon, we need favicon |
| 373 // width. | 388 // width. |
| 374 return ui::ResourceBundle::GetSharedInstance().GetImageNamed( | 389 return ui::ResourceBundle::GetSharedInstance().GetImageNamed( |
| 375 IDR_EXTENSIONS_FAVICON).Width(); | 390 IDR_EXTENSIONS_FAVICON).Width(); |
| 376 } | 391 } |
| OLD | NEW |