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

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

Issue 2528683002: PaymentApp: Blink side of payment request event dispatching in service worker. (Closed)
Patch Set: PaymentApp: Blink side of payment request event dispatching in service worker. 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/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 PaymentDetailsModifier toPaymentDetailsModifier(
38 ScriptState* scriptState,
39 const WebPaymentDetailsModifier& webModifier) {
40 PaymentDetailsModifier modifier;
41 Vector<String> supportedMethods;
42 for (const auto& webMethod : webModifier.supportedMethods) {
43 supportedMethods.append(webMethod);
44 }
45 modifier.setSupportedMethods(supportedMethods);
46 modifier.setTotal(toPaymentItem(webModifier.total));
47 HeapVector<PaymentItem> additionalDisplayItems;
48 for (const auto& webItem : webModifier.additionalDisplayItems) {
49 additionalDisplayItems.append(toPaymentItem(webItem));
50 }
51 modifier.setAdditionalDisplayItems(additionalDisplayItems);
52 return modifier;
53 }
54
55 ScriptValue stringDataToScriptValue(ScriptState* scriptState,
56 const WebString& stringifiedData) {
57 if (scriptState->contextIsValid())
zino 2016/12/02 04:18:33 Done.
58 return ScriptValue();
59
60 ScriptState::Scope scope(
zino 2016/12/02 04:18:33 Done.
61 workerGlobalScope()->scriptController()->getScriptState());
62 v8::Local<v8::Value> v8Value;
63 if (!v8::JSON::Parse(scriptState->isolate(),
64 v8String(scriptState->isolate(), stringifiedData))
65 .ToLocal(&v8Value)) {
66 return ScriptValue();
67 }
68 return ScriptValue(scriptState, v8Value);
69 }
70
71 PaymentMethodData toPaymentMethodData(
72 ScriptState* scriptState,
73 const WebPaymentMethodData& webMethodData) {
74 PaymentMethodData methodData;
75 Vector<String> supportedMethods;
76 for (const auto& method : webMethodData.supportedMethods) {
77 supportedMethods.append(method);
78 }
79 methodData.setSupportedMethods(supportedMethods);
80 methodData.setData(
81 stringDataToScriptValue(scriptState, webMethodData.stringifiedData));
82 return methodData;
83 }
84
85 } // namespace
86
87 PaymentAppRequestData PaymentAppRequestDataConversion::toPaymentAppRequestData(
88 ScriptState* scriptState,
89 const WebPaymentAppRequestData& webData) {
90 PaymentAppRequestData data;
91
92 data.setOrigin(webData.origin);
93 HeapVector<PaymentMethodData> methodData;
94 for (const auto& md : webData.methodData) {
95 methodData.append(toPaymentMethodData(scriptState, md));
96 }
97 data.setMethodData(methodData);
98 data.setTotal(toPaymentItem(webData.total));
99 HeapVector<PaymentDetailsModifier> modifiers;
100 for (const auto& modifier : webData.modifiers) {
101 modifiers.append(toPaymentDetailsModifier(scriptState, modifier));
102 }
103 data.setOptionId(webData.optionId);
104 return data;
105 }
106
107 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698