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

Side by Side Diff: chrome/browser/extensions/api/commands/command_service.cc

Issue 23812010: Implement first part of supporting global extension commands. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Polishing a bit Created 7 years, 3 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/api/commands/command_service.h" 5 #include "chrome/browser/extensions/api/commands/command_service.h"
6 6
7 #include "base/lazy_instance.h" 7 #include "base/lazy_instance.h"
8 #include "base/strings/string_util.h" 8 #include "base/strings/string_util.h"
9 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "chrome/browser/chrome_notification_types.h" 10 #include "chrome/browser/chrome_notification_types.h"
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 const std::string& extension_id, 118 const std::string& extension_id,
119 QueryType type, 119 QueryType type,
120 extensions::Command* command, 120 extensions::Command* command,
121 bool* active) { 121 bool* active) {
122 return GetExtensionActionCommand( 122 return GetExtensionActionCommand(
123 extension_id, type, command, active, SCRIPT_BADGE); 123 extension_id, type, command, active, SCRIPT_BADGE);
124 } 124 }
125 125
126 bool CommandService::GetNamedCommands(const std::string& extension_id, 126 bool CommandService::GetNamedCommands(const std::string& extension_id,
127 QueryType type, 127 QueryType type,
128 CommandScope scope,
128 extensions::CommandMap* command_map) { 129 extensions::CommandMap* command_map) {
129 const ExtensionSet* extensions = 130 const ExtensionSet* extensions =
130 ExtensionSystem::Get(profile_)->extension_service()->extensions(); 131 ExtensionSystem::Get(profile_)->extension_service()->extensions();
131 const Extension* extension = extensions->GetByID(extension_id); 132 const Extension* extension = extensions->GetByID(extension_id);
132 CHECK(extension); 133 CHECK(extension);
133 134
134 command_map->clear(); 135 command_map->clear();
135 const extensions::CommandMap* commands = 136 const extensions::CommandMap* commands =
136 CommandsInfo::GetNamedCommands(extension); 137 CommandsInfo::GetNamedCommands(extension);
137 if (!commands) 138 if (!commands)
138 return false; 139 return false;
139 140
140 extensions::CommandMap::const_iterator iter = commands->begin(); 141 extensions::CommandMap::const_iterator iter = commands->begin();
141 for (; iter != commands->end(); ++iter) { 142 for (; iter != commands->end(); ++iter) {
142 ui::Accelerator shortcut_assigned = 143 ui::Accelerator shortcut_assigned =
143 FindShortcutForCommand(extension_id, iter->second.command_name()); 144 FindShortcutForCommand(extension_id, iter->second.command_name());
144 145
145 if (type == ACTIVE_ONLY && shortcut_assigned.key_code() == ui::VKEY_UNKNOWN) 146 if (type == ACTIVE_ONLY && shortcut_assigned.key_code() == ui::VKEY_UNKNOWN)
146 continue; 147 continue;
147 148
148 extensions::Command command = iter->second; 149 extensions::Command command = iter->second;
150 if (scope != ANY_SCOPE && ((scope == GLOBAL) != command.global()))
151 continue;
152
149 if (shortcut_assigned.key_code() != ui::VKEY_UNKNOWN) 153 if (shortcut_assigned.key_code() != ui::VKEY_UNKNOWN)
150 command.set_accelerator(shortcut_assigned); 154 command.set_accelerator(shortcut_assigned);
151 155
152 (*command_map)[iter->second.command_name()] = command; 156 (*command_map)[iter->second.command_name()] = command;
153 } 157 }
154 158
155 return true; 159 return true;
156 } 160 }
157 161
158 bool CommandService::AddKeybindingPref( 162 bool CommandService::AddKeybindingPref(
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after
398 return false; 402 return false;
399 403
400 *command = *requested_command; 404 *command = *requested_command;
401 if (shortcut_assigned.key_code() != ui::VKEY_UNKNOWN) 405 if (shortcut_assigned.key_code() != ui::VKEY_UNKNOWN)
402 command->set_accelerator(shortcut_assigned); 406 command->set_accelerator(shortcut_assigned);
403 407
404 return true; 408 return true;
405 } 409 }
406 410
407 } // namespace extensions 411 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698