| 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/PaymentAppRequestDataConversion.h" | 5 #include "modules/payments/PaymentAppRequestDataConversion.h" |
| 6 | 6 |
| 7 #include "bindings/core/v8/ScriptState.h" | 7 #include "bindings/core/v8/ScriptState.h" |
| 8 #include "bindings/core/v8/ToV8.h" | 8 #include "bindings/core/v8/ToV8.h" |
| 9 #include "modules/payments/PaymentAppRequestData.h" | 9 #include "modules/payments/PaymentAppRequestData.h" |
| 10 #include "modules/payments/PaymentCurrencyAmount.h" | 10 #include "modules/payments/PaymentCurrencyAmount.h" |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 item.setPending(webItem.pending); | 33 item.setPending(webItem.pending); |
| 34 return item; | 34 return item; |
| 35 } | 35 } |
| 36 | 36 |
| 37 PaymentDetailsModifier toPaymentDetailsModifier( | 37 PaymentDetailsModifier toPaymentDetailsModifier( |
| 38 ScriptState* scriptState, | 38 ScriptState* scriptState, |
| 39 const WebPaymentDetailsModifier& webModifier) { | 39 const WebPaymentDetailsModifier& webModifier) { |
| 40 PaymentDetailsModifier modifier; | 40 PaymentDetailsModifier modifier; |
| 41 Vector<String> supportedMethods; | 41 Vector<String> supportedMethods; |
| 42 for (const auto& webMethod : webModifier.supportedMethods) { | 42 for (const auto& webMethod : webModifier.supportedMethods) { |
| 43 supportedMethods.append(webMethod); | 43 supportedMethods.push_back(webMethod); |
| 44 } | 44 } |
| 45 modifier.setSupportedMethods(supportedMethods); | 45 modifier.setSupportedMethods(supportedMethods); |
| 46 modifier.setTotal(toPaymentItem(webModifier.total)); | 46 modifier.setTotal(toPaymentItem(webModifier.total)); |
| 47 HeapVector<PaymentItem> additionalDisplayItems; | 47 HeapVector<PaymentItem> additionalDisplayItems; |
| 48 for (const auto& webItem : webModifier.additionalDisplayItems) { | 48 for (const auto& webItem : webModifier.additionalDisplayItems) { |
| 49 additionalDisplayItems.append(toPaymentItem(webItem)); | 49 additionalDisplayItems.push_back(toPaymentItem(webItem)); |
| 50 } | 50 } |
| 51 modifier.setAdditionalDisplayItems(additionalDisplayItems); | 51 modifier.setAdditionalDisplayItems(additionalDisplayItems); |
| 52 return modifier; | 52 return modifier; |
| 53 } | 53 } |
| 54 | 54 |
| 55 ScriptValue stringDataToScriptValue(ScriptState* scriptState, | 55 ScriptValue stringDataToScriptValue(ScriptState* scriptState, |
| 56 const WebString& stringifiedData) { | 56 const WebString& stringifiedData) { |
| 57 if (!scriptState->contextIsValid()) | 57 if (!scriptState->contextIsValid()) |
| 58 return ScriptValue(); | 58 return ScriptValue(); |
| 59 | 59 |
| 60 ScriptState::Scope scope(scriptState); | 60 ScriptState::Scope scope(scriptState); |
| 61 v8::Local<v8::Value> v8Value; | 61 v8::Local<v8::Value> v8Value; |
| 62 if (!v8::JSON::Parse(scriptState->isolate(), | 62 if (!v8::JSON::Parse(scriptState->isolate(), |
| 63 v8String(scriptState->isolate(), stringifiedData)) | 63 v8String(scriptState->isolate(), stringifiedData)) |
| 64 .ToLocal(&v8Value)) { | 64 .ToLocal(&v8Value)) { |
| 65 return ScriptValue(); | 65 return ScriptValue(); |
| 66 } | 66 } |
| 67 return ScriptValue(scriptState, v8Value); | 67 return ScriptValue(scriptState, v8Value); |
| 68 } | 68 } |
| 69 | 69 |
| 70 PaymentMethodData toPaymentMethodData( | 70 PaymentMethodData toPaymentMethodData( |
| 71 ScriptState* scriptState, | 71 ScriptState* scriptState, |
| 72 const WebPaymentMethodData& webMethodData) { | 72 const WebPaymentMethodData& webMethodData) { |
| 73 PaymentMethodData methodData; | 73 PaymentMethodData methodData; |
| 74 Vector<String> supportedMethods; | 74 Vector<String> supportedMethods; |
| 75 for (const auto& method : webMethodData.supportedMethods) { | 75 for (const auto& method : webMethodData.supportedMethods) { |
| 76 supportedMethods.append(method); | 76 supportedMethods.push_back(method); |
| 77 } | 77 } |
| 78 methodData.setSupportedMethods(supportedMethods); | 78 methodData.setSupportedMethods(supportedMethods); |
| 79 methodData.setData( | 79 methodData.setData( |
| 80 stringDataToScriptValue(scriptState, webMethodData.stringifiedData)); | 80 stringDataToScriptValue(scriptState, webMethodData.stringifiedData)); |
| 81 return methodData; | 81 return methodData; |
| 82 } | 82 } |
| 83 | 83 |
| 84 } // namespace | 84 } // namespace |
| 85 | 85 |
| 86 PaymentAppRequestData PaymentAppRequestDataConversion::toPaymentAppRequestData( | 86 PaymentAppRequestData PaymentAppRequestDataConversion::toPaymentAppRequestData( |
| 87 ScriptState* scriptState, | 87 ScriptState* scriptState, |
| 88 const WebPaymentAppRequestData& webData) { | 88 const WebPaymentAppRequestData& webData) { |
| 89 PaymentAppRequestData data; | 89 PaymentAppRequestData data; |
| 90 | 90 |
| 91 data.setOrigin(webData.origin); | 91 data.setOrigin(webData.origin); |
| 92 HeapVector<PaymentMethodData> methodData; | 92 HeapVector<PaymentMethodData> methodData; |
| 93 for (const auto& md : webData.methodData) { | 93 for (const auto& md : webData.methodData) { |
| 94 methodData.append(toPaymentMethodData(scriptState, md)); | 94 methodData.push_back(toPaymentMethodData(scriptState, md)); |
| 95 } | 95 } |
| 96 data.setMethodData(methodData); | 96 data.setMethodData(methodData); |
| 97 data.setTotal(toPaymentItem(webData.total)); | 97 data.setTotal(toPaymentItem(webData.total)); |
| 98 HeapVector<PaymentDetailsModifier> modifiers; | 98 HeapVector<PaymentDetailsModifier> modifiers; |
| 99 for (const auto& modifier : webData.modifiers) { | 99 for (const auto& modifier : webData.modifiers) { |
| 100 modifiers.append(toPaymentDetailsModifier(scriptState, modifier)); | 100 modifiers.push_back(toPaymentDetailsModifier(scriptState, modifier)); |
| 101 } | 101 } |
| 102 data.setOptionId(webData.optionId); | 102 data.setOptionId(webData.optionId); |
| 103 return data; | 103 return data; |
| 104 } | 104 } |
| 105 | 105 |
| 106 } // namespace blink | 106 } // namespace blink |
| OLD | NEW |