Title: [237012] trunk
Revision
237012
Author
[email protected]
Date
2018-10-10 12:05:03 -0700 (Wed, 10 Oct 2018)

Log Message

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.

Modified Paths

Added Paths

Removed Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (237011 => 237012)


--- trunk/LayoutTests/ChangeLog	2018-10-10 18:43:20 UTC (rev 237011)
+++ trunk/LayoutTests/ChangeLog	2018-10-10 19:05:03 UTC (rev 237012)
@@ -1,3 +1,23 @@
+2018-10-10  Tim Horton  <[email protected]>
+
+        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.
+
+        * 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.
+
 2018-10-10  Devin Rousso  <[email protected]>
 
         Web Inspector: notify the frontend when a canvas has started recording via console.record

Modified: trunk/LayoutTests/TestExpectations (237011 => 237012)


--- trunk/LayoutTests/TestExpectations	2018-10-10 18:43:20 UTC (rev 237011)
+++ trunk/LayoutTests/TestExpectations	2018-10-10 19:05:03 UTC (rev 237012)
@@ -420,6 +420,9 @@
 # This test currently only works for mac-wk2
 fast/events/inactive-window-no-mouse-event.html [ Skip ]
 
+# The Web Share API is currently only implemented for modern WebKit on iOS and macOS
+fast/web-share [ Skip ]
+
 #//////////////////////////////////////////////////////////////////////////////////////////
 # End platform-specific tests.
 #//////////////////////////////////////////////////////////////////////////////////////////

Deleted: trunk/LayoutTests/fast/events/ios/share-expected.txt (237011 => 237012)


--- trunk/LayoutTests/fast/events/ios/share-expected.txt	2018-10-10 18:43:20 UTC (rev 237011)
+++ trunk/LayoutTests/fast/events/ios/share-expected.txt	2018-10-10 19:05:03 UTC (rev 237012)
@@ -1,2 +0,0 @@
-PASS: Share sheet invoked.
-

Deleted: trunk/LayoutTests/fast/events/ios/share.html (237011 => 237012)


--- trunk/LayoutTests/fast/events/ios/share.html	2018-10-10 18:43:20 UTC (rev 237011)
+++ trunk/LayoutTests/fast/events/ios/share.html	2018-10-10 19:05:03 UTC (rev 237012)
@@ -1,45 +0,0 @@
-<!DOCTYPE html> <!-- webkit-test-runner [ useFlexibleViewport=true ] -->
-
-<html>
-<meta name="viewport" content="initial-scale=5, width=device-width">
-<head>
-
-    <script src=""
-    <script>
-        
-        if (window.testRunner) {
-            testRunner.dumpAsText();
-            testRunner.waitUntilDone();
-        }
-    
-        let write = (message) => output.innerHTML += (message + "<br>");
-
-        async function runTest()
-        {
-            document.getElementById("target").addEventListener("click", async () => {
-                navigator.share({ title: "Example Page", url: "url", text: "text" }).then((result) => {
-                    write("PASS: Share sheet invoked.");
-                    testRunner.notifyDone();
-                });
-                UIHelper.invokeShareSheetWithResolution(true);
-            });
-            await UIHelper.activateAt(50, 50);
-        }
-
-    </script>
-    <style>
-        #target {
-            height: 100px;
-            width: 100px;
-            background-color: silver;
-        }
-    </style>
-</head>
-<body _onload_="runTest()">
-<pre id="output"></pre>
-<button id="target">
-</button>
-
-</body>
-</html>
-

Copied: trunk/LayoutTests/fast/web-share/share-expected.txt (from rev 237011, trunk/LayoutTests/fast/events/ios/share-expected.txt) (0 => 237012)


--- trunk/LayoutTests/fast/web-share/share-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/web-share/share-expected.txt	2018-10-10 19:05:03 UTC (rev 237012)
@@ -0,0 +1,2 @@
+PASS: Share sheet invoked.
+

Copied: trunk/LayoutTests/fast/web-share/share-with-no-url-expected.txt (from rev 237011, trunk/LayoutTests/fast/events/ios/share-expected.txt) (0 => 237012)


--- trunk/LayoutTests/fast/web-share/share-with-no-url-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/web-share/share-with-no-url-expected.txt	2018-10-10 19:05:03 UTC (rev 237012)
@@ -0,0 +1,2 @@
+PASS: Share sheet invoked.
+

Copied: trunk/LayoutTests/fast/web-share/share-with-no-url.html (from rev 237011, trunk/LayoutTests/fast/events/ios/share.html) (0 => 237012)


--- trunk/LayoutTests/fast/web-share/share-with-no-url.html	                        (rev 0)
+++ trunk/LayoutTests/fast/web-share/share-with-no-url.html	2018-10-10 19:05:03 UTC (rev 237012)
@@ -0,0 +1,47 @@
+<!DOCTYPE html> <!-- webkit-test-runner [ useFlexibleViewport=true ] -->
+
+<html>
+<meta name="viewport" content="initial-scale=5, width=device-width">
+<head>
+
+    <script src=""
+    <script>
+        
+        if (window.testRunner) {
+            testRunner.dumpAsText();
+            testRunner.waitUntilDone();
+        }
+    
+        let write = (message) => output.innerHTML += (message + "<br>");
+
+        function runTest()
+        {
+            document.getElementById("target").addEventListener("click", () => {
+                navigator.share({ text: "text" }).then((result) => {
+                    write("PASS: Share sheet invoked.");
+                    testRunner.notifyDone();
+                });    
+            });
+            
+            UIHelper.setShareSheetCompletesImmediatelyWithResolution(true).then(() => {
+                UIHelper.activateAt(50, 50);
+            });
+        }
+
+    </script>
+    <style>
+        #target {
+            height: 100px;
+            width: 100px;
+            background-color: silver;
+        }
+    </style>
+</head>
+<body _onload_="runTest()">
+<pre id="output"></pre>
+<button id="target">
+</button>
+
+</body>
+</html>
+

Copied: trunk/LayoutTests/fast/web-share/share.html (from rev 237011, trunk/LayoutTests/fast/events/ios/share.html) (0 => 237012)


--- trunk/LayoutTests/fast/web-share/share.html	                        (rev 0)
+++ trunk/LayoutTests/fast/web-share/share.html	2018-10-10 19:05:03 UTC (rev 237012)
@@ -0,0 +1,47 @@
+<!DOCTYPE html> <!-- webkit-test-runner [ useFlexibleViewport=true ] -->
+
+<html>
+<meta name="viewport" content="initial-scale=5, width=device-width">
+<head>
+
+    <script src=""
+    <script>
+        
+        if (window.testRunner) {
+            testRunner.dumpAsText();
+            testRunner.waitUntilDone();
+        }
+    
+        let write = (message) => output.innerHTML += (message + "<br>");
+
+        function runTest()
+        {
+            document.getElementById("target").addEventListener("click", () => {
+                navigator.share({ title: "Example Page", url: "url", text: "text" }).then((result) => {
+                    write("PASS: Share sheet invoked.");
+                    testRunner.notifyDone();
+                });    
+            });
+            
+            UIHelper.setShareSheetCompletesImmediatelyWithResolution(true).then(() => {
+                UIHelper.activateAt(50, 50);
+            });
+        }
+
+    </script>
+    <style>
+        #target {
+            height: 100px;
+            width: 100px;
+            background-color: silver;
+        }
+    </style>
+</head>
+<body _onload_="runTest()">
+<pre id="output"></pre>
+<button id="target">
+</button>
+
+</body>
+</html>
+

Modified: trunk/LayoutTests/platform/ios-wk2/TestExpectations (237011 => 237012)


--- trunk/LayoutTests/platform/ios-wk2/TestExpectations	2018-10-10 18:43:20 UTC (rev 237011)
+++ trunk/LayoutTests/platform/ios-wk2/TestExpectations	2018-10-10 19:05:03 UTC (rev 237012)
@@ -13,6 +13,8 @@
 fast/visual-viewport/ios/ [ Pass ]
 scrollingcoordinator/ios [ Pass ]
 tiled-drawing/ios [ Pass ]
+fast/web-share [ Pass ]
+
 editing/selection/character-granularity-rect.html [ Failure ]
 
 accessibility/smart-invert.html [ Pass ]

Modified: trunk/LayoutTests/platform/mac-wk2/TestExpectations (237011 => 237012)


--- trunk/LayoutTests/platform/mac-wk2/TestExpectations	2018-10-10 18:43:20 UTC (rev 237011)
+++ trunk/LayoutTests/platform/mac-wk2/TestExpectations	2018-10-10 19:05:03 UTC (rev 237012)
@@ -9,6 +9,7 @@
 tiled-drawing/ios [ Skip ]
 fast/visual-viewport/tiled-drawing [ Pass ]
 swipe [ Pass ]
+fast/web-share [ Pass ]
 
 fast/events/autoscroll-when-zoomed.html [ Pass ]
 fast/events/autoscroll-main-document.html [ Pass ]

Modified: trunk/LayoutTests/resources/ui-helper.js (237011 => 237012)


--- trunk/LayoutTests/resources/ui-helper.js	2018-10-10 18:43:20 UTC (rev 237011)
+++ trunk/LayoutTests/resources/ui-helper.js	2018-10-10 19:05:03 UTC (rev 237012)
@@ -262,9 +262,9 @@
         return new Promise(resolve => testRunner.runUIScript(setValueScript, resolve));
     }
 
-    static invokeShareSheetWithResolution(resolved)
+    static setShareSheetCompletesImmediatelyWithResolution(resolved)
     {
-        const resolveShareSheet = `(() => uiController.invokeShareSheetWithResolution(${resolved}))()`;
+        const resolveShareSheet = `(() => uiController.setShareSheetCompletesImmediatelyWithResolution(${resolved}))()`;
         return new Promise(resolve => testRunner.runUIScript(resolveShareSheet, resolve));
     }
 

Modified: trunk/Source/WebCore/ChangeLog (237011 => 237012)


--- trunk/Source/WebCore/ChangeLog	2018-10-10 18:43:20 UTC (rev 237011)
+++ trunk/Source/WebCore/ChangeLog	2018-10-10 19:05:03 UTC (rev 237012)
@@ -1,3 +1,18 @@
+2018-10-10  Tim Horton  <[email protected]>
+
+        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.
+
+        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).
+
 2018-10-10  Devin Rousso  <[email protected]>
 
         Web Inspector: notify the frontend when a canvas has started recording via console.record

Modified: trunk/Source/WebCore/page/Navigator.cpp (237011 => 237012)


--- trunk/Source/WebCore/page/Navigator.cpp	2018-10-10 18:43:20 UTC (rev 237011)
+++ trunk/Source/WebCore/page/Navigator.cpp	2018-10-10 19:05:03 UTC (rev 237012)
@@ -118,11 +118,14 @@
         promise->reject(TypeError);
         return;
     }
-    
-    URL url = ""
-    if (!url.isValid()) {
-        promise->reject(TypeError);
-        return;
+
+    std::optional<URL> url;
+    if (!data.url.isEmpty()) {
+        url = ""
+        if (!url->isValid()) {
+            promise->reject(TypeError);
+            return;
+        }
     }
     
     if (!UserGestureIndicator::processingUserGesture()) {

Modified: trunk/Source/WebCore/page/ShareData.h (237011 => 237012)


--- trunk/Source/WebCore/page/ShareData.h	2018-10-10 18:43:20 UTC (rev 237011)
+++ trunk/Source/WebCore/page/ShareData.h	2018-10-10 19:05:03 UTC (rev 237012)
@@ -36,7 +36,7 @@
     
 struct ShareDataWithParsedURL {
     ShareData shareData;
-    URL url;
+    std::optional<URL> url;
 };
     
 }

Modified: trunk/Source/WebKit/ChangeLog (237011 => 237012)


--- trunk/Source/WebKit/ChangeLog	2018-10-10 18:43:20 UTC (rev 237011)
+++ trunk/Source/WebKit/ChangeLog	2018-10-10 19:05:03 UTC (rev 237012)
@@ -1,5 +1,55 @@
 2018-10-10  Tim Horton  <[email protected]>
 
+        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.
+
+        * 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.
+
+2018-10-10  Tim Horton  <[email protected]>
+
         REGRESSION (r236678): Keyboard scrolling with arrow keys doesn't work on iOS
         https://bugs.webkit.org/show_bug.cgi?id=190433
         <rdar://problem/45111986>

Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm (237011 => 237012)


--- trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm	2018-10-10 18:43:20 UTC (rev 237011)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm	2018-10-10 19:05:03 UTC (rev 237012)
@@ -263,6 +263,8 @@
 
     WeakObjCPtr<id <_WKInputDelegate>> _inputDelegate;
 
+    std::optional<BOOL> _resolutionForShareSheetImmediateCompletionForTesting;
+
 #if PLATFORM(IOS)
     RetainPtr<_WKRemoteObjectRegistry> _remoteObjectRegistry;
 
@@ -4252,6 +4254,11 @@
     return WebCore::SchemeRegistry::isBuiltinScheme(urlScheme);
 }
 
+- (std::optional<BOOL>)_resolutionForShareSheetImmediateCompletionForTesting
+{
+    return _resolutionForShareSheetImmediateCompletionForTesting;
+}
+
 @end
 
 @implementation WKWebView (WKPrivate)
@@ -6074,11 +6081,6 @@
     [_contentView setTimePickerValueToHour:hour minute:minute];
 }
 
-- (void)_invokeShareSheetWithResolution:(BOOL)resolved
-{
-    [_contentView invokeShareSheetWithResolution:resolved];
-}
-
 - (void)selectFormAccessoryPickerRow:(int)rowIndex
 {
     [_contentView selectFormAccessoryPickerRow:rowIndex];
@@ -6624,6 +6626,11 @@
     _page->setDefersLoadingForTesting(defersLoading);
 }
 
+- (void)_setShareSheetCompletesImmediatelyWithResolutionForTesting:(BOOL)resolved
+{
+    _resolutionForShareSheetImmediateCompletionForTesting = resolved;
+}
+
 - (_WKInspector *)_inspector
 {
     if (auto* inspector = _page->inspector())

Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebViewInternal.h (237011 => 237012)


--- trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebViewInternal.h	2018-10-10 18:43:20 UTC (rev 237011)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebViewInternal.h	2018-10-10 19:05:03 UTC (rev 237012)
@@ -170,6 +170,8 @@
 - (void)_didInsertAttachment:(API::Attachment&)attachment withSource:(NSString *)source;
 #endif
 
+- (std::optional<BOOL>)_resolutionForShareSheetImmediateCompletionForTesting;
+
 - (WKPageRef)_pageForTesting;
 - (WebKit::WebPageProxy*)_page;
 

Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebViewPrivate.h (237011 => 237012)


--- trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebViewPrivate.h	2018-10-10 18:43:20 UTC (rev 237011)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebViewPrivate.h	2018-10-10 19:05:03 UTC (rev 237012)
@@ -409,8 +409,6 @@
 @property (nonatomic, readonly) NSString *formInputLabel WK_API_AVAILABLE(ios(12.0));
 - (void)setTimePickerValueToHour:(NSInteger)hour minute:(NSInteger)minute WK_API_AVAILABLE(ios(12.0));
 
-- (void)_invokeShareSheetWithResolution:(BOOL)resolved WK_API_AVAILABLE(ios(WK_IOS_TBA));
-
 - (void)applyAutocorrection:(NSString *)newString toString:(NSString *)oldString withCompletionHandler:(void (^)(void))completionHandler WK_API_AVAILABLE(ios(11.0));
 
 - (void)didStartFormControlInteraction WK_API_AVAILABLE(ios(10.3));
@@ -499,6 +497,8 @@
 - (BOOL)_completeBackSwipeForTesting;
 - (void)_setDefersLoadingForTesting:(BOOL)defersLoading;
 
+- (void)_setShareSheetCompletesImmediatelyWithResolutionForTesting:(BOOL)resolved WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
+
 @property (nonatomic, readonly) _WKInspector *_inspector WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
 @property (nonatomic, readonly) _WKFrameHandle *_mainFrame WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
 

Modified: trunk/Source/WebKit/UIProcess/Cocoa/WKShareSheet.h (237011 => 237012)


--- trunk/Source/WebKit/UIProcess/Cocoa/WKShareSheet.h	2018-10-10 18:43:20 UTC (rev 237011)
+++ trunk/Source/WebKit/UIProcess/Cocoa/WKShareSheet.h	2018-10-10 19:05:03 UTC (rev 237012)
@@ -27,35 +27,22 @@
 
 #if PLATFORM(COCOA) && !PLATFORM(WATCHOS) && !PLATFORM(APPLETV) && WK_API_ENABLED
 
-#import <WebCore/ShareData.h>
-#import <wtf/BlockPtr.h>
-#import <wtf/Forward.h>
-#import <wtf/Vector.h>
-#import <wtf/WeakObjCPtr.h>
-#import <wtf/text/WTFString.h>
+@class WKWebView;
+@protocol WKShareSheetDelegate;
 
-#if PLATFORM(IOS)
-#import <UIKit/UIKit.h>
-#else
-#import "WKWebView.h"
-#endif
+namespace WebCore {
+struct ShareDataWithParsedURL;
+}
 
-@class WKContentView;
-@protocol WKShareSheetDelegate;
+@interface WKShareSheet : NSObject
 
-#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;
-- (void)invokeShareSheetWithResolution:(BOOL)resolved;
 
 @property (nonatomic, weak) id <WKShareSheetDelegate> delegate;
+
 @end
 
 @protocol WKShareSheetDelegate <NSObject>
@@ -63,4 +50,4 @@
 - (void)shareSheetDidDismiss:(WKShareSheet *)shareSheet;
 @end
 
-#endif // !PLATFORM(WATCHOS) && !PLATFORM(APPLETV)
+#endif // PLATFORM(COCOA) && !PLATFORM(WATCHOS) && !PLATFORM(APPLETV) && WK_API_ENABLED

Modified: trunk/Source/WebKit/UIProcess/Cocoa/WKShareSheet.mm (237011 => 237012)


--- trunk/Source/WebKit/UIProcess/Cocoa/WKShareSheet.mm	2018-10-10 18:43:20 UTC (rev 237011)
+++ trunk/Source/WebKit/UIProcess/Cocoa/WKShareSheet.mm	2018-10-10 19:05:03 UTC (rev 237012)
@@ -28,7 +28,7 @@
 
 #if PLATFORM(COCOA) && !PLATFORM(WATCHOS) && !PLATFORM(APPLETV) && WK_API_ENABLED
 
-#import "WKContentViewInteraction.h"
+#import "WKWebViewInternal.h"
 #import "WebPageProxy.h"
 #import <WebCore/ShareData.h>
 #import <wtf/RetainPtr.h>
@@ -36,40 +36,35 @@
 
 #if PLATFORM(IOS)
 #import "UIKitSPI.h"
+#import "WKContentViewInteraction.h"
 #else
-#import "WKWebView.h"
+#import <pal/spi/mac/NSSharingServicePickerSPI.h>
 #endif
 
-using namespace WebKit;
+#if PLATFORM(MAC)
+@interface WKShareSheet () <NSSharingServicePickerDelegate>
+@end
+#endif
 
 @implementation WKShareSheet {
+    WeakObjCPtr<WKWebView> _webView;
+    WTF::CompletionHandler<void(bool)> _completionHandler;
+
 #if PLATFORM(MAC)
-    WeakObjCPtr<WKWebView> _view;
-
-    BOOL _isShowingSharingServicePicker;
-    RetainPtr<NSSharingServicePicker> _sharingServicePickerForMenu;
-    WTF::CompletionHandler<void(bool)> _completionHandler;
+    RetainPtr<NSSharingServicePicker> _sharingServicePicker;
 #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
+
+    _webView = view;
+
     return self;
 }
 
@@ -80,8 +75,8 @@
     if (!data.shareData.text.isEmpty())
         [shareDataArray addObject:(NSString *)data.shareData.text];
     
-    if (!data.url.isNull()) {
-        NSURL *url = "" *)data.url;
+    if (data.url) {
+        NSURL *url = "" *)data.url.value();
 #if PLATFORM(IOS)
         if (!data.shareData.title.isEmpty())
             url._title = data.shareData.title;
@@ -91,92 +86,80 @@
     
     if (!data.shareData.title.isEmpty() && ![shareDataArray count])
         [shareDataArray addObject:(NSString *)data.shareData.title];
+
+    _completionHandler = WTFMove(completionHandler);
+
+    if (auto resolution = [_webView _resolutionForShareSheetImmediateCompletionForTesting]) {
+        [self _didCompleteWithSuccess:*resolution];
+        [self dismiss];
+        return;
+    }
     
 #if PLATFORM(MAC)
-    _sharingServicePickerForMenu = adoptNS([[NSSharingServicePicker alloc] initWithItems:shareDataArray.get()]);
-    _sharingServicePickerForMenu.get().delegate = self;
-    _completionHandler = WTFMove(completionHandler);
+    _sharingServicePicker = adoptNS([[NSSharingServicePicker alloc] initWithItems:shareDataArray.get()]);
+    _sharingServicePicker.get().delegate = self;
     
     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];
+    NSRect mouseLocationInWindow = [[_webView window] convertRectFromScreen:mouseLocationRect];
+    NSRect mouseLocationInView = [_webView convertRect:mouseLocationInWindow fromView:nil];
+    [_sharingServicePicker showRelativeToRect:mouseLocationInView ofView:_webView.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 {
-        completionHandler(completed);
-        [shareSheet dismiss];
-    });
-    
-    shareSheetController.get().completionWithItemsHandler = completionHandlerBlock.get();
-    _shareSheetViewController = WTFMove(shareSheetController);
-    [self _presentFullscreenViewController:_shareSheetViewController.get() animated:YES];
+    _shareSheetViewController = adoptNS([[UIActivityViewController alloc] initWithActivityItems:shareDataArray.get() applicationActivities:nil]);
+    [_shareSheetViewController setCompletionWithItemsHandler:^(NSString *, BOOL completed, NSArray *, NSError *) {
+        [self _didCompleteWithSuccess:completed];
+        [self dispatchDidDismiss];
+    }];
+    _presentationViewController = [UIViewController _viewControllerForFullScreenPresentationFromView:_webView.getAutoreleased()];
+    [_presentationViewController presentViewController:_shareSheetViewController.get() animated:YES completion:nil];
 #endif
 }
 
 #if PLATFORM(MAC)
-- (void)sharingServicePicker:(NSSharingServicePicker *)sharingServicePicker didChooseSharingService:(nullable NSSharingService *)service
+- (void)sharingServicePicker:(NSSharingServicePicker *)sharingServicePicker didChooseSharingService:(NSSharingService *)service
 {
-    self->_completionHandler(!service);
-    [self _dispatchDidDismiss];
+    [self _didCompleteWithSuccess:!!service];
+    [self dispatchDidDismiss];
 }
-
 #endif
-- (void)_dispatchDidDismiss
-{
-    if ([_delegate respondsToSelector:@selector(shareSheetDidDismiss:)])
-        [_delegate shareSheetDidDismiss:self];
-}
 
-- (void)_cancel
+- (void)_didCompleteWithSuccess:(BOOL)success
 {
-#if PLATFORM(IOS)
-    [self _dispatchDidDismiss];
-#endif
+    auto completionHandler = WTFMove(_completionHandler);
+    if (completionHandler)
+        completionHandler(success);
 }
 
 - (void)dismiss
 {
-#if PLATFORM(IOS)
-    [[UIViewController _viewControllerForFullScreenPresentationFromView:_view.getAutoreleased()] dismissViewControllerAnimated:_shouldDismissWithAnimation completion:nil];
-    _presentationViewController = nil;
-    
-    [self _cancel];
-#endif
-}
+    // If programmatically dismissed without having already called the
+    // completion handler, call it assuming failure.
+    [self _didCompleteWithSuccess:NO];
 
-#if PLATFORM(IOS)
+#if PLATFORM(MAC)
+    [_sharingServicePicker hide];
+    [self dispatchDidDismiss];
+#else
+    if (!_presentationViewController)
+        return;
 
-- (void)_dismissDisplayAnimated:(BOOL)animated
-{
-    if (_presentationViewController) {
-        UIViewController *currentPresentedViewController = [_presentationViewController presentedViewController];
-        if (currentPresentedViewController == _shareSheetViewController) {
-            [currentPresentedViewController dismissViewControllerAnimated:animated completion:^{
-                _presentationViewController = nil;
-            }];
-        }
-    }
-}
+    UIViewController *currentPresentedViewController = [_presentationViewController presentedViewController];
+    if (currentPresentedViewController != _shareSheetViewController)
+        return;
 
-- (void)_presentFullscreenViewController:(UIViewController *)viewController animated:(BOOL)animated
-{
-    _presentationViewController = [UIViewController _viewControllerForFullScreenPresentationFromView:_view.getAutoreleased()];
-    [_presentationViewController presentViewController:viewController animated:animated completion:nil];
+    [currentPresentedViewController dismissViewControllerAnimated:YES completion:^{
+        [self dispatchDidDismiss];
+        _presentationViewController = nil;
+    }];
+#endif
 }
-#endif
 
-- (void)invokeShareSheetWithResolution:(BOOL)resolved
+- (void)dispatchDidDismiss
 {
-#if PLATFORM(IOS)
-    _shouldDismissWithAnimation = NO;
-    _shareSheetViewController.get().completionWithItemsHandler(nil, resolved, nil, nil);
-#else
-    _completionHandler(resolved);
-#endif
+    if ([_delegate respondsToSelector:@selector(shareSheetDidDismiss:)])
+        [_delegate shareSheetDidDismiss:self];
 }
 
 @end
-#endif // !PLATFORM(WATCHOS) && !PLATFORM(APPLETV)
+
+#endif // PLATFORM(COCOA) && !PLATFORM(WATCHOS) && !PLATFORM(APPLETV) && WK_API_ENABLED

Modified: trunk/Source/WebKit/UIProcess/Cocoa/WebViewImpl.mm (237011 => 237012)


--- trunk/Source/WebKit/UIProcess/Cocoa/WebViewImpl.mm	2018-10-10 18:43:20 UTC (rev 237011)
+++ trunk/Source/WebKit/UIProcess/Cocoa/WebViewImpl.mm	2018-10-10 19:05:03 UTC (rev 237012)
@@ -2758,9 +2758,8 @@
 #if WK_API_ENABLED
 void WebViewImpl::showShareSheet(const WebCore::ShareDataWithParsedURL& data, WTF::CompletionHandler<void(bool)>&& completionHandler, WKWebView *view)
 {
-    ASSERT(!_shareSheet);
     if (_shareSheet)
-        return;
+        [_shareSheet dismiss];
     
     ASSERT([view respondsToSelector:@selector(shareSheetDidDismiss:)]);
     _shareSheet = adoptNS([[WKShareSheet alloc] initWithView:view]);

Modified: trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.h (237011 => 237012)


--- trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.h	2018-10-10 18:43:20 UTC (rev 237011)
+++ trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.h	2018-10-10 19:05:03 UTC (rev 237012)
@@ -400,7 +400,6 @@
 - (void)_simulateTextEntered:(NSString *)text;
 - (void)selectFormAccessoryPickerRow:(NSInteger)rowIndex;
 - (void)setTimePickerValueToHour:(NSInteger)hour minute:(NSInteger)minute;
-- (void)invokeShareSheetWithResolution:(BOOL)resolved;
 - (NSDictionary *)_contentsOfUserInterfaceItem:(NSString *)userInterfaceItem;
 
 @property (nonatomic, readonly) NSString *textContentTypeForTesting;

Modified: trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm (237011 => 237012)


--- trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm	2018-10-10 18:43:20 UTC (rev 237011)
+++ trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm	2018-10-10 19:05:03 UTC (rev 237012)
@@ -4817,11 +4817,10 @@
 - (void)_showShareSheet:(const ShareDataWithParsedURL&)data completionHandler:(CompletionHandler<void(bool)>&&)completionHandler
 {
 #if !PLATFORM(WATCHOS) && !PLATFORM(APPLETV)
-    ASSERT(!_shareSheet);
     if (_shareSheet)
-        return;
+        [_shareSheet dismiss];
     
-    _shareSheet = adoptNS([[WKShareSheet alloc] initWithView:self]);
+    _shareSheet = adoptNS([[WKShareSheet alloc] initWithView:_webView]);
     [_shareSheet setDelegate:self];
     
     [_shareSheet presentWithParameters:data completionHandler:WTFMove(completionHandler)];
@@ -6010,13 +6009,6 @@
 #endif
 }
 
-- (void)invokeShareSheetWithResolution:(BOOL)resolved
-{
-#if !PLATFORM(WATCHOS) && !PLATFORM(APPLETV)
-    [_shareSheet invokeShareSheetWithResolution:resolved];
-#endif
-}
-
 - (NSDictionary *)_contentsOfUserInterfaceItem:(NSString *)userInterfaceItem
 {
     if ([userInterfaceItem isEqualToString:@"actionSheet"])

Modified: trunk/Tools/ChangeLog (237011 => 237012)


--- trunk/Tools/ChangeLog	2018-10-10 18:43:20 UTC (rev 237011)
+++ trunk/Tools/ChangeLog	2018-10-10 19:05:03 UTC (rev 237012)
@@ -1,3 +1,33 @@
+2018-10-10  Tim Horton  <[email protected]>
+
+        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.
+
+        * 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.
+
 2018-10-10  Yusuke Suzuki  <[email protected]>
 
         [JSC] Rename createXXX to tryCreateXXX if it can return RefPtr

Modified: trunk/Tools/DumpRenderTree/ios/UIScriptControllerIOS.mm (237011 => 237012)


--- trunk/Tools/DumpRenderTree/ios/UIScriptControllerIOS.mm	2018-10-10 18:43:20 UTC (rev 237011)
+++ trunk/Tools/DumpRenderTree/ios/UIScriptControllerIOS.mm	2018-10-10 19:05:03 UTC (rev 237012)
@@ -159,7 +159,7 @@
 {
 }
 
-void UIScriptController::invokeShareSheetWithResolution(bool)
+void UIScriptController::setShareSheetCompletesImmediatelyWithResolution(bool)
 {
 }
 

Modified: trunk/Tools/DumpRenderTree/mac/UIScriptControllerMac.mm (237011 => 237012)


--- trunk/Tools/DumpRenderTree/mac/UIScriptControllerMac.mm	2018-10-10 18:43:20 UTC (rev 237011)
+++ trunk/Tools/DumpRenderTree/mac/UIScriptControllerMac.mm	2018-10-10 19:05:03 UTC (rev 237012)
@@ -185,6 +185,10 @@
     return false;
 }
 
+void UIScriptController::setShareSheetCompletesImmediatelyWithResolution(bool)
+{
 }
 
+}
+
 #endif // PLATFORM(MAC)

Modified: trunk/Tools/TestRunnerShared/UIScriptContext/Bindings/UIScriptController.idl (237011 => 237012)


--- trunk/Tools/TestRunnerShared/UIScriptContext/Bindings/UIScriptController.idl	2018-10-10 18:43:20 UTC (rev 237011)
+++ trunk/Tools/TestRunnerShared/UIScriptContext/Bindings/UIScriptController.idl	2018-10-10 19:05:03 UTC (rev 237012)
@@ -194,7 +194,7 @@
     void setTimePickerValue(long hour, long minute);
 
     // Share sheet
-    void invokeShareSheetWithResolution(boolean resolved);
+    void setShareSheetCompletesImmediatelyWithResolution(boolean resolved);
 
     // <datalist>
     readonly attribute boolean isShowingDataListSuggestions;

Modified: trunk/Tools/TestRunnerShared/UIScriptContext/UIScriptController.cpp (237011 => 237012)


--- trunk/Tools/TestRunnerShared/UIScriptContext/UIScriptController.cpp	2018-10-10 18:43:20 UTC (rev 237011)
+++ trunk/Tools/TestRunnerShared/UIScriptContext/UIScriptController.cpp	2018-10-10 19:05:03 UTC (rev 237012)
@@ -294,10 +294,6 @@
 {
 }
 
-void UIScriptController::invokeShareSheetWithResolution(bool)
-{
-}
-
 void UIScriptController::selectFormAccessoryPickerRow(long)
 {
 }
@@ -494,6 +490,10 @@
 {
 }
 
+void UIScriptController::setShareSheetCompletesImmediatelyWithResolution(bool)
+{
+}
+
 #endif // !PLATFORM(COCOA)
 
 #if !PLATFORM(MAC)

Modified: trunk/Tools/TestRunnerShared/UIScriptContext/UIScriptController.h (237011 => 237012)


--- trunk/Tools/TestRunnerShared/UIScriptContext/UIScriptController.h	2018-10-10 18:43:20 UTC (rev 237011)
+++ trunk/Tools/TestRunnerShared/UIScriptContext/UIScriptController.h	2018-10-10 19:05:03 UTC (rev 237012)
@@ -101,7 +101,7 @@
     JSRetainPtr<JSStringRef> formInputLabel() const;
     void setTimePickerValue(long hour, long minute);
 
-    void invokeShareSheetWithResolution(bool resolved);
+    void setShareSheetCompletesImmediatelyWithResolution(bool resolved);
 
     bool isShowingDataListSuggestions() const;
 

Modified: trunk/Tools/WebKitTestRunner/ios/UIScriptControllerIOS.mm (237011 => 237012)


--- trunk/Tools/WebKitTestRunner/ios/UIScriptControllerIOS.mm	2018-10-10 18:43:20 UTC (rev 237011)
+++ trunk/Tools/WebKitTestRunner/ios/UIScriptControllerIOS.mm	2018-10-10 19:05:03 UTC (rev 237012)
@@ -410,10 +410,10 @@
     [webView setTimePickerValueToHour:hour minute:minute];
 }
 
-void UIScriptController::invokeShareSheetWithResolution(bool resolved)
+void UIScriptController::setShareSheetCompletesImmediatelyWithResolution(bool resolved)
 {
     TestRunnerWKWebView *webView = TestController::singleton().mainWebView()->platformView();
-    [webView _invokeShareSheetWithResolution:resolved];
+    [webView _setShareSheetCompletesImmediatelyWithResolutionForTesting:resolved];
 }
     
 JSObjectRef UIScriptController::contentsOfUserInterfaceItem(JSStringRef interfaceItem) const

Modified: trunk/Tools/WebKitTestRunner/mac/UIScriptControllerMac.mm (237011 => 237012)


--- trunk/Tools/WebKitTestRunner/mac/UIScriptControllerMac.mm	2018-10-10 18:43:20 UTC (rev 237011)
+++ trunk/Tools/WebKitTestRunner/mac/UIScriptControllerMac.mm	2018-10-10 19:05:03 UTC (rev 237012)
@@ -270,4 +270,14 @@
     return [window firstResponder] == [window contentView];
 }
 
+void UIScriptController::setShareSheetCompletesImmediatelyWithResolution(bool resolved)
+{
+#if WK_API_ENABLED
+    TestRunnerWKWebView *webView = TestController::singleton().mainWebView()->platformView();
+    [webView _setShareSheetCompletesImmediatelyWithResolutionForTesting:resolved];
+#else
+    UNUSED_PARAM(resolved);
+#endif
+}
+
 } // namespace WTR
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to