Title: [212115] trunk/Source/WebKit2
- Revision
- 212115
- Author
- bb...@apple.com
- Date
- 2017-02-10 09:25:36 -0800 (Fri, 10 Feb 2017)
Log 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):
Modified Paths
Diff
Modified: trunk/Source/WebKit2/ChangeLog (212114 => 212115)
--- trunk/Source/WebKit2/ChangeLog 2017-02-10 16:50:57 UTC (rev 212114)
+++ trunk/Source/WebKit2/ChangeLog 2017-02-10 17:25:36 UTC (rev 212115)
@@ -1,3 +1,21 @@
+2017-02-10 Brian Burg <bb...@apple.com>
+
+ 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):
+
2017-02-09 Carlos Garcia Campos <cgar...@igalia.com>
Unreviewed. Fix GTK+ build with threaded compositor disabled.
Modified: trunk/Source/WebKit2/UIProcess/Automation/WebAutomationSession.cpp (212114 => 212115)
--- trunk/Source/WebKit2/UIProcess/Automation/WebAutomationSession.cpp 2017-02-10 16:50:57 UTC (rev 212114)
+++ trunk/Source/WebKit2/UIProcess/Automation/WebAutomationSession.cpp 2017-02-10 17:25:36 UTC (rev 212115)
@@ -916,13 +916,13 @@
return;
}
- String base64EncodedData = platformGetBase64EncodedPNGData(imageDataHandle);
- if (base64EncodedData.isEmpty()) {
+ std::optional<String> base64EncodedData = platformGetBase64EncodedPNGData(imageDataHandle);
+ if (!base64EncodedData) {
callback->sendFailure(STRING_FOR_PREDEFINED_ERROR_NAME(InternalError));
return;
}
- callback->sendSuccess(base64EncodedData);
+ callback->sendSuccess(base64EncodedData.value());
}
// Platform-dependent Implementation Stubs.
@@ -942,7 +942,7 @@
#endif // !PLATFORM(MAC)
#if !PLATFORM(COCOA)
-String WebAutomationSession::platformGetBase64EncodedPNGData(const ShareableBitmap::Handle&)
+std::optional<String> WebAutomationSession::platformGetBase64EncodedPNGData(const ShareableBitmap::Handle&)
{
return String();
}
Modified: trunk/Source/WebKit2/UIProcess/Automation/WebAutomationSession.h (212114 => 212115)
--- trunk/Source/WebKit2/UIProcess/Automation/WebAutomationSession.h 2017-02-10 16:50:57 UTC (rev 212114)
+++ trunk/Source/WebKit2/UIProcess/Automation/WebAutomationSession.h 2017-02-10 17:25:36 UTC (rev 212115)
@@ -167,7 +167,7 @@
// Simulates key presses to produce the codepoints in a string. One or more code points are delivered atomically at grapheme cluster boundaries.
void platformSimulateKeySequence(WebPageProxy&, const String&);
// Get base64 encoded PNG data from a bitmap.
- String platformGetBase64EncodedPNGData(const ShareableBitmap::Handle&);
+ std::optional<String> platformGetBase64EncodedPNGData(const ShareableBitmap::Handle&);
#if PLATFORM(MAC)
void sendSynthesizedEventsToPage(WebPageProxy&, NSArray *eventsToSend);
Modified: trunk/Source/WebKit2/UIProcess/Automation/cocoa/WebAutomationSessionCocoa.mm (212114 => 212115)
--- trunk/Source/WebKit2/UIProcess/Automation/cocoa/WebAutomationSessionCocoa.mm 2017-02-10 16:50:57 UTC (rev 212114)
+++ trunk/Source/WebKit2/UIProcess/Automation/cocoa/WebAutomationSessionCocoa.mm 2017-02-10 17:25:36 UTC (rev 212115)
@@ -37,19 +37,22 @@
namespace WebKit {
-String WebAutomationSession::platformGetBase64EncodedPNGData(const ShareableBitmap::Handle& imageDataHandle)
+std::optional<String> WebAutomationSession::platformGetBase64EncodedPNGData(const ShareableBitmap::Handle& imageDataHandle)
{
RefPtr<ShareableBitmap> bitmap = ShareableBitmap::create(imageDataHandle, SharedMemory::Protection::ReadOnly);
+ if (!bitmap)
+ return std::nullopt;
+
RetainPtr<CGImageRef> cgImage = bitmap->makeCGImage();
RetainPtr<NSMutableData> imageData = adoptNS([[NSMutableData alloc] init]);
RetainPtr<CGImageDestinationRef> destination = adoptCF(CGImageDestinationCreateWithData((CFMutableDataRef)imageData.get(), kUTTypePNG, 1, 0));
if (!destination)
- return String();
+ return std::nullopt;
CGImageDestinationAddImage(destination.get(), cgImage.get(), 0);
CGImageDestinationFinalize(destination.get());
- return [imageData base64EncodedStringWithOptions:0];
+ return String([imageData base64EncodedStringWithOptions:0]);
}
} // namespace WebKit
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes