| 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_keybinding_registry.h" | 5 #include "chrome/browser/extensions/extension_keybinding_registry.h" |
| 6 | 6 |
| 7 #include "base/values.h" | 7 #include "base/values.h" |
| 8 #include "chrome/browser/chrome_notification_types.h" | |
| 9 #include "chrome/browser/extensions/active_tab_permission_granter.h" | 8 #include "chrome/browser/extensions/active_tab_permission_granter.h" |
| 10 #include "chrome/browser/extensions/extension_service.h" | 9 #include "chrome/browser/extensions/extension_service.h" |
| 11 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
| 12 #include "chrome/common/extensions/command.h" | 11 #include "chrome/common/extensions/command.h" |
| 13 #include "content/public/browser/browser_context.h" | 12 #include "content/public/browser/browser_context.h" |
| 14 #include "extensions/browser/event_router.h" | 13 #include "extensions/browser/event_router.h" |
| 15 #include "extensions/browser/extension_registry.h" | 14 #include "extensions/browser/extension_registry.h" |
| 16 #include "extensions/browser/extension_system.h" | 15 #include "extensions/browser/extension_system.h" |
| 16 #include "extensions/browser/notification_types.h" |
| 17 #include "extensions/common/extension_set.h" | 17 #include "extensions/common/extension_set.h" |
| 18 #include "extensions/common/manifest_constants.h" | 18 #include "extensions/common/manifest_constants.h" |
| 19 | 19 |
| 20 namespace extensions { | 20 namespace extensions { |
| 21 | 21 |
| 22 ExtensionKeybindingRegistry::ExtensionKeybindingRegistry( | 22 ExtensionKeybindingRegistry::ExtensionKeybindingRegistry( |
| 23 content::BrowserContext* context, | 23 content::BrowserContext* context, |
| 24 ExtensionFilter extension_filter, | 24 ExtensionFilter extension_filter, |
| 25 Delegate* delegate) | 25 Delegate* delegate) |
| 26 : browser_context_(context), | 26 : browser_context_(context), |
| 27 extension_filter_(extension_filter), | 27 extension_filter_(extension_filter), |
| 28 delegate_(delegate), | 28 delegate_(delegate), |
| 29 extension_registry_observer_(this) { | 29 extension_registry_observer_(this) { |
| 30 extension_registry_observer_.Add(ExtensionRegistry::Get(browser_context_)); | 30 extension_registry_observer_.Add(ExtensionRegistry::Get(browser_context_)); |
| 31 | 31 |
| 32 Profile* profile = Profile::FromBrowserContext(browser_context_); | 32 Profile* profile = Profile::FromBrowserContext(browser_context_); |
| 33 registrar_.Add(this, | 33 registrar_.Add(this, |
| 34 chrome::NOTIFICATION_EXTENSION_COMMAND_ADDED, | 34 extensions::NOTIFICATION_EXTENSION_COMMAND_ADDED, |
| 35 content::Source<Profile>(profile->GetOriginalProfile())); | 35 content::Source<Profile>(profile->GetOriginalProfile())); |
| 36 registrar_.Add(this, | 36 registrar_.Add(this, |
| 37 chrome::NOTIFICATION_EXTENSION_COMMAND_REMOVED, | 37 extensions::NOTIFICATION_EXTENSION_COMMAND_REMOVED, |
| 38 content::Source<Profile>(profile->GetOriginalProfile())); | 38 content::Source<Profile>(profile->GetOriginalProfile())); |
| 39 } | 39 } |
| 40 | 40 |
| 41 ExtensionKeybindingRegistry::~ExtensionKeybindingRegistry() { | 41 ExtensionKeybindingRegistry::~ExtensionKeybindingRegistry() { |
| 42 } | 42 } |
| 43 | 43 |
| 44 void ExtensionKeybindingRegistry::RemoveExtensionKeybinding( | 44 void ExtensionKeybindingRegistry::RemoveExtensionKeybinding( |
| 45 const Extension* extension, | 45 const Extension* extension, |
| 46 const std::string& command_name) { | 46 const std::string& command_name) { |
| 47 EventTargets::iterator it = event_targets_.begin(); | 47 EventTargets::iterator it = event_targets_.begin(); |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 UnloadedExtensionInfo::Reason reason) { | 177 UnloadedExtensionInfo::Reason reason) { |
| 178 if (ExtensionMatchesFilter(extension)) | 178 if (ExtensionMatchesFilter(extension)) |
| 179 RemoveExtensionKeybinding(extension, std::string()); | 179 RemoveExtensionKeybinding(extension, std::string()); |
| 180 } | 180 } |
| 181 | 181 |
| 182 void ExtensionKeybindingRegistry::Observe( | 182 void ExtensionKeybindingRegistry::Observe( |
| 183 int type, | 183 int type, |
| 184 const content::NotificationSource& source, | 184 const content::NotificationSource& source, |
| 185 const content::NotificationDetails& details) { | 185 const content::NotificationDetails& details) { |
| 186 switch (type) { | 186 switch (type) { |
| 187 case chrome::NOTIFICATION_EXTENSION_COMMAND_ADDED: | 187 case extensions::NOTIFICATION_EXTENSION_COMMAND_ADDED: |
| 188 case chrome::NOTIFICATION_EXTENSION_COMMAND_REMOVED: { | 188 case extensions::NOTIFICATION_EXTENSION_COMMAND_REMOVED: { |
| 189 std::pair<const std::string, const std::string>* payload = | 189 std::pair<const std::string, const std::string>* payload = |
| 190 content::Details<std::pair<const std::string, const std::string> >( | 190 content::Details<std::pair<const std::string, const std::string> >( |
| 191 details).ptr(); | 191 details).ptr(); |
| 192 | 192 |
| 193 const Extension* extension = ExtensionSystem::Get(browser_context_) | 193 const Extension* extension = ExtensionSystem::Get(browser_context_) |
| 194 ->extension_service() | 194 ->extension_service() |
| 195 ->extensions() | 195 ->extensions() |
| 196 ->GetByID(payload->first); | 196 ->GetByID(payload->first); |
| 197 // During install and uninstall the extension won't be found. We'll catch | 197 // During install and uninstall the extension won't be found. We'll catch |
| 198 // those events above, with the LOADED/UNLOADED, so we ignore this event. | 198 // those events above, with the LOADED/UNLOADED, so we ignore this event. |
| 199 if (!extension) | 199 if (!extension) |
| 200 return; | 200 return; |
| 201 | 201 |
| 202 if (ExtensionMatchesFilter(extension)) { | 202 if (ExtensionMatchesFilter(extension)) { |
| 203 if (type == chrome::NOTIFICATION_EXTENSION_COMMAND_ADDED) | 203 if (type == extensions::NOTIFICATION_EXTENSION_COMMAND_ADDED) |
| 204 AddExtensionKeybinding(extension, payload->second); | 204 AddExtensionKeybinding(extension, payload->second); |
| 205 else | 205 else |
| 206 RemoveExtensionKeybinding(extension, payload->second); | 206 RemoveExtensionKeybinding(extension, payload->second); |
| 207 } | 207 } |
| 208 break; | 208 break; |
| 209 } | 209 } |
| 210 default: | 210 default: |
| 211 NOTREACHED(); | 211 NOTREACHED(); |
| 212 break; | 212 break; |
| 213 } | 213 } |
| (...skipping 26 matching lines...) Expand all Loading... |
| 240 if (extension_id.empty() || it->first == extension_id) { | 240 if (extension_id.empty() || it->first == extension_id) { |
| 241 CommandExecuted(it->first, it->second); | 241 CommandExecuted(it->first, it->second); |
| 242 executed = true; | 242 executed = true; |
| 243 } | 243 } |
| 244 } | 244 } |
| 245 | 245 |
| 246 return executed; | 246 return executed; |
| 247 } | 247 } |
| 248 | 248 |
| 249 } // namespace extensions | 249 } // namespace extensions |
| OLD | NEW |