Changeset 198914 in webkit


Ignore:
Timestamp:
Mar 31, 2016 1:52:44 PM (8 years ago)
Author:
timothy@apple.com
Message:

Web Automation: Navigation commands should not return until page loads or fails

https://bugs.webkit.org/show_bug.cgi?id=156063
rdar://problem/25464373

Reviewed by Brian Burg.

  • UIProcess/Automation/Automation.json: Make navigation commands async.
  • UIProcess/Automation/WebAutomationSession.cpp:

(WebKit::WebAutomationSession::navigateBrowsingContext): Save callback and timeout previous.
(WebKit::WebAutomationSession::goBackInBrowsingContext): Ditto.
(WebKit::WebAutomationSession::goForwardInBrowsingContext): Ditto.
(WebKit::WebAutomationSession::reloadBrowsingContext): Ditto.
(WebKit::WebAutomationSession::navigationOccuredForPage): Added. Fire callback for page.

  • UIProcess/Automation/WebAutomationSession.h:
  • UIProcess/WebPageProxy.cpp:

(WebKit::WebPageProxy::didFinishLoadForFrame): Call WebAutomationSession::navigationOccuredForPage.
(WebKit::WebPageProxy::didFailLoadForFrame): Ditto.
(WebKit::WebPageProxy::didSameDocumentNavigationForFrame): Ditto.

  • UIProcess/WebProcessPool.h: Added automationSession() getter.
Location:
trunk/Source/WebKit2
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit2/ChangeLog

    r198913 r198914  
     12016-03-31  Timothy Hatcher  <timothy@apple.com>
     2
     3        Web Automation: Navigation commands should not return until page loads or fails
     4
     5        https://bugs.webkit.org/show_bug.cgi?id=156063
     6        rdar://problem/25464373
     7
     8        Reviewed by Brian Burg.
     9
     10        * UIProcess/Automation/Automation.json: Make navigation commands async.
     11        * UIProcess/Automation/WebAutomationSession.cpp:
     12        (WebKit::WebAutomationSession::navigateBrowsingContext): Save callback and timeout previous.
     13        (WebKit::WebAutomationSession::goBackInBrowsingContext): Ditto.
     14        (WebKit::WebAutomationSession::goForwardInBrowsingContext): Ditto.
     15        (WebKit::WebAutomationSession::reloadBrowsingContext): Ditto.
     16        (WebKit::WebAutomationSession::navigationOccuredForPage): Added. Fire callback for page.
     17        * UIProcess/Automation/WebAutomationSession.h:
     18
     19        * UIProcess/WebPageProxy.cpp:
     20        (WebKit::WebPageProxy::didFinishLoadForFrame): Call WebAutomationSession::navigationOccuredForPage.
     21        (WebKit::WebPageProxy::didFailLoadForFrame): Ditto.
     22        (WebKit::WebPageProxy::didSameDocumentNavigationForFrame): Ditto.
     23
     24        * UIProcess/WebProcessPool.h: Added automationSession() getter.
     25
    1262016-03-30  Timothy Hatcher  <timothy@apple.com>
    227
  • trunk/Source/WebKit2/UIProcess/Automation/Automation.json

    r198913 r198914  
    4848            "enum": [
    4949                "InternalError",
     50                "Timeout",
    5051                "JavaScriptError",
    5152                "JavaScriptTimeout",
     
    251252                { "name": "handle", "$ref": "BrowsingContextHandle", "description": "The handle for the browsing context that should be navigated." },
    252253                { "name": "url", "type": "string", "description": "The URL to load in the browsing context." }
    253             ]
     254            ],
     255            "async": true
    254256        },
    255257        {
     
    258260            "parameters": [
    259261                { "name": "handle", "$ref": "BrowsingContextHandle", "description": "The handle for the browsing context that should be navigated." }
    260             ]
     262            ],
     263            "async": true
    261264        },
    262265        {
     
    265268            "parameters": [
    266269                { "name": "handle", "$ref": "BrowsingContextHandle", "description": "The handle for the browsing context that should be navigated." }
    267             ]
     270            ],
     271            "async": true
    268272        },
    269273        {
     
    272276            "parameters": [
    273277                { "name": "handle", "$ref": "BrowsingContextHandle", "description": "The handle for the browsing context that should be reloaded." }
    274             ]
     278            ],
     279            "async": true
    275280        },
    276281        {
  • trunk/Source/WebKit2/UIProcess/Automation/WebAutomationSession.cpp

    r198913 r198914  
    358358}
    359359
    360 void WebAutomationSession::navigateBrowsingContext(Inspector::ErrorString& errorString, const String& handle, const String& url)
    361 {
    362     WebPageProxy* page = webPageProxyForHandle(handle);
    363     if (!page)
    364         FAIL_WITH_PREDEFINED_ERROR_MESSAGE(WindowNotFound);
     360void WebAutomationSession::navigateBrowsingContext(Inspector::ErrorString& errorString, const String& handle, const String& url, Ref<NavigateBrowsingContextCallback>&& callback)
     361{
     362    WebPageProxy* page = webPageProxyForHandle(handle);
     363    if (!page)
     364        FAIL_WITH_PREDEFINED_ERROR_MESSAGE(WindowNotFound);
     365
     366    if (auto callback = m_pendingNavigationInBrowsingContextCallbacksPerPage.take(page->pageID()))
     367        callback->sendFailure(Inspector::Protocol::getEnumConstantValue(Inspector::Protocol::Automation::ErrorMessage::Timeout));
     368    m_pendingNavigationInBrowsingContextCallbacksPerPage.set(page->pageID(), WTFMove(callback));
    365369
    366370    page->loadRequest(WebCore::URL(WebCore::URL(), url));
    367371}
    368372
    369 void WebAutomationSession::goBackInBrowsingContext(Inspector::ErrorString& errorString, const String& handle)
    370 {
    371     WebPageProxy* page = webPageProxyForHandle(handle);
    372     if (!page)
    373         FAIL_WITH_PREDEFINED_ERROR_MESSAGE(WindowNotFound);
     373void WebAutomationSession::goBackInBrowsingContext(Inspector::ErrorString& errorString, const String& handle, Ref<GoBackInBrowsingContextCallback>&& callback)
     374{
     375    WebPageProxy* page = webPageProxyForHandle(handle);
     376    if (!page)
     377        FAIL_WITH_PREDEFINED_ERROR_MESSAGE(WindowNotFound);
     378
     379    if (auto callback = m_pendingNavigationInBrowsingContextCallbacksPerPage.take(page->pageID()))
     380        callback->sendFailure(Inspector::Protocol::getEnumConstantValue(Inspector::Protocol::Automation::ErrorMessage::Timeout));
     381    m_pendingNavigationInBrowsingContextCallbacksPerPage.set(page->pageID(), WTFMove(callback));
    374382
    375383    page->goBack();
    376384}
    377385
    378 void WebAutomationSession::goForwardInBrowsingContext(Inspector::ErrorString& errorString, const String& handle)
    379 {
    380     WebPageProxy* page = webPageProxyForHandle(handle);
    381     if (!page)
    382         FAIL_WITH_PREDEFINED_ERROR_MESSAGE(WindowNotFound);
     386void WebAutomationSession::goForwardInBrowsingContext(Inspector::ErrorString& errorString, const String& handle, Ref<GoForwardInBrowsingContextCallback>&& callback)
     387{
     388    WebPageProxy* page = webPageProxyForHandle(handle);
     389    if (!page)
     390        FAIL_WITH_PREDEFINED_ERROR_MESSAGE(WindowNotFound);
     391
     392    if (auto callback = m_pendingNavigationInBrowsingContextCallbacksPerPage.take(page->pageID()))
     393        callback->sendFailure(Inspector::Protocol::getEnumConstantValue(Inspector::Protocol::Automation::ErrorMessage::Timeout));
     394    m_pendingNavigationInBrowsingContextCallbacksPerPage.set(page->pageID(), WTFMove(callback));
    383395
    384396    page->goForward();
    385397}
    386398
    387 void WebAutomationSession::reloadBrowsingContext(Inspector::ErrorString& errorString, const String& handle)
    388 {
    389     WebPageProxy* page = webPageProxyForHandle(handle);
    390     if (!page)
    391         FAIL_WITH_PREDEFINED_ERROR_MESSAGE(WindowNotFound);
     399void WebAutomationSession::reloadBrowsingContext(Inspector::ErrorString& errorString, const String& handle, Ref<ReloadBrowsingContextCallback>&& callback)
     400{
     401    WebPageProxy* page = webPageProxyForHandle(handle);
     402    if (!page)
     403        FAIL_WITH_PREDEFINED_ERROR_MESSAGE(WindowNotFound);
     404
     405    if (auto callback = m_pendingNavigationInBrowsingContextCallbacksPerPage.take(page->pageID()))
     406        callback->sendFailure(Inspector::Protocol::getEnumConstantValue(Inspector::Protocol::Automation::ErrorMessage::Timeout));
     407    m_pendingNavigationInBrowsingContextCallbacksPerPage.set(page->pageID(), WTFMove(callback));
    392408
    393409    const bool reloadFromOrigin = false;
    394410    const bool contentBlockersEnabled = true;
    395411    page->reload(reloadFromOrigin, contentBlockersEnabled);
     412}
     413
     414void WebAutomationSession::navigationOccurredForPage(const WebPageProxy& page)
     415{
     416    if (auto callback = m_pendingNavigationInBrowsingContextCallbacksPerPage.take(page.pageID()))
     417        callback->sendSuccess(InspectorObject::create());
    396418}
    397419
  • trunk/Source/WebKit2/UIProcess/Automation/WebAutomationSession.h

    r198913 r198914  
    8484    void setProcessPool(WebProcessPool*);
    8585
     86    void navigationOccurredForPage(const WebPageProxy&);
     87
    8688#if ENABLE(REMOTE_INSPECTOR)
    8789    // Inspector::RemoteAutomationTarget API
     
    100102    void resizeWindowOfBrowsingContext(Inspector::ErrorString&, const String& handle, const Inspector::InspectorObject& size) override;
    101103    void moveWindowOfBrowsingContext(Inspector::ErrorString&, const String& handle, const Inspector::InspectorObject& position) override;
    102     void navigateBrowsingContext(Inspector::ErrorString&, const String& handle, const String& url) override;
    103     void goBackInBrowsingContext(Inspector::ErrorString&, const String&) override;
    104     void goForwardInBrowsingContext(Inspector::ErrorString&, const String&) override;
    105     void reloadBrowsingContext(Inspector::ErrorString&, const String&) override;
     104    void navigateBrowsingContext(Inspector::ErrorString&, const String& handle, const String& url, Ref<NavigateBrowsingContextCallback>&&) override;
     105    void goBackInBrowsingContext(Inspector::ErrorString&, const String&, Ref<GoBackInBrowsingContextCallback>&&) override;
     106    void goForwardInBrowsingContext(Inspector::ErrorString&, const String&, Ref<GoForwardInBrowsingContextCallback>&&) override;
     107    void reloadBrowsingContext(Inspector::ErrorString&, const String&, Ref<ReloadBrowsingContextCallback>&&) override;
    106108    void evaluateJavaScriptFunction(Inspector::ErrorString&, const String& browsingContextHandle, const String* optionalFrameHandle, const String& function, const Inspector::InspectorArray& arguments, const bool* optionalExpectsImplicitCallbackArgument, const int* optionalCallbackTimeout, Ref<Inspector::AutomationBackendDispatcherHandler::EvaluateJavaScriptFunctionCallback>&&) override;
    107109    void performMouseInteraction(Inspector::ErrorString&, const String& handle, const Inspector::InspectorObject& requestedPosition, const String& mouseButton, const String& mouseInteraction, const Inspector::InspectorArray& keyModifiers, RefPtr<Inspector::Protocol::Automation::Point>& updatedPosition) override;
     
    168170    HashMap<String, uint64_t> m_handleWebFrameMap;
    169171
     172    HashMap<uint64_t, RefPtr<Inspector::BackendDispatcher::CallbackBase>> m_pendingNavigationInBrowsingContextCallbacksPerPage;
     173
    170174    uint64_t m_nextEvaluateJavaScriptCallbackID { 1 };
    171175    HashMap<uint64_t, RefPtr<Inspector::AutomationBackendDispatcherHandler::EvaluateJavaScriptFunctionCallback>> m_evaluateJavaScriptFunctionCallbacks;
  • trunk/Source/WebKit2/UIProcess/WebPageProxy.cpp

    r198901 r198914  
    7272#include "UserMediaPermissionRequestProxy.h"
    7373#include "WKContextPrivate.h"
     74#include "WebAutomationSession.h"
    7475#include "WebBackForwardList.h"
    7576#include "WebBackForwardListItem.h"
     
    31273128        m_pageLoadState.didFinishLoad(transaction);
    31283129
     3130    if (isMainFrame && m_controlledByAutomation) {
     3131        if (auto* automationSession = process().processPool().automationSession())
     3132            automationSession->navigationOccurredForPage(*this);
     3133    }
     3134
    31293135    frame->didFinishLoad();
    31303136
     
    31613167        m_pageLoadState.didFailLoad(transaction);
    31623168
     3169    if (isMainFrame && m_controlledByAutomation) {
     3170        if (auto* automationSession = process().processPool().automationSession())
     3171            automationSession->navigationOccurredForPage(*this);
     3172    }
     3173
    31633174    frame->didFailLoad();
    31643175
     
    31923203    if (isMainFrame)
    31933204        m_pageLoadState.didSameDocumentNavigation(transaction, url);
     3205
     3206    if (isMainFrame && m_controlledByAutomation) {
     3207        if (auto* automationSession = process().processPool().automationSession())
     3208            automationSession->navigationOccurredForPage(*this);
     3209    }
    31943210
    31953211    m_pageLoadState.clearPendingAPIRequestURL(transaction);
  • trunk/Source/WebKit2/UIProcess/WebProcessPool.h

    r198736 r198914  
    260260    void updateAutomationCapabilities() const;
    261261    void setAutomationSession(RefPtr<WebAutomationSession>&&);
     262    WebAutomationSession* automationSession() const { return m_automationSession.get(); }
    262263
    263264    // Defaults to false.
Note: See TracChangeset for help on using the changeset viewer.