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

Side by Side 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 unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "modules/payments/PaymentRequestUpdateEvent.h" 5 #include "modules/payments/PaymentRequestUpdateEvent.h"
6 6
7 #include "bindings/core/v8/ExceptionState.h" 7 #include "bindings/core/v8/ExceptionState.h"
8 #include "bindings/core/v8/ScriptFunction.h" 8 #include "bindings/core/v8/ScriptFunction.h"
9 #include "core/dom/DOMException.h" 9 #include "core/dom/DOMException.h"
10 #include "core/dom/ExceptionCode.h" 10 #include "core/dom/ExceptionCode.h"
11 #include "modules/payments/PaymentUpdater.h" 11 #include "modules/payments/PaymentUpdater.h"
12 #include "public/platform/WebTraceLocation.h"
12 13
13 namespace blink { 14 namespace blink {
14 namespace { 15 namespace {
15 16
17 static const int abortTimeout = 60; // Reject the payment request if the page do es not resolve the promise from updateWith within 60 seconds.
18
16 class UpdatePaymentDetailsFunction : public ScriptFunction { 19 class UpdatePaymentDetailsFunction : public ScriptFunction {
17 public: 20 public:
18 static v8::Local<v8::Function> createFunction(ScriptState* scriptState, Paym entUpdater* updater) 21 static v8::Local<v8::Function> createFunction(ScriptState* scriptState, Paym entUpdater* updater)
19 { 22 {
20 UpdatePaymentDetailsFunction* self = new UpdatePaymentDetailsFunction(sc riptState, updater); 23 UpdatePaymentDetailsFunction* self = new UpdatePaymentDetailsFunction(sc riptState, updater);
21 return self->bindToV8Function(); 24 return self->bindToV8Function();
22 } 25 }
23 26
24 DEFINE_INLINE_VIRTUAL_TRACE() 27 DEFINE_INLINE_VIRTUAL_TRACE()
25 { 28 {
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 return new PaymentRequestUpdateEvent(); 89 return new PaymentRequestUpdateEvent();
87 } 90 }
88 91
89 PaymentRequestUpdateEvent* PaymentRequestUpdateEvent::create(const AtomicString& type, const PaymentRequestUpdateEventInit& init) 92 PaymentRequestUpdateEvent* PaymentRequestUpdateEvent::create(const AtomicString& type, const PaymentRequestUpdateEventInit& init)
90 { 93 {
91 return new PaymentRequestUpdateEvent(type, init); 94 return new PaymentRequestUpdateEvent(type, init);
92 } 95 }
93 96
94 void PaymentRequestUpdateEvent::setPaymentDetailsUpdater(PaymentUpdater* updater ) 97 void PaymentRequestUpdateEvent::setPaymentDetailsUpdater(PaymentUpdater* updater )
95 { 98 {
99 DCHECK(!m_abortTimer.isActive());
100 m_abortTimer.startOneShot(abortTimeout, BLINK_FROM_HERE);
96 m_updater = updater; 101 m_updater = updater;
97 } 102 }
98 103
99 void PaymentRequestUpdateEvent::updateWith(ScriptState* scriptState, ScriptPromi se promise, ExceptionState& exceptionState) 104 void PaymentRequestUpdateEvent::updateWith(ScriptState* scriptState, ScriptPromi se promise, ExceptionState& exceptionState)
100 { 105 {
101 if (!m_updater) 106 if (!m_updater)
102 return; 107 return;
103 108
104 if (!isBeingDispatched()) { 109 if (!isBeingDispatched()) {
105 exceptionState.throwDOMException(InvalidStateError, "Cannot update detai ls when the event is not being dispatched"); 110 exceptionState.throwDOMException(InvalidStateError, "Cannot update detai ls when the event is not being dispatched");
106 return; 111 return;
107 } 112 }
108 113
109 if (m_waitForUpdate) { 114 if (m_waitForUpdate) {
110 exceptionState.throwDOMException(InvalidStateError, "Cannot update detai ls twice"); 115 exceptionState.throwDOMException(InvalidStateError, "Cannot update detai ls twice");
111 return; 116 return;
112 } 117 }
113 118
114 stopImmediatePropagation(); 119 stopImmediatePropagation();
115 m_waitForUpdate = true; 120 m_waitForUpdate = true;
121 m_abortTimer.stop();
116 122
117 promise.then(UpdatePaymentDetailsFunction::createFunction(scriptState, m_upd ater), 123 promise.then(UpdatePaymentDetailsFunction::createFunction(scriptState, m_upd ater),
118 UpdatePaymentDetailsErrorFunction::createFunction(scriptState, m_updater )); 124 UpdatePaymentDetailsErrorFunction::createFunction(scriptState, m_updater ));
119 } 125 }
120 126
127 void PaymentRequestUpdateEvent::onTimerFired(Timer<PaymentRequestUpdateEvent>*)
128 {
129 if (!m_updater)
130 return;
131
132 m_updater->onUpdatePaymentDetailsFailure(ScriptValue());
133 }
134
121 DEFINE_TRACE(PaymentRequestUpdateEvent) 135 DEFINE_TRACE(PaymentRequestUpdateEvent)
122 { 136 {
123 visitor->trace(m_updater); 137 visitor->trace(m_updater);
124 Event::trace(visitor); 138 Event::trace(visitor);
125 } 139 }
126 140
127 PaymentRequestUpdateEvent::PaymentRequestUpdateEvent() 141 PaymentRequestUpdateEvent::PaymentRequestUpdateEvent()
128 : m_waitForUpdate(false) 142 : m_waitForUpdate(false)
143 , m_abortTimer(this, &PaymentRequestUpdateEvent::onTimerFired)
129 { 144 {
130 } 145 }
131 146
132 PaymentRequestUpdateEvent::PaymentRequestUpdateEvent(const AtomicString& type, c onst PaymentRequestUpdateEventInit& init) 147 PaymentRequestUpdateEvent::PaymentRequestUpdateEvent(const AtomicString& type, c onst PaymentRequestUpdateEventInit& init)
133 : Event(type, init) 148 : Event(type, init)
134 , m_waitForUpdate(false) 149 , m_waitForUpdate(false)
150 , m_abortTimer(this, &PaymentRequestUpdateEvent::onTimerFired)
135 { 151 {
136 } 152 }
137 153
138 } // namespace blink 154 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698