| 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/PaymentResponse.h" | 5 #include "modules/payments/PaymentResponse.h" |
| 6 | 6 |
| 7 #include "bindings/core/v8/ExceptionStatePlaceholder.h" |
| 7 #include "bindings/core/v8/JSONValuesForV8.h" | 8 #include "bindings/core/v8/JSONValuesForV8.h" |
| 9 #include "bindings/core/v8/V8ObjectBuilder.h" |
| 8 #include "modules/payments/PaymentAddress.h" | 10 #include "modules/payments/PaymentAddress.h" |
| 9 #include "modules/payments/PaymentCompleter.h" | 11 #include "modules/payments/PaymentCompleter.h" |
| 10 #include "wtf/Assertions.h" | 12 #include "wtf/Assertions.h" |
| 11 | 13 |
| 12 namespace blink { | 14 namespace blink { |
| 13 | 15 |
| 14 PaymentResponse::PaymentResponse(mojom::blink::PaymentResponsePtr response, Paym
entCompleter* paymentCompleter) | 16 PaymentResponse::PaymentResponse(mojom::blink::PaymentResponsePtr response, Paym
entCompleter* paymentCompleter) |
| 15 : m_methodName(response->method_name) | 17 : m_methodName(response->method_name) |
| 16 , m_stringifiedDetails(response->stringified_details) | 18 , m_stringifiedDetails(response->stringified_details) |
| 17 , m_shippingAddress(response->shipping_address ? new PaymentAddress(std::mov
e(response->shipping_address)) : nullptr) | 19 , m_shippingAddress(response->shipping_address ? new PaymentAddress(std::mov
e(response->shipping_address)) : nullptr) |
| 18 , m_shippingOption(response->shipping_option) | 20 , m_shippingOption(response->shipping_option) |
| 19 , m_payerEmail(response->payer_email) | 21 , m_payerEmail(response->payer_email) |
| 20 , m_payerPhone(response->payer_phone) | 22 , m_payerPhone(response->payer_phone) |
| 21 , m_paymentCompleter(paymentCompleter) | 23 , m_paymentCompleter(paymentCompleter) |
| 22 { | 24 { |
| 23 DCHECK(m_paymentCompleter); | 25 DCHECK(m_paymentCompleter); |
| 24 } | 26 } |
| 25 | 27 |
| 26 PaymentResponse::~PaymentResponse() | 28 PaymentResponse::~PaymentResponse() |
| 27 { | 29 { |
| 28 } | 30 } |
| 29 | 31 |
| 32 ScriptValue PaymentResponse::toJSONForBinding(ScriptState* scriptState) const |
| 33 { |
| 34 V8ObjectBuilder result(scriptState); |
| 35 result.addString("methodName", methodName()); |
| 36 result.add("details", details(scriptState, ASSERT_NO_EXCEPTION)); |
| 37 |
| 38 if (shippingAddress()) |
| 39 result.add("shippingAddress", shippingAddress()->toJSONForBinding(script
State)); |
| 40 else |
| 41 result.addNull("shippingAddress"); |
| 42 |
| 43 if (shippingOption().isNull()) |
| 44 result.addNull("shippingOption"); |
| 45 else |
| 46 result.addString("shippingOption", shippingOption()); |
| 47 |
| 48 if (payerEmail().isNull()) |
| 49 result.addNull("payerEmail"); |
| 50 else |
| 51 result.addString("payerEmail", payerEmail()); |
| 52 |
| 53 if (payerPhone().isNull()) |
| 54 result.addNull("payerPhone"); |
| 55 else |
| 56 result.addString("payerPhone", payerPhone()); |
| 57 |
| 58 return result.scriptValue(); |
| 59 } |
| 60 |
| 30 ScriptValue PaymentResponse::details(ScriptState* scriptState, ExceptionState& e
xceptionState) const | 61 ScriptValue PaymentResponse::details(ScriptState* scriptState, ExceptionState& e
xceptionState) const |
| 31 { | 62 { |
| 32 return ScriptValue(scriptState, fromJSONString(scriptState, m_stringifiedDet
ails, exceptionState)); | 63 return ScriptValue(scriptState, fromJSONString(scriptState, m_stringifiedDet
ails, exceptionState)); |
| 33 } | 64 } |
| 34 | 65 |
| 35 ScriptPromise PaymentResponse::complete(ScriptState* scriptState, const String&
result) | 66 ScriptPromise PaymentResponse::complete(ScriptState* scriptState, const String&
result) |
| 36 { | 67 { |
| 37 PaymentCompleter::PaymentComplete convertedResult = PaymentCompleter::Unknow
n; | 68 PaymentCompleter::PaymentComplete convertedResult = PaymentCompleter::Unknow
n; |
| 38 if (result == "success") | 69 if (result == "success") |
| 39 convertedResult = PaymentCompleter::Success; | 70 convertedResult = PaymentCompleter::Success; |
| 40 else if (result == "fail") | 71 else if (result == "fail") |
| 41 convertedResult = PaymentCompleter::Fail; | 72 convertedResult = PaymentCompleter::Fail; |
| 42 return m_paymentCompleter->complete(scriptState, convertedResult); | 73 return m_paymentCompleter->complete(scriptState, convertedResult); |
| 43 } | 74 } |
| 44 | 75 |
| 45 DEFINE_TRACE(PaymentResponse) | 76 DEFINE_TRACE(PaymentResponse) |
| 46 { | 77 { |
| 47 visitor->trace(m_shippingAddress); | 78 visitor->trace(m_shippingAddress); |
| 48 visitor->trace(m_paymentCompleter); | 79 visitor->trace(m_paymentCompleter); |
| 49 } | 80 } |
| 50 | 81 |
| 51 } // namespace blink | 82 } // namespace blink |
| OLD | NEW |