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

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: Fix the test case!! 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++;
46 } 51 }
47 52
48 // Let each platform-specific implementation get a chance to clean up. 53 EventTargets::iterator old = it++;
49 RemoveExtensionKeybindingImpl(iter->first, command_name); 54 if (target_list.empty()) {
55 // Let each platform-specific implementation get a chance to clean up.
56 RemoveExtensionKeybindingImpl(old->first, command_name);
57 event_targets_.erase(old);
58 }
50 59
51 EventTargets::iterator old = iter++; 60 // If a specific command_name was requested, it has now been deleted so no
52 event_targets_.erase(old); 61 // further work is required.
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()) 62 if (!command_name.empty())
57 break; 63 break;
58 } 64 }
59 } 65 }
60 66
61 void ExtensionKeybindingRegistry::Init() { 67 void ExtensionKeybindingRegistry::Init() {
62 ExtensionService* service = 68 ExtensionService* service =
63 extensions::ExtensionSystem::Get(profile_)->extension_service(); 69 extensions::ExtensionSystem::Get(profile_)->extension_service();
64 if (!service) 70 if (!service)
65 return; // ExtensionService can be null during testing. 71 return; // ExtensionService can be null during testing.
66 72
67 const ExtensionSet* extensions = service->extensions(); 73 const ExtensionSet* extensions = service->extensions();
68 ExtensionSet::const_iterator iter = extensions->begin(); 74 ExtensionSet::const_iterator iter = extensions->begin();
69 for (; iter != extensions->end(); ++iter) 75 for (; iter != extensions->end(); ++iter)
70 if (ExtensionMatchesFilter(iter->get())) 76 if (ExtensionMatchesFilter(iter->get()))
71 AddExtensionKeybinding(iter->get(), std::string()); 77 AddExtensionKeybinding(iter->get(), std::string());
72 } 78 }
73 79
74 bool ExtensionKeybindingRegistry::ShouldIgnoreCommand( 80 bool ExtensionKeybindingRegistry::ShouldIgnoreCommand(
75 const std::string& command) const { 81 const std::string& command) const {
76 return command == manifest_values::kPageActionCommandEvent || 82 return command == manifest_values::kPageActionCommandEvent ||
77 command == manifest_values::kBrowserActionCommandEvent || 83 command == manifest_values::kBrowserActionCommandEvent ||
78 command == manifest_values::kScriptBadgeCommandEvent; 84 command == manifest_values::kScriptBadgeCommandEvent;
79 } 85 }
80 86
87 bool ExtensionKeybindingRegistry::NotifyEventTargets(
88 const ui::Accelerator& accelerator) {
89 EventTargets::iterator targets = event_targets_.find(accelerator);
90 if (targets == event_targets_.end() || targets->second.empty())
91 return false;
92
93 for (TargetList::const_iterator it = targets->second.begin();
94 it != targets->second.end(); it++)
95 CommandExecuted(it->first, it->second);
96
97 return true;
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