Branch: refs/heads/main
Home: https://github.com/WebKit/WebKit
Commit: 9e1b4bc5f110647270eef4dfff5d7dc8e61337a2
https://github.com/WebKit/WebKit/commit/9e1b4bc5f110647270eef4dfff5d7dc8e61337a2
Author: BJ Burg <[email protected]>
Date: 2025-02-27 (Thu, 27 Feb 2025)
Changed paths:
M Source/JavaScriptCore/inspector/InspectorBackendDispatcher.h
M Source/JavaScriptCore/inspector/scripts/codegen/cpp_generator_templates.py
M
Source/JavaScriptCore/inspector/scripts/codegen/generate_cpp_backend_dispatcher_header.py
M
Source/JavaScriptCore/inspector/scripts/codegen/generate_cpp_backend_dispatcher_implementation.py
M Source/JavaScriptCore/inspector/scripts/codegen/models.py
M Source/WebKit/UIProcess/Automation/WebAutomationSession.cpp
M Source/WebKit/UIProcess/Automation/WebAutomationSession.h
M Source/WebKit/UIProcess/Automation/WebAutomationSessionMacros.h
M Source/WebKit/UIProcess/Automation/WebDriverBidiProcessor.cpp
M Source/WebKit/UIProcess/Automation/WebDriverBidiProcessor.h
M Source/WebKit/UIProcess/Automation/mac/WebAutomationSessionMac.mm
Log Message:
-----------
Web Automation: modernize callback thunks for async protocol commands
https://bugs.webkit.org/show_bug.cgi?id=284470
<rdar://141291944>
Reviewed by Devin Rousso and Patrick Angle.
To avoid code duplication, we need to be able to connect async
`WebAutomationSession` / `WebDriverBidiProcessor`
methods to each other. Right now these callbacks are all
`BackendDispatcher::CallbackBase` subclasses,
which does not have a standalone constructor. So, we cannot easily pass a
lambda that chains completion handlers.
In order to chain callbacks, switch from using `CallbackBase` subclasses to
using `Function<>` with proper type parameters.
We can move away from CallbackBase by capturing any needed state in a closure
and changing the type of callbacks to mention return types.
We deploy the new type aliases `CommandResponse<T>` and `CommandCallback<T>` to
make code more readable, adding the 'Of'
suffix for multiple arguments.
```
namespace Inspector {
typedef String ErrorString;
template <typename T>
using ErrorStringOr = Expected<T, ErrorString>;
template <typename T>
using CommandResponse = Inspector::Protocol::ErrorStringOr<T>;
template <typename T>
using CommandResponseOf = Inspector::Protocol::ErrorStringOr<std::tuple<T>>;
template <typename T>
using CommandCallback = Function<void(CommandResponse<T>)>;
template <typename T>
using CommandCallbackOf = Function<void(CommandResponseOf<T>)>;
}
```
These changes are scoped to *not* affect existing Web Inspector protocol
generated code. I'd love to remove
uses of `CallbackBase` from the existing uses of 'async' commands entirely.
However, doing so is essentially the
same work as refactoring/modernizing IndexedDBAgent. We can do that at a time
of our choosing. Fixing this is
tracked by <https://webkit.org/b/288203>.
The remainder of this commit is updating callsites in `WebAutomationSession` to
reflect that calling `sendSuccess()` /
`sendFailure()` has been superceded by returning expected or unexpected values
of `CommandResult<T>` (aka `ErrorStringOr<T>`).
Also, adapt code to use `CommandCallback<T>` for zero and single parameter
async commands, and `CommandCallbackOf<T>` for
async commands with more than one return value.
* Source/JavaScriptCore/inspector/InspectorBackendDispatcher.h:
Introduce new type aliases which make it easier to express the type of an async
callback in command implementations.
* Source/JavaScriptCore/inspector/scripts/codegen/cpp_generator_templates.py:
Split out the declaration of the reply thunk class from the command's method
declaration.
*
Source/JavaScriptCore/inspector/scripts/codegen/generate_cpp_backend_dispatcher_header.py:
(CppBackendDispatcherHeaderGenerator._generate_handler_declarations_for_domain):
(CppBackendDispatcherHeaderGenerator._generate_async_response_thunk_declaration_for_command):
Added.
(CppBackendDispatcherHeaderGenerator):
(CppBackendDispatcherHeaderGenerator._generate_async_handler_declaration_for_command):
Now that the return types are part of the type signature, enhance
`_generate_dispatcher_declaration_for_command`
to compute the type arguments for `Inspector::CommandCallbackOf<T...>`.
Add a new framework setting so that we can continue to generate existing async
protocol code
for non-WebDriver domains.
*
Source/JavaScriptCore/inspector/scripts/codegen/generate_cpp_backend_dispatcher_implementation.py:
(CppBackendDispatcherImplementationGenerator._generate_dispatcher_implementations_for_domain):
(CppBackendDispatcherImplementationGenerator._generate_async_command_response_thunk_class_for_domain):
Added.
(CppBackendDispatcherImplementationGenerator._generate_async_dispatcher_class_for_domain):
Deleted.
(CppBackendDispatcherImplementationGenerator._generate_dispatcher_implementation_for_command):
Refactor `_generate_dispatcher_implementation_for_command` so that the code to
convert return parameters
is shared between the sync and async command cases. Move the return parameter
passing code from the thunk
class to the anonymous lambda function passed as the last argument. Inside the
lambda, capture what would
have been stored in the thunk class's member variables so that we can associate
the error with the
originating command request (`protocol_requestId`).
* Source/WebKit/UIProcess/Automation/WebAutomationSession.cpp:
(WebKit::WebAutomationSession::terminate):
(WebKit::WebAutomationSession::getBrowsingContext):
(WebKit::WebAutomationSession::createBrowsingContext):
(WebKit::WebAutomationSession::switchToBrowsingContext):
(WebKit::WebAutomationSession::setWindowFrameOfBrowsingContext):
(WebKit::WebAutomationSession::waitForNavigationToComplete):
Fix this function so that it explicitly returns after moving `callback` into
the queue of callbacks waiting for navigation. It's not safe to use it anyway,
so simplify the control flow to make it easier to read.
(WebKit::WebAutomationSession::waitForNavigationToCompleteOnPage):
(WebKit::WebAutomationSession::waitForNavigationToCompleteOnFrame):
(WebKit::WebAutomationSession::respondToPendingPageNavigationCallbacksWithTimeout):
(WebKit::WebAutomationSession::respondToPendingFrameNavigationCallbacksWithTimeout):
(WebKit::WebAutomationSession::maximizeWindowOfBrowsingContext):
(WebKit::WebAutomationSession::hideWindowOfBrowsingContext):
(WebKit::WebAutomationSession::willShowJavaScriptDialog):
(WebKit::WebAutomationSession::navigateBrowsingContext):
(WebKit::WebAutomationSession::goBackInBrowsingContext):
(WebKit::WebAutomationSession::goForwardInBrowsingContext):
(WebKit::WebAutomationSession::reloadBrowsingContext):
(WebKit::WebAutomationSession::navigationOccurredForFrame):
(WebKit::WebAutomationSession::documentLoadedForFrame):
(WebKit::WebAutomationSession::inspectorFrontendLoaded):
(WebKit::WebAutomationSession::mouseEventsFlushedForPage):
(WebKit::WebAutomationSession::keyboardEventsFlushedForPage):
(WebKit::WebAutomationSession::wheelEventsFlushedForPage):
(WebKit::WebAutomationSession::willClosePage):
(WebKit::WebAutomationSession::evaluateJavaScriptFunction):
(WebKit::WebAutomationSession::resolveChildFrameHandle):
(WebKit::WebAutomationSession::resolveParentFrameHandle):
(WebKit::WebAutomationSession::computeElementLayout):
(WebKit::WebAutomationSession::getComputedRole):
(WebKit::WebAutomationSession::getComputedLabel):
(WebKit::WebAutomationSession::selectOptionElement):
(WebKit::WebAutomationSession::setFilesForInputFileUpload):
(WebKit::WebAutomationSession::getAllCookies):
(WebKit::WebAutomationSession::deleteSingleCookie):
(WebKit::WebAutomationSession::addSingleCookie):
Add missing move for `callback` to be owned the completion handler.
(WebKit::WebAutomationSession::simulateMouseInteraction):
(WebKit::WebAutomationSession::simulateTouchInteraction):
(WebKit::WebAutomationSession::simulateKeyboardInteraction):
(WebKit::WebAutomationSession::simulateWheelInteraction):
These cases require a bit more care to bridge between `CommandResponse<void>`
and `AutomationCommandError`.
(WebKit::WebAutomationSession::performMouseInteraction):
(WebKit::WebAutomationSession::performKeyboardInteractions):
(WebKit::pressedCharKey):
(WebKit::WebAutomationSession::performInteractionSequence):
(WebKit::WebAutomationSession::cancelInteractionSequence):
(WebKit::WebAutomationSession::takeScreenshot):
Adapt to using `CommandCallback<void>` and `CommandCallback<T>`.
* Source/WebKit/UIProcess/Automation/WebAutomationSession.h:
* Source/WebKit/UIProcess/Automation/WebAutomationSessionMacros.h:
* Source/WebKit/UIProcess/Automation/mac/WebAutomationSessionMac.mm:
(WebKit::WebAutomationSession::inspectBrowsingContext):
Adapt to using `CommandCallback<void>` and `CommandCallback<T>`.
* Source/WebKit/UIProcess/Automation/WebAutomationSession.h:
* Source/WebKit/UIProcess/Automation/WebAutomationSessionMacros.h:
* Source/WebKit/UIProcess/Automation/WebDriverBidiProcessor.h:
* Source/WebKit/UIProcess/Automation/WebDriverBidiProcessor.cpp:
(WebKit::WebDriverBidiProcessor::navigate): Update signature.
Canonical link: https://commits.webkit.org/291284@main
To unsubscribe from these emails, change your notification settings at
https://github.com/WebKit/WebKit/settings/notifications
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes