Title: [264101] trunk
Revision
264101
Author
[email protected]
Date
2020-07-08 09:16:41 -0700 (Wed, 08 Jul 2020)

Log Message

[iOS] Sharing an <img> element with a base64-encoded URL shares the URL as raw text instead of an image
https://bugs.webkit.org/show_bug.cgi?id=214042
<rdar://problem/56669102>

Reviewed by Wenson Hsieh.

Source/WebCore:

* en.lproj/Localizable.strings:

Source/WebKit:

In the case where the <img> element that was the target when the share sheet was brought has its data encoded
as a base64 URL, we need to share the UIImage that was created as its snapshot as a file rather than the URL
to avoid a base64 string to be shared instead of the image data.

To support testing of this, we add a new optional WKShareSheet delegate to indicate that the share sheet will
show and the provided activity items, which we forward to a new optional WKUIDelegatePrivate delegate method.
API tests can thus be written to check the data provided to the share sheet.

* UIProcess/API/Cocoa/WKUIDelegatePrivate.h:
* UIProcess/Cocoa/WKShareSheet.h:
* UIProcess/Cocoa/WKShareSheet.mm:
(-[WKShareSheet presentWithShareDataArray:inRect:]):
* UIProcess/ios/WKActionSheetAssistant.h:
* UIProcess/ios/WKActionSheetAssistant.mm:
(-[WKActionSheetAssistant handleElementActionWithType:element:needsInteraction:]):
* UIProcess/ios/WKContentViewInteraction.mm:
(-[WKContentView shareSheet:willShowActivityItems:]):
(-[WKContentView actionSheetAssistant:shareElementWithURL:rect:]):
(-[WKContentView actionSheetAssistant:shareElementWithImage:rect:]):

Tools:

Add a test that loads a page with an <img> with its data encoded as a base64 URL, brings up the share sheet for it
and checks a single NSURL object is made available in the activity items.

* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
* TestWebKitAPI/Tests/ios/ShareSheetTests.mm: Added.
(-[ShareSheetObserver _webView:actionsForElement:defaultActions:]):
(-[ShareSheetObserver _webView:willShareActivityItems:]):
(TestWebKitAPI::showShareSheet):
(TestWebKitAPI::TEST):
* TestWebKitAPI/Tests/ios/img-with-base64-url.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (264100 => 264101)


--- trunk/Source/WebCore/ChangeLog	2020-07-08 15:48:24 UTC (rev 264100)
+++ trunk/Source/WebCore/ChangeLog	2020-07-08 16:16:41 UTC (rev 264101)
@@ -1,3 +1,13 @@
+2020-07-07  Antoine Quint  <[email protected]>
+
+        [iOS] Sharing an <img> element with a base64-encoded URL shares the URL as raw text instead of an image
+        https://bugs.webkit.org/show_bug.cgi?id=214042
+        <rdar://problem/56669102>
+
+        Reviewed by Wenson Hsieh.
+
+        * en.lproj/Localizable.strings:
+
 2020-07-08  Philippe Normand  <[email protected]>
 
         REGRESSION(r263836): [GStreamer] Debug ASSERT hits

Modified: trunk/Source/WebCore/en.lproj/Localizable.strings (264100 => 264101)


--- trunk/Source/WebCore/en.lproj/Localizable.strings	2020-07-08 15:48:24 UTC (rev 264100)
+++ trunk/Source/WebCore/en.lproj/Localizable.strings	2020-07-08 16:16:41 UTC (rev 264101)
@@ -712,6 +712,9 @@
 /* Title for Share context menu item. */
 "Share" = "Share";
 
+/* Default name for the file created for a shared image with no explicit name. */
+"Shared Image" = "Shared Image";
+
 /* Title for Share action button */
 "Share…" = "Share…";
 

Modified: trunk/Source/WebKit/ChangeLog (264100 => 264101)


--- trunk/Source/WebKit/ChangeLog	2020-07-08 15:48:24 UTC (rev 264100)
+++ trunk/Source/WebKit/ChangeLog	2020-07-08 16:16:41 UTC (rev 264101)
@@ -1,3 +1,31 @@
+2020-07-07  Antoine Quint  <[email protected]>
+
+        [iOS] Sharing an <img> element with a base64-encoded URL shares the URL as raw text instead of an image
+        https://bugs.webkit.org/show_bug.cgi?id=214042
+        <rdar://problem/56669102>
+
+        Reviewed by Wenson Hsieh.
+
+        In the case where the <img> element that was the target when the share sheet was brought has its data encoded
+        as a base64 URL, we need to share the UIImage that was created as its snapshot as a file rather than the URL
+        to avoid a base64 string to be shared instead of the image data.
+
+        To support testing of this, we add a new optional WKShareSheet delegate to indicate that the share sheet will
+        show and the provided activity items, which we forward to a new optional WKUIDelegatePrivate delegate method.
+        API tests can thus be written to check the data provided to the share sheet.
+
+        * UIProcess/API/Cocoa/WKUIDelegatePrivate.h:
+        * UIProcess/Cocoa/WKShareSheet.h:
+        * UIProcess/Cocoa/WKShareSheet.mm:
+        (-[WKShareSheet presentWithShareDataArray:inRect:]):
+        * UIProcess/ios/WKActionSheetAssistant.h:
+        * UIProcess/ios/WKActionSheetAssistant.mm:
+        (-[WKActionSheetAssistant handleElementActionWithType:element:needsInteraction:]):
+        * UIProcess/ios/WKContentViewInteraction.mm:
+        (-[WKContentView shareSheet:willShowActivityItems:]):
+        (-[WKContentView actionSheetAssistant:shareElementWithURL:rect:]):
+        (-[WKContentView actionSheetAssistant:shareElementWithImage:rect:]):
+
 2020-07-08  Philippe Normand  <[email protected]>
 
         [WPE][Qt] Deprecation warnings

Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/WKUIDelegatePrivate.h (264100 => 264101)


--- trunk/Source/WebKit/UIProcess/API/Cocoa/WKUIDelegatePrivate.h	2020-07-08 15:48:24 UTC (rev 264100)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/WKUIDelegatePrivate.h	2020-07-08 16:16:41 UTC (rev 264101)
@@ -147,6 +147,8 @@
 
 - (void)_webView:(WKWebView *)webView handleAutoplayEvent:(_WKAutoplayEvent)event withFlags:(_WKAutoplayEventFlags)flags WK_API_AVAILABLE(macos(10.13.4), ios(WK_IOS_TBA));
 
+- (void)_webView:(WKWebView *)webView willShareActivityItems:(NSArray *)activityItems WK_API_AVAILABLE(ios(WK_IOS_TBA));
+
 #if TARGET_OS_IPHONE
 
 - (BOOL)_webView:(WKWebView *)webView shouldIncludeAppLinkActionsForElement:(_WKActivatedElementInfo *)element WK_API_AVAILABLE(ios(9.0));

Modified: trunk/Source/WebKit/UIProcess/Cocoa/WKShareSheet.h (264100 => 264101)


--- trunk/Source/WebKit/UIProcess/Cocoa/WKShareSheet.h	2020-07-08 15:48:24 UTC (rev 264100)
+++ trunk/Source/WebKit/UIProcess/Cocoa/WKShareSheet.h	2020-07-08 16:16:41 UTC (rev 264101)
@@ -47,6 +47,7 @@
 @protocol WKShareSheetDelegate <NSObject>
 @optional
 - (void)shareSheetDidDismiss:(WKShareSheet *)shareSheet;
+- (void)shareSheet:(WKShareSheet *)shareSheet willShowActivityItems:(NSArray *)activityItems;
 @end
 
 #endif // PLATFORM(COCOA) && !PLATFORM(WATCHOS) && !PLATFORM(APPLETV)

Modified: trunk/Source/WebKit/UIProcess/Cocoa/WKShareSheet.mm (264100 => 264101)


--- trunk/Source/WebKit/UIProcess/Cocoa/WKShareSheet.mm	2020-07-08 15:48:24 UTC (rev 264100)
+++ trunk/Source/WebKit/UIProcess/Cocoa/WKShareSheet.mm	2020-07-08 16:16:41 UTC (rev 264101)
@@ -182,7 +182,10 @@
         popoverController.sourceRect = *rect;
     } else
         popoverController._centersPopoverIfSourceViewNotSet = YES;
-    
+
+    if ([_delegate respondsToSelector:@selector(shareSheet:willShowActivityItems:)])
+        [_delegate shareSheet:self willShowActivityItems:sharingItems];
+
     _presentationViewController = [UIViewController _viewControllerForFullScreenPresentationFromView:webView];
     [_presentationViewController presentViewController:_shareSheetViewController.get() animated:YES completion:nil];
 #endif

Modified: trunk/Source/WebKit/UIProcess/ios/WKActionSheetAssistant.h (264100 => 264101)


--- trunk/Source/WebKit/UIProcess/ios/WKActionSheetAssistant.h	2020-07-08 15:48:24 UTC (rev 264100)
+++ trunk/Source/WebKit/UIProcess/ios/WKActionSheetAssistant.h	2020-07-08 16:16:41 UTC (rev 264101)
@@ -70,6 +70,7 @@
 - (UITargetedPreview *)createTargetedContextMenuHintForActionSheetAssistant:(WKActionSheetAssistant *)assistant;
 - (void)removeContextMenuViewIfPossibleForActionSheetAssistant:(WKActionSheetAssistant *)assistant;
 #endif
+- (void)actionSheetAssistant:(WKActionSheetAssistant *)assistant shareElementWithImage:(UIImage *)image rect:(CGRect)boundingRect;
 
 @end
 

Modified: trunk/Source/WebKit/UIProcess/ios/WKActionSheetAssistant.mm (264100 => 264101)


--- trunk/Source/WebKit/UIProcess/ios/WKActionSheetAssistant.mm	2020-07-08 15:48:24 UTC (rev 264100)
+++ trunk/Source/WebKit/UIProcess/ios/WKActionSheetAssistant.mm	2020-07-08 16:16:41 UTC (rev 264101)
@@ -828,7 +828,10 @@
         [delegate actionSheetAssistant:self performAction:WebKit::SheetAction::SaveImage];
         break;
     case _WKElementActionTypeShare:
-        [delegate actionSheetAssistant:self shareElementWithURL:element.URL ?: element.imageURL rect:element.boundingRect];
+        if ([element.imageURL.scheme caseInsensitiveCompare:@"data"] == NSOrderedSame && element.image && [delegate respondsToSelector:@selector(actionSheetAssistant:shareElementWithImage:rect:)])
+            [delegate actionSheetAssistant:self shareElementWithImage:element.image rect:element.boundingRect];
+        else
+            [delegate actionSheetAssistant:self shareElementWithURL:element.URL ?: element.imageURL rect:element.boundingRect];
         break;
     default:
         ASSERT_NOT_REACHED();

Modified: trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm (264100 => 264101)


--- trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm	2020-07-08 15:48:24 UTC (rev 264100)
+++ trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm	2020-07-08 16:16:41 UTC (rev 264101)
@@ -6792,6 +6792,16 @@
     [_shareSheet setDelegate:nil];
     _shareSheet = nil;
 }
+
+- (void)shareSheet:(WKShareSheet *)shareSheet willShowActivityItems:(NSArray *)activityItems
+{
+    ASSERT(_shareSheet == shareSheet);
+
+    id <WKUIDelegatePrivate> uiDelegate = static_cast<id <WKUIDelegatePrivate>>([_webView UIDelegate]);
+    if ([uiDelegate respondsToSelector:@selector(_webView:willShareActivityItems:)])
+        [uiDelegate _webView:self.webView willShareActivityItems:activityItems];
+}
+
 #endif
 
 - (NSString *)inputLabelText
@@ -6908,9 +6918,17 @@
 {
     WebCore::ShareDataWithParsedURL shareData;
     shareData.url = { url };
-    [self _showShareSheet:shareData inRect: { [self convertRect:boundingRect toView:self.webView] } completionHandler:[] (bool success) { }];
+    [self _showShareSheet:shareData inRect: { [self convertRect:boundingRect toView:self.webView] } completionHandler:nil];
 }
 
+- (void)actionSheetAssistant:(WKActionSheetAssistant *)assistant shareElementWithImage:(UIImage *)image rect:(CGRect)boundingRect
+{
+    WebCore::ShareDataWithParsedURL shareData;
+    NSString* fileName = [NSString stringWithFormat:@"%@.png", (NSString*)WEB_UI_STRING("Shared Image", "Default name for the file created for a shared image with no explicit name.")];
+    shareData.files = { { fileName, WebCore::SharedBuffer::create(UIImagePNGRepresentation(image)) } };
+    [self _showShareSheet:shareData inRect: { [self convertRect:boundingRect toView:self.webView] } completionHandler:nil];
+}
+
 #if HAVE(APP_LINKS)
 - (BOOL)actionSheetAssistant:(WKActionSheetAssistant *)assistant shouldIncludeAppLinkActionsForElement:(_WKActivatedElementInfo *)element
 {

Modified: trunk/Tools/ChangeLog (264100 => 264101)


--- trunk/Tools/ChangeLog	2020-07-08 15:48:24 UTC (rev 264100)
+++ trunk/Tools/ChangeLog	2020-07-08 16:16:41 UTC (rev 264101)
@@ -1,3 +1,22 @@
+2020-07-07  Antoine Quint  <[email protected]>
+
+        [iOS] Sharing an <img> element with a base64-encoded URL shares the URL as raw text instead of an image
+        https://bugs.webkit.org/show_bug.cgi?id=214042
+        <rdar://problem/56669102>
+
+        Reviewed by Wenson Hsieh.
+
+        Add a test that loads a page with an <img> with its data encoded as a base64 URL, brings up the share sheet for it
+        and checks a single NSURL object is made available in the activity items.
+
+        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+        * TestWebKitAPI/Tests/ios/ShareSheetTests.mm: Added.
+        (-[ShareSheetObserver _webView:actionsForElement:defaultActions:]):
+        (-[ShareSheetObserver _webView:willShareActivityItems:]):
+        (TestWebKitAPI::showShareSheet):
+        (TestWebKitAPI::TEST):
+        * TestWebKitAPI/Tests/ios/img-with-base64-url.html: Added.
+
 2020-07-08  Philippe Normand  <[email protected]>
 
         [Flatpak SDK] Pre-start sccache server

Modified: trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj (264100 => 264101)


--- trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj	2020-07-08 15:48:24 UTC (rev 264100)
+++ trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj	2020-07-08 16:16:41 UTC (rev 264101)
@@ -488,6 +488,8 @@
 		6B9ABE122086952F00D75DE6 /* HTTPParsers.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6B9ABE112086952F00D75DE6 /* HTTPParsers.cpp */; };
 		6BF4A683239ED4CD00E2F45B /* LoggedInStatus.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6BF4A682239ED4CD00E2F45B /* LoggedInStatus.cpp */; };
 		6BFD294C1D5E6C1D008EC968 /* HashCountedSet.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7A38D7E51C752D5F004F157D /* HashCountedSet.cpp */; };
+		71E88C4124B5299C00665160 /* ShareSheetTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = 71E88C4024B5299C00665160 /* ShareSheetTests.mm */; };
+		71E88C4524B534B700665160 /* img-with-base64-url.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 71E88C4324B533EC00665160 /* img-with-base64-url.html */; };
 		725C3EF322058A5B007C36FC /* AdditionalSupportedImageTypes.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 725C3EF2220584BA007C36FC /* AdditionalSupportedImageTypes.html */; };
 		7283A9D022FA754900B21C7D /* img-with-rotated-image.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 7283A9CE22FA6BBE00B21C7D /* img-with-rotated-image.html */; };
 		7283A9D222FB1E0600B21C7D /* exif-orientation-8-llo.jpg in Copy Resources */ = {isa = PBXBuildFile; fileRef = 7283A9D122FB1D9700B21C7D /* exif-orientation-8-llo.jpg */; };
@@ -1394,6 +1396,7 @@
 				F4DEF6ED1E9B4DB60048EF61 /* image-in-link-and-input.html in Copy Resources */,
 				F45B63FB1F197F4A009D38B9 /* image-map.html in Copy Resources */,
 				3128A8152376413300D90D40 /* image.html in Copy Resources */,
+				71E88C4524B534B700665160 /* img-with-base64-url.html in Copy Resources */,
 				7283A9D022FA754900B21C7D /* img-with-rotated-image.html in Copy Resources */,
 				49897D6C241FE9E400ECF153 /* in-app-browser-privacy-local-file.html in Copy Resources */,
 				4971B1182451F29A0096994D /* incorrectCreateTableSchema.db in Copy Resources */,
@@ -2194,6 +2197,8 @@
 		6B4E861B2220A5520022F389 /* RegistrableDomain.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = RegistrableDomain.cpp; sourceTree = "<group>"; };
 		6B9ABE112086952F00D75DE6 /* HTTPParsers.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = HTTPParsers.cpp; sourceTree = "<group>"; };
 		6BF4A682239ED4CD00E2F45B /* LoggedInStatus.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = LoggedInStatus.cpp; sourceTree = "<group>"; };
+		71E88C4024B5299C00665160 /* ShareSheetTests.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ShareSheetTests.mm; sourceTree = "<group>"; };
+		71E88C4324B533EC00665160 /* img-with-base64-url.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "img-with-base64-url.html"; sourceTree = "<group>"; };
 		725C3EF2220584BA007C36FC /* AdditionalSupportedImageTypes.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = AdditionalSupportedImageTypes.html; sourceTree = "<group>"; };
 		7283A9CE22FA6BBE00B21C7D /* img-with-rotated-image.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "img-with-rotated-image.html"; sourceTree = "<group>"; };
 		7283A9D122FB1D9700B21C7D /* exif-orientation-8-llo.jpg */ = {isa = PBXFileReference; lastKnownFileType = image.jpeg; path = "exif-orientation-8-llo.jpg"; sourceTree = "<group>"; };
@@ -3463,6 +3468,7 @@
 				1C90420B2326E03C00BEF91E /* SelectionByWord.mm */,
 				9B4B5EA422DEBE19001E3D5A /* SelectionModifyByParagraphBoundary.mm */,
 				CE6E819F20A6935F00E2C80F /* SetTimeoutFunction.mm */,
+				71E88C4024B5299C00665160 /* ShareSheetTests.mm */,
 				4433A395208044130091ED57 /* SynchronousTimeoutTests.mm */,
 				F45E15742112CE6200307E82 /* TestInputDelegate.h */,
 				F45E15752112CE6200307E82 /* TestInputDelegate.mm */,
@@ -3807,6 +3813,7 @@
 			children = (
 				0F16BED72304A1D100B4A167 /* composited.html */,
 				CEDA12402437C9EA00C28A9E /* editable-region-composited-and-non-composited-overlap.html */,
+				71E88C4324B533EC00665160 /* img-with-base64-url.html */,
 				CE6D0EE22426B8ED002AD901 /* insert-text.html */,
 				A11E7D9F24A169E200026745 /* link-with-hover-menu.html */,
 				0F340777230382540060A1A0 /* overflow-scroll.html */,
@@ -5216,6 +5223,7 @@
 				7C83E0521D0A641800FEBCF3 /* SharedBuffer.cpp in Sources */,
 				A17991881E1C994E00A505ED /* SharedBuffer.mm in Sources */,
 				A179918B1E1CA24100A505ED /* SharedBufferTest.cpp in Sources */,
+				71E88C4124B5299C00665160 /* ShareSheetTests.mm in Sources */,
 				5CCB10E4213457E000AC5AF0 /* ShouldGoToBackForwardListItem.mm in Sources */,
 				7CCE7F141A411AE600447C4C /* ShouldKeepCurrentBackForwardListItemInList.cpp in Sources */,
 				37BCA61C1B596BA9002012CA /* ShouldOpenExternalURLsInNewWindowActions.mm in Sources */,

Added: trunk/Tools/TestWebKitAPI/Tests/ios/ShareSheetTests.mm (0 => 264101)


--- trunk/Tools/TestWebKitAPI/Tests/ios/ShareSheetTests.mm	                        (rev 0)
+++ trunk/Tools/TestWebKitAPI/Tests/ios/ShareSheetTests.mm	2020-07-08 16:16:41 UTC (rev 264101)
@@ -0,0 +1,108 @@
+/*
+ * Copyright (C) 2017 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import "config.h"
+#import "Test.h"
+
+#if PLATFORM(IOS_FAMILY) && !PLATFORM(MACCATALYST)
+
+#import "PlatformUtilities.h"
+#import "TestWKWebView.h"
+#import <WebKit/WKUIDelegatePrivate.h>
+#import <WebKit/WKWebViewPrivateForTesting.h>
+#import <WebKit/_WKActivatedElementInfo.h>
+#import <WebKit/_WKElementAction.h>
+#import <wtf/BlockPtr.h>
+
+@interface ShareSheetObserver : NSObject<WKUIDelegatePrivate>
+@property (nonatomic) BlockPtr<NSArray *(_WKActivatedElementInfo *, NSArray *)> presentationHandler;
+@property (nonatomic) BlockPtr<void(NSArray *)> activityItemsHandler;
+@end
+
+@implementation ShareSheetObserver
+
+- (NSArray *)_webView:(WKWebView *)webView actionsForElement:(_WKActivatedElementInfo *)element defaultActions:(NSArray<_WKElementAction *> *)defaultActions
+{
+    return _presentationHandler ? _presentationHandler(element, defaultActions) : defaultActions;
+}
+
+- (void)_webView:(WKWebView *)webView willShareActivityItems:(NSArray *)activityItems
+{
+    if (_activityItemsHandler)
+        _activityItemsHandler(activityItems);
+}
+
+@end
+
+namespace TestWebKitAPI {
+
+#if !PLATFORM(WATCHOS) && !PLATFORM(APPLETV)
+
+static void showShareSheet(WKWebView *webView, ShareSheetObserver *observer, CGPoint location)
+{
+    __block RetainPtr<_WKElementAction> copyAction;
+    __block RetainPtr<_WKActivatedElementInfo> copyElement;
+    __block bool done = false;
+    [observer setPresentationHandler:^(_WKActivatedElementInfo *element, NSArray *actions) {
+        copyElement = element;
+        for (_WKElementAction *action in actions) {
+            if (action.type == _WKElementActionTypeShare)
+                copyAction = action;
+        }
+        done = true;
+        return @[ copyAction.get() ];
+    }];
+    [webView _simulateLongPressActionAtLocation:location];
+    TestWebKitAPI::Util::run(&done);
+
+    EXPECT_TRUE(!!copyAction);
+    EXPECT_TRUE(!!copyElement);
+    [copyAction runActionWithElementInfo:copyElement.get()];
+}
+
+TEST(ShareSheetTests, ShareImgElementWithBase64URL)
+{
+    auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 500)]);
+    auto observer = adoptNS([[ShareSheetObserver alloc] init]);
+    [webView setUIDelegate:observer.get()];
+    [webView synchronouslyLoadTestPageNamed:@"img-with-base64-url"];
+
+    __block bool done = false;
+    [observer setActivityItemsHandler:^(NSArray *activityItems) {
+        EXPECT_EQ(1UL, activityItems.count);
+        NSURL *url = "" objectAtIndex:0];
+        EXPECT_WK_STREQ("Shared Image.png", url.lastPathComponent);
+        done = true;
+    }];
+
+    showShareSheet(webView.get(), observer.get(), CGPointMake(100, 100));
+    TestWebKitAPI::Util::run(&done);
+}
+
+#endif // !PLATFORM(WATCHOS) && !PLATFORM(APPLETV)
+
+} // namespace TestWebKitAPI
+
+#endif // PLATFORM(IOS_FAMILY) && !PLATFORM(MACCATALYST)

Added: trunk/Tools/TestWebKitAPI/Tests/ios/img-with-base64-url.html (0 => 264101)


--- trunk/Tools/TestWebKitAPI/Tests/ios/img-with-base64-url.html	                        (rev 0)
+++ trunk/Tools/TestWebKitAPI/Tests/ios/img-with-base64-url.html	2020-07-08 16:16:41 UTC (rev 264101)
@@ -0,0 +1,11 @@
+<script>
+
+const canvas = document.createElement("canvas");
+canvas.getContext("2d").fillRect(0, 0, canvas.width, canvas.height);
+
+const img = document.createElement("img");
+img.src = ""
+
+document.addEventListener("DOMContentLoaded", () => document.body.appendChild(img));
+
+</script>
\ No newline at end of file
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to