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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 color_utils::HSL shift = {-1, 0, 0.5}; | 43 color_utils::HSL shift = {-1, 0, 0.5}; |
44 return gfx::ImageSkiaRep( | 44 return gfx::ImageSkiaRep( |
45 SkBitmapOperations::CreateHSLShiftedBitmap(icon_rep.sk_bitmap(), shift), | 45 SkBitmapOperations::CreateHSLShiftedBitmap(icon_rep.sk_bitmap(), shift), |
46 icon_rep.scale()); | 46 icon_rep.scale()); |
47 } | 47 } |
48 | 48 |
49 private: | 49 private: |
50 const gfx::ImageSkia icon_; | 50 const gfx::ImageSkia icon_; |
51 }; | 51 }; |
52 | 52 |
53 template <class T> | |
54 bool HasValue(const std::map<int, T>& map, int tab_id) { | |
55 return map.find(tab_id) != map.end(); | |
56 } | |
57 | |
58 } // namespace | 53 } // namespace |
59 | 54 |
60 const int ExtensionAction::kDefaultTabId = -1; | 55 const int ExtensionAction::kDefaultTabId = -1; |
61 | 56 |
62 ExtensionAction::ExtensionAction(const std::string& extension_id, | 57 ExtensionAction::ExtensionAction( |
63 extensions::ActionInfo::Type action_type, | 58 const std::string& extension_id, |
64 const extensions::ActionInfo& manifest_data) | 59 extensions::ActionInfo::Type action_type, |
65 : extension_id_(extension_id), action_type_(action_type) { | 60 const extensions::ActionInfo& manifest_data) |
| 61 : extension_id_(extension_id), |
| 62 action_type_(action_type), |
| 63 has_changed_(false) { |
66 // Page/script actions are hidden/disabled by default, and browser actions are | 64 // Page/script actions are hidden/disabled by default, and browser actions are |
67 // visible/enabled by default. | 65 // visible/enabled by default. |
68 SetIsVisible(kDefaultTabId, | 66 SetIsVisible(kDefaultTabId, |
69 action_type == extensions::ActionInfo::TYPE_BROWSER); | 67 action_type == extensions::ActionInfo::TYPE_BROWSER); |
70 SetTitle(kDefaultTabId, manifest_data.default_title); | 68 SetTitle(kDefaultTabId, manifest_data.default_title); |
71 SetPopupUrl(kDefaultTabId, manifest_data.default_popup_url); | 69 SetPopupUrl(kDefaultTabId, manifest_data.default_popup_url); |
72 if (!manifest_data.default_icon.empty()) { | 70 if (!manifest_data.default_icon.empty()) { |
73 set_default_icon(make_scoped_ptr(new ExtensionIconSet( | 71 set_default_icon(make_scoped_ptr(new ExtensionIconSet( |
74 manifest_data.default_icon))); | 72 manifest_data.default_icon))); |
75 } | 73 } |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
200 new IconWithBadgeImageSource(icon, | 198 new IconWithBadgeImageSource(icon, |
201 icon.size(), | 199 icon.size(), |
202 spacing, | 200 spacing, |
203 GetBadgeText(tab_id), | 201 GetBadgeText(tab_id), |
204 GetBadgeTextColor(tab_id), | 202 GetBadgeTextColor(tab_id), |
205 GetBadgeBackgroundColor(tab_id), | 203 GetBadgeBackgroundColor(tab_id), |
206 action_type()), | 204 action_type()), |
207 icon.size()); | 205 icon.size()); |
208 } | 206 } |
209 | 207 |
210 bool ExtensionAction::HasPopupUrl(int tab_id) const { | |
211 return HasValue(popup_url_, tab_id); | |
212 } | |
213 | |
214 bool ExtensionAction::HasTitle(int tab_id) const { | |
215 return HasValue(title_, tab_id); | |
216 } | |
217 | |
218 bool ExtensionAction::HasBadgeText(int tab_id) const { | |
219 return HasValue(badge_text_, tab_id); | |
220 } | |
221 | |
222 bool ExtensionAction::HasBadgeBackgroundColor(int tab_id) const { | |
223 return HasValue(badge_background_color_, tab_id); | |
224 } | |
225 | |
226 bool ExtensionAction::HasBadgeTextColor(int tab_id) const { | |
227 return HasValue(badge_text_color_, tab_id); | |
228 } | |
229 | |
230 bool ExtensionAction::HasIsVisible(int tab_id) const { | |
231 return HasValue(is_visible_, tab_id); | |
232 } | |
233 | |
234 bool ExtensionAction::HasIcon(int tab_id) const { | |
235 return HasValue(icon_, tab_id); | |
236 } | |
237 | |
238 // Determines which icon would be returned by |GetIcon|, and returns its width. | 208 // Determines which icon would be returned by |GetIcon|, and returns its width. |
239 int ExtensionAction::GetIconWidth(int tab_id) const { | 209 int ExtensionAction::GetIconWidth(int tab_id) const { |
240 // If icon has been set, return its width. | 210 // If icon has been set, return its width. |
241 gfx::ImageSkia icon = GetValue(&icon_, tab_id); | 211 gfx::ImageSkia icon = GetValue(&icon_, tab_id); |
242 if (!icon.isNull()) | 212 if (!icon.isNull()) |
243 return icon.width(); | 213 return icon.width(); |
244 // If there is a default icon, the icon width will be set depending on our | 214 // If there is a default icon, the icon width will be set depending on our |
245 // action type. | 215 // action type. |
246 if (default_icon_) | 216 if (default_icon_) |
247 return GetIconSizeForType(action_type()); | 217 return GetIconSizeForType(action_type()); |
248 | 218 |
249 // If no icon has been set and there is no default icon, we need favicon | 219 // If no icon has been set and there is no default icon, we need favicon |
250 // width. | 220 // width. |
251 return ui::ResourceBundle::GetSharedInstance().GetImageNamed( | 221 return ui::ResourceBundle::GetSharedInstance().GetImageNamed( |
252 IDR_EXTENSIONS_FAVICON).ToImageSkia()->width(); | 222 IDR_EXTENSIONS_FAVICON).ToImageSkia()->width(); |
253 } | 223 } |
OLD | NEW |