Changeset 225501 in webkit


Ignore:
Timestamp:
Dec 4, 2017 4:06:25 PM (6 years ago)
Author:
BJ Burg
Message:

Web Automation: add flag to preserve legacy page screenshot behavior
https://bugs.webkit.org/show_bug.cgi?id=180313
<rdar://problem/34379930>

Reviewed by Joseph Pecoraro.

Source/WebDriver:

Set the clipToViewport flag to true when sending Automation.takeScreenshot.
This preserves the current behavior for this driver implementation.

  • Session.cpp:

(WebDriver::Session::takeScreenshot):

Source/WebKit:

For compatibility with JSON Wire Protocol implemented by Safari,
we need to retain the ability to perform whole page contents
snapshots using Automation.takeScreenshot. Add an extra flag,
clipToViewport, which can be used by W3C-conforming drivers.

  • UIProcess/Automation/Automation.json: Add new flag.
  • UIProcess/Automation/WebAutomationSession.h:
  • UIProcess/Automation/WebAutomationSession.cpp:

(WebKit::WebAutomationSession::takeScreenshot):

  • WebProcess/Automation/WebAutomationSessionProxy.h:
  • WebProcess/Automation/WebAutomationSessionProxy.messages.in:
  • WebProcess/Automation/WebAutomationSessionProxy.cpp:

(WebKit::snapshotRectForScreenshot):
(WebKit::WebAutomationSessionProxy::takeScreenshot):
If the flag is false, take a screenshot of the whole page contents.

Location:
trunk/Source
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebDriver/ChangeLog

    r225474 r225501  
     12017-12-04  Brian Burg  <bburg@apple.com>
     2
     3        Web Automation: add flag to preserve legacy page screenshot behavior
     4        https://bugs.webkit.org/show_bug.cgi?id=180313
     5        <rdar://problem/34379930>
     6
     7        Reviewed by Joseph Pecoraro.
     8
     9        Set the clipToViewport flag to true when sending Automation.takeScreenshot.
     10        This preserves the current behavior for this driver implementation.
     11
     12        * Session.cpp:
     13        (WebDriver::Session::takeScreenshot):
     14
    1152017-12-04  Carlos Garcia Campos  <cgarcia@igalia.com>
    216
  • trunk/Source/WebDriver/Session.cpp

    r225474 r225501  
    21242124        if (elementID)
    21252125            parameters->setString(ASCIILiteral("nodeHandle"), elementID.value());
     2126        else
     2127            parameters->setBoolean(ASCIILiteral("clipToViewport"), true);
    21262128        if (scrollIntoView.value_or(false))
    21272129            parameters->setBoolean(ASCIILiteral("scrollIntoViewIfNeeded"), true);
  • trunk/Source/WebKit/ChangeLog

    r225499 r225501  
     12017-12-04  Brian Burg  <bburg@apple.com>
     2
     3        Web Automation: add flag to preserve legacy page screenshot behavior
     4        https://bugs.webkit.org/show_bug.cgi?id=180313
     5        <rdar://problem/34379930>
     6
     7        Reviewed by Joseph Pecoraro.
     8
     9        For compatibility with JSON Wire Protocol implemented by Safari,
     10        we need to retain the ability to perform whole page contents
     11        snapshots using Automation.takeScreenshot. Add an extra flag,
     12        clipToViewport, which can be used by W3C-conforming drivers.
     13
     14        * UIProcess/Automation/Automation.json: Add new flag.
     15        * UIProcess/Automation/WebAutomationSession.h:
     16        * UIProcess/Automation/WebAutomationSession.cpp:
     17        (WebKit::WebAutomationSession::takeScreenshot):
     18        * WebProcess/Automation/WebAutomationSessionProxy.h:
     19        * WebProcess/Automation/WebAutomationSessionProxy.messages.in:
     20        * WebProcess/Automation/WebAutomationSessionProxy.cpp:
     21        (WebKit::snapshotRectForScreenshot):
     22        (WebKit::WebAutomationSessionProxy::takeScreenshot):
     23        If the flag is false, take a screenshot of the whole page contents.
     24
    1252017-12-04  JF Bastien  <jfbastien@apple.com>
    226
  • trunk/Source/WebKit/UIProcess/Automation/Automation.json

    r225448 r225501  
    416416                { "name": "frameHandle", "$ref": "FrameHandle", "optional": true, "description": "The handle for the frame that contains the element. The main frame is used if this parameter is empty string or excluded." },
    417417                { "name": "nodeHandle", "$ref": "NodeHandle", "optional": true, "description": "The handle of the element to take a screenshot of. The browsing context document element is used if this parameter is excluded." },
    418                 { "name": "scrollIntoViewIfNeeded", "type": "boolean", "optional": true, "description": "If the element should be scrolled into view before taking the screenshot." }
     418                { "name": "scrollIntoViewIfNeeded", "type": "boolean", "optional": true, "description": "If the element should be scrolled into view before taking the screenshot." },
     419                { "name": "clipToViewport", "type": "boolean", "optional": true, "description": "Whether a screenshot of the entire page should be clipped to the visual viewport. A value of 'false' preserves behavior for legacy protocol screenshots." }
    419420            ],
    420421            "returns": [
  • trunk/Source/WebKit/UIProcess/Automation/WebAutomationSession.cpp

    r225448 r225501  
    14501450}
    14511451
    1452 void WebAutomationSession::takeScreenshot(ErrorString& errorString, const String& handle, const String* optionalFrameHandle, const String* optionalNodeHandle, const bool* optionalScrollIntoViewIfNeeded, Ref<TakeScreenshotCallback>&& callback)
     1452void WebAutomationSession::takeScreenshot(ErrorString& errorString, const String& handle, const String* optionalFrameHandle, const String* optionalNodeHandle, const bool* optionalScrollIntoViewIfNeeded, const bool* optionalClipToViewport, Ref<TakeScreenshotCallback>&& callback)
    14531453{
    14541454    WebPageProxy* page = webPageProxyForHandle(handle);
     
    14621462    bool scrollIntoViewIfNeeded = optionalScrollIntoViewIfNeeded ? *optionalScrollIntoViewIfNeeded : false;
    14631463    String nodeHandle = optionalNodeHandle ? *optionalNodeHandle : emptyString();
     1464    bool clipToViewport = optionalClipToViewport ? *optionalClipToViewport : false;
    14641465
    14651466    uint64_t callbackID = m_nextScreenshotCallbackID++;
    14661467    m_screenshotCallbacks.set(callbackID, WTFMove(callback));
    14671468
    1468     page->process().send(Messages::WebAutomationSessionProxy::TakeScreenshot(page->pageID(), frameID.value(), nodeHandle, scrollIntoViewIfNeeded, callbackID), 0);
     1469    page->process().send(Messages::WebAutomationSessionProxy::TakeScreenshot(page->pageID(), frameID.value(), nodeHandle, scrollIntoViewIfNeeded, clipToViewport, callbackID), 0);
    14691470}
    14701471
  • trunk/Source/WebKit/UIProcess/Automation/WebAutomationSession.h

    r225425 r225501  
    133133    void performMouseInteraction(Inspector::ErrorString&, const String& handle, const JSON::Object& requestedPosition, const String& mouseButton, const String& mouseInteraction, const JSON::Array& keyModifiers, Ref<PerformMouseInteractionCallback>&&) final;
    134134    void performKeyboardInteractions(Inspector::ErrorString&, const String& handle, const JSON::Array& interactions, Ref<PerformKeyboardInteractionsCallback>&&) override;
    135     void takeScreenshot(Inspector::ErrorString&, const String& handle, const String* optionalFrameHandle, const String* optionalNodeHandle, const bool* optionalScrollIntoViewIfNeeded, Ref<TakeScreenshotCallback>&&) override;
     135    void takeScreenshot(Inspector::ErrorString&, const String& handle, const String* optionalFrameHandle, const String* optionalNodeHandle, const bool* optionalScrollIntoViewIfNeeded, const bool* optionalClipToViewport, Ref<TakeScreenshotCallback>&&) override;
    136136    void resolveChildFrameHandle(Inspector::ErrorString&, const String& browsingContextHandle, const String* optionalFrameHandle, const int* optionalOrdinal, const String* optionalName, const String* optionalNodeHandle, Ref<ResolveChildFrameHandleCallback>&&) override;
    137137    void resolveParentFrameHandle(Inspector::ErrorString&, const String& browsingContextHandle, const String& frameHandle, Ref<ResolveParentFrameHandleCallback>&&) override;
  • trunk/Source/WebKit/WebProcess/Automation/WebAutomationSessionProxy.cpp

    r225367 r225501  
    663663}
    664664
    665 static WebCore::IntRect snapshotRectForScreenshot(WebPage& page, WebCore::Element* element)
     665static WebCore::IntRect snapshotRectForScreenshot(WebPage& page, WebCore::Element* element, bool clipToViewport)
    666666{
    667667    if (element) {
     
    674674
    675675    if (auto* frameView = page.mainFrameView())
    676         return frameView->visibleContentRect();
     676        return clipToViewport ? frameView->visibleContentRect() : WebCore::IntRect(WebCore::IntPoint(0, 0), frameView->contentsSize());
    677677
    678678    return { };
    679679}
    680680
    681 void WebAutomationSessionProxy::takeScreenshot(uint64_t pageID, uint64_t frameID, String nodeHandle, bool scrollIntoViewIfNeeded, uint64_t callbackID)
     681void WebAutomationSessionProxy::takeScreenshot(uint64_t pageID, uint64_t frameID, String nodeHandle, bool scrollIntoViewIfNeeded, bool clipToViewport, uint64_t callbackID)
    682682{
    683683    ShareableBitmap::Handle handle;
     
    708708
    709709    String screenshotErrorType = Inspector::Protocol::AutomationHelpers::getEnumConstantValue(Inspector::Protocol::Automation::ErrorMessage::ScreenshotError);
    710     WebCore::IntRect snapshotRect = snapshotRectForScreenshot(*page, coreElement);
     710    WebCore::IntRect snapshotRect = snapshotRectForScreenshot(*page, coreElement, clipToViewport);
    711711    if (snapshotRect.isEmpty()) {
    712712        WebProcess::singleton().parentProcessConnection()->send(Messages::WebAutomationSession::DidTakeScreenshot(callbackID, handle, screenshotErrorType), 0);
  • trunk/Source/WebKit/WebProcess/Automation/WebAutomationSessionProxy.h

    r224789 r225501  
    6767    void computeElementLayout(uint64_t pageID, uint64_t frameID, String nodeHandle, bool scrollIntoViewIfNeeded, CoordinateSystem, uint64_t callbackID);
    6868    void selectOptionElement(uint64_t pageID, uint64_t frameID, String nodeHandle, uint64_t callbackID);
    69     void takeScreenshot(uint64_t pageID, uint64_t frameID, String nodeHandle, bool scrollIntoViewIfNeeded, uint64_t callbackID);
     69    void takeScreenshot(uint64_t pageID, uint64_t frameID, String nodeHandle, bool scrollIntoViewIfNeeded, bool clipToViewport, uint64_t callbackID);
    7070    void getCookiesForFrame(uint64_t pageID, uint64_t frameID, uint64_t callbackID);
    7171    void deleteCookie(uint64_t pageID, uint64_t frameID, String cookieName, uint64_t callbackID);
  • trunk/Source/WebKit/WebProcess/Automation/WebAutomationSessionProxy.messages.in

    r224789 r225501  
    3535    SelectOptionElement(uint64_t pageID, uint64_t frameID, String nodeHandle, uint64_t callbackID)
    3636
    37     TakeScreenshot(uint64_t pageID, uint64_t frameID, String nodeHandle, bool scrollIntoViewIfNeeded, uint64_t callbackID)
     37    TakeScreenshot(uint64_t pageID, uint64_t frameID, String nodeHandle, bool scrollIntoViewIfNeeded, bool clipToViewport, uint64_t callbackID)
    3838
    3939    GetCookiesForFrame(uint64_t pageID, uint64_t frameID, uint64_t callbackID)
Note: See TracChangeset for help on using the changeset viewer.