#include "ui/accessibility/platform/automation/automation_v8_bindings.h"
#include <string>
#include <string_view>
#include "base/functional/bind.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/scoped_refptr.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/utf_offset_string_conversions.h"
#include "base/strings/utf_string_conversions.h"
#include "gin/arguments.h"
#include "gin/converter.h"
#include "gin/data_object_builder.h"
#include "gin/handle.h"
#include "ui/accessibility/ax_enum_util.h"
#include "ui/accessibility/ax_event_generator.h"
#include "ui/accessibility/ax_language_detection.h"
#include "ui/accessibility/ax_role_properties.h"
#include "ui/accessibility/ax_selection.h"
#include "ui/accessibility/ax_text_utils.h"
#include "ui/accessibility/ax_tree.h"
#include "ui/accessibility/platform/automation/automation_api_util.h"
#include "ui/accessibility/platform/automation/automation_position.h"
#include "ui/accessibility/platform/automation/automation_tree_manager_owner.h"
#include "ui/accessibility/platform/automation/automation_v8_router.h"
#include "ui/gfx/geometry/rect_conversions.h"
#include "v8/include/v8-function-callback.h"
namespace ui {
namespace {
v8::Local<v8::String> CreateV8String(v8::Isolate* isolate,
std::string_view str) { … }
v8::Local<v8::Object> RectToV8Object(v8::Isolate* isolate,
const gfx::Rect& rect) { … }
class GenericHandlerFunctionWrapper : public V8HandlerFunctionWrapper { … };
TreeIDFunction;
class TreeIDWrapper : public V8HandlerFunctionWrapper { … };
NodeIDFunction;
class NodeIDWrapper : public V8HandlerFunctionWrapper { … };
NodeIDPlusAttributeFunction;
class NodeIDPlusAttributeWrapper : public V8HandlerFunctionWrapper { … };
NodeIDPlusRangeFunction;
class NodeIDPlusRangeWrapper : public V8HandlerFunctionWrapper { … };
NodeIDPlusStringBoolFunction;
class NodeIDPlusStringBoolWrapper : public V8HandlerFunctionWrapper { … };
NodeIDPlusDimensionsFunction;
class NodeIDPlusDimensionsWrapper : public V8HandlerFunctionWrapper { … };
NodeIDPlusEventFunction;
class NodeIDPlusEventWrapper : public V8HandlerFunctionWrapper { … };
}
AutomationV8Bindings::AutomationV8Bindings(AutomationTreeManagerOwner* owner,
AutomationV8Router* router)
: … { … }
AutomationV8Bindings::~AutomationV8Bindings() = default;
void AutomationV8Bindings::SendTreeChangeEvent(
int observer_id,
const AXTreeID& tree_id,
int node_id,
ax::mojom::Mutation change_type) { … }
void AutomationV8Bindings::SendNodesRemovedEvent(const AXTreeID& tree_id,
const std::vector<int>& ids) { … }
void AutomationV8Bindings::SendChildTreeIDEvent(const AXTreeID& child_tree_id) { … }
void AutomationV8Bindings::SendTreeDestroyedEvent(const AXTreeID& tree_id) { … }
void AutomationV8Bindings::SendGetTextLocationResult(
const AXActionData& data,
const std::optional<gfx::Rect>& rect) { … }
void AutomationV8Bindings::SendActionResultEvent(const AXActionData& data,
bool result) { … }
void AutomationV8Bindings::SendAutomationEvent(
const AXTreeID& tree_id,
const AXEvent& event,
const gfx::Point& mouse_location,
const std::tuple<ax::mojom::Event, AXEventGenerator::Event>& event_type) { … }
void AutomationV8Bindings::SendTreeSerializationError(const AXTreeID& tree_id) { … }
void AutomationV8Bindings::SendOnAllEventListenersRemoved() { … }
void AutomationV8Bindings::AddV8Routes() { … }
void AutomationV8Bindings::RouteTreeIDFunction(const std::string& name,
TreeIDFunction callback) { … }
void AutomationV8Bindings::RouteNodeIDFunction(const std::string& name,
NodeIDFunction callback) { … }
void AutomationV8Bindings::RouteNodeIDPlusAttributeFunction(
const std::string& name,
NodeIDPlusAttributeFunction callback) { … }
void AutomationV8Bindings::RouteNodeIDPlusRangeFunction(
const std::string& name,
NodeIDPlusRangeFunction callback) { … }
void AutomationV8Bindings::RouteNodeIDPlusStringBoolFunction(
const std::string& name,
NodeIDPlusStringBoolFunction callback) { … }
void AutomationV8Bindings::RouteNodeIDPlusDimensionsFunction(
const std::string& name,
NodeIDPlusDimensionsFunction callback) { … }
void AutomationV8Bindings::RouteNodeIDPlusEventFunction(
const std::string& name,
NodeIDPlusEventFunction callback) { … }
void AutomationV8Bindings::GetFocus(
const v8::FunctionCallbackInfo<v8::Value>& args) const { … }
void AutomationV8Bindings::GetAccessibilityFocus(
const v8::FunctionCallbackInfo<v8::Value>& args) const { … }
void AutomationV8Bindings::StringAXTreeIDToUnguessableToken(
const v8::FunctionCallbackInfo<v8::Value>& args) const { … }
void AutomationV8Bindings::SetDesktopID(
const v8::FunctionCallbackInfo<v8::Value>& args) { … }
void AutomationV8Bindings::GetHtmlAttributes(
const v8::FunctionCallbackInfo<v8::Value>& args) const { … }
void AutomationV8Bindings::GetChildIDAtIndex(
const v8::FunctionCallbackInfo<v8::Value>& args) const { … }
void AutomationV8Bindings::CreateAutomationPosition(
const v8::FunctionCallbackInfo<v8::Value>& args) { … }
void AutomationV8Bindings::DestroyAccessibilityTree(
const v8::FunctionCallbackInfo<v8::Value>& args) { … }
void AutomationV8Bindings::AddTreeChangeObserver(
const v8::FunctionCallbackInfo<v8::Value>& args) { … }
void AutomationV8Bindings::RemoveTreeChangeObserver(
const v8::FunctionCallbackInfo<v8::Value>& args) { … }
void AutomationV8Bindings::GetParentID(v8::Isolate* isolate,
v8::ReturnValue<v8::Value> result,
AutomationAXTreeWrapper* tree_wrapper,
AXNode* node) const { … }
void AutomationV8Bindings::GetChildCount(v8::Isolate* isolate,
v8::ReturnValue<v8::Value> result,
AutomationAXTreeWrapper* tree_wrapper,
AXNode* node) const { … }
void AutomationV8Bindings::GetLocation(v8::Isolate* isolate,
v8::ReturnValue<v8::Value> result,
AutomationAXTreeWrapper* tree_wrapper,
AXNode* node) const { … }
void AutomationV8Bindings::GetUnclippedLocation(
v8::Isolate* isolate,
v8::ReturnValue<v8::Value> result,
AutomationAXTreeWrapper* tree_wrapper,
AXNode* node) const { … }
void AutomationV8Bindings::GetChildIDs(v8::Isolate* isolate,
v8::ReturnValue<v8::Value> result,
AutomationAXTreeWrapper* tree_wrapper,
AXNode* node) const { … }
void AutomationV8Bindings::GetSentenceStartOffsets(
v8::Isolate* isolate,
v8::ReturnValue<v8::Value> result,
AutomationAXTreeWrapper* tree_wrapper,
AXNode* node) const { … }
void AutomationV8Bindings::GetSentenceEndOffsets(
v8::Isolate* isolate,
v8::ReturnValue<v8::Value> result,
AutomationAXTreeWrapper* tree_wrapper,
AXNode* node) const { … }
void AutomationV8Bindings::GetBoundsForRange(
v8::Isolate* isolate,
v8::ReturnValue<v8::Value> result,
AutomationAXTreeWrapper* tree_wrapper,
AXNode* node,
int start,
int end,
bool clipped) const { … }
void AutomationV8Bindings::ComputeGlobalBounds(
v8::Isolate* isolate,
v8::ReturnValue<v8::Value> result,
AutomationAXTreeWrapper* tree_wrapper,
AXNode* node,
int x,
int y,
int width,
int height) const { … }
void AutomationV8Bindings::GetName(v8::Isolate* isolate,
v8::ReturnValue<v8::Value> result,
AutomationAXTreeWrapper* tree_wrapper,
AXNode* node) const { … }
void AutomationV8Bindings::GetNextTextMatch(
v8::Isolate* isolate,
v8::ReturnValue<v8::Value> result,
AutomationAXTreeWrapper* tree_wrapper,
AXNode* node,
const std::string& search_str,
bool backward) const { … }
void AutomationV8Bindings::SetAccessibilityFocus(
v8::Isolate* isolate,
v8::ReturnValue<v8::Value> result,
AutomationAXTreeWrapper* tree_wrapper,
AXNode* node) { … }
void AutomationV8Bindings::EventListenerAdded(
v8::Isolate* isolate,
v8::ReturnValue<v8::Value> result,
AutomationAXTreeWrapper* tree_wrapper,
AXNode* node,
const std::tuple<ax::mojom::Event, AXEventGenerator::Event>& event_type) { … }
void AutomationV8Bindings::EventListenerRemoved(
v8::Isolate* isolate,
v8::ReturnValue<v8::Value> result,
AutomationAXTreeWrapper* tree_wrapper,
AXNode* node,
const std::tuple<ax::mojom::Event, AXEventGenerator::Event>& event_type) { … }
void AutomationV8Bindings::GetMarkers(v8::Isolate* isolate,
v8::ReturnValue<v8::Value> result,
AutomationAXTreeWrapper* tree_wrapper,
AXNode* node) const { … }
void AutomationV8Bindings::GetState(
const v8::FunctionCallbackInfo<v8::Value>& args) const { … }
void AutomationV8Bindings::GetImageAnnotation(
v8::Isolate* isolate,
v8::ReturnValue<v8::Value> result,
AutomationAXTreeWrapper* tree_wrapper,
AXNode* node) const { … }
void AutomationV8Bindings::StartCachingAccessibilityTrees(
const v8::FunctionCallbackInfo<v8::Value>& args) { … }
void AutomationV8Bindings::StopCachingAccessibilityTrees(
const v8::FunctionCallbackInfo<v8::Value>& args) { … }
}