Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(405)

Unified Diff: third_party/WebKit/Source/modules/payments/PaymentRequestUpdateEvent.cpp

Issue 2170783002: Add a timeout to the update event in case page doesn't resolve promise from updateWith (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Missed the DCHECK Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/modules/payments/PaymentRequestUpdateEvent.cpp
diff --git a/third_party/WebKit/Source/modules/payments/PaymentRequestUpdateEvent.cpp b/third_party/WebKit/Source/modules/payments/PaymentRequestUpdateEvent.cpp
index d04dd8b983de79b8b739c1e8e234ca1952eccfe4..02e5161e759e7c1a53441ad2df3c00ee7f7481bd 100644
--- a/third_party/WebKit/Source/modules/payments/PaymentRequestUpdateEvent.cpp
+++ b/third_party/WebKit/Source/modules/payments/PaymentRequestUpdateEvent.cpp
@@ -9,10 +9,13 @@
#include "core/dom/DOMException.h"
#include "core/dom/ExceptionCode.h"
#include "modules/payments/PaymentUpdater.h"
+#include "public/platform/WebTraceLocation.h"
namespace blink {
namespace {
+static const int abortTimeout = 60; // Reject the payment request if the page does not resolve the promise from updateWith within 60 seconds.
+
class UpdatePaymentDetailsFunction : public ScriptFunction {
public:
static v8::Local<v8::Function> createFunction(ScriptState* scriptState, PaymentUpdater* updater)
@@ -93,6 +96,8 @@ PaymentRequestUpdateEvent* PaymentRequestUpdateEvent::create(const AtomicString&
void PaymentRequestUpdateEvent::setPaymentDetailsUpdater(PaymentUpdater* updater)
{
+ DCHECK(!m_abortTimer.isActive());
+ m_abortTimer.startOneShot(abortTimeout, BLINK_FROM_HERE);
m_updater = updater;
}
@@ -113,11 +118,20 @@ void PaymentRequestUpdateEvent::updateWith(ScriptState* scriptState, ScriptPromi
stopImmediatePropagation();
m_waitForUpdate = true;
+ m_abortTimer.stop();
promise.then(UpdatePaymentDetailsFunction::createFunction(scriptState, m_updater),
UpdatePaymentDetailsErrorFunction::createFunction(scriptState, m_updater));
}
+void PaymentRequestUpdateEvent::onTimerFired(Timer<PaymentRequestUpdateEvent>*)
+{
+ if (!m_updater)
+ return;
+
+ m_updater->onUpdatePaymentDetailsFailure(ScriptValue());
+}
+
DEFINE_TRACE(PaymentRequestUpdateEvent)
{
visitor->trace(m_updater);
@@ -126,12 +140,14 @@ DEFINE_TRACE(PaymentRequestUpdateEvent)
PaymentRequestUpdateEvent::PaymentRequestUpdateEvent()
: m_waitForUpdate(false)
+ , m_abortTimer(this, &PaymentRequestUpdateEvent::onTimerFired)
{
}
PaymentRequestUpdateEvent::PaymentRequestUpdateEvent(const AtomicString& type, const PaymentRequestUpdateEventInit& init)
: Event(type, init)
, m_waitForUpdate(false)
+ , m_abortTimer(this, &PaymentRequestUpdateEvent::onTimerFired)
{
}

Powered by Google App Engine
This is Rietveld 408576698