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

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

Issue 2830683002: Log duplicate shipping option ID warning in web payments API. (Closed)
Patch Set: Fix test Created 3 years, 8 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 | « third_party/WebKit/LayoutTests/payments/payment-request-interface-expected.txt ('k') | 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 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 } 179 }
180 180
181 // Validates and converts |input| shipping options into |output|. Throws an 181 // Validates and converts |input| shipping options into |output|. Throws an
182 // exception if the data is not valid, except for duplicate identifiers, which 182 // exception if the data is not valid, except for duplicate identifiers, which
183 // returns an empty |output| instead of throwing an exception. There's no need 183 // returns an empty |output| instead of throwing an exception. There's no need
184 // to clear |output| when an exception is thrown, because the caller takes care 184 // to clear |output| when an exception is thrown, because the caller takes care
185 // of deleting |output|. 185 // of deleting |output|.
186 void ValidateAndConvertShippingOptions( 186 void ValidateAndConvertShippingOptions(
187 const HeapVector<PaymentShippingOption>& input, 187 const HeapVector<PaymentShippingOption>& input,
188 Vector<PaymentShippingOptionPtr>& output, 188 Vector<PaymentShippingOptionPtr>& output,
189 ExecutionContext& execution_context,
189 ExceptionState& exception_state) { 190 ExceptionState& exception_state) {
190 HashSet<String> unique_ids; 191 HashSet<String> unique_ids;
191 for (const PaymentShippingOption& option : input) { 192 for (const PaymentShippingOption& option : input) {
192 if (!option.hasId() || option.id().IsEmpty()) { 193 if (!option.hasId() || option.id().IsEmpty()) {
193 exception_state.ThrowTypeError("ShippingOption id required"); 194 exception_state.ThrowTypeError("ShippingOption id required");
194 return; 195 return;
195 } 196 }
196 197
197 if (unique_ids.Contains(option.id())) { 198 if (unique_ids.Contains(option.id())) {
199 execution_context.AddConsoleMessage(ConsoleMessage::Create(
200 kJSMessageSource, kWarningMessageLevel,
201 "Duplicate shipping option identifier '" + option.id() +
202 "' is treated as an invalid address indicator."));
198 // Clear |output| instead of throwing an exception. 203 // Clear |output| instead of throwing an exception.
199 output.clear(); 204 output.clear();
200 return; 205 return;
201 } 206 }
202 207
203 unique_ids.insert(option.id()); 208 unique_ids.insert(option.id());
204 209
205 ValidateShippingOptionOrPaymentItem(option, exception_state); 210 ValidateShippingOptionOrPaymentItem(option, exception_state);
206 if (exception_state.HadException()) 211 if (exception_state.HadException())
207 return; 212 return;
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after
485 ExecutionContext& execution_context, 490 ExecutionContext& execution_context,
486 ExceptionState& exception_state) { 491 ExceptionState& exception_state) {
487 if (input.hasDisplayItems()) { 492 if (input.hasDisplayItems()) {
488 ValidateAndConvertDisplayItems(input.displayItems(), output->display_items, 493 ValidateAndConvertDisplayItems(input.displayItems(), output->display_items,
489 exception_state); 494 exception_state);
490 if (exception_state.HadException()) 495 if (exception_state.HadException())
491 return; 496 return;
492 } 497 }
493 498
494 if (input.hasShippingOptions() && request_shipping) { 499 if (input.hasShippingOptions() && request_shipping) {
495 ValidateAndConvertShippingOptions( 500 ValidateAndConvertShippingOptions(input.shippingOptions(),
496 input.shippingOptions(), output->shipping_options, exception_state); 501 output->shipping_options,
502 execution_context, exception_state);
497 if (exception_state.HadException()) 503 if (exception_state.HadException())
498 return; 504 return;
499 } 505 }
500 506
501 shipping_option_output = GetSelectedShippingOption(output->shipping_options); 507 shipping_option_output = GetSelectedShippingOption(output->shipping_options);
502 508
503 if (input.hasModifiers()) { 509 if (input.hasModifiers()) {
504 ValidateAndConvertPaymentDetailsModifiers( 510 ValidateAndConvertPaymentDetailsModifiers(
505 input.modifiers(), output->modifiers, execution_context, 511 input.modifiers(), output->modifiers, execution_context,
506 exception_state); 512 exception_state);
(...skipping 572 matching lines...) Expand 10 before | Expand all | Expand 10 after
1079 complete_resolver_.Clear(); 1085 complete_resolver_.Clear();
1080 show_resolver_.Clear(); 1086 show_resolver_.Clear();
1081 abort_resolver_.Clear(); 1087 abort_resolver_.Clear();
1082 can_make_payment_resolver_.Clear(); 1088 can_make_payment_resolver_.Clear();
1083 if (client_binding_.is_bound()) 1089 if (client_binding_.is_bound())
1084 client_binding_.Close(); 1090 client_binding_.Close();
1085 payment_provider_.reset(); 1091 payment_provider_.reset();
1086 } 1092 }
1087 1093
1088 } // namespace blink 1094 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/LayoutTests/payments/payment-request-interface-expected.txt ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698