Web Automation: report the browsing context's window frame (size and origin)
authorbburg@apple.com <bburg@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 28 Mar 2016 18:52:12 +0000 (18:52 +0000)
committerbburg@apple.com <bburg@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 28 Mar 2016 18:52:12 +0000 (18:52 +0000)
https://bugs.webkit.org/show_bug.cgi?id=155323
<rdar://problem/25094089>

Reviewed by Timothy Hatcher.

To prepare for implementing resize and move commands, add a
windowFrame member to the browsing context protocol type.

* UIProcess/Automation/Automation.json:
Add a frame Rect to BrowsingContext.

* UIProcess/Automation/WebAutomationSession.cpp:
(WebKit::WebAutomationSession::handleForWebPageProxy):
(WebKit::WebAutomationSession::buildBrowsingContextForPage):
Extract the code to build a BrowsingContext object. Add
code to calculate and insert the page's window frame size.

(WebKit::WebAutomationSession::getBrowsingContexts):
(WebKit::WebAutomationSession::getBrowsingContext):
(WebKit::WebAutomationSession::createBrowsingContext):
(WebKit::WebAutomationSession::switchToBrowsingContext):
Refactoring as above.

* UIProcess/Automation/WebAutomationSession.h:
Adjust signatures.

* UIProcess/WebPageProxy.h: Make getWindowFrame public.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@198754 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebKit2/ChangeLog
Source/WebKit2/UIProcess/Automation/Automation.json
Source/WebKit2/UIProcess/Automation/WebAutomationSession.cpp
Source/WebKit2/UIProcess/Automation/WebAutomationSession.h
Source/WebKit2/UIProcess/WebPageProxy.h

index a745706..b4794cd 100644 (file)
@@ -1,5 +1,36 @@
 2016-03-28  Brian Burg  <bburg@apple.com>
 
+        Web Automation: report the browsing context's window frame (size and origin)
+        https://bugs.webkit.org/show_bug.cgi?id=155323
+        <rdar://problem/25094089>
+
+        Reviewed by Timothy Hatcher.
+
+        To prepare for implementing resize and move commands, add a
+        windowFrame member to the browsing context protocol type.
+
+        * UIProcess/Automation/Automation.json:
+        Add a frame Rect to BrowsingContext.
+
+        * UIProcess/Automation/WebAutomationSession.cpp:
+        (WebKit::WebAutomationSession::handleForWebPageProxy):
+        (WebKit::WebAutomationSession::buildBrowsingContextForPage):
+        Extract the code to build a BrowsingContext object. Add
+        code to calculate and insert the page's window frame size.
+
+        (WebKit::WebAutomationSession::getBrowsingContexts):
+        (WebKit::WebAutomationSession::getBrowsingContext):
+        (WebKit::WebAutomationSession::createBrowsingContext):
+        (WebKit::WebAutomationSession::switchToBrowsingContext):
+        Refactoring as above.
+
+        * UIProcess/Automation/WebAutomationSession.h:
+        Adjust signatures.
+
+        * UIProcess/WebPageProxy.h: Make getWindowFrame public.
+
+2016-03-28  Brian Burg  <bburg@apple.com>
+
         Unreviewed, fix the build.
 
         * WebProcess/Automation/WebAutomationSessionProxy.cpp:
index 91259ed..04e9b7a 100644 (file)
@@ -63,7 +63,8 @@
             "properties": [
                 { "name": "handle", "$ref": "BrowsingContextHandle", "description": "Opaque handle for a browsing context (window or tab). Used as a key for window-related commands." },
                 { "name": "active", "type": "boolean", "description": "Whether the browsing context has focus at the time the command is handled." },
-                { "name": "url", "type": "string", "description": "The URL loaded by the browsing context at the time the command is handled." }
+                { "name": "url", "type": "string", "description": "The URL loaded by the browsing context at the time the command is handled." },
+                { "name": "windowFrame", "$ref": "Rect", "description": "The current frame (position and size) of the browsing context's window." }
             ]
         }
     ],
index 1fc43be..ccbfd47 100644 (file)
@@ -190,24 +190,47 @@ String WebAutomationSession::handleForWebFrameProxy(const WebFrameProxy& webFram
     return handleForWebFrameID(webFrameProxy.frameID());
 }
 
+RefPtr<Inspector::Protocol::Automation::BrowsingContext> WebAutomationSession::buildBrowsingContextForPage(WebPageProxy& page)
+{
+    WebCore::FloatRect windowFrame;
+    page.getWindowFrame(windowFrame);
+
+    auto originObject = Inspector::Protocol::Automation::Point::create()
+        .setX(windowFrame.x())
+        .setY(windowFrame.y())
+        .release();
+
+    auto sizeObject = Inspector::Protocol::Automation::Size::create()
+        .setWidth(windowFrame.width())
+        .setHeight(windowFrame.height())
+        .release();
+
+    auto windowFrameObject = Inspector::Protocol::Automation::Rect::create()
+        .setOrigin(WTFMove(originObject))
+        .setSize(WTFMove(sizeObject))
+        .release();
+
+    String handle = handleForWebPageProxy(page);
+
+    return Inspector::Protocol::Automation::BrowsingContext::create()
+        .setHandle(handle)
+        .setActive(m_activeBrowsingContextHandle == handle)
+        .setUrl(page.pageLoadState().activeURL())
+        .setWindowFrame(WTFMove(windowFrameObject))
+        .release();
+}
+
 void WebAutomationSession::getBrowsingContexts(Inspector::ErrorString& errorString, RefPtr<Inspector::Protocol::Array<Inspector::Protocol::Automation::BrowsingContext>>& contexts)
 {
     contexts = Inspector::Protocol::Array<Inspector::Protocol::Automation::BrowsingContext>::create();
 
     for (auto& process : m_processPool->processes()) {
-        for (auto& page : process->pages()) {
+        for (auto* page : process->pages()) {
+            ASSERT(page);
             if (!page->isControlledByAutomation())
                 continue;
 
-            String handle = handleForWebPageProxy(*page);
-
-            auto browsingContext = Inspector::Protocol::Automation::BrowsingContext::create()
-                .setHandle(handleForWebPageProxy(*page))
-                .setActive(m_activeBrowsingContextHandle == handle)
-                .setUrl(page->pageLoadState().activeURL())
-                .release();
-
-            contexts->addItem(browsingContext.copyRef());
+            contexts->addItem(buildBrowsingContextForPage(*page));
         }
     }
 }
@@ -218,11 +241,7 @@ void WebAutomationSession::getBrowsingContext(Inspector::ErrorString& errorStrin
     if (!page)
         FAIL_WITH_PREDEFINED_ERROR_MESSAGE(WindowNotFound);
 
-    context = Inspector::Protocol::Automation::BrowsingContext::create()
-        .setHandle(handleForWebPageProxy(*page))
-        .setActive(m_activeBrowsingContextHandle == handle)
-        .setUrl(page->pageLoadState().activeURL())
-        .release();
+    context = buildBrowsingContextForPage(*page);
 }
 
 void WebAutomationSession::createBrowsingContext(Inspector::ErrorString& errorString, String* handle)
index 6d8baa1..91fce60 100644 (file)
@@ -104,6 +104,7 @@ public:
 private:
     WebPageProxy* webPageProxyForHandle(const String&);
     String handleForWebPageProxy(const WebPageProxy&);
+    RefPtr<Inspector::Protocol::Automation::BrowsingContext> buildBrowsingContextForPage(WebPageProxy&);
 
     WebFrameProxy* webFrameProxyForHandle(const String&, WebPageProxy&);
     String handleForWebFrameID(uint64_t frameID);
index 414ebed..4336acf 100644 (file)
@@ -1094,6 +1094,7 @@ public:
     void didRestoreScrollPosition();
 
     void setFocus(bool focused);
+    void getWindowFrame(WebCore::FloatRect&);
 
     bool isResourceCachingDisabled() const { return m_isResourceCachingDisabled; }
     void setResourceCachingDisabled(bool);
@@ -1198,7 +1199,6 @@ private:
     void setIsResizable(bool isResizable);
     void getIsResizable(bool& isResizable);
     void setWindowFrame(const WebCore::FloatRect&);
-    void getWindowFrame(WebCore::FloatRect&);
     void screenToRootView(const WebCore::IntPoint& screenPoint, WebCore::IntPoint& windowPoint);
     void rootViewToScreen(const WebCore::IntRect& viewRect, WebCore::IntRect& result);
 #if PLATFORM(IOS)