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

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

Issue 64273008: [Windows] Finish global and non-global media keys support on Windows. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address comments. Created 7 years, 1 month 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
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/api/commands/command_service.h"
10 #include "chrome/browser/extensions/event_router.h" 11 #include "chrome/browser/extensions/event_router.h"
11 #include "chrome/browser/extensions/extension_service.h" 12 #include "chrome/browser/extensions/extension_service.h"
12 #include "chrome/browser/extensions/extension_system.h" 13 #include "chrome/browser/extensions/extension_system.h"
13 #include "chrome/browser/profiles/profile.h" 14 #include "chrome/browser/profiles/profile.h"
14 #include "chrome/common/extensions/extension_set.h" 15 #include "chrome/common/extensions/extension_set.h"
15 #include "extensions/common/manifest_constants.h" 16 #include "extensions/common/manifest_constants.h"
16 17
17 namespace extensions { 18 namespace extensions {
18 19
19 ExtensionKeybindingRegistry::ExtensionKeybindingRegistry( 20 ExtensionKeybindingRegistry::ExtensionKeybindingRegistry(
(...skipping 10 matching lines...) Expand all
30 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_COMMAND_REMOVED, 31 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_COMMAND_REMOVED,
31 content::Source<Profile>(profile->GetOriginalProfile())); 32 content::Source<Profile>(profile->GetOriginalProfile()));
32 } 33 }
33 34
34 ExtensionKeybindingRegistry::~ExtensionKeybindingRegistry() { 35 ExtensionKeybindingRegistry::~ExtensionKeybindingRegistry() {
35 } 36 }
36 37
37 void ExtensionKeybindingRegistry::RemoveExtensionKeybinding( 38 void ExtensionKeybindingRegistry::RemoveExtensionKeybinding(
38 const Extension* extension, 39 const Extension* extension,
39 const std::string& command_name) { 40 const std::string& command_name) {
40 EventTargets::iterator iter = event_targets_.begin(); 41 EventTargets::iterator it = event_targets_.begin();
41 while (iter != event_targets_.end()) { 42 while (it != event_targets_.end()) {
42 if (iter->second.first != extension->id() || 43 TargetList& target_list = it->second;
43 (!command_name.empty() && (iter->second.second != command_name))) { 44 TargetList::iterator target = target_list.begin();
44 ++iter; 45 while (target != target_list.end()) {
45 continue; // Not the extension or command we asked for. 46 if (target->first == extension->id() &&
47 (command_name.empty() || command_name == target->second)) {
48 target = target_list.erase(target);
Finnur 2013/11/18 11:16:14 Um, how does this work? Don't you need to advance
zhchbin 2013/11/18 13:10:13 The return value is an iterator pointing to the ne
Finnur 2013/11/18 14:14:53 Oh, I missed the assignment there.
49 } else {
50 target++;
51 }
Finnur 2013/11/18 11:16:14 Nit: Both of these are single-line so no braces ne
zhchbin 2013/11/18 13:10:13 Done.
46 } 52 }
47 53
48 // Let each platform-specific implementation get a chance to clean up. 54 EventTargets::iterator old = it++;
49 RemoveExtensionKeybindingImpl(iter->first, command_name); 55 if (target_list.empty()) {
56 // Let each platform-specific implementation get a chance to clean up.
57 RemoveExtensionKeybindingImpl(old->first, command_name);
58 event_targets_.erase(old);
50 59
51 EventTargets::iterator old = iter++; 60 // If a specific command_name was requested, it has now been deleted so
52 event_targets_.erase(old); 61 // no further work is required.
53 62 if (!command_name.empty())
54 // If a specific command_name was requested, it has now been deleted so 63 break;
Finnur 2013/11/18 11:16:14 I think this should be outside the if clause that
zhchbin 2013/11/18 13:10:13 Done.
55 // no further work is required. 64 }
56 if (!command_name.empty())
57 break;
58 } 65 }
59 } 66 }
60 67
61 void ExtensionKeybindingRegistry::Init() { 68 void ExtensionKeybindingRegistry::Init() {
62 ExtensionService* service = 69 ExtensionService* service =
63 extensions::ExtensionSystem::Get(profile_)->extension_service(); 70 extensions::ExtensionSystem::Get(profile_)->extension_service();
64 if (!service) 71 if (!service)
65 return; // ExtensionService can be null during testing. 72 return; // ExtensionService can be null during testing.
66 73
67 const ExtensionSet* extensions = service->extensions(); 74 const ExtensionSet* extensions = service->extensions();
68 ExtensionSet::const_iterator iter = extensions->begin(); 75 ExtensionSet::const_iterator iter = extensions->begin();
69 for (; iter != extensions->end(); ++iter) 76 for (; iter != extensions->end(); ++iter)
70 if (ExtensionMatchesFilter(iter->get())) 77 if (ExtensionMatchesFilter(iter->get()))
71 AddExtensionKeybinding(iter->get(), std::string()); 78 AddExtensionKeybinding(iter->get(), std::string());
72 } 79 }
73 80
74 bool ExtensionKeybindingRegistry::ShouldIgnoreCommand( 81 bool ExtensionKeybindingRegistry::ShouldIgnoreCommand(
75 const std::string& command) const { 82 const std::string& command) const {
76 return command == manifest_values::kPageActionCommandEvent || 83 return command == manifest_values::kPageActionCommandEvent ||
77 command == manifest_values::kBrowserActionCommandEvent || 84 command == manifest_values::kBrowserActionCommandEvent ||
78 command == manifest_values::kScriptBadgeCommandEvent; 85 command == manifest_values::kScriptBadgeCommandEvent;
79 } 86 }
80 87
88 bool ExtensionKeybindingRegistry::NotifyEventTargetsByAccelerator(
89 const ui::Accelerator& accelerator) {
90 EventTargets::iterator targets = event_targets_.find(accelerator);
91 if (targets == event_targets_.end() || targets->second.empty())
92 return false;
93
94 for (TargetList::const_iterator it = targets->second.begin();
95 it != targets->second.end(); it++)
96 CommandExecuted(it->first, it->second);
97 return true;
Finnur 2013/11/18 11:16:14 nit: Line break above.
zhchbin 2013/11/18 13:10:13 Done.
98 }
99
81 void ExtensionKeybindingRegistry::CommandExecuted( 100 void ExtensionKeybindingRegistry::CommandExecuted(
82 const std::string& extension_id, const std::string& command) { 101 const std::string& extension_id, const std::string& command) {
83 ExtensionService* service = 102 ExtensionService* service =
84 ExtensionSystem::Get(profile_)->extension_service(); 103 ExtensionSystem::Get(profile_)->extension_service();
85 104
86 const Extension* extension = service->extensions()->GetByID(extension_id); 105 const Extension* extension = service->extensions()->GetByID(extension_id);
87 if (!extension) 106 if (!extension)
88 return; 107 return;
89 108
90 // Grant before sending the event so that the permission is granted before 109 // Grant before sending the event so that the permission is granted before
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 return true; 180 return true;
162 case PLATFORM_APPS_ONLY: 181 case PLATFORM_APPS_ONLY:
163 return extension->is_platform_app(); 182 return extension->is_platform_app();
164 default: 183 default:
165 NOTREACHED(); 184 NOTREACHED();
166 } 185 }
167 return false; 186 return false;
168 } 187 }
169 188
170 } // namespace extensions 189 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698