Chromium Code Reviews| Index: chrome/browser/extensions/extension_keybinding_registry.cc |
| diff --git a/chrome/browser/extensions/extension_keybinding_registry.cc b/chrome/browser/extensions/extension_keybinding_registry.cc |
| index 1d6001e280b12cde9da61c881be6af3164d68353..1603851127ece69e03c682b63afd3ad7e05cebe4 100644 |
| --- a/chrome/browser/extensions/extension_keybinding_registry.cc |
| +++ b/chrome/browser/extensions/extension_keybinding_registry.cc |
| @@ -13,8 +13,9 @@ |
| namespace extensions { |
| -ExtensionKeybindingRegistry::ExtensionKeybindingRegistry(Profile* profile) |
| - : profile_(profile) { |
| +ExtensionKeybindingRegistry::ExtensionKeybindingRegistry( |
| + Profile* profile, ExtensionFilter extension_filter) |
| + : profile_(profile), extension_filter_(extension_filter) { |
| registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED, |
| content::Source<Profile>(profile->GetOriginalProfile())); |
| registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, |
| @@ -36,7 +37,8 @@ void ExtensionKeybindingRegistry::Init() { |
| const ExtensionSet* extensions = service->extensions(); |
| ExtensionSet::const_iterator iter = extensions->begin(); |
| for (; iter != extensions->end(); ++iter) |
| - AddExtensionKeybinding(*iter, std::string()); |
| + if (ExtensionMatchesFilter(*iter)) |
| + AddExtensionKeybinding(*iter, std::string()); |
|
Finnur
2012/09/11 10:29:42
nit: This is now multiline and needs braces.
|
| } |
| bool ExtensionKeybindingRegistry::ShouldIgnoreCommand( |
| @@ -51,16 +53,20 @@ void ExtensionKeybindingRegistry::Observe( |
| const content::NotificationSource& source, |
| const content::NotificationDetails& details) { |
| switch (type) { |
| - case chrome::NOTIFICATION_EXTENSION_LOADED: |
| - AddExtensionKeybinding( |
| - content::Details<const extensions::Extension>(details).ptr(), |
| - std::string()); |
| + case chrome::NOTIFICATION_EXTENSION_LOADED: { |
| + const extensions::Extension* extension = |
| + content::Details<const extensions::Extension>(details).ptr(); |
| + if (ExtensionMatchesFilter(extension)) |
| + AddExtensionKeybinding(extension, std::string()); |
| break; |
| - case chrome::NOTIFICATION_EXTENSION_UNLOADED: |
| - RemoveExtensionKeybinding( |
| - content::Details<UnloadedExtensionInfo>(details)->extension, |
| - std::string()); |
| + } |
| + case chrome::NOTIFICATION_EXTENSION_UNLOADED: { |
| + const extensions::Extension* extension = |
| + content::Details<UnloadedExtensionInfo>(details)->extension; |
| + if (ExtensionMatchesFilter(extension)) |
| + RemoveExtensionKeybinding(extension, std::string()); |
| break; |
| + } |
| case chrome::NOTIFICATION_EXTENSION_COMMAND_ADDED: |
| case chrome::NOTIFICATION_EXTENSION_COMMAND_REMOVED: { |
| std::pair<const std::string, const std::string>* payload = |
| @@ -75,10 +81,12 @@ void ExtensionKeybindingRegistry::Observe( |
| if (!extension) |
| return; |
| - if (type == chrome::NOTIFICATION_EXTENSION_COMMAND_ADDED) |
| - AddExtensionKeybinding(extension, payload->second); |
| - else |
| - RemoveExtensionKeybinding(extension, payload->second); |
| + if (ExtensionMatchesFilter(extension)) { |
| + if (type == chrome::NOTIFICATION_EXTENSION_COMMAND_ADDED) |
| + AddExtensionKeybinding(extension, payload->second); |
| + else |
| + RemoveExtensionKeybinding(extension, payload->second); |
| + } |
|
Finnur
2012/09/11 10:29:42
I'm a little worried about the fact that this clas
|
| break; |
| } |
| default: |
| @@ -87,4 +95,18 @@ void ExtensionKeybindingRegistry::Observe( |
| } |
| } |
| +bool ExtensionKeybindingRegistry::ExtensionMatchesFilter( |
| + const extensions::Extension* extension) |
| +{ |
|
Finnur
2012/09/11 10:29:42
nit: Should be on the line above.
|
| + switch (extension_filter_) { |
| + case ALL_EXTENSIONS: |
| + return true; |
| + case PLATFORM_APPS_ONLY: |
| + return extension->is_platform_app(); |
| + default: |
| + NOTREACHED(); |
|
Finnur
2012/09/11 10:29:42
For enum types it is better to leave out the defau
|
| + } |
| + return false; |
| +} |
| + |
| } // namespace extensions |