|
51 | 51 | #include <JavaScriptCore/ConsoleTypes.h> |
52 | 52 | #include <JavaScriptCore/InspectorBackendDispatcher.h> |
53 | 53 | #include <JavaScriptCore/InspectorFrontendRouter.h> |
| 54 | +#include <WebCore/AXObjectCache.h> |
54 | 55 | #include <WebCore/MIMETypeRegistry.h> |
55 | 56 | #include <WebCore/PointerEventTypeNames.h> |
56 | 57 | #include <algorithm> |
@@ -1683,6 +1684,60 @@ void WebAutomationSession::getComputedLabel(const Inspector::Protocol::Automatio |
1683 | 1684 | page->sendWithAsyncReplyToProcessContainingFrameWithoutDestinationIdentifier(frameID, Messages::WebAutomationSessionProxy::GetComputedLabel(page->webPageIDInMainFrameProcess(), frameID, nodeHandle), WTF::move(completionHandler)); |
1684 | 1685 | } |
1685 | 1686 |
|
| 1687 | +static Ref<JSON::ArrayOf<String>> buildArrayForAXChildren(Vector<String>& axChildren) |
| 1688 | +{ |
| 1689 | + auto childrenArray = JSON::ArrayOf<String>::create(); |
| 1690 | + |
| 1691 | + for (const auto& child : axChildren) |
| 1692 | + childrenArray->addItem(child); |
| 1693 | + |
| 1694 | + return childrenArray; |
| 1695 | +} |
| 1696 | + |
| 1697 | +static WTF::CompletionHandler<void(std::optional<String>, AccessibilityProperties)> makeAccessibilityPropertiesCompletionHandler(Inspector::CommandCallback<Ref<Inspector::Protocol::Automation::AccessibilityProperties>>&& callback) |
| 1698 | +{ |
| 1699 | + return [callback = WTF::move(callback)](std::optional<String>&& optionalError, AccessibilityProperties&& properties) mutable { |
| 1700 | + ASYNC_FAIL_WITH_PREDEFINED_ERROR_IF_SET(optionalError); |
| 1701 | + auto axProperties = Inspector::Protocol::Automation::AccessibilityProperties::create() |
| 1702 | + .setAccessibilityNodeId(*properties.accessibilityNodeId) |
| 1703 | + .setRole(*properties.role) |
| 1704 | + .setLabel(*properties.label) |
| 1705 | + .setChecked(*properties.checked) |
| 1706 | + .setPressed(*properties.pressed) |
| 1707 | + .setParent(*properties.parent) |
| 1708 | + .setChildren(buildArrayForAXChildren(properties.children)) |
| 1709 | + .release(); |
| 1710 | + callback({ WTF::move(axProperties) }); |
| 1711 | + }; |
| 1712 | +} |
| 1713 | + |
| 1714 | +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) |
| 1715 | +{ |
| 1716 | + auto page = webPageProxyForHandle(browsingContextHandle); |
| 1717 | + ASYNC_FAIL_WITH_PREDEFINED_ERROR_IF(!page, WindowNotFound); |
| 1718 | + |
| 1719 | + bool frameNotFound = false; |
| 1720 | + auto frameID = webFrameIDForHandle(frameHandle, frameNotFound); |
| 1721 | + ASYNC_FAIL_WITH_PREDEFINED_ERROR_IF(frameNotFound, FrameNotFound); |
| 1722 | + |
| 1723 | + page->sendWithAsyncReplyToProcessContainingFrameWithoutDestinationIdentifier( |
| 1724 | + frameID, |
| 1725 | + Messages::WebAutomationSessionProxy::GetAccessibilityPropertiesForElement(page->webPageIDInMainFrameProcess(), frameID, nodeHandle), |
| 1726 | + Messages::WebAutomationSessionProxy::GetAccessibilityPropertiesForElement::Reply { |
| 1727 | + makeAccessibilityPropertiesCompletionHandler(WTF::move(callback)) |
| 1728 | + }); |
| 1729 | +} |
| 1730 | + |
| 1731 | +void WebAutomationSession::getAccessibilityPropertiesForAccessibilityNode(const Inspector::Protocol::Automation::BrowsingContextHandle& browsingContextHandle, const String& accessibilityNodeHandle, Inspector::CommandCallback<Ref<Inspector::Protocol::Automation::AccessibilityProperties>>&& callback) |
| 1732 | +{ |
| 1733 | + RefPtr page = webPageProxyForHandle(browsingContextHandle); |
| 1734 | + ASYNC_FAIL_WITH_PREDEFINED_ERROR_IF(!page, WindowNotFound); |
| 1735 | + |
| 1736 | + protect(page->legacyMainFrameProcess()).sendWithAsyncReply( |
| 1737 | + Messages::WebAutomationSessionProxy::GetAccessibilityPropertiesForAccessibilityNode(page->webPageIDInMainFrameProcess(), accessibilityNodeHandle), |
| 1738 | + makeAccessibilityPropertiesCompletionHandler(WTF::move(callback))); |
| 1739 | +} |
| 1740 | + |
1686 | 1741 | void WebAutomationSession::selectOptionElement(const Inspector::Protocol::Automation::BrowsingContextHandle& browsingContextHandle, const Inspector::Protocol::Automation::FrameHandle& frameHandle, const Inspector::Protocol::Automation::NodeHandle& nodeHandle, CommandCallback<void>&& callback) |
1687 | 1742 | { |
1688 | 1743 | auto page = webPageProxyForHandle(browsingContextHandle); |
|
0 commit comments