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

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

Issue 1994913002: PaymentRequest: Remove id attribute from PaymentItem. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 months 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
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/PaymentRequest.h" 5 #include "modules/payments/PaymentRequest.h"
6 6
7 #include "bindings/core/v8/ExceptionState.h" 7 #include "bindings/core/v8/ExceptionState.h"
8 #include "bindings/core/v8/JSONValuesForV8.h" 8 #include "bindings/core/v8/JSONValuesForV8.h"
9 #include "bindings/core/v8/ScriptPromiseResolver.h" 9 #include "bindings/core/v8/ScriptPromiseResolver.h"
10 #include "bindings/core/v8/ScriptState.h" 10 #include "bindings/core/v8/ScriptState.h"
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 output->value = input.value(); 49 output->value = input.value();
50 return output; 50 return output;
51 } 51 }
52 }; 52 };
53 53
54 template <> 54 template <>
55 struct TypeConverter<PaymentItemPtr, blink::PaymentItem> { 55 struct TypeConverter<PaymentItemPtr, blink::PaymentItem> {
56 static PaymentItemPtr Convert(const blink::PaymentItem& input) 56 static PaymentItemPtr Convert(const blink::PaymentItem& input)
57 { 57 {
58 PaymentItemPtr output = PaymentItem::New(); 58 PaymentItemPtr output = PaymentItem::New();
59 output->id = input.id();
60 output->label = input.label(); 59 output->label = input.label();
61 output->amount = CurrencyAmount::From(input.amount()); 60 output->amount = CurrencyAmount::From(input.amount());
62 return output; 61 return output;
63 } 62 }
64 }; 63 };
65 64
66 template <> 65 template <>
67 struct TypeConverter<ShippingOptionPtr, blink::ShippingOption> { 66 struct TypeConverter<ShippingOptionPtr, blink::ShippingOption> {
68 static ShippingOptionPtr Convert(const blink::ShippingOption& input) 67 static ShippingOptionPtr Convert(const blink::ShippingOption& input)
69 { 68 {
(...skipping 28 matching lines...) Expand all
98 return output; 97 return output;
99 } 98 }
100 }; 99 };
101 100
102 } // namespace mojo 101 } // namespace mojo
103 102
104 namespace blink { 103 namespace blink {
105 namespace { 104 namespace {
106 105
107 // Validates ShippingOption and PaymentItem dictionaries, which happen to have i dentical fields. 106 // Validates ShippingOption and PaymentItem dictionaries, which happen to have i dentical fields.
107 // except for "id", which is present only in ShippingOption.
108 template <typename T> 108 template <typename T>
109 void validateShippingOptionsOrPaymentItems(HeapVector<T> items, ExceptionState& exceptionState) 109 void validateShippingOptionsOrPaymentItems(HeapVector<T> items, ExceptionState& exceptionState)
110 { 110 {
111 String errorMessage; 111 String errorMessage;
112 for (const auto& item : items) { 112 for (const auto& item : items) {
113 if (!item.hasId() || item.id().isEmpty()) {
114 exceptionState.throwTypeError("Item id required");
115 return;
116 }
117
118 if (!item.hasLabel() || item.label().isEmpty()) { 113 if (!item.hasLabel() || item.label().isEmpty()) {
119 exceptionState.throwTypeError("Item label required"); 114 exceptionState.throwTypeError("Item label required");
120 return; 115 return;
121 } 116 }
122 117
123 if (!item.hasAmount()) { 118 if (!item.hasAmount()) {
124 exceptionState.throwTypeError("Currency amount required"); 119 exceptionState.throwTypeError("Currency amount required");
125 return; 120 return;
126 } 121 }
127 122
(...skipping 12 matching lines...) Expand all
140 return; 135 return;
141 } 136 }
142 137
143 if (!PaymentsValidators::isValidAmountFormat(item.amount().value(), &err orMessage)) { 138 if (!PaymentsValidators::isValidAmountFormat(item.amount().value(), &err orMessage)) {
144 exceptionState.throwTypeError(errorMessage); 139 exceptionState.throwTypeError(errorMessage);
145 return; 140 return;
146 } 141 }
147 } 142 }
148 } 143 }
149 144
145 void validateShippingOptionsIds(HeapVector<ShippingOption> options, ExceptionSta te& exceptionState)
146 {
147 for (const auto& option : options) {
148 if (!option.hasId() | option.id().isEmpty()) {
please use gerrit instead 2016/05/22 22:55:29 | should be ||
zino 2016/05/23 01:42:30 OMG! it's terrible mistake.. Done.
149 exceptionState.throwTypeError("ShippingOption id required");
150 return;
151 }
152 }
153 }
154
150 void validatePaymentDetails(const PaymentDetails& details, ExceptionState& excep tionState) 155 void validatePaymentDetails(const PaymentDetails& details, ExceptionState& excep tionState)
151 { 156 {
152 if (!details.hasItems()) { 157 if (!details.hasItems()) {
153 exceptionState.throwTypeError("Must specify items"); 158 exceptionState.throwTypeError("Must specify items");
154 return; 159 return;
155 } 160 }
156 161
157 if (details.items().isEmpty()) { 162 if (details.items().isEmpty()) {
158 exceptionState.throwTypeError("Must specify at least one item"); 163 exceptionState.throwTypeError("Must specify at least one item");
159 return; 164 return;
160 } 165 }
161 166
162 validateShippingOptionsOrPaymentItems(details.items(), exceptionState); 167 validateShippingOptionsOrPaymentItems(details.items(), exceptionState);
163 if (exceptionState.hadException()) 168 if (exceptionState.hadException())
164 return; 169 return;
165 170
166 if (details.hasShippingOptions()) 171 if (details.hasShippingOptions()) {
167 validateShippingOptionsOrPaymentItems(details.shippingOptions(), excepti onState); 172 validateShippingOptionsOrPaymentItems(details.shippingOptions(), excepti onState);
173 validateShippingOptionsIds(details.shippingOptions(), exceptionState);
174 }
168 } 175 }
169 176
170 } // namespace 177 } // namespace
171 178
172 PaymentRequest* PaymentRequest::create(ScriptState* scriptState, const Vector<St ring>& supportedMethods, const PaymentDetails& details, ExceptionState& exceptio nState) 179 PaymentRequest* PaymentRequest::create(ScriptState* scriptState, const Vector<St ring>& supportedMethods, const PaymentDetails& details, ExceptionState& exceptio nState)
173 { 180 {
174 return new PaymentRequest(scriptState, supportedMethods, details, PaymentOpt ions(), ScriptValue(), exceptionState); 181 return new PaymentRequest(scriptState, supportedMethods, details, PaymentOpt ions(), ScriptValue(), exceptionState);
175 } 182 }
176 183
177 PaymentRequest* PaymentRequest::create(ScriptState* scriptState, const Vector<St ring>& supportedMethods, const PaymentDetails& details, const PaymentOptions& op tions, ExceptionState& exceptionState) 184 PaymentRequest* PaymentRequest::create(ScriptState* scriptState, const Vector<St ring>& supportedMethods, const PaymentDetails& details, const PaymentOptions& op tions, ExceptionState& exceptionState)
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after
433 void PaymentRequest::clearResolversAndCloseMojoConnection() 440 void PaymentRequest::clearResolversAndCloseMojoConnection()
434 { 441 {
435 m_completeResolver.clear(); 442 m_completeResolver.clear();
436 m_showResolver.clear(); 443 m_showResolver.clear();
437 if (m_clientBinding.is_bound()) 444 if (m_clientBinding.is_bound())
438 m_clientBinding.Close(); 445 m_clientBinding.Close();
439 m_paymentProvider.reset(); 446 m_paymentProvider.reset();
440 } 447 }
441 448
442 } // namespace blink 449 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698