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_manager.h" | 5 #include "chrome/browser/extensions/extension_action_manager.h" |
6 | 6 |
7 #include "chrome/browser/extensions/api/system_indicator/system_indicator_manage
r_factory.h" | 7 #include "chrome/browser/extensions/api/system_indicator/system_indicator_manage
r_factory.h" |
8 #include "chrome/browser/extensions/extension_action.h" | 8 #include "chrome/browser/extensions/extension_action.h" |
9 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
10 #include "components/keyed_service/content/browser_context_dependency_manager.h" | 10 #include "components/keyed_service/content/browser_context_dependency_manager.h" |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 browser_actions_.erase(extension->id()); | 82 browser_actions_.erase(extension->id()); |
83 system_indicators_.erase(extension->id()); | 83 system_indicators_.erase(extension->id()); |
84 } | 84 } |
85 | 85 |
86 namespace { | 86 namespace { |
87 | 87 |
88 // Loads resources missing from |action| (i.e. title, icons) from the "icons" | 88 // Loads resources missing from |action| (i.e. title, icons) from the "icons" |
89 // key of |extension|'s manifest. | 89 // key of |extension|'s manifest. |
90 void PopulateMissingValues(const Extension& extension, | 90 void PopulateMissingValues(const Extension& extension, |
91 ExtensionAction* action) { | 91 ExtensionAction* action) { |
92 const int* kIconSizes = extension_misc::kExtensionActionIconSizes; | |
93 const size_t kNumIconSizes = extension_misc::kNumExtensionActionIconSizes; | |
94 | |
95 // If the title is missing from |action|, set it to |extension|'s name. | 92 // If the title is missing from |action|, set it to |extension|'s name. |
96 if (action->GetTitle(ExtensionAction::kDefaultTabId).empty()) | 93 if (action->GetTitle(ExtensionAction::kDefaultTabId).empty()) |
97 action->SetTitle(ExtensionAction::kDefaultTabId, extension.name()); | 94 action->SetTitle(ExtensionAction::kDefaultTabId, extension.name()); |
98 | 95 |
99 scoped_ptr<ExtensionIconSet> default_icon(new ExtensionIconSet()); | 96 scoped_ptr<ExtensionIconSet> default_icon(new ExtensionIconSet()); |
100 if (action->default_icon()) | 97 if (action->default_icon()) |
101 *default_icon = *action->default_icon(); | 98 *default_icon = *action->default_icon(); |
102 | 99 |
103 const ExtensionIconSet& extension_icons = | 100 const ExtensionIconSet& extension_icons = |
104 extensions::IconsInfo::GetIcons(&extension); | 101 extensions::IconsInfo::GetIcons(&extension); |
105 std::string largest_icon = extension_icons.Get( | 102 std::string largest_icon = extension_icons.Get( |
106 extension_misc::EXTENSION_ICON_GIGANTOR, | 103 extension_misc::EXTENSION_ICON_GIGANTOR, |
107 ExtensionIconSet::MATCH_SMALLER); | 104 ExtensionIconSet::MATCH_SMALLER); |
108 | 105 |
109 if (!largest_icon.empty()) { | 106 if (!largest_icon.empty()) { |
110 int largest_icon_size = extension_icons.GetIconSizeFromPath(largest_icon); | 107 int largest_icon_size = extension_icons.GetIconSizeFromPath(largest_icon); |
111 // Replace any missing extension action icons with the largest icon | 108 // Replace any missing extension action icons with the largest icon |
112 // retrieved from |extension|'s manifest so long as the largest icon is | 109 // retrieved from |extension|'s manifest so long as the largest icon is |
113 // larger than the current key. | 110 // larger than the current key. |
114 for (int i = kNumIconSizes - 1; i >= 0; --i) { | 111 for (int i = extension_misc::kNumExtensionActionIconSizes - 1; |
115 int size = kIconSizes[i]; | 112 i >= 0; --i) { |
| 113 int size = extension_misc::kExtensionActionIconSizes[i].size; |
116 if (default_icon->Get(size, ExtensionIconSet::MATCH_BIGGER).empty() | 114 if (default_icon->Get(size, ExtensionIconSet::MATCH_BIGGER).empty() |
117 && largest_icon_size > size) { | 115 && largest_icon_size > size) { |
118 default_icon->Add(size, largest_icon); | 116 default_icon->Add(size, largest_icon); |
119 break; | 117 break; |
120 } | 118 } |
121 } | 119 } |
122 action->set_default_icon(default_icon.Pass()); | 120 action->set_default_icon(default_icon.Pass()); |
123 } | 121 } |
124 } | 122 } |
125 | 123 |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
198 if (!extensions::SystemIndicatorManagerFactory::GetForProfile(profile_)) | 196 if (!extensions::SystemIndicatorManagerFactory::GetForProfile(profile_)) |
199 return NULL; | 197 return NULL; |
200 | 198 |
201 return GetOrCreateOrNull(&system_indicators_, extension, | 199 return GetOrCreateOrNull(&system_indicators_, extension, |
202 ActionInfo::TYPE_SYSTEM_INDICATOR, | 200 ActionInfo::TYPE_SYSTEM_INDICATOR, |
203 ActionInfo::GetSystemIndicatorInfo(&extension), | 201 ActionInfo::GetSystemIndicatorInfo(&extension), |
204 profile_); | 202 profile_); |
205 } | 203 } |
206 | 204 |
207 } // namespace extensions | 205 } // namespace extensions |
OLD | NEW |