Chromium Code Reviews| 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" |
| 11 #include "bindings/modules/v8/V8AndroidPayMethodData.h" | 11 #include "bindings/modules/v8/V8AndroidPayMethodData.h" |
| 12 #include "bindings/modules/v8/V8BasicCardRequest.h" | |
| 12 #include "bindings/modules/v8/V8PaymentDetails.h" | 13 #include "bindings/modules/v8/V8PaymentDetails.h" |
| 13 #include "core/EventTypeNames.h" | 14 #include "core/EventTypeNames.h" |
| 14 #include "core/dom/DOMException.h" | 15 #include "core/dom/DOMException.h" |
| 15 #include "core/dom/ExceptionCode.h" | 16 #include "core/dom/ExceptionCode.h" |
| 16 #include "core/events/Event.h" | 17 #include "core/events/Event.h" |
| 17 #include "core/events/EventQueue.h" | 18 #include "core/events/EventQueue.h" |
| 18 #include "core/frame/FrameOwner.h" | 19 #include "core/frame/FrameOwner.h" |
| 19 #include "core/html/HTMLIFrameElement.h" | 20 #include "core/html/HTMLIFrameElement.h" |
| 20 #include "modules/EventTargetModulesNames.h" | 21 #include "modules/EventTargetModulesNames.h" |
| 21 #include "modules/payments/AndroidPayMethodData.h" | 22 #include "modules/payments/AndroidPayMethodData.h" |
| 22 #include "modules/payments/AndroidPayTokenization.h" | 23 #include "modules/payments/AndroidPayTokenization.h" |
| 24 #include "modules/payments/BasicCardRequest.h" | |
| 23 #include "modules/payments/HTMLIFrameElementPayments.h" | 25 #include "modules/payments/HTMLIFrameElementPayments.h" |
| 24 #include "modules/payments/PaymentAddress.h" | 26 #include "modules/payments/PaymentAddress.h" |
| 25 #include "modules/payments/PaymentItem.h" | 27 #include "modules/payments/PaymentItem.h" |
| 26 #include "modules/payments/PaymentRequestUpdateEvent.h" | 28 #include "modules/payments/PaymentRequestUpdateEvent.h" |
| 27 #include "modules/payments/PaymentResponse.h" | 29 #include "modules/payments/PaymentResponse.h" |
| 28 #include "modules/payments/PaymentShippingOption.h" | 30 #include "modules/payments/PaymentShippingOption.h" |
| 29 #include "modules/payments/PaymentsValidators.h" | 31 #include "modules/payments/PaymentsValidators.h" |
| 30 #include "mojo/public/cpp/bindings/interface_request.h" | 32 #include "mojo/public/cpp/bindings/interface_request.h" |
| 31 #include "mojo/public/cpp/bindings/wtf_array.h" | 33 #include "mojo/public/cpp/bindings/wtf_array.h" |
| 32 #include "platform/mojo/MojoHelper.h" | 34 #include "platform/mojo/MojoHelper.h" |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 172 } | 174 } |
| 173 }; | 175 }; |
| 174 | 176 |
| 175 } // namespace mojo | 177 } // namespace mojo |
| 176 | 178 |
| 177 namespace blink { | 179 namespace blink { |
| 178 namespace { | 180 namespace { |
| 179 | 181 |
| 180 using payments::mojom::blink::AndroidPayCardNetwork; | 182 using payments::mojom::blink::AndroidPayCardNetwork; |
| 181 using payments::mojom::blink::AndroidPayTokenization; | 183 using payments::mojom::blink::AndroidPayTokenization; |
| 184 using payments::mojom::blink::BasicCardNetwork; | |
| 185 using payments::mojom::blink::BasicCardType; | |
| 182 | 186 |
| 183 // If the website does not call complete() 60 seconds after show() has been | 187 // If the website does not call complete() 60 seconds after show() has been |
| 184 // resolved, then behave as if the website called complete("fail"). | 188 // resolved, then behave as if the website called complete("fail"). |
| 185 static const int completeTimeoutSeconds = 60; | 189 static const int completeTimeoutSeconds = 60; |
| 186 | 190 |
| 187 const struct { | 191 const struct { |
| 188 const AndroidPayCardNetwork code; | 192 const AndroidPayCardNetwork code; |
| 189 const char* name; | 193 const char* name; |
| 190 } kAndroidPayNetwork[] = {{AndroidPayCardNetwork::AMEX, "AMEX"}, | 194 } kAndroidPayNetwork[] = {{AndroidPayCardNetwork::AMEX, "AMEX"}, |
| 191 {AndroidPayCardNetwork::DISCOVER, "DISCOVER"}, | 195 {AndroidPayCardNetwork::DISCOVER, "DISCOVER"}, |
| 192 {AndroidPayCardNetwork::MASTERCARD, "MASTERCARD"}, | 196 {AndroidPayCardNetwork::MASTERCARD, "MASTERCARD"}, |
| 193 {AndroidPayCardNetwork::VISA, "VISA"}}; | 197 {AndroidPayCardNetwork::VISA, "VISA"}}; |
| 194 | 198 |
| 195 const struct { | 199 const struct { |
| 196 const AndroidPayTokenization code; | 200 const AndroidPayTokenization code; |
| 197 const char* name; | 201 const char* name; |
| 198 } kAndroidPayTokenization[] = { | 202 } kAndroidPayTokenization[] = { |
| 199 {AndroidPayTokenization::GATEWAY_TOKEN, "GATEWAY_TOKEN"}, | 203 {AndroidPayTokenization::GATEWAY_TOKEN, "GATEWAY_TOKEN"}, |
| 200 {AndroidPayTokenization::NETWORK_TOKEN, "NETWORK_TOKEN"}}; | 204 {AndroidPayTokenization::NETWORK_TOKEN, "NETWORK_TOKEN"}}; |
| 201 | 205 |
| 206 const struct { | |
| 207 const BasicCardNetwork code; | |
| 208 const char* name; | |
| 209 } kBasicCardNetworks[] = {{BasicCardNetwork::AMEX, "amex"}, | |
| 210 {BasicCardNetwork::DINERS, "diners"}, | |
| 211 {BasicCardNetwork::DISCOVER, "discover"}, | |
| 212 {BasicCardNetwork::JCB, "jcb"}, | |
| 213 {BasicCardNetwork::MASTERCARD, "mastercard"}, | |
| 214 {BasicCardNetwork::UNIONPAY, "unionpay"}, | |
| 215 {BasicCardNetwork::VISA, "visa"}}; | |
| 216 | |
| 217 const struct { | |
| 218 const BasicCardType code; | |
| 219 const char* name; | |
| 220 } kBasicCardTypes[] = {{BasicCardType::CREDIT, "credit"}, | |
| 221 {BasicCardType::DEBIT, "debit"}, | |
| 222 {BasicCardType::PREPAID, "prepaid"}}; | |
| 223 | |
| 202 // Validates ShippingOption or PaymentItem, which happen to have identical | 224 // Validates ShippingOption or PaymentItem, which happen to have identical |
| 203 // fields, except for "id", which is present only in ShippingOption. | 225 // fields, except for "id", which is present only in ShippingOption. |
| 204 template <typename T> | 226 template <typename T> |
| 205 void validateShippingOptionOrPaymentItem(const T& item, | 227 void validateShippingOptionOrPaymentItem(const T& item, |
| 206 ExceptionState& exceptionState) { | 228 ExceptionState& exceptionState) { |
| 207 if (!item.hasLabel() || item.label().isEmpty()) { | 229 if (!item.hasLabel() || item.label().isEmpty()) { |
| 208 exceptionState.throwTypeError("Item label required"); | 230 exceptionState.throwTypeError("Item label required"); |
| 209 return; | 231 return; |
| 210 } | 232 } |
| 211 | 233 |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 350 | 372 |
| 351 String errorMessage; | 373 String errorMessage; |
| 352 if (!PaymentsValidators::isValidErrorMsgFormat(details.error(), | 374 if (!PaymentsValidators::isValidErrorMsgFormat(details.error(), |
| 353 &errorMessage)) { | 375 &errorMessage)) { |
| 354 exceptionState.throwTypeError(errorMessage); | 376 exceptionState.throwTypeError(errorMessage); |
| 355 } | 377 } |
| 356 | 378 |
| 357 return keepShippingOptions; | 379 return keepShippingOptions; |
| 358 } | 380 } |
| 359 | 381 |
| 360 void maybeSetAndroidPayMethodata( | 382 void maybeSetAndroidPayMethodData( |
| 361 const ScriptValue& input, | 383 const ScriptValue& input, |
| 362 payments::mojom::blink::PaymentMethodDataPtr& output) { | 384 payments::mojom::blink::PaymentMethodDataPtr& output) { |
| 363 AndroidPayMethodData androidPay; | 385 AndroidPayMethodData androidPay; |
| 364 TrackExceptionState exceptionState; | 386 TrackExceptionState exceptionState; |
| 365 V8AndroidPayMethodData::toImpl(input.isolate(), input.v8Value(), androidPay, | 387 V8AndroidPayMethodData::toImpl(input.isolate(), input.v8Value(), androidPay, |
| 366 exceptionState); | 388 exceptionState); |
| 367 if (exceptionState.hadException()) | 389 if (exceptionState.hadException()) |
| 368 return; | 390 return; |
| 369 | 391 |
| 370 if (androidPay.hasEnvironment() && androidPay.environment() == "TEST") | 392 if (androidPay.hasEnvironment() && androidPay.environment() == "TEST") |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 417 payments::mojom::blink::AndroidPayTokenizationParameter::New(); | 439 payments::mojom::blink::AndroidPayTokenizationParameter::New(); |
| 418 output->parameters[numberOfParameters]->key = keys[i]; | 440 output->parameters[numberOfParameters]->key = keys[i]; |
| 419 output->parameters[numberOfParameters]->value = value; | 441 output->parameters[numberOfParameters]->value = value; |
| 420 ++numberOfParameters; | 442 ++numberOfParameters; |
| 421 } | 443 } |
| 422 output->parameters.resize(numberOfParameters); | 444 output->parameters.resize(numberOfParameters); |
| 423 } | 445 } |
| 424 } | 446 } |
| 425 } | 447 } |
| 426 | 448 |
| 449 void maybeSetBasicCardMethodData( | |
| 450 const ScriptValue& input, | |
| 451 payments::mojom::blink::PaymentMethodDataPtr& output) { | |
| 452 BasicCardRequest basicCard; | |
| 453 TrackExceptionState exceptionState; | |
|
haraken
2016/11/22 01:18:59
It looks strange to use TrackExceptionState in pro
please use gerrit instead
2016/11/22 03:10:55
That's an excellent point. I am indeed ignoring th
haraken
2016/11/22 04:26:03
Yeah, but would it be better to pass in the Except
please use gerrit instead
2016/11/22 15:20:03
Done. I'm deferring to your expertise on this subj
| |
| 454 V8BasicCardRequest::toImpl(input.isolate(), input.v8Value(), basicCard, | |
| 455 exceptionState); | |
| 456 if (exceptionState.hadException()) | |
| 457 return; | |
| 458 | |
| 459 if (basicCard.hasSupportedNetworks()) { | |
| 460 output->supported_networks.resize(basicCard.supportedNetworks().size()); | |
| 461 size_t numberOfNetworks = 0; | |
| 462 for (size_t i = 0; i < basicCard.supportedNetworks().size(); ++i) { | |
| 463 for (size_t j = 0; j < arraysize(kBasicCardNetworks); ++j) { | |
| 464 if (basicCard.supportedNetworks()[i] == kBasicCardNetworks[j].name) { | |
| 465 output->supported_networks[numberOfNetworks++] = | |
| 466 kBasicCardNetworks[j].code; | |
| 467 break; | |
| 468 } | |
| 469 } | |
| 470 } | |
| 471 output->supported_networks.resize(numberOfNetworks); | |
| 472 } | |
| 473 | |
| 474 if (basicCard.hasSupportedTypes()) { | |
| 475 output->supported_types.resize(basicCard.supportedTypes().size()); | |
| 476 size_t numberOfTypes = 0; | |
| 477 for (size_t i = 0; i < basicCard.supportedTypes().size(); ++i) { | |
| 478 for (size_t j = 0; j < arraysize(kBasicCardTypes); ++j) { | |
| 479 if (basicCard.supportedTypes()[i] == kBasicCardTypes[j].name) { | |
| 480 output->supported_types[numberOfTypes++] = kBasicCardTypes[j].code; | |
| 481 break; | |
| 482 } | |
| 483 } | |
| 484 } | |
| 485 output->supported_types.resize(numberOfTypes); | |
| 486 } | |
| 487 } | |
| 488 | |
| 427 void validateAndConvertPaymentMethodData( | 489 void validateAndConvertPaymentMethodData( |
| 428 const HeapVector<PaymentMethodData>& input, | 490 const HeapVector<PaymentMethodData>& input, |
| 429 Vector<payments::mojom::blink::PaymentMethodDataPtr>& output, | 491 Vector<payments::mojom::blink::PaymentMethodDataPtr>& output, |
| 430 ExceptionState& exceptionState) { | 492 ExceptionState& exceptionState) { |
| 431 if (input.isEmpty()) { | 493 if (input.isEmpty()) { |
| 432 exceptionState.throwTypeError( | 494 exceptionState.throwTypeError( |
| 433 "Must specify at least one payment method identifier"); | 495 "Must specify at least one payment method identifier"); |
| 434 return; | 496 return; |
| 435 } | 497 } |
| 436 | 498 |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 461 "Unable to parse payment method specific data"); | 523 "Unable to parse payment method specific data"); |
| 462 return; | 524 return; |
| 463 } | 525 } |
| 464 stringifiedData = | 526 stringifiedData = |
| 465 v8StringToWebCoreString<String>(value, DoNotExternalize); | 527 v8StringToWebCoreString<String>(value, DoNotExternalize); |
| 466 } | 528 } |
| 467 | 529 |
| 468 output[i] = payments::mojom::blink::PaymentMethodData::New(); | 530 output[i] = payments::mojom::blink::PaymentMethodData::New(); |
| 469 output[i]->supported_methods = paymentMethodData.supportedMethods(); | 531 output[i]->supported_methods = paymentMethodData.supportedMethods(); |
| 470 output[i]->stringified_data = stringifiedData; | 532 output[i]->stringified_data = stringifiedData; |
| 471 maybeSetAndroidPayMethodata(paymentMethodData.data(), output[i]); | 533 maybeSetAndroidPayMethodData(paymentMethodData.data(), output[i]); |
| 534 maybeSetBasicCardMethodData(paymentMethodData.data(), output[i]); | |
| 472 } | 535 } |
| 473 } | 536 } |
| 474 | 537 |
| 475 String getSelectedShippingOption(const PaymentDetails& details) { | 538 String getSelectedShippingOption(const PaymentDetails& details) { |
| 476 String result; | 539 String result; |
| 477 if (!details.hasShippingOptions()) | 540 if (!details.hasShippingOptions()) |
| 478 return result; | 541 return result; |
| 479 | 542 |
| 480 for (int i = details.shippingOptions().size() - 1; i >= 0; --i) { | 543 for (int i = details.shippingOptions().size() - 1; i >= 0; --i) { |
| 481 if (details.shippingOptions()[i].hasSelected() && | 544 if (details.shippingOptions()[i].hasSelected() && |
| (...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 963 m_completeResolver.clear(); | 1026 m_completeResolver.clear(); |
| 964 m_showResolver.clear(); | 1027 m_showResolver.clear(); |
| 965 m_abortResolver.clear(); | 1028 m_abortResolver.clear(); |
| 966 m_canMakeActivePaymentResolver.clear(); | 1029 m_canMakeActivePaymentResolver.clear(); |
| 967 if (m_clientBinding.is_bound()) | 1030 if (m_clientBinding.is_bound()) |
| 968 m_clientBinding.Close(); | 1031 m_clientBinding.Close(); |
| 969 m_paymentProvider.reset(); | 1032 m_paymentProvider.reset(); |
| 970 } | 1033 } |
| 971 | 1034 |
| 972 } // namespace blink | 1035 } // namespace blink |
| OLD | NEW |