| 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/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 | 142 |
| 143 void ExtensionAction::IconAnimation::AnimateToState(double state) { | 143 void ExtensionAction::IconAnimation::AnimateToState(double state) { |
| 144 FOR_EACH_OBSERVER(Observer, observers_, OnIconChanged()); | 144 FOR_EACH_OBSERVER(Observer, observers_, OnIconChanged()); |
| 145 } | 145 } |
| 146 | 146 |
| 147 ExtensionAction::IconAnimation::ScopedObserver::ScopedObserver( | 147 ExtensionAction::IconAnimation::ScopedObserver::ScopedObserver( |
| 148 const base::WeakPtr<IconAnimation>& icon_animation, | 148 const base::WeakPtr<IconAnimation>& icon_animation, |
| 149 Observer* observer) | 149 Observer* observer) |
| 150 : icon_animation_(icon_animation), | 150 : icon_animation_(icon_animation), |
| 151 observer_(observer) { | 151 observer_(observer) { |
| 152 if (icon_animation.get()) | 152 if (icon_animation) |
| 153 icon_animation->AddObserver(observer); | 153 icon_animation->AddObserver(observer); |
| 154 } | 154 } |
| 155 | 155 |
| 156 ExtensionAction::IconAnimation::ScopedObserver::~ScopedObserver() { | 156 ExtensionAction::IconAnimation::ScopedObserver::~ScopedObserver() { |
| 157 if (icon_animation_.get()) | 157 if (icon_animation_) |
| 158 icon_animation_->RemoveObserver(observer_); | 158 icon_animation_->RemoveObserver(observer_); |
| 159 } | 159 } |
| 160 | 160 |
| 161 ExtensionAction::ExtensionAction( | 161 ExtensionAction::ExtensionAction( |
| 162 const std::string& extension_id, | 162 const std::string& extension_id, |
| 163 extensions::ActionInfo::Type action_type, | 163 extensions::ActionInfo::Type action_type, |
| 164 const extensions::ActionInfo& manifest_data) | 164 const extensions::ActionInfo& manifest_data) |
| 165 : extension_id_(extension_id), | 165 : extension_id_(extension_id), |
| 166 action_type_(action_type), | 166 action_type_(action_type), |
| 167 has_changed_(false) { | 167 has_changed_(false) { |
| (...skipping 21 matching lines...) Expand all Loading... |
| 189 copy->popup_url_ = popup_url_; | 189 copy->popup_url_ = popup_url_; |
| 190 copy->title_ = title_; | 190 copy->title_ = title_; |
| 191 copy->icon_ = icon_; | 191 copy->icon_ = icon_; |
| 192 copy->badge_text_ = badge_text_; | 192 copy->badge_text_ = badge_text_; |
| 193 copy->badge_background_color_ = badge_background_color_; | 193 copy->badge_background_color_ = badge_background_color_; |
| 194 copy->badge_text_color_ = badge_text_color_; | 194 copy->badge_text_color_ = badge_text_color_; |
| 195 copy->appearance_ = appearance_; | 195 copy->appearance_ = appearance_; |
| 196 copy->icon_animation_ = icon_animation_; | 196 copy->icon_animation_ = icon_animation_; |
| 197 copy->id_ = id_; | 197 copy->id_ = id_; |
| 198 | 198 |
| 199 if (default_icon_.get()) | 199 if (default_icon_) |
| 200 copy->default_icon_.reset(new ExtensionIconSet(*default_icon_)); | 200 copy->default_icon_.reset(new ExtensionIconSet(*default_icon_)); |
| 201 | 201 |
| 202 return copy.Pass(); | 202 return copy.Pass(); |
| 203 } | 203 } |
| 204 | 204 |
| 205 // static | 205 // static |
| 206 int ExtensionAction::GetIconSizeForType( | 206 int ExtensionAction::GetIconSizeForType( |
| 207 extensions::ActionInfo::Type type) { | 207 extensions::ActionInfo::Type type) { |
| 208 switch (type) { | 208 switch (type) { |
| 209 case extensions::ActionInfo::TYPE_BROWSER: | 209 case extensions::ActionInfo::TYPE_BROWSER: |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 332 } | 332 } |
| 333 | 333 |
| 334 // Determines which icon would be returned by |GetIcon|, and returns its width. | 334 // Determines which icon would be returned by |GetIcon|, and returns its width. |
| 335 int ExtensionAction::GetIconWidth(int tab_id) const { | 335 int ExtensionAction::GetIconWidth(int tab_id) const { |
| 336 // If icon has been set, return its width. | 336 // If icon has been set, return its width. |
| 337 gfx::ImageSkia icon = GetValue(&icon_, tab_id); | 337 gfx::ImageSkia icon = GetValue(&icon_, tab_id); |
| 338 if (!icon.isNull()) | 338 if (!icon.isNull()) |
| 339 return icon.width(); | 339 return icon.width(); |
| 340 // If there is a default icon, the icon width will be set depending on our | 340 // If there is a default icon, the icon width will be set depending on our |
| 341 // action type. | 341 // action type. |
| 342 if (default_icon_.get()) | 342 if (default_icon_) |
| 343 return GetIconSizeForType(action_type()); | 343 return GetIconSizeForType(action_type()); |
| 344 | 344 |
| 345 // If no icon has been set and there is no default icon, we need favicon | 345 // If no icon has been set and there is no default icon, we need favicon |
| 346 // width. | 346 // width. |
| 347 return ui::ResourceBundle::GetSharedInstance().GetImageNamed( | 347 return ui::ResourceBundle::GetSharedInstance().GetImageNamed( |
| 348 IDR_EXTENSIONS_FAVICON).ToImageSkia()->width(); | 348 IDR_EXTENSIONS_FAVICON).ToImageSkia()->width(); |
| 349 } | 349 } |
| 350 | 350 |
| 351 base::WeakPtr<ExtensionAction::IconAnimation> ExtensionAction::GetIconAnimation( | 351 base::WeakPtr<ExtensionAction::IconAnimation> ExtensionAction::GetIconAnimation( |
| 352 int tab_id) const { | 352 int tab_id) const { |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 392 icon_animation->Start(); | 392 icon_animation->Start(); |
| 393 // After the icon is finished fading in (plus some padding to handle random | 393 // After the icon is finished fading in (plus some padding to handle random |
| 394 // timer delays), destroy it. We use a delayed task so that the Animation is | 394 // timer delays), destroy it. We use a delayed task so that the Animation is |
| 395 // deleted even if it hasn't finished by the time the MessageLoop is | 395 // deleted even if it hasn't finished by the time the MessageLoop is |
| 396 // destroyed. | 396 // destroyed. |
| 397 MessageLoop::current()->PostDelayedTask( | 397 MessageLoop::current()->PostDelayedTask( |
| 398 FROM_HERE, | 398 FROM_HERE, |
| 399 base::Bind(&DestroyIconAnimation, base::Passed(&icon_animation)), | 399 base::Bind(&DestroyIconAnimation, base::Passed(&icon_animation)), |
| 400 base::TimeDelta::FromMilliseconds(kIconFadeInDurationMs * 2)); | 400 base::TimeDelta::FromMilliseconds(kIconFadeInDurationMs * 2)); |
| 401 } | 401 } |
| OLD | NEW |