Commit a9d06e19 authored by Daniel Bratell's avatar Daniel Bratell Committed by Commit Bot

Unduplicate a kMaxListSize constant that broke jumbo builds

The two kMaxListSize constants collided in jumbo builds where
files are merged before compilation, for higher build performance.

This patch makes the constants be shared.

Bug: 777470
Change-Id: Idf90fcf389ba3895b4f0e28b4649f11ff5f8257e
Reviewed-on: https://chromium-review.googlesource.com/749142
Commit-Queue: Daniel Bratell <bratell@opera.com>
Commit-Queue: Rouslan Solomakhin <rouslan@chromium.org>
Reviewed-by: default avatarRouslan Solomakhin <rouslan@chromium.org>
Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Reviewed-by: default avatarGanggui Tang <gogerald@chromium.org>
Cr-Commit-Position: refs/heads/master@{#513119}
parent 7d3caeff
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include "bindings/modules/v8/V8BasicCardRequest.h" #include "bindings/modules/v8/V8BasicCardRequest.h"
#include "modules/payments/BasicCardRequest.h" #include "modules/payments/BasicCardRequest.h"
#include "modules/payments/PaymentRequest.h"
namespace blink { namespace blink {
...@@ -14,8 +15,6 @@ namespace { ...@@ -14,8 +15,6 @@ namespace {
using ::payments::mojom::blink::BasicCardNetwork; using ::payments::mojom::blink::BasicCardNetwork;
using ::payments::mojom::blink::BasicCardType; using ::payments::mojom::blink::BasicCardType;
static const size_t kMaxListSize = 1024;
const struct { const struct {
const payments::mojom::BasicCardNetwork code; const payments::mojom::BasicCardNetwork code;
const char* const name; const char* const name;
...@@ -51,7 +50,7 @@ void BasicCardHelper::parseBasiccardData( ...@@ -51,7 +50,7 @@ void BasicCardHelper::parseBasiccardData(
return; return;
if (basic_card.hasSupportedNetworks()) { if (basic_card.hasSupportedNetworks()) {
if (basic_card.supportedNetworks().size() > kMaxListSize) { if (basic_card.supportedNetworks().size() > PaymentRequest::kMaxListSize) {
exception_state.ThrowTypeError( exception_state.ThrowTypeError(
"basic-card supportedNetworks cannot be longer than 1024 elements"); "basic-card supportedNetworks cannot be longer than 1024 elements");
return; return;
...@@ -68,7 +67,7 @@ void BasicCardHelper::parseBasiccardData( ...@@ -68,7 +67,7 @@ void BasicCardHelper::parseBasiccardData(
} }
if (basic_card.hasSupportedTypes()) { if (basic_card.hasSupportedTypes()) {
if (basic_card.supportedTypes().size() > kMaxListSize) { if (basic_card.supportedTypes().size() > PaymentRequest::kMaxListSize) {
exception_state.ThrowTypeError( exception_state.ThrowTypeError(
"basic-card supportedTypes cannot be longer than 1024 elements"); "basic-card supportedTypes cannot be longer than 1024 elements");
return; return;
......
...@@ -139,10 +139,6 @@ namespace { ...@@ -139,10 +139,6 @@ namespace {
// resolved, then behave as if the website called complete("fail"). // resolved, then behave as if the website called complete("fail").
static const int kCompleteTimeoutSeconds = 60; static const int kCompleteTimeoutSeconds = 60;
static const size_t kMaxStringLength = 1024;
static const size_t kMaxJSONStringLength = 1048576;
static const size_t kMaxListSize = 1024;
// Validates ShippingOption or PaymentItem, which happen to have identical // Validates ShippingOption or PaymentItem, which happen to have identical
// fields, except for "id", which is present only in ShippingOption. // fields, except for "id", which is present only in ShippingOption.
template <typename T> template <typename T>
...@@ -155,25 +151,26 @@ void ValidateShippingOptionOrPaymentItem(const T& item, ...@@ -155,25 +151,26 @@ void ValidateShippingOptionOrPaymentItem(const T& item,
DCHECK(item.amount().hasValue()); DCHECK(item.amount().hasValue());
DCHECK(item.amount().hasCurrency()); DCHECK(item.amount().hasCurrency());
if (item.label().length() > kMaxStringLength) { if (item.label().length() > PaymentRequest::kMaxStringLength) {
exception_state.ThrowTypeError("The label for " + item_name + exception_state.ThrowTypeError("The label for " + item_name +
" cannot be longer than 1024 characters"); " cannot be longer than 1024 characters");
return; return;
} }
if (item.amount().currency().length() > kMaxStringLength) { if (item.amount().currency().length() > PaymentRequest::kMaxStringLength) {
exception_state.ThrowTypeError("The currency code for " + item_name + exception_state.ThrowTypeError("The currency code for " + item_name +
" cannot be longer than 1024 characters"); " cannot be longer than 1024 characters");
return; return;
} }
if (item.amount().currencySystem().length() > kMaxStringLength) { if (item.amount().currencySystem().length() >
PaymentRequest::kMaxStringLength) {
exception_state.ThrowTypeError("The currency system for " + item_name + exception_state.ThrowTypeError("The currency system for " + item_name +
" cannot be longer than 1024 characters"); " cannot be longer than 1024 characters");
return; return;
} }
if (item.amount().value().length() > kMaxStringLength) { if (item.amount().value().length() > PaymentRequest::kMaxStringLength) {
exception_state.ThrowTypeError("The amount value for " + item_name + exception_state.ThrowTypeError("The amount value for " + item_name +
" cannot be longer than 1024 characters"); " cannot be longer than 1024 characters");
return; return;
...@@ -206,7 +203,7 @@ void ValidateAndConvertDisplayItems(const HeapVector<PaymentItem>& input, ...@@ -206,7 +203,7 @@ void ValidateAndConvertDisplayItems(const HeapVector<PaymentItem>& input,
Vector<PaymentItemPtr>& output, Vector<PaymentItemPtr>& output,
ExecutionContext& execution_context, ExecutionContext& execution_context,
ExceptionState& exception_state) { ExceptionState& exception_state) {
if (input.size() > kMaxListSize) { if (input.size() > PaymentRequest::kMaxListSize) {
exception_state.ThrowTypeError("At most 1024 " + item_names + " allowed"); exception_state.ThrowTypeError("At most 1024 " + item_names + " allowed");
return; return;
} }
...@@ -231,7 +228,7 @@ void ValidateAndConvertShippingOptions( ...@@ -231,7 +228,7 @@ void ValidateAndConvertShippingOptions(
String& shipping_option_output, String& shipping_option_output,
ExecutionContext& execution_context, ExecutionContext& execution_context,
ExceptionState& exception_state) { ExceptionState& exception_state) {
if (input.size() > kMaxListSize) { if (input.size() > PaymentRequest::kMaxListSize) {
exception_state.ThrowTypeError("At most 1024 shipping options allowed"); exception_state.ThrowTypeError("At most 1024 shipping options allowed");
return; return;
} }
...@@ -244,7 +241,7 @@ void ValidateAndConvertShippingOptions( ...@@ -244,7 +241,7 @@ void ValidateAndConvertShippingOptions(
return; return;
DCHECK(option.hasId()); DCHECK(option.hasId());
if (option.id().length() > kMaxStringLength) { if (option.id().length() > PaymentRequest::kMaxStringLength) {
exception_state.ThrowTypeError( exception_state.ThrowTypeError(
"Shipping option ID cannot be longer than 1024 characters"); "Shipping option ID cannot be longer than 1024 characters");
return; return;
...@@ -305,7 +302,7 @@ void SetAndroidPayMethodData(const ScriptValue& input, ...@@ -305,7 +302,7 @@ void SetAndroidPayMethodData(const ScriptValue& input,
output->environment = payments::mojom::blink::AndroidPayEnvironment::TEST; output->environment = payments::mojom::blink::AndroidPayEnvironment::TEST;
if (android_pay.hasMerchantName() && if (android_pay.hasMerchantName() &&
android_pay.merchantName().length() > kMaxStringLength) { android_pay.merchantName().length() > PaymentRequest::kMaxStringLength) {
exception_state.ThrowTypeError( exception_state.ThrowTypeError(
"Android Pay merchant name cannot be longer than 1024 characters"); "Android Pay merchant name cannot be longer than 1024 characters");
return; return;
...@@ -313,7 +310,7 @@ void SetAndroidPayMethodData(const ScriptValue& input, ...@@ -313,7 +310,7 @@ void SetAndroidPayMethodData(const ScriptValue& input,
output->merchant_name = android_pay.merchantName(); output->merchant_name = android_pay.merchantName();
if (android_pay.hasMerchantId() && if (android_pay.hasMerchantId() &&
android_pay.merchantId().length() > kMaxStringLength) { android_pay.merchantId().length() > PaymentRequest::kMaxStringLength) {
exception_state.ThrowTypeError( exception_state.ThrowTypeError(
"Android Pay merchant id cannot be longer than 1024 characters"); "Android Pay merchant id cannot be longer than 1024 characters");
return; return;
...@@ -388,7 +385,7 @@ void SetAndroidPayMethodData(const ScriptValue& input, ...@@ -388,7 +385,7 @@ void SetAndroidPayMethodData(const ScriptValue& input,
tokenization.parameters().GetPropertyNames(exception_state); tokenization.parameters().GetPropertyNames(exception_state);
if (exception_state.HadException()) if (exception_state.HadException())
return; return;
if (keys.size() > kMaxListSize) { if (keys.size() > PaymentRequest::kMaxListSize) {
exception_state.ThrowTypeError( exception_state.ThrowTypeError(
"At most 1024 tokenization parameters allowed for Android Pay"); "At most 1024 tokenization parameters allowed for Android Pay");
return; return;
...@@ -397,13 +394,13 @@ void SetAndroidPayMethodData(const ScriptValue& input, ...@@ -397,13 +394,13 @@ void SetAndroidPayMethodData(const ScriptValue& input,
for (const String& key : keys) { for (const String& key : keys) {
if (!DictionaryHelper::Get(tokenization.parameters(), key, value)) if (!DictionaryHelper::Get(tokenization.parameters(), key, value))
continue; continue;
if (key.length() > kMaxStringLength) { if (key.length() > PaymentRequest::kMaxStringLength) {
exception_state.ThrowTypeError( exception_state.ThrowTypeError(
"Android Pay tokenization parameter key cannot be longer than " "Android Pay tokenization parameter key cannot be longer than "
"1024 characters"); "1024 characters");
return; return;
} }
if (value.length() > kMaxStringLength) { if (value.length() > PaymentRequest::kMaxStringLength) {
exception_state.ThrowTypeError( exception_state.ThrowTypeError(
"Android Pay tokenization parameter value cannot be longer than " "Android Pay tokenization parameter value cannot be longer than "
"1024 characters"); "1024 characters");
...@@ -444,7 +441,8 @@ void StringifyAndParseMethodSpecificData( ...@@ -444,7 +441,8 @@ void StringifyAndParseMethodSpecificData(
output->stringified_data = output->stringified_data =
V8StringToWebCoreString<String>(value, kDoNotExternalize); V8StringToWebCoreString<String>(value, kDoNotExternalize);
if (output->stringified_data.length() > kMaxJSONStringLength) { if (output->stringified_data.length() >
PaymentRequest::kMaxJSONStringLength) {
exception_state.ThrowTypeError( exception_state.ThrowTypeError(
"JSON serialization of payment method data should be no longer than " "JSON serialization of payment method data should be no longer than "
"1048576 characters"); "1048576 characters");
...@@ -501,7 +499,7 @@ void ValidateAndConvertPaymentDetailsModifiers( ...@@ -501,7 +499,7 @@ void ValidateAndConvertPaymentDetailsModifiers(
Vector<PaymentDetailsModifierPtr>& output, Vector<PaymentDetailsModifierPtr>& output,
ExecutionContext& execution_context, ExecutionContext& execution_context,
ExceptionState& exception_state) { ExceptionState& exception_state) {
if (input.size() > kMaxListSize) { if (input.size() > PaymentRequest::kMaxListSize) {
exception_state.ThrowTypeError("At most 1024 modifiers allowed"); exception_state.ThrowTypeError("At most 1024 modifiers allowed");
return; return;
} }
...@@ -543,14 +541,14 @@ void ValidateAndConvertPaymentDetailsModifiers( ...@@ -543,14 +541,14 @@ void ValidateAndConvertPaymentDetailsModifiers(
return; return;
} }
if (supported_methods.size() > kMaxListSize) { if (supported_methods.size() > PaymentRequest::kMaxListSize) {
exception_state.ThrowTypeError( exception_state.ThrowTypeError(
"At most 1024 supportedMethods allowed for modifier"); "At most 1024 supportedMethods allowed for modifier");
return; return;
} }
for (const String& method : supported_methods) { for (const String& method : supported_methods) {
if (method.length() > kMaxStringLength) { if (method.length() > PaymentRequest::kMaxStringLength) {
exception_state.ThrowTypeError( exception_state.ThrowTypeError(
"Supported method name for identifier cannot be longer than 1024 " "Supported method name for identifier cannot be longer than 1024 "
"characters"); "characters");
...@@ -671,7 +669,7 @@ void ValidateAndConvertPaymentMethodData( ...@@ -671,7 +669,7 @@ void ValidateAndConvertPaymentMethodData(
return; return;
} }
if (input.size() > kMaxListSize) { if (input.size() > PaymentRequest::kMaxListSize) {
exception_state.ThrowTypeError( exception_state.ThrowTypeError(
"At most 1024 payment methods are supported"); "At most 1024 payment methods are supported");
return; return;
...@@ -699,14 +697,14 @@ void ValidateAndConvertPaymentMethodData( ...@@ -699,14 +697,14 @@ void ValidateAndConvertPaymentMethodData(
return; return;
} }
if (supported_methods.size() > kMaxListSize) { if (supported_methods.size() > PaymentRequest::kMaxListSize) {
exception_state.ThrowTypeError( exception_state.ThrowTypeError(
"At most 1024 payment method identifiers are supported"); "At most 1024 payment method identifiers are supported");
return; return;
} }
for (const String identifier : supported_methods) { for (const String identifier : supported_methods) {
if (identifier.length() > kMaxStringLength) { if (identifier.length() > PaymentRequest::kMaxStringLength) {
exception_state.ThrowTypeError( exception_state.ThrowTypeError(
"A payment method identifier cannot be longer than 1024 " "A payment method identifier cannot be longer than 1024 "
"characters"); "characters");
...@@ -1005,7 +1003,8 @@ PaymentRequest::PaymentRequest(ExecutionContext* execution_context, ...@@ -1005,7 +1003,8 @@ PaymentRequest::PaymentRequest(ExecutionContext* execution_context,
return; return;
} }
if (details.hasId() && details.id().length() > kMaxStringLength) { if (details.hasId() &&
details.id().length() > PaymentRequest::kMaxStringLength) {
exception_state.ThrowTypeError("ID cannot be longer than 1024 characters"); exception_state.ThrowTypeError("ID cannot be longer than 1024 characters");
return; return;
} }
......
...@@ -89,6 +89,15 @@ class MODULES_EXPORT PaymentRequest final ...@@ -89,6 +89,15 @@ class MODULES_EXPORT PaymentRequest final
void OnCompleteTimeoutForTesting(); void OnCompleteTimeoutForTesting();
enum {
// Implementation defined constants controlling the allowed list length
kMaxListSize = 1024,
// ... and string length
kMaxStringLength = 1024,
// ... and JSON length.
kMaxJSONStringLength = 1048576
};
private: private:
PaymentRequest(ExecutionContext*, PaymentRequest(ExecutionContext*,
const HeapVector<PaymentMethodData>&, const HeapVector<PaymentMethodData>&,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment