⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 244033 in webkit


Ignore:
Timestamp:
Apr 8, 2019, 12:31:45 PM (7 years ago)
Author:
BJ Burg
Message:

Web Automation: clean up some WebAutomationSession methods to use modern async IPC
https://bugs.webkit.org/show_bug.cgi?id=196168

Reviewed by Devin Rousso.

Modern WebKit IPC is capable of providing completion handlers and can track callback IDs.
So, most messages between WebAutomationSession and its proxy can use this facility and stop
keeping track of callback IDs manually. This makes most code easier to read on both the
sender and receiver side.

There are two cases that could not be converted:

  • For evaluateJavaScript, we cannot use async IPC because WebAutomationSession expects to

be able to cancel all pending replies when a page navigates away, the web process crashes,
or when handling an alert.

  • For takeScreenshot, there is not currently support in the modern async IPC code paths for

sending the result back. ShareableBitmap and friends lack a modern decoder implementation.

  • UIProcess/Automation/WebAutomationSession.cpp:

(WebKit::WebAutomationSession::resolveChildFrameHandle):
(WebKit::WebAutomationSession::resolveParentFrameHandle):
(WebKit::WebAutomationSession::computeElementLayout):
(WebKit::WebAutomationSession::selectOptionElement):
(WebKit::WebAutomationSession::getAllCookies):
(WebKit::WebAutomationSession::deleteSingleCookie):
(WebKit::WebAutomationSession::viewportInViewCenterPointOfElement):
(WebKit::WebAutomationSession::didResolveChildFrame): Deleted.
(WebKit::WebAutomationSession::didResolveParentFrame): Deleted.
(WebKit::WebAutomationSession::didComputeElementLayout): Deleted.
(WebKit::WebAutomationSession::didSelectOptionElement): Deleted.
(WebKit::WebAutomationSession::didGetCookiesForFrame): Deleted.
(WebKit::WebAutomationSession::didDeleteCookie): Deleted.

  • UIProcess/Automation/WebAutomationSession.h:
  • UIProcess/Automation/WebAutomationSession.messages.in:
  • WebProcess/Automation/WebAutomationSessionProxy.cpp:

(WebKit::WebAutomationSessionProxy::resolveChildFrameWithOrdinal):
(WebKit::WebAutomationSessionProxy::resolveChildFrameWithNodeHandle):
(WebKit::WebAutomationSessionProxy::resolveChildFrameWithName):
(WebKit::WebAutomationSessionProxy::resolveParentFrame):
(WebKit::WebAutomationSessionProxy::computeElementLayout):
(WebKit::WebAutomationSessionProxy::selectOptionElement):
(WebKit::WebAutomationSessionProxy::getCookiesForFrame):
(WebKit::WebAutomationSessionProxy::deleteCookie):

  • WebProcess/Automation/WebAutomationSessionProxy.h:
  • WebProcess/Automation/WebAutomationSessionProxy.messages.in:
Location:
trunk/Source/WebKit
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/ChangeLog

    r244030 r244033  
     12019-04-05  Brian Burg  <bburg@apple.com>
     2
     3        Web Automation: clean up some WebAutomationSession methods to use modern async IPC
     4        https://bugs.webkit.org/show_bug.cgi?id=196168
     5
     6        Reviewed by Devin Rousso.
     7
     8        Modern WebKit IPC is capable of providing completion handlers and can track callback IDs.
     9        So, most messages between WebAutomationSession and its proxy can use this facility and stop
     10        keeping track of callback IDs manually. This makes most code easier to read on both the
     11        sender and receiver side.
     12
     13        There are two cases that could not be converted:
     14        - For evaluateJavaScript, we cannot use async IPC because WebAutomationSession expects to
     15        be able to cancel all pending replies when a page navigates away, the web process crashes,
     16        or when handling an alert.
     17        - For takeScreenshot, there is not currently support in the modern async IPC code paths for
     18        sending the result back. ShareableBitmap and friends lack a modern decoder implementation.
     19
     20        * UIProcess/Automation/WebAutomationSession.cpp:
     21        (WebKit::WebAutomationSession::resolveChildFrameHandle):
     22        (WebKit::WebAutomationSession::resolveParentFrameHandle):
     23        (WebKit::WebAutomationSession::computeElementLayout):
     24        (WebKit::WebAutomationSession::selectOptionElement):
     25        (WebKit::WebAutomationSession::getAllCookies):
     26        (WebKit::WebAutomationSession::deleteSingleCookie):
     27        (WebKit::WebAutomationSession::viewportInViewCenterPointOfElement):
     28        (WebKit::WebAutomationSession::didResolveChildFrame): Deleted.
     29        (WebKit::WebAutomationSession::didResolveParentFrame): Deleted.
     30        (WebKit::WebAutomationSession::didComputeElementLayout): Deleted.
     31        (WebKit::WebAutomationSession::didSelectOptionElement): Deleted.
     32        (WebKit::WebAutomationSession::didGetCookiesForFrame): Deleted.
     33        (WebKit::WebAutomationSession::didDeleteCookie): Deleted.
     34        * UIProcess/Automation/WebAutomationSession.h:
     35        * UIProcess/Automation/WebAutomationSession.messages.in:
     36        * WebProcess/Automation/WebAutomationSessionProxy.cpp:
     37        (WebKit::WebAutomationSessionProxy::resolveChildFrameWithOrdinal):
     38        (WebKit::WebAutomationSessionProxy::resolveChildFrameWithNodeHandle):
     39        (WebKit::WebAutomationSessionProxy::resolveChildFrameWithName):
     40        (WebKit::WebAutomationSessionProxy::resolveParentFrame):
     41        (WebKit::WebAutomationSessionProxy::computeElementLayout):
     42        (WebKit::WebAutomationSessionProxy::selectOptionElement):
     43        (WebKit::WebAutomationSessionProxy::getCookiesForFrame):
     44        (WebKit::WebAutomationSessionProxy::deleteCookie):
     45        * WebProcess/Automation/WebAutomationSessionProxy.h:
     46        * WebProcess/Automation/WebAutomationSessionProxy.messages.in:
     47
    1482019-04-08  Alex Christensen  <achristensen@webkit.org>
    249
  • trunk/Source/WebKit/UIProcess/Automation/WebAutomationSession.cpp

    r243378 r244033  
    971971        ASYNC_FAIL_WITH_PREDEFINED_ERROR(FrameNotFound);
    972972
    973     uint64_t callbackID = m_nextResolveFrameCallbackID++;
    974     m_resolveChildFrameHandleCallbacks.set(callbackID, WTFMove(callback));
     973    WTF::CompletionHandler<void(Optional<String>, uint64_t)> completionHandler = [this, protectedThis = makeRef(*this), callback = callback.copyRef()](Optional<String> errorType, uint64_t frameID) mutable {
     974        if (errorType) {
     975            callback->sendFailure(STRING_FOR_PREDEFINED_ERROR_MESSAGE(*errorType));
     976            return;
     977        }
     978
     979        callback->sendSuccess(handleForWebFrameID(frameID));
     980    };
    975981
    976982    if (optionalNodeHandle) {
    977         page->process().send(Messages::WebAutomationSessionProxy::ResolveChildFrameWithNodeHandle(page->pageID(), frameID.value(), *optionalNodeHandle, callbackID), 0);
     983        page->process().sendWithAsyncReply(Messages::WebAutomationSessionProxy::ResolveChildFrameWithNodeHandle(page->pageID(), frameID.value(), *optionalNodeHandle), WTFMove(completionHandler));
    978984        return;
    979985    }
    980986
    981987    if (optionalName) {
    982         page->process().send(Messages::WebAutomationSessionProxy::ResolveChildFrameWithName(page->pageID(), frameID.value(), *optionalName, callbackID), 0);
     988        page->process().sendWithAsyncReply(Messages::WebAutomationSessionProxy::ResolveChildFrameWithName(page->pageID(), frameID.value(), *optionalName), WTFMove(completionHandler));
    983989        return;
    984990    }
    985991
    986992    if (optionalOrdinal) {
    987         page->process().send(Messages::WebAutomationSessionProxy::ResolveChildFrameWithOrdinal(page->pageID(), frameID.value(), *optionalOrdinal, callbackID), 0);
     993        page->process().sendWithAsyncReply(Messages::WebAutomationSessionProxy::ResolveChildFrameWithOrdinal(page->pageID(), frameID.value(), *optionalOrdinal), WTFMove(completionHandler));
    988994        return;
    989995    }
    990996
    991997    ASSERT_NOT_REACHED();
    992 }
    993 
    994 void WebAutomationSession::didResolveChildFrame(uint64_t callbackID, uint64_t frameID, const String& errorType)
    995 {
    996     auto callback = m_resolveChildFrameHandleCallbacks.take(callbackID);
    997     if (!callback)
    998         return;
    999 
    1000     if (!errorType.isEmpty())
    1001         callback->sendFailure(STRING_FOR_PREDEFINED_ERROR_MESSAGE(errorType));
    1002     else
    1003         callback->sendSuccess(handleForWebFrameID(frameID));
    1004998}
    1005999
     
    10141008        ASYNC_FAIL_WITH_PREDEFINED_ERROR(FrameNotFound);
    10151009
    1016     uint64_t callbackID = m_nextResolveParentFrameCallbackID++;
    1017     m_resolveParentFrameHandleCallbacks.set(callbackID, WTFMove(callback));
    1018 
    1019     page->process().send(Messages::WebAutomationSessionProxy::ResolveParentFrame(page->pageID(), frameID.value(), callbackID), 0);
    1020 }
    1021 
    1022 void WebAutomationSession::didResolveParentFrame(uint64_t callbackID, uint64_t frameID, const String& errorType)
    1023 {
    1024     auto callback = m_resolveParentFrameHandleCallbacks.take(callbackID);
    1025     if (!callback)
    1026         return;
    1027 
    1028     if (!errorType.isEmpty())
    1029         callback->sendFailure(STRING_FOR_PREDEFINED_ERROR_MESSAGE(errorType));
    1030     else
     1010    WTF::CompletionHandler<void(Optional<String>, uint64_t)> completionHandler = [this, protectedThis = makeRef(*this), callback = callback.copyRef()](Optional<String> errorType, uint64_t frameID) mutable {
     1011        if (errorType) {
     1012            callback->sendFailure(STRING_FOR_PREDEFINED_ERROR_MESSAGE(*errorType));
     1013            return;
     1014        }
     1015
    10311016        callback->sendSuccess(handleForWebFrameID(frameID));
     1017    };
     1018
     1019    page->process().sendWithAsyncReply(Messages::WebAutomationSessionProxy::ResolveParentFrame(page->pageID(), frameID.value()), WTFMove(completionHandler));
    10321020}
    10331021
     
    10551043        ASYNC_FAIL_WITH_PREDEFINED_ERROR_AND_DETAILS(InvalidParameter, "The parameter 'coordinateSystem' is invalid.");
    10561044
    1057     // Start at 2 and use only even numbers to not conflict with m_nextViewportInViewCenterPointOfElementCallbackID.
    1058     uint64_t callbackID = m_nextComputeElementLayoutCallbackID += 2;
    1059     m_computeElementLayoutCallbacks.set(callbackID, WTFMove(callback));
     1045    WTF::CompletionHandler<void(Optional<String>, WebCore::IntRect, Optional<WebCore::IntPoint>, bool)> completionHandler = [callback = callback.copyRef()](Optional<String> errorType, WebCore::IntRect rect, Optional<WebCore::IntPoint> inViewCenterPoint, bool isObscured) mutable {
     1046        if (errorType) {
     1047            callback->sendFailure(STRING_FOR_PREDEFINED_ERROR_MESSAGE(*errorType));
     1048            return;
     1049        }
     1050
     1051        auto originObject = Inspector::Protocol::Automation::Point::create()
     1052            .setX(rect.x())
     1053            .setY(rect.y())
     1054            .release();
     1055
     1056        auto sizeObject = Inspector::Protocol::Automation::Size::create()
     1057            .setWidth(rect.width())
     1058            .setHeight(rect.height())
     1059            .release();
     1060
     1061        auto rectObject = Inspector::Protocol::Automation::Rect::create()
     1062            .setOrigin(WTFMove(originObject))
     1063            .setSize(WTFMove(sizeObject))
     1064            .release();
     1065
     1066        if (!inViewCenterPoint) {
     1067            callback->sendSuccess(WTFMove(rectObject), nullptr, isObscured);
     1068            return;
     1069        }
     1070
     1071        auto inViewCenterPointObject = Inspector::Protocol::Automation::Point::create()
     1072            .setX(inViewCenterPoint.value().x())
     1073            .setY(inViewCenterPoint.value().y())
     1074            .release();
     1075
     1076        callback->sendSuccess(WTFMove(rectObject), WTFMove(inViewCenterPointObject), isObscured);
     1077    };
    10601078
    10611079    bool scrollIntoViewIfNeeded = optionalScrollIntoViewIfNeeded ? *optionalScrollIntoViewIfNeeded : false;
    1062     page->process().send(Messages::WebAutomationSessionProxy::ComputeElementLayout(page->pageID(), frameID.value(), nodeHandle, scrollIntoViewIfNeeded, coordinateSystem.value(), callbackID), 0);
    1063 }
    1064 
    1065 void WebAutomationSession::didComputeElementLayout(uint64_t callbackID, WebCore::IntRect rect, Optional<WebCore::IntPoint> inViewCenterPoint, bool isObscured, const String& errorType)
    1066 {
    1067     if (callbackID % 2 == 1) {
    1068         ASSERT(inViewCenterPoint);
    1069         if (auto callback = m_viewportInViewCenterPointOfElementCallbacks.take(callbackID)) {
    1070             Optional<AutomationCommandError> error;
    1071             if (!errorType.isEmpty())
    1072                 error = AUTOMATION_COMMAND_ERROR_WITH_MESSAGE(errorType);
    1073             callback(inViewCenterPoint, error);
    1074         }
    1075         return;
    1076     }
    1077 
    1078     auto callback = m_computeElementLayoutCallbacks.take(callbackID);
    1079     if (!callback)
    1080         return;
    1081 
    1082     if (!errorType.isEmpty()) {
    1083         callback->sendFailure(STRING_FOR_PREDEFINED_ERROR_MESSAGE(errorType));
    1084         return;
    1085     }
    1086 
    1087     auto originObject = Inspector::Protocol::Automation::Point::create()
    1088         .setX(rect.x())
    1089         .setY(rect.y())
    1090         .release();
    1091 
    1092     auto sizeObject = Inspector::Protocol::Automation::Size::create()
    1093         .setWidth(rect.width())
    1094         .setHeight(rect.height())
    1095         .release();
    1096 
    1097     auto rectObject = Inspector::Protocol::Automation::Rect::create()
    1098         .setOrigin(WTFMove(originObject))
    1099         .setSize(WTFMove(sizeObject))
    1100         .release();
    1101 
    1102     if (!inViewCenterPoint) {
    1103         callback->sendSuccess(WTFMove(rectObject), nullptr, isObscured);
    1104         return;
    1105     }
    1106 
    1107     auto inViewCenterPointObject = Inspector::Protocol::Automation::Point::create()
    1108         .setX(inViewCenterPoint.value().x())
    1109         .setY(inViewCenterPoint.value().y())
    1110         .release();
    1111 
    1112     callback->sendSuccess(WTFMove(rectObject), WTFMove(inViewCenterPointObject), isObscured);
     1080    page->process().sendWithAsyncReply(Messages::WebAutomationSessionProxy::ComputeElementLayout(page->pageID(), frameID.value(), nodeHandle, scrollIntoViewIfNeeded, coordinateSystem.value()), WTFMove(completionHandler));
    11131081}
    11141082
     
    11231091        ASYNC_FAIL_WITH_PREDEFINED_ERROR(FrameNotFound);
    11241092
    1125     uint64_t callbackID = m_nextSelectOptionElementCallbackID++;
    1126     m_selectOptionElementCallbacks.set(callbackID, WTFMove(callback));
    1127 
    1128     page->process().send(Messages::WebAutomationSessionProxy::SelectOptionElement(page->pageID(), frameID.value(), nodeHandle, callbackID), 0);
    1129 }
    1130 
    1131 void WebAutomationSession::didSelectOptionElement(uint64_t callbackID, const String& errorType)
    1132 {
    1133     auto callback = m_selectOptionElementCallbacks.take(callbackID);
    1134     if (!callback)
    1135         return;
    1136 
    1137     if (!errorType.isEmpty()) {
    1138         callback->sendFailure(STRING_FOR_PREDEFINED_ERROR_MESSAGE(errorType));
    1139         return;
    1140     }
    1141 
    1142     callback->sendSuccess();
    1143 }
    1144 
     1093    WTF::CompletionHandler<void(Optional<String>)> completionHandler = [callback = callback.copyRef()](Optional<String> errorType) mutable {
     1094        if (errorType) {
     1095            callback->sendFailure(STRING_FOR_PREDEFINED_ERROR_MESSAGE(*errorType));
     1096            return;
     1097        }
     1098       
     1099        callback->sendSuccess();
     1100    };
     1101
     1102    page->process().sendWithAsyncReply(Messages::WebAutomationSessionProxy::SelectOptionElement(page->pageID(), frameID.value(), nodeHandle), WTFMove(completionHandler));
     1103}
    11451104
    11461105void WebAutomationSession::isShowingJavaScriptDialog(Inspector::ErrorString& errorString, const String& browsingContextHandle, bool* result)
     
    12711230}
    12721231
    1273 void WebAutomationSession::getAllCookies(const String& browsingContextHandle, Ref<GetAllCookiesCallback>&& callback)
    1274 {
    1275     WebPageProxy* page = webPageProxyForHandle(browsingContextHandle);
    1276     if (!page)
    1277         ASYNC_FAIL_WITH_PREDEFINED_ERROR(WindowNotFound);
    1278 
    1279     // Always send the main frame ID as 0 so it is resolved on the WebProcess side. This avoids a race when page->mainFrame() is null still.
    1280     const uint64_t mainFrameID = 0;
    1281 
    1282     uint64_t callbackID = m_nextGetCookiesCallbackID++;
    1283     m_getCookieCallbacks.set(callbackID, WTFMove(callback));
    1284 
    1285     page->process().send(Messages::WebAutomationSessionProxy::GetCookiesForFrame(page->pageID(), mainFrameID, callbackID), 0);
    1286 }
    1287 
    12881232static Ref<Inspector::Protocol::Automation::Cookie> buildObjectForCookie(const WebCore::Cookie& cookie)
    12891233{
     
    13111255}
    13121256
    1313 void WebAutomationSession::didGetCookiesForFrame(uint64_t callbackID, Vector<WebCore::Cookie> cookies, const String& errorType)
    1314 {
    1315     auto callback = m_getCookieCallbacks.take(callbackID);
    1316     if (!callback)
    1317         return;
    1318 
    1319     if (!errorType.isEmpty()) {
    1320         callback->sendFailure(STRING_FOR_PREDEFINED_ERROR_MESSAGE(errorType));
    1321         return;
    1322     }
    1323 
    1324     callback->sendSuccess(buildArrayForCookies(cookies));
    1325 }
    1326 
    1327 void WebAutomationSession::deleteSingleCookie(const String& browsingContextHandle, const String& cookieName, Ref<DeleteSingleCookieCallback>&& callback)
     1257void WebAutomationSession::getAllCookies(const String& browsingContextHandle, Ref<GetAllCookiesCallback>&& callback)
    13281258{
    13291259    WebPageProxy* page = webPageProxyForHandle(browsingContextHandle);
    13301260    if (!page)
    13311261        ASYNC_FAIL_WITH_PREDEFINED_ERROR(WindowNotFound);
     1262
     1263    WTF::CompletionHandler<void(Optional<String>, Vector<WebCore::Cookie>)> completionHandler = [callback = callback.copyRef()](Optional<String> errorType, Vector<WebCore::Cookie> cookies) mutable {
     1264        if (errorType) {
     1265            callback->sendFailure(STRING_FOR_PREDEFINED_ERROR_MESSAGE(*errorType));
     1266            return;
     1267        }
     1268
     1269        callback->sendSuccess(buildArrayForCookies(cookies));
     1270    };
    13321271
    13331272    // Always send the main frame ID as 0 so it is resolved on the WebProcess side. This avoids a race when page->mainFrame() is null still.
    13341273    const uint64_t mainFrameID = 0;
    1335 
    1336     uint64_t callbackID = m_nextDeleteCookieCallbackID++;
    1337     m_deleteCookieCallbacks.set(callbackID, WTFMove(callback));
    1338 
    1339     page->process().send(Messages::WebAutomationSessionProxy::DeleteCookie(page->pageID(), mainFrameID, cookieName, callbackID), 0);
    1340 }
    1341 
    1342 void WebAutomationSession::didDeleteCookie(uint64_t callbackID, const String& errorType)
    1343 {
    1344     auto callback = m_deleteCookieCallbacks.take(callbackID);
    1345     if (!callback)
    1346         return;
    1347 
    1348     if (!errorType.isEmpty()) {
    1349         callback->sendFailure(STRING_FOR_PREDEFINED_ERROR_MESSAGE(errorType));
    1350         return;
    1351     }
    1352 
    1353     callback->sendSuccess();
     1274    page->process().sendWithAsyncReply(Messages::WebAutomationSessionProxy::GetCookiesForFrame(page->pageID(), mainFrameID), WTFMove(completionHandler));
     1275}
     1276
     1277void WebAutomationSession::deleteSingleCookie(const String& browsingContextHandle, const String& cookieName, Ref<DeleteSingleCookieCallback>&& callback)
     1278{
     1279    WebPageProxy* page = webPageProxyForHandle(browsingContextHandle);
     1280    if (!page)
     1281        ASYNC_FAIL_WITH_PREDEFINED_ERROR(WindowNotFound);
     1282
     1283    WTF::CompletionHandler<void(Optional<String>)> completionHandler = [callback = callback.copyRef()](Optional<String> errorType) mutable {
     1284        if (errorType) {
     1285            callback->sendFailure(STRING_FOR_PREDEFINED_ERROR_MESSAGE(*errorType));
     1286            return;
     1287        }
     1288
     1289        callback->sendSuccess();
     1290    };
     1291
     1292    // Always send the main frame ID as 0 so it is resolved on the WebProcess side. This avoids a race when page->mainFrame() is null still.
     1293    const uint64_t mainFrameID = 0;
     1294    page->process().sendWithAsyncReply(Messages::WebAutomationSessionProxy::DeleteCookie(page->pageID(), mainFrameID, cookieName), WTFMove(completionHandler));
    13541295}
    13551296
     
    15191460void WebAutomationSession::viewportInViewCenterPointOfElement(WebPageProxy& page, uint64_t frameID, const String& nodeHandle, Function<void (Optional<WebCore::IntPoint>, Optional<AutomationCommandError>)>&& completionHandler)
    15201461{
    1521     // Start at 3 and use only odd numbers to not conflict with m_nextComputeElementLayoutCallbackID.
    1522     uint64_t callbackID = m_nextViewportInViewCenterPointOfElementCallbackID += 2;
    1523     m_viewportInViewCenterPointOfElementCallbacks.set(callbackID, WTFMove(completionHandler));
    1524 
    1525     page.process().send(Messages::WebAutomationSessionProxy::ComputeElementLayout(page.pageID(), frameID, nodeHandle, false, CoordinateSystem::LayoutViewport, callbackID), 0);
     1462    WTF::CompletionHandler<void(Optional<String>, WebCore::IntRect, Optional<WebCore::IntPoint>, bool)> didComputeElementLayoutHandler = [completionHandler = WTFMove(completionHandler)](Optional<String> errorType, WebCore::IntRect, Optional<WebCore::IntPoint> inViewCenterPoint, bool) mutable {
     1463        if (errorType) {
     1464            completionHandler(WTF::nullopt, AUTOMATION_COMMAND_ERROR_WITH_MESSAGE(*errorType));
     1465            return;
     1466        }
     1467
     1468        ASSERT(inViewCenterPoint);
     1469        completionHandler(inViewCenterPoint, WTF::nullopt);
     1470    };
     1471
     1472    page.process().sendWithAsyncReply(Messages::WebAutomationSessionProxy::ComputeElementLayout(page.pageID(), frameID, nodeHandle, false, CoordinateSystem::LayoutViewport), WTFMove(didComputeElementLayoutHandler));
    15261473}
    15271474
  • trunk/Source/WebKit/UIProcess/Automation/WebAutomationSession.h

    r243340 r244033  
    3030#include "AutomationFrontendDispatchers.h"
    3131#include "Connection.h"
     32#include "MessageReceiver.h"
     33#include "MessageSender.h"
    3234#include "ShareableBitmap.h"
    3335#include "SimulatedInputDispatcher.h"
     
    233235    void hideWindowForPage(WebPageProxy&, WTF::CompletionHandler<void()>&&);
    234236
    235     // Implemented in generated WebAutomationSessionMessageReceiver.cpp.
     237    // IPC::MessageReceiver (Implemented by generated code in WebAutomationSessionMessageReceiver.cpp).
    236238    void didReceiveMessage(IPC::Connection&, IPC::Decoder&) override;
    237239
    238240    // Called by WebAutomationSession messages.
    239241    void didEvaluateJavaScriptFunction(uint64_t callbackID, const String& result, const String& errorType);
    240     void didResolveChildFrame(uint64_t callbackID, uint64_t frameID, const String& errorType);
    241     void didResolveParentFrame(uint64_t callbackID, uint64_t frameID, const String& errorType);
    242     void didComputeElementLayout(uint64_t callbackID, WebCore::IntRect, Optional<WebCore::IntPoint>, bool isObscured, const String& errorType);
    243     void didSelectOptionElement(uint64_t callbackID, const String& errorType);
    244242    void didTakeScreenshot(uint64_t callbackID, const ShareableBitmap::Handle&, const String& errorType);
    245     void didGetCookiesForFrame(uint64_t callbackID, Vector<WebCore::Cookie>, const String& errorType);
    246     void didDeleteCookie(uint64_t callbackID, const String& errorType);
    247243
    248244    // Platform-dependent implementations.
     
    306302    HashMap<uint64_t, RefPtr<Inspector::AutomationBackendDispatcherHandler::EvaluateJavaScriptFunctionCallback>> m_evaluateJavaScriptFunctionCallbacks;
    307303
    308     uint64_t m_nextResolveFrameCallbackID { 1 };
    309     HashMap<uint64_t, RefPtr<Inspector::AutomationBackendDispatcherHandler::ResolveChildFrameHandleCallback>> m_resolveChildFrameHandleCallbacks;
    310 
    311     uint64_t m_nextResolveParentFrameCallbackID { 1 };
    312     HashMap<uint64_t, RefPtr<Inspector::AutomationBackendDispatcherHandler::ResolveParentFrameHandleCallback>> m_resolveParentFrameHandleCallbacks;
    313 
    314     // Start at 2 and use only even numbers to not conflict with m_nextViewportInViewCenterPointOfElementCallbackID.
    315     uint64_t m_nextComputeElementLayoutCallbackID { 2 };
    316     HashMap<uint64_t, RefPtr<Inspector::AutomationBackendDispatcherHandler::ComputeElementLayoutCallback>> m_computeElementLayoutCallbacks;
    317 
    318     // Start at 3 and use only odd numbers to not conflict with m_nextComputeElementLayoutCallbackID.
    319     uint64_t m_nextViewportInViewCenterPointOfElementCallbackID { 3 };
    320     HashMap<uint64_t, Function<void(Optional<WebCore::IntPoint>, Optional<AutomationCommandError>)>> m_viewportInViewCenterPointOfElementCallbacks;
    321 
    322304    uint64_t m_nextScreenshotCallbackID { 1 };
    323305    HashMap<uint64_t, RefPtr<Inspector::AutomationBackendDispatcherHandler::TakeScreenshotCallback>> m_screenshotCallbacks;
    324 
    325     uint64_t m_nextGetCookiesCallbackID { 1 };
    326     HashMap<uint64_t, RefPtr<Inspector::AutomationBackendDispatcherHandler::GetAllCookiesCallback>> m_getCookieCallbacks;
    327 
    328     uint64_t m_nextDeleteCookieCallbackID { 1 };
    329     HashMap<uint64_t, RefPtr<Inspector::AutomationBackendDispatcherHandler::DeleteSingleCookieCallback>> m_deleteCookieCallbacks;
    330 
    331     uint64_t m_nextSelectOptionElementCallbackID { 1 };
    332     HashMap<uint64_t, RefPtr<Inspector::AutomationBackendDispatcherHandler::SelectOptionElementCallback>> m_selectOptionElementCallbacks;
    333306
    334307    enum class WindowTransitionedToState {
  • trunk/Source/WebKit/UIProcess/Automation/WebAutomationSession.messages.in

    r239427 r244033  
    1 # Copyright (C) 2016 Apple Inc. All rights reserved.
     1# Copyright (C) 2016-2019 Apple Inc. All rights reserved.
    22#
    33# Redistribution and use in source and binary forms, with or without
     
    2323messages -> WebAutomationSession {
    2424    DidEvaluateJavaScriptFunction(uint64_t callbackID, String result, String errorType)
    25 
    26     DidResolveChildFrame(uint64_t callbackID, uint64_t frameID, String errorType)
    27     DidResolveParentFrame(uint64_t callbackID, uint64_t frameID, String errorType)
    28 
    29     DidComputeElementLayout(uint64_t callbackID, WebCore::IntRect rect, Optional<WebCore::IntPoint> inViewCenterPoint, bool isObscured, String errorType)
    30 
    31     DidSelectOptionElement(uint64_t callbackID, String errorType)
    32 
    3325    DidTakeScreenshot(uint64_t callbackID, WebKit::ShareableBitmap::Handle imageDataHandle, String errorType)
    34 
    35     DidGetCookiesForFrame(uint64_t callbackID, Vector<WebCore::Cookie> cookies, String errorType)
    36     DidDeleteCookie(uint64_t callbackID, String errorType)
    3726}
  • trunk/Source/WebKit/WebProcess/Automation/WebAutomationSessionProxy.cpp

    r241934 r244033  
    313313}
    314314
    315 void WebAutomationSessionProxy::resolveChildFrameWithOrdinal(uint64_t pageID, uint64_t frameID, uint32_t ordinal, uint64_t callbackID)
    316 {
    317     WebPage* page = WebProcess::singleton().webPage(pageID);
    318     if (!page) {
    319         String windowNotFoundErrorType = Inspector::Protocol::AutomationHelpers::getEnumConstantValue(Inspector::Protocol::Automation::ErrorMessage::WindowNotFound);
    320         WebProcess::singleton().parentProcessConnection()->send(Messages::WebAutomationSession::DidResolveChildFrame(callbackID, 0, windowNotFoundErrorType), 0);
     315void WebAutomationSessionProxy::resolveChildFrameWithOrdinal(uint64_t pageID, uint64_t frameID, uint32_t ordinal, CompletionHandler<void(Optional<String>, uint64_t)>&& completionHandler)
     316{
     317    WebPage* page = WebProcess::singleton().webPage(pageID);
     318    if (!page) {
     319        String windowNotFoundErrorType = Inspector::Protocol::AutomationHelpers::getEnumConstantValue(Inspector::Protocol::Automation::ErrorMessage::WindowNotFound);
     320        completionHandler(windowNotFoundErrorType, 0);
    321321        return;
    322322    }
     
    326326    WebFrame* frame = frameID ? WebProcess::singleton().webFrame(frameID) : page->mainWebFrame();
    327327    if (!frame) {
    328         WebProcess::singleton().parentProcessConnection()->send(Messages::WebAutomationSession::DidResolveChildFrame(callbackID, 0, frameNotFoundErrorType), 0);
     328        completionHandler(frameNotFoundErrorType, 0);
    329329        return;
    330330    }
     
    332332    WebCore::Frame* coreFrame = frame->coreFrame();
    333333    if (!coreFrame) {
    334         WebProcess::singleton().parentProcessConnection()->send(Messages::WebAutomationSession::DidResolveChildFrame(callbackID, 0, frameNotFoundErrorType), 0);
     334        completionHandler(frameNotFoundErrorType, 0);
    335335        return;
    336336    }
     
    338338    WebCore::Frame* coreChildFrame = coreFrame->tree().scopedChild(ordinal);
    339339    if (!coreChildFrame) {
    340         WebProcess::singleton().parentProcessConnection()->send(Messages::WebAutomationSession::DidResolveChildFrame(callbackID, 0, frameNotFoundErrorType), 0);
     340        completionHandler(frameNotFoundErrorType, 0);
    341341        return;
    342342    }
     
    344344    WebFrame* childFrame = WebFrame::fromCoreFrame(*coreChildFrame);
    345345    if (!childFrame) {
    346         WebProcess::singleton().parentProcessConnection()->send(Messages::WebAutomationSession::DidResolveChildFrame(callbackID, 0, frameNotFoundErrorType), 0);
    347         return;
    348     }
    349 
    350     WebProcess::singleton().parentProcessConnection()->send(Messages::WebAutomationSession::DidResolveChildFrame(callbackID, childFrame->frameID(), String()), 0);
    351 }
    352 
    353 void WebAutomationSessionProxy::resolveChildFrameWithNodeHandle(uint64_t pageID, uint64_t frameID, const String& nodeHandle, uint64_t callbackID)
    354 {
    355     WebPage* page = WebProcess::singleton().webPage(pageID);
    356     if (!page) {
    357         String windowNotFoundErrorType = Inspector::Protocol::AutomationHelpers::getEnumConstantValue(Inspector::Protocol::Automation::ErrorMessage::WindowNotFound);
    358         WebProcess::singleton().parentProcessConnection()->send(Messages::WebAutomationSession::DidResolveChildFrame(callbackID, 0, windowNotFoundErrorType), 0);
     346        completionHandler(frameNotFoundErrorType, 0);
     347        return;
     348    }
     349
     350    completionHandler(WTF::nullopt, childFrame->frameID());
     351}
     352
     353void WebAutomationSessionProxy::resolveChildFrameWithNodeHandle(uint64_t pageID, uint64_t frameID, const String& nodeHandle, CompletionHandler<void(Optional<String>, uint64_t)>&& completionHandler)
     354{
     355    WebPage* page = WebProcess::singleton().webPage(pageID);
     356    if (!page) {
     357        String windowNotFoundErrorType = Inspector::Protocol::AutomationHelpers::getEnumConstantValue(Inspector::Protocol::Automation::ErrorMessage::WindowNotFound);
     358        completionHandler(windowNotFoundErrorType, 0);
    359359        return;
    360360    }
     
    364364    WebFrame* frame = frameID ? WebProcess::singleton().webFrame(frameID) : page->mainWebFrame();
    365365    if (!frame) {
    366         WebProcess::singleton().parentProcessConnection()->send(Messages::WebAutomationSession::DidResolveChildFrame(callbackID, 0, frameNotFoundErrorType), 0);
     366        completionHandler(frameNotFoundErrorType, 0);
    367367        return;
    368368    }
     
    370370    WebCore::Element* coreElement = elementForNodeHandle(*frame, nodeHandle);
    371371    if (!coreElement || !coreElement->isFrameElementBase()) {
    372         WebProcess::singleton().parentProcessConnection()->send(Messages::WebAutomationSession::DidResolveChildFrame(callbackID, 0, frameNotFoundErrorType), 0);
     372        completionHandler(frameNotFoundErrorType, 0);
    373373        return;
    374374    }
     
    376376    WebCore::Frame* coreFrameFromElement = static_cast<WebCore::HTMLFrameElementBase*>(coreElement)->contentFrame();
    377377    if (!coreFrameFromElement) {
    378         WebProcess::singleton().parentProcessConnection()->send(Messages::WebAutomationSession::DidResolveChildFrame(callbackID, 0, frameNotFoundErrorType), 0);
     378        completionHandler(frameNotFoundErrorType, 0);
    379379        return;
    380380    }
     
    382382    WebFrame* frameFromElement = WebFrame::fromCoreFrame(*coreFrameFromElement);
    383383    if (!frameFromElement) {
    384         WebProcess::singleton().parentProcessConnection()->send(Messages::WebAutomationSession::DidResolveChildFrame(callbackID, 0, frameNotFoundErrorType), 0);
    385         return;
    386     }
    387 
    388     WebProcess::singleton().parentProcessConnection()->send(Messages::WebAutomationSession::DidResolveChildFrame(callbackID, frameFromElement->frameID(), String()), 0);
    389 }
    390 
    391 void WebAutomationSessionProxy::resolveChildFrameWithName(uint64_t pageID, uint64_t frameID, const String& name, uint64_t callbackID)
    392 {
    393     WebPage* page = WebProcess::singleton().webPage(pageID);
    394     if (!page) {
    395         String windowNotFoundErrorType = Inspector::Protocol::AutomationHelpers::getEnumConstantValue(Inspector::Protocol::Automation::ErrorMessage::WindowNotFound);
    396         WebProcess::singleton().parentProcessConnection()->send(Messages::WebAutomationSession::DidResolveChildFrame(callbackID, 0, windowNotFoundErrorType), 0);
     384        completionHandler(frameNotFoundErrorType, 0);
     385        return;
     386    }
     387
     388    completionHandler(WTF::nullopt, frameFromElement->frameID());
     389}
     390
     391void WebAutomationSessionProxy::resolveChildFrameWithName(uint64_t pageID, uint64_t frameID, const String& name, CompletionHandler<void(Optional<String>, uint64_t)>&& completionHandler)
     392{
     393    WebPage* page = WebProcess::singleton().webPage(pageID);
     394    if (!page) {
     395        String windowNotFoundErrorType = Inspector::Protocol::AutomationHelpers::getEnumConstantValue(Inspector::Protocol::Automation::ErrorMessage::WindowNotFound);
     396        completionHandler(windowNotFoundErrorType, 0);
    397397        return;
    398398    }
     
    402402    WebFrame* frame = frameID ? WebProcess::singleton().webFrame(frameID) : page->mainWebFrame();
    403403    if (!frame) {
    404         WebProcess::singleton().parentProcessConnection()->send(Messages::WebAutomationSession::DidResolveChildFrame(callbackID, 0, frameNotFoundErrorType), 0);
     404        completionHandler(frameNotFoundErrorType, 0);
    405405        return;
    406406    }
     
    408408    WebCore::Frame* coreFrame = frame->coreFrame();
    409409    if (!coreFrame) {
    410         WebProcess::singleton().parentProcessConnection()->send(Messages::WebAutomationSession::DidResolveChildFrame(callbackID, 0, frameNotFoundErrorType), 0);
     410        completionHandler(frameNotFoundErrorType, 0);
    411411        return;
    412412    }
     
    414414    WebCore::Frame* coreChildFrame = coreFrame->tree().scopedChild(name);
    415415    if (!coreChildFrame) {
    416         WebProcess::singleton().parentProcessConnection()->send(Messages::WebAutomationSession::DidResolveChildFrame(callbackID, 0, frameNotFoundErrorType), 0);
     416        completionHandler(frameNotFoundErrorType, 0);
    417417        return;
    418418    }
     
    420420    WebFrame* childFrame = WebFrame::fromCoreFrame(*coreChildFrame);
    421421    if (!childFrame) {
    422         WebProcess::singleton().parentProcessConnection()->send(Messages::WebAutomationSession::DidResolveChildFrame(callbackID, 0, frameNotFoundErrorType), 0);
    423         return;
    424     }
    425 
    426     WebProcess::singleton().parentProcessConnection()->send(Messages::WebAutomationSession::DidResolveChildFrame(callbackID, childFrame->frameID(), String()), 0);
    427 }
    428 
    429 void WebAutomationSessionProxy::resolveParentFrame(uint64_t pageID, uint64_t frameID, uint64_t callbackID)
    430 {
    431     WebPage* page = WebProcess::singleton().webPage(pageID);
    432     if (!page) {
    433         String windowNotFoundErrorType = Inspector::Protocol::AutomationHelpers::getEnumConstantValue(Inspector::Protocol::Automation::ErrorMessage::WindowNotFound);
    434         WebProcess::singleton().parentProcessConnection()->send(Messages::WebAutomationSession::DidResolveParentFrame(callbackID, 0, windowNotFoundErrorType), 0);
     422        completionHandler(frameNotFoundErrorType, 0);
     423        return;
     424    }
     425
     426    completionHandler(WTF::nullopt, childFrame->frameID());
     427}
     428
     429void WebAutomationSessionProxy::resolveParentFrame(uint64_t pageID, uint64_t frameID, CompletionHandler<void(Optional<String>, uint64_t)>&& completionHandler)
     430{
     431    WebPage* page = WebProcess::singleton().webPage(pageID);
     432    if (!page) {
     433        String windowNotFoundErrorType = Inspector::Protocol::AutomationHelpers::getEnumConstantValue(Inspector::Protocol::Automation::ErrorMessage::WindowNotFound);
     434        completionHandler(windowNotFoundErrorType, 0);
    435435        return;
    436436    }
     
    440440    WebFrame* frame = frameID ? WebProcess::singleton().webFrame(frameID) : page->mainWebFrame();
    441441    if (!frame) {
    442         WebProcess::singleton().parentProcessConnection()->send(Messages::WebAutomationSession::DidResolveParentFrame(callbackID, 0, frameNotFoundErrorType), 0);
     442        completionHandler(frameNotFoundErrorType, 0);
    443443        return;
    444444    }
     
    446446    WebFrame* parentFrame = frame->parentFrame();
    447447    if (!parentFrame) {
    448         WebProcess::singleton().parentProcessConnection()->send(Messages::WebAutomationSession::DidResolveParentFrame(callbackID, 0, frameNotFoundErrorType), 0);
    449         return;
    450     }
    451 
    452     WebProcess::singleton().parentProcessConnection()->send(Messages::WebAutomationSession::DidResolveParentFrame(callbackID, parentFrame->frameID(), String()), 0);
     448        completionHandler(frameNotFoundErrorType, 0);
     449        return;
     450    }
     451
     452    completionHandler(WTF::nullopt, parentFrame->frameID());
    453453}
    454454
     
    535535}
    536536
    537 void WebAutomationSessionProxy::computeElementLayout(uint64_t pageID, uint64_t frameID, String nodeHandle, bool scrollIntoViewIfNeeded, CoordinateSystem coordinateSystem, uint64_t callbackID)
    538 {
    539     WebPage* page = WebProcess::singleton().webPage(pageID);
    540     if (!page) {
    541         String windowNotFoundErrorType = Inspector::Protocol::AutomationHelpers::getEnumConstantValue(Inspector::Protocol::Automation::ErrorMessage::WindowNotFound);
    542         WebProcess::singleton().parentProcessConnection()->send(Messages::WebAutomationSession::DidComputeElementLayout(callbackID, { }, WTF::nullopt, false, windowNotFoundErrorType), 0);
     537void WebAutomationSessionProxy::computeElementLayout(uint64_t pageID, uint64_t frameID, String nodeHandle, bool scrollIntoViewIfNeeded, CoordinateSystem coordinateSystem, CompletionHandler<void(Optional<String>, WebCore::IntRect, Optional<WebCore::IntPoint>, bool)>&& completionHandler)
     538{
     539    WebPage* page = WebProcess::singleton().webPage(pageID);
     540    if (!page) {
     541        String windowNotFoundErrorType = Inspector::Protocol::AutomationHelpers::getEnumConstantValue(Inspector::Protocol::Automation::ErrorMessage::WindowNotFound);
     542        completionHandler(windowNotFoundErrorType, { }, WTF::nullopt, false);
    543543        return;
    544544    }
     
    550550    WebFrame* frame = frameID ? WebProcess::singleton().webFrame(frameID) : page->mainWebFrame();
    551551    if (!frame || !frame->coreFrame() || !frame->coreFrame()->view()) {
    552         WebProcess::singleton().parentProcessConnection()->send(Messages::WebAutomationSession::DidComputeElementLayout(callbackID, { }, WTF::nullopt, false, frameNotFoundErrorType), 0);
     552        completionHandler(frameNotFoundErrorType, { }, WTF::nullopt, false);
    553553        return;
    554554    }
     
    556556    WebCore::Element* coreElement = elementForNodeHandle(*frame, nodeHandle);
    557557    if (!coreElement) {
    558         WebProcess::singleton().parentProcessConnection()->send(Messages::WebAutomationSession::DidComputeElementLayout(callbackID, { }, WTF::nullopt, false, nodeNotFoundErrorType), 0);
     558        completionHandler(nodeNotFoundErrorType, { }, WTF::nullopt, false);
    559559        return;
    560560    }
     
    601601    }
    602602
    603     WebProcess::singleton().parentProcessConnection()->send(Messages::WebAutomationSession::DidComputeElementLayout(callbackID, resultElementBounds, resultInViewCenterPoint, isObscured, String()), 0);
    604 }
    605 
    606 void WebAutomationSessionProxy::selectOptionElement(uint64_t pageID, uint64_t frameID, String nodeHandle, uint64_t callbackID)
    607 {
    608     WebPage* page = WebProcess::singleton().webPage(pageID);
    609     if (!page) {
    610         String windowNotFoundErrorType = Inspector::Protocol::AutomationHelpers::getEnumConstantValue(Inspector::Protocol::Automation::ErrorMessage::WindowNotFound);
    611         WebProcess::singleton().parentProcessConnection()->send(Messages::WebAutomationSession::DidSelectOptionElement(callbackID, windowNotFoundErrorType), 0);
     603    completionHandler(WTF::nullopt, resultElementBounds, resultInViewCenterPoint, isObscured);
     604}
     605
     606void WebAutomationSessionProxy::selectOptionElement(uint64_t pageID, uint64_t frameID, String nodeHandle, CompletionHandler<void(Optional<String>)>&& completionHandler)
     607{
     608    WebPage* page = WebProcess::singleton().webPage(pageID);
     609    if (!page) {
     610        String windowNotFoundErrorType = Inspector::Protocol::AutomationHelpers::getEnumConstantValue(Inspector::Protocol::Automation::ErrorMessage::WindowNotFound);
     611        completionHandler(windowNotFoundErrorType);
    612612        return;
    613613    }
     
    616616    if (!frame || !frame->coreFrame() || !frame->coreFrame()->view()) {
    617617        String frameNotFoundErrorType = Inspector::Protocol::AutomationHelpers::getEnumConstantValue(Inspector::Protocol::Automation::ErrorMessage::FrameNotFound);
    618         WebProcess::singleton().parentProcessConnection()->send(Messages::WebAutomationSession::DidSelectOptionElement(callbackID, frameNotFoundErrorType), 0);
     618        completionHandler(frameNotFoundErrorType);
    619619        return;
    620620    }
     
    623623    if (!coreElement || (!is<WebCore::HTMLOptionElement>(coreElement) && !is<WebCore::HTMLOptGroupElement>(coreElement))) {
    624624        String nodeNotFoundErrorType = Inspector::Protocol::AutomationHelpers::getEnumConstantValue(Inspector::Protocol::Automation::ErrorMessage::NodeNotFound);
    625         WebProcess::singleton().parentProcessConnection()->send(Messages::WebAutomationSession::DidSelectOptionElement(callbackID, nodeNotFoundErrorType), 0);
     625        completionHandler(nodeNotFoundErrorType);
    626626        return;
    627627    }
     
    629629    String elementNotInteractableErrorType = Inspector::Protocol::AutomationHelpers::getEnumConstantValue(Inspector::Protocol::Automation::ErrorMessage::ElementNotInteractable);
    630630    if (is<WebCore::HTMLOptGroupElement>(coreElement)) {
    631         WebProcess::singleton().parentProcessConnection()->send(Messages::WebAutomationSession::DidSelectOptionElement(callbackID, elementNotInteractableErrorType), 0);
     631        completionHandler(elementNotInteractableErrorType);
    632632        return;
    633633    }
     
    636636    auto* selectElement = optionElement.ownerSelectElement();
    637637    if (!selectElement) {
    638         WebProcess::singleton().parentProcessConnection()->send(Messages::WebAutomationSession::DidSelectOptionElement(callbackID, elementNotInteractableErrorType), 0);
     638        completionHandler(elementNotInteractableErrorType);
    639639        return;
    640640    }
     
    645645        selectElement->optionSelectedByUser(optionElement.index(), true, selectElement->multiple());
    646646    }
    647     WebProcess::singleton().parentProcessConnection()->send(Messages::WebAutomationSession::DidSelectOptionElement(callbackID, { }), 0);
     647    completionHandler(WTF::nullopt);
    648648}
    649649
     
    720720}
    721721
    722 void WebAutomationSessionProxy::getCookiesForFrame(uint64_t pageID, uint64_t frameID, uint64_t callbackID)
    723 {
    724     WebPage* page = WebProcess::singleton().webPage(pageID);
    725     if (!page) {
    726         String windowNotFoundErrorType = Inspector::Protocol::AutomationHelpers::getEnumConstantValue(Inspector::Protocol::Automation::ErrorMessage::WindowNotFound);
    727         WebProcess::singleton().parentProcessConnection()->send(Messages::WebAutomationSession::DidGetCookiesForFrame(callbackID, Vector<WebCore::Cookie>(), windowNotFoundErrorType), 0);
     722void WebAutomationSessionProxy::getCookiesForFrame(uint64_t pageID, uint64_t frameID, CompletionHandler<void(Optional<String>, Vector<WebCore::Cookie>)>&& completionHandler)
     723{
     724    WebPage* page = WebProcess::singleton().webPage(pageID);
     725    if (!page) {
     726        String windowNotFoundErrorType = Inspector::Protocol::AutomationHelpers::getEnumConstantValue(Inspector::Protocol::Automation::ErrorMessage::WindowNotFound);
     727        completionHandler(windowNotFoundErrorType, Vector<WebCore::Cookie>());
    728728        return;
    729729    }
     
    732732    if (!frame || !frame->coreFrame() || !frame->coreFrame()->document()) {
    733733        String frameNotFoundErrorType = Inspector::Protocol::AutomationHelpers::getEnumConstantValue(Inspector::Protocol::Automation::ErrorMessage::FrameNotFound);
    734         WebProcess::singleton().parentProcessConnection()->send(Messages::WebAutomationSession::DidGetCookiesForFrame(callbackID, Vector<WebCore::Cookie>(), frameNotFoundErrorType), 0);
     734        completionHandler(frameNotFoundErrorType, Vector<WebCore::Cookie>());
    735735        return;
    736736    }
     
    742742        page->corePage()->cookieJar().getRawCookies(document, document.cookieURL(), foundCookies);
    743743
    744     WebProcess::singleton().parentProcessConnection()->send(Messages::WebAutomationSession::DidGetCookiesForFrame(callbackID, foundCookies, String()), 0);
    745 }
    746 
    747 void WebAutomationSessionProxy::deleteCookie(uint64_t pageID, uint64_t frameID, String cookieName, uint64_t callbackID)
    748 {
    749     WebPage* page = WebProcess::singleton().webPage(pageID);
    750     if (!page) {
    751         String windowNotFoundErrorType = Inspector::Protocol::AutomationHelpers::getEnumConstantValue(Inspector::Protocol::Automation::ErrorMessage::WindowNotFound);
    752         WebProcess::singleton().parentProcessConnection()->send(Messages::WebAutomationSession::DidDeleteCookie(callbackID, windowNotFoundErrorType), 0);
     744    completionHandler(WTF::nullopt, foundCookies);
     745}
     746
     747void WebAutomationSessionProxy::deleteCookie(uint64_t pageID, uint64_t frameID, String cookieName, CompletionHandler<void(Optional<String>)>&& completionHandler)
     748{
     749    WebPage* page = WebProcess::singleton().webPage(pageID);
     750    if (!page) {
     751        String windowNotFoundErrorType = Inspector::Protocol::AutomationHelpers::getEnumConstantValue(Inspector::Protocol::Automation::ErrorMessage::WindowNotFound);
     752        completionHandler(windowNotFoundErrorType);
    753753        return;
    754754    }
     
    757757    if (!frame || !frame->coreFrame() || !frame->coreFrame()->document()) {
    758758        String frameNotFoundErrorType = Inspector::Protocol::AutomationHelpers::getEnumConstantValue(Inspector::Protocol::Automation::ErrorMessage::FrameNotFound);
    759         WebProcess::singleton().parentProcessConnection()->send(Messages::WebAutomationSession::DidDeleteCookie(callbackID, frameNotFoundErrorType), 0);
     759        completionHandler(frameNotFoundErrorType);
    760760        return;
    761761    }
     
    764764    page->corePage()->cookieJar().deleteCookie(document, document.cookieURL(), cookieName);
    765765
    766     WebProcess::singleton().parentProcessConnection()->send(Messages::WebAutomationSession::DidDeleteCookie(callbackID, String()), 0);
     766    completionHandler(WTF::nullopt);
    767767}
    768768
  • trunk/Source/WebKit/WebProcess/Automation/WebAutomationSessionProxy.h

    r241183 r244033  
    11/*
    2  * Copyright (C) 2016 Apple Inc. All rights reserved.
     2 * Copyright (C) 2016-2019 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    3232
    3333namespace WebCore {
     34struct Cookie;
    3435class Element;
    3536}
     
    6162    // Called by WebAutomationSessionProxy messages
    6263    void evaluateJavaScriptFunction(uint64_t pageID, uint64_t frameID, const String& function, Vector<String> arguments, bool expectsImplicitCallbackArgument, int callbackTimeout, uint64_t callbackID);
    63     void resolveChildFrameWithOrdinal(uint64_t pageID, uint64_t frameID, uint32_t ordinal, uint64_t callbackID);
    64     void resolveChildFrameWithNodeHandle(uint64_t pageID, uint64_t frameID, const String& nodeHandle, uint64_t callbackID);
    65     void resolveChildFrameWithName(uint64_t pageID, uint64_t frameID, const String& name, uint64_t callbackID);
    66     void resolveParentFrame(uint64_t pageID, uint64_t frameID, uint64_t callbackID);
     64    void resolveChildFrameWithOrdinal(uint64_t pageID, uint64_t frameID, uint32_t ordinal, CompletionHandler<void(Optional<String>, uint64_t)>&&);
     65    void resolveChildFrameWithNodeHandle(uint64_t pageID, uint64_t frameID, const String& nodeHandle, CompletionHandler<void(Optional<String>, uint64_t)>&&);
     66    void resolveChildFrameWithName(uint64_t pageID, uint64_t frameID, const String& name, CompletionHandler<void(Optional<String>, uint64_t)>&&);
     67    void resolveParentFrame(uint64_t pageID, uint64_t frameID, CompletionHandler<void(Optional<String>, uint64_t)>&&);
    6768    void focusFrame(uint64_t pageID, uint64_t frameID);
    68     void computeElementLayout(uint64_t pageID, uint64_t frameID, String nodeHandle, bool scrollIntoViewIfNeeded, CoordinateSystem, uint64_t callbackID);
    69     void selectOptionElement(uint64_t pageID, uint64_t frameID, String nodeHandle, uint64_t callbackID);
     69    void computeElementLayout(uint64_t pageID, uint64_t frameID, String nodeHandle, bool scrollIntoViewIfNeeded, CoordinateSystem, CompletionHandler<void(Optional<String>, WebCore::IntRect, Optional<WebCore::IntPoint>, bool)>&&);
     70    void selectOptionElement(uint64_t pageID, uint64_t frameID, String nodeHandle, CompletionHandler<void(Optional<String>)>&&);
    7071    void takeScreenshot(uint64_t pageID, uint64_t frameID, String nodeHandle, bool scrollIntoViewIfNeeded, bool clipToViewport, uint64_t callbackID);
    71     void getCookiesForFrame(uint64_t pageID, uint64_t frameID, uint64_t callbackID);
    72     void deleteCookie(uint64_t pageID, uint64_t frameID, String cookieName, uint64_t callbackID);
     72    void getCookiesForFrame(uint64_t pageID, uint64_t frameID, CompletionHandler<void(Optional<String>, Vector<WebCore::Cookie>)>&&);
     73    void deleteCookie(uint64_t pageID, uint64_t frameID, String cookieName, CompletionHandler<void(Optional<String>)>&&);
    7374
    7475    String m_sessionIdentifier;
  • trunk/Source/WebKit/WebProcess/Automation/WebAutomationSessionProxy.messages.in

    r237110 r244033  
    1 # Copyright (C) 2016 Apple Inc. All rights reserved.
     1# Copyright (C) 2016-2019 Apple Inc. All rights reserved.
    22#
    33# Redistribution and use in source and binary forms, with or without
     
    2424    EvaluateJavaScriptFunction(uint64_t pageID, uint64_t frameID, String function, Vector<String> arguments, bool expectsImplicitCallbackArgument, int callbackTimeout, uint64_t callbackID)
    2525
    26     ResolveChildFrameWithOrdinal(uint64_t pageID, uint64_t frameID, uint32_t ordinal, uint64_t callbackID)
    27     ResolveChildFrameWithNodeHandle(uint64_t pageID, uint64_t frameID, String nodeHandle, uint64_t callbackID)
    28     ResolveChildFrameWithName(uint64_t pageID, uint64_t frameID, String name, uint64_t callbackID)
    29     ResolveParentFrame(uint64_t pageID, uint64_t frameID, uint64_t callbackID)
     26    ResolveChildFrameWithOrdinal(uint64_t pageID, uint64_t frameID, uint32_t ordinal) -> (Optional<String> errorType, uint64_t frameID) Async
     27    ResolveChildFrameWithNodeHandle(uint64_t pageID, uint64_t frameID, String nodeHandle) -> (Optional<String> errorType, uint64_t frameID) Async
     28    ResolveChildFrameWithName(uint64_t pageID, uint64_t frameID, String name) -> (Optional<String> errorType, uint64_t frameID) Async
     29    ResolveParentFrame(uint64_t pageID, uint64_t frameID) -> (Optional<String> errorType, uint64_t frameID) Async
    3030
    3131    FocusFrame(uint64_t pageID, uint64_t frameID)
    3232
    33     ComputeElementLayout(uint64_t pageID, uint64_t frameID, String nodeHandle, bool scrollIntoViewIfNeeded, enum:uint8_t WebKit::CoordinateSystem coordinateSystem, uint64_t callbackID)
     33    ComputeElementLayout(uint64_t pageID, uint64_t frameID, String nodeHandle, bool scrollIntoViewIfNeeded, enum:uint8_t WebKit::CoordinateSystem coordinateSystem) -> (Optional<String> errorType, WebCore::IntRect rect, Optional<WebCore::IntPoint> inViewCenterPoint, bool isObscured) Async
    3434
    35     SelectOptionElement(uint64_t pageID, uint64_t frameID, String nodeHandle, uint64_t callbackID)
     35    SelectOptionElement(uint64_t pageID, uint64_t frameID, String nodeHandle) -> (Optional<String> errorType) Async
    3636
    3737    TakeScreenshot(uint64_t pageID, uint64_t frameID, String nodeHandle, bool scrollIntoViewIfNeeded, bool clipToViewport, uint64_t callbackID)
    3838
    39     GetCookiesForFrame(uint64_t pageID, uint64_t frameID, uint64_t callbackID)
    40     DeleteCookie(uint64_t pageID, uint64_t frameID, String cookieName, uint64_t callbackID)
     39    GetCookiesForFrame(uint64_t pageID, uint64_t frameID) -> (Optional<String> errorType, Vector<WebCore::Cookie> cookies) Async
     40    DeleteCookie(uint64_t pageID, uint64_t frameID, String cookieName) -> (Optional<String> errorType) Async
    4141}
Note: See TracChangeset for help on using the changeset viewer.