Bug 189443 - Implement the Web Share API for mac
Summary: Implement the Web Share API for mac
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: New Bugs (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Nobody
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2018-09-07 17:12 PDT by Olivia Barnett
Modified: 2018-09-13 11:08 PDT (History)
11 users (show)

See Also:


Attachments
Patch (22.84 KB, patch)
2018-09-07 17:17 PDT, Olivia Barnett
no flags Details | Formatted Diff | Diff
Archive of layout-test-results from ews107 for mac-sierra-wk2 (2.80 MB, application/zip)
2018-09-07 18:33 PDT, EWS Watchlist
no flags Details
Patch (40.21 KB, patch)
2018-09-10 12:47 PDT, Olivia Barnett
no flags Details | Formatted Diff | Diff
Archive of layout-test-results from ews104 for mac-sierra-wk2 (2.86 MB, application/zip)
2018-09-10 14:03 PDT, EWS Watchlist
no flags Details
Patch (37.68 KB, patch)
2018-09-10 14:28 PDT, Olivia Barnett
no flags Details | Formatted Diff | Diff
Archive of layout-test-results from ews106 for mac-sierra-wk2 (2.80 MB, application/zip)
2018-09-10 15:45 PDT, EWS Watchlist
no flags Details
Patch (38.11 KB, patch)
2018-09-10 16:01 PDT, Olivia Barnett
no flags Details | Formatted Diff | Diff
Archive of layout-test-results from ews107 for mac-sierra-wk2 (3.24 MB, application/zip)
2018-09-10 18:01 PDT, EWS Watchlist
no flags Details
Patch (37.29 KB, patch)
2018-09-11 11:17 PDT, Olivia Barnett
no flags Details | Formatted Diff | Diff
Patch (37.38 KB, patch)
2018-09-11 14:16 PDT, Olivia Barnett
no flags Details | Formatted Diff | Diff
Patch (37.44 KB, patch)
2018-09-11 15:08 PDT, Olivia Barnett
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Olivia Barnett 2018-09-07 17:12:52 PDT
Implement the Web Share API for mac
Comment 1 Olivia Barnett 2018-09-07 17:17:06 PDT
Created attachment 349217 [details]
Patch
Comment 2 Tim Horton 2018-09-07 18:01:35 PDT
Comment on attachment 349217 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=349217&action=review

> Source/WebKit/Shared/WebPreferencesDefaultValues.h:175
> -#if PLATFORM(IOS) && !PLATFORM(WATCHOS) && !PLATFORM(APPLETV)
> +#if !PLATFORM(WATCHOS) && !PLATFORM(APPLETV)

You can't do this, because there are platforms other than ours. You can instead change it to:

#if PLATFORM(COCOA) && !PLATFORM(WATCHOS) && !PLATFORM(APPLETV)

which will be Mac and iOS but not watch/GTK/etc.

> Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm:206
> +@interface WKWebView () <NSFilePromiseProviderDelegate, NSDraggingSource, WKShareSheetDelegate>

This isn't about ENABLE(DRAG_SUPPORT), so it doesn't go here. Stick it up above with WebViewImplDelegate.

ACTUALLY you don't need this here at all because it's in WKWebViewInternal.h, right?

> Source/WebKit/UIProcess/Cocoa/WebViewImpl.h:617
> +    RetainPtr<WKShareSheet> _shareSheet;

This is a member variable, it doesn't belong amongst functions. Move it down further.

> Source/WebKit/UIProcess/Cocoa/WebViewImpl.mm:2721
> +    
> +    _shareSheet = adoptNS([[WKShareSheet alloc] initWithView:(NSView<WKShareSheetDelegate> *)view]);

You should assert that the view conforms to WKShareSheetDelegate before this nasty cast. Also, you only need the cast when setting the delegate; initWithView doesn't care about protocol conformance.

> Source/WebKit/UIProcess/ios/forms/WKShareSheet.h:26
> -#if PLATFORM(IOS) && !PLATFORM(WATCHOS) && !PLATFORM(APPLETV)
> +#if !PLATFORM(WATCHOS) && !PLATFORM(APPLETV)

Ditto the thing I said before about PLATFORM(COCOA)

> Source/WebKit/UIProcess/ios/forms/WKShareSheet.h:43
> +@interface WKShareSheet : NSObject<NSSharingServicePickerDelegate>

We usually put spaces before the protocol conformance list (NSObject <NSSharingServicePickerDelegate>)

> Source/WebKit/UIProcess/ios/forms/WKShareSheet.mm:-29
> -#if PLATFORM(IOS) && !PLATFORM(WATCHOS) && !PLATFORM(APPLETV)

PLATFORM(COCOA) thing

> Source/WebKit/UIProcess/ios/forms/WKShareSheet.mm:32
> +#if PLATFORM(IOS)
>  #import "UIKitSPI.h"
> +#endif

Usually platform-specific includes go in a section separated by newlines below the others

> Source/WebKit/UIProcess/ios/forms/WKShareSheet.mm:94
> +    _sharingServicePickerForMenu = [[NSSharingServicePicker alloc] initWithItems:shareDataArray.get()];

You're missing an adoptNS here (this is initialized with a +1 reference count, and you're sticking it in a RetainPtr, which immediately retains it (to +2); it will never make it back to zero, so it will leak).

> Source/WebKit/UIProcess/ios/forms/WKShareSheet.mm:98
> +    NSRect mouseLocationRect = {[NSEvent mouseLocation], CGSizeMake(1.0, 1.0)};

Let's use NSMakeRect instead of weird curly braces.

> Source/WebKit/UIProcess/ios/forms/WKShareSheet.mm:100
> +    NSRect mouseLocationInView = [_view.getAutoreleased() convertRect:mouseLocationInWindow fromView:nil];

No need for the .getAutoreleased()

> Source/WebKit/UIProcess/ios/forms/WKShareSheet.mm:118
> +/* Invoked when the user has selected a service and before it is executed. Service will be nil if the picker was dismissed.
> + */

No need for this comment.

> Source/WebKit/UIProcess/ios/forms/WKShareSheet.mm:170
>  - (void)invokeShareSheetWithResolution:(BOOL)resolved

How does your test work without this implemented? (I see below that it perhaps does not)
Comment 3 EWS Watchlist 2018-09-07 18:33:35 PDT
Comment on attachment 349217 [details]
Patch

Attachment 349217 [details] did not pass mac-wk2-ews (mac-wk2):
Output: https://webkit-queues.webkit.org/results/9135262

New failing tests:
fast/dom/navigator-detached-no-crash.html
Comment 4 EWS Watchlist 2018-09-07 18:33:36 PDT
Created attachment 349226 [details]
Archive of layout-test-results from ews107 for mac-sierra-wk2

The attached test failures were seen while running run-webkit-tests on the mac-wk2-ews.
Bot: ews107  Port: mac-sierra-wk2  Platform: Mac OS X 10.12.6
Comment 5 Wenson Hsieh 2018-09-07 23:14:09 PDT
Comment on attachment 349217 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=349217&action=review

> Source/WebKit/UIProcess/ios/forms/WKShareSheet.mm:26
>  #import "config.h"

This file is currently in Source/WebKit/UIProcess/ios; perhaps it should go in the Cocoa folder instead?

> Source/WebKit/UIProcess/ios/forms/WKShareSheet.mm:69
>      _shouldDismissWithAnimation = YES;

Hm...I'd think this should be useful on macOS as well, once we get the test working.
Comment 6 Olivia Barnett 2018-09-10 10:12:00 PDT
> > Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm:206
> > +@interface WKWebView () <NSFilePromiseProviderDelegate, NSDraggingSource, WKShareSheetDelegate>
> 
> This isn't about ENABLE(DRAG_SUPPORT), so it doesn't go here. Stick it up
> above with WebViewImplDelegate.
> 
> ACTUALLY you don't need this here at all because it's in
> WKWebViewInternal.h, right?

Hmm, I don't see any reference to dragging in WKWebViewInternal.h actually
Comment 7 Tim Horton 2018-09-10 10:21:00 PDT
(In reply to Olivia Barnett from comment #6)
> > > Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm:206
> > > +@interface WKWebView () <NSFilePromiseProviderDelegate, NSDraggingSource, WKShareSheetDelegate>
> > 
> > This isn't about ENABLE(DRAG_SUPPORT), so it doesn't go here. Stick it up
> > above with WebViewImplDelegate.
> > 
> > ACTUALLY you don't need this here at all because it's in
> > WKWebViewInternal.h, right?
> 
> Hmm, I don't see any reference to dragging in WKWebViewInternal.h actually

I meant your thing, not the DRAG_SUPPORT thing.
Comment 8 Tim Horton 2018-09-10 10:21:19 PDT
Comment on attachment 349217 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=349217&action=review

> Source/WebKit/UIProcess/API/Cocoa/WKWebViewInternal.h:51
> +#if PLATFORM(MAC)

This one!
Comment 9 Olivia Barnett 2018-09-10 12:47:14 PDT
Created attachment 349322 [details]
Patch
Comment 10 Tim Horton 2018-09-10 13:49:27 PDT
Comment on attachment 349322 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=349322&action=review

> Source/WebKit/UIProcess/mac/PageClientImplMac.h:106
> +    bool showShareSheet(const ShareDataWithParsedURL&, WTF::CompletionHandler<void(bool)>&&) override;

/Volumes/Data/EWS/WebKit/Source/WebKit/UIProcess/mac/PageClientImplMac.h:106:31: error: unknown type name 'ShareDataWithParsedURL'; did you mean 'WebCore::ShareDataWithParsedURL'?
    bool showShareSheet(const ShareDataWithParsedURL&, WTF::CompletionHandler<void(bool)>&&) override;
                              ^~~~~~~~~~~~~~~~~~~~~~
                              WebCore::ShareDataWithParsedURL
Comment 11 Tim Horton 2018-09-10 13:55:38 PDT
Comment on attachment 349322 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=349322&action=review

> Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm:-204
> -#if PLATFORM(MAC) && ENABLE(DRAG_SUPPORT)

I don't think you meant to remove this existing code.

> Source/WebKit/UIProcess/Cocoa/WKShareSheet.h:31
> +#if PLATFORM(IOS)
> +#import <UIKit/UIKit.h>
> +#endif
> +

Should go below the other headers.

> Source/WebKit/UIProcess/Cocoa/WKShareSheet.mm:43
> +#if PLATFORM(MAC)

the #if here could go just around the members, not around the @implementation or curly braces

> Source/WebKit/UIProcess/ios/WKContentViewInteraction.h:30
> +#if PLATFORM(COCOA) && !PLATFORM(WATCHOS) && !PLATFORM(APPLETV)

Not needed here, this file is already PLATFORM(IOS) only. (you still need the existing checks, but don't need to add a cocoa check).

> Source/WebKit/UIProcess/ios/WKContentViewInteraction.h:194
> +#if PLATFORM(COCOA) && !PLATFORM(WATCHOS) && !PLATFORM(APPLETV)

Not needed here, this file is already PLATFORM(IOS) only. (you still need the existing checks, but don't need to add a cocoa check).

> Source/WebKit/UIProcess/ios/WKContentViewInteraction.h:286
> +#if PLATFORM(COCOA) && !PLATFORM(WATCHOS) && !PLATFORM(APPLETV)

Not needed here, this file is already PLATFORM(IOS) only. (you still need the existing checks, but don't need to add a cocoa check).

> Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm:793
> +#if PLATFORM(COCOA) && !PLATFORM(WATCHOS) && !PLATFORM(APPLETV)

Not needed here, this file is already PLATFORM(IOS) only. (you still need the existing checks, but don't need to add a cocoa check).

> Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm:4739
> +#if PLATFORM(COCOA) && !PLATFORM(WATCHOS) && !PLATFORM(APPLETV)

Not needed here, this file is already PLATFORM(IOS) only. (you still need the existing checks, but don't need to add a cocoa check).

> Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm:4751
> +#if PLATFORM(COCOA) && !PLATFORM(WATCHOS) && !PLATFORM(APPLETV)

Not needed here, this file is already PLATFORM(IOS) only. (you still need the existing checks, but don't need to add a cocoa check).

> Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm:5920
> +#if PLATFORM(COCOA) && !PLATFORM(WATCHOS) && !PLATFORM(APPLETV)

Not needed here, this file is already PLATFORM(IOS) only. (you still need the existing checks, but don't need to add a cocoa check).
Comment 12 EWS Watchlist 2018-09-10 14:03:56 PDT
Comment on attachment 349322 [details]
Patch

Attachment 349322 [details] did not pass mac-wk2-ews (mac-wk2):
Output: https://webkit-queues.webkit.org/results/9163655

New failing tests:
fast/dom/navigator-detached-no-crash.html
Comment 13 EWS Watchlist 2018-09-10 14:03:58 PDT
Created attachment 349326 [details]
Archive of layout-test-results from ews104 for mac-sierra-wk2

The attached test failures were seen while running run-webkit-tests on the mac-wk2-ews.
Bot: ews104  Port: mac-sierra-wk2  Platform: Mac OS X 10.12.6
Comment 14 Tim Horton 2018-09-10 14:09:36 PDT
(In reply to Build Bot from comment #13)
> Created attachment 349326 [details]
> Archive of layout-test-results from ews104 for mac-sierra-wk2
> 
> The attached test failures were seen while running run-webkit-tests on the
> mac-wk2-ews.
> Bot: ews104  Port: mac-sierra-wk2  Platform: Mac OS X 10.12.6

This is happening because of the existence of navigator-detached-no-crash-expected.txt in platform/mac-highsierra/fast/dom, which overrides your mac-wk2 result on High Sierra and earlier.

I would just go into that file and add the share() lines in the right places :)
Comment 15 Olivia Barnett 2018-09-10 14:28:35 PDT
Created attachment 349329 [details]
Patch
Comment 16 Tim Horton 2018-09-10 14:44:28 PDT
Comment on attachment 349329 [details]
Patch

Let's wait and see what EWS says about the tests before landing
Comment 17 EWS Watchlist 2018-09-10 15:45:31 PDT
Comment on attachment 349329 [details]
Patch

Attachment 349329 [details] did not pass mac-wk2-ews (mac-wk2):
Output: https://webkit-queues.webkit.org/results/9164850

New failing tests:
fast/dom/navigator-detached-no-crash.html
Comment 18 EWS Watchlist 2018-09-10 15:45:33 PDT
Created attachment 349341 [details]
Archive of layout-test-results from ews106 for mac-sierra-wk2

The attached test failures were seen while running run-webkit-tests on the mac-wk2-ews.
Bot: ews106  Port: mac-sierra-wk2  Platform: Mac OS X 10.12.6
Comment 19 Olivia Barnett 2018-09-10 16:01:17 PDT
Created attachment 349348 [details]
Patch
Comment 20 EWS Watchlist 2018-09-10 18:01:09 PDT
Comment on attachment 349348 [details]
Patch

Attachment 349348 [details] did not pass mac-wk2-ews (mac-wk2):
Output: https://webkit-queues.webkit.org/results/9166851

New failing tests:
fast/dom/navigator-detached-no-crash.html
Comment 21 EWS Watchlist 2018-09-10 18:01:11 PDT
Created attachment 349367 [details]
Archive of layout-test-results from ews107 for mac-sierra-wk2

The attached test failures were seen while running run-webkit-tests on the mac-wk2-ews.
Bot: ews107  Port: mac-sierra-wk2  Platform: Mac OS X 10.12.6
Comment 22 Tim Horton 2018-09-10 21:32:57 PDT
Comment on attachment 349348 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=349348&action=review

ALSO it looks like you missed a trailing space in the new expected test result :P (or your editor deleted it on you!)

> Source/WebKit/ChangeLog:2
> +

To fix the 32-bit build, let's just make this feature modern-API only (the other option is to make it legacy-runtime-compatible by moving the ivar definitions to the header, but that is ugly and less forward-looking), by doing the following:

> Source/WebKit/UIProcess/API/mac/WKView.mm:1334
> +- (void)shareSheetDidDismiss:(WKShareSheet *)shareSheet

Get rid of this.

> Source/WebKit/UIProcess/Cocoa/WKShareSheet.h:26
> +#if PLATFORM(COCOA) && !PLATFORM(WATCHOS) && !PLATFORM(APPLETV)

Add a && WK_API_ENABLED here, so it only builds in places where WKWebView exists

> Source/WebKit/UIProcess/Cocoa/WKShareSheet.h:44
> +- (instancetype)initWithView:(NSView *)view;

Make this take a WKWebView instead.

> Source/WebKit/UIProcess/Cocoa/WKShareSheet.mm:29
> +#if PLATFORM(COCOA) && !PLATFORM(WATCHOS) && !PLATFORM(APPLETV)

WK_API_ENABLED

> Source/WebKit/UIProcess/Cocoa/WKShareSheet.mm:45
> +    WeakObjCPtr<NSView> _view;

WKWebView (and in various other places here).

> Source/WebKit/UIProcess/Cocoa/WebViewImpl.mm:2730
> +void WebViewImpl::showShareSheet(const WebCore::ShareDataWithParsedURL& data, WTF::CompletionHandler<void(bool)>&& completionHandler, NSView *view)

WKWebView.

> Source/WebKit/UIProcess/Cocoa/WebViewImpl.mm:2738
> +    [_shareSheet setDelegate:(NSView<WKShareSheetDelegate> *)view];

No more need for this ugly cast!

> Source/WebKit/UIProcess/mac/PageClientImplMac.mm:546
> +    m_impl->showShareSheet(shareData, WTFMove(completionHandler), m_view);

Pass m_webView instead
Comment 23 Olivia Barnett 2018-09-11 11:17:19 PDT
Created attachment 349416 [details]
Patch
Comment 24 Tim Horton 2018-09-11 11:19:41 PDT
Comment on attachment 349416 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=349416&action=review

> Source/WebKit/UIProcess/Cocoa/WebViewImpl.h:657
> +    RetainPtr<WKShareSheet> _shareSheet;

Probably need some WK_API_ENABLED in this file

> Source/WebKit/UIProcess/Cocoa/WebViewImpl.mm:2730
> +void WebViewImpl::showShareSheet(const WebCore::ShareDataWithParsedURL& data, WTF::CompletionHandler<void(bool)>&& completionHandler, WKWebView *view)

And here.
Comment 25 Olivia Barnett 2018-09-11 14:16:22 PDT
Created attachment 349450 [details]
Patch
Comment 26 Olivia Barnett 2018-09-11 15:08:18 PDT
Created attachment 349469 [details]
Patch
Comment 27 WebKit Commit Bot 2018-09-11 17:58:06 PDT
Comment on attachment 349469 [details]
Patch

Clearing flags on attachment: 349469

Committed r235925: <https://trac.webkit.org/changeset/235925>
Comment 28 WebKit Commit Bot 2018-09-11 17:58:08 PDT
All reviewed patches have been landed.  Closing bug.
Comment 29 Radar WebKit Bug Importer 2018-09-11 17:59:35 PDT
<rdar://problem/44365441>
Comment 30 Truitt Savell 2018-09-13 09:19:18 PDT
Looks like after https://trac.webkit.org/changeset/235925/webkit

imported/w3c/web-platform-tests/web-share/idlharness.https.html has started failing constantly. 

History:
https://webkit-test-results.webkit.org/dashboards/flakiness_dashboard.html#showAllRuns=true&tests=imported%2Fw3c%2Fweb-platform-tests%2Fweb-share%2Fidlharness.https.html


Diff:
--- /Volumes/Data/slave/highsierra-release-tests-wk2/build/layout-test-results/imported/w3c/web-platform-tests/web-share/idlharness.https-expected.txt
+++ /Volumes/Data/slave/highsierra-release-tests-wk2/build/layout-test-results/imported/w3c/web-platform-tests/web-share/idlharness.https-actual.txt
@@ -1,7 +1,7 @@
 
 PASS Test driver 
+PASS Partial interface Navigator: original interface defined 
 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 
 

Is this possibly just a rebaseline?
Comment 31 Ryan Haddad 2018-09-13 11:08:03 PDT
(In reply to Truitt Savell from comment #30)
> Is this possibly just a rebaseline?

I went ahead and rebaselined it in https://trac.webkit.org/changeset/235980/webkit