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/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 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
199 { | 199 { |
200 for (const auto& item : items) { | 200 for (const auto& item : items) { |
201 validateShippingOptionOrPaymentItem(item, exceptionState); | 201 validateShippingOptionOrPaymentItem(item, exceptionState); |
202 if (exceptionState.hadException()) | 202 if (exceptionState.hadException()) |
203 return; | 203 return; |
204 } | 204 } |
205 } | 205 } |
206 | 206 |
207 void validateShippingOptions(const HeapVector<PaymentShippingOption>& options, E
xceptionState& exceptionState) | 207 void validateShippingOptions(const HeapVector<PaymentShippingOption>& options, E
xceptionState& exceptionState) |
208 { | 208 { |
| 209 HashSet<String> uniqueIds; |
209 for (const auto& option : options) { | 210 for (const auto& option : options) { |
210 if (!option.hasId() || option.id().isEmpty()) { | 211 if (!option.hasId() || option.id().isEmpty()) { |
211 exceptionState.throwTypeError("ShippingOption id required"); | 212 exceptionState.throwTypeError("ShippingOption id required"); |
212 return; | 213 return; |
213 } | 214 } |
214 | 215 |
| 216 if (uniqueIds.contains(option.id())) { |
| 217 exceptionState.throwTypeError("Duplicate shipping option identifiers
are not allowed"); |
| 218 return; |
| 219 } |
| 220 uniqueIds.add(option.id()); |
| 221 |
215 validateShippingOptionOrPaymentItem(option, exceptionState); | 222 validateShippingOptionOrPaymentItem(option, exceptionState); |
216 if (exceptionState.hadException()) | 223 if (exceptionState.hadException()) |
217 return; | 224 return; |
218 } | 225 } |
219 } | 226 } |
220 | 227 |
221 void validatePaymentDetailsModifiers(const HeapVector<PaymentDetailsModifier>& m
odifiers, ExceptionState& exceptionState) | 228 void validatePaymentDetailsModifiers(const HeapVector<PaymentDetailsModifier>& m
odifiers, ExceptionState& exceptionState) |
222 { | 229 { |
223 if (modifiers.isEmpty()) { | 230 if (modifiers.isEmpty()) { |
224 exceptionState.throwTypeError("Must specify at least one payment details
modifier"); | 231 exceptionState.throwTypeError("Must specify at least one payment details
modifier"); |
225 return; | 232 return; |
226 } | 233 } |
227 | 234 |
228 HashSet<String> uniqueMethods; | 235 HashSet<String> uniqueMethods; |
229 for (const auto& modifier : modifiers) { | 236 for (const auto& modifier : modifiers) { |
230 if (modifier.supportedMethods().isEmpty()) { | 237 if (modifier.supportedMethods().isEmpty()) { |
231 exceptionState.throwTypeError("Must specify at least one payment met
hod identifier"); | 238 exceptionState.throwTypeError("Must specify at least one payment met
hod identifier"); |
232 return; | 239 return; |
233 } | 240 } |
| 241 |
234 for (const auto& method : modifier.supportedMethods()) { | 242 for (const auto& method : modifier.supportedMethods()) { |
235 if (uniqueMethods.contains(method)) { | 243 if (uniqueMethods.contains(method)) { |
236 exceptionState.throwTypeError("Duplicate payment method identifi
ers are not allowed"); | 244 exceptionState.throwTypeError("Duplicate payment method identifi
ers are not allowed"); |
237 return; | 245 return; |
238 } | 246 } |
239 uniqueMethods.add(method); | 247 uniqueMethods.add(method); |
240 } | 248 } |
241 | 249 |
242 if (modifier.hasTotal()) { | 250 if (modifier.hasTotal()) { |
243 validateShippingOptionOrPaymentItem(modifier.total(), exceptionState
); | 251 validateShippingOptionOrPaymentItem(modifier.total(), exceptionState
); |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
297 exceptionState.throwTypeError("Must specify at least one payment method
identifier"); | 305 exceptionState.throwTypeError("Must specify at least one payment method
identifier"); |
298 return; | 306 return; |
299 } | 307 } |
300 | 308 |
301 HashSet<String> uniqueMethods; | 309 HashSet<String> uniqueMethods; |
302 for (const auto& pmd : paymentMethodData) { | 310 for (const auto& pmd : paymentMethodData) { |
303 if (pmd.supportedMethods().isEmpty()) { | 311 if (pmd.supportedMethods().isEmpty()) { |
304 exceptionState.throwTypeError("Must specify at least one payment met
hod identifier"); | 312 exceptionState.throwTypeError("Must specify at least one payment met
hod identifier"); |
305 return; | 313 return; |
306 } | 314 } |
| 315 |
307 for (const auto& method : pmd.supportedMethods()) { | 316 for (const auto& method : pmd.supportedMethods()) { |
308 if (uniqueMethods.contains(method)) { | 317 if (uniqueMethods.contains(method)) { |
309 exceptionState.throwTypeError("Duplicate payment method identifi
ers are not allowed"); | 318 exceptionState.throwTypeError("Duplicate payment method identifi
ers are not allowed"); |
310 return; | 319 return; |
311 } | 320 } |
312 uniqueMethods.add(method); | 321 uniqueMethods.add(method); |
313 } | 322 } |
314 | 323 |
315 String stringifiedData = ""; | 324 String stringifiedData = ""; |
316 if (pmd.hasData() && !pmd.data().isEmpty()) { | 325 if (pmd.hasData() && !pmd.data().isEmpty()) { |
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
624 { | 633 { |
625 m_completeResolver.clear(); | 634 m_completeResolver.clear(); |
626 m_showResolver.clear(); | 635 m_showResolver.clear(); |
627 m_abortResolver.clear(); | 636 m_abortResolver.clear(); |
628 if (m_clientBinding.is_bound()) | 637 if (m_clientBinding.is_bound()) |
629 m_clientBinding.Close(); | 638 m_clientBinding.Close(); |
630 m_paymentProvider.reset(); | 639 m_paymentProvider.reset(); |
631 } | 640 } |
632 | 641 |
633 } // namespace blink | 642 } // namespace blink |
OLD | NEW |