Commit b30851c6 authored by Avi Drissman's avatar Avi Drissman Committed by Commit Bot

Update WebContents::RequestAXTreeSnapshot() to OnceCallback.

BUG=714018

Change-Id: Ic6fa05a2ebd6ca21bd1b2a349a58f7a419a3465d
Reviewed-on: https://chromium-review.googlesource.com/952991Reviewed-by: default avatarDominic Mazzoni <dmazzoni@chromium.org>
Reviewed-by: default avatarLuis Hector Chavez <lhchavez@chromium.org>
Reviewed-by: default avatarJames Cook <jamescook@chromium.org>
Commit-Queue: Avi Drissman <avi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#541881}
parent 6227a706
...@@ -318,9 +318,8 @@ void ArcVoiceInteractionArcHomeService::GetVoiceInteractionStructure( ...@@ -318,9 +318,8 @@ void ArcVoiceInteractionArcHomeService::GetVoiceInteractionStructure(
->GetHost() ->GetHost()
->GetRootTransform(); ->GetRootTransform();
float scale_factor = ash::GetScaleFactorForTransform(transform); float scale_factor = ash::GetScaleFactorForTransform(transform);
web_contents->RequestAXTreeSnapshot(base::Bind( web_contents->RequestAXTreeSnapshot(base::BindOnce(
&RequestVoiceInteractionStructureCallback, &RequestVoiceInteractionStructureCallback, std::move(callback),
base::Passed(std::move(callback)),
gfx::ConvertRectToPixel(scale_factor, browser->window()->GetBounds()), gfx::ConvertRectToPixel(scale_factor, browser->window()->GetBounds()),
web_contents->GetLastCommittedURL().spec(), web_contents->GetTitle())); web_contents->GetLastCommittedURL().spec(), web_contents->GetTitle()));
} }
......
...@@ -58,7 +58,7 @@ class ArcVoiceInteractionArcHomeServiceTest : public InProcessBrowserTest { ...@@ -58,7 +58,7 @@ class ArcVoiceInteractionArcHomeServiceTest : public InProcessBrowserTest {
ui_test_utils::NavigateToURL(browser(), url); ui_test_utils::NavigateToURL(browser(), url);
auto* web_contents = browser()->tab_strip_model()->GetActiveWebContents(); auto* web_contents = browser()->tab_strip_model()->GetActiveWebContents();
AXTreeSnapshotWaiter waiter; AXTreeSnapshotWaiter waiter;
web_contents->RequestAXTreeSnapshot(base::Bind( web_contents->RequestAXTreeSnapshot(base::BindOnce(
&AXTreeSnapshotWaiter::ReceiveSnapshot, base::Unretained(&waiter))); &AXTreeSnapshotWaiter::ReceiveSnapshot, base::Unretained(&waiter)));
waiter.Wait(); waiter.Wait();
auto node = ui::AXSnapshotNodeAndroid::Create(waiter.snapshot(), false); auto node = ui::AXSnapshotNodeAndroid::Create(waiter.snapshot(), false);
......
...@@ -74,9 +74,8 @@ IN_PROC_BROWSER_TEST_F(SnapshotAXTreeBrowserTest, ...@@ -74,9 +74,8 @@ IN_PROC_BROWSER_TEST_F(SnapshotAXTreeBrowserTest,
static_cast<WebContentsImpl*>(shell()->web_contents()); static_cast<WebContentsImpl*>(shell()->web_contents());
AXTreeSnapshotWaiter waiter; AXTreeSnapshotWaiter waiter;
web_contents->RequestAXTreeSnapshot( web_contents->RequestAXTreeSnapshot(base::BindOnce(
base::Bind(&AXTreeSnapshotWaiter::ReceiveSnapshot, &AXTreeSnapshotWaiter::ReceiveSnapshot, base::Unretained(&waiter)));
base::Unretained(&waiter)));
waiter.Wait(); waiter.Wait();
// Dump the whole tree if one of the assertions below fails // Dump the whole tree if one of the assertions below fails
...@@ -109,9 +108,8 @@ IN_PROC_BROWSER_TEST_F(SnapshotAXTreeBrowserTest, ...@@ -109,9 +108,8 @@ IN_PROC_BROWSER_TEST_F(SnapshotAXTreeBrowserTest,
"/accessibility/snapshot/inner.html")); "/accessibility/snapshot/inner.html"));
AXTreeSnapshotWaiter waiter; AXTreeSnapshotWaiter waiter;
web_contents->RequestAXTreeSnapshot( web_contents->RequestAXTreeSnapshot(base::BindOnce(
base::Bind(&AXTreeSnapshotWaiter::ReceiveSnapshot, &AXTreeSnapshotWaiter::ReceiveSnapshot, base::Unretained(&waiter)));
base::Unretained(&waiter)));
waiter.Wait(); waiter.Wait();
// Dump the whole tree if one of the assertions below fails // Dump the whole tree if one of the assertions below fails
......
...@@ -1892,8 +1892,8 @@ void RenderFrameHostImpl::OnRenderProcessGone(int status, int exit_code) { ...@@ -1892,8 +1892,8 @@ void RenderFrameHostImpl::OnRenderProcessGone(int status, int exit_code) {
// Execute any pending AX tree snapshot callbacks with an empty response, // Execute any pending AX tree snapshot callbacks with an empty response,
// since we're never going to get a response from this renderer. // since we're never going to get a response from this renderer.
for (const auto& iter : ax_tree_snapshot_callbacks_) for (auto& iter : ax_tree_snapshot_callbacks_)
iter.second.Run(ui::AXTreeUpdate()); std::move(iter.second).Run(ui::AXTreeUpdate());
#if defined(OS_ANDROID) #if defined(OS_ANDROID)
// Execute any pending Samsung smart clip callbacks. // Execute any pending Samsung smart clip callbacks.
...@@ -2629,7 +2629,7 @@ void RenderFrameHostImpl::OnAccessibilitySnapshotResponse( ...@@ -2629,7 +2629,7 @@ void RenderFrameHostImpl::OnAccessibilitySnapshotResponse(
AXContentTreeDataToAXTreeData(&dst_snapshot.tree_data); AXContentTreeDataToAXTreeData(&dst_snapshot.tree_data);
dst_snapshot.has_tree_data = true; dst_snapshot.has_tree_data = true;
} }
it->second.Run(dst_snapshot); std::move(it->second).Run(dst_snapshot);
ax_tree_snapshot_callbacks_.erase(it); ax_tree_snapshot_callbacks_.erase(it);
} else { } else {
NOTREACHED() << "Received AX tree snapshot response for unknown id"; NOTREACHED() << "Received AX tree snapshot response for unknown id";
...@@ -3952,7 +3952,8 @@ void RenderFrameHostImpl::RequestAXTreeSnapshot( ...@@ -3952,7 +3952,8 @@ void RenderFrameHostImpl::RequestAXTreeSnapshot(
static int next_id = 1; static int next_id = 1;
int callback_id = next_id++; int callback_id = next_id++;
Send(new AccessibilityMsg_SnapshotTree(routing_id_, callback_id)); Send(new AccessibilityMsg_SnapshotTree(routing_id_, callback_id));
ax_tree_snapshot_callbacks_.insert(std::make_pair(callback_id, callback)); ax_tree_snapshot_callbacks_.insert(
std::make_pair(callback_id, std::move(callback)));
} }
void RenderFrameHostImpl::SetAccessibilityCallbackForTesting( void RenderFrameHostImpl::SetAccessibilityCallbackForTesting(
......
...@@ -158,8 +158,7 @@ class CONTENT_EXPORT RenderFrameHostImpl ...@@ -158,8 +158,7 @@ class CONTENT_EXPORT RenderFrameHostImpl
public CSPContext { public CSPContext {
public: public:
using AXTreeSnapshotCallback = using AXTreeSnapshotCallback =
base::Callback<void( base::OnceCallback<void(const ui::AXTreeUpdate&)>;
const ui::AXTreeUpdate&)>;
// An accessibility reset is only allowed to prevent very rare corner cases // An accessibility reset is only allowed to prevent very rare corner cases
// or race conditions where the browser and renderer get out of sync. If // or race conditions where the browser and renderer get out of sync. If
......
...@@ -561,10 +561,9 @@ void WebContentsAndroid::RequestAccessibilitySnapshot( ...@@ -561,10 +561,9 @@ void WebContentsAndroid::RequestAccessibilitySnapshot(
ScopedJavaGlobalRef<jobject> j_callback; ScopedJavaGlobalRef<jobject> j_callback;
j_callback.Reset(env, callback); j_callback.Reset(env, callback);
WebContentsImpl::AXTreeSnapshotCallback snapshot_callback = static_cast<WebContentsImpl*>(web_contents_)
base::Bind(&AXTreeSnapshotCallback, j_callback); ->RequestAXTreeSnapshot(
static_cast<WebContentsImpl*>(web_contents_)->RequestAXTreeSnapshot( base::BindOnce(&AXTreeSnapshotCallback, j_callback));
snapshot_callback);
} }
ScopedJavaLocalRef<jstring> WebContentsAndroid::GetEncoding( ScopedJavaLocalRef<jstring> WebContentsAndroid::GetEncoding(
......
...@@ -219,8 +219,7 @@ void ResetAccessibility(RenderFrameHost* rfh) { ...@@ -219,8 +219,7 @@ void ResetAccessibility(RenderFrameHost* rfh) {
static_cast<RenderFrameHostImpl*>(rfh)->AccessibilityReset(); static_cast<RenderFrameHostImpl*>(rfh)->AccessibilityReset();
} }
using AXTreeSnapshotCallback = using AXTreeSnapshotCallback = WebContents::AXTreeSnapshotCallback;
base::Callback<void(const ui::AXTreeUpdate&)>;
// Helper class used by WebContentsImpl::RequestAXTreeSnapshot. // Helper class used by WebContentsImpl::RequestAXTreeSnapshot.
// Handles the callbacks from parallel snapshot requests to each frame, // Handles the callbacks from parallel snapshot requests to each frame,
...@@ -229,14 +228,12 @@ using AXTreeSnapshotCallback = ...@@ -229,14 +228,12 @@ using AXTreeSnapshotCallback =
class AXTreeSnapshotCombiner : public base::RefCounted<AXTreeSnapshotCombiner> { class AXTreeSnapshotCombiner : public base::RefCounted<AXTreeSnapshotCombiner> {
public: public:
explicit AXTreeSnapshotCombiner(AXTreeSnapshotCallback callback) explicit AXTreeSnapshotCombiner(AXTreeSnapshotCallback callback)
: callback_(callback) { : callback_(std::move(callback)) {}
}
AXTreeSnapshotCallback AddFrame(bool is_root) { AXTreeSnapshotCallback AddFrame(bool is_root) {
// Adds a reference to |this|. // Adds a reference to |this|.
return base::Bind(&AXTreeSnapshotCombiner::ReceiveSnapshot, return base::BindOnce(&AXTreeSnapshotCombiner::ReceiveSnapshot, this,
this, is_root);
is_root);
} }
void ReceiveSnapshot(bool is_root, const ui::AXTreeUpdate& snapshot) { void ReceiveSnapshot(bool is_root, const ui::AXTreeUpdate& snapshot) {
...@@ -250,7 +247,7 @@ class AXTreeSnapshotCombiner : public base::RefCounted<AXTreeSnapshotCombiner> { ...@@ -250,7 +247,7 @@ class AXTreeSnapshotCombiner : public base::RefCounted<AXTreeSnapshotCombiner> {
// when there are no more references to this object. // when there are no more references to this object.
~AXTreeSnapshotCombiner() { ~AXTreeSnapshotCombiner() {
combiner_.Combine(); combiner_.Combine();
callback_.Run(combiner_.combined()); std::move(callback_).Run(combiner_.combined());
} }
ui::AXTreeCombiner combiner_; ui::AXTreeCombiner combiner_;
...@@ -1072,13 +1069,13 @@ void WebContentsImpl::AddAccessibilityMode(ui::AXMode mode) { ...@@ -1072,13 +1069,13 @@ void WebContentsImpl::AddAccessibilityMode(ui::AXMode mode) {
SetAccessibilityMode(new_mode); SetAccessibilityMode(new_mode);
} }
void WebContentsImpl::RequestAXTreeSnapshot( void WebContentsImpl::RequestAXTreeSnapshot(AXTreeSnapshotCallback callback) {
const AXTreeSnapshotCallback& callback) {
// Send a request to each of the frames in parallel. Each one will return // Send a request to each of the frames in parallel. Each one will return
// an accessibility tree snapshot, and AXTreeSnapshotCombiner will combine // an accessibility tree snapshot, and AXTreeSnapshotCombiner will combine
// them into a single tree and call |callback| with that result, then // them into a single tree and call |callback| with that result, then
// delete |combiner|. // delete |combiner|.
AXTreeSnapshotCombiner* combiner = new AXTreeSnapshotCombiner(callback); AXTreeSnapshotCombiner* combiner =
new AXTreeSnapshotCombiner(std::move(callback));
for (FrameTreeNode* frame_tree_node : frame_tree_.Nodes()) { for (FrameTreeNode* frame_tree_node : frame_tree_.Nodes()) {
bool is_root = frame_tree_node->parent() == nullptr; bool is_root = frame_tree_node->parent() == nullptr;
frame_tree_node->current_frame_host()->RequestAXTreeSnapshot( frame_tree_node->current_frame_host()->RequestAXTreeSnapshot(
......
...@@ -341,7 +341,7 @@ class CONTENT_EXPORT WebContentsImpl : public WebContents, ...@@ -341,7 +341,7 @@ class CONTENT_EXPORT WebContentsImpl : public WebContents,
bool IsWaitingForResponse() const override; bool IsWaitingForResponse() const override;
const net::LoadStateWithParam& GetLoadState() const override; const net::LoadStateWithParam& GetLoadState() const override;
const base::string16& GetLoadStateHost() const override; const base::string16& GetLoadStateHost() const override;
void RequestAXTreeSnapshot(const AXTreeSnapshotCallback& callback) override; void RequestAXTreeSnapshot(AXTreeSnapshotCallback callback) override;
uint64_t GetUploadSize() const override; uint64_t GetUploadSize() const override;
uint64_t GetUploadPosition() const override; uint64_t GetUploadPosition() const override;
const std::string& GetEncoding() const override; const std::string& GetEncoding() const override;
......
...@@ -300,9 +300,9 @@ class WebContents : public PageNavigator, ...@@ -300,9 +300,9 @@ class WebContents : public PageNavigator,
// Request a one-time snapshot of the accessibility tree without changing // Request a one-time snapshot of the accessibility tree without changing
// the accessibility mode. // the accessibility mode.
using AXTreeSnapshotCallback = base::Callback<void(const ui::AXTreeUpdate&)>; using AXTreeSnapshotCallback =
virtual void RequestAXTreeSnapshot( base::OnceCallback<void(const ui::AXTreeUpdate&)>;
const AXTreeSnapshotCallback& callback) = 0; virtual void RequestAXTreeSnapshot(AXTreeSnapshotCallback callback) = 0;
// Causes the current page to be closed, including running its onunload event // Causes the current page to be closed, including running its onunload event
// handler. // handler.
......
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