Commit 59575ceb authored by Eric Willigers's avatar Eric Willigers Committed by Commit Bot

Web Share: Share can succeed after rejected file share

If excessively large files, or too many files, were passed to
navigator.share(), we rejected the request but also incorrectly
updated state (client_ in NavigatorShare), leading to future share
attempts failing with InvalidStateError
"A earlier share had not yet completed."

We now only set client_ when we are about to make a mojo call.

Bug: 1146317
Change-Id: I8ced104d0c2486c75987847c0f23c2d632a6cc9f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2522813
Auto-Submit: Eric Willigers <ericwilligers@chromium.org>
Reviewed-by: default avatarGlen Robertson <glenrob@chromium.org>
Commit-Queue: Eric Willigers <ericwilligers@chromium.org>
Cr-Commit-Position: refs/heads/master@{#825243}
parent 168835a0
...@@ -245,9 +245,6 @@ ScriptPromise NavigatorShare::share(ScriptState* script_state, ...@@ -245,9 +245,6 @@ ScriptPromise NavigatorShare::share(ScriptState* script_state,
} }
bool has_files = HasFiles(*data); bool has_files = HasFiles(*data);
auto* resolver = MakeGarbageCollected<ScriptPromiseResolver>(script_state);
client_ = MakeGarbageCollected<ShareClientImpl>(this, has_files, resolver);
WTF::Vector<mojom::blink::SharedFilePtr> files; WTF::Vector<mojom::blink::SharedFilePtr> files;
uint64_t total_bytes = 0; uint64_t total_bytes = 0;
if (has_files) { if (has_files) {
...@@ -266,6 +263,8 @@ ScriptPromise NavigatorShare::share(ScriptState* script_state, ...@@ -266,6 +263,8 @@ ScriptPromise NavigatorShare::share(ScriptState* script_state,
} }
} }
auto* resolver = MakeGarbageCollected<ScriptPromiseResolver>(script_state);
client_ = MakeGarbageCollected<ShareClientImpl>(this, has_files, resolver);
service_remote_->Share( service_remote_->Share(
data->hasTitle() ? data->title() : g_empty_string, data->hasTitle() ? data->title() : g_empty_string,
data->hasText() ? data->text() : g_empty_string, url, std::move(files), data->hasText() ? data->text() : g_empty_string, url, std::move(files),
......
...@@ -85,4 +85,31 @@ share_test(mock => { ...@@ -85,4 +85,31 @@ share_test(mock => {
} ); } );
}, 'only one share at a time'); }, 'only one share at a time');
share_test(mock => {
mock.pushShareResult('the title', 'the message', 'https://example.com/',
blink.mojom.ShareError.CANCELED);
return callWithKeyDown(async () => {
const content = ['Hello'];
const name = 'hello.txt';
const options = {type: 'text/plain'};
const excess_file_data = {
files: Array(11).fill(new File(content, name, options))
};
await assertRejectsWithError(
navigator.share(excess_file_data),
'NotAllowedError');
return callWithKeyDown(async () => {
const data = {
title: 'the title',
text: 'the message',
url: 'https://example.com/'
};
return assertRejectsWithError(
navigator.share(data),
'AbortError');
});
} );
}, 'Failed file share does not lead to InvalidStateError');
</script> </script>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment