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

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: Fixed review comments 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;
Marijn Kruisselbrink 2016/07/22 04:18:46 Maybe add a comment to mention what unit the 60 is
pals 2016/07/22 05:00:31 Done.
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 m_abortTimer.startOneShot(abortTimeout, BLINK_FROM_HERE);
96 m_updater = updater; 100 m_updater = updater;
97 } 101 }
98 102
99 void PaymentRequestUpdateEvent::updateWith(ScriptState* scriptState, ScriptPromi se promise, ExceptionState& exceptionState) 103 void PaymentRequestUpdateEvent::updateWith(ScriptState* scriptState, ScriptPromi se promise, ExceptionState& exceptionState)
100 { 104 {
101 if (!m_updater) 105 if (!m_updater)
102 return; 106 return;
103 107
104 if (!isBeingDispatched()) { 108 if (!isBeingDispatched()) {
105 exceptionState.throwDOMException(InvalidStateError, "Cannot update detai ls when the event is not being dispatched"); 109 exceptionState.throwDOMException(InvalidStateError, "Cannot update detai ls when the event is not being dispatched");
106 return; 110 return;
107 } 111 }
108 112
109 if (m_waitForUpdate) { 113 if (m_waitForUpdate) {
110 exceptionState.throwDOMException(InvalidStateError, "Cannot update detai ls twice"); 114 exceptionState.throwDOMException(InvalidStateError, "Cannot update detai ls twice");
111 return; 115 return;
112 } 116 }
113 117
114 stopImmediatePropagation(); 118 stopImmediatePropagation();
115 m_waitForUpdate = true; 119 m_waitForUpdate = true;
120 m_abortTimer.stop();
116 121
117 promise.then(UpdatePaymentDetailsFunction::createFunction(scriptState, m_upd ater), 122 promise.then(UpdatePaymentDetailsFunction::createFunction(scriptState, m_upd ater),
118 UpdatePaymentDetailsErrorFunction::createFunction(scriptState, m_updater )); 123 UpdatePaymentDetailsErrorFunction::createFunction(scriptState, m_updater ));
119 } 124 }
120 125
126 void PaymentRequestUpdateEvent::onTimerFired(Timer<PaymentRequestUpdateEvent>*)
127 {
128 if (!m_updater)
129 return;
130
131 m_updater->onUpdatePaymentDetailsFailure(ScriptValue());
132 }
133
121 DEFINE_TRACE(PaymentRequestUpdateEvent) 134 DEFINE_TRACE(PaymentRequestUpdateEvent)
122 { 135 {
123 visitor->trace(m_updater); 136 visitor->trace(m_updater);
124 Event::trace(visitor); 137 Event::trace(visitor);
125 } 138 }
126 139
127 PaymentRequestUpdateEvent::PaymentRequestUpdateEvent() 140 PaymentRequestUpdateEvent::PaymentRequestUpdateEvent()
128 : m_waitForUpdate(false) 141 : m_waitForUpdate(false)
142 , m_abortTimer(this, &PaymentRequestUpdateEvent::onTimerFired)
129 { 143 {
130 } 144 }
131 145
132 PaymentRequestUpdateEvent::PaymentRequestUpdateEvent(const AtomicString& type, c onst PaymentRequestUpdateEventInit& init) 146 PaymentRequestUpdateEvent::PaymentRequestUpdateEvent(const AtomicString& type, c onst PaymentRequestUpdateEventInit& init)
133 : Event(type, init) 147 : Event(type, init)
134 , m_waitForUpdate(false) 148 , m_waitForUpdate(false)
149 , m_abortTimer(this, &PaymentRequestUpdateEvent::onTimerFired)
135 { 150 {
136 } 151 }
137 152
138 } // namespace blink 153 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698