Chromium Code Reviews| Index: third_party/WebKit/Source/modules/payments/PaymentRequest.cpp |
| diff --git a/third_party/WebKit/Source/modules/payments/PaymentRequest.cpp b/third_party/WebKit/Source/modules/payments/PaymentRequest.cpp |
| index f67b63bede62e3795377d09323f5ff31669c1382..422e45668eda55f7564faafa5e3c078cbdd2a549 100644 |
| --- a/third_party/WebKit/Source/modules/payments/PaymentRequest.cpp |
| +++ b/third_party/WebKit/Source/modules/payments/PaymentRequest.cpp |
| @@ -9,6 +9,7 @@ |
| #include "bindings/core/v8/ScriptState.h" |
| #include "bindings/core/v8/V8StringResource.h" |
| #include "bindings/modules/v8/V8AndroidPayMethodData.h" |
| +#include "bindings/modules/v8/V8BasicCardRequest.h" |
| #include "bindings/modules/v8/V8PaymentDetails.h" |
| #include "core/EventTypeNames.h" |
| #include "core/dom/DOMException.h" |
| @@ -20,6 +21,7 @@ |
| #include "modules/EventTargetModulesNames.h" |
| #include "modules/payments/AndroidPayMethodData.h" |
| #include "modules/payments/AndroidPayTokenization.h" |
| +#include "modules/payments/BasicCardRequest.h" |
| #include "modules/payments/HTMLIFrameElementPayments.h" |
| #include "modules/payments/PaymentAddress.h" |
| #include "modules/payments/PaymentItem.h" |
| @@ -179,6 +181,8 @@ namespace { |
| using payments::mojom::blink::AndroidPayCardNetwork; |
| using payments::mojom::blink::AndroidPayTokenization; |
| +using payments::mojom::blink::BasicCardNetwork; |
| +using payments::mojom::blink::BasicCardType; |
| // If the website does not call complete() 60 seconds after show() has been |
| // resolved, then behave as if the website called complete("fail"). |
| @@ -199,6 +203,24 @@ const struct { |
| {AndroidPayTokenization::GATEWAY_TOKEN, "GATEWAY_TOKEN"}, |
| {AndroidPayTokenization::NETWORK_TOKEN, "NETWORK_TOKEN"}}; |
| +const struct { |
| + const BasicCardNetwork code; |
| + const char* name; |
| +} kBasicCardNetworks[] = {{BasicCardNetwork::AMEX, "amex"}, |
| + {BasicCardNetwork::DINERS, "diners"}, |
| + {BasicCardNetwork::DISCOVER, "discover"}, |
| + {BasicCardNetwork::JCB, "jcb"}, |
| + {BasicCardNetwork::MASTERCARD, "mastercard"}, |
| + {BasicCardNetwork::UNIONPAY, "unionpay"}, |
| + {BasicCardNetwork::VISA, "visa"}}; |
| + |
| +const struct { |
| + const BasicCardType code; |
| + const char* name; |
| +} kBasicCardTypes[] = {{BasicCardType::CREDIT, "credit"}, |
| + {BasicCardType::DEBIT, "debit"}, |
| + {BasicCardType::PREPAID, "prepaid"}}; |
| + |
| // Validates ShippingOption or PaymentItem, which happen to have identical |
| // fields, except for "id", which is present only in ShippingOption. |
| template <typename T> |
| @@ -357,7 +379,7 @@ bool validatePaymentDetails(const PaymentDetails& details, |
| return keepShippingOptions; |
| } |
| -void maybeSetAndroidPayMethodata( |
| +void maybeSetAndroidPayMethodData( |
| const ScriptValue& input, |
| payments::mojom::blink::PaymentMethodDataPtr& output) { |
| AndroidPayMethodData androidPay; |
| @@ -424,6 +446,46 @@ void maybeSetAndroidPayMethodata( |
| } |
| } |
| +void maybeSetBasicCardMethodData( |
| + const ScriptValue& input, |
| + payments::mojom::blink::PaymentMethodDataPtr& output) { |
| + BasicCardRequest basicCard; |
| + 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
|
| + V8BasicCardRequest::toImpl(input.isolate(), input.v8Value(), basicCard, |
| + exceptionState); |
| + if (exceptionState.hadException()) |
| + return; |
| + |
| + if (basicCard.hasSupportedNetworks()) { |
| + output->supported_networks.resize(basicCard.supportedNetworks().size()); |
| + size_t numberOfNetworks = 0; |
| + for (size_t i = 0; i < basicCard.supportedNetworks().size(); ++i) { |
| + for (size_t j = 0; j < arraysize(kBasicCardNetworks); ++j) { |
| + if (basicCard.supportedNetworks()[i] == kBasicCardNetworks[j].name) { |
| + output->supported_networks[numberOfNetworks++] = |
| + kBasicCardNetworks[j].code; |
| + break; |
| + } |
| + } |
| + } |
| + output->supported_networks.resize(numberOfNetworks); |
| + } |
| + |
| + if (basicCard.hasSupportedTypes()) { |
| + output->supported_types.resize(basicCard.supportedTypes().size()); |
| + size_t numberOfTypes = 0; |
| + for (size_t i = 0; i < basicCard.supportedTypes().size(); ++i) { |
| + for (size_t j = 0; j < arraysize(kBasicCardTypes); ++j) { |
| + if (basicCard.supportedTypes()[i] == kBasicCardTypes[j].name) { |
| + output->supported_types[numberOfTypes++] = kBasicCardTypes[j].code; |
| + break; |
| + } |
| + } |
| + } |
| + output->supported_types.resize(numberOfTypes); |
| + } |
| +} |
| + |
| void validateAndConvertPaymentMethodData( |
| const HeapVector<PaymentMethodData>& input, |
| Vector<payments::mojom::blink::PaymentMethodDataPtr>& output, |
| @@ -468,7 +530,8 @@ void validateAndConvertPaymentMethodData( |
| output[i] = payments::mojom::blink::PaymentMethodData::New(); |
| output[i]->supported_methods = paymentMethodData.supportedMethods(); |
| output[i]->stringified_data = stringifiedData; |
| - maybeSetAndroidPayMethodata(paymentMethodData.data(), output[i]); |
| + maybeSetAndroidPayMethodData(paymentMethodData.data(), output[i]); |
| + maybeSetBasicCardMethodData(paymentMethodData.data(), output[i]); |
| } |
| } |