Title: [197621] trunk/Source/WebKit2
Revision
197621
Author
[email protected]
Date
2016-03-05 16:40:09 -0800 (Sat, 05 Mar 2016)

Log 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.

Modified Paths

Diff

Modified: trunk/Source/WebKit2/ChangeLog (197620 => 197621)


--- trunk/Source/WebKit2/ChangeLog	2016-03-06 00:40:01 UTC (rev 197620)
+++ trunk/Source/WebKit2/ChangeLog	2016-03-06 00:40:09 UTC (rev 197621)
@@ -1,5 +1,45 @@
 2016-03-05  Timothy Hatcher  <[email protected]>
 
+        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.
+
+2016-03-05  Timothy Hatcher  <[email protected]>
+
         Rename Automation protocol methods to use "BrowsingContext" instead of "Window".
         Also flesh out the protocol commands more by adding switchToBrowsingContext
         and return a BrowsingContextHandle for createBrowsingContext.

Modified: trunk/Source/WebKit2/UIProcess/API/APIAutomationSessionClient.h (197620 => 197621)


--- trunk/Source/WebKit2/UIProcess/API/APIAutomationSessionClient.h	2016-03-06 00:40:01 UTC (rev 197620)
+++ trunk/Source/WebKit2/UIProcess/API/APIAutomationSessionClient.h	2016-03-06 00:40:09 UTC (rev 197621)
@@ -30,6 +30,7 @@
 
 namespace WebKit {
 class WebAutomationSession;
+class WebPageProxy;
 }
 
 namespace API {
@@ -40,7 +41,7 @@
 
     virtual String sessionIdentifier() const { return String(); }
     virtual void didDisconnectFromRemote(WebKit::WebAutomationSession*) { }
-    virtual void didRequestNewWindow(WebKit::WebAutomationSession*) { }
+    virtual WebKit::WebPageProxy* didRequestNewWindow(WebKit::WebAutomationSession*) { return nullptr; }
 };
 
 } // namespace API

Modified: trunk/Source/WebKit2/UIProcess/API/Cocoa/_WKAutomationSessionDelegate.h (197620 => 197621)


--- trunk/Source/WebKit2/UIProcess/API/Cocoa/_WKAutomationSessionDelegate.h	2016-03-06 00:40:01 UTC (rev 197620)
+++ trunk/Source/WebKit2/UIProcess/API/Cocoa/_WKAutomationSessionDelegate.h	2016-03-06 00:40:09 UTC (rev 197621)
@@ -28,12 +28,13 @@
 #if WK_API_ENABLED
 
 #import <Foundation/Foundation.h>
+#import <WebKit/WKBase.h>
 
 @class _WKAutomationSession;
 
 @protocol _WKAutomationSessionDelegate <NSObject>
 @optional
-- (void)_automationSessionDidRequestNewWindow:(_WKAutomationSession *)automationSession;
+- (WKPageRef)_automationSessionDidRequestNewWindow:(_WKAutomationSession *)automationSession;
 - (void)_automationSessionDidDisconnectFromRemote:(_WKAutomationSession *)automationSession;
 @end
 

Modified: trunk/Source/WebKit2/UIProcess/Automation/WebAutomationSession.cpp (197620 => 197621)


--- trunk/Source/WebKit2/UIProcess/Automation/WebAutomationSession.cpp	2016-03-06 00:40:01 UTC (rev 197620)
+++ trunk/Source/WebKit2/UIProcess/Automation/WebAutomationSession.cpp	2016-03-06 00:40:09 UTC (rev 197621)
@@ -28,8 +28,11 @@
 
 #include "APIAutomationSessionClient.h"
 #include "InspectorProtocolObjects.h"
+#include "WebProcessPool.h"
 #include <_javascript_Core/InspectorBackendDispatcher.h>
 #include <_javascript_Core/InspectorFrontendRouter.h>
+#include <WebCore/UUID.h>
+#include <wtf/HashMap.h>
 
 using namespace Inspector;
 
@@ -97,26 +100,92 @@
 
 #endif // ENABLE(REMOTE_INSPECTOR)
 
+WebPageProxy* WebAutomationSession::webPageProxyForHandle(const String& handle)
+{
+    auto iter = m_handleWebPageMap.find(handle);
+    if (iter == m_handleWebPageMap.end())
+        return nullptr;
+    return WebProcessProxy::webPage(iter->value);
+}
+
+String WebAutomationSession::handleForWebPageProxy(WebPageProxy* webPageProxy)
+{
+    auto iter = m_webPageHandleMap.find(webPageProxy->pageID());
+    if (iter != m_webPageHandleMap.end())
+        return iter->value;
+
+    String handle = WebCore::createCanonicalUUIDString().convertToASCIIUppercase();
+
+    auto firstAddResult = m_webPageHandleMap.add(webPageProxy->pageID(), handle);
+    RELEASE_ASSERT(firstAddResult.isNewEntry);
+
+    auto secondAddResult = m_handleWebPageMap.add(handle, webPageProxy->pageID());
+    RELEASE_ASSERT(secondAddResult.isNewEntry);
+
+    return handle;
+}
+
 // Inspector::AutomationBackendDispatcherHandler API
 
 void WebAutomationSession::getBrowsingContexts(Inspector::ErrorString& errorString, RefPtr<Inspector::Protocol::Array<Inspector::Protocol::Automation::BrowsingContext>>& contexts)
 {
-    FAIL_WITH_PREDEFINED_ERROR_MESSAGE(NotImplemented);
+    contexts = Inspector::Protocol::Array<Inspector::Protocol::Automation::BrowsingContext>::create();
+
+    for (auto& process : m_processPool->processes()) {
+        for (auto& page : process->pages()) {
+            if (!page->isControlledByAutomation())
+                continue;
+
+            String handle = handleForWebPageProxy(page);
+
+            auto browsingContext = Inspector::Protocol::Automation::BrowsingContext::create()
+                .setHandle(handleForWebPageProxy(page))
+                .setActive(m_activeBrowsingContextHandle == handle)
+                .release();
+
+            contexts->addItem(browsingContext.copyRef());
+        }
+    }
 }
 
 void WebAutomationSession::createBrowsingContext(Inspector::ErrorString& errorString, String* handle)
 {
-    FAIL_WITH_PREDEFINED_ERROR_MESSAGE(NotImplemented);
+    ASSERT(m_client);
+    if (!m_client)
+        FAIL_WITH_PREDEFINED_ERROR_MESSAGE(InternalError);
+
+    WebPageProxy* page = m_client->didRequestNewWindow(this);
+    if (!page)
+        FAIL_WITH_PREDEFINED_ERROR_MESSAGE(InternalError);
+
+    m_activeBrowsingContextHandle = *handle = handleForWebPageProxy(page);
 }
 
 void WebAutomationSession::closeBrowsingContext(Inspector::ErrorString& errorString, const String& handle)
 {
-    FAIL_WITH_PREDEFINED_ERROR_MESSAGE(NotImplemented);
+    WebPageProxy* page = webPageProxyForHandle(handle);
+    if (!page)
+        FAIL_WITH_PREDEFINED_ERROR_MESSAGE(WindowNotFound);
+
+    if (handle == m_activeBrowsingContextHandle)
+        m_activeBrowsingContextHandle = emptyString();
+
+    // FIXME: Verify this is enough. We still might want to go through the AutomationSessionClient
+    // to get closer to a user pressing the close button.
+    page->tryClose();
 }
 
 void WebAutomationSession::switchToBrowsingContext(Inspector::ErrorString& errorString, const String& handle)
 {
-    FAIL_WITH_PREDEFINED_ERROR_MESSAGE(NotImplemented);
+    WebPageProxy* page = webPageProxyForHandle(handle);
+    if (!page)
+        FAIL_WITH_PREDEFINED_ERROR_MESSAGE(WindowNotFound);
+
+    m_activeBrowsingContextHandle = handle;
+
+    // FIXME: Verify this is enough. We still might want to go through the AutomationSessionClient
+    // to get closer a user pressing focusing the window / page.
+    page->setFocus(true);
 }
 
 } // namespace WebKit

Modified: trunk/Source/WebKit2/UIProcess/Automation/WebAutomationSession.h (197620 => 197621)


--- trunk/Source/WebKit2/UIProcess/Automation/WebAutomationSession.h	2016-03-06 00:40:01 UTC (rev 197620)
+++ trunk/Source/WebKit2/UIProcess/Automation/WebAutomationSession.h	2016-03-06 00:40:09 UTC (rev 197621)
@@ -46,6 +46,8 @@
 namespace WebKit {
 
 class WebAutomationSessionClient;
+class WebPageProxy;
+class WebProcessPool;
 
 class WebAutomationSession final : public API::ObjectImpl<API::Object::Type::AutomationSession>
 #if ENABLE(REMOTE_INSPECTOR)
@@ -54,6 +56,9 @@
     , public Inspector::AutomationBackendDispatcherHandler
 {
 public:
+    typedef HashMap<uint64_t, String> WebPageHandleMap;
+    typedef HashMap<String, uint64_t> HandleWebPageMap;
+
     WebAutomationSession();
     ~WebAutomationSession();
 
@@ -62,6 +67,9 @@
     void setSessionIdentifier(const String& sessionIdentifier) { m_sessionIdentifier = sessionIdentifier; }
     String sessionIdentifier() const { return m_sessionIdentifier; }
 
+    WebKit::WebProcessPool* processPool() const { return m_processPool; }
+    void setProcessPool(WebKit::WebProcessPool* processPool) { m_processPool = processPool; }
+
 #if ENABLE(REMOTE_INSPECTOR)
     // Inspector::RemoteAutomationTarget API
     String name() const override { return m_sessionIdentifier; }
@@ -77,12 +85,20 @@
     void switchToBrowsingContext(Inspector::ErrorString&, const String&) override;
 
 private:
+    WebKit::WebPageProxy* webPageProxyForHandle(const String&);
+    String handleForWebPageProxy(WebKit::WebPageProxy*);
+
+    WebKit::WebProcessPool* m_processPool { nullptr };
     std::unique_ptr<API::AutomationSessionClient> m_client;
     String m_sessionIdentifier { ASCIILiteral("Untitled Session") };
     Ref<Inspector::FrontendRouter> m_frontendRouter;
     Ref<Inspector::BackendDispatcher> m_backendDispatcher;
     Ref<Inspector::AutomationBackendDispatcher> m_domainDispatcher;
 
+    WebPageHandleMap m_webPageHandleMap;
+    HandleWebPageMap m_handleWebPageMap;
+    String m_activeBrowsingContextHandle;
+
 #if ENABLE(REMOTE_INSPECTOR)
     Inspector::FrontendChannel* m_remoteChannel { nullptr };
 #endif

Modified: trunk/Source/WebKit2/UIProcess/Cocoa/AutomationSessionClient.h (197620 => 197621)


--- trunk/Source/WebKit2/UIProcess/Cocoa/AutomationSessionClient.h	2016-03-06 00:40:01 UTC (rev 197620)
+++ trunk/Source/WebKit2/UIProcess/Cocoa/AutomationSessionClient.h	2016-03-06 00:40:09 UTC (rev 197621)
@@ -43,7 +43,7 @@
 
 private:
     // From API::AutomationSessionClient
-    void didRequestNewWindow(WebKit::WebAutomationSession*) override;
+    WebPageProxy* didRequestNewWindow(WebKit::WebAutomationSession*) override;
     void didDisconnectFromRemote(WebKit::WebAutomationSession *) override;
 
     WeakObjCPtr<id <_WKAutomationSessionDelegate>> m_delegate;

Modified: trunk/Source/WebKit2/UIProcess/Cocoa/AutomationSessionClient.mm (197620 => 197621)


--- trunk/Source/WebKit2/UIProcess/Cocoa/AutomationSessionClient.mm	2016-03-06 00:40:01 UTC (rev 197620)
+++ trunk/Source/WebKit2/UIProcess/Cocoa/AutomationSessionClient.mm	2016-03-06 00:40:09 UTC (rev 197621)
@@ -28,7 +28,9 @@
 
 #if WK_API_ENABLED
 
+#import "WKSharedAPICast.h"
 #import "WebAutomationSession.h"
+#import "WebPageProxy.h"
 #import "_WKAutomationSessionDelegate.h"
 #import "_WKAutomationSessionInternal.h"
 
@@ -41,10 +43,11 @@
     m_delegateMethods.didDisconnectFromRemote = [delegate respondsToSelector:@selector(_automationSessionDidDisconnectFromRemote:)];
 }
 
-void AutomationSessionClient::didRequestNewWindow(WebAutomationSession* session)
+WebPageProxy* AutomationSessionClient::didRequestNewWindow(WebAutomationSession* session)
 {
     if (m_delegateMethods.didRequestNewWindow)
-        [m_delegate.get() _automationSessionDidRequestNewWindow:wrapper(*session)];
+        return toImpl([m_delegate.get() _automationSessionDidRequestNewWindow:wrapper(*session)]);
+    return nullptr;
 }
 
 void AutomationSessionClient::didDisconnectFromRemote(WebAutomationSession* session)

Modified: trunk/Source/WebKit2/UIProcess/WebPageProxy.h (197620 => 197621)


--- trunk/Source/WebKit2/UIProcess/WebPageProxy.h	2016-03-06 00:40:01 UTC (rev 197620)
+++ trunk/Source/WebKit2/UIProcess/WebPageProxy.h	2016-03-06 00:40:09 UTC (rev 197621)
@@ -1090,6 +1090,8 @@
 
     void didRestoreScrollPosition();
 
+    void setFocus(bool focused);
+
 private:
     WebPageProxy(PageClient&, WebProcessProxy&, uint64_t pageID, Ref<API::PageConfiguration>&&);
     void platformInitialize();
@@ -1326,7 +1328,6 @@
     void ignoreWord(const String& word);
     void requestCheckingOfString(uint64_t requestID, const WebCore::TextCheckingRequestData&);
 
-    void setFocus(bool focused);
     void takeFocus(uint32_t direction);
     void setToolTip(const String&);
     void setCursor(const WebCore::Cursor&);

Modified: trunk/Source/WebKit2/UIProcess/WebProcessPool.cpp (197620 => 197621)


--- trunk/Source/WebKit2/UIProcess/WebProcessPool.cpp	2016-03-06 00:40:01 UTC (rev 197620)
+++ trunk/Source/WebKit2/UIProcess/WebProcessPool.cpp	2016-03-06 00:40:09 UTC (rev 197621)
@@ -1120,8 +1120,10 @@
     m_automationSession = WTFMove(automationSession);
 
 #if ENABLE(REMOTE_INSPECTOR)
-    if (m_automationSession)
+    if (m_automationSession) {
         m_automationSession->init();
+        m_automationSession->setProcessPool(this);
+    }
 #endif
 }
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to