Changeset 212115 in webkit
- Timestamp:
- Feb 10, 2017 9:25:36 AM (7 years ago)
- Location:
- trunk/Source/WebKit2
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebKit2/ChangeLog
r212097 r212115 1 2017-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 1 19 2017-02-09 Carlos Garcia Campos <cgarcia@igalia.com> 2 20 -
trunk/Source/WebKit2/UIProcess/Automation/WebAutomationSession.cpp
r210927 r212115 917 917 } 918 918 919 Stringbase64EncodedData = platformGetBase64EncodedPNGData(imageDataHandle);920 if ( base64EncodedData.isEmpty()) {919 std::optional<String> base64EncodedData = platformGetBase64EncodedPNGData(imageDataHandle); 920 if (!base64EncodedData) { 921 921 callback->sendFailure(STRING_FOR_PREDEFINED_ERROR_NAME(InternalError)); 922 922 return; 923 923 } 924 924 925 callback->sendSuccess(base64EncodedData );925 callback->sendSuccess(base64EncodedData.value()); 926 926 } 927 927 … … 943 943 944 944 #if !PLATFORM(COCOA) 945 StringWebAutomationSession::platformGetBase64EncodedPNGData(const ShareableBitmap::Handle&)945 std::optional<String> WebAutomationSession::platformGetBase64EncodedPNGData(const ShareableBitmap::Handle&) 946 946 { 947 947 return String(); -
trunk/Source/WebKit2/UIProcess/Automation/WebAutomationSession.h
r210927 r212115 168 168 void platformSimulateKeySequence(WebPageProxy&, const String&); 169 169 // Get base64 encoded PNG data from a bitmap. 170 StringplatformGetBase64EncodedPNGData(const ShareableBitmap::Handle&);170 std::optional<String> platformGetBase64EncodedPNGData(const ShareableBitmap::Handle&); 171 171 172 172 #if PLATFORM(MAC) -
trunk/Source/WebKit2/UIProcess/Automation/cocoa/WebAutomationSessionCocoa.mm
r210927 r212115 38 38 namespace WebKit { 39 39 40 StringWebAutomationSession::platformGetBase64EncodedPNGData(const ShareableBitmap::Handle& imageDataHandle)40 std::optional<String> WebAutomationSession::platformGetBase64EncodedPNGData(const ShareableBitmap::Handle& imageDataHandle) 41 41 { 42 42 RefPtr<ShareableBitmap> bitmap = ShareableBitmap::create(imageDataHandle, SharedMemory::Protection::ReadOnly); 43 if (!bitmap) 44 return std::nullopt; 45 43 46 RetainPtr<CGImageRef> cgImage = bitmap->makeCGImage(); 44 47 RetainPtr<NSMutableData> imageData = adoptNS([[NSMutableData alloc] init]); 45 48 RetainPtr<CGImageDestinationRef> destination = adoptCF(CGImageDestinationCreateWithData((CFMutableDataRef)imageData.get(), kUTTypePNG, 1, 0)); 46 49 if (!destination) 47 return String();50 return std::nullopt; 48 51 49 52 CGImageDestinationAddImage(destination.get(), cgImage.get(), 0); 50 53 CGImageDestinationFinalize(destination.get()); 51 54 52 return [imageData base64EncodedStringWithOptions:0];55 return String([imageData base64EncodedStringWithOptions:0]); 53 56 } 54 57
Note: See TracChangeset
for help on using the changeset viewer.