| OLD | NEW |
| 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 "bindings/core/v8/V8Binding.h" | 9 #include "bindings/core/v8/V8Binding.h" |
| 10 #include "core/dom/DOMException.h" | 10 #include "core/dom/DOMException.h" |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 | 116 |
| 117 if (wait_for_update_) { | 117 if (wait_for_update_) { |
| 118 exception_state.ThrowDOMException(kInvalidStateError, | 118 exception_state.ThrowDOMException(kInvalidStateError, |
| 119 "Cannot update details twice"); | 119 "Cannot update details twice"); |
| 120 return; | 120 return; |
| 121 } | 121 } |
| 122 | 122 |
| 123 stopPropagation(); | 123 stopPropagation(); |
| 124 stopImmediatePropagation(); | 124 stopImmediatePropagation(); |
| 125 wait_for_update_ = true; | 125 wait_for_update_ = true; |
| 126 abort_timer_.Stop(); | |
| 127 | 126 |
| 128 promise.Then( | 127 promise.Then( |
| 129 UpdatePaymentDetailsFunction::CreateFunction(script_state, updater_), | 128 UpdatePaymentDetailsFunction::CreateFunction(script_state, this), |
| 130 UpdatePaymentDetailsErrorFunction::CreateFunction(script_state, | 129 UpdatePaymentDetailsErrorFunction::CreateFunction(script_state, this)); |
| 131 updater_)); | 130 } |
| 131 |
| 132 void PaymentRequestUpdateEvent::OnUpdatePaymentDetails( |
| 133 const ScriptValue& details_script_value) { |
| 134 if (!updater_) |
| 135 return; |
| 136 abort_timer_.Stop(); |
| 137 updater_->OnUpdatePaymentDetails(details_script_value); |
| 138 updater_ = nullptr; |
| 139 } |
| 140 |
| 141 void PaymentRequestUpdateEvent::OnUpdatePaymentDetailsFailure( |
| 142 const String& error) { |
| 143 if (!updater_) |
| 144 return; |
| 145 abort_timer_.Stop(); |
| 146 updater_->OnUpdatePaymentDetailsFailure(error); |
| 147 updater_ = nullptr; |
| 132 } | 148 } |
| 133 | 149 |
| 134 DEFINE_TRACE(PaymentRequestUpdateEvent) { | 150 DEFINE_TRACE(PaymentRequestUpdateEvent) { |
| 135 visitor->Trace(updater_); | 151 visitor->Trace(updater_); |
| 136 Event::Trace(visitor); | 152 Event::Trace(visitor); |
| 137 } | 153 } |
| 138 | 154 |
| 139 void PaymentRequestUpdateEvent::OnUpdateEventTimeoutForTesting() { | 155 void PaymentRequestUpdateEvent::OnUpdateEventTimeoutForTesting() { |
| 140 OnUpdateEventTimeout(0); | 156 OnUpdateEventTimeout(nullptr); |
| 141 } | |
| 142 | |
| 143 void PaymentRequestUpdateEvent::OnUpdateEventTimeout(TimerBase*) { | |
| 144 if (!updater_) | |
| 145 return; | |
| 146 | |
| 147 updater_->OnUpdatePaymentDetailsFailure( | |
| 148 "Timed out as the page didn't resolve the promise from change event"); | |
| 149 } | 157 } |
| 150 | 158 |
| 151 PaymentRequestUpdateEvent::PaymentRequestUpdateEvent( | 159 PaymentRequestUpdateEvent::PaymentRequestUpdateEvent( |
| 152 ExecutionContext* execution_context, | 160 ExecutionContext* execution_context, |
| 153 const AtomicString& type, | 161 const AtomicString& type, |
| 154 const PaymentRequestUpdateEventInit& init) | 162 const PaymentRequestUpdateEventInit& init) |
| 155 : Event(type, init), | 163 : Event(type, init), |
| 156 wait_for_update_(false), | 164 wait_for_update_(false), |
| 157 abort_timer_( | 165 abort_timer_( |
| 158 TaskRunnerHelper::Get(TaskType::kUserInteraction, execution_context), | 166 TaskRunnerHelper::Get(TaskType::kUserInteraction, execution_context), |
| 159 this, | 167 this, |
| 160 &PaymentRequestUpdateEvent::OnUpdateEventTimeout) {} | 168 &PaymentRequestUpdateEvent::OnUpdateEventTimeout) {} |
| 161 | 169 |
| 170 void PaymentRequestUpdateEvent::OnUpdateEventTimeout(TimerBase*) { |
| 171 OnUpdatePaymentDetailsFailure("Timed out waiting for a response to a '" + |
| 172 type() + "' event"); |
| 173 } |
| 174 |
| 162 } // namespace blink | 175 } // namespace blink |
| OLD | NEW |