Skip to content
Permalink
Browse files
Navigator.share() rejects with wrong exception when called multiple t…
…imes

https://bugs.webkit.org/show_bug.cgi?id=243652

Reviewed by Chris Dumez.

Unfortunately, `run-webkit-tests` doesn't cause `isControlledByAutomation()`
to return `true`, so we can't test this directly. Instead, it needs to be run
with directly with web driver (as is done on WPT).

* LayoutTests/platform/ios-simulator-wk2/imported/w3c/web-platform-tests/web-share/share-sharePromise-internal-slot.https-expected.txt: Renamed from LayoutTests/platform/ios-simulator-wk2/share-sharePromise-internal-slot.https-expected.txt.
* LayoutTests/platform/ios-wk2/imported/w3c/web-platform-tests/web-share/share-sharePromise-internal-slot.https-expected.txt: Renamed from LayoutTests/platform/ios-wk2/share-sharePromise-internal-slot.https-expected.txt.
* Source/WebCore/page/Navigator.cpp:
(WebCore::Navigator::share):
(WebCore::Navigator::showShareData):

Canonical link: https://commits.webkit.org/253419@main
  • Loading branch information
marcoscaceres authored and djg committed Aug 15, 2022
1 parent 613f469 commit 7654da12692d947efe23243092725dc6abc96436
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 7 deletions.
@@ -0,0 +1,4 @@


PASS Only allow one share call at a time, which is controlled by the [[sharePromise]] internal slot.

@@ -1781,8 +1781,6 @@ imported/w3c/web-platform-tests/web-share/share-url-noscheme-manual.https.html [
imported/w3c/web-platform-tests/web-share/share-url-pathonly-manual.https.html [ Skip ]
imported/w3c/web-platform-tests/web-share/share-url-relative-manual.https.html [ Skip ]

imported/w3c/web-platform-tests/web-share/share-sharePromise-internal-slot.https.html [ DumpJSConsoleLogInStdErr ]

# rdar://problem/59595496
quicklook/keynote-09.html [ Failure ]
quicklook/keynote.html [ ImageOnlyFailure ]
@@ -0,0 +1,4 @@


PASS Only allow one share call at a time, which is controlled by the [[sharePromise]] internal slot.

@@ -162,7 +162,7 @@ void Navigator::share(Document& document, const ShareData& data, Ref<DeferredPro
}

if (m_hasPendingShare) {
promise->reject(NotAllowedError);
promise->reject(InvalidStateError, "share() is already in progress"_s);
return;
}

@@ -209,16 +209,22 @@ void Navigator::showShareData(ExceptionOr<ShareDataWithParsedURL&> readData, Ref
if (!frame || !frame->page())
return;

m_hasPendingShare = true;

if (frame->page()->isControlledByAutomation()) {
promise->resolve();
RunLoop::main().dispatch([promise = WTFMove(promise), weakThis = WeakPtr { *this }] {
if (weakThis)
weakThis->m_hasPendingShare = false;
promise->resolve();
});
return;
}

m_hasPendingShare = true;
auto shareData = readData.returnValue();

frame->page()->chrome().showShareSheet(shareData, [promise = WTFMove(promise), this] (bool completed) {
m_hasPendingShare = false;
frame->page()->chrome().showShareSheet(shareData, [promise = WTFMove(promise), weakThis = WeakPtr { *this }] (bool completed) {
if (weakThis)
weakThis->m_hasPendingShare = false;
if (completed) {
promise->resolve();
return;

0 comments on commit 7654da1

Please sign in to comment.