Changeset 212115 in webkit


Ignore:
Timestamp:
Feb 10, 2017 9:25:36 AM (7 years ago)
Author:
BJ Burg
Message:

Web Automation: fail gracefully when a screenshot cannot be encoded as base64
https://bugs.webkit.org/show_bug.cgi?id=168095
<rdar://problem/30297427>

Reviewed by Joseph Pecoraro.

Convert platformGetBase64EncodedPNGData to return a std::optional<String>.
Return nullopt if we can't create a screenshot or convert it to base64.

  • UIProcess/Automation/WebAutomationSession.cpp:

(WebKit::WebAutomationSession::didTakeScreenshot):
(WebKit::WebAutomationSession::platformGetBase64EncodedPNGData):

  • UIProcess/Automation/WebAutomationSession.h:
  • UIProcess/Automation/cocoa/WebAutomationSessionCocoa.mm:

(WebKit::WebAutomationSession::platformGetBase64EncodedPNGData):

Location:
trunk/Source/WebKit2
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit2/ChangeLog

    r212097 r212115  
     12017-02-10  Brian Burg  <bburg@apple.com>
     2
     3        Web Automation: fail gracefully when a screenshot cannot be encoded as base64
     4        https://bugs.webkit.org/show_bug.cgi?id=168095
     5        <rdar://problem/30297427>
     6
     7        Reviewed by Joseph Pecoraro.
     8
     9        Convert platformGetBase64EncodedPNGData to return a std::optional<String>.
     10        Return nullopt if we can't create a screenshot or convert it to base64.
     11
     12        * UIProcess/Automation/WebAutomationSession.cpp:
     13        (WebKit::WebAutomationSession::didTakeScreenshot):
     14        (WebKit::WebAutomationSession::platformGetBase64EncodedPNGData):
     15        * UIProcess/Automation/WebAutomationSession.h:
     16        * UIProcess/Automation/cocoa/WebAutomationSessionCocoa.mm:
     17        (WebKit::WebAutomationSession::platformGetBase64EncodedPNGData):
     18
    1192017-02-09  Carlos Garcia Campos  <cgarcia@igalia.com>
    220
  • trunk/Source/WebKit2/UIProcess/Automation/WebAutomationSession.cpp

    r210927 r212115  
    917917    }
    918918
    919     String base64EncodedData = platformGetBase64EncodedPNGData(imageDataHandle);
    920     if (base64EncodedData.isEmpty()) {
     919    std::optional<String> base64EncodedData = platformGetBase64EncodedPNGData(imageDataHandle);
     920    if (!base64EncodedData) {
    921921        callback->sendFailure(STRING_FOR_PREDEFINED_ERROR_NAME(InternalError));
    922922        return;
    923923    }
    924924
    925     callback->sendSuccess(base64EncodedData);
     925    callback->sendSuccess(base64EncodedData.value());
    926926}
    927927
     
    943943
    944944#if !PLATFORM(COCOA)
    945 String WebAutomationSession::platformGetBase64EncodedPNGData(const ShareableBitmap::Handle&)
     945std::optional<String> WebAutomationSession::platformGetBase64EncodedPNGData(const ShareableBitmap::Handle&)
    946946{
    947947    return String();
  • trunk/Source/WebKit2/UIProcess/Automation/WebAutomationSession.h

    r210927 r212115  
    168168    void platformSimulateKeySequence(WebPageProxy&, const String&);
    169169    // Get base64 encoded PNG data from a bitmap.
    170     String platformGetBase64EncodedPNGData(const ShareableBitmap::Handle&);
     170    std::optional<String> platformGetBase64EncodedPNGData(const ShareableBitmap::Handle&);
    171171
    172172#if PLATFORM(MAC)
  • trunk/Source/WebKit2/UIProcess/Automation/cocoa/WebAutomationSessionCocoa.mm

    r210927 r212115  
    3838namespace WebKit {
    3939
    40 String WebAutomationSession::platformGetBase64EncodedPNGData(const ShareableBitmap::Handle& imageDataHandle)
     40std::optional<String> WebAutomationSession::platformGetBase64EncodedPNGData(const ShareableBitmap::Handle& imageDataHandle)
    4141{
    4242    RefPtr<ShareableBitmap> bitmap = ShareableBitmap::create(imageDataHandle, SharedMemory::Protection::ReadOnly);
     43    if (!bitmap)
     44        return std::nullopt;
     45
    4346    RetainPtr<CGImageRef> cgImage = bitmap->makeCGImage();
    4447    RetainPtr<NSMutableData> imageData = adoptNS([[NSMutableData alloc] init]);
    4548    RetainPtr<CGImageDestinationRef> destination = adoptCF(CGImageDestinationCreateWithData((CFMutableDataRef)imageData.get(), kUTTypePNG, 1, 0));
    4649    if (!destination)
    47         return String();
     50        return std::nullopt;
    4851
    4952    CGImageDestinationAddImage(destination.get(), cgImage.get(), 0);
    5053    CGImageDestinationFinalize(destination.get());
    5154
    52     return [imageData base64EncodedStringWithOptions:0];
     55    return String([imageData base64EncodedStringWithOptions:0]);
    5356}
    5457
Note: See TracChangeset for help on using the changeset viewer.