Implement the Web Share API for mac
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 12 Sep 2018 00:57:58 +0000 (00:57 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 12 Sep 2018 00:57:58 +0000 (00:57 +0000)
https://bugs.webkit.org/show_bug.cgi?id=189443

Patch by Olivia Barnett <obarnett@apple.com> on 2018-09-11
Reviewed by Tim Horton.

Source/WebKit:

* Shared/WebPreferencesDefaultValues.h:
* UIProcess/API/Cocoa/WKWebView.mm:
(-[WKWebView shareSheetDidDismiss:]):
* UIProcess/API/Cocoa/WKWebViewInternal.h:
* UIProcess/API/mac/WKView.mm:
(-[WKView shareSheetDidDismiss:]):
* UIProcess/Cocoa/WebViewImpl.h:
* UIProcess/Cocoa/WebViewImpl.mm:
(WebKit::WebViewImpl::showShareSheet):
(WebKit::WebViewImpl::shareSheetDidDismiss):
Implemented function for WKShareSheetDelegate.

* UIProcess/Cocoa/WKShareSheet.h:
* UIProcess/Cocoa/WKShareSheet.mm:
(-[WKShareSheet initWithView:initWithView:]):
(-[WKShareSheet presentWithParameters:completionHandler:]):
(-[WKShareSheet sharingServicePicker:didChooseSharingService:]):
(-[WKShareSheet _cancel]):
(-[WKShareSheet dismiss]):
(-[WKShareSheet _dismissDisplayAnimated:]):
(-[WKShareSheet invokeShareSheetWithResolution:]):
(-[WKShareSheet initWithView:]): Deleted.
Added mac platform checks and share sheet functionality.

* UIProcess/mac/PageClientImplMac.h:
* UIProcess/mac/PageClientImplMac.mm:
(WebKit::PageClientImpl::showShareSheet):
Allows macos to invoke the system share sheet.

LayoutTests:

* platform/mac-wk2/fast/dom/navigator-detached-no-crash-expected.txt: Added.
* platform/mac-wk2/imported/w3c/web-platform-tests/web-share/idlharness.https-expected.txt: Added.
* platform/mac-wk2/imported/w3c/web-platform-tests/web-share/share-empty.https-expected.txt: Added.
* platform/mac-wk2/imported/w3c/web-platform-tests/web-share/share-securecontext.http-expected.txt: Added.
* platform/mac-wk2/imported/w3c/web-platform-tests/web-share/share-url-invalid.https-expected.txt: Added.
* platform/mac-wk2/imported/w3c/web-platform-tests/web-share/share-without-user-gesture.https-expected.txt: Added.
Updated test expectations.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@235925 268f45cc-cd09-0410-ab3c-d52691b4dbfc

19 files changed:
LayoutTests/ChangeLog
LayoutTests/platform/mac-highsierra/fast/dom/navigator-detached-no-crash-expected.txt
LayoutTests/platform/mac-wk2/fast/dom/navigator-detached-no-crash-expected.txt [new file with mode: 0644]
LayoutTests/platform/mac-wk2/imported/w3c/web-platform-tests/web-share/idlharness.https-expected.txt [new file with mode: 0644]
LayoutTests/platform/mac-wk2/imported/w3c/web-platform-tests/web-share/share-empty.https-expected.txt [new file with mode: 0644]
LayoutTests/platform/mac-wk2/imported/w3c/web-platform-tests/web-share/share-securecontext.http-expected.txt [new file with mode: 0644]
LayoutTests/platform/mac-wk2/imported/w3c/web-platform-tests/web-share/share-url-invalid.https-expected.txt [new file with mode: 0644]
LayoutTests/platform/mac-wk2/imported/w3c/web-platform-tests/web-share/share-without-user-gesture.https-expected.txt [new file with mode: 0644]
Source/WebKit/ChangeLog
Source/WebKit/Shared/WebPreferencesDefaultValues.h
Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm
Source/WebKit/UIProcess/API/Cocoa/WKWebViewInternal.h
Source/WebKit/UIProcess/Cocoa/WKShareSheet.h [moved from Source/WebKit/UIProcess/ios/forms/WKShareSheet.h with 84% similarity]
Source/WebKit/UIProcess/Cocoa/WKShareSheet.mm [moved from Source/WebKit/UIProcess/ios/forms/WKShareSheet.mm with 73% similarity]
Source/WebKit/UIProcess/Cocoa/WebViewImpl.h
Source/WebKit/UIProcess/Cocoa/WebViewImpl.mm
Source/WebKit/UIProcess/mac/PageClientImplMac.h
Source/WebKit/UIProcess/mac/PageClientImplMac.mm
Source/WebKit/WebKit.xcodeproj/project.pbxproj

index e4f6710..d1ff4f6 100644 (file)
@@ -1,3 +1,18 @@
+2018-09-11  Olivia Barnett  <obarnett@apple.com>
+
+        Implement the Web Share API for mac
+        https://bugs.webkit.org/show_bug.cgi?id=189443
+
+        Reviewed by Tim Horton.
+
+        * platform/mac-wk2/fast/dom/navigator-detached-no-crash-expected.txt: Added.
+        * platform/mac-wk2/imported/w3c/web-platform-tests/web-share/idlharness.https-expected.txt: Added.
+        * platform/mac-wk2/imported/w3c/web-platform-tests/web-share/share-empty.https-expected.txt: Added.
+        * platform/mac-wk2/imported/w3c/web-platform-tests/web-share/share-securecontext.http-expected.txt: Added.
+        * platform/mac-wk2/imported/w3c/web-platform-tests/web-share/share-url-invalid.https-expected.txt: Added.
+        * platform/mac-wk2/imported/w3c/web-platform-tests/web-share/share-without-user-gesture.https-expected.txt: Added.
+        Updated test expectations.
+
 2018-09-11  Myles C. Maxfield  <mmaxfield@apple.com>
 
         Unreviewed test fix after r235910
index d4b7071..d93add7 100644 (file)
@@ -1,3 +1,4 @@
+CONSOLE MESSAGE: Unhandled Promise Rejection: TypeError: Type error
 This tests that the navigator object of a deleted frame is disconnected properly. Accessing fields or methods shouldn't crash the browser. 
  Check Navigator
 navigator.appCodeName is OK
@@ -18,6 +19,7 @@ navigator.product is OK
 navigator.productSub is OK
 navigator.sendBeacon() threw err TypeError: Not enough arguments
 navigator.serviceWorker is OK
+navigator.share() is OK
 navigator.userAgent is OK
 navigator.vendor is OK
 navigator.vendorSub is OK
@@ -40,6 +42,7 @@ navigator.product is OK
 navigator.productSub is OK
 navigator.sendBeacon() threw err TypeError: Not enough arguments
 navigator.serviceWorker is OK
+navigator.share() is OK
 navigator.userAgent is OK
 navigator.vendor is OK
 navigator.vendorSub is OK
diff --git a/LayoutTests/platform/mac-wk2/fast/dom/navigator-detached-no-crash-expected.txt b/LayoutTests/platform/mac-wk2/fast/dom/navigator-detached-no-crash-expected.txt
new file mode 100644 (file)
index 0000000..6c99ccb
--- /dev/null
@@ -0,0 +1,53 @@
+CONSOLE MESSAGE: Unhandled Promise Rejection: TypeError: Not enough arguments
+CONSOLE MESSAGE: Unhandled Promise Rejection: TypeError: Type error
+This tests that the navigator object of a deleted frame is disconnected properly. Accessing fields or methods shouldn't crash the browser. 
+ Check Navigator
+navigator.appCodeName is OK
+navigator.appName is OK
+navigator.appVersion is OK
+navigator.cookieEnabled is OK
+navigator.credentials is OK
+navigator.getStorageUpdates() is OK
+navigator.javaEnabled() is OK
+navigator.language is OK
+navigator.languages is OK
+navigator.mediaCapabilities is OK
+navigator.mimeTypes is OK
+navigator.onLine is OK
+navigator.platform is OK
+navigator.plugins is OK
+navigator.product is OK
+navigator.productSub is OK
+navigator.requestMediaKeySystemAccess() is OK
+navigator.sendBeacon() threw err TypeError: Not enough arguments
+navigator.serviceWorker is OK
+navigator.share() is OK
+navigator.userAgent is OK
+navigator.vendor is OK
+navigator.vendorSub is OK
+navigator.webdriver is OK
+navigator.appCodeName is OK
+navigator.appName is OK
+navigator.appVersion is OK
+navigator.cookieEnabled is OK
+navigator.credentials is OK
+navigator.getStorageUpdates() is OK
+navigator.javaEnabled() is OK
+navigator.language is OK
+navigator.languages is OK
+navigator.mediaCapabilities is OK
+navigator.mimeTypes is OK
+navigator.onLine is OK
+navigator.platform is OK
+navigator.plugins is OK
+navigator.product is OK
+navigator.productSub is OK
+navigator.requestMediaKeySystemAccess() is OK
+navigator.sendBeacon() threw err TypeError: Not enough arguments
+navigator.serviceWorker is OK
+navigator.share() is OK
+navigator.userAgent is OK
+navigator.vendor is OK
+navigator.vendorSub is OK
+navigator.webdriver is OK
+
diff --git a/LayoutTests/platform/mac-wk2/imported/w3c/web-platform-tests/web-share/idlharness.https-expected.txt b/LayoutTests/platform/mac-wk2/imported/w3c/web-platform-tests/web-share/idlharness.https-expected.txt
new file mode 100644 (file)
index 0000000..2fff230
--- /dev/null
@@ -0,0 +1,7 @@
+
+PASS Test driver 
+PASS Navigator interface: operation share(ShareData) 
+PASS Unscopable handled correctly for share(ShareData) on Navigator 
+PASS Navigator interface: navigator must inherit property "share(ShareData)" with the proper type 
+PASS Navigator interface: calling share(ShareData) on navigator with too few arguments must throw TypeError 
+
diff --git a/LayoutTests/platform/mac-wk2/imported/w3c/web-platform-tests/web-share/share-empty.https-expected.txt b/LayoutTests/platform/mac-wk2/imported/w3c/web-platform-tests/web-share/share-empty.https-expected.txt
new file mode 100644 (file)
index 0000000..57d3291
--- /dev/null
@@ -0,0 +1,7 @@
+
+PASS share with no arguments (same as empty dictionary) 
+PASS share with an empty dictionary 
+PASS share with a undefined argument (same as empty dictionary) 
+PASS share with a null argument (same as empty dictionary) 
+PASS share with a dictionary containing only surplus fields 
+
diff --git a/LayoutTests/platform/mac-wk2/imported/w3c/web-platform-tests/web-share/share-securecontext.http-expected.txt b/LayoutTests/platform/mac-wk2/imported/w3c/web-platform-tests/web-share/share-securecontext.http-expected.txt
new file mode 100644 (file)
index 0000000..b39bcda
--- /dev/null
@@ -0,0 +1,3 @@
+
+FAIL navigator.share must be undefined in non-secure context assert_false: navigator has attribute 'share'. expected false got true
+
diff --git a/LayoutTests/platform/mac-wk2/imported/w3c/web-platform-tests/web-share/share-url-invalid.https-expected.txt b/LayoutTests/platform/mac-wk2/imported/w3c/web-platform-tests/web-share/share-url-invalid.https-expected.txt
new file mode 100644 (file)
index 0000000..0e90442
--- /dev/null
@@ -0,0 +1,3 @@
+
+PASS share with an invalid URL 
+
diff --git a/LayoutTests/platform/mac-wk2/imported/w3c/web-platform-tests/web-share/share-without-user-gesture.https-expected.txt b/LayoutTests/platform/mac-wk2/imported/w3c/web-platform-tests/web-share/share-without-user-gesture.https-expected.txt
new file mode 100644 (file)
index 0000000..1ddfa67
--- /dev/null
@@ -0,0 +1,3 @@
+
+PASS share without a user gesture 
+
index 3760210..951c54e 100644 (file)
@@ -1,3 +1,39 @@
+2018-09-11  Olivia Barnett  <obarnett@apple.com>
+
+        Implement the Web Share API for mac
+        https://bugs.webkit.org/show_bug.cgi?id=189443
+
+        Reviewed by Tim Horton.
+
+        * Shared/WebPreferencesDefaultValues.h:
+        * UIProcess/API/Cocoa/WKWebView.mm:
+        (-[WKWebView shareSheetDidDismiss:]):
+        * UIProcess/API/Cocoa/WKWebViewInternal.h:
+        * UIProcess/API/mac/WKView.mm:
+        (-[WKView shareSheetDidDismiss:]):
+        * UIProcess/Cocoa/WebViewImpl.h:
+        * UIProcess/Cocoa/WebViewImpl.mm:
+        (WebKit::WebViewImpl::showShareSheet):
+        (WebKit::WebViewImpl::shareSheetDidDismiss):
+        Implemented function for WKShareSheetDelegate.
+
+        * UIProcess/Cocoa/WKShareSheet.h:
+        * UIProcess/Cocoa/WKShareSheet.mm:
+        (-[WKShareSheet initWithView:initWithView:]):
+        (-[WKShareSheet presentWithParameters:completionHandler:]):
+        (-[WKShareSheet sharingServicePicker:didChooseSharingService:]):
+        (-[WKShareSheet _cancel]):
+        (-[WKShareSheet dismiss]):
+        (-[WKShareSheet _dismissDisplayAnimated:]):
+        (-[WKShareSheet invokeShareSheetWithResolution:]):
+        (-[WKShareSheet initWithView:]): Deleted.
+        Added mac platform checks and share sheet functionality.
+
+        * UIProcess/mac/PageClientImplMac.h:
+        * UIProcess/mac/PageClientImplMac.mm:
+        (WebKit::PageClientImpl::showShareSheet):
+        Allows macos to invoke the system share sheet.
+
 2018-09-07  Dean Jackson  <dino@apple.com>
 
         Add and expose Internal features from WebKit
index 3735777..84c0668 100644 (file)
@@ -84,7 +84,6 @@
 #define DEFAULT_TEXT_AREAS_ARE_RESIZABLE true
 #define DEFAULT_JAVASCRIPT_CAN_OPEN_WINDOWS_AUTOMATICALLY true
 #define DEFAULT_SHOULD_RESPECT_IMAGE_ORIENTATION false
-#define DEFAULT_WEB_SHARE_ENABLED false
 #define DEFAULT_PASSWORD_ECHO_ENABLED false
 #define DEFAULT_ALLOWS_INLINE_MEDIA_PLAYBACK true
 #define DEFAULT_ALLOWS_INLINE_MEDIA_PLAYBACK_AFTER_FULLSCREEN false
 
 #endif
 
-#if PLATFORM(IOS) && !PLATFORM(WATCHOS) && !PLATFORM(APPLETV)
+#if PLATFORM(COCOA) && !PLATFORM(WATCHOS) && !PLATFORM(APPLETV)
 #define DEFAULT_WEB_SHARE_ENABLED true
 #else
 #define DEFAULT_WEB_SHARE_ENABLED false
index 49e74d0..d07e72f 100644 (file)
@@ -5680,6 +5680,11 @@ static WebCore::UserInterfaceLayoutDirection toUserInterfaceLayoutDirection(UISe
     _impl->setWindowOcclusionDetectionEnabled(enabled);
 }
 
+- (void)shareSheetDidDismiss:(WKShareSheet *)shareSheet
+{
+    _impl->shareSheetDidDismiss(shareSheet);
+}
+
 - (void)_setOverrideDeviceScaleFactor:(CGFloat)deviceScaleFactor
 {
     _impl->setOverrideDeviceScaleFactor(deviceScaleFactor);
index 74e9a27..0a36728 100644 (file)
@@ -28,6 +28,7 @@
 #if WK_API_ENABLED
 
 #import "SameDocumentNavigationType.h"
+#import "WKShareSheet.h"
 #import "WKWebViewConfiguration.h"
 #import "_WKAttachmentInternal.h"
 #import "_WKWebViewPrintFormatterInternal.h"
 #define WK_WEB_VIEW_PROTOCOLS <UIScrollViewDelegate>
 #endif
 
+#if PLATFORM(MAC)
+#define WK_WEB_VIEW_PROTOCOLS <WKShareSheetDelegate>
+#endif
+
 #if !defined(WK_WEB_VIEW_PROTOCOLS)
 #define WK_WEB_VIEW_PROTOCOLS
 #endif
  * THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#if PLATFORM(IOS) && !PLATFORM(WATCHOS) && !PLATFORM(APPLETV)
+#import "WKAPICast.h"
+
+#if PLATFORM(COCOA) && !PLATFORM(WATCHOS) && !PLATFORM(APPLETV) && WK_API_ENABLED
 
-#import <UIKit/UIKit.h>
 #import <WebCore/ShareData.h>
 #import <wtf/BlockPtr.h>
 #import <wtf/Forward.h>
 #import <wtf/WeakObjCPtr.h>
 #import <wtf/text/WTFString.h>
 
+#if PLATFORM(IOS)
+#import <UIKit/UIKit.h>
+#else
+#import "WKWebView.h"
+#endif
+
 @class WKContentView;
 @protocol WKShareSheetDelegate;
 
-@interface WKShareSheet : UIViewController
+#if PLATFORM(MAC)
+@interface WKShareSheet : NSObject <NSSharingServicePickerDelegate>
+- (instancetype)initWithView:(WKWebView *)view;
+#else
+@interface WKShareSheet : NSObject
 - (instancetype)initWithView:(WKContentView *)view;
+#endif
 
 - (void)presentWithParameters:(const WebCore::ShareDataWithParsedURL&)data completionHandler:(WTF::CompletionHandler<void(bool)>&&)completionHandler;
 - (void)dismiss;
@@ -51,4 +63,4 @@
 - (void)shareSheetDidDismiss:(WKShareSheet *)shareSheet;
 @end
 
-#endif // PLATFORM(IOS) && !PLATFORM(WATCHOS) && !PLATFORM(APPLETV)
+#endif // !PLATFORM(WATCHOS) && !PLATFORM(APPLETV)
 #import "config.h"
 #import "WKShareSheet.h"
 
-#if PLATFORM(IOS) && !PLATFORM(WATCHOS) && !PLATFORM(APPLETV)
-#import "UIKitSPI.h"
+#if PLATFORM(COCOA) && !PLATFORM(WATCHOS) && !PLATFORM(APPLETV) && WK_API_ENABLED
+
 #import "WKContentViewInteraction.h"
 #import "WebPageProxy.h"
 #import <WebCore/ShareData.h>
 #import <wtf/RetainPtr.h>
 #import <wtf/WeakObjCPtr.h>
 
+#if PLATFORM(IOS)
+#import "UIKitSPI.h"
+#else
+#import "WKWebView.h"
+#endif
+
 using namespace WebKit;
 
 @implementation WKShareSheet {
-    WeakObjCPtr<WKContentView> _view;
+#if PLATFORM(MAC)
+    WeakObjCPtr<WKWebView> _view;
 
+    BOOL _isShowingSharingServicePicker;
+    RetainPtr<NSSharingServicePicker> _sharingServicePickerForMenu;
+    WTF::CompletionHandler<void(bool)> _completionHandler;
+#else
+    WeakObjCPtr<WKContentView> _view;
+    
     RetainPtr<UIActivityViewController> _shareSheetViewController;
     RetainPtr<UIViewController> _presentationViewController;
     BOOL _shouldDismissWithAnimation;
+#endif
 }
 
+#if PLATFORM(MAC)
+- (instancetype)initWithView:(WKWebView *)view
+#else
 - (instancetype)initWithView:(WKContentView *)view
+#endif
 {
     if (!(self = [super init]))
         return nil;
     _view = view;
+#if PLATFORM(IOS)
     _shouldDismissWithAnimation = YES;
+#endif
     return self;
 }
 
@@ -62,14 +82,27 @@ using namespace WebKit;
     
     if (!data.url.isNull()) {
         NSURL *url = (NSURL *)data.url;
+#if PLATFORM(IOS)
         if (!data.shareData.title.isEmpty())
             url._title = data.shareData.title;
+#endif
         [shareDataArray addObject:url];
     }
     
     if (!data.shareData.title.isEmpty() && ![shareDataArray count])
         [shareDataArray addObject:(NSString *)data.shareData.title];
     
+#if PLATFORM(MAC)
+    _sharingServicePickerForMenu = adoptNS([[NSSharingServicePicker alloc] initWithItems:shareDataArray.get()]);
+    _sharingServicePickerForMenu.get().delegate = self;
+    _completionHandler = WTFMove(completionHandler);
+    
+    NSPoint location = [NSEvent mouseLocation];
+    NSRect mouseLocationRect = NSMakeRect(location.x, location.y, 1.0, 1.0);
+    NSRect mouseLocationInWindow = [[_view window] convertRectFromScreen:mouseLocationRect];
+    NSRect mouseLocationInView = [_view convertRect:mouseLocationInWindow fromView:nil];
+    [_sharingServicePickerForMenu showRelativeToRect:mouseLocationInView ofView:_view.getAutoreleased() preferredEdge:NSMinYEdge];
+#else
     auto shareSheetController = adoptNS([[UIActivityViewController alloc] initWithActivityItems:shareDataArray.get() applicationActivities:nil]);
 
     auto completionHandlerBlock = BlockPtr<void((NSString *, BOOL completed, NSArray *, NSError *))>::fromCallable([completionHandler = WTFMove(completionHandler), shareSheet = self](NSString *, BOOL completed, NSArray *, NSError *) mutable {
@@ -80,8 +113,17 @@ using namespace WebKit;
     shareSheetController.get().completionWithItemsHandler = completionHandlerBlock.get();
     _shareSheetViewController = WTFMove(shareSheetController);
     [self _presentFullscreenViewController:_shareSheetViewController.get() animated:YES];
+#endif
+}
+
+#if PLATFORM(MAC)
+- (void)sharingServicePicker:(NSSharingServicePicker *)sharingServicePicker didChooseSharingService:(nullable NSSharingService *)service
+{
+    self->_completionHandler(!service);
+    [self _dispatchDidDismiss];
 }
 
+#endif
 - (void)_dispatchDidDismiss
 {
     if ([_delegate respondsToSelector:@selector(shareSheetDidDismiss:)])
@@ -90,22 +132,28 @@ using namespace WebKit;
 
 - (void)_cancel
 {
+#if PLATFORM(IOS)
     [self _dispatchDidDismiss];
+#endif
 }
 
 - (void)dismiss
 {
+#if PLATFORM(IOS)
     [[UIViewController _viewControllerForFullScreenPresentationFromView:_view.getAutoreleased()] dismissViewControllerAnimated:_shouldDismissWithAnimation completion:nil];
     _presentationViewController = nil;
     
     [self _cancel];
+#endif
 }
 
+#if PLATFORM(IOS)
+
 - (void)_dismissDisplayAnimated:(BOOL)animated
 {
     if (_presentationViewController) {
         UIViewController *currentPresentedViewController = [_presentationViewController presentedViewController];
-        if (currentPresentedViewController == self) {
+        if (currentPresentedViewController == _shareSheetViewController) {
             [currentPresentedViewController dismissViewControllerAnimated:animated completion:^{
                 _presentationViewController = nil;
             }];
@@ -118,12 +166,17 @@ using namespace WebKit;
     _presentationViewController = [UIViewController _viewControllerForFullScreenPresentationFromView:_view.getAutoreleased()];
     [_presentationViewController presentViewController:viewController animated:animated completion:nil];
 }
+#endif
 
 - (void)invokeShareSheetWithResolution:(BOOL)resolved
 {
+#if PLATFORM(IOS)
     _shouldDismissWithAnimation = NO;
     _shareSheetViewController.get().completionWithItemsHandler(nil, resolved, nil, nil);
+#else
+    _completionHandler(resolved);
+#endif
 }
 
 @end
-#endif // PLATFORM(IOS) && !PLATFORM(WATCHOS) && !PLATFORM(APPLETV)
+#endif // !PLATFORM(WATCHOS) && !PLATFORM(APPLETV)
index d4e2857..d86f865 100644 (file)
@@ -59,6 +59,10 @@ OBJC_CLASS WKWindowVisibilityObserver;
 OBJC_CLASS _WKRemoteObjectRegistry;
 OBJC_CLASS _WKThumbnailView;
 
+#if WK_API_ENABLED
+OBJC_CLASS WKShareSheet;
+#endif
+
 #if HAVE(TOUCH_BAR)
 OBJC_CLASS NSCandidateListTouchBarItem;
 OBJC_CLASS NSCustomTouchBarItem;
@@ -75,6 +79,10 @@ class Object;
 class PageConfiguration;
 }
 
+namespace WebCore {
+struct ShareDataWithParsedURL;
+}
+
 @protocol WebViewImplDelegate
 
 - (NSTextInputContext *)_web_superInputContext;
@@ -313,6 +321,7 @@ public:
     id validRequestorForSendAndReturnTypes(NSString *sendType, NSString *returnType);
     void centerSelectionInVisibleArea();
     void selectionDidChange();
+    
     void didBecomeEditable();
     void updateFontPanelIfNeeded();
     void changeFontFromFontManager();
@@ -412,6 +421,9 @@ public:
 
     void setInspectorAttachmentView(NSView *);
     NSView *inspectorAttachmentView();
+    
+    void showShareSheet(const WebCore::ShareDataWithParsedURL&, WTF::CompletionHandler<void(bool)>&&, WKWebView *);
+    void shareSheetDidDismiss(WKShareSheet *);
 
     _WKRemoteObjectRegistry *remoteObjectRegistry();
 
@@ -687,6 +699,10 @@ private:
 #if ENABLE(FULLSCREEN_API)
     RetainPtr<WKFullScreenWindowController> m_fullScreenWindowController;
 #endif
+    
+#if WK_API_ENABLED
+    RetainPtr<WKShareSheet> _shareSheet;
+#endif
 
     RetainPtr<WKWindowVisibilityObserver> m_windowVisibilityObserver;
     RetainPtr<WKAccessibilitySettingsObserver> m_accessibilitySettingsObserver;
index 201abc4..9bb805e 100644 (file)
@@ -2726,6 +2726,29 @@ void WebViewImpl::selectionDidChange()
     [m_view _web_editorStateDidChange];
 }
 
+#if WK_API_ENABLED
+void WebViewImpl::showShareSheet(const WebCore::ShareDataWithParsedURL& data, WTF::CompletionHandler<void(bool)>&& completionHandler, WKWebView *view)
+{
+    ASSERT(!_shareSheet);
+    if (_shareSheet)
+        return;
+    
+    ASSERT([view respondsToSelector:@selector(shareSheetDidDismiss:)]);
+    _shareSheet = adoptNS([[WKShareSheet alloc] initWithView:view]);
+    [_shareSheet setDelegate:view];
+    
+    [_shareSheet presentWithParameters:data completionHandler:WTFMove(completionHandler)];
+}
+    
+void WebViewImpl::shareSheetDidDismiss(WKShareSheet *shareSheet)
+{
+    ASSERT(_shareSheet == shareSheet);
+    
+    [_shareSheet setDelegate:nil];
+    _shareSheet = nil;
+}
+#endif
+
 void WebViewImpl::didBecomeEditable()
 {
     [m_windowVisibilityObserver startObservingFontPanel];
index c538b5b..f50f72a 100644 (file)
@@ -103,7 +103,11 @@ private:
     void resetSecureInputState() override;
     void notifyInputContextAboutDiscardedComposition() override;
     void selectionDidChange() override;
-
+    
+#if WK_API_ENABLED
+    bool showShareSheet(const WebCore::ShareDataWithParsedURL&, WTF::CompletionHandler<void(bool)>&&) override;
+#endif
+        
     WebCore::FloatRect convertToDeviceSpace(const WebCore::FloatRect&) override;
     WebCore::FloatRect convertToUserSpace(const WebCore::FloatRect&) override;
     WebCore::IntPoint screenToRootView(const WebCore::IntPoint&) override;
index 8c23b28..eabb008 100644 (file)
@@ -540,6 +540,13 @@ void PageClientImpl::selectionDidChange()
 {
     m_impl->selectionDidChange();
 }
+#if WK_API_ENABLED
+bool PageClientImpl::showShareSheet(const ShareDataWithParsedURL& shareData, WTF::CompletionHandler<void(bool)>&& completionHandler)
+{
+    m_impl->showShareSheet(shareData, WTFMove(completionHandler), m_webView);
+    return true;
+}
+#endif
 
 void PageClientImpl::wheelEventWasNotHandledByWebCore(const NativeWebWheelEvent& event)
 {
index f681719..b1fed18 100644 (file)
                1CBBE49F19B66C53006B7D81 /* WebInspectorUIMessages.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebInspectorUIMessages.h; sourceTree = "<group>"; };
                1CC417C912C00CCA002BE67B /* TextCheckerCompletion.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TextCheckerCompletion.h; sourceTree = "<group>"; };
                1D67B338212E1F6100FAA786 /* ShareSheetCallbackID.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ShareSheetCallbackID.h; sourceTree = "<group>"; };
-               1DBBB061211CC3CB00502ECC /* WKShareSheet.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = WKShareSheet.mm; path = ios/forms/WKShareSheet.mm; sourceTree = "<group>"; };
-               1DE0D095211CC21300439B5F /* WKShareSheet.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = WKShareSheet.h; path = ios/forms/WKShareSheet.h; sourceTree = "<group>"; };
+               1DBBB061211CC3CB00502ECC /* WKShareSheet.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WKShareSheet.mm; sourceTree = "<group>"; };
+               1DE0D095211CC21300439B5F /* WKShareSheet.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WKShareSheet.h; sourceTree = "<group>"; };
                1F0181691858DC1500F92884 /* WKWebProcessPlugInFrame.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WKWebProcessPlugInFrame.h; sourceTree = "<group>"; };
                1F01816A1858DC1500F92884 /* WKWebProcessPlugInFrame.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WKWebProcessPlugInFrame.mm; sourceTree = "<group>"; };
                1F01816B1858DC1500F92884 /* WKWebProcessPlugInFrameInternal.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WKWebProcessPlugInFrameInternal.h; sourceTree = "<group>"; };
                                2DFC7DBA1BCCC19500C1548C /* WebViewImpl.mm */,
                                1AD01BCB1905D54900C9C45F /* WKReloadFrameErrorRecoveryAttempter.h */,
                                1AD01BCA1905D54900C9C45F /* WKReloadFrameErrorRecoveryAttempter.mm */,
+                               1DE0D095211CC21300439B5F /* WKShareSheet.h */,
+                               1DBBB061211CC3CB00502ECC /* WKShareSheet.mm */,
                                2D7AAFD218C8640600A7ACD4 /* WKWebViewContentProvider.h */,
                                2DC6D9C118C44A610043BAD4 /* WKWebViewContentProviderRegistry.h */,
                                2DC6D9C218C44A610043BAD4 /* WKWebViewContentProviderRegistry.mm */,
                                F4D5F51C206087A10038BBA8 /* WKQuickboardListViewController.mm */,
                                F4F59AD42065A5CA006CAA46 /* WKSelectMenuListViewController.h */,
                                F4F59AD32065A5C9006CAA46 /* WKSelectMenuListViewController.mm */,
-                               1DE0D095211CC21300439B5F /* WKShareSheet.h */,
-                               1DBBB061211CC3CB00502ECC /* WKShareSheet.mm */,
                                F4D5F519206087A00038BBA8 /* WKTextInputListViewController.h */,
                                F4D5F51A206087A10038BBA8 /* WKTextInputListViewController.mm */,
                                2EB6FBFF203021960017E619 /* WKTimePickerViewController.h */,