Chromium Code Reviews| OLD | NEW | 
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "modules/payments/PaymentAppRequestDataConversion.h" | |
| 6 | |
| 7 #include "bindings/core/v8/ScriptState.h" | |
| 8 #include "bindings/core/v8/ToV8.h" | |
| 9 #include "modules/payments/PaymentAppRequestData.h" | |
| 10 #include "modules/payments/PaymentCurrencyAmount.h" | |
| 11 #include "modules/payments/PaymentDetailsModifier.h" | |
| 12 #include "modules/payments/PaymentItem.h" | |
| 13 #include "modules/payments/PaymentMethodData.h" | |
| 14 #include "public/platform/modules/payments/WebPaymentAppRequestData.h" | |
| 15 #include "public/platform/modules/payments/WebPaymentMethodData.h" | |
| 16 | |
| 17 namespace blink { | |
| 18 namespace { | |
| 19 | |
| 20 PaymentCurrencyAmount toPaymentCurrencyAmount( | |
| 21 const WebPaymentCurrencyAmount& webAmount) { | |
| 22 PaymentCurrencyAmount amount; | |
| 23 amount.setCurrency(webAmount.currency); | |
| 24 amount.setValue(webAmount.value); | |
| 25 amount.setCurrencySystem(webAmount.currencySystem); | |
| 26 return amount; | |
| 27 } | |
| 28 | |
| 29 PaymentItem toPaymentItem(const WebPaymentItem& webItem) { | |
| 30 PaymentItem item; | |
| 31 item.setLabel(webItem.label); | |
| 32 item.setAmount(toPaymentCurrencyAmount(webItem.amount)); | |
| 33 item.setPending(webItem.pending); | |
| 34 return item; | |
| 35 } | |
| 36 | |
| 37 ScriptValue stringDataToScriptValue(ScriptState* scriptState, | |
| 
 
please use gerrit instead
2016/11/29 15:10:35
Place this function immediately above the function
 
zino
2016/11/30 16:09:32
Done.
 
 | |
| 38 const WebString& stringifiedData) { | |
| 39 v8::Local<v8::Value> v8Value; | |
| 40 if (!v8::JSON::Parse(scriptState->isolate(), | |
| 41 v8String(scriptState->isolate(), stringifiedData)) | |
| 42 .ToLocal(&v8Value)) { | |
| 43 return ScriptValue(); | |
| 44 } | |
| 45 return ScriptValue(scriptState, v8Value); | |
| 46 } | |
| 47 | |
| 48 PaymentDetailsModifier toPaymentDetailsModifier( | |
| 49 ScriptState* scriptState, | |
| 50 const WebPaymentDetailsModifier& webModifier) { | |
| 51 PaymentDetailsModifier modifier; | |
| 52 Vector<String> supportedMethods; | |
| 53 for (const auto& webMethod : webModifier.supportedMethods) { | |
| 54 supportedMethods.append(webMethod); | |
| 55 } | |
| 56 modifier.setSupportedMethods(supportedMethods); | |
| 57 modifier.setTotal(toPaymentItem(webModifier.total)); | |
| 58 HeapVector<PaymentItem> additionalDisplayItems; | |
| 59 for (const auto& webItem : webModifier.additionalDisplayItems) { | |
| 60 additionalDisplayItems.append(toPaymentItem(webItem)); | |
| 61 } | |
| 62 modifier.setAdditionalDisplayItems(additionalDisplayItems); | |
| 63 return modifier; | |
| 64 } | |
| 65 | |
| 66 PaymentMethodData toPaymentMethodData( | |
| 67 ScriptState* scriptState, | |
| 68 const WebPaymentMethodData& webMethodData) { | |
| 69 PaymentMethodData methodData; | |
| 70 Vector<String> supportedMethods; | |
| 71 for (const auto& method : webMethodData.supportedMethods) { | |
| 72 supportedMethods.append(method); | |
| 73 } | |
| 74 methodData.setSupportedMethods(supportedMethods); | |
| 75 methodData.setData( | |
| 76 stringDataToScriptValue(scriptState, webMethodData.stringifiedData)); | |
| 77 return methodData; | |
| 78 } | |
| 79 | |
| 80 } // namespace | |
| 81 | |
| 82 PaymentAppRequestData PaymentAppRequestDataConversion::toPaymentAppRequestData( | |
| 83 ScriptState* scriptState, | |
| 84 const WebPaymentAppRequestData& webData) { | |
| 85 PaymentAppRequestData data; | |
| 86 | |
| 87 data.setOrigin(webData.origin); | |
| 88 HeapVector<PaymentMethodData> methodData; | |
| 89 for (const auto& md : webData.methodData) { | |
| 90 methodData.append(toPaymentMethodData(scriptState, md)); | |
| 91 } | |
| 92 data.setMethodData(methodData); | |
| 93 data.setTotal(toPaymentItem(webData.total)); | |
| 94 HeapVector<PaymentDetailsModifier> modifiers; | |
| 95 for (const auto& modifier : webData.modifiers) { | |
| 96 modifiers.append(toPaymentDetailsModifier(scriptState, modifier)); | |
| 97 } | |
| 98 data.setOptionId(webData.optionId); | |
| 99 return data; | |
| 100 } | |
| 101 | |
| 102 } // namespace blink | |
| OLD | NEW |