Chromium Code Reviews| 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 10 matching lines...) Expand all Loading... | |
| 21 namespace keys = manifest_keys; | 21 namespace keys = manifest_keys; |
| 22 namespace values = manifest_values; | 22 namespace values = manifest_values; |
| 23 | 23 |
| 24 namespace { | 24 namespace { |
| 25 | 25 |
| 26 static const char kMissing[] = "Missing"; | 26 static const char kMissing[] = "Missing"; |
| 27 | 27 |
| 28 static const char kCommandKeyNotSupported[] = | 28 static const char kCommandKeyNotSupported[] = |
| 29 "Command key is not supported. Note: Ctrl means Command on Mac"; | 29 "Command key is not supported. Note: Ctrl means Command on Mac"; |
| 30 | 30 |
| 31 #if defined(OS_CHROMEOS) | |
| 32 static const int kMaxTokenSize = 4; | |
|
Finnur
2014/10/30 10:04:06
Nit: I'd comment this with:
// ChromeOS supports a
David Tseng
2014/10/30 17:01:46
Done.
| |
| 33 #else | |
| 34 static const int kMaxTokenSize = 3; | |
| 35 #endif // OS_CHROMEOS | |
| 36 | |
| 31 bool IsNamedCommand(const std::string& command_name) { | 37 bool IsNamedCommand(const std::string& command_name) { |
| 32 return command_name != values::kPageActionCommandEvent && | 38 return command_name != values::kPageActionCommandEvent && |
| 33 command_name != values::kBrowserActionCommandEvent; | 39 command_name != values::kBrowserActionCommandEvent; |
| 34 } | 40 } |
| 35 | 41 |
| 36 bool DoesRequireModifier(const std::string& accelerator) { | 42 bool DoesRequireModifier(const std::string& accelerator) { |
| 37 return accelerator != values::kKeyMediaNextTrack && | 43 return accelerator != values::kKeyMediaNextTrack && |
| 38 accelerator != values::kKeyMediaPlayPause && | 44 accelerator != values::kKeyMediaPlayPause && |
| 39 accelerator != values::kKeyMediaPrevTrack && | 45 accelerator != values::kKeyMediaPrevTrack && |
| 40 accelerator != values::kKeyMediaStop; | 46 accelerator != values::kKeyMediaStop; |
| 41 } | 47 } |
| 42 | 48 |
| 43 ui::Accelerator ParseImpl(const std::string& accelerator, | 49 ui::Accelerator ParseImpl(const std::string& accelerator, |
|
Finnur
2014/10/30 10:04:06
Can you comment this function with something like:
David Tseng
2014/10/30 17:01:47
Done.
| |
| 44 const std::string& platform_key, | 50 const std::string& platform_key, |
| 45 int index, | 51 int index, |
| 46 bool should_parse_media_keys, | 52 bool should_parse_media_keys, |
| 47 base::string16* error) { | 53 base::string16* error) { |
| 48 error->clear(); | 54 error->clear(); |
| 49 if (platform_key != values::kKeybindingPlatformWin && | 55 if (platform_key != values::kKeybindingPlatformWin && |
| 50 platform_key != values::kKeybindingPlatformMac && | 56 platform_key != values::kKeybindingPlatformMac && |
| 51 platform_key != values::kKeybindingPlatformChromeOs && | 57 platform_key != values::kKeybindingPlatformChromeOs && |
| 52 platform_key != values::kKeybindingPlatformLinux && | 58 platform_key != values::kKeybindingPlatformLinux && |
| 53 platform_key != values::kKeybindingPlatformDefault) { | 59 platform_key != values::kKeybindingPlatformDefault) { |
| 54 *error = ErrorUtils::FormatErrorMessageUTF16( | 60 *error = ErrorUtils::FormatErrorMessageUTF16( |
| 55 errors::kInvalidKeyBindingUnknownPlatform, | 61 errors::kInvalidKeyBindingUnknownPlatform, |
| 56 base::IntToString(index), | 62 base::IntToString(index), |
| 57 platform_key); | 63 platform_key); |
| 58 return ui::Accelerator(); | 64 return ui::Accelerator(); |
| 59 } | 65 } |
| 60 | 66 |
| 61 std::vector<std::string> tokens; | 67 std::vector<std::string> tokens; |
| 62 base::SplitString(accelerator, '+', &tokens); | 68 base::SplitString(accelerator, '+', &tokens); |
| 63 if (tokens.size() == 0 || | 69 if (tokens.size() == 0 || |
| 64 (tokens.size() == 1 && DoesRequireModifier(accelerator)) || | 70 (tokens.size() == 1 && DoesRequireModifier(accelerator)) || |
| 65 tokens.size() > 3) { | 71 tokens.size() > kMaxTokenSize) { |
| 66 *error = ErrorUtils::FormatErrorMessageUTF16( | 72 *error = ErrorUtils::FormatErrorMessageUTF16( |
| 67 errors::kInvalidKeyBinding, | 73 errors::kInvalidKeyBinding, |
| 68 base::IntToString(index), | 74 base::IntToString(index), |
| 69 platform_key, | 75 platform_key, |
| 70 accelerator); | 76 accelerator); |
| 71 return ui::Accelerator(); | 77 return ui::Accelerator(); |
| 72 } | 78 } |
| 73 | 79 |
| 74 // Now, parse it into an accelerator. | 80 // Now, parse it into an accelerator. |
| 75 int modifiers = ui::EF_NONE; | 81 int modifiers = ui::EF_NONE; |
| (...skipping 472 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 548 extension_data->SetBoolean("active", active); | 554 extension_data->SetBoolean("active", active); |
| 549 extension_data->SetString("keybinding", accelerator().GetShortcutText()); | 555 extension_data->SetString("keybinding", accelerator().GetShortcutText()); |
| 550 extension_data->SetString("command_name", command_name()); | 556 extension_data->SetString("command_name", command_name()); |
| 551 extension_data->SetString("extension_id", extension->id()); | 557 extension_data->SetString("extension_id", extension->id()); |
| 552 extension_data->SetBoolean("global", global()); | 558 extension_data->SetBoolean("global", global()); |
| 553 extension_data->SetBoolean("extension_action", extension_action); | 559 extension_data->SetBoolean("extension_action", extension_action); |
| 554 return extension_data; | 560 return extension_data; |
| 555 } | 561 } |
| 556 | 562 |
| 557 } // namespace extensions | 563 } // namespace extensions |
| OLD | NEW |