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

Unified Diff: third_party/WebKit/Source/modules/payments/PaymentRequest.cpp

Issue 2501593003: Implement the new basic card specification. (Closed)
Patch Set: Address review comments for Java Created 4 years, 1 month 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 side-by-side diff with in-line comments
Download patch
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 10dc9a605e61d45e4a642548af1f2ae46f80e0c5..945eaa9fb5040b4b5eb13f79dc495e4f1ce805e0 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"
@@ -180,11 +182,16 @@ 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").
static const int completeTimeoutSeconds = 60;
+static const char* androidPayMethodName = "https://android.com/pay";
+static const char* basicCardMethodName = "basic-card";
+
const struct {
const AndroidPayCardNetwork code;
const char* name;
@@ -200,6 +207,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>
@@ -358,15 +383,15 @@ bool validatePaymentDetails(const PaymentDetails& details,
return keepShippingOptions;
}
-void maybeSetAndroidPayMethodData(
+// Parses Android Pay data to avoid parsing JSON in the browser.
+void setAndroidPayMethodData(
const ScriptValue& input,
payments::mojom::blink::PaymentMethodDataPtr& output,
ExceptionState& exceptionState) {
AndroidPayMethodData androidPay;
- TrackExceptionState trackExceptionState;
V8AndroidPayMethodData::toImpl(input.isolate(), input.v8Value(), androidPay,
- trackExceptionState);
- if (trackExceptionState.hadException())
+ exceptionState);
+ if (exceptionState.hadException())
return;
if (androidPay.hasEnvironment() && androidPay.environment() == "TEST")
@@ -428,6 +453,47 @@ void maybeSetAndroidPayMethodData(
}
}
+// Parses basic-card data to avoid parsing JSON in the browser.
+void setBasicCardMethodData(
+ const ScriptValue& input,
+ payments::mojom::blink::PaymentMethodDataPtr& output,
+ ExceptionState& exceptionState) {
+ BasicCardRequest basicCard;
+ 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,
@@ -472,10 +538,21 @@ void validateAndConvertPaymentMethodData(
output[i] = payments::mojom::blink::PaymentMethodData::New();
output[i]->supported_methods = paymentMethodData.supportedMethods();
output[i]->stringified_data = stringifiedData;
- maybeSetAndroidPayMethodData(paymentMethodData.data(), output[i],
- exceptionState);
- if (exceptionState.hadException())
- return;
+
+ if (paymentMethodData.supportedMethods().contains(androidPayMethodName)) {
+ setAndroidPayMethodData(paymentMethodData.data(), output[i],
+ exceptionState);
+ if (exceptionState.hadException())
Marijn Kruisselbrink 2016/11/29 21:09:53 So after this change the PaymentRequest constructo
+ return;
+ }
+
+ if (RuntimeEnabledFeatures::paymentRequestBasicCardEnabled() &&
+ paymentMethodData.supportedMethods().contains(basicCardMethodName)) {
+ setBasicCardMethodData(paymentMethodData.data(), output[i],
+ exceptionState);
+ if (exceptionState.hadException())
+ return;
+ }
}
}

Powered by Google App Engine
This is Rietveld 408576698