Commit c6f5e719 authored by Jacques Newman's avatar Jacques Newman Committed by Commit Bot

Avoid calling UIA APIs internally.

By calling these methods internally, we cause the histograms to be
inaccurate, as they should be tracking external calls.
Bug: 1095772
AX-Relnotes: n/a

Change-Id: I505a7bcddee34a382ead4387088c53dc921571af
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2247346
Commit-Queue: Jacques Newman <janewman@microsoft.com>
Reviewed-by: default avatarKurt Catti-Schmidt <kschmi@microsoft.com>
Reviewed-by: default avatarKevin Babbitt <kbabbitt@microsoft.com>
Cr-Commit-Position: refs/heads/master@{#779552}
parent f6661e85
...@@ -489,7 +489,7 @@ void BrowserAccessibilityManagerWin::FireUiaPropertyChangedEvent( ...@@ -489,7 +489,7 @@ void BrowserAccessibilityManagerWin::FireUiaPropertyChangedEvent(
auto* provider = ToBrowserAccessibilityWin(node)->GetCOM(); auto* provider = ToBrowserAccessibilityWin(node)->GetCOM();
base::win::ScopedVariant new_value; base::win::ScopedVariant new_value;
if (SUCCEEDED( if (SUCCEEDED(
provider->GetPropertyValue(uia_property, new_value.Receive()))) { provider->GetPropertyValueImpl(uia_property, new_value.Receive()))) {
::UiaRaiseAutomationPropertyChangedEvent(provider, uia_property, old_value, ::UiaRaiseAutomationPropertyChangedEvent(provider, uia_property, old_value,
new_value); new_value);
} }
......
...@@ -172,6 +172,11 @@ HRESULT AXPlatformNodeTextRangeProviderWin::CompareEndpoints( ...@@ -172,6 +172,11 @@ HRESULT AXPlatformNodeTextRangeProviderWin::CompareEndpoints(
HRESULT AXPlatformNodeTextRangeProviderWin::ExpandToEnclosingUnit( HRESULT AXPlatformNodeTextRangeProviderWin::ExpandToEnclosingUnit(
TextUnit unit) { TextUnit unit) {
WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_TEXTRANGE_EXPANDTOENCLOSINGUNIT); WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_TEXTRANGE_EXPANDTOENCLOSINGUNIT);
return ExpandToEnclosingUnitImpl(unit);
}
HRESULT AXPlatformNodeTextRangeProviderWin::ExpandToEnclosingUnitImpl(
TextUnit unit) {
UIA_VALIDATE_TEXTRANGEPROVIDER_CALL(); UIA_VALIDATE_TEXTRANGEPROVIDER_CALL();
NormalizeTextRange(); NormalizeTextRange();
...@@ -627,8 +632,8 @@ HRESULT AXPlatformNodeTextRangeProviderWin::Move(TextUnit unit, ...@@ -627,8 +632,8 @@ HRESULT AXPlatformNodeTextRangeProviderWin::Move(TextUnit unit,
// Move the start of the text range forward or backward in the document by the // Move the start of the text range forward or backward in the document by the
// requested number of text unit boundaries. // requested number of text unit boundaries.
int start_units_moved = 0; int start_units_moved = 0;
HRESULT hr = MoveEndpointByUnit(TextPatternRangeEndpoint_Start, unit, count, HRESULT hr = MoveEndpointByUnitImpl(TextPatternRangeEndpoint_Start, unit,
&start_units_moved); count, &start_units_moved);
bool succeeded_move = SUCCEEDED(hr) && start_units_moved != 0; bool succeeded_move = SUCCEEDED(hr) && start_units_moved != 0;
if (succeeded_move) { if (succeeded_move) {
...@@ -640,8 +645,8 @@ HRESULT AXPlatformNodeTextRangeProviderWin::Move(TextUnit unit, ...@@ -640,8 +645,8 @@ HRESULT AXPlatformNodeTextRangeProviderWin::Move(TextUnit unit,
// by one text unit to expand the text range from the degenerate range // by one text unit to expand the text range from the degenerate range
// state. // state.
int current_start_units_moved = 0; int current_start_units_moved = 0;
hr = MoveEndpointByUnit(TextPatternRangeEndpoint_Start, unit, -1, hr = MoveEndpointByUnitImpl(TextPatternRangeEndpoint_Start, unit, -1,
&current_start_units_moved); &current_start_units_moved);
start_units_moved -= 1; start_units_moved -= 1;
succeeded_move = SUCCEEDED(hr) && current_start_units_moved == -1 && succeeded_move = SUCCEEDED(hr) && current_start_units_moved == -1 &&
start_units_moved > 0; start_units_moved > 0;
...@@ -650,8 +655,8 @@ HRESULT AXPlatformNodeTextRangeProviderWin::Move(TextUnit unit, ...@@ -650,8 +655,8 @@ HRESULT AXPlatformNodeTextRangeProviderWin::Move(TextUnit unit,
// forward by one text unit to expand the text range from the degenerate // forward by one text unit to expand the text range from the degenerate
// state. // state.
int end_units_moved = 0; int end_units_moved = 0;
hr = MoveEndpointByUnit(TextPatternRangeEndpoint_End, unit, 1, hr = MoveEndpointByUnitImpl(TextPatternRangeEndpoint_End, unit, 1,
&end_units_moved); &end_units_moved);
succeeded_move = SUCCEEDED(hr) && end_units_moved == 1; succeeded_move = SUCCEEDED(hr) && end_units_moved == 1;
} }
...@@ -660,7 +665,7 @@ HRESULT AXPlatformNodeTextRangeProviderWin::Move(TextUnit unit, ...@@ -660,7 +665,7 @@ HRESULT AXPlatformNodeTextRangeProviderWin::Move(TextUnit unit,
// sure to bring back the end endpoint to the end of the start's anchor. // sure to bring back the end endpoint to the end of the start's anchor.
if (start_->anchor_id() != end_->anchor_id() && if (start_->anchor_id() != end_->anchor_id() &&
(unit == TextUnit_Character || unit == TextUnit_Word)) { (unit == TextUnit_Character || unit == TextUnit_Word)) {
ExpandToEnclosingUnit(unit); ExpandToEnclosingUnitImpl(unit);
} }
} }
} }
...@@ -683,6 +688,14 @@ HRESULT AXPlatformNodeTextRangeProviderWin::MoveEndpointByUnit( ...@@ -683,6 +688,14 @@ HRESULT AXPlatformNodeTextRangeProviderWin::MoveEndpointByUnit(
int count, int count,
int* units_moved) { int* units_moved) {
WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_TEXTRANGE_MOVEENDPOINTBYUNIT); WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_TEXTRANGE_MOVEENDPOINTBYUNIT);
return MoveEndpointByUnitImpl(endpoint, unit, count, units_moved);
}
HRESULT AXPlatformNodeTextRangeProviderWin::MoveEndpointByUnitImpl(
TextPatternRangeEndpoint endpoint,
TextUnit unit,
int count,
int* units_moved) {
UIA_VALIDATE_TEXTRANGEPROVIDER_CALL_1_OUT(units_moved); UIA_VALIDATE_TEXTRANGEPROVIDER_CALL_1_OUT(units_moved);
// Per MSDN, MoveEndpointByUnit with zero count has no effect. // Per MSDN, MoveEndpointByUnit with zero count has no effect.
......
...@@ -99,6 +99,16 @@ class AX_EXPORT __declspec(uuid("3071e40d-a10d-45ff-a59f-6e8e1138e2c1")) ...@@ -99,6 +99,16 @@ class AX_EXPORT __declspec(uuid("3071e40d-a10d-45ff-a59f-6e8e1138e2c1"))
AXBoundaryBehavior boundary_behavior, AXBoundaryBehavior boundary_behavior,
ax::mojom::MoveDirection boundary_direction); ax::mojom::MoveDirection boundary_direction);
// Prefer these *Impl methods when functionality is needed internally. We
// should avoid calling external APIs internally as it will cause the
// histograms to become innaccurate.
HRESULT MoveEndpointByUnitImpl(TextPatternRangeEndpoint endpoint,
TextUnit unit,
int count,
int* units_moved);
IFACEMETHODIMP ExpandToEnclosingUnitImpl(TextUnit unit);
base::string16 GetString(int max_count, base::string16 GetString(int max_count,
size_t* appended_newlines_count = nullptr); size_t* appended_newlines_count = nullptr);
AXPlatformNodeWin* owner() const; AXPlatformNodeWin* owner() const;
......
...@@ -643,7 +643,7 @@ void AXPlatformNodeWin::NotifyAccessibilityEvent(ax::mojom::Event event_type) { ...@@ -643,7 +643,7 @@ void AXPlatformNodeWin::NotifyAccessibilityEvent(ax::mojom::Event event_type) {
::VariantInit(old_value.Receive()); ::VariantInit(old_value.Receive());
base::win::ScopedVariant new_value; base::win::ScopedVariant new_value;
::VariantInit(new_value.Receive()); ::VariantInit(new_value.Receive());
GetPropertyValue((*uia_property), new_value.Receive()); GetPropertyValueImpl((*uia_property), new_value.Receive());
::UiaRaiseAutomationPropertyChangedEvent(this, (*uia_property), old_value, ::UiaRaiseAutomationPropertyChangedEvent(this, (*uia_property), old_value,
new_value); new_value);
} }
...@@ -4011,7 +4011,11 @@ IFACEMETHODIMP AXPlatformNodeWin::GetPropertyValue(PROPERTYID property_id, ...@@ -4011,7 +4011,11 @@ IFACEMETHODIMP AXPlatformNodeWin::GetPropertyValue(PROPERTYID property_id,
// Collapse all unknown property IDs into a single bucket. // Collapse all unknown property IDs into a single bucket.
base::UmaHistogramSparse("Accessibility.WinAPIs.GetPropertyValue", 0); base::UmaHistogramSparse("Accessibility.WinAPIs.GetPropertyValue", 0);
} }
return GetPropertyValueImpl(property_id, result);
}
HRESULT AXPlatformNodeWin::GetPropertyValueImpl(PROPERTYID property_id,
VARIANT* result) {
UIA_VALIDATE_CALL_1_ARG(result); UIA_VALIDATE_CALL_1_ARG(result);
result->vt = VT_EMPTY; result->vt = VT_EMPTY;
......
...@@ -1060,6 +1060,11 @@ class AX_EXPORT __declspec(uuid("26f5641a-246d-457b-a96d-07f3fae6acf2")) ...@@ -1060,6 +1060,11 @@ class AX_EXPORT __declspec(uuid("26f5641a-246d-457b-a96d-07f3fae6acf2"))
// IRawElementProviderSimple support method. // IRawElementProviderSimple support method.
bool IsPatternProviderSupported(PATTERNID pattern_id); bool IsPatternProviderSupported(PATTERNID pattern_id);
// Prefer GetPropertyValueImpl when calling internally. We should avoid
// calling external APIs internally as it will cause the histograms to become
// innaccurate.
HRESULT GetPropertyValueImpl(PROPERTYID property_id, VARIANT* result);
// Helper to return the runtime id (without going through a SAFEARRAY) // Helper to return the runtime id (without going through a SAFEARRAY)
using RuntimeIdArray = std::array<int, 2>; using RuntimeIdArray = std::array<int, 2>;
void GetRuntimeIdArray(RuntimeIdArray& runtime_id); void GetRuntimeIdArray(RuntimeIdArray& runtime_id);
......
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