Changeset 235925 in webkit


Ignore:
Timestamp:
Sep 11, 2018 5:57:58 PM (6 years ago)
Author:
commit-queue@webkit.org
Message:

Implement the Web Share API for mac
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.

Location:
trunk
Files:
6 added
11 edited
1 copied
2 moved

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r235924 r235925  
     12018-09-11  Olivia Barnett  <obarnett@apple.com>
     2
     3        Implement the Web Share API for mac
     4        https://bugs.webkit.org/show_bug.cgi?id=189443
     5
     6        Reviewed by Tim Horton.
     7
     8        * platform/mac-wk2/fast/dom/navigator-detached-no-crash-expected.txt: Added.
     9        * platform/mac-wk2/imported/w3c/web-platform-tests/web-share/idlharness.https-expected.txt: Added.
     10        * platform/mac-wk2/imported/w3c/web-platform-tests/web-share/share-empty.https-expected.txt: Added.
     11        * platform/mac-wk2/imported/w3c/web-platform-tests/web-share/share-securecontext.http-expected.txt: Added.
     12        * platform/mac-wk2/imported/w3c/web-platform-tests/web-share/share-url-invalid.https-expected.txt: Added.
     13        * platform/mac-wk2/imported/w3c/web-platform-tests/web-share/share-without-user-gesture.https-expected.txt: Added.
     14        Updated test expectations.
     15
    1162018-09-11  Myles C. Maxfield  <mmaxfield@apple.com>
    217
  • trunk/LayoutTests/platform/mac-highsierra/fast/dom/navigator-detached-no-crash-expected.txt

    r233831 r235925  
     1CONSOLE MESSAGE: Unhandled Promise Rejection: TypeError: Type error
    12This tests that the navigator object of a deleted frame is disconnected properly. Accessing fields or methods shouldn't crash the browser.
    23 Check Navigator
     
    1920navigator.sendBeacon() threw err TypeError: Not enough arguments
    2021navigator.serviceWorker is OK
     22navigator.share() is OK
    2123navigator.userAgent is OK
    2224navigator.vendor is OK
     
    4143navigator.sendBeacon() threw err TypeError: Not enough arguments
    4244navigator.serviceWorker is OK
     45navigator.share() is OK
    4346navigator.userAgent is OK
    4447navigator.vendor is OK
  • trunk/LayoutTests/platform/mac-wk2/fast/dom/navigator-detached-no-crash-expected.txt

    r235924 r235925  
     1CONSOLE MESSAGE: Unhandled Promise Rejection: TypeError: Not enough arguments
     2CONSOLE MESSAGE: Unhandled Promise Rejection: TypeError: Type error
    13This tests that the navigator object of a deleted frame is disconnected properly. Accessing fields or methods shouldn't crash the browser.
    24 Check Navigator
     
    1719navigator.product is OK
    1820navigator.productSub is OK
     21navigator.requestMediaKeySystemAccess() is OK
    1922navigator.sendBeacon() threw err TypeError: Not enough arguments
    2023navigator.serviceWorker is OK
     24navigator.share() is OK
    2125navigator.userAgent is OK
    2226navigator.vendor is OK
     
    3943navigator.product is OK
    4044navigator.productSub is OK
     45navigator.requestMediaKeySystemAccess() is OK
    4146navigator.sendBeacon() threw err TypeError: Not enough arguments
    4247navigator.serviceWorker is OK
     48navigator.share() is OK
    4349navigator.userAgent is OK
    4450navigator.vendor is OK
  • trunk/Source/WebKit/ChangeLog

    r235921 r235925  
     12018-09-11  Olivia Barnett  <obarnett@apple.com>
     2
     3        Implement the Web Share API for mac
     4        https://bugs.webkit.org/show_bug.cgi?id=189443
     5
     6        Reviewed by Tim Horton.
     7
     8        * Shared/WebPreferencesDefaultValues.h:
     9        * UIProcess/API/Cocoa/WKWebView.mm:
     10        (-[WKWebView shareSheetDidDismiss:]):
     11        * UIProcess/API/Cocoa/WKWebViewInternal.h:
     12        * UIProcess/API/mac/WKView.mm:
     13        (-[WKView shareSheetDidDismiss:]):
     14        * UIProcess/Cocoa/WebViewImpl.h:
     15        * UIProcess/Cocoa/WebViewImpl.mm:
     16        (WebKit::WebViewImpl::showShareSheet):
     17        (WebKit::WebViewImpl::shareSheetDidDismiss):
     18        Implemented function for WKShareSheetDelegate.
     19
     20        * UIProcess/Cocoa/WKShareSheet.h:
     21        * UIProcess/Cocoa/WKShareSheet.mm:
     22        (-[WKShareSheet initWithView:initWithView:]):
     23        (-[WKShareSheet presentWithParameters:completionHandler:]):
     24        (-[WKShareSheet sharingServicePicker:didChooseSharingService:]):
     25        (-[WKShareSheet _cancel]):
     26        (-[WKShareSheet dismiss]):
     27        (-[WKShareSheet _dismissDisplayAnimated:]):
     28        (-[WKShareSheet invokeShareSheetWithResolution:]):
     29        (-[WKShareSheet initWithView:]): Deleted.
     30        Added mac platform checks and share sheet functionality.
     31
     32        * UIProcess/mac/PageClientImplMac.h:
     33        * UIProcess/mac/PageClientImplMac.mm:
     34        (WebKit::PageClientImpl::showShareSheet):
     35        Allows macos to invoke the system share sheet.
     36
    1372018-09-07  Dean Jackson  <dino@apple.com>
    238
  • trunk/Source/WebKit/Shared/WebPreferencesDefaultValues.h

    r235772 r235925  
    8585#define DEFAULT_JAVASCRIPT_CAN_OPEN_WINDOWS_AUTOMATICALLY true
    8686#define DEFAULT_SHOULD_RESPECT_IMAGE_ORIENTATION false
    87 #define DEFAULT_WEB_SHARE_ENABLED false
    8887#define DEFAULT_PASSWORD_ECHO_ENABLED false
    8988#define DEFAULT_ALLOWS_INLINE_MEDIA_PLAYBACK true
     
    174173#endif
    175174
    176 #if PLATFORM(IOS) && !PLATFORM(WATCHOS) && !PLATFORM(APPLETV)
     175#if PLATFORM(COCOA) && !PLATFORM(WATCHOS) && !PLATFORM(APPLETV)
    177176#define DEFAULT_WEB_SHARE_ENABLED true
    178177#else
  • trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm

    r235914 r235925  
    56815681}
    56825682
     5683- (void)shareSheetDidDismiss:(WKShareSheet *)shareSheet
     5684{
     5685    _impl->shareSheetDidDismiss(shareSheet);
     5686}
     5687
    56835688- (void)_setOverrideDeviceScaleFactor:(CGFloat)deviceScaleFactor
    56845689{
  • trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebViewInternal.h

    r235878 r235925  
    2929
    3030#import "SameDocumentNavigationType.h"
     31#import "WKShareSheet.h"
    3132#import "WKWebViewConfiguration.h"
    3233#import "_WKAttachmentInternal.h"
     
    4647#if PLATFORM(IOS)
    4748#define WK_WEB_VIEW_PROTOCOLS <UIScrollViewDelegate>
     49#endif
     50
     51#if PLATFORM(MAC)
     52#define WK_WEB_VIEW_PROTOCOLS <WKShareSheetDelegate>
    4853#endif
    4954
  • trunk/Source/WebKit/UIProcess/Cocoa/WKShareSheet.h

    r235924 r235925  
    2424 */
    2525
    26 #if PLATFORM(IOS) && !PLATFORM(WATCHOS) && !PLATFORM(APPLETV)
     26#import "WKAPICast.h"
    2727
    28 #import <UIKit/UIKit.h>
     28#if PLATFORM(COCOA) && !PLATFORM(WATCHOS) && !PLATFORM(APPLETV) && WK_API_ENABLED
     29
    2930#import <WebCore/ShareData.h>
    3031#import <wtf/BlockPtr.h>
     
    3435#import <wtf/text/WTFString.h>
    3536
     37#if PLATFORM(IOS)
     38#import <UIKit/UIKit.h>
     39#else
     40#import "WKWebView.h"
     41#endif
     42
    3643@class WKContentView;
    3744@protocol WKShareSheetDelegate;
    3845
    39 @interface WKShareSheet : UIViewController
     46#if PLATFORM(MAC)
     47@interface WKShareSheet : NSObject <NSSharingServicePickerDelegate>
     48- (instancetype)initWithView:(WKWebView *)view;
     49#else
     50@interface WKShareSheet : NSObject
    4051- (instancetype)initWithView:(WKContentView *)view;
     52#endif
    4153
    4254- (void)presentWithParameters:(const WebCore::ShareDataWithParsedURL&)data completionHandler:(WTF::CompletionHandler<void(bool)>&&)completionHandler;
     
    5264@end
    5365
    54 #endif // PLATFORM(IOS) && !PLATFORM(WATCHOS) && !PLATFORM(APPLETV)
     66#endif // !PLATFORM(WATCHOS) && !PLATFORM(APPLETV)
  • trunk/Source/WebKit/UIProcess/Cocoa/WKShareSheet.mm

    r235924 r235925  
    2727#import "WKShareSheet.h"
    2828
    29 #if PLATFORM(IOS) && !PLATFORM(WATCHOS) && !PLATFORM(APPLETV)
    30 #import "UIKitSPI.h"
     29#if PLATFORM(COCOA) && !PLATFORM(WATCHOS) && !PLATFORM(APPLETV) && WK_API_ENABLED
     30
    3131#import "WKContentViewInteraction.h"
    3232#import "WebPageProxy.h"
     
    3535#import <wtf/WeakObjCPtr.h>
    3636
     37#if PLATFORM(IOS)
     38#import "UIKitSPI.h"
     39#else
     40#import "WKWebView.h"
     41#endif
     42
    3743using namespace WebKit;
    3844
    3945@implementation WKShareSheet {
     46#if PLATFORM(MAC)
     47    WeakObjCPtr<WKWebView> _view;
     48
     49    BOOL _isShowingSharingServicePicker;
     50    RetainPtr<NSSharingServicePicker> _sharingServicePickerForMenu;
     51    WTF::CompletionHandler<void(bool)> _completionHandler;
     52#else
    4053    WeakObjCPtr<WKContentView> _view;
    41 
     54   
    4255    RetainPtr<UIActivityViewController> _shareSheetViewController;
    4356    RetainPtr<UIViewController> _presentationViewController;
    4457    BOOL _shouldDismissWithAnimation;
     58#endif
    4559}
    4660
     61#if PLATFORM(MAC)
     62- (instancetype)initWithView:(WKWebView *)view
     63#else
    4764- (instancetype)initWithView:(WKContentView *)view
     65#endif
    4866{
    4967    if (!(self = [super init]))
    5068        return nil;
    5169    _view = view;
     70#if PLATFORM(IOS)
    5271    _shouldDismissWithAnimation = YES;
     72#endif
    5373    return self;
    5474}
     
    6383    if (!data.url.isNull()) {
    6484        NSURL *url = (NSURL *)data.url;
     85#if PLATFORM(IOS)
    6586        if (!data.shareData.title.isEmpty())
    6687            url._title = data.shareData.title;
     88#endif
    6789        [shareDataArray addObject:url];
    6890    }
     
    7193        [shareDataArray addObject:(NSString *)data.shareData.title];
    7294   
     95#if PLATFORM(MAC)
     96    _sharingServicePickerForMenu = adoptNS([[NSSharingServicePicker alloc] initWithItems:shareDataArray.get()]);
     97    _sharingServicePickerForMenu.get().delegate = self;
     98    _completionHandler = WTFMove(completionHandler);
     99   
     100    NSPoint location = [NSEvent mouseLocation];
     101    NSRect mouseLocationRect = NSMakeRect(location.x, location.y, 1.0, 1.0);
     102    NSRect mouseLocationInWindow = [[_view window] convertRectFromScreen:mouseLocationRect];
     103    NSRect mouseLocationInView = [_view convertRect:mouseLocationInWindow fromView:nil];
     104    [_sharingServicePickerForMenu showRelativeToRect:mouseLocationInView ofView:_view.getAutoreleased() preferredEdge:NSMinYEdge];
     105#else
    73106    auto shareSheetController = adoptNS([[UIActivityViewController alloc] initWithActivityItems:shareDataArray.get() applicationActivities:nil]);
    74107
     
    81114    _shareSheetViewController = WTFMove(shareSheetController);
    82115    [self _presentFullscreenViewController:_shareSheetViewController.get() animated:YES];
     116#endif
    83117}
    84118
     119#if PLATFORM(MAC)
     120- (void)sharingServicePicker:(NSSharingServicePicker *)sharingServicePicker didChooseSharingService:(nullable NSSharingService *)service
     121{
     122    self->_completionHandler(!service);
     123    [self _dispatchDidDismiss];
     124}
     125
     126#endif
    85127- (void)_dispatchDidDismiss
    86128{
     
    91133- (void)_cancel
    92134{
     135#if PLATFORM(IOS)
    93136    [self _dispatchDidDismiss];
     137#endif
    94138}
    95139
    96140- (void)dismiss
    97141{
     142#if PLATFORM(IOS)
    98143    [[UIViewController _viewControllerForFullScreenPresentationFromView:_view.getAutoreleased()] dismissViewControllerAnimated:_shouldDismissWithAnimation completion:nil];
    99144    _presentationViewController = nil;
    100145   
    101146    [self _cancel];
     147#endif
    102148}
     149
     150#if PLATFORM(IOS)
    103151
    104152- (void)_dismissDisplayAnimated:(BOOL)animated
     
    106154    if (_presentationViewController) {
    107155        UIViewController *currentPresentedViewController = [_presentationViewController presentedViewController];
    108         if (currentPresentedViewController == self) {
     156        if (currentPresentedViewController == _shareSheetViewController) {
    109157            [currentPresentedViewController dismissViewControllerAnimated:animated completion:^{
    110158                _presentationViewController = nil;
     
    119167    [_presentationViewController presentViewController:viewController animated:animated completion:nil];
    120168}
     169#endif
    121170
    122171- (void)invokeShareSheetWithResolution:(BOOL)resolved
    123172{
     173#if PLATFORM(IOS)
    124174    _shouldDismissWithAnimation = NO;
    125175    _shareSheetViewController.get().completionWithItemsHandler(nil, resolved, nil, nil);
     176#else
     177    _completionHandler(resolved);
     178#endif
    126179}
    127180
    128181@end
    129 #endif // PLATFORM(IOS) && !PLATFORM(WATCHOS) && !PLATFORM(APPLETV)
     182#endif // !PLATFORM(WATCHOS) && !PLATFORM(APPLETV)
  • trunk/Source/WebKit/UIProcess/Cocoa/WebViewImpl.h

    r235914 r235925  
    6060OBJC_CLASS _WKThumbnailView;
    6161
     62#if WK_API_ENABLED
     63OBJC_CLASS WKShareSheet;
     64#endif
     65
    6266#if HAVE(TOUCH_BAR)
    6367OBJC_CLASS NSCandidateListTouchBarItem;
     
    7478class Object;
    7579class PageConfiguration;
     80}
     81
     82namespace WebCore {
     83struct ShareDataWithParsedURL;
    7684}
    7785
     
    314322    void centerSelectionInVisibleArea();
    315323    void selectionDidChange();
     324   
    316325    void didBecomeEditable();
    317326    void updateFontPanelIfNeeded();
     
    413422    void setInspectorAttachmentView(NSView *);
    414423    NSView *inspectorAttachmentView();
     424   
     425    void showShareSheet(const WebCore::ShareDataWithParsedURL&, WTF::CompletionHandler<void(bool)>&&, WKWebView *);
     426    void shareSheetDidDismiss(WKShareSheet *);
    415427
    416428    _WKRemoteObjectRegistry *remoteObjectRegistry();
     
    688700    RetainPtr<WKFullScreenWindowController> m_fullScreenWindowController;
    689701#endif
     702   
     703#if WK_API_ENABLED
     704    RetainPtr<WKShareSheet> _shareSheet;
     705#endif
    690706
    691707    RetainPtr<WKWindowVisibilityObserver> m_windowVisibilityObserver;
  • trunk/Source/WebKit/UIProcess/Cocoa/WebViewImpl.mm

    r235914 r235925  
    27272727}
    27282728
     2729#if WK_API_ENABLED
     2730void WebViewImpl::showShareSheet(const WebCore::ShareDataWithParsedURL& data, WTF::CompletionHandler<void(bool)>&& completionHandler, WKWebView *view)
     2731{
     2732    ASSERT(!_shareSheet);
     2733    if (_shareSheet)
     2734        return;
     2735   
     2736    ASSERT([view respondsToSelector:@selector(shareSheetDidDismiss:)]);
     2737    _shareSheet = adoptNS([[WKShareSheet alloc] initWithView:view]);
     2738    [_shareSheet setDelegate:view];
     2739   
     2740    [_shareSheet presentWithParameters:data completionHandler:WTFMove(completionHandler)];
     2741}
     2742   
     2743void WebViewImpl::shareSheetDidDismiss(WKShareSheet *shareSheet)
     2744{
     2745    ASSERT(_shareSheet == shareSheet);
     2746   
     2747    [_shareSheet setDelegate:nil];
     2748    _shareSheet = nil;
     2749}
     2750#endif
     2751
    27292752void WebViewImpl::didBecomeEditable()
    27302753{
  • trunk/Source/WebKit/UIProcess/mac/PageClientImplMac.h

    r235365 r235925  
    104104    void notifyInputContextAboutDiscardedComposition() override;
    105105    void selectionDidChange() override;
    106 
     106   
     107#if WK_API_ENABLED
     108    bool showShareSheet(const WebCore::ShareDataWithParsedURL&, WTF::CompletionHandler<void(bool)>&&) override;
     109#endif
     110       
    107111    WebCore::FloatRect convertToDeviceSpace(const WebCore::FloatRect&) override;
    108112    WebCore::FloatRect convertToUserSpace(const WebCore::FloatRect&) override;
  • trunk/Source/WebKit/UIProcess/mac/PageClientImplMac.mm

    r235365 r235925  
    541541    m_impl->selectionDidChange();
    542542}
     543#if WK_API_ENABLED
     544bool PageClientImpl::showShareSheet(const ShareDataWithParsedURL& shareData, WTF::CompletionHandler<void(bool)>&& completionHandler)
     545{
     546    m_impl->showShareSheet(shareData, WTFMove(completionHandler), m_webView);
     547    return true;
     548}
     549#endif
    543550
    544551void PageClientImpl::wheelEventWasNotHandledByWebCore(const NativeWebWheelEvent& event)
  • trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj

    r235921 r235925  
    24212421                1CC417C912C00CCA002BE67B /* TextCheckerCompletion.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TextCheckerCompletion.h; sourceTree = "<group>"; };
    24222422                1D67B338212E1F6100FAA786 /* ShareSheetCallbackID.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ShareSheetCallbackID.h; sourceTree = "<group>"; };
    2423                 1DBBB061211CC3CB00502ECC /* WKShareSheet.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = WKShareSheet.mm; path = ios/forms/WKShareSheet.mm; sourceTree = "<group>"; };
    2424                 1DE0D095211CC21300439B5F /* WKShareSheet.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = WKShareSheet.h; path = ios/forms/WKShareSheet.h; sourceTree = "<group>"; };
     2423                1DBBB061211CC3CB00502ECC /* WKShareSheet.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WKShareSheet.mm; sourceTree = "<group>"; };
     2424                1DE0D095211CC21300439B5F /* WKShareSheet.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WKShareSheet.h; sourceTree = "<group>"; };
    24252425                1F0181691858DC1500F92884 /* WKWebProcessPlugInFrame.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WKWebProcessPlugInFrame.h; sourceTree = "<group>"; };
    24262426                1F01816A1858DC1500F92884 /* WKWebProcessPlugInFrame.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WKWebProcessPlugInFrame.mm; sourceTree = "<group>"; };
     
    52955295                                1AD01BCB1905D54900C9C45F /* WKReloadFrameErrorRecoveryAttempter.h */,
    52965296                                1AD01BCA1905D54900C9C45F /* WKReloadFrameErrorRecoveryAttempter.mm */,
     5297                                1DE0D095211CC21300439B5F /* WKShareSheet.h */,
     5298                                1DBBB061211CC3CB00502ECC /* WKShareSheet.mm */,
    52975299                                2D7AAFD218C8640600A7ACD4 /* WKWebViewContentProvider.h */,
    52985300                                2DC6D9C118C44A610043BAD4 /* WKWebViewContentProviderRegistry.h */,
     
    85088510                                F4F59AD42065A5CA006CAA46 /* WKSelectMenuListViewController.h */,
    85098511                                F4F59AD32065A5C9006CAA46 /* WKSelectMenuListViewController.mm */,
    8510                                 1DE0D095211CC21300439B5F /* WKShareSheet.h */,
    8511                                 1DBBB061211CC3CB00502ECC /* WKShareSheet.mm */,
    85128512                                F4D5F519206087A00038BBA8 /* WKTextInputListViewController.h */,
    85138513                                F4D5F51A206087A10038BBA8 /* WKTextInputListViewController.mm */,
Note: See TracChangeset for help on using the changeset viewer.