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/chrome_notification_types.h" | 7 #include "chrome/browser/chrome_notification_types.h" |
8 #include "chrome/browser/extensions/api/system_indicator/system_indicator_manage r.h" | 8 #include "chrome/browser/extensions/api/system_indicator/system_indicator_manage r.h" |
9 #include "chrome/browser/extensions/api/system_indicator/system_indicator_manage r_factory.h" | 9 #include "chrome/browser/extensions/api/system_indicator/system_indicator_manage r_factory.h" |
10 #include "chrome/browser/extensions/extension_action.h" | 10 #include "chrome/browser/extensions/extension_action.h" |
11 #include "chrome/browser/extensions/extension_service.h" | |
11 #include "chrome/browser/extensions/extension_system.h" | 12 #include "chrome/browser/extensions/extension_system.h" |
12 #include "chrome/browser/profiles/incognito_helpers.h" | 13 #include "chrome/browser/profiles/incognito_helpers.h" |
13 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
14 #include "chrome/common/extensions/api/extension_action/action_info.h" | 15 #include "chrome/common/extensions/api/extension_action/action_info.h" |
15 #include "chrome/common/extensions/api/extension_action/page_action_handler.h" | 16 #include "chrome/common/extensions/api/extension_action/page_action_handler.h" |
16 #include "chrome/common/extensions/api/extension_action/script_badge_handler.h" | 17 #include "chrome/common/extensions/api/extension_action/script_badge_handler.h" |
17 #include "chrome/common/extensions/extension.h" | 18 #include "chrome/common/extensions/extension.h" |
18 #include "chrome/common/extensions/feature_switch.h" | 19 #include "chrome/common/extensions/feature_switch.h" |
19 #include "components/browser_context_keyed_service/browser_context_dependency_ma nager.h" | 20 #include "components/browser_context_keyed_service/browser_context_dependency_ma nager.h" |
20 #include "components/browser_context_keyed_service/browser_context_keyed_service _factory.h" | 21 #include "components/browser_context_keyed_service/browser_context_keyed_service _factory.h" |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
99 | 100 |
100 namespace { | 101 namespace { |
101 | 102 |
102 // Returns map[extension_id] if that entry exists. Otherwise, if | 103 // Returns map[extension_id] if that entry exists. Otherwise, if |
103 // action_info!=NULL, creates an ExtensionAction from it, fills in the map, and | 104 // action_info!=NULL, creates an ExtensionAction from it, fills in the map, and |
104 // returns that. Otherwise (action_info==NULL), returns NULL. | 105 // returns that. Otherwise (action_info==NULL), returns NULL. |
105 ExtensionAction* GetOrCreateOrNull( | 106 ExtensionAction* GetOrCreateOrNull( |
106 std::map<std::string, linked_ptr<ExtensionAction> >* map, | 107 std::map<std::string, linked_ptr<ExtensionAction> >* map, |
107 const std::string& extension_id, | 108 const std::string& extension_id, |
108 ActionInfo::Type action_type, | 109 ActionInfo::Type action_type, |
109 const ActionInfo* action_info) { | 110 const ActionInfo* action_info, |
111 Profile* profile) { | |
110 std::map<std::string, linked_ptr<ExtensionAction> >::const_iterator it = | 112 std::map<std::string, linked_ptr<ExtensionAction> >::const_iterator it = |
111 map->find(extension_id); | 113 map->find(extension_id); |
112 if (it != map->end()) | 114 if (it != map->end()) |
113 return it->second.get(); | 115 return it->second.get(); |
114 if (!action_info) | 116 if (!action_info) |
115 return NULL; | 117 return NULL; |
118 | |
119 // Only create action info for enabled extensions. | |
120 // This avoids bugs where actions are recreated just after being removed | |
Jeffrey Yasskin
2013/07/30 00:25:22
Argh, use after free. :( Do you know which code pa
| |
121 // in response to NOTIFICATION_EXTENSION_UNLOADED in | |
122 // ExtensionActionManager::Observe() | |
123 ExtensionService* service = | |
124 ExtensionSystem::Get(profile)->extension_service(); | |
125 if (!service->GetExtensionById(extension_id, false)) | |
126 return NULL; | |
127 | |
116 linked_ptr<ExtensionAction> action(new ExtensionAction( | 128 linked_ptr<ExtensionAction> action(new ExtensionAction( |
117 extension_id, action_type, *action_info)); | 129 extension_id, action_type, *action_info)); |
118 (*map)[extension_id] = action; | 130 (*map)[extension_id] = action; |
119 return action.get(); | 131 return action.get(); |
120 } | 132 } |
121 | 133 |
122 } // namespace | 134 } // namespace |
123 | 135 |
124 ExtensionAction* ExtensionActionManager::GetPageAction( | 136 ExtensionAction* ExtensionActionManager::GetPageAction( |
125 const extensions::Extension& extension) const { | 137 const extensions::Extension& extension) const { |
126 // The action box changes the meaning of the page action area, so we | 138 // The action box changes the meaning of the page action area, so we |
127 // need to convert page actions into browser actions. | 139 // need to convert page actions into browser actions. |
128 if (FeatureSwitch::script_badges()->IsEnabled()) | 140 if (FeatureSwitch::script_badges()->IsEnabled()) |
129 return NULL; | 141 return NULL; |
130 return GetOrCreateOrNull(&page_actions_, extension.id(), | 142 return GetOrCreateOrNull(&page_actions_, extension.id(), |
131 ActionInfo::TYPE_PAGE, | 143 ActionInfo::TYPE_PAGE, |
132 ActionInfo::GetPageActionInfo(&extension)); | 144 ActionInfo::GetPageActionInfo(&extension), |
145 profile_); | |
133 } | 146 } |
134 | 147 |
135 ExtensionAction* ExtensionActionManager::GetBrowserAction( | 148 ExtensionAction* ExtensionActionManager::GetBrowserAction( |
136 const extensions::Extension& extension) const { | 149 const extensions::Extension& extension) const { |
137 const ActionInfo* action_info = ActionInfo::GetBrowserActionInfo(&extension); | 150 const ActionInfo* action_info = ActionInfo::GetBrowserActionInfo(&extension); |
138 ActionInfo::Type action_type = ActionInfo::TYPE_BROWSER; | 151 ActionInfo::Type action_type = ActionInfo::TYPE_BROWSER; |
139 if (FeatureSwitch::script_badges()->IsEnabled() && | 152 if (FeatureSwitch::script_badges()->IsEnabled() && |
140 ActionInfo::GetPageActionInfo(&extension)) { | 153 ActionInfo::GetPageActionInfo(&extension)) { |
141 // The action box changes the meaning of the page action area, so we | 154 // The action box changes the meaning of the page action area, so we |
142 // need to convert page actions into browser actions. | 155 // need to convert page actions into browser actions. |
143 action_info = ActionInfo::GetPageActionInfo(&extension); | 156 action_info = ActionInfo::GetPageActionInfo(&extension); |
144 action_type = ActionInfo::TYPE_PAGE; | 157 action_type = ActionInfo::TYPE_PAGE; |
145 } | 158 } |
146 return GetOrCreateOrNull(&browser_actions_, extension.id(), | 159 return GetOrCreateOrNull(&browser_actions_, extension.id(), |
147 action_type, action_info); | 160 action_type, action_info, profile_); |
148 } | 161 } |
149 | 162 |
150 ExtensionAction* ExtensionActionManager::GetSystemIndicator( | 163 ExtensionAction* ExtensionActionManager::GetSystemIndicator( |
151 const extensions::Extension& extension) const { | 164 const extensions::Extension& extension) const { |
152 // If it does not already exist, create the SystemIndicatorManager for the | 165 // If it does not already exist, create the SystemIndicatorManager for the |
153 // given profile. This could return NULL if the system indicator area is | 166 // given profile. This could return NULL if the system indicator area is |
154 // unavailable on the current system. If so, return NULL to signal that | 167 // unavailable on the current system. If so, return NULL to signal that |
155 // the system indicator area is unusable. | 168 // the system indicator area is unusable. |
156 if (!extensions::SystemIndicatorManagerFactory::GetForProfile(profile_)) | 169 if (!extensions::SystemIndicatorManagerFactory::GetForProfile(profile_)) |
157 return NULL; | 170 return NULL; |
158 | 171 |
159 return GetOrCreateOrNull(&system_indicators_, extension.id(), | 172 return GetOrCreateOrNull(&system_indicators_, extension.id(), |
160 ActionInfo::TYPE_SYSTEM_INDICATOR, | 173 ActionInfo::TYPE_SYSTEM_INDICATOR, |
161 ActionInfo::GetSystemIndicatorInfo(&extension)); | 174 ActionInfo::GetSystemIndicatorInfo(&extension), |
175 profile_); | |
162 } | 176 } |
163 | 177 |
164 ExtensionAction* ExtensionActionManager::GetScriptBadge( | 178 ExtensionAction* ExtensionActionManager::GetScriptBadge( |
165 const extensions::Extension& extension) const { | 179 const extensions::Extension& extension) const { |
166 return GetOrCreateOrNull(&script_badges_, extension.id(), | 180 return GetOrCreateOrNull(&script_badges_, extension.id(), |
167 ActionInfo::TYPE_SCRIPT_BADGE, | 181 ActionInfo::TYPE_SCRIPT_BADGE, |
168 ActionInfo::GetScriptBadgeInfo(&extension)); | 182 ActionInfo::GetScriptBadgeInfo(&extension), |
183 profile_); | |
169 } | 184 } |
170 | 185 |
171 } // namespace extensions | 186 } // namespace extensions |
OLD | NEW |