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

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: Update. 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);
49 } else {
50 target++;
51 }
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()) {
50 56 // Let each platform-specific implementation get a chance to clean up.
51 EventTargets::iterator old = iter++; 57 RemoveExtensionKeybindingImpl(old->first, command_name);
52 event_targets_.erase(old); 58 event_targets_.erase(old);
53 59 }
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;
Finnur 2013/11/15 21:10:10 Don't we still need this?
zhchbin 2013/11/16 01:33:31 Done. I had noticed this, but seems I'm wrong at t
58 } 60 }
59 } 61 }
60 62
61 void ExtensionKeybindingRegistry::Init() { 63 void ExtensionKeybindingRegistry::Init() {
62 ExtensionService* service = 64 ExtensionService* service =
63 extensions::ExtensionSystem::Get(profile_)->extension_service(); 65 extensions::ExtensionSystem::Get(profile_)->extension_service();
64 if (!service) 66 if (!service)
65 return; // ExtensionService can be null during testing. 67 return; // ExtensionService can be null during testing.
66 68
67 const ExtensionSet* extensions = service->extensions(); 69 const ExtensionSet* extensions = service->extensions();
68 ExtensionSet::const_iterator iter = extensions->begin(); 70 ExtensionSet::const_iterator iter = extensions->begin();
69 for (; iter != extensions->end(); ++iter) 71 for (; iter != extensions->end(); ++iter)
70 if (ExtensionMatchesFilter(iter->get())) 72 if (ExtensionMatchesFilter(iter->get()))
71 AddExtensionKeybinding(iter->get(), std::string()); 73 AddExtensionKeybinding(iter->get(), std::string());
72 } 74 }
73 75
74 bool ExtensionKeybindingRegistry::ShouldIgnoreCommand( 76 bool ExtensionKeybindingRegistry::ShouldIgnoreCommand(
75 const std::string& command) const { 77 const std::string& command) const {
76 return command == manifest_values::kPageActionCommandEvent || 78 return command == manifest_values::kPageActionCommandEvent ||
77 command == manifest_values::kBrowserActionCommandEvent || 79 command == manifest_values::kBrowserActionCommandEvent ||
78 command == manifest_values::kScriptBadgeCommandEvent; 80 command == manifest_values::kScriptBadgeCommandEvent;
79 } 81 }
80 82
83 bool ExtensionKeybindingRegistry::NotifyEventTargetsByAccelerator(
84 const ui::Accelerator& accelerator) {
85 EventTargets::iterator targets = event_targets_.find(accelerator);
86 if (targets == event_targets_.end() || targets->second.empty())
87 return false;
88
89 for (TargetList::const_iterator it = targets->second.begin();
90 it != targets->second.end(); it++)
91 CommandExecuted(it->first, it->second);
92 return true;
93 }
94
81 void ExtensionKeybindingRegistry::CommandExecuted( 95 void ExtensionKeybindingRegistry::CommandExecuted(
82 const std::string& extension_id, const std::string& command) { 96 const std::string& extension_id, const std::string& command) {
83 ExtensionService* service = 97 ExtensionService* service =
84 ExtensionSystem::Get(profile_)->extension_service(); 98 ExtensionSystem::Get(profile_)->extension_service();
85 99
86 const Extension* extension = service->extensions()->GetByID(extension_id); 100 const Extension* extension = service->extensions()->GetByID(extension_id);
87 if (!extension) 101 if (!extension)
88 return; 102 return;
89 103
90 // Grant before sending the event so that the permission is granted before 104 // 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; 175 return true;
162 case PLATFORM_APPS_ONLY: 176 case PLATFORM_APPS_ONLY:
163 return extension->is_platform_app(); 177 return extension->is_platform_app();
164 default: 178 default:
165 NOTREACHED(); 179 NOTREACHED();
166 } 180 }
167 return false; 181 return false;
168 } 182 }
169 183
170 } // namespace extensions 184 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698