OLD | NEW |
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/strings/string_number_conversions.h" | 8 #include "base/strings/string_number_conversions.h" |
9 #include "base/strings/string_split.h" | 9 #include "base/strings/string_split.h" |
10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
(...skipping 29 matching lines...) Expand all Loading... |
40 return accelerator != values::kKeyMediaNextTrack && | 40 return accelerator != values::kKeyMediaNextTrack && |
41 accelerator != values::kKeyMediaPlayPause && | 41 accelerator != values::kKeyMediaPlayPause && |
42 accelerator != values::kKeyMediaPrevTrack && | 42 accelerator != values::kKeyMediaPrevTrack && |
43 accelerator != values::kKeyMediaStop; | 43 accelerator != values::kKeyMediaStop; |
44 } | 44 } |
45 | 45 |
46 ui::Accelerator ParseImpl(const std::string& accelerator, | 46 ui::Accelerator ParseImpl(const std::string& accelerator, |
47 const std::string& platform_key, | 47 const std::string& platform_key, |
48 int index, | 48 int index, |
49 bool should_parse_media_keys, | 49 bool should_parse_media_keys, |
50 string16* error) { | 50 base::string16* error) { |
51 error->clear(); | 51 error->clear(); |
52 if (platform_key != values::kKeybindingPlatformWin && | 52 if (platform_key != values::kKeybindingPlatformWin && |
53 platform_key != values::kKeybindingPlatformMac && | 53 platform_key != values::kKeybindingPlatformMac && |
54 platform_key != values::kKeybindingPlatformChromeOs && | 54 platform_key != values::kKeybindingPlatformChromeOs && |
55 platform_key != values::kKeybindingPlatformLinux && | 55 platform_key != values::kKeybindingPlatformLinux && |
56 platform_key != values::kKeybindingPlatformDefault) { | 56 platform_key != values::kKeybindingPlatformDefault) { |
57 *error = ErrorUtils::FormatErrorMessageUTF16( | 57 *error = ErrorUtils::FormatErrorMessageUTF16( |
58 errors::kInvalidKeyBindingUnknownPlatform, | 58 errors::kInvalidKeyBindingUnknownPlatform, |
59 base::IntToString(index), | 59 base::IntToString(index), |
60 platform_key); | 60 platform_key); |
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
248 tokens[i] = values::kKeyCtrl; | 248 tokens[i] = values::kKeyCtrl; |
249 } | 249 } |
250 return JoinString(tokens, '+'); | 250 return JoinString(tokens, '+'); |
251 } | 251 } |
252 | 252 |
253 } // namespace | 253 } // namespace |
254 | 254 |
255 Command::Command() : global_(false) {} | 255 Command::Command() : global_(false) {} |
256 | 256 |
257 Command::Command(const std::string& command_name, | 257 Command::Command(const std::string& command_name, |
258 const string16& description, | 258 const base::string16& description, |
259 const std::string& accelerator, | 259 const std::string& accelerator, |
260 bool global) | 260 bool global) |
261 : command_name_(command_name), | 261 : command_name_(command_name), |
262 description_(description), | 262 description_(description), |
263 global_(global) { | 263 global_(global) { |
264 string16 error; | 264 base::string16 error; |
265 accelerator_ = ParseImpl(accelerator, CommandPlatform(), 0, | 265 accelerator_ = ParseImpl(accelerator, CommandPlatform(), 0, |
266 IsNamedCommand(command_name), &error); | 266 IsNamedCommand(command_name), &error); |
267 } | 267 } |
268 | 268 |
269 Command::~Command() {} | 269 Command::~Command() {} |
270 | 270 |
271 // static | 271 // static |
272 std::string Command::CommandPlatform() { | 272 std::string Command::CommandPlatform() { |
273 #if defined(OS_WIN) | 273 #if defined(OS_WIN) |
274 return values::kKeybindingPlatformWin; | 274 return values::kKeybindingPlatformWin; |
275 #elif defined(OS_MACOSX) | 275 #elif defined(OS_MACOSX) |
276 return values::kKeybindingPlatformMac; | 276 return values::kKeybindingPlatformMac; |
277 #elif defined(OS_CHROMEOS) | 277 #elif defined(OS_CHROMEOS) |
278 return values::kKeybindingPlatformChromeOs; | 278 return values::kKeybindingPlatformChromeOs; |
279 #elif defined(OS_LINUX) | 279 #elif defined(OS_LINUX) |
280 return values::kKeybindingPlatformLinux; | 280 return values::kKeybindingPlatformLinux; |
281 #else | 281 #else |
282 return ""; | 282 return ""; |
283 #endif | 283 #endif |
284 } | 284 } |
285 | 285 |
286 // static | 286 // static |
287 ui::Accelerator Command::StringToAccelerator(const std::string& accelerator, | 287 ui::Accelerator Command::StringToAccelerator(const std::string& accelerator, |
288 const std::string& command_name) { | 288 const std::string& command_name) { |
289 string16 error; | 289 base::string16 error; |
290 ui::Accelerator parsed = | 290 ui::Accelerator parsed = |
291 ParseImpl(accelerator, Command::CommandPlatform(), 0, | 291 ParseImpl(accelerator, Command::CommandPlatform(), 0, |
292 IsNamedCommand(command_name), &error); | 292 IsNamedCommand(command_name), &error); |
293 return parsed; | 293 return parsed; |
294 } | 294 } |
295 | 295 |
296 // static | 296 // static |
297 std::string Command::AcceleratorToString(const ui::Accelerator& accelerator) { | 297 std::string Command::AcceleratorToString(const ui::Accelerator& accelerator) { |
298 std::string shortcut; | 298 std::string shortcut; |
299 | 299 |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
377 default: | 377 default: |
378 return ""; | 378 return ""; |
379 } | 379 } |
380 } | 380 } |
381 return shortcut; | 381 return shortcut; |
382 } | 382 } |
383 | 383 |
384 bool Command::Parse(const base::DictionaryValue* command, | 384 bool Command::Parse(const base::DictionaryValue* command, |
385 const std::string& command_name, | 385 const std::string& command_name, |
386 int index, | 386 int index, |
387 string16* error) { | 387 base::string16* error) { |
388 DCHECK(!command_name.empty()); | 388 DCHECK(!command_name.empty()); |
389 | 389 |
390 string16 description; | 390 base::string16 description; |
391 if (IsNamedCommand(command_name)) { | 391 if (IsNamedCommand(command_name)) { |
392 if (!command->GetString(keys::kDescription, &description) || | 392 if (!command->GetString(keys::kDescription, &description) || |
393 description.empty()) { | 393 description.empty()) { |
394 *error = ErrorUtils::FormatErrorMessageUTF16( | 394 *error = ErrorUtils::FormatErrorMessageUTF16( |
395 errors::kInvalidKeyBindingDescription, | 395 errors::kInvalidKeyBindingDescription, |
396 base::IntToString(index)); | 396 base::IntToString(index)); |
397 return false; | 397 return false; |
398 } | 398 } |
399 } | 399 } |
400 | 400 |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
507 global_ = global; | 507 global_ = global; |
508 } | 508 } |
509 } | 509 } |
510 return true; | 510 return true; |
511 } | 511 } |
512 | 512 |
513 base::DictionaryValue* Command::ToValue(const Extension* extension, | 513 base::DictionaryValue* Command::ToValue(const Extension* extension, |
514 bool active) const { | 514 bool active) const { |
515 base::DictionaryValue* extension_data = new base::DictionaryValue(); | 515 base::DictionaryValue* extension_data = new base::DictionaryValue(); |
516 | 516 |
517 string16 command_description; | 517 base::string16 command_description; |
518 bool extension_action = false; | 518 bool extension_action = false; |
519 if (command_name() == values::kBrowserActionCommandEvent || | 519 if (command_name() == values::kBrowserActionCommandEvent || |
520 command_name() == values::kPageActionCommandEvent || | 520 command_name() == values::kPageActionCommandEvent || |
521 command_name() == values::kScriptBadgeCommandEvent) { | 521 command_name() == values::kScriptBadgeCommandEvent) { |
522 command_description = | 522 command_description = |
523 l10n_util::GetStringUTF16(IDS_EXTENSION_COMMANDS_GENERIC_ACTIVATE); | 523 l10n_util::GetStringUTF16(IDS_EXTENSION_COMMANDS_GENERIC_ACTIVATE); |
524 extension_action = true; | 524 extension_action = true; |
525 } else { | 525 } else { |
526 command_description = description(); | 526 command_description = description(); |
527 } | 527 } |
(...skipping 10 matching lines...) Expand all Loading... |
538 // dev and will be removed when we launch. | 538 // dev and will be removed when we launch. |
539 static bool stable_or_beta = | 539 static bool stable_or_beta = |
540 chrome::VersionInfo::GetChannel() >= chrome::VersionInfo::CHANNEL_BETA; | 540 chrome::VersionInfo::GetChannel() >= chrome::VersionInfo::CHANNEL_BETA; |
541 extension_data->SetBoolean("scope_ui_visible", !stable_or_beta); | 541 extension_data->SetBoolean("scope_ui_visible", !stable_or_beta); |
542 } | 542 } |
543 | 543 |
544 return extension_data; | 544 return extension_data; |
545 } | 545 } |
546 | 546 |
547 } // namespace extensions | 547 } // namespace extensions |
OLD | NEW |