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/common/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/bind.h" | 9 #include "base/bind.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "base/message_loop.h" | 11 #include "base/message_loop.h" |
| 12 #include "chrome/browser/extensions/extension_service.h" |
| 13 #include "chrome/browser/extensions/extension_system.h" |
12 #include "chrome/common/badge_util.h" | 14 #include "chrome/common/badge_util.h" |
13 #include "googleurl/src/gurl.h" | 15 #include "googleurl/src/gurl.h" |
14 #include "grit/theme_resources.h" | 16 #include "grit/theme_resources.h" |
15 #include "grit/ui_resources.h" | 17 #include "grit/ui_resources.h" |
16 #include "third_party/skia/include/core/SkBitmap.h" | 18 #include "third_party/skia/include/core/SkBitmap.h" |
17 #include "third_party/skia/include/core/SkCanvas.h" | 19 #include "third_party/skia/include/core/SkCanvas.h" |
18 #include "third_party/skia/include/core/SkDevice.h" | 20 #include "third_party/skia/include/core/SkDevice.h" |
19 #include "third_party/skia/include/core/SkPaint.h" | 21 #include "third_party/skia/include/core/SkPaint.h" |
20 #include "third_party/skia/include/effects/SkGradientShader.h" | 22 #include "third_party/skia/include/effects/SkGradientShader.h" |
21 #include "ui/base/animation/animation_delegate.h" | 23 #include "ui/base/animation/animation_delegate.h" |
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
225 observer_(observer) { | 227 observer_(observer) { |
226 if (icon_animation.get()) | 228 if (icon_animation.get()) |
227 icon_animation->AddObserver(observer); | 229 icon_animation->AddObserver(observer); |
228 } | 230 } |
229 | 231 |
230 ExtensionAction::IconAnimation::ScopedObserver::~ScopedObserver() { | 232 ExtensionAction::IconAnimation::ScopedObserver::~ScopedObserver() { |
231 if (icon_animation_.get()) | 233 if (icon_animation_.get()) |
232 icon_animation_->RemoveObserver(observer_); | 234 icon_animation_->RemoveObserver(observer_); |
233 } | 235 } |
234 | 236 |
235 ExtensionAction::ExtensionAction(const std::string& extension_id, | 237 ExtensionAction::ExtensionAction( |
236 Type action_type) | 238 const std::string& extension_id, |
| 239 const extensions::Extension::ActionInfo& manifest_info) |
237 : extension_id_(extension_id), | 240 : extension_id_(extension_id), |
238 action_type_(action_type), | 241 action_type_(manifest_info.action_type), |
239 has_changed_(false) { | 242 has_changed_(false) { |
| 243 // Page/script actions are hidden/disabled by default, and browser actions are |
| 244 // visible/enabled by default. |
| 245 SetAppearance( |
| 246 kDefaultTabId, |
| 247 action_type_ == extensions::Extension::ActionInfo::TYPE_BROWSER ? |
| 248 ACTIVE : INVISIBLE); |
| 249 set_default_icon_path(manifest_info.default_icon_path); |
| 250 set_id(manifest_info.id); |
| 251 if (!manifest_info.default_title.empty()) |
| 252 SetTitle(ExtensionAction::kDefaultTabId, manifest_info.default_title); |
| 253 if (!manifest_info.default_popup_url.is_empty()) { |
| 254 SetPopupUrl(ExtensionAction::kDefaultTabId, |
| 255 manifest_info.default_popup_url); |
| 256 } |
240 } | 257 } |
241 | 258 |
242 ExtensionAction::~ExtensionAction() { | 259 ExtensionAction::~ExtensionAction() { |
243 } | 260 } |
244 | 261 |
245 scoped_ptr<ExtensionAction> ExtensionAction::CopyForTest() const { | 262 scoped_ptr<ExtensionAction> ExtensionAction::CopyForTest() const { |
| 263 |
246 scoped_ptr<ExtensionAction> copy( | 264 scoped_ptr<ExtensionAction> copy( |
247 new ExtensionAction(extension_id_, action_type_)); | 265 new ExtensionAction(extension_id_, |
| 266 extensions::Extension::ActionInfo(action_type_))); |
248 copy->popup_url_ = popup_url_; | 267 copy->popup_url_ = popup_url_; |
249 copy->title_ = title_; | 268 copy->title_ = title_; |
250 copy->icon_ = icon_; | 269 copy->icon_ = icon_; |
251 copy->icon_index_ = icon_index_; | 270 copy->icon_index_ = icon_index_; |
252 copy->badge_text_ = badge_text_; | 271 copy->badge_text_ = badge_text_; |
253 copy->badge_background_color_ = badge_background_color_; | 272 copy->badge_background_color_ = badge_background_color_; |
254 copy->badge_text_color_ = badge_text_color_; | 273 copy->badge_text_color_ = badge_text_color_; |
255 copy->appearance_ = appearance_; | 274 copy->appearance_ = appearance_; |
256 copy->icon_animation_ = icon_animation_; | 275 copy->icon_animation_ = icon_animation_; |
257 copy->default_icon_path_ = default_icon_path_; | 276 copy->default_icon_path_ = default_icon_path_; |
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
515 icon_animation->Start(); | 534 icon_animation->Start(); |
516 // After the icon is finished fading in (plus some padding to handle random | 535 // After the icon is finished fading in (plus some padding to handle random |
517 // timer delays), destroy it. We use a delayed task so that the Animation is | 536 // timer delays), destroy it. We use a delayed task so that the Animation is |
518 // deleted even if it hasn't finished by the time the MessageLoop is | 537 // deleted even if it hasn't finished by the time the MessageLoop is |
519 // destroyed. | 538 // destroyed. |
520 MessageLoop::current()->PostDelayedTask( | 539 MessageLoop::current()->PostDelayedTask( |
521 FROM_HERE, | 540 FROM_HERE, |
522 base::Bind(&DestroyIconAnimation, base::Passed(icon_animation.Pass())), | 541 base::Bind(&DestroyIconAnimation, base::Passed(icon_animation.Pass())), |
523 base::TimeDelta::FromMilliseconds(kIconFadeInDurationMs * 2)); | 542 base::TimeDelta::FromMilliseconds(kIconFadeInDurationMs * 2)); |
524 } | 543 } |
| 544 |
| 545 namespace extensions { |
| 546 |
| 547 ExtensionAction* GetBrowserAction(Profile* profile, |
| 548 const Extension& extension) { |
| 549 return ExtensionSystem::Get(profile)->extension_service()-> |
| 550 GetBrowserAction(extension); |
| 551 } |
| 552 ExtensionAction* GetPageAction(Profile* profile, const Extension& extension) { |
| 553 return ExtensionSystem::Get(profile)->extension_service()-> |
| 554 GetPageAction(extension); |
| 555 } |
| 556 ExtensionAction* GetScriptBadge(Profile* profile, const Extension& extension) { |
| 557 return ExtensionSystem::Get(profile)->extension_service()-> |
| 558 GetScriptBadge(extension); |
| 559 } |
| 560 |
| 561 } |
OLD | NEW |