Commit 145cb570 authored by Dominic Mazzoni's avatar Dominic Mazzoni Committed by Chromium LUCI CQ

Simplify AXTreeSnapshotterImpl code

This is a simple refactoring that should have no side effects.

The change 'Use EmbeddingTokens as the "backing store" for AXTreeIDs'
(http://crrev.com/c/2270065) got rid of AXContentTreeUpdate, which was
previously a more complex version of AXTreeUpdate with some extra
content-specific fields.

There was a small missed opportunity to refactor here -
AXTreeSnapshotterImpl was serializing to a AXContentTreeUpdate and
then converting that to an AXTreeUpdate. Since AXContentTreeUpdate
no longer exists, the code to populate one struct and then copy it
to another one is redundant and can be simplified.

This shouldn't result in any change in functionality. AXTreeSnapshotter
is already covered by tests, primarily in
snapshot_ax_tree_browsertest.cc

Bug: 1094150, 1161541
AX-Relnotes: N/A
Change-Id: If9863ce23cca5538eeab5e0a34350d2f9bfe9e46
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2602438Reviewed-by: default avatarMark Schillaci <mschillaci@google.com>
Commit-Queue: Dominic Mazzoni <dmazzoni@chromium.org>
Cr-Commit-Position: refs/heads/master@{#839193}
parent 7ea1bc41
......@@ -109,29 +109,6 @@ AXTreeSnapshotterImpl::~AXTreeSnapshotterImpl() = default;
void AXTreeSnapshotterImpl::Snapshot(ui::AXMode ax_mode,
size_t max_node_count,
ui::AXTreeUpdate* response) {
// Get a snapshot of the accessibility tree as an AXNodeData.
ui::AXTreeUpdate content_tree;
SnapshotContentTree(ax_mode, max_node_count, &content_tree);
// As a sanity check, node_id_to_clear and event_from should be uninitialized
// if this is a full tree snapshot. They'd only be set to something if
// this was indeed a partial update to the tree (which we don't want).
DCHECK_EQ(0, content_tree.node_id_to_clear);
DCHECK_EQ(ax::mojom::EventFrom::kNone, content_tree.event_from);
// We now have a complete serialization of the accessibility tree, but it
// includes a few fields we don't want to export outside of content/,
// so copy it into a more generic ui::AXTreeUpdate instead.
response->root_id = content_tree.root_id;
response->nodes.resize(content_tree.nodes.size());
response->node_id_to_clear = content_tree.node_id_to_clear;
response->event_from = content_tree.event_from;
response->nodes.assign(content_tree.nodes.begin(), content_tree.nodes.end());
}
void AXTreeSnapshotterImpl::SnapshotContentTree(ui::AXMode ax_mode,
size_t max_node_count,
ui::AXTreeUpdate* response) {
if (!render_frame_->GetWebFrame())
return;
if (!WebAXObject::MaybeUpdateLayoutAndCheckValidity(
......@@ -163,6 +140,12 @@ void AXTreeSnapshotterImpl::SnapshotContentTree(ui::AXMode ax_mode,
// It failed again. Clear the response object because it might have errors.
*response = ui::AXTreeUpdate();
LOG(WARNING) << "Unable to serialize accessibility tree.";
// As a sanity check, node_id_to_clear and event_from should be uninitialized
// if this is a full tree snapshot. They'd only be set to something if
// this was indeed a partial update to the tree (which we don't want).
DCHECK_EQ(0, response->node_id_to_clear);
DCHECK_EQ(ax::mojom::EventFrom::kNone, response->event_from);
}
// static
......@@ -178,7 +161,7 @@ void RenderAccessibilityImpl::SnapshotAccessibilityTree(
return;
AXTreeSnapshotterImpl snapshotter(render_frame);
snapshotter.SnapshotContentTree(ax_mode, kMaxSnapshotNodeCount, response);
snapshotter.Snapshot(ax_mode, kMaxSnapshotNodeCount, response);
}
RenderAccessibilityImpl::RenderAccessibilityImpl(
......
......@@ -66,12 +66,6 @@ class AXTreeSnapshotterImpl : public AXTreeSnapshotter {
size_t max_node_count,
ui::AXTreeUpdate* accessibility_tree) override;
// Same as above, but returns in |accessibility_tree| a ui::AXTreeUpdate
// with content-specific metadata, instead of an AXTreeUpdate.
void SnapshotContentTree(ui::AXMode ax_mode,
size_t max_node_count,
ui::AXTreeUpdate* accessibility_tree);
private:
RenderFrameImpl* render_frame_;
std::unique_ptr<blink::WebAXContext> context_;
......
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