Changeset 197621 in webkit


Ignore:
Timestamp:
Mar 5, 2016 4:40:09 PM (8 years ago)
Author:
timothy@apple.com
Message:

Implement the Automation protocol commands by tracking WebPageProxy objects
that are controlled by automation and assigning them a UUID handle.

https://bugs.webkit.org/show_bug.cgi?id=154953
rdar://problem/24947489

Reviewed by Brian Burg.

  • UIProcess/API/APIAutomationSessionClient.h:

(API::AutomationSessionClient::didRequestNewWindow):
Return a WebPageProxy instead of void so it can be assigned a UUID handle.

  • UIProcess/API/Cocoa/_WKAutomationSessionDelegate.h:

Return a WKPageRef from _automationSessionDidRequestNewWindow:.

  • UIProcess/Automation/WebAutomationSession.cpp:

(WebKit::WebAutomationSession::webPageProxyForHandle):
(WebKit::WebAutomationSession::handleForWebPageProxy):
(WebKit::WebAutomationSession::getBrowsingContexts):
(WebKit::WebAutomationSession::createBrowsingContext):
(WebKit::WebAutomationSession::closeBrowsingContext):
(WebKit::WebAutomationSession::switchToBrowsingContext):

  • UIProcess/Automation/WebAutomationSession.h:

Added new methods and maps to track pages and handles.

  • UIProcess/Cocoa/AutomationSessionClient.h:
  • UIProcess/Cocoa/AutomationSessionClient.mm:

(WebKit::AutomationSessionClient::didRequestNewWindow):
Return a WebPageProxy from the WKPageRef.

  • UIProcess/WebPageProxy.h: Make setFocus public.
  • UIProcess/WebProcessPool.cpp:

(WebKit::WebProcessPool::setAutomationSession):
Set the WebProcessPool on the WebAutomationSession so it can be used to find
WebPageProxy objects controlled by automation.

Location:
trunk/Source/WebKit2
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit2/ChangeLog

    r197620 r197621  
     12016-03-05  Timothy Hatcher  <timothy@apple.com>
     2
     3        Implement the Automation protocol commands by tracking WebPageProxy objects
     4        that are controlled by automation and assigning them a UUID handle.
     5
     6        https://bugs.webkit.org/show_bug.cgi?id=154953
     7        rdar://problem/24947489
     8
     9        Reviewed by Brian Burg.
     10
     11        * UIProcess/API/APIAutomationSessionClient.h:
     12        (API::AutomationSessionClient::didRequestNewWindow):
     13        Return a WebPageProxy instead of void so it can be assigned a UUID handle.
     14
     15        * UIProcess/API/Cocoa/_WKAutomationSessionDelegate.h:
     16        Return a WKPageRef from _automationSessionDidRequestNewWindow:.
     17
     18        * UIProcess/Automation/WebAutomationSession.cpp:
     19        (WebKit::WebAutomationSession::webPageProxyForHandle):
     20        (WebKit::WebAutomationSession::handleForWebPageProxy):
     21        (WebKit::WebAutomationSession::getBrowsingContexts):
     22        (WebKit::WebAutomationSession::createBrowsingContext):
     23        (WebKit::WebAutomationSession::closeBrowsingContext):
     24        (WebKit::WebAutomationSession::switchToBrowsingContext):
     25
     26        * UIProcess/Automation/WebAutomationSession.h:
     27        Added new methods and maps to track pages and handles.
     28
     29        * UIProcess/Cocoa/AutomationSessionClient.h:
     30        * UIProcess/Cocoa/AutomationSessionClient.mm:
     31        (WebKit::AutomationSessionClient::didRequestNewWindow):
     32        Return a WebPageProxy from the WKPageRef.
     33
     34        * UIProcess/WebPageProxy.h: Make setFocus public.
     35
     36        * UIProcess/WebProcessPool.cpp:
     37        (WebKit::WebProcessPool::setAutomationSession):
     38        Set the WebProcessPool on the WebAutomationSession so it can be used to find
     39        WebPageProxy objects controlled by automation.
     40
    1412016-03-05  Timothy Hatcher  <timothy@apple.com>
    242
  • trunk/Source/WebKit2/UIProcess/API/APIAutomationSessionClient.h

    r196848 r197621  
    3131namespace WebKit {
    3232class WebAutomationSession;
     33class WebPageProxy;
    3334}
    3435
     
    4142    virtual String sessionIdentifier() const { return String(); }
    4243    virtual void didDisconnectFromRemote(WebKit::WebAutomationSession*) { }
    43     virtual void didRequestNewWindow(WebKit::WebAutomationSession*) { }
     44    virtual WebKit::WebPageProxy* didRequestNewWindow(WebKit::WebAutomationSession*) { return nullptr; }
    4445};
    4546
  • trunk/Source/WebKit2/UIProcess/API/Cocoa/_WKAutomationSessionDelegate.h

    r196848 r197621  
    2929
    3030#import <Foundation/Foundation.h>
     31#import <WebKit/WKBase.h>
    3132
    3233@class _WKAutomationSession;
     
    3435@protocol _WKAutomationSessionDelegate <NSObject>
    3536@optional
    36 - (void)_automationSessionDidRequestNewWindow:(_WKAutomationSession *)automationSession;
     37- (WKPageRef)_automationSessionDidRequestNewWindow:(_WKAutomationSession *)automationSession;
    3738- (void)_automationSessionDidDisconnectFromRemote:(_WKAutomationSession *)automationSession;
    3839@end
  • trunk/Source/WebKit2/UIProcess/Automation/WebAutomationSession.cpp

    r197620 r197621  
    2929#include "APIAutomationSessionClient.h"
    3030#include "InspectorProtocolObjects.h"
     31#include "WebProcessPool.h"
    3132#include <JavaScriptCore/InspectorBackendDispatcher.h>
    3233#include <JavaScriptCore/InspectorFrontendRouter.h>
     34#include <WebCore/UUID.h>
     35#include <wtf/HashMap.h>
    3336
    3437using namespace Inspector;
     
    98101#endif // ENABLE(REMOTE_INSPECTOR)
    99102
     103WebPageProxy* WebAutomationSession::webPageProxyForHandle(const String& handle)
     104{
     105    auto iter = m_handleWebPageMap.find(handle);
     106    if (iter == m_handleWebPageMap.end())
     107        return nullptr;
     108    return WebProcessProxy::webPage(iter->value);
     109}
     110
     111String WebAutomationSession::handleForWebPageProxy(WebPageProxy* webPageProxy)
     112{
     113    auto iter = m_webPageHandleMap.find(webPageProxy->pageID());
     114    if (iter != m_webPageHandleMap.end())
     115        return iter->value;
     116
     117    String handle = WebCore::createCanonicalUUIDString().convertToASCIIUppercase();
     118
     119    auto firstAddResult = m_webPageHandleMap.add(webPageProxy->pageID(), handle);
     120    RELEASE_ASSERT(firstAddResult.isNewEntry);
     121
     122    auto secondAddResult = m_handleWebPageMap.add(handle, webPageProxy->pageID());
     123    RELEASE_ASSERT(secondAddResult.isNewEntry);
     124
     125    return handle;
     126}
     127
    100128// Inspector::AutomationBackendDispatcherHandler API
    101129
    102130void WebAutomationSession::getBrowsingContexts(Inspector::ErrorString& errorString, RefPtr<Inspector::Protocol::Array<Inspector::Protocol::Automation::BrowsingContext>>& contexts)
    103131{
    104     FAIL_WITH_PREDEFINED_ERROR_MESSAGE(NotImplemented);
     132    contexts = Inspector::Protocol::Array<Inspector::Protocol::Automation::BrowsingContext>::create();
     133
     134    for (auto& process : m_processPool->processes()) {
     135        for (auto& page : process->pages()) {
     136            if (!page->isControlledByAutomation())
     137                continue;
     138
     139            String handle = handleForWebPageProxy(page);
     140
     141            auto browsingContext = Inspector::Protocol::Automation::BrowsingContext::create()
     142                .setHandle(handleForWebPageProxy(page))
     143                .setActive(m_activeBrowsingContextHandle == handle)
     144                .release();
     145
     146            contexts->addItem(browsingContext.copyRef());
     147        }
     148    }
    105149}
    106150
    107151void WebAutomationSession::createBrowsingContext(Inspector::ErrorString& errorString, String* handle)
    108152{
    109     FAIL_WITH_PREDEFINED_ERROR_MESSAGE(NotImplemented);
     153    ASSERT(m_client);
     154    if (!m_client)
     155        FAIL_WITH_PREDEFINED_ERROR_MESSAGE(InternalError);
     156
     157    WebPageProxy* page = m_client->didRequestNewWindow(this);
     158    if (!page)
     159        FAIL_WITH_PREDEFINED_ERROR_MESSAGE(InternalError);
     160
     161    m_activeBrowsingContextHandle = *handle = handleForWebPageProxy(page);
    110162}
    111163
    112164void WebAutomationSession::closeBrowsingContext(Inspector::ErrorString& errorString, const String& handle)
    113165{
    114     FAIL_WITH_PREDEFINED_ERROR_MESSAGE(NotImplemented);
     166    WebPageProxy* page = webPageProxyForHandle(handle);
     167    if (!page)
     168        FAIL_WITH_PREDEFINED_ERROR_MESSAGE(WindowNotFound);
     169
     170    if (handle == m_activeBrowsingContextHandle)
     171        m_activeBrowsingContextHandle = emptyString();
     172
     173    // FIXME: Verify this is enough. We still might want to go through the AutomationSessionClient
     174    // to get closer to a user pressing the close button.
     175    page->tryClose();
    115176}
    116177
    117178void WebAutomationSession::switchToBrowsingContext(Inspector::ErrorString& errorString, const String& handle)
    118179{
    119     FAIL_WITH_PREDEFINED_ERROR_MESSAGE(NotImplemented);
     180    WebPageProxy* page = webPageProxyForHandle(handle);
     181    if (!page)
     182        FAIL_WITH_PREDEFINED_ERROR_MESSAGE(WindowNotFound);
     183
     184    m_activeBrowsingContextHandle = handle;
     185
     186    // FIXME: Verify this is enough. We still might want to go through the AutomationSessionClient
     187    // to get closer a user pressing focusing the window / page.
     188    page->setFocus(true);
    120189}
    121190
  • trunk/Source/WebKit2/UIProcess/Automation/WebAutomationSession.h

    r197620 r197621  
    4747
    4848class WebAutomationSessionClient;
     49class WebPageProxy;
     50class WebProcessPool;
    4951
    5052class WebAutomationSession final : public API::ObjectImpl<API::Object::Type::AutomationSession>
     
    5557{
    5658public:
     59    typedef HashMap<uint64_t, String> WebPageHandleMap;
     60    typedef HashMap<String, uint64_t> HandleWebPageMap;
     61
    5762    WebAutomationSession();
    5863    ~WebAutomationSession();
     
    6267    void setSessionIdentifier(const String& sessionIdentifier) { m_sessionIdentifier = sessionIdentifier; }
    6368    String sessionIdentifier() const { return m_sessionIdentifier; }
     69
     70    WebKit::WebProcessPool* processPool() const { return m_processPool; }
     71    void setProcessPool(WebKit::WebProcessPool* processPool) { m_processPool = processPool; }
    6472
    6573#if ENABLE(REMOTE_INSPECTOR)
     
    7886
    7987private:
     88    WebKit::WebPageProxy* webPageProxyForHandle(const String&);
     89    String handleForWebPageProxy(WebKit::WebPageProxy*);
     90
     91    WebKit::WebProcessPool* m_processPool { nullptr };
    8092    std::unique_ptr<API::AutomationSessionClient> m_client;
    8193    String m_sessionIdentifier { ASCIILiteral("Untitled Session") };
     
    8395    Ref<Inspector::BackendDispatcher> m_backendDispatcher;
    8496    Ref<Inspector::AutomationBackendDispatcher> m_domainDispatcher;
     97
     98    WebPageHandleMap m_webPageHandleMap;
     99    HandleWebPageMap m_handleWebPageMap;
     100    String m_activeBrowsingContextHandle;
    85101
    86102#if ENABLE(REMOTE_INSPECTOR)
  • trunk/Source/WebKit2/UIProcess/Cocoa/AutomationSessionClient.h

    r197563 r197621  
    4444private:
    4545    // From API::AutomationSessionClient
    46     void didRequestNewWindow(WebKit::WebAutomationSession*) override;
     46    WebPageProxy* didRequestNewWindow(WebKit::WebAutomationSession*) override;
    4747    void didDisconnectFromRemote(WebKit::WebAutomationSession *) override;
    4848
  • trunk/Source/WebKit2/UIProcess/Cocoa/AutomationSessionClient.mm

    r196848 r197621  
    2929#if WK_API_ENABLED
    3030
     31#import "WKSharedAPICast.h"
    3132#import "WebAutomationSession.h"
     33#import "WebPageProxy.h"
    3234#import "_WKAutomationSessionDelegate.h"
    3335#import "_WKAutomationSessionInternal.h"
     
    4244}
    4345
    44 void AutomationSessionClient::didRequestNewWindow(WebAutomationSession* session)
     46WebPageProxy* AutomationSessionClient::didRequestNewWindow(WebAutomationSession* session)
    4547{
    4648    if (m_delegateMethods.didRequestNewWindow)
    47         [m_delegate.get() _automationSessionDidRequestNewWindow:wrapper(*session)];
     49        return toImpl([m_delegate.get() _automationSessionDidRequestNewWindow:wrapper(*session)]);
     50    return nullptr;
    4851}
    4952
  • trunk/Source/WebKit2/UIProcess/WebPageProxy.h

    r197564 r197621  
    10911091    void didRestoreScrollPosition();
    10921092
     1093    void setFocus(bool focused);
     1094
    10931095private:
    10941096    WebPageProxy(PageClient&, WebProcessProxy&, uint64_t pageID, Ref<API::PageConfiguration>&&);
     
    13271329    void requestCheckingOfString(uint64_t requestID, const WebCore::TextCheckingRequestData&);
    13281330
    1329     void setFocus(bool focused);
    13301331    void takeFocus(uint32_t direction);
    13311332    void setToolTip(const String&);
  • trunk/Source/WebKit2/UIProcess/WebProcessPool.cpp

    r197592 r197621  
    11211121
    11221122#if ENABLE(REMOTE_INSPECTOR)
    1123     if (m_automationSession)
     1123    if (m_automationSession) {
    11241124        m_automationSession->init();
     1125        m_automationSession->setProcessPool(this);
     1126    }
    11251127#endif
    11261128}
Note: See TracChangeset for help on using the changeset viewer.