| 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/ScriptPromiseResolver.h" | 8 #include "bindings/core/v8/ScriptPromiseResolver.h" |
| 9 #include "bindings/core/v8/ScriptState.h" | 9 #include "bindings/core/v8/ScriptState.h" |
| 10 #include "bindings/core/v8/V8StringResource.h" | 10 #include "bindings/core/v8/V8StringResource.h" |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 179 } | 179 } |
| 180 } | 180 } |
| 181 | 181 |
| 182 void validateAndConvertDisplayItems(const HeapVector<PaymentItem>& input, | 182 void validateAndConvertDisplayItems(const HeapVector<PaymentItem>& input, |
| 183 Vector<PaymentItemPtr>& output, | 183 Vector<PaymentItemPtr>& output, |
| 184 ExceptionState& exceptionState) { | 184 ExceptionState& exceptionState) { |
| 185 for (const PaymentItem& item : input) { | 185 for (const PaymentItem& item : input) { |
| 186 validateShippingOptionOrPaymentItem(item, exceptionState); | 186 validateShippingOptionOrPaymentItem(item, exceptionState); |
| 187 if (exceptionState.hadException()) | 187 if (exceptionState.hadException()) |
| 188 return; | 188 return; |
| 189 output.append(payments::mojom::blink::PaymentItem::From(item)); | 189 output.push_back(payments::mojom::blink::PaymentItem::From(item)); |
| 190 } | 190 } |
| 191 } | 191 } |
| 192 | 192 |
| 193 // Validates and converts |input| shipping options into |output|. Throws an | 193 // Validates and converts |input| shipping options into |output|. Throws an |
| 194 // exception if the data is not valid, except for duplicate identifiers, which | 194 // exception if the data is not valid, except for duplicate identifiers, which |
| 195 // returns an empty |output| instead of throwing an exception. There's no need | 195 // returns an empty |output| instead of throwing an exception. There's no need |
| 196 // to clear |output| when an exception is thrown, because the caller takes care | 196 // to clear |output| when an exception is thrown, because the caller takes care |
| 197 // of deleting |output|. | 197 // of deleting |output|. |
| 198 void validateAndConvertShippingOptions( | 198 void validateAndConvertShippingOptions( |
| 199 const HeapVector<PaymentShippingOption>& input, | 199 const HeapVector<PaymentShippingOption>& input, |
| (...skipping 11 matching lines...) Expand all Loading... |
| 211 output.clear(); | 211 output.clear(); |
| 212 return; | 212 return; |
| 213 } | 213 } |
| 214 | 214 |
| 215 uniqueIds.add(option.id()); | 215 uniqueIds.add(option.id()); |
| 216 | 216 |
| 217 validateShippingOptionOrPaymentItem(option, exceptionState); | 217 validateShippingOptionOrPaymentItem(option, exceptionState); |
| 218 if (exceptionState.hadException()) | 218 if (exceptionState.hadException()) |
| 219 return; | 219 return; |
| 220 | 220 |
| 221 output.append(payments::mojom::blink::PaymentShippingOption::From(option)); | 221 output.push_back( |
| 222 payments::mojom::blink::PaymentShippingOption::From(option)); |
| 222 } | 223 } |
| 223 } | 224 } |
| 224 | 225 |
| 225 void validateAndConvertTotal(const PaymentItem& input, | 226 void validateAndConvertTotal(const PaymentItem& input, |
| 226 PaymentItemPtr& output, | 227 PaymentItemPtr& output, |
| 227 ExceptionState& exceptionState) { | 228 ExceptionState& exceptionState) { |
| 228 validateShippingOptionOrPaymentItem(input, exceptionState); | 229 validateShippingOptionOrPaymentItem(input, exceptionState); |
| 229 if (exceptionState.hadException()) | 230 if (exceptionState.hadException()) |
| 230 return; | 231 return; |
| 231 | 232 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 261 androidPay.minGooglePlayServicesVersion().toIntStrict(&ok); | 262 androidPay.minGooglePlayServicesVersion().toIntStrict(&ok); |
| 262 if (ok) { | 263 if (ok) { |
| 263 output->min_google_play_services_version = minGooglePlayServicesVersion; | 264 output->min_google_play_services_version = minGooglePlayServicesVersion; |
| 264 } | 265 } |
| 265 } | 266 } |
| 266 | 267 |
| 267 if (androidPay.hasAllowedCardNetworks()) { | 268 if (androidPay.hasAllowedCardNetworks()) { |
| 268 for (const String& allowedCardNetwork : androidPay.allowedCardNetworks()) { | 269 for (const String& allowedCardNetwork : androidPay.allowedCardNetworks()) { |
| 269 for (size_t i = 0; i < arraysize(kAndroidPayNetwork); ++i) { | 270 for (size_t i = 0; i < arraysize(kAndroidPayNetwork); ++i) { |
| 270 if (allowedCardNetwork == kAndroidPayNetwork[i].name) { | 271 if (allowedCardNetwork == kAndroidPayNetwork[i].name) { |
| 271 output->allowed_card_networks.append(kAndroidPayNetwork[i].code); | 272 output->allowed_card_networks.push_back(kAndroidPayNetwork[i].code); |
| 272 break; | 273 break; |
| 273 } | 274 } |
| 274 } | 275 } |
| 275 } | 276 } |
| 276 } | 277 } |
| 277 | 278 |
| 278 if (androidPay.hasPaymentMethodTokenizationParameters()) { | 279 if (androidPay.hasPaymentMethodTokenizationParameters()) { |
| 279 const blink::AndroidPayTokenization& tokenization = | 280 const blink::AndroidPayTokenization& tokenization = |
| 280 androidPay.paymentMethodTokenizationParameters(); | 281 androidPay.paymentMethodTokenizationParameters(); |
| 281 output->tokenization_type = | 282 output->tokenization_type = |
| (...skipping 10 matching lines...) Expand all Loading... |
| 292 | 293 |
| 293 if (tokenization.hasParameters()) { | 294 if (tokenization.hasParameters()) { |
| 294 const Vector<String>& keys = | 295 const Vector<String>& keys = |
| 295 tokenization.parameters().getPropertyNames(exceptionState); | 296 tokenization.parameters().getPropertyNames(exceptionState); |
| 296 if (exceptionState.hadException()) | 297 if (exceptionState.hadException()) |
| 297 return; | 298 return; |
| 298 String value; | 299 String value; |
| 299 for (const String& key : keys) { | 300 for (const String& key : keys) { |
| 300 if (!DictionaryHelper::get(tokenization.parameters(), key, value)) | 301 if (!DictionaryHelper::get(tokenization.parameters(), key, value)) |
| 301 continue; | 302 continue; |
| 302 output->parameters.append( | 303 output->parameters.push_back( |
| 303 payments::mojom::blink::AndroidPayTokenizationParameter::New()); | 304 payments::mojom::blink::AndroidPayTokenizationParameter::New()); |
| 304 output->parameters.back()->key = key; | 305 output->parameters.back()->key = key; |
| 305 output->parameters.back()->value = value; | 306 output->parameters.back()->value = value; |
| 306 } | 307 } |
| 307 } | 308 } |
| 308 } | 309 } |
| 309 } | 310 } |
| 310 | 311 |
| 311 void stringifyAndParseMethodSpecificData(const ScriptValue& input, | 312 void stringifyAndParseMethodSpecificData(const ScriptValue& input, |
| 312 PaymentMethodDataPtr& output, | 313 PaymentMethodDataPtr& output, |
| (...skipping 21 matching lines...) Expand all Loading... |
| 334 const HeapVector<PaymentDetailsModifier>& input, | 335 const HeapVector<PaymentDetailsModifier>& input, |
| 335 Vector<PaymentDetailsModifierPtr>& output, | 336 Vector<PaymentDetailsModifierPtr>& output, |
| 336 ExceptionState& exceptionState) { | 337 ExceptionState& exceptionState) { |
| 337 if (input.isEmpty()) { | 338 if (input.isEmpty()) { |
| 338 exceptionState.throwTypeError( | 339 exceptionState.throwTypeError( |
| 339 "Must specify at least one payment details modifier"); | 340 "Must specify at least one payment details modifier"); |
| 340 return; | 341 return; |
| 341 } | 342 } |
| 342 | 343 |
| 343 for (const PaymentDetailsModifier& modifier : input) { | 344 for (const PaymentDetailsModifier& modifier : input) { |
| 344 output.append(payments::mojom::blink::PaymentDetailsModifier::New()); | 345 output.push_back(payments::mojom::blink::PaymentDetailsModifier::New()); |
| 345 if (modifier.hasTotal()) { | 346 if (modifier.hasTotal()) { |
| 346 validateAndConvertTotal(modifier.total(), output.back()->total, | 347 validateAndConvertTotal(modifier.total(), output.back()->total, |
| 347 exceptionState); | 348 exceptionState); |
| 348 if (exceptionState.hadException()) | 349 if (exceptionState.hadException()) |
| 349 return; | 350 return; |
| 350 } | 351 } |
| 351 | 352 |
| 352 if (modifier.hasAdditionalDisplayItems()) { | 353 if (modifier.hasAdditionalDisplayItems()) { |
| 353 validateAndConvertDisplayItems(modifier.additionalDisplayItems(), | 354 validateAndConvertDisplayItems(modifier.additionalDisplayItems(), |
| 354 output.back()->additional_display_items, | 355 output.back()->additional_display_items, |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 446 return; | 447 return; |
| 447 } | 448 } |
| 448 | 449 |
| 449 for (const PaymentMethodData paymentMethodData : input) { | 450 for (const PaymentMethodData paymentMethodData : input) { |
| 450 if (paymentMethodData.supportedMethods().isEmpty()) { | 451 if (paymentMethodData.supportedMethods().isEmpty()) { |
| 451 exceptionState.throwTypeError( | 452 exceptionState.throwTypeError( |
| 452 "Must specify at least one payment method identifier"); | 453 "Must specify at least one payment method identifier"); |
| 453 return; | 454 return; |
| 454 } | 455 } |
| 455 | 456 |
| 456 output.append(payments::mojom::blink::PaymentMethodData::New()); | 457 output.push_back(payments::mojom::blink::PaymentMethodData::New()); |
| 457 output.back()->supported_methods = paymentMethodData.supportedMethods(); | 458 output.back()->supported_methods = paymentMethodData.supportedMethods(); |
| 458 | 459 |
| 459 if (paymentMethodData.hasData() && !paymentMethodData.data().isEmpty()) { | 460 if (paymentMethodData.hasData() && !paymentMethodData.data().isEmpty()) { |
| 460 stringifyAndParseMethodSpecificData(paymentMethodData.data(), | 461 stringifyAndParseMethodSpecificData(paymentMethodData.data(), |
| 461 output.back(), exceptionState); | 462 output.back(), exceptionState); |
| 462 } else { | 463 } else { |
| 463 output.back()->stringified_data = ""; | 464 output.back()->stringified_data = ""; |
| 464 } | 465 } |
| 465 } | 466 } |
| 466 } | 467 } |
| (...skipping 453 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 920 m_completeResolver.clear(); | 921 m_completeResolver.clear(); |
| 921 m_showResolver.clear(); | 922 m_showResolver.clear(); |
| 922 m_abortResolver.clear(); | 923 m_abortResolver.clear(); |
| 923 m_canMakePaymentResolver.clear(); | 924 m_canMakePaymentResolver.clear(); |
| 924 if (m_clientBinding.is_bound()) | 925 if (m_clientBinding.is_bound()) |
| 925 m_clientBinding.Close(); | 926 m_clientBinding.Close(); |
| 926 m_paymentProvider.reset(); | 927 m_paymentProvider.reset(); |
| 927 } | 928 } |
| 928 | 929 |
| 929 } // namespace blink | 930 } // namespace blink |
| OLD | NEW |