Changeset 198760 in webkit


Ignore:
Timestamp:
Mar 28, 2016 3:34:44 PM (8 years ago)
Author:
BJ Burg
Message:

Web Automation: add commands to move and resize a browsing context's window
https://bugs.webkit.org/show_bug.cgi?id=155349
<rdar://problem/25104911>

Reviewed by Timothy Hatcher.

Parse the new origin or size and request the window to change to the
new frame. This calls through to PageUIClient::setWindowFrame().

  • UIProcess/Automation/Automation.json:

Add new enum values for protocol parsing error cases.
Add new commands.

  • UIProcess/Automation/WebAutomationSession.cpp:

(WebKit::WebAutomationSession::resizeWindowOfBrowsingContext):
(WebKit::WebAutomationSession::moveWindowOfBrowsingContext):
Added. Parse the incoming payload and bail if nothing would happen
or the values are not usable or out of range. Complain if a change
did not happen when the requested and actual size are different.

  • UIProcess/Automation/WebAutomationSession.h:
  • UIProcess/WebPageProxy.h: Move setWindowFrame to be public.
Location:
trunk/Source/WebKit2
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit2/ChangeLog

    r198759 r198760  
     12016-03-28  Brian Burg  <bburg@apple.com>
     2
     3        Web Automation: add commands to move and resize a browsing context's window
     4        https://bugs.webkit.org/show_bug.cgi?id=155349
     5        <rdar://problem/25104911>
     6
     7        Reviewed by Timothy Hatcher.
     8
     9        Parse the new origin or size and request the window to change to the
     10        new frame. This calls through to PageUIClient::setWindowFrame().
     11
     12        * UIProcess/Automation/Automation.json:
     13        Add new enum values for protocol parsing error cases.
     14        Add new commands.
     15
     16        * UIProcess/Automation/WebAutomationSession.cpp:
     17        (WebKit::WebAutomationSession::resizeWindowOfBrowsingContext):
     18        (WebKit::WebAutomationSession::moveWindowOfBrowsingContext):
     19        Added. Parse the incoming payload and bail if nothing would happen
     20        or the values are not usable or out of range. Complain if a change
     21        did not happen when the requested and actual size are different.
     22
     23        * UIProcess/Automation/WebAutomationSession.h:
     24        * UIProcess/WebPageProxy.h: Move setWindowFrame to be public.
     25
    1262016-03-28  Brian Burg  <bburg@apple.com>
    227
  • trunk/Source/WebKit2/UIProcess/Automation/Automation.json

    r198759 r198760  
    5454                "NoJavaScriptDialog",
    5555                "NotImplemented",
    56                 "MissingParameter"
     56                "MissingParameter",
     57                "InvalidParameter"
    5758            ]
    5859        },
     
    111112        },
    112113        {
     114            "name": "resizeWindowOfBrowsingContext",
     115            "description": "Resizes the window of the specified browsing context to the specified size.",
     116            "parameters": [
     117                { "name": "handle", "$ref": "BrowsingContextHandle", "description": "The handle for the browsing context to be resized." },
     118                { "name": "size", "$ref": "Size", "description": "The new size for the browsing context's window." }
     119            ]
     120        },
     121        {
     122            "name": "moveWindowOfBrowsingContext",
     123            "description": "Moves the window of the specified browsing context to the specified position.",
     124            "parameters": [
     125                { "name": "handle", "$ref": "BrowsingContextHandle", "description": "The handle for the browsing context to be moved." },
     126                { "name": "origin", "$ref": "Point", "description": "The new origin for the browsing context's window. The position is interpreted in screen coordinate space, relative to the upper left corner of the screen." }
     127            ]
     128        },
     129        {
    113130            "name": "navigateBrowsingContext",
    114131            "description": "Navigates a browsing context to a specified URL.",
  • trunk/Source/WebKit2/UIProcess/Automation/WebAutomationSession.cpp

    r198759 r198760  
    283283}
    284284
     285void WebAutomationSession::resizeWindowOfBrowsingContext(Inspector::ErrorString& errorString, const String& handle, const Inspector::InspectorObject& sizeObject)
     286{
     287    // FIXME <rdar://problem/25094106>: Specify what parameter was missing or invalid and how.
     288    // This requires some changes to the other end's error handling. Right now it looks for an
     289    // exact error message match. We could stuff this into the 'data' field on error object.
     290    float width;
     291    if (!sizeObject.getDouble(WTF::ASCIILiteral("width"), width))
     292        FAIL_WITH_PREDEFINED_ERROR_MESSAGE(MissingParameter);
     293
     294    float height;
     295    if (!sizeObject.getDouble(WTF::ASCIILiteral("height"), height))
     296        FAIL_WITH_PREDEFINED_ERROR_MESSAGE(MissingParameter);
     297
     298    if (width < 0 || height < 0)
     299        FAIL_WITH_PREDEFINED_ERROR_MESSAGE(InvalidParameter);
     300
     301    WebPageProxy* page = webPageProxyForHandle(handle);
     302    if (!page)
     303        FAIL_WITH_PREDEFINED_ERROR_MESSAGE(WindowNotFound);
     304
     305    WebCore::FloatRect originalFrame;
     306    page->getWindowFrame(originalFrame);
     307   
     308    WebCore::FloatRect newFrame = WebCore::FloatRect(originalFrame.location(), WebCore::FloatSize(width, height));
     309    if (newFrame == originalFrame)
     310        return;
     311
     312    page->setWindowFrame(newFrame);
     313   
     314    // If nothing changed at all, it's probably fair to report that something went wrong.
     315    // (We can't assume that the requested frame size will be honored exactly, however.)
     316    WebCore::FloatRect updatedFrame;
     317    page->getWindowFrame(updatedFrame);
     318    if (originalFrame == updatedFrame)
     319        FAIL_WITH_PREDEFINED_ERROR_MESSAGE(InternalError);
     320}
     321
     322void WebAutomationSession::moveWindowOfBrowsingContext(Inspector::ErrorString& errorString, const String& handle, const Inspector::InspectorObject& positionObject)
     323{
     324    // FIXME <rdar://problem/25094106>: Specify what parameter was missing or invalid and how.
     325    // This requires some changes to the other end's error handling. Right now it looks for an
     326    // exact error message match. We could stuff this into the 'data' field on error object.
     327    float x;
     328    if (!positionObject.getDouble(WTF::ASCIILiteral("x"), x))
     329        FAIL_WITH_PREDEFINED_ERROR_MESSAGE(MissingParameter);
     330
     331    float y;
     332    if (!positionObject.getDouble(WTF::ASCIILiteral("y"), y))
     333        FAIL_WITH_PREDEFINED_ERROR_MESSAGE(MissingParameter);
     334
     335    if (x < 0 || y < 0)
     336        FAIL_WITH_PREDEFINED_ERROR_MESSAGE(InvalidParameter);
     337
     338    WebPageProxy* page = webPageProxyForHandle(handle);
     339    if (!page)
     340        FAIL_WITH_PREDEFINED_ERROR_MESSAGE(WindowNotFound);
     341
     342    WebCore::FloatRect originalFrame;
     343    page->getWindowFrame(originalFrame);
     344   
     345    WebCore::FloatRect newFrame = WebCore::FloatRect(WebCore::FloatPoint(x, y), originalFrame.size());
     346    if (newFrame == originalFrame)
     347        return;
     348
     349    page->setWindowFrame(newFrame);
     350   
     351    // If nothing changed at all, it's probably fair to report that something went wrong.
     352    // (We can't assume that the requested frame size will be honored exactly, however.)
     353    WebCore::FloatRect updatedFrame;
     354    page->getWindowFrame(updatedFrame);
     355    if (originalFrame == updatedFrame)
     356        FAIL_WITH_PREDEFINED_ERROR_MESSAGE(InternalError);
     357}
     358
    285359void WebAutomationSession::navigateBrowsingContext(Inspector::ErrorString& errorString, const String& handle, const String& url)
    286360{
  • trunk/Source/WebKit2/UIProcess/Automation/WebAutomationSession.h

    r198754 r198760  
    8888    void closeBrowsingContext(Inspector::ErrorString&, const String&) override;
    8989    void switchToBrowsingContext(Inspector::ErrorString&, const String& browsingContextHandle, const String* optionalFrameHandle) override;
     90    void resizeWindowOfBrowsingContext(Inspector::ErrorString&, const String& handle, const Inspector::InspectorObject& size) override;
     91    void moveWindowOfBrowsingContext(Inspector::ErrorString&, const String& handle, const Inspector::InspectorObject& position) override;
    9092    void navigateBrowsingContext(Inspector::ErrorString&, const String& handle, const String& url) override;
    9193    void goBackInBrowsingContext(Inspector::ErrorString&, const String&) override;
  • trunk/Source/WebKit2/UIProcess/WebPageProxy.h

    r198754 r198760  
    10951095
    10961096    void setFocus(bool focused);
     1097    void setWindowFrame(const WebCore::FloatRect&);
    10971098    void getWindowFrame(WebCore::FloatRect&);
    10981099
     
    11991200    void setIsResizable(bool isResizable);
    12001201    void getIsResizable(bool& isResizable);
    1201     void setWindowFrame(const WebCore::FloatRect&);
    12021202    void screenToRootView(const WebCore::IntPoint& screenPoint, WebCore::IntPoint& windowPoint);
    12031203    void rootViewToScreen(const WebCore::IntRect& viewRect, WebCore::IntRect& result);
Note: See TracChangeset for help on using the changeset viewer.