Commit 24961c1e authored by Joel Einbinder's avatar Joel Einbinder Committed by Commit Bot

DevTools: Accessibility.enable and disable protocol methods

This will allow for new methods that operate on AXNodeIds, like
Accessibility.click and Accessibility.focus. It also allows multiple
calls to getFullAXTree to be compared.

Bug: 887173
Change-Id: Iaaf103bced9c5dbc9dd04306c2562044f50dfd2c
Reviewed-on: https://chromium-review.googlesource.com/c/1237526
Commit-Queue: Joel Einbinder <einbinder@chromium.org>
Reviewed-by: default avatarDmitry Gozman <dgozman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#599847}
parent 099f614a
Test that each agent could be enabled/disabled separately.
Accessibility.disable finished successfully
Animation.disable finished successfully
CSS.disable finished successfully
DOM.disable finished successfully
......@@ -18,6 +19,9 @@ Performance.disable finished successfully
Profiler.disable finished successfully
Runtime.disable finished successfully
Accessibility.enable finished successfully
Accessibility.disable finished successfully
Animation.enable finished successfully
Animation.disable finished successfully
......
......@@ -178,6 +178,13 @@ experimental domain Accessibility
# The backend ID for the associated DOM node, if any.
optional DOM.BackendNodeId backendDOMNodeId
# Disables the accessibility domain.
command disable
# Enables the accessibility domain which causes `AXNodeId`s to remain consistent between method calls.
# This turns on accessibility for the page, which can impact performance until accessibility is disabled.
command enable
# Fetches the accessibility node and partial accessibility tree for this DOM node, if it exists.
experimental command getPartialAXTree
parameters
......
......@@ -5,7 +5,6 @@
#include "third_party/blink/renderer/modules/accessibility/inspector_accessibility_agent.h"
#include <memory>
#include "third_party/blink/renderer/core/accessibility/ax_context.h"
#include "third_party/blink/renderer/core/accessibility/ax_object_cache.h"
#include "third_party/blink/renderer/core/dom/dom_node_ids.h"
#include "third_party/blink/renderer/core/dom/element.h"
......@@ -499,10 +498,22 @@ std::unique_ptr<AXValue> CreateRoleNameValue(ax::mojom::Role role) {
} // namespace
using EnabledAgentsMultimap =
HeapHashMap<WeakMember<LocalFrame>,
HeapHashSet<Member<InspectorAccessibilityAgent>>>;
EnabledAgentsMultimap& EnabledAgents() {
DEFINE_STATIC_LOCAL(Persistent<EnabledAgentsMultimap>, enabled_agents,
(new EnabledAgentsMultimap()));
return *enabled_agents;
}
InspectorAccessibilityAgent::InspectorAccessibilityAgent(
InspectedFrames* inspected_frames,
InspectorDOMAgent* dom_agent)
: inspected_frames_(inspected_frames), dom_agent_(dom_agent) {}
: inspected_frames_(inspected_frames),
dom_agent_(dom_agent),
enabled_(&agent_state_, /*default_value=*/false) {}
Response InspectorAccessibilityAgent::getPartialAXTree(
Maybe<int> dom_node_id,
......@@ -830,6 +841,55 @@ void InspectorAccessibilityAgent::AddChildren(
}
}
void InspectorAccessibilityAgent::EnableAndReset() {
enabled_.Set(true);
LocalFrame* frame = inspected_frames_->Root();
if (!EnabledAgents().Contains(frame)) {
EnabledAgents().Set(frame,
HeapHashSet<Member<InspectorAccessibilityAgent>>());
}
EnabledAgents().find(frame)->value.insert(this);
CreateAXContext();
}
protocol::Response InspectorAccessibilityAgent::enable() {
if (!enabled_.Get())
EnableAndReset();
return Response::OK();
}
protocol::Response InspectorAccessibilityAgent::disable() {
if (!enabled_.Get())
return Response::OK();
enabled_.Set(false);
context_ = nullptr;
LocalFrame* frame = inspected_frames_->Root();
DCHECK(EnabledAgents().Contains(frame));
auto it = EnabledAgents().find(frame);
it->value.erase(this);
if (it->value.IsEmpty())
EnabledAgents().erase(frame);
return Response::OK();
}
void InspectorAccessibilityAgent::Restore() {
if (enabled_.Get())
EnableAndReset();
}
void InspectorAccessibilityAgent::ProvideTo(LocalFrame* frame) {
if (!EnabledAgents().Contains(frame))
return;
for (InspectorAccessibilityAgent* agent : EnabledAgents().find(frame)->value)
agent->CreateAXContext();
}
void InspectorAccessibilityAgent::CreateAXContext() {
Document* document = inspected_frames_->Root()->GetDocument();
if (document)
context_ = std::make_unique<AXContext>(*document);
}
void InspectorAccessibilityAgent::Trace(blink::Visitor* visitor) {
visitor->Trace(inspected_frames_);
visitor->Trace(dom_agent_);
......
......@@ -6,6 +6,7 @@
#define THIRD_PARTY_BLINK_RENDERER_MODULES_ACCESSIBILITY_INSPECTOR_ACCESSIBILITY_AGENT_H_
#include "base/macros.h"
#include "third_party/blink/renderer/core/accessibility/ax_context.h"
#include "third_party/blink/renderer/core/inspector/inspector_base_agent.h"
#include "third_party/blink/renderer/core/inspector/protocol/Accessibility.h"
#include "third_party/blink/renderer/modules/modules_export.h"
......@@ -16,6 +17,7 @@ class AXObject;
class AXObjectCacheImpl;
class InspectorDOMAgent;
class InspectedFrames;
class LocalFrame;
using protocol::Accessibility::AXNode;
using protocol::Accessibility::AXNodeId;
......@@ -25,10 +27,16 @@ class MODULES_EXPORT InspectorAccessibilityAgent
public:
InspectorAccessibilityAgent(InspectedFrames*, InspectorDOMAgent*);
static void ProvideTo(LocalFrame* frame);
void CreateAXContext();
// Base agent methods.
void Trace(blink::Visitor*) override;
void Restore() override;
// Protocol methods.
protocol::Response enable() override;
protocol::Response disable() override;
protocol::Response getPartialAXTree(
protocol::Maybe<int> dom_node_id,
protocol::Maybe<int> backend_node_id,
......@@ -41,6 +49,9 @@ class MODULES_EXPORT InspectorAccessibilityAgent
override;
private:
// Unconditionally enables the agent, even if |enabled_.Get()==true|.
// For idempotence, call enable().
void EnableAndReset();
std::unique_ptr<AXNode> BuildObjectForIgnoredNode(
Node* dom_node,
AXObject*,
......@@ -91,6 +102,8 @@ class MODULES_EXPORT InspectorAccessibilityAgent
Member<InspectedFrames> inspected_frames_;
Member<InspectorDOMAgent> dom_agent_;
InspectorAgentState::Boolean enabled_;
std::unique_ptr<AXContext> context_;
DISALLOW_COPY_AND_ASSIGN(InspectorAccessibilityAgent);
};
......
......@@ -87,6 +87,7 @@
#if defined(SUPPORT_WEBGL2_COMPUTE_CONTEXT)
#include "third_party/blink/renderer/modules/webgl/webgl2_compute_rendering_context.h"
#endif
#include "third_party/blink/renderer/modules/accessibility/inspector_accessibility_agent.h"
#include "third_party/blink/renderer/modules/webgl/webgl2_rendering_context.h"
#include "third_party/blink/renderer/modules/webgl/webgl_rendering_context.h"
#include "third_party/blink/renderer/modules/xr/xr_presentation_context.h"
......@@ -190,6 +191,7 @@ void ModulesInitializer::InstallSupplements(LocalFrame& frame) const {
}
InstalledAppController::ProvideTo(frame, client->GetRelatedAppsFetcher());
::blink::ProvideSpeechRecognitionTo(frame);
InspectorAccessibilityAgent::ProvideTo(&frame);
}
void ModulesInitializer::ProvideLocalFileSystemToWorker(
......
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