Commit a1c681bf authored by Akihiro Ota's avatar Akihiro Ota Committed by Commit Bot

Add ChromeVox hotkey to report battery status.

Adds new hotkey for ChromeVox users to quickly get
battery status. This change involves:

1. Plumbing hotkey request from ChromeVox extension
to ash, where battery status can be retrieved.

2. Setting up callbacks from ash to Browser and
and from Browser to ChromeVox so that battery status
can be reported to the user.

Change-Id: I9c2b96a49a54d152bffc1e373eec352d0a902403
Reviewed-on: https://chromium-review.googlesource.com/c/1388176
Commit-Queue: Akihiro Ota <akihiroota@chromium.org>
Reviewed-by: default avatarDevlin <rdevlin.cronin@chromium.org>
Reviewed-by: default avatarDominick Ng <dominickn@chromium.org>
Reviewed-by: default avatarDavid Tseng <dtseng@chromium.org>
Reviewed-by: default avatarKatie Dektar <katie@chromium.org>
Cr-Commit-Position: refs/heads/master@{#622162}
parent fcc82262
......@@ -26,6 +26,7 @@
#include "ash/sticky_keys/sticky_keys_controller.h"
#include "ash/strings/grit/ash_strings.h"
#include "ash/system/power/backlights_forced_off_setter.h"
#include "ash/system/power/power_status.h"
#include "ash/system/power/scoped_backlights_forced_off.h"
#include "ash/wm/tablet_mode/tablet_mode_controller.h"
#include "base/command_line.h"
......@@ -1241,4 +1242,11 @@ void AccessibilityController::UpdateVirtualKeyboardFromPref() {
Shell::Get()->DisableKeyboard();
}
void AccessibilityController::GetBatteryDescription(
GetBatteryDescriptionCallback callback) {
// Pass battery status as string to callback function.
std::move(callback).Run(PowerStatus::Get()->GetAccessibleNameString(
true /* Enables full description*/));
}
} // namespace ash
......@@ -183,6 +183,7 @@ class ASH_EXPORT AccessibilityController
mojom::SwitchAccessEventHandlerDelegatePtr delegate) override;
void ToggleDictationFromSource(mojom::DictationToggleSource source) override;
void ForwardKeyEventsToSwitchAccess(bool should_forward) override;
void GetBatteryDescription(GetBatteryDescriptionCallback callback) override;
// SessionObserver:
void OnSigninScreenPrefServiceInitialized(PrefService* prefs) override;
......
......@@ -4,6 +4,7 @@
module ash.mojom;
import "mojo/public/mojom/base/string16.mojom";
import "mojo/public/mojom/base/time.mojom";
import "ui/accessibility/ax_enums.mojom";
import "ui/events/mojo/event.mojom";
......@@ -173,6 +174,10 @@ interface AccessibilityController {
// Tells the Switch Access Event Handler whether to forward all key events to
// the Switch Access extension.
ForwardKeyEventsToSwitchAccess(bool should_forward);
// Retrieves a string description of the current battery status.
GetBatteryDescription()
=> (mojo_base.mojom.String16 battery_description);
};
// Interface for ash to request accessibility service from its client (e.g.
......
......@@ -9,6 +9,7 @@
#include <set>
#include <vector>
#include "base/bind.h"
#include "base/json/json_writer.h"
#include "base/strings/string_number_conversions.h"
#include "base/values.h"
......@@ -35,7 +36,6 @@
#include "ui/events/keycodes/keyboard_codes.h"
#if defined(OS_CHROMEOS)
#include "ash/public/interfaces/accessibility_controller.mojom.h"
#include "ash/public/interfaces/accessibility_focus_ring_controller.mojom.h"
#include "ash/public/interfaces/constants.mojom.h"
#include "ash/public/interfaces/event_rewriter_controller.mojom.h"
......@@ -421,4 +421,32 @@ AccessibilityPrivateForwardKeyEventsToSwitchAccessFunction::Run() {
return RespondNow(NoArguments());
}
AccessibilityPrivateGetBatteryDescriptionFunction::
AccessibilityPrivateGetBatteryDescriptionFunction() {}
AccessibilityPrivateGetBatteryDescriptionFunction::
~AccessibilityPrivateGetBatteryDescriptionFunction() {}
ExtensionFunction::ResponseAction
AccessibilityPrivateGetBatteryDescriptionFunction::Run() {
// Get AccessibilityControllerPtr; needs to exist for lifetime of this
// function and its callback.
controller_ = GetAccessibilityController();
// Get battery description from ash and return it via callback.
controller_->GetBatteryDescription(
base::BindOnce(&AccessibilityPrivateGetBatteryDescriptionFunction::
OnGotBatteryDescription,
this));
return RespondLater();
}
void AccessibilityPrivateGetBatteryDescriptionFunction::OnGotBatteryDescription(
const base::string16& battery_description) {
// Send battery description to extension.
Respond(OneArgument(std::make_unique<base::Value>(battery_description)));
controller_.reset();
}
#endif // defined (OS_CHROMEOS)
......@@ -6,13 +6,16 @@
#define CHROME_BROWSER_ACCESSIBILITY_ACCESSIBILITY_EXTENSION_API_H_
#include <string>
#include "base/compiler_specific.h"
#include "base/memory/singleton.h"
#include "base/values.h"
#include "extensions/browser/extension_function.h"
#include "ui/accessibility/ax_enums.mojom.h"
#if defined(OS_CHROMEOS)
#include "ash/public/interfaces/accessibility_controller.mojom.h"
#endif
// API function that enables or disables web content accessibility support.
class AccessibilityPrivateSetNativeAccessibilityEnabledFunction
: public UIThreadExtensionFunction {
......@@ -146,6 +149,21 @@ class AccessibilityPrivateForwardKeyEventsToSwitchAccessFunction
ACCESSIBILITY_PRIVATE_FORWARDKEYEVENTSTOSWITCHACCESS)
};
// API function that is called to get the device's battery status as a string.
class AccessibilityPrivateGetBatteryDescriptionFunction
: public UIThreadExtensionFunction {
public:
AccessibilityPrivateGetBatteryDescriptionFunction();
ResponseAction Run() override;
void OnGotBatteryDescription(const base::string16& battery_description);
DECLARE_EXTENSION_FUNCTION("accessibilityPrivate.getBatteryDescription",
ACCESSIBILITY_PRIVATE_GETBATTERYDESCRIPTION)
private:
~AccessibilityPrivateGetBatteryDescriptionFunction() override;
ash::mojom::AccessibilityControllerPtr controller_ = nullptr;
};
#endif // defined (OS_CHROMEOS)
#endif // CHROME_BROWSER_ACCESSIBILITY_ACCESSIBILITY_EXTENSION_API_H_
......@@ -996,6 +996,15 @@
"keyCode": [79, 83]
}
}
},
{
"command": "getBatteryDescription",
"sequence": {
"cvoxModifier": true,
"keys": {
"keyCode": [79, 66]
}
}
}
]
}
......@@ -850,6 +850,15 @@ CommandHandler.onCommand = function(command) {
}
cvox.ChromeVox.tts.speak(announce, cvox.QueueMode.FLUSH);
return false;
case 'getBatteryDescription':
chrome.accessibilityPrivate.getBatteryDescription(function(
batteryDescription) {
new Output()
.withString(batteryDescription)
.withQueueMode(cvox.QueueMode.FLUSH)
.go();
});
break;
default:
return true;
}
......
......@@ -52,6 +52,7 @@ class TestAccessibilityController : ash::mojom::AccessibilityController {
void ToggleDictationFromSource(
ash::mojom::DictationToggleSource source) override {}
void ForwardKeyEventsToSwitchAccess(bool should_forward) override {}
void GetBatteryDescription(GetBatteryDescriptionCallback callback) override {}
bool was_client_set() const { return was_client_set_; }
......
......@@ -106,6 +106,25 @@
}
],
"functions": [
{
"name": "getBatteryDescription",
"type": "function",
"description": "Called to request battery status from Chrome OS system.",
"parameters": [
{
"name": "callback",
"type": "function",
"description": "Returns battery description as a string.",
"parameters": [
{
"name": "batteryDescription",
"type": "string"
}
]
}
],
"platforms": ["chromeos"]
},
{
"name": "setNativeAccessibilityEnabled",
"type": "function",
......
......@@ -1370,6 +1370,7 @@ enum HistogramValue {
ACTIVITYLOGPRIVATE_DELETEACTIVITIESBYEXTENSION = 1307,
ACCESSIBILITY_PRIVATE_FORWARDKEYEVENTSTOSWITCHACCESS = 1308,
AUTOTESTPRIVATE_ENSUREWINDOWSERVICECLIENTHASDRAWNWINDOW = 1309,
ACCESSIBILITY_PRIVATE_GETBATTERYDESCRIPTION = 1310,
// Last entry: Add new entries above, then run:
// python tools/metrics/histograms/update_extension_histograms.py
ENUM_BOUNDARY
......
......@@ -257,3 +257,11 @@ chrome.accessibilityPrivate.onSelectToSpeakStateChangeRequested;
* Called when a Switch Access user activates dictation from the context menu.
*/
chrome.accessibilityPrivate.toggleDictation = function() {};
/**
* Called to request battery status from Chrome OS system.
* @param {function(string):void} callback Returns battery description as a
* string.
*/
chrome.accessibilityPrivate.getBatteryDescription = function(callback) {};
......@@ -17636,6 +17636,7 @@ Called by update_net_error_codes.py.-->
label="ACCESSIBILITY_PRIVATE_FORWARDKEYEVENTSTOSWITCHACCESS"/>
<int value="1309"
label="AUTOTESTPRIVATE_ENSUREWINDOWSERVICECLIENTHASDRAWNWINDOW"/>
<int value="1310" label="ACCESSIBILITY_PRIVATE_GETBATTERYDESCRIPTION"/>
</enum>
<enum name="ExtensionIconState">
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment