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.h" | 7 #include "chrome/browser/extensions/api/system_indicator/system_indicator_manage
r.h" |
8 #include "chrome/browser/extensions/api/system_indicator/system_indicator_manage
r_factory.h" | 8 #include "chrome/browser/extensions/api/system_indicator/system_indicator_manage
r_factory.h" |
9 #include "chrome/browser/extensions/extension_action.h" | 9 #include "chrome/browser/extensions/extension_action.h" |
10 #include "chrome/browser/extensions/extension_system.h" | 10 #include "chrome/browser/extensions/extension_system.h" |
11 #include "chrome/browser/profiles/profile.h" | 11 #include "chrome/browser/profiles/profile.h" |
12 #include "chrome/browser/profiles/profile_dependency_manager.h" | 12 #include "chrome/browser/profiles/profile_dependency_manager.h" |
13 #include "chrome/browser/profiles/profile_keyed_service_factory.h" | 13 #include "chrome/browser/profiles/profile_keyed_service_factory.h" |
14 #include "chrome/common/chrome_notification_types.h" | 14 #include "chrome/common/chrome_notification_types.h" |
| 15 #include "chrome/common/extensions/api/extension_action/action_info.h" |
| 16 #include "chrome/common/extensions/api/extension_action/script_badge_handler.h" |
15 #include "chrome/common/extensions/extension.h" | 17 #include "chrome/common/extensions/extension.h" |
16 #include "chrome/common/extensions/feature_switch.h" | 18 #include "chrome/common/extensions/feature_switch.h" |
17 #include "content/public/browser/notification_service.h" | 19 #include "content/public/browser/notification_service.h" |
18 #include "content/public/browser/notification_source.h" | 20 #include "content/public/browser/notification_source.h" |
19 | 21 |
20 namespace extensions { | 22 namespace extensions { |
21 | 23 |
22 namespace { | 24 namespace { |
23 | 25 |
24 // ProfileKeyedServiceFactory for ExtensionActionManager. | 26 // ProfileKeyedServiceFactory for ExtensionActionManager. |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 } | 94 } |
93 | 95 |
94 namespace { | 96 namespace { |
95 | 97 |
96 // Returns map[extension_id] if that entry exists. Otherwise, if | 98 // Returns map[extension_id] if that entry exists. Otherwise, if |
97 // action_info!=NULL, creates an ExtensionAction from it, fills in the map, and | 99 // action_info!=NULL, creates an ExtensionAction from it, fills in the map, and |
98 // returns that. Otherwise (action_info==NULL), returns NULL. | 100 // returns that. Otherwise (action_info==NULL), returns NULL. |
99 ExtensionAction* GetOrCreateOrNull( | 101 ExtensionAction* GetOrCreateOrNull( |
100 std::map<std::string, linked_ptr<ExtensionAction> >* map, | 102 std::map<std::string, linked_ptr<ExtensionAction> >* map, |
101 const std::string& extension_id, | 103 const std::string& extension_id, |
102 Extension::ActionInfo::Type action_type, | 104 ActionInfo::Type action_type, |
103 const Extension::ActionInfo* action_info) { | 105 const ActionInfo* action_info) { |
104 std::map<std::string, linked_ptr<ExtensionAction> >::const_iterator it = | 106 std::map<std::string, linked_ptr<ExtensionAction> >::const_iterator it = |
105 map->find(extension_id); | 107 map->find(extension_id); |
106 if (it != map->end()) | 108 if (it != map->end()) |
107 return it->second.get(); | 109 return it->second.get(); |
108 if (!action_info) | 110 if (!action_info) |
109 return NULL; | 111 return NULL; |
110 linked_ptr<ExtensionAction> action(new ExtensionAction( | 112 linked_ptr<ExtensionAction> action(new ExtensionAction( |
111 extension_id, action_type, *action_info)); | 113 extension_id, action_type, *action_info)); |
112 (*map)[extension_id] = action; | 114 (*map)[extension_id] = action; |
113 return action.get(); | 115 return action.get(); |
114 } | 116 } |
115 | 117 |
116 } // namespace | 118 } // namespace |
117 | 119 |
118 ExtensionAction* ExtensionActionManager::GetPageAction( | 120 ExtensionAction* ExtensionActionManager::GetPageAction( |
119 const extensions::Extension& extension) const { | 121 const extensions::Extension& extension) const { |
120 // The action box changes the meaning of the page action area, so we | 122 // The action box changes the meaning of the page action area, so we |
121 // need to convert page actions into browser actions. | 123 // need to convert page actions into browser actions. |
122 if (FeatureSwitch::script_badges()->IsEnabled()) | 124 if (FeatureSwitch::script_badges()->IsEnabled()) |
123 return NULL; | 125 return NULL; |
124 return GetOrCreateOrNull(&page_actions_, extension.id(), | 126 return GetOrCreateOrNull(&page_actions_, extension.id(), |
125 Extension::ActionInfo::TYPE_PAGE, | 127 ActionInfo::TYPE_PAGE, |
126 extension.page_action_info()); | 128 extension.page_action_info()); |
127 } | 129 } |
128 | 130 |
129 ExtensionAction* ExtensionActionManager::GetBrowserAction( | 131 ExtensionAction* ExtensionActionManager::GetBrowserAction( |
130 const extensions::Extension& extension) const { | 132 const extensions::Extension& extension) const { |
131 const Extension::ActionInfo* action_info = extension.browser_action_info(); | 133 const ActionInfo* action_info = extension.browser_action_info(); |
132 Extension::ActionInfo::Type action_type = Extension::ActionInfo::TYPE_BROWSER; | 134 ActionInfo::Type action_type = ActionInfo::TYPE_BROWSER; |
133 if (FeatureSwitch::script_badges()->IsEnabled() && | 135 if (FeatureSwitch::script_badges()->IsEnabled() && |
134 extension.page_action_info()) { | 136 extension.page_action_info()) { |
135 // The action box changes the meaning of the page action area, so we | 137 // The action box changes the meaning of the page action area, so we |
136 // need to convert page actions into browser actions. | 138 // need to convert page actions into browser actions. |
137 action_info = extension.page_action_info(); | 139 action_info = extension.page_action_info(); |
138 action_type = Extension::ActionInfo::TYPE_PAGE; | 140 action_type = ActionInfo::TYPE_PAGE; |
139 } | 141 } |
140 return GetOrCreateOrNull(&browser_actions_, extension.id(), | 142 return GetOrCreateOrNull(&browser_actions_, extension.id(), |
141 action_type, action_info); | 143 action_type, action_info); |
142 } | 144 } |
143 | 145 |
144 ExtensionAction* ExtensionActionManager::GetSystemIndicator( | 146 ExtensionAction* ExtensionActionManager::GetSystemIndicator( |
145 const extensions::Extension& extension) const { | 147 const extensions::Extension& extension) const { |
146 // If it does not already exist, create the SystemIndicatorManager for the | 148 // If it does not already exist, create the SystemIndicatorManager for the |
147 // given profile. This could return NULL if the system indicator area is | 149 // given profile. This could return NULL if the system indicator area is |
148 // unavailable on the current system. If so, return NULL to signal that | 150 // unavailable on the current system. If so, return NULL to signal that |
149 // the system indicator area is unusable. | 151 // the system indicator area is unusable. |
150 if (!extensions::SystemIndicatorManagerFactory::GetForProfile(profile_)) | 152 if (!extensions::SystemIndicatorManagerFactory::GetForProfile(profile_)) |
151 return NULL; | 153 return NULL; |
152 | 154 |
153 return GetOrCreateOrNull(&system_indicators_, extension.id(), | 155 return GetOrCreateOrNull(&system_indicators_, extension.id(), |
154 Extension::ActionInfo::TYPE_SYSTEM_INDICATOR, | 156 ActionInfo::TYPE_SYSTEM_INDICATOR, |
155 extension.system_indicator_info()); | 157 extension.system_indicator_info()); |
156 } | 158 } |
157 | 159 |
158 ExtensionAction* ExtensionActionManager::GetScriptBadge( | 160 ExtensionAction* ExtensionActionManager::GetScriptBadge( |
159 const extensions::Extension& extension) const { | 161 const extensions::Extension& extension) const { |
160 return GetOrCreateOrNull(&script_badges_, extension.id(), | 162 return GetOrCreateOrNull(&script_badges_, extension.id(), |
161 Extension::ActionInfo::TYPE_SCRIPT_BADGE, | 163 ActionInfo::TYPE_SCRIPT_BADGE, |
162 extension.script_badge_info()); | 164 ActionInfo::GetScriptBadgeInfo(&extension)); |
163 } | 165 } |
164 | 166 |
165 } // namespace extensions | 167 } // namespace extensions |
OLD | NEW |