|
33 | 33 | #include "APIOpenPanelParameters.h" |
34 | 34 | #include "APIString.h" |
35 | 35 | #include "AutomationProtocolObjects.h" |
| 36 | +#include "ComputedAccessibilityProperties.h" |
36 | 37 | #include "CoordinateSystem.h" |
37 | 38 | #include "InspectorPassthroughChannel.h" |
38 | 39 | #include "PageLoadState.h" |
@@ -1783,6 +1784,83 @@ void WebAutomationSession::getComputedLabel(const Inspector::Protocol::Automatio |
1783 | 1784 | page->sendWithAsyncReplyToProcessContainingFrameWithoutDestinationIdentifier(frameID, Messages::WebAutomationSessionProxy::GetComputedLabel(page->webPageIDInProcessForFrame(frameID), frameID, nodeHandle), WTF::move(completionHandler)); |
1784 | 1785 | } |
1785 | 1786 |
|
| 1787 | +static String stringForAccessibilityNodeID(WebCore::AXID accessibilityNodeID) |
| 1788 | +{ |
| 1789 | + return String::number(accessibilityNodeID.toUInt64()); |
| 1790 | +} |
| 1791 | + |
| 1792 | +static String stringForAccessibilityTriState(AccessibilityTriState state) |
| 1793 | +{ |
| 1794 | + switch (state) { |
| 1795 | + case AccessibilityTriState::True: |
| 1796 | + return "true"_s; |
| 1797 | + case AccessibilityTriState::False: |
| 1798 | + return "false"_s; |
| 1799 | + case AccessibilityTriState::Mixed: |
| 1800 | + return "mixed"_s; |
| 1801 | + } |
| 1802 | + ASSERT_NOT_REACHED(); |
| 1803 | + return "false"_s; |
| 1804 | +} |
| 1805 | + |
| 1806 | +static WTF::CompletionHandler<void(std::optional<String>, std::optional<ComputedAccessibilityProperties>)> makeAccessibilityPropertiesCompletionHandler(Inspector::CommandCallback<Ref<Inspector::Protocol::Automation::AccessibilityProperties>>&& callback) |
| 1807 | +{ |
| 1808 | + return [callback = WTF::move(callback)](std::optional<String>&& optionalError, std::optional<ComputedAccessibilityProperties>&& properties) mutable { |
| 1809 | + ASYNC_FAIL_WITH_PREDEFINED_ERROR_IF_SET(optionalError); |
| 1810 | + ASYNC_FAIL_WITH_PREDEFINED_ERROR_IF(!properties, InternalError); |
| 1811 | + |
| 1812 | + auto children = JSON::ArrayOf<String>::create(); |
| 1813 | + for (auto childAccessibilityNodeID : properties->childAccessibilityNodeIDs) |
| 1814 | + children->addItem(stringForAccessibilityNodeID(childAccessibilityNodeID)); |
| 1815 | + |
| 1816 | + auto axProperties = Inspector::Protocol::Automation::AccessibilityProperties::create() |
| 1817 | + .setAccessibilityNodeId(stringForAccessibilityNodeID(properties->accessibilityNodeID)) |
| 1818 | + .setRole(WTF::move(properties->role)) |
| 1819 | + .setLabel(WTF::move(properties->label)) |
| 1820 | + .setChildren(WTF::move(children)) |
| 1821 | + .release(); |
| 1822 | + |
| 1823 | + if (properties->checked) |
| 1824 | + axProperties->setChecked(stringForAccessibilityTriState(*properties->checked)); |
| 1825 | + if (properties->pressed) |
| 1826 | + axProperties->setPressed(stringForAccessibilityTriState(*properties->pressed)); |
| 1827 | + if (properties->parentAccessibilityNodeID) |
| 1828 | + axProperties->setParent(stringForAccessibilityNodeID(*properties->parentAccessibilityNodeID)); |
| 1829 | + |
| 1830 | + callback({ WTF::move(axProperties) }); |
| 1831 | + }; |
| 1832 | +} |
| 1833 | + |
| 1834 | +void WebAutomationSession::getAccessibilityPropertiesForElement(const Inspector::Protocol::Automation::BrowsingContextHandle& browsingContextHandle, const Inspector::Protocol::Automation::FrameHandle& frameHandle, const Inspector::Protocol::Automation::NodeHandle& nodeHandle, Inspector::CommandCallback<Ref<Inspector::Protocol::Automation::AccessibilityProperties>>&& callback) |
| 1835 | +{ |
| 1836 | + auto page = webPageProxyForHandle(browsingContextHandle); |
| 1837 | + ASYNC_FAIL_WITH_PREDEFINED_ERROR_IF(!page, WindowNotFound); |
| 1838 | + |
| 1839 | + bool frameNotFound = false; |
| 1840 | + auto frameID = webFrameIDForHandle(frameHandle, frameNotFound); |
| 1841 | + ASYNC_FAIL_WITH_PREDEFINED_ERROR_IF(frameNotFound, FrameNotFound); |
| 1842 | + |
| 1843 | + page->sendWithAsyncReplyToProcessContainingFrameWithoutDestinationIdentifier( |
| 1844 | + frameID, |
| 1845 | + Messages::WebAutomationSessionProxy::GetAccessibilityPropertiesForElement(page->webPageIDInProcessForFrame(frameID), frameID, nodeHandle), |
| 1846 | + Messages::WebAutomationSessionProxy::GetAccessibilityPropertiesForElement::Reply { |
| 1847 | + makeAccessibilityPropertiesCompletionHandler(WTF::move(callback)) |
| 1848 | + }); |
| 1849 | +} |
| 1850 | + |
| 1851 | +void WebAutomationSession::getAccessibilityPropertiesForAccessibilityNode(const Inspector::Protocol::Automation::BrowsingContextHandle& browsingContextHandle, const String& accessibilityNodeHandle, Inspector::CommandCallback<Ref<Inspector::Protocol::Automation::AccessibilityProperties>>&& callback) |
| 1852 | +{ |
| 1853 | + RefPtr page = webPageProxyForHandle(browsingContextHandle); |
| 1854 | + ASYNC_FAIL_WITH_PREDEFINED_ERROR_IF(!page, WindowNotFound); |
| 1855 | + |
| 1856 | + // FIXME: Accessibility node handles are AXIDs, which are only unique within a single web process, and this |
| 1857 | + // always looks them up in the main frame's process. Encode the frame in the handle and route to the process |
| 1858 | + // containing that frame so that nodes in cross-process (site-isolated) iframes work. |
| 1859 | + protect(page->legacyMainFrameProcess())->sendWithAsyncReply( |
| 1860 | + Messages::WebAutomationSessionProxy::GetAccessibilityPropertiesForAccessibilityNode(page->webPageIDInMainFrameProcess(), accessibilityNodeHandle), |
| 1861 | + makeAccessibilityPropertiesCompletionHandler(WTF::move(callback))); |
| 1862 | +} |
| 1863 | + |
1786 | 1864 | void WebAutomationSession::selectOptionElement(const Inspector::Protocol::Automation::BrowsingContextHandle& browsingContextHandle, const Inspector::Protocol::Automation::FrameHandle& frameHandle, const Inspector::Protocol::Automation::NodeHandle& nodeHandle, CommandCallback<void>&& callback) |
1787 | 1865 | { |
1788 | 1866 | auto page = webPageProxyForHandle(browsingContextHandle); |
|
0 commit comments