| 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_manager.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(Profile* profile) | 18 ExtensionKeybindingRegistry::ExtensionKeybindingRegistry(Profile* profile, |
| 17 : profile_(profile) { | 19 Delegate* delegate) |
| 20 : profile_(profile), delegate_(delegate) { |
| 18 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED, | 21 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED, |
| 19 content::Source<Profile>(profile->GetOriginalProfile())); | 22 content::Source<Profile>(profile->GetOriginalProfile())); |
| 20 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, | 23 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, |
| 21 content::Source<Profile>(profile->GetOriginalProfile())); | 24 content::Source<Profile>(profile->GetOriginalProfile())); |
| 22 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_COMMAND_ADDED, | 25 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_COMMAND_ADDED, |
| 23 content::Source<Profile>(profile->GetOriginalProfile())); | 26 content::Source<Profile>(profile->GetOriginalProfile())); |
| 24 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_COMMAND_REMOVED, | 27 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_COMMAND_REMOVED, |
| 25 content::Source<Profile>(profile->GetOriginalProfile())); | 28 content::Source<Profile>(profile->GetOriginalProfile())); |
| 26 } | 29 } |
| 27 | 30 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 39 AddExtensionKeybinding(*iter, std::string()); | 42 AddExtensionKeybinding(*iter, std::string()); |
| 40 } | 43 } |
| 41 | 44 |
| 42 bool ExtensionKeybindingRegistry::ShouldIgnoreCommand( | 45 bool ExtensionKeybindingRegistry::ShouldIgnoreCommand( |
| 43 const std::string& command) const { | 46 const std::string& command) const { |
| 44 return command == extension_manifest_values::kPageActionCommandEvent || | 47 return command == extension_manifest_values::kPageActionCommandEvent || |
| 45 command == extension_manifest_values::kBrowserActionCommandEvent || | 48 command == extension_manifest_values::kBrowserActionCommandEvent || |
| 46 command == extension_manifest_values::kScriptBadgeCommandEvent; | 49 command == extension_manifest_values::kScriptBadgeCommandEvent; |
| 47 } | 50 } |
| 48 | 51 |
| 52 void ExtensionKeybindingRegistry::CommandExecuted( |
| 53 const std::string& extension_id, const std::string& command) { |
| 54 ExtensionService* service = |
| 55 ExtensionSystem::Get(profile_)->extension_service(); |
| 56 |
| 57 const Extension* extension = service->extensions()->GetByID(extension_id); |
| 58 if (!extension) |
| 59 return; |
| 60 |
| 61 // Grant before sending the event so that the permission is granted before |
| 62 // the extension acts on the command. |
| 63 ActiveTabPermissionManager* granter = |
| 64 delegate_->GetActiveTabPermissionGranter(); |
| 65 if (granter) |
| 66 granter->GrantIfRequested(extension); |
| 67 |
| 68 service->browser_event_router()->CommandExecuted(profile_, |
| 69 extension_id, |
| 70 command); |
| 71 } |
| 72 |
| 49 void ExtensionKeybindingRegistry::Observe( | 73 void ExtensionKeybindingRegistry::Observe( |
| 50 int type, | 74 int type, |
| 51 const content::NotificationSource& source, | 75 const content::NotificationSource& source, |
| 52 const content::NotificationDetails& details) { | 76 const content::NotificationDetails& details) { |
| 53 switch (type) { | 77 switch (type) { |
| 54 case chrome::NOTIFICATION_EXTENSION_LOADED: | 78 case chrome::NOTIFICATION_EXTENSION_LOADED: |
| 55 AddExtensionKeybinding( | 79 AddExtensionKeybinding( |
| 56 content::Details<const extensions::Extension>(details).ptr(), | 80 content::Details<const extensions::Extension>(details).ptr(), |
| 57 std::string()); | 81 std::string()); |
| 58 break; | 82 break; |
| (...skipping 22 matching lines...) Expand all Loading... |
| 81 RemoveExtensionKeybinding(extension, payload->second); | 105 RemoveExtensionKeybinding(extension, payload->second); |
| 82 break; | 106 break; |
| 83 } | 107 } |
| 84 default: | 108 default: |
| 85 NOTREACHED(); | 109 NOTREACHED(); |
| 86 break; | 110 break; |
| 87 } | 111 } |
| 88 } | 112 } |
| 89 | 113 |
| 90 } // namespace extensions | 114 } // namespace extensions |
| OLD | NEW |