Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(97)

Side by Side Diff: chrome/browser/extensions/extension_keybinding_registry.cc

Issue 23812010: Implement first part of supporting global extension commands. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: gclient sync Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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" 8 #include "chrome/browser/chrome_notification_types.h"
9 #include "chrome/browser/extensions/active_tab_permission_granter.h" 9 #include "chrome/browser/extensions/active_tab_permission_granter.h"
10 #include "chrome/browser/extensions/event_router.h" 10 #include "chrome/browser/extensions/event_router.h"
(...skipping 16 matching lines...) Expand all
27 content::Source<Profile>(profile->GetOriginalProfile())); 27 content::Source<Profile>(profile->GetOriginalProfile()));
28 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_COMMAND_ADDED, 28 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_COMMAND_ADDED,
29 content::Source<Profile>(profile->GetOriginalProfile())); 29 content::Source<Profile>(profile->GetOriginalProfile()));
30 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_COMMAND_REMOVED, 30 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_COMMAND_REMOVED,
31 content::Source<Profile>(profile->GetOriginalProfile())); 31 content::Source<Profile>(profile->GetOriginalProfile()));
32 } 32 }
33 33
34 ExtensionKeybindingRegistry::~ExtensionKeybindingRegistry() { 34 ExtensionKeybindingRegistry::~ExtensionKeybindingRegistry() {
35 } 35 }
36 36
37 void ExtensionKeybindingRegistry::RemoveExtensionKeybinding(
38 const Extension* extension,
39 const std::string& command_name) {
40 EventTargets::iterator iter = event_targets_.begin();
41 while (iter != event_targets_.end()) {
42 if (iter->second.first != extension->id() ||
43 (!command_name.empty() && (iter->second.second != command_name))) {
44 ++iter;
45 continue; // Not the extension or command we asked for.
46 }
47
48 // Let each platform-specific implementation get a chance to clean up.
49 RemoveExtensionKeybindingImpl(iter->first, command_name);
50
51 EventTargets::iterator old = iter++;
52 event_targets_.erase(old);
53
54 // If a specific command_name was requested, it has now been deleted so
55 // no further work is required.
56 if (!command_name.empty())
57 break;
58 }
59 }
60
37 void ExtensionKeybindingRegistry::Init() { 61 void ExtensionKeybindingRegistry::Init() {
38 ExtensionService* service = 62 ExtensionService* service =
39 extensions::ExtensionSystem::Get(profile_)->extension_service(); 63 extensions::ExtensionSystem::Get(profile_)->extension_service();
40 if (!service) 64 if (!service)
41 return; // ExtensionService can be null during testing. 65 return; // ExtensionService can be null during testing.
42 66
43 const ExtensionSet* extensions = service->extensions(); 67 const ExtensionSet* extensions = service->extensions();
44 ExtensionSet::const_iterator iter = extensions->begin(); 68 ExtensionSet::const_iterator iter = extensions->begin();
45 for (; iter != extensions->end(); ++iter) 69 for (; iter != extensions->end(); ++iter)
46 if (ExtensionMatchesFilter(iter->get())) 70 if (ExtensionMatchesFilter(iter->get()))
(...skipping 10 matching lines...) Expand all
57 void ExtensionKeybindingRegistry::CommandExecuted( 81 void ExtensionKeybindingRegistry::CommandExecuted(
58 const std::string& extension_id, const std::string& command) { 82 const std::string& extension_id, const std::string& command) {
59 ExtensionService* service = 83 ExtensionService* service =
60 ExtensionSystem::Get(profile_)->extension_service(); 84 ExtensionSystem::Get(profile_)->extension_service();
61 85
62 const Extension* extension = service->extensions()->GetByID(extension_id); 86 const Extension* extension = service->extensions()->GetByID(extension_id);
63 if (!extension) 87 if (!extension)
64 return; 88 return;
65 89
66 // Grant before sending the event so that the permission is granted before 90 // Grant before sending the event so that the permission is granted before
67 // the extension acts on the command. 91 // the extension acts on the command. NOTE: The Global Commands handler does
92 // not set the delegate as it deals only with named commands (not page/browser
93 // actions that are associated with the current page directly).
68 ActiveTabPermissionGranter* granter = 94 ActiveTabPermissionGranter* granter =
69 delegate_->GetActiveTabPermissionGranter(); 95 delegate_ ? delegate_->GetActiveTabPermissionGranter() : NULL;
70 if (granter) 96 if (granter)
71 granter->GrantIfRequested(extension); 97 granter->GrantIfRequested(extension);
72 98
73 scoped_ptr<base::ListValue> args(new base::ListValue()); 99 scoped_ptr<base::ListValue> args(new base::ListValue());
74 args->Append(new base::StringValue(command)); 100 args->Append(new base::StringValue(command));
75 101
76 scoped_ptr<Event> event(new Event("commands.onCommand", args.Pass())); 102 scoped_ptr<Event> event(new Event("commands.onCommand", args.Pass()));
77 event->restrict_to_profile = profile_; 103 event->restrict_to_profile = profile_;
78 event->user_gesture = EventRouter::USER_GESTURE_ENABLED; 104 event->user_gesture = EventRouter::USER_GESTURE_ENABLED;
79 ExtensionSystem::Get(profile_)->event_router()-> 105 ExtensionSystem::Get(profile_)->event_router()->
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 return true; 161 return true;
136 case PLATFORM_APPS_ONLY: 162 case PLATFORM_APPS_ONLY:
137 return extension->is_platform_app(); 163 return extension->is_platform_app();
138 default: 164 default:
139 NOTREACHED(); 165 NOTREACHED();
140 } 166 }
141 return false; 167 return false;
142 } 168 }
143 169
144 } // namespace extensions 170 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_keybinding_registry.h ('k') | chrome/browser/extensions/global_shortcut_listener.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698