Skip to content

Commit

Permalink
[ATP] Support gin bindings for Automation.
Browse files Browse the repository at this point in the history
ATP will re-implement the V8 bindings for Automation and other
extension APIs used by accessibility feature component extensions.
This change makes it easier to re-use existing bindings code:
*Allows ATP to use gin::CreateFunctionTemplate while extensions
continues to use v8::FunctionTemplate::New
*Requires a change to add a way to get the original
V8::FunctionCallbackInfo from a gin::Arguments.

If we don't add the getter to gin::Arguments, all bindings code
across all extensions used by Accessibility Features would need
to be updated to take a gin::Bindings, or we'd need to build
a custom way outside of gin::Arguments to get the
FunctionCallbackInfo.

For diagrams and high-level overview of the context of this
change see go/chromeos-atp-v8-design (WIP).

Bug: 1357889
AX-Relnotes: N/A
Test: Existing
Change-Id: If4552a4c08ae8a32a2c0ee9288891dcd8c8a64a7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3985889
Reviewed-by: David Tseng <dtseng@chromium.org>
Reviewed-by: Michael Lippautz <mlippautz@chromium.org>
Commit-Queue: Katie Dektar <katie@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1067695}
  • Loading branch information
Katie Dektar authored and Chromium LUCI CQ committed Nov 4, 2022
1 parent 59a1f37 commit bcdde52
Show file tree
Hide file tree
Showing 8 changed files with 183 additions and 74 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -212,16 +212,20 @@ v8::Local<v8::Context> AutomationInternalCustomBindings::GetContext() const {

void AutomationInternalCustomBindings::RouteHandlerFunction(
const std::string& name,
AutomationV8Router::HandlerFunction handler_function) {
ObjectBackedNativeHandler::RouteHandlerFunction(name, handler_function);
scoped_refptr<ui::V8HandlerFunctionWrapper> handler_function_wrapper) {
ObjectBackedNativeHandler::RouteHandlerFunction(
name, base::BindRepeating(&ui::V8HandlerFunctionWrapper::RunV8,
handler_function_wrapper));
}

void AutomationInternalCustomBindings::RouteHandlerFunction(
const std::string& name,
const std::string& api_name,
AutomationV8Router::HandlerFunction handler_function) {
ObjectBackedNativeHandler::RouteHandlerFunction(name, api_name,
handler_function);
scoped_refptr<ui::V8HandlerFunctionWrapper> handler_function_wrapper) {
ObjectBackedNativeHandler::RouteHandlerFunction(
name, api_name,
base::BindRepeating(&ui::V8HandlerFunctionWrapper::RunV8,
handler_function_wrapper));
}

ui::TreeChangeObserverFilter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,13 @@ class AutomationInternalCustomBindings : public ObjectBackedNativeHandler,
void ThrowInvalidArgumentsException(bool is_fatal = true) const override;
v8::Isolate* GetIsolate() const override;
v8::Local<v8::Context> GetContext() const override;
void RouteHandlerFunction(
const std::string& name,
AutomationV8Router::HandlerFunction handler_function) override;
void RouteHandlerFunction(
const std::string& name,
const std::string& api_name,
AutomationV8Router::HandlerFunction handler_function) override;
void RouteHandlerFunction(const std::string& name,
scoped_refptr<ui::V8HandlerFunctionWrapper>
handler_function_wrapper) override;
void RouteHandlerFunction(const std::string& name,
const std::string& api_name,
scoped_refptr<ui::V8HandlerFunctionWrapper>
handler_function_wrapper) override;
ui::TreeChangeObserverFilter ParseTreeChangeObserverFilter(
const std::string& filter) const override;
std::string GetMarkerTypeString(ax::mojom::MarkerType type) const override;
Expand Down
6 changes: 6 additions & 0 deletions gin/arguments.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,12 @@ class GIN_EXPORT Arguments {
// array used by Get/PeekNext().
std::vector<v8::Local<v8::Value>> GetAll() const;

// Returns the original v8::FunctionCallbackInfo used to construct this
// Arguments if it exists, or nullptr otherwise.
const v8::FunctionCallbackInfo<v8::Value>* GetFunctionCallbackInfo() const {
return info_for_function_;
}

void ThrowError() const;
void ThrowTypeError(const std::string& message) const;

Expand Down
2 changes: 2 additions & 0 deletions ui/accessibility/platform/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ source_set("platform") {
"automation/automation_v8_bindings.cc",
"automation/automation_v8_bindings.h",
"automation/automation_v8_router.h",
"automation/v8_handler_function_wrapper.cc",
"automation/v8_handler_function_wrapper.h",
]

deps = [
Expand Down

0 comments on commit bcdde52

Please sign in to comment.