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,
return ScriptPromise();
}
bool is_user_gesture =
LocalFrame::HasTransientUserActivation(DomWindow()->GetFrame());
LocalFrame* local_frame = DomWindow()->GetFrame();
bool is_user_gesture = LocalFrame::HasTransientUserActivation(local_frame);
if (!is_user_gesture) {
UseCounter::Count(GetExecutionContext(),
WebFeature::kPaymentRequestShowWithoutGesture);
......@@ -817,12 +817,17 @@ ScriptPromise PaymentRequest::show(ScriptState* script_state,
if (RuntimeEnabledFeatures::PaymentRequestShowConsumesUserActivationEnabled(
GetExecutionContext())) {
if (!is_user_gesture) {
exception_state.ThrowDOMException(
DOMExceptionCode::kNotAllowedError,
"show() must be called with transient user activation");
String message =
"PaymentRequest.show() requires transient user activation";
GetExecutionContext()->AddConsoleMessage(
MakeGarbageCollected<ConsoleMessage>(
mojom::blink::ConsoleMessageSource::kJavaScript,
mojom::blink::ConsoleMessageLevel::kWarning, message));
exception_state.ThrowDOMException(DOMExceptionCode::kNotAllowedError,
message);
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
......@@ -836,7 +841,7 @@ ScriptPromise PaymentRequest::show(ScriptState* script_state,
// TODO(crbug.com/779126): add support for handling payment requests in
// immersive mode.
if (DomWindow()->GetFrame()->GetSettings()->GetImmersiveModeEnabled()) {
if (local_frame->GetSettings()->GetImmersiveModeEnabled()) {
exception_state.ThrowDOMException(DOMExceptionCode::kInvalidStateError,
"Page popups are suppressed");
return ScriptPromise();
......
......@@ -330,6 +330,7 @@ TEST(PaymentRequestTest, ShowConsumesUserActivation) {
&(scope.GetFrame()), mojom::UserActivationNotificationType::kTest);
request->show(scope.GetScriptState(), ASSERT_NO_EXCEPTION)
.Then(funcs.ExpectNoCall(), funcs.ExpectNoCall());
EXPECT_FALSE(LocalFrame::HasTransientUserActivation(&(scope.GetFrame())));
}
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