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

Side by Side Diff: third_party/WebKit/Source/modules/payments/PaymentRequest.cpp

Issue 2865023003: Warn web developers that card networks as method names are deprecated. (Closed)
Patch Set: Created 3 years, 7 months 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 unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <stddef.h> 7 #include <stddef.h>
8 #include <utility> 8 #include <utility>
9 #include "bindings/core/v8/ExceptionState.h" 9 #include "bindings/core/v8/ExceptionState.h"
10 #include "bindings/core/v8/ScriptPromiseResolver.h" 10 #include "bindings/core/v8/ScriptPromiseResolver.h"
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 121
122 return output; 122 return output;
123 } 123 }
124 }; 124 };
125 125
126 } // namespace mojo 126 } // namespace mojo
127 127
128 namespace blink { 128 namespace blink {
129 namespace { 129 namespace {
130 130
131 using ::payments::mojom::blink::BasicCardNetwork;
132
133 const struct {
134 const BasicCardNetwork code;
135 const char* const name;
136 } kBasicCardNetworks[] = {{BasicCardNetwork::AMEX, "amex"},
137 {BasicCardNetwork::DINERS, "diners"},
138 {BasicCardNetwork::DISCOVER, "discover"},
139 {BasicCardNetwork::JCB, "jcb"},
140 {BasicCardNetwork::MASTERCARD, "mastercard"},
141 {BasicCardNetwork::MIR, "mir"},
142 {BasicCardNetwork::UNIONPAY, "unionpay"},
143 {BasicCardNetwork::VISA, "visa"}};
144
131 // If the website does not call complete() 60 seconds after show() has been 145 // If the website does not call complete() 60 seconds after show() has been
132 // resolved, then behave as if the website called complete("fail"). 146 // resolved, then behave as if the website called complete("fail").
133 static const int kCompleteTimeoutSeconds = 60; 147 static const int kCompleteTimeoutSeconds = 60;
134 148
135 // Validates ShippingOption or PaymentItem, which happen to have identical 149 // Validates ShippingOption or PaymentItem, which happen to have identical
136 // fields, except for "id", which is present only in ShippingOption. 150 // fields, except for "id", which is present only in ShippingOption.
137 template <typename T> 151 template <typename T>
138 void ValidateShippingOptionOrPaymentItem(const T& item, 152 void ValidateShippingOptionOrPaymentItem(const T& item,
139 const String& item_name, 153 const String& item_name,
140 ExecutionContext& execution_context, 154 ExecutionContext& execution_context,
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
342 PaymentMethodDataPtr& output, 356 PaymentMethodDataPtr& output,
343 ExecutionContext& execution_context, 357 ExecutionContext& execution_context,
344 ExceptionState& exception_state) { 358 ExceptionState& exception_state) {
345 BasicCardRequest basic_card; 359 BasicCardRequest basic_card;
346 V8BasicCardRequest::toImpl(input.GetIsolate(), input.V8Value(), basic_card, 360 V8BasicCardRequest::toImpl(input.GetIsolate(), input.V8Value(), basic_card,
347 exception_state); 361 exception_state);
348 if (exception_state.HadException()) 362 if (exception_state.HadException())
349 return; 363 return;
350 364
351 if (basic_card.hasSupportedNetworks()) { 365 if (basic_card.hasSupportedNetworks()) {
352 using ::payments::mojom::blink::BasicCardNetwork;
353
354 const struct {
355 const BasicCardNetwork code;
356 const char* const name;
357 } kBasicCardNetworks[] = {{BasicCardNetwork::AMEX, "amex"},
358 {BasicCardNetwork::DINERS, "diners"},
359 {BasicCardNetwork::DISCOVER, "discover"},
360 {BasicCardNetwork::JCB, "jcb"},
361 {BasicCardNetwork::MASTERCARD, "mastercard"},
362 {BasicCardNetwork::MIR, "mir"},
363 {BasicCardNetwork::UNIONPAY, "unionpay"},
364 {BasicCardNetwork::VISA, "visa"}};
365
366 for (const String& network : basic_card.supportedNetworks()) { 366 for (const String& network : basic_card.supportedNetworks()) {
367 for (size_t i = 0; i < arraysize(kBasicCardNetworks); ++i) { 367 for (size_t i = 0; i < arraysize(kBasicCardNetworks); ++i) {
368 if (network == kBasicCardNetworks[i].name) { 368 if (network == kBasicCardNetworks[i].name) {
369 output->supported_networks.push_back(kBasicCardNetworks[i].code); 369 output->supported_networks.push_back(kBasicCardNetworks[i].code);
370 break; 370 break;
371 } 371 }
372 } 372 }
373 } 373 }
374 } 374 }
375 375
(...skipping 17 matching lines...) Expand all
393 } 393 }
394 394
395 if (output->supported_types.size() != arraysize(kBasicCardTypes)) { 395 if (output->supported_types.size() != arraysize(kBasicCardTypes)) {
396 execution_context.AddConsoleMessage(ConsoleMessage::Create( 396 execution_context.AddConsoleMessage(ConsoleMessage::Create(
397 kJSMessageSource, kWarningMessageLevel, 397 kJSMessageSource, kWarningMessageLevel,
398 "Cannot yet distinguish credit, debit, and prepaid cards.")); 398 "Cannot yet distinguish credit, debit, and prepaid cards."));
399 } 399 }
400 } 400 }
401 } 401 }
402 402
403 void WarnDeprecatedBasicCard(const Vector<String>& supported_methods,
404 ExecutionContext& execution_context) {
405 for (const auto& method : supported_methods) {
406 for (size_t i = 0; i < arraysize(kBasicCardNetworks); ++i) {
407 if (method == kBasicCardNetworks[i].name) {
408 execution_context.AddConsoleMessage(ConsoleMessage::Create(
409 kJSMessageSource, kWarningMessageLevel,
Rick Byers 2017/05/16 13:48:58 Please use the "DeprecationMessageSource" - that'l
please use gerrit instead 2017/05/16 18:02:55 Done.
410 "The supported methods 'amex', 'diners', 'discover', 'jcb', "
411 "'mastercard', 'mir', 'unionpay', and 'visa' are deprecated. Use "
412 "'basic-card' instead."));
Rick Byers 2017/05/16 13:48:58 In general we prefer to give developers a concrete
please use gerrit instead 2017/05/16 18:02:55 Done.
413 return;
414 }
415 }
416 }
417 }
418
403 void StringifyAndParseMethodSpecificData( 419 void StringifyAndParseMethodSpecificData(
404 const Vector<String>& supported_methods, 420 const Vector<String>& supported_methods,
405 const ScriptValue& input, 421 const ScriptValue& input,
406 PaymentMethodDataPtr& output, 422 PaymentMethodDataPtr& output,
407 ExecutionContext& execution_context, 423 ExecutionContext& execution_context,
408 ExceptionState& exception_state) { 424 ExceptionState& exception_state) {
409 DCHECK(!input.IsEmpty()); 425 DCHECK(!input.IsEmpty());
410 v8::Local<v8::String> value; 426 v8::Local<v8::String> value;
411 if (!input.V8Value()->IsObject() || 427 if (!input.V8Value()->IsObject() ||
412 !v8::JSON::Stringify(input.GetContext(), input.V8Value().As<v8::Object>()) 428 !v8::JSON::Stringify(input.GetContext(), input.V8Value().As<v8::Object>())
(...skipping 14 matching lines...) Expand all
427 SetAndroidPayMethodData(input, output, exception_state); 443 SetAndroidPayMethodData(input, output, exception_state);
428 if (exception_state.HadException()) 444 if (exception_state.HadException())
429 exception_state.ClearException(); 445 exception_state.ClearException();
430 } 446 }
431 if (RuntimeEnabledFeatures::paymentRequestBasicCardEnabled() && 447 if (RuntimeEnabledFeatures::paymentRequestBasicCardEnabled() &&
432 supported_methods.Contains("basic-card")) { 448 supported_methods.Contains("basic-card")) {
433 SetBasicCardMethodData(input, output, execution_context, exception_state); 449 SetBasicCardMethodData(input, output, execution_context, exception_state);
434 if (exception_state.HadException()) 450 if (exception_state.HadException())
435 exception_state.ClearException(); 451 exception_state.ClearException();
436 } 452 }
453 WarnDeprecatedBasicCard(supported_methods, execution_context);
437 } 454 }
438 455
439 void ValidateAndConvertPaymentDetailsModifiers( 456 void ValidateAndConvertPaymentDetailsModifiers(
440 const HeapVector<PaymentDetailsModifier>& input, 457 const HeapVector<PaymentDetailsModifier>& input,
441 Vector<PaymentDetailsModifierPtr>& output, 458 Vector<PaymentDetailsModifierPtr>& output,
442 ExecutionContext& execution_context, 459 ExecutionContext& execution_context,
443 ExceptionState& exception_state) { 460 ExceptionState& exception_state) {
444 for (const PaymentDetailsModifier& modifier : input) { 461 for (const PaymentDetailsModifier& modifier : input) {
445 output.push_back(payments::mojom::blink::PaymentDetailsModifier::New()); 462 output.push_back(payments::mojom::blink::PaymentDetailsModifier::New());
446 if (modifier.hasTotal()) { 463 if (modifier.hasTotal()) {
(...skipping 622 matching lines...) Expand 10 before | Expand all | Expand 10 after
1069 complete_resolver_.Clear(); 1086 complete_resolver_.Clear();
1070 show_resolver_.Clear(); 1087 show_resolver_.Clear();
1071 abort_resolver_.Clear(); 1088 abort_resolver_.Clear();
1072 can_make_payment_resolver_.Clear(); 1089 can_make_payment_resolver_.Clear();
1073 if (client_binding_.is_bound()) 1090 if (client_binding_.is_bound())
1074 client_binding_.Close(); 1091 client_binding_.Close();
1075 payment_provider_.reset(); 1092 payment_provider_.reset();
1076 } 1093 }
1077 1094
1078 } // namespace blink 1095 } // namespace blink
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698