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

Side by Side Diff: chrome/common/extensions/command.cc

Issue 11662013: Move Commands from Extension to CommandsHandler (Closed) Base URL: http://git.chromium.org/chromium/src.git@dc_unref_script_badge
Patch Set: Created 7 years, 12 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
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/common/extensions/command.h" 5 #include "chrome/common/extensions/command.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/string_number_conversions.h" 8 #include "base/string_number_conversions.h"
9 #include "base/string_split.h" 9 #include "base/string_split.h"
10 #include "base/string_util.h" 10 #include "base/string_util.h"
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 195
196 // static 196 // static
197 ui::Accelerator Command::StringToAccelerator(const std::string& accelerator) { 197 ui::Accelerator Command::StringToAccelerator(const std::string& accelerator) {
198 string16 error; 198 string16 error;
199 Command command; 199 Command command;
200 ui::Accelerator parsed = 200 ui::Accelerator parsed =
201 ParseImpl(accelerator, Command::CommandPlatform(), 0, &error); 201 ParseImpl(accelerator, Command::CommandPlatform(), 0, &error);
202 return parsed; 202 return parsed;
203 } 203 }
204 204
205 bool Command::Parse(DictionaryValue* command, 205 bool Command::Parse(const base::DictionaryValue* command,
206 const std::string& command_name, 206 const std::string& command_name,
207 int index, 207 int index,
208 string16* error) { 208 string16* error) {
209 DCHECK(!command_name.empty()); 209 DCHECK(!command_name.empty());
210 210
211 // We'll build up a map of platform-to-shortcut suggestions. 211 // We'll build up a map of platform-to-shortcut suggestions.
212 typedef std::map<const std::string, std::string> SuggestionMap; 212 typedef std::map<const std::string, std::string> SuggestionMap;
213 SuggestionMap suggestions; 213 SuggestionMap suggestions;
214 214
215 // First try to parse the |suggested_key| as a dictionary. 215 // First try to parse the |suggested_key| as a dictionary.
216 DictionaryValue* suggested_key_dict; 216 const base::DictionaryValue* suggested_key_dict;
217 if (command->GetDictionary(keys::kSuggestedKey, &suggested_key_dict)) { 217 if (command->GetDictionary(keys::kSuggestedKey, &suggested_key_dict)) {
218 DictionaryValue::key_iterator iter = suggested_key_dict->begin_keys(); 218 base::DictionaryValue::key_iterator iter = suggested_key_dict->begin_keys();
219 for ( ; iter != suggested_key_dict->end_keys(); ++iter) { 219 for ( ; iter != suggested_key_dict->end_keys(); ++iter) {
220 // For each item in the dictionary, extract the platforms specified. 220 // For each item in the dictionary, extract the platforms specified.
221 std::string suggested_key_string; 221 std::string suggested_key_string;
222 if (suggested_key_dict->GetString(*iter, &suggested_key_string) && 222 if (suggested_key_dict->GetString(*iter, &suggested_key_string) &&
223 !suggested_key_string.empty()) { 223 !suggested_key_string.empty()) {
224 // Found a platform, add it to the suggestions list. 224 // Found a platform, add it to the suggestions list.
225 suggestions[*iter] = suggested_key_string; 225 suggestions[*iter] = suggested_key_string;
226 } else { 226 } else {
227 *error = ErrorUtils::FormatErrorMessageUTF16( 227 *error = ErrorUtils::FormatErrorMessageUTF16(
228 errors::kInvalidKeyBinding, 228 errors::kInvalidKeyBinding,
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
320 errors::kInvalidKeyBindingDescription, 320 errors::kInvalidKeyBindingDescription,
321 base::IntToString(index)); 321 base::IntToString(index));
322 return false; 322 return false;
323 } 323 }
324 } 324 }
325 } 325 }
326 } 326 }
327 return true; 327 return true;
328 } 328 }
329 329
330 DictionaryValue* Command::ToValue(const Extension* extension, 330 base::DictionaryValue* Command::ToValue(const Extension* extension,
331 bool active) const { 331 bool active) const {
332 DictionaryValue* extension_data = new DictionaryValue(); 332 base::DictionaryValue* extension_data = new base::DictionaryValue();
333 333
334 string16 command_description; 334 string16 command_description;
335 if (command_name() == values::kBrowserActionCommandEvent || 335 if (command_name() == values::kBrowserActionCommandEvent ||
336 command_name() == values::kPageActionCommandEvent || 336 command_name() == values::kPageActionCommandEvent ||
337 command_name() == values::kScriptBadgeCommandEvent) { 337 command_name() == values::kScriptBadgeCommandEvent) {
338 command_description = 338 command_description =
339 l10n_util::GetStringUTF16(IDS_EXTENSION_COMMANDS_GENERIC_ACTIVATE); 339 l10n_util::GetStringUTF16(IDS_EXTENSION_COMMANDS_GENERIC_ACTIVATE);
340 } else { 340 } else {
341 command_description = description(); 341 command_description = description();
342 } 342 }
343 extension_data->SetString("description", command_description); 343 extension_data->SetString("description", command_description);
344 extension_data->SetBoolean("active", active); 344 extension_data->SetBoolean("active", active);
345 extension_data->SetString("keybinding", accelerator().GetShortcutText()); 345 extension_data->SetString("keybinding", accelerator().GetShortcutText());
346 extension_data->SetString("command_name", command_name()); 346 extension_data->SetString("command_name", command_name());
347 extension_data->SetString("extension_id", extension->id()); 347 extension_data->SetString("extension_id", extension->id());
348 348
349 return extension_data; 349 return extension_data;
350 } 350 }
351 351
352 } // namespace extensions 352 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698