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/browser/accessibility/accessibility_extension_api.h" | 5 #include "chrome/browser/accessibility/accessibility_extension_api.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/json/json_writer.h" | 9 #include "base/json/json_writer.h" |
| 10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
| 11 #include "base/values.h" | 11 #include "base/values.h" |
| 12 #include "build/build_config.h" | 12 #include "build/build_config.h" |
| 13 #include "chrome/browser/extensions/api/tabs/tabs_constants.h" | 13 #include "chrome/browser/extensions/api/tabs/tabs_constants.h" |
| 14 #include "chrome/browser/extensions/chrome_extension_function_details.h" | 14 #include "chrome/browser/extensions/chrome_extension_function_details.h" |
| 15 #include "chrome/browser/extensions/extension_service.h" | 15 #include "chrome/browser/extensions/extension_service.h" |
| 16 #include "chrome/browser/extensions/extension_tab_util.h" | 16 #include "chrome/browser/extensions/extension_tab_util.h" |
| 17 #include "chrome/browser/infobars/infobar_service.h" | 17 #include "chrome/browser/infobars/infobar_service.h" |
| 18 #include "chrome/browser/profiles/profile.h" | 18 #include "chrome/browser/profiles/profile.h" |
| 19 #include "chrome/common/extensions/api/accessibility_private.h" | 19 #include "chrome/common/extensions/api/accessibility_private.h" |
| 20 #include "chrome/common/extensions/extension_constants.h" | 20 #include "chrome/common/extensions/extension_constants.h" |
| 21 #include "components/infobars/core/confirm_infobar_delegate.h" | 21 #include "components/infobars/core/confirm_infobar_delegate.h" |
| 22 #include "components/infobars/core/infobar.h" | 22 #include "components/infobars/core/infobar.h" |
| 23 #include "content/public/browser/browser_accessibility_state.h" | 23 #include "content/public/browser/browser_accessibility_state.h" |
| 24 #include "extensions/browser/event_router.h" | 24 #include "extensions/browser/event_router.h" |
| 25 #include "extensions/browser/extension_system.h" | 25 #include "extensions/browser/extension_system.h" |
| 26 #include "extensions/browser/lazy_background_task_queue.h" | 26 #include "extensions/browser/lazy_background_task_queue.h" |
| 27 #include "extensions/common/error_utils.h" | 27 #include "extensions/common/error_utils.h" |
| 28 #include "extensions/common/image_util.h" | 28 #include "extensions/common/image_util.h" |
| 29 #include "extensions/common/manifest_handlers/background_info.h" | 29 #include "extensions/common/manifest_handlers/background_info.h" |
| 30 #include "ui/events/keycodes/keyboard_codes.h" | |
| 30 | 31 |
| 31 #if defined(OS_CHROMEOS) | 32 #if defined(OS_CHROMEOS) |
| 32 #include "chrome/browser/chromeos/accessibility/accessibility_manager.h" | 33 #include "chrome/browser/chromeos/accessibility/accessibility_manager.h" |
| 33 #include "chrome/browser/chromeos/ui/accessibility_focus_ring_controller.h" | 34 #include "chrome/browser/chromeos/ui/accessibility_focus_ring_controller.h" |
| 34 #include "chromeos/dbus/dbus_thread_manager.h" | 35 #include "chromeos/dbus/dbus_thread_manager.h" |
| 35 #include "chromeos/dbus/power_manager_client.h" | 36 #include "chromeos/dbus/power_manager_client.h" |
| 36 | 37 |
| 37 using chromeos::AccessibilityFocusRingController; | 38 using chromeos::AccessibilityFocusRingController; |
| 38 #endif | 39 #endif |
| 39 | 40 |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 157 | 158 |
| 158 // Called twice to ensure the cros end of the dbus message is in a good | 159 // Called twice to ensure the cros end of the dbus message is in a good |
| 159 // state. | 160 // state. |
| 160 client->SetBacklightsForcedOff(!darken); | 161 client->SetBacklightsForcedOff(!darken); |
| 161 client->SetBacklightsForcedOff(darken); | 162 client->SetBacklightsForcedOff(darken); |
| 162 return RespondNow(NoArguments()); | 163 return RespondNow(NoArguments()); |
| 163 #endif // defined OS_CHROMEOS | 164 #endif // defined OS_CHROMEOS |
| 164 | 165 |
| 165 return RespondNow(Error(kErrorNotSupported)); | 166 return RespondNow(Error(kErrorNotSupported)); |
| 166 } | 167 } |
| 168 | |
| 169 #if defined(OS_CHROMEOS) | |
| 170 ExtensionFunction::ResponseAction | |
| 171 AccessibilityPrivateSetSwitchAccessKeysFunction::Run() { | |
| 172 std::unique_ptr<accessibility_private::SetSwitchAccessKeys::Params> params = | |
| 173 accessibility_private::SetSwitchAccessKeys::Params::Create(*args_); | |
| 174 EXTENSION_FUNCTION_VALIDATE(params); | |
| 175 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.
| |
| 176 | |
| 177 // For now, only accept key code if it represents an alphanumeric character. | |
| 178 std::set<int> key_codes; | |
| 179 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.
| |
| 180 int key_code = key_codes_list.at(i); | |
| 181 EXTENSION_FUNCTION_VALIDATE(key_code >= ui::VKEY_0 && | |
| 182 key_code <= ui::VKEY_Z); | |
| 183 key_codes.insert(key_code); | |
| 184 } | |
| 185 | |
| 186 chromeos::AccessibilityManager* manager = | |
| 187 chromeos::AccessibilityManager::Get(); | |
| 188 | |
| 189 // AccessibilityManager can be null during system shut down, but no need to | |
| 190 // return error in this case, so just check that manager is not null. | |
| 191 if (manager) | |
| 192 manager->SetSwitchAccessKeys(key_codes); | |
| 193 return RespondNow(NoArguments()); | |
| 194 } | |
| 195 #endif // defined (OS_CHROMEOS) | |
| OLD | NEW |