| 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 "chrome/browser/extensions/active_tab_permission_granter.h" |
| 8 #include "chrome/browser/extensions/browser_event_router.h" |
| 7 #include "chrome/browser/extensions/extension_service.h" | 9 #include "chrome/browser/extensions/extension_service.h" |
| 8 #include "chrome/browser/extensions/extension_system.h" | 10 #include "chrome/browser/extensions/extension_system.h" |
| 9 #include "chrome/browser/profiles/profile.h" | 11 #include "chrome/browser/profiles/profile.h" |
| 10 #include "chrome/common/chrome_notification_types.h" | 12 #include "chrome/common/chrome_notification_types.h" |
| 11 #include "chrome/common/extensions/extension_manifest_constants.h" | 13 #include "chrome/common/extensions/extension_manifest_constants.h" |
| 12 #include "chrome/common/extensions/extension_set.h" | 14 #include "chrome/common/extensions/extension_set.h" |
| 13 | 15 |
| 14 namespace extensions { | 16 namespace extensions { |
| 15 | 17 |
| 16 ExtensionKeybindingRegistry::ExtensionKeybindingRegistry( | 18 ExtensionKeybindingRegistry::ExtensionKeybindingRegistry( |
| 17 Profile* profile, ExtensionFilter extension_filter) | 19 Profile* profile, ExtensionFilter extension_filter, Delegate* delegate) |
| 18 : profile_(profile), extension_filter_(extension_filter) { | 20 : profile_(profile), |
| 21 extension_filter_(extension_filter), |
| 22 delegate_(delegate) { |
| 19 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED, | 23 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED, |
| 20 content::Source<Profile>(profile->GetOriginalProfile())); | 24 content::Source<Profile>(profile->GetOriginalProfile())); |
| 21 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, | 25 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, |
| 22 content::Source<Profile>(profile->GetOriginalProfile())); | 26 content::Source<Profile>(profile->GetOriginalProfile())); |
| 23 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_COMMAND_ADDED, | 27 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_COMMAND_ADDED, |
| 24 content::Source<Profile>(profile->GetOriginalProfile())); | 28 content::Source<Profile>(profile->GetOriginalProfile())); |
| 25 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_COMMAND_REMOVED, | 29 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_COMMAND_REMOVED, |
| 26 content::Source<Profile>(profile->GetOriginalProfile())); | 30 content::Source<Profile>(profile->GetOriginalProfile())); |
| 27 } | 31 } |
| 28 | 32 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 41 AddExtensionKeybinding(*iter, std::string()); | 45 AddExtensionKeybinding(*iter, std::string()); |
| 42 } | 46 } |
| 43 | 47 |
| 44 bool ExtensionKeybindingRegistry::ShouldIgnoreCommand( | 48 bool ExtensionKeybindingRegistry::ShouldIgnoreCommand( |
| 45 const std::string& command) const { | 49 const std::string& command) const { |
| 46 return command == extension_manifest_values::kPageActionCommandEvent || | 50 return command == extension_manifest_values::kPageActionCommandEvent || |
| 47 command == extension_manifest_values::kBrowserActionCommandEvent || | 51 command == extension_manifest_values::kBrowserActionCommandEvent || |
| 48 command == extension_manifest_values::kScriptBadgeCommandEvent; | 52 command == extension_manifest_values::kScriptBadgeCommandEvent; |
| 49 } | 53 } |
| 50 | 54 |
| 55 void ExtensionKeybindingRegistry::CommandExecuted( |
| 56 const std::string& extension_id, const std::string& command) { |
| 57 ExtensionService* service = |
| 58 ExtensionSystem::Get(profile_)->extension_service(); |
| 59 |
| 60 const Extension* extension = service->extensions()->GetByID(extension_id); |
| 61 if (!extension) |
| 62 return; |
| 63 |
| 64 // Grant before sending the event so that the permission is granted before |
| 65 // the extension acts on the command. |
| 66 ActiveTabPermissionGranter* granter = |
| 67 delegate_->GetActiveTabPermissionGranter(); |
| 68 if (granter) |
| 69 granter->GrantIfRequested(extension); |
| 70 |
| 71 service->browser_event_router()->CommandExecuted(profile_, |
| 72 extension_id, |
| 73 command); |
| 74 } |
| 75 |
| 51 void ExtensionKeybindingRegistry::Observe( | 76 void ExtensionKeybindingRegistry::Observe( |
| 52 int type, | 77 int type, |
| 53 const content::NotificationSource& source, | 78 const content::NotificationSource& source, |
| 54 const content::NotificationDetails& details) { | 79 const content::NotificationDetails& details) { |
| 55 switch (type) { | 80 switch (type) { |
| 56 case chrome::NOTIFICATION_EXTENSION_LOADED: { | 81 case chrome::NOTIFICATION_EXTENSION_LOADED: { |
| 57 const extensions::Extension* extension = | 82 const extensions::Extension* extension = |
| 58 content::Details<const extensions::Extension>(details).ptr(); | 83 content::Details<const extensions::Extension>(details).ptr(); |
| 59 if (ExtensionMatchesFilter(extension)) | 84 if (ExtensionMatchesFilter(extension)) |
| 60 AddExtensionKeybinding(extension, std::string()); | 85 AddExtensionKeybinding(extension, std::string()); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 return true; | 128 return true; |
| 104 case PLATFORM_APPS_ONLY: | 129 case PLATFORM_APPS_ONLY: |
| 105 return extension->is_platform_app(); | 130 return extension->is_platform_app(); |
| 106 default: | 131 default: |
| 107 NOTREACHED(); | 132 NOTREACHED(); |
| 108 } | 133 } |
| 109 return false; | 134 return false; |
| 110 } | 135 } |
| 111 | 136 |
| 112 } // namespace extensions | 137 } // namespace extensions |
| OLD | NEW |