Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(279)

Side by Side Diff: third_party/WebKit/Source/modules/payments/PaymentAppRequestDataConversion.cpp

Issue 2523583002: test
Patch Set: test Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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/PaymentCurrencyAmount.h"
10 #include "modules/payments/PaymentDetailsModifier.h"
11 #include "modules/payments/PaymentItem.h"
12 #include "modules/payments/PaymentMethodData.h"
13 #include "public/platform/modules/payments/WebPaymentAppRequestData.h"
14 #include "public/platform/modules/payments/WebPaymentMethodData.h"
15
16 namespace blink {
17 namespace {
18
19 PaymentCurrencyAmount toPaymentCurrencyAmount(
20 const WebPaymentCurrencyAmount& webAmount) {
21 PaymentCurrencyAmount amount;
22 amount.setCurrency(webAmount.currency);
23 amount.setValue(webAmount.value);
24 amount.setCurrencySystem(webAmount.currencySystem);
25 return amount;
26 }
27
28 PaymentItem toPaymentItem(const WebPaymentItem& webItem) {
29 PaymentItem item;
30 item.setLabel(webItem.label);
31 item.setAmount(toPaymentCurrencyAmount(webItem.amount));
32 item.setPending(webItem.pending);
33 return item;
34 }
35
36 ScriptValue stringDataToScriptValue(ScriptState* scriptState,
37 const WebString& stringifiedData) {
38 v8::Local<v8::Value> v8Value;
39 if (!v8::JSON::Parse(scriptState->isolate(),
40 v8String(scriptState->isolate(), stringifiedData))
41 .ToLocal(&v8Value)) {
42 return ScriptValue();
43 }
44 return ScriptValue(scriptState, v8Value);
45 }
46
47 PaymentDetailsModifier toPaymentDetailsModifier(
48 ScriptState* scriptState,
49 const WebPaymentDetailsModifier& webModifier) {
50 PaymentDetailsModifier modifier;
51 Vector<String> supportedMethods;
52 for (const auto& webMethod : webModifier.supportedMethods) {
53 supportedMethods.append(webMethod);
54 }
55 modifier.setSupportedMethods(supportedMethods);
56 modifier.setTotal(toPaymentItem(webModifier.total));
57 HeapVector<PaymentItem> additionalDisplayItems;
58 for (const auto& webItem : webModifier.additionalDisplayItems) {
59 additionalDisplayItems.append(toPaymentItem(webItem));
60 }
61 modifier.setAdditionalDisplayItems(additionalDisplayItems);
62 return modifier;
63 }
64
65 PaymentMethodData toPaymentMethodData(
66 ScriptState* scriptState,
67 const WebPaymentMethodData& webMethodData) {
68 PaymentMethodData methodData;
69 Vector<String> supportedMethods;
70 for (const auto& method : webMethodData.supportedMethods) {
71 supportedMethods.append(method);
72 }
73 methodData.setData(
74 stringDataToScriptValue(scriptState, webMethodData.stringifiedData));
75 return methodData;
76 }
77
78 } // namespace
79
80 PaymentAppRequestData PaymentAppRequestDataConversion::toPaymentAppRequestData(
81 ScriptState* scriptState,
82 const WebPaymentAppRequestData& webData) {
83 PaymentAppRequestData data;
84
85 data.setOrigin(webData.origin);
86 HeapVector<PaymentMethodData> methodData;
87 for (const auto& md : webData.methodData) {
88 methodData.append(toPaymentMethodData(scriptState, md));
89 }
90 data.setTotal(toPaymentItem(webData.total));
91 HeapVector<PaymentDetailsModifier> modifiers;
92 for (const auto& modifier : webData.modifiers) {
93 modifiers.append(toPaymentDetailsModifier(scriptState, modifier));
94 }
95 data.setOptionId(webData.optionId);
96 return data;
97 }
98
99 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698