Share more WKShareSheet code between macOS and iOS, and fix a few bugs
authortimothy_horton@apple.com <timothy_horton@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 10 Oct 2018 19:05:03 +0000 (19:05 +0000)
committertimothy_horton@apple.com <timothy_horton@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 10 Oct 2018 19:05:03 +0000 (19:05 +0000)
commit59302fc7755aad58b9de24a20bb077a13a524061
tree08f28938804f8ef183b5adae452fa1e0723a3144
parent85bf0f432dfb1b31fa28662bd3c59e5d398e9857
Share more WKShareSheet code between macOS and iOS, and fix a few bugs
https://bugs.webkit.org/show_bug.cgi?id=190420

Reviewed by Simon Fraser.

Source/WebCore:

Test: fast/web-share/share-with-no-url.html

* page/Navigator.cpp:
(WebCore::Navigator::share):
* page/ShareData.h:
Make 'url' an optional field on ShareDataWithParsedURL, and don't
reject the share() promise if the URL is totally empty (as opposed to invalid).

Source/WebKit:

* UIProcess/API/Cocoa/WKWebView.mm:
(-[WKWebView _resolutionForShareSheetImmediateCompletionForTesting]):
(-[WKWebView _setShareSheetCompletesImmediatelyWithResolutionForTesting:]):
(-[WKWebView _invokeShareSheetWithResolution:]): Deleted.
Add a new mechanism to tell the share sheet up-front that it should
immediately dismiss with a particular resolution, for testing.
See the Tools ChangeLog for justification.
We keep the bit on WKWebView instead of WKShareSheet so that it can be
called prior to invoking the share sheet.

* UIProcess/API/Cocoa/WKWebViewInternal.h:
* UIProcess/API/Cocoa/WKWebViewPrivate.h:
* UIProcess/Cocoa/WKShareSheet.h:
* UIProcess/Cocoa/WKShareSheet.mm:
(-[WKShareSheet initWithView:]):
(-[WKShareSheet presentWithParameters:completionHandler:]):
(-[WKShareSheet sharingServicePicker:didChooseSharingService:]):
(-[WKShareSheet _didCompleteWithSuccess:]):
(-[WKShareSheet dismiss]):
(-[WKShareSheet dispatchDidDismiss]):
(-[WKShareSheet initWithView:initWithView:]): Deleted.
(-[WKShareSheet _dispatchDidDismiss]): Deleted.
(-[WKShareSheet _cancel]): Deleted.
(-[WKShareSheet _dismissDisplayAnimated:]): Deleted.
(-[WKShareSheet _presentFullscreenViewController:animated:]): Deleted.
(-[WKShareSheet invokeShareSheetWithResolution:]): Deleted.
Reduce the number of extraneous members, methods, and #ifdefs.
Try to share as much of WKShareSheet between the platforms as makes sense.
The interface is now totally identical on the two platforms.

* UIProcess/Cocoa/WebViewImpl.mm:
(WebKit::WebViewImpl::showShareSheet):
* UIProcess/ios/WKContentViewInteraction.h:
* UIProcess/ios/WKContentViewInteraction.mm:
(-[WKContentView _showShareSheet:completionHandler:]):
(-[WKContentView invokeShareSheetWithResolution:]): Deleted.
Instead of silently failing (without even calling the completion handler!)
if we try to present one share sheet on top of another, dismiss the first
and present the new one. This is important because there are (separately
filed) bugs on both platforms where the completion handler is not called;
now, instead of a tab getting stuck forever, we'll reject the promise
when another share takes place.

Tools:

* DumpRenderTree/ios/UIScriptControllerIOS.mm:
(WTR::UIScriptController::setShareSheetCompletesImmediatelyWithResolution):
(WTR::UIScriptController::invokeShareSheetWithResolution): Deleted.
* DumpRenderTree/mac/UIScriptControllerMac.mm:
(WTR::UIScriptController::setShareSheetCompletesImmediatelyWithResolution):
* TestRunnerShared/UIScriptContext/Bindings/UIScriptController.idl:
* TestRunnerShared/UIScriptContext/UIScriptController.cpp:
(WTR::UIScriptController::setShareSheetCompletesImmediatelyWithResolution):
(WTR::UIScriptController::invokeShareSheetWithResolution): Deleted.
* TestRunnerShared/UIScriptContext/UIScriptController.h:
* WebKitTestRunner/ios/UIScriptControllerIOS.mm:
(WTR::UIScriptController::setShareSheetCompletesImmediatelyWithResolution):
(WTR::UIScriptController::invokeShareSheetWithResolution): Deleted.
* WebKitTestRunner/mac/UIScriptControllerMac.mm:
(WTR::UIScriptController::setShareSheetCompletesImmediatelyWithResolution):
Change the testing mechanism for the share sheet such that we up-front
set that it should immediately return with a particular state, instead
of programmatically dismissing the sheet.

Otherwise, running the tests on macOS doesn't work, because we pop
a context menu, which spins the runloop and prevents dismissal from
going through.

LayoutTests:

* fast/events/ios/share-expected.txt: Removed.
* fast/events/ios/share.html: Removed.
* fast/web-share/share.html: Added.
* fast/web-share/share-expected.txt: Added.
* resources/ui-helper.js:
(window.UIHelper.setShareSheetCompletesImmediatelyWithResolution):
(window.UIHelper.invokeShareSheetWithResolution): Deleted.
Move the existing share sheet test to fast/web-share so it runs on both macOS and iOS.

* fast/web-share/share-with-no-url.html: Added.
* fast/web-share/share-with-no-url-expected.txt: Added.
Add a new test that the sheet is successfully invoked even when a URL is not provided.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@237012 268f45cc-cd09-0410-ab3c-d52691b4dbfc
29 files changed:
LayoutTests/ChangeLog
LayoutTests/TestExpectations
LayoutTests/fast/web-share/share-expected.txt [moved from LayoutTests/fast/events/ios/share-expected.txt with 100% similarity]
LayoutTests/fast/web-share/share-with-no-url-expected.txt [new file with mode: 0644]
LayoutTests/fast/web-share/share-with-no-url.html [new file with mode: 0644]
LayoutTests/fast/web-share/share.html [moved from LayoutTests/fast/events/ios/share.html with 76% similarity]
LayoutTests/platform/ios-wk2/TestExpectations
LayoutTests/platform/mac-wk2/TestExpectations
LayoutTests/resources/ui-helper.js
Source/WebCore/ChangeLog
Source/WebCore/page/Navigator.cpp
Source/WebCore/page/ShareData.h
Source/WebKit/ChangeLog
Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm
Source/WebKit/UIProcess/API/Cocoa/WKWebViewInternal.h
Source/WebKit/UIProcess/API/Cocoa/WKWebViewPrivate.h
Source/WebKit/UIProcess/Cocoa/WKShareSheet.h
Source/WebKit/UIProcess/Cocoa/WKShareSheet.mm
Source/WebKit/UIProcess/Cocoa/WebViewImpl.mm
Source/WebKit/UIProcess/ios/WKContentViewInteraction.h
Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm
Tools/ChangeLog
Tools/DumpRenderTree/ios/UIScriptControllerIOS.mm
Tools/DumpRenderTree/mac/UIScriptControllerMac.mm
Tools/TestRunnerShared/UIScriptContext/Bindings/UIScriptController.idl
Tools/TestRunnerShared/UIScriptContext/UIScriptController.cpp
Tools/TestRunnerShared/UIScriptContext/UIScriptController.h
Tools/WebKitTestRunner/ios/UIScriptControllerIOS.mm
Tools/WebKitTestRunner/mac/UIScriptControllerMac.mm