Chromium Code Reviews| Index: chrome/browser/accessibility/accessibility_extension_api.cc |
| diff --git a/chrome/browser/accessibility/accessibility_extension_api.cc b/chrome/browser/accessibility/accessibility_extension_api.cc |
| index 62abc25566768286c5c722d2896334b09bbf0b2b..86e427db51ff9438be17bde2c4c83e39ef229623 100644 |
| --- a/chrome/browser/accessibility/accessibility_extension_api.cc |
| +++ b/chrome/browser/accessibility/accessibility_extension_api.cc |
| @@ -27,6 +27,7 @@ |
| #include "extensions/common/error_utils.h" |
| #include "extensions/common/image_util.h" |
| #include "extensions/common/manifest_handlers/background_info.h" |
| +#include "ui/events/keycodes/keyboard_codes.h" |
| #if defined(OS_CHROMEOS) |
| #include "chrome/browser/chromeos/accessibility/accessibility_manager.h" |
| @@ -164,3 +165,31 @@ AccessibilityPrivateDarkenScreenFunction::Run() { |
| return RespondNow(Error(kErrorNotSupported)); |
| } |
| + |
| +#if defined(OS_CHROMEOS) |
| +ExtensionFunction::ResponseAction |
| +AccessibilityPrivateSetSwitchAccessKeysFunction::Run() { |
| + std::unique_ptr<accessibility_private::SetSwitchAccessKeys::Params> params = |
| + accessibility_private::SetSwitchAccessKeys::Params::Create(*args_); |
| + EXTENSION_FUNCTION_VALIDATE(params); |
| + std::vector<int> key_codes_list = params->key_codes; |
|
Devlin
2017/06/02 02:02:36
No need to copy this; prefer const std::vector<int
elichtenberg
2017/06/02 17:57:47
Done.
|
| + |
| + // For now, only accept key code if it represents an alphanumeric character. |
| + std::set<int> key_codes; |
| + for (size_t i = 0; i < key_codes_list.size(); ++i) { |
|
Devlin
2017/06/02 02:02:36
prefer:
for (auto key_code : key_codes_list) {
E
elichtenberg
2017/06/02 17:57:46
Done.
|
| + int key_code = key_codes_list.at(i); |
| + EXTENSION_FUNCTION_VALIDATE(key_code >= ui::VKEY_0 && |
| + key_code <= ui::VKEY_Z); |
| + key_codes.insert(key_code); |
| + } |
| + |
| + chromeos::AccessibilityManager* manager = |
| + chromeos::AccessibilityManager::Get(); |
| + |
| + // AccessibilityManager can be null during system shut down, but no need to |
| + // return error in this case, so just check that manager is not null. |
| + if (manager) |
| + manager->SetSwitchAccessKeys(key_codes); |
| + return RespondNow(NoArguments()); |
| +} |
| +#endif // defined (OS_CHROMEOS) |