Chromium Code Reviews| 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_payerName(response->payer_name) | 21 , m_payerName(response->payer_name) | 
| 20 , m_payerEmail(response->payer_email) | 22 , m_payerEmail(response->payer_email) | 
| 21 , m_payerPhone(response->payer_phone) | 23 , m_payerPhone(response->payer_phone) | 
| 22 , m_paymentCompleter(paymentCompleter) | 24 , m_paymentCompleter(paymentCompleter) | 
| 23 { | 25 { | 
| 24 DCHECK(m_paymentCompleter); | 26 DCHECK(m_paymentCompleter); | 
| 25 } | 27 } | 
| 26 | 28 | 
| 27 PaymentResponse::~PaymentResponse() | 29 PaymentResponse::~PaymentResponse() | 
| 28 { | 30 { | 
| 29 } | 31 } | 
| 30 | 32 | 
| 33 ScriptValue PaymentResponse::toJSONForBinding(ScriptState* scriptState) const | |
| 34 { | |
| 35 V8ObjectBuilder result(scriptState); | |
| 36 result.addString("methodName", methodName()); | |
| 37 result.add("details", details(scriptState, ASSERT_NO_EXCEPTION)); | |
| 38 | |
| 39 if (shippingAddress()) | |
| 40 result.add("shippingAddress", shippingAddress()->toJSONForBinding(script State)); | |
| 41 else | |
| 42 result.addNull("shippingAddress"); | |
| 
 
please use gerrit instead
2016/09/20 08:15:46
Do we need to add null shippingAddress, shippingOp
 
zino
2016/09/20 16:55:43
I'm not sure but we can not omit them even if the
 
 | |
| 43 | |
| 44 if (shippingOption().isNull()) | |
| 45 result.addNull("shippingOption"); | |
| 46 else | |
| 47 result.addString("shippingOption", shippingOption()); | |
| 48 | |
| 49 if (payerEmail().isNull()) | |
| 50 result.addNull("payerEmail"); | |
| 51 else | |
| 52 result.addString("payerEmail", payerEmail()); | |
| 53 | |
| 54 if (payerPhone().isNull()) | |
| 55 result.addNull("payerPhone"); | |
| 56 else | |
| 57 result.addString("payerPhone", payerPhone()); | |
| 58 | |
| 59 return result.scriptValue(); | |
| 60 } | |
| 61 | |
| 31 ScriptValue PaymentResponse::details(ScriptState* scriptState, ExceptionState& e xceptionState) const | 62 ScriptValue PaymentResponse::details(ScriptState* scriptState, ExceptionState& e xceptionState) const | 
| 32 { | 63 { | 
| 33 return ScriptValue(scriptState, fromJSONString(scriptState, m_stringifiedDet ails, exceptionState)); | 64 return ScriptValue(scriptState, fromJSONString(scriptState, m_stringifiedDet ails, exceptionState)); | 
| 34 } | 65 } | 
| 35 | 66 | 
| 36 ScriptPromise PaymentResponse::complete(ScriptState* scriptState, const String& result) | 67 ScriptPromise PaymentResponse::complete(ScriptState* scriptState, const String& result) | 
| 37 { | 68 { | 
| 38 PaymentCompleter::PaymentComplete convertedResult = PaymentCompleter::Unknow n; | 69 PaymentCompleter::PaymentComplete convertedResult = PaymentCompleter::Unknow n; | 
| 39 if (result == "success") | 70 if (result == "success") | 
| 40 convertedResult = PaymentCompleter::Success; | 71 convertedResult = PaymentCompleter::Success; | 
| 41 else if (result == "fail") | 72 else if (result == "fail") | 
| 42 convertedResult = PaymentCompleter::Fail; | 73 convertedResult = PaymentCompleter::Fail; | 
| 43 return m_paymentCompleter->complete(scriptState, convertedResult); | 74 return m_paymentCompleter->complete(scriptState, convertedResult); | 
| 44 } | 75 } | 
| 45 | 76 | 
| 46 DEFINE_TRACE(PaymentResponse) | 77 DEFINE_TRACE(PaymentResponse) | 
| 47 { | 78 { | 
| 48 visitor->trace(m_shippingAddress); | 79 visitor->trace(m_shippingAddress); | 
| 49 visitor->trace(m_paymentCompleter); | 80 visitor->trace(m_paymentCompleter); | 
| 50 } | 81 } | 
| 51 | 82 | 
| 52 } // namespace blink | 83 } // namespace blink | 
| OLD | NEW |