Commit d7edd336 authored by Mustaq Ahmed's avatar Mustaq Ahmed Committed by Chromium LUCI CQ

Consume user activation on PaymentRequest.show().

This change is behind a flag.

Fixed: 1130553
Change-Id: I07c96c2bc53b402170029d66b4c99eb47d6a5e01
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2633364
Commit-Queue: Mustaq Ahmed <mustaq@chromium.org>
Reviewed-by: default avatarDanyao Wang <danyao@chromium.org>
Cr-Commit-Position: refs/heads/master@{#845241}
parent 4977fb95
...@@ -808,8 +808,8 @@ ScriptPromise PaymentRequest::show(ScriptState* script_state, ...@@ -808,8 +808,8 @@ ScriptPromise PaymentRequest::show(ScriptState* script_state,
return ScriptPromise(); return ScriptPromise();
} }
bool is_user_gesture = LocalFrame* local_frame = DomWindow()->GetFrame();
LocalFrame::HasTransientUserActivation(DomWindow()->GetFrame()); bool is_user_gesture = LocalFrame::HasTransientUserActivation(local_frame);
if (!is_user_gesture) { if (!is_user_gesture) {
UseCounter::Count(GetExecutionContext(), UseCounter::Count(GetExecutionContext(),
WebFeature::kPaymentRequestShowWithoutGesture); WebFeature::kPaymentRequestShowWithoutGesture);
...@@ -817,12 +817,17 @@ ScriptPromise PaymentRequest::show(ScriptState* script_state, ...@@ -817,12 +817,17 @@ ScriptPromise PaymentRequest::show(ScriptState* script_state,
if (RuntimeEnabledFeatures::PaymentRequestShowConsumesUserActivationEnabled( if (RuntimeEnabledFeatures::PaymentRequestShowConsumesUserActivationEnabled(
GetExecutionContext())) { GetExecutionContext())) {
if (!is_user_gesture) { if (!is_user_gesture) {
exception_state.ThrowDOMException( String message =
DOMExceptionCode::kNotAllowedError, "PaymentRequest.show() requires transient user activation";
"show() must be called with transient user activation"); GetExecutionContext()->AddConsoleMessage(
MakeGarbageCollected<ConsoleMessage>(
mojom::blink::ConsoleMessageSource::kJavaScript,
mojom::blink::ConsoleMessageLevel::kWarning, message));
exception_state.ThrowDOMException(DOMExceptionCode::kNotAllowedError,
message);
return ScriptPromise(); return ScriptPromise();
} }
// TODO(crbug.com/1130553): consume the user activation as well. LocalFrame::ConsumeTransientUserActivation(local_frame);
} }
// TODO(crbug.com/825270): Pretend that a user gesture is provided to allow // TODO(crbug.com/825270): Pretend that a user gesture is provided to allow
...@@ -836,7 +841,7 @@ ScriptPromise PaymentRequest::show(ScriptState* script_state, ...@@ -836,7 +841,7 @@ ScriptPromise PaymentRequest::show(ScriptState* script_state,
// TODO(crbug.com/779126): add support for handling payment requests in // TODO(crbug.com/779126): add support for handling payment requests in
// immersive mode. // immersive mode.
if (DomWindow()->GetFrame()->GetSettings()->GetImmersiveModeEnabled()) { if (local_frame->GetSettings()->GetImmersiveModeEnabled()) {
exception_state.ThrowDOMException(DOMExceptionCode::kInvalidStateError, exception_state.ThrowDOMException(DOMExceptionCode::kInvalidStateError,
"Page popups are suppressed"); "Page popups are suppressed");
return ScriptPromise(); return ScriptPromise();
......
...@@ -330,6 +330,7 @@ TEST(PaymentRequestTest, ShowConsumesUserActivation) { ...@@ -330,6 +330,7 @@ TEST(PaymentRequestTest, ShowConsumesUserActivation) {
&(scope.GetFrame()), mojom::UserActivationNotificationType::kTest); &(scope.GetFrame()), mojom::UserActivationNotificationType::kTest);
request->show(scope.GetScriptState(), ASSERT_NO_EXCEPTION) request->show(scope.GetScriptState(), ASSERT_NO_EXCEPTION)
.Then(funcs.ExpectNoCall(), funcs.ExpectNoCall()); .Then(funcs.ExpectNoCall(), funcs.ExpectNoCall());
EXPECT_FALSE(LocalFrame::HasTransientUserActivation(&(scope.GetFrame())));
} }
TEST(PaymentRequestTest, RejectShowPromiseOnErrorPaymentMethodNotSupported) { TEST(PaymentRequestTest, RejectShowPromiseOnErrorPaymentMethodNotSupported) {
......
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