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

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

Issue 2406713002: PaymentRequest: Ignore shipping options if there are duplicated IDs. (Closed)
Patch Set: presubmit Created 4 years, 2 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
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 "bindings/core/v8/ExceptionState.h" 7 #include "bindings/core/v8/ExceptionState.h"
8 #include "bindings/core/v8/JSONValuesForV8.h" 8 #include "bindings/core/v8/JSONValuesForV8.h"
9 #include "bindings/core/v8/ScriptPromiseResolver.h" 9 #include "bindings/core/v8/ScriptPromiseResolver.h"
10 #include "bindings/core/v8/ScriptState.h" 10 #include "bindings/core/v8/ScriptState.h"
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 216
217 void validateDisplayItems(const HeapVector<PaymentItem>& items, 217 void validateDisplayItems(const HeapVector<PaymentItem>& items,
218 ExceptionState& exceptionState) { 218 ExceptionState& exceptionState) {
219 for (const auto& item : items) { 219 for (const auto& item : items) {
220 validateShippingOptionOrPaymentItem(item, exceptionState); 220 validateShippingOptionOrPaymentItem(item, exceptionState);
221 if (exceptionState.hadException()) 221 if (exceptionState.hadException())
222 return; 222 return;
223 } 223 }
224 } 224 }
225 225
226 void validateShippingOptions(const HeapVector<PaymentShippingOption>& options, 226 void validateAndFixupShippingOptions(HeapVector<PaymentShippingOption>& options,
227 ExceptionState& exceptionState) { 227 ExceptionState& exceptionState) {
228 HashSet<String> uniqueIds; 228 HashSet<String> uniqueIds;
229 for (const auto& option : options) { 229 for (const auto& option : options) {
230 if (!option.hasId() || option.id().isEmpty()) { 230 if (!option.hasId() || option.id().isEmpty()) {
231 exceptionState.throwTypeError("ShippingOption id required"); 231 exceptionState.throwTypeError("ShippingOption id required");
232 return; 232 return;
233 } 233 }
234 234
235 if (uniqueIds.contains(option.id())) { 235 if (uniqueIds.contains(option.id())) {
236 exceptionState.throwTypeError( 236 options = HeapVector<PaymentShippingOption>();
237 "Duplicate shipping option identifiers are not allowed");
238 return; 237 return;
239 } 238 }
240 uniqueIds.add(option.id()); 239 uniqueIds.add(option.id());
241 240
242 validateShippingOptionOrPaymentItem(option, exceptionState); 241 validateShippingOptionOrPaymentItem(option, exceptionState);
243 if (exceptionState.hadException()) 242 if (exceptionState.hadException())
244 return; 243 return;
245 } 244 }
246 } 245 }
247 246
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
284 } 283 }
285 284
286 if (modifier.hasAdditionalDisplayItems()) { 285 if (modifier.hasAdditionalDisplayItems()) {
287 validateDisplayItems(modifier.additionalDisplayItems(), exceptionState); 286 validateDisplayItems(modifier.additionalDisplayItems(), exceptionState);
288 if (exceptionState.hadException()) 287 if (exceptionState.hadException())
289 return; 288 return;
290 } 289 }
291 } 290 }
292 } 291 }
293 292
294 void validatePaymentDetails(const PaymentDetails& details, 293 void validateAndFixupPaymentDetails(PaymentDetails& details,
295 ExceptionState& exceptionState) { 294 ExceptionState& exceptionState) {
296 if (!details.hasTotal()) { 295 if (!details.hasTotal()) {
297 exceptionState.throwTypeError("Must specify total"); 296 exceptionState.throwTypeError("Must specify total");
298 return; 297 return;
299 } 298 }
300 299
301 validateShippingOptionOrPaymentItem(details.total(), exceptionState); 300 validateShippingOptionOrPaymentItem(details.total(), exceptionState);
302 if (exceptionState.hadException()) 301 if (exceptionState.hadException())
303 return; 302 return;
304 303
305 if (details.total().amount().value()[0] == '-') { 304 if (details.total().amount().value()[0] == '-') {
306 exceptionState.throwTypeError("Total amount value should be non-negative"); 305 exceptionState.throwTypeError("Total amount value should be non-negative");
307 return; 306 return;
308 } 307 }
309 308
310 if (details.hasDisplayItems()) { 309 if (details.hasDisplayItems()) {
311 validateDisplayItems(details.displayItems(), exceptionState); 310 validateDisplayItems(details.displayItems(), exceptionState);
312 if (exceptionState.hadException()) 311 if (exceptionState.hadException())
313 return; 312 return;
314 } 313 }
315 314
316 if (details.hasShippingOptions()) { 315 if (details.hasShippingOptions()) {
317 validateShippingOptions(details.shippingOptions(), exceptionState); 316 HeapVector<PaymentShippingOption> fixedShippingOptions =
please use gerrit instead 2016/10/12 23:19:10 Don't break this line. There's no character limit
zino 2016/10/13 01:46:24 Good point. But there *was* no character limit in
317 details.shippingOptions();
318 validateAndFixupShippingOptions(fixedShippingOptions, exceptionState);
319 details.setShippingOptions(fixedShippingOptions);
318 if (exceptionState.hadException()) 320 if (exceptionState.hadException())
319 return; 321 return;
320 } 322 }
321 323
322 if (details.hasModifiers()) { 324 if (details.hasModifiers()) {
323 validatePaymentDetailsModifiers(details.modifiers(), exceptionState); 325 validatePaymentDetailsModifiers(details.modifiers(), exceptionState);
324 } 326 }
325 327
326 String errorMessage; 328 String errorMessage;
327 if (!PaymentsValidators::isValidErrorMsgFormat(details.error(), 329 if (!PaymentsValidators::isValidErrorMsgFormat(details.error(),
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
517 V8PaymentDetails::toImpl(detailsScriptValue.isolate(), 519 V8PaymentDetails::toImpl(detailsScriptValue.isolate(),
518 detailsScriptValue.v8Value(), details, 520 detailsScriptValue.v8Value(), details,
519 exceptionState); 521 exceptionState);
520 if (exceptionState.hadException()) { 522 if (exceptionState.hadException()) {
521 m_showResolver->reject( 523 m_showResolver->reject(
522 DOMException::create(SyntaxError, exceptionState.message())); 524 DOMException::create(SyntaxError, exceptionState.message()));
523 clearResolversAndCloseMojoConnection(); 525 clearResolversAndCloseMojoConnection();
524 return; 526 return;
525 } 527 }
526 528
527 validatePaymentDetails(details, exceptionState); 529 validateAndFixupPaymentDetails(details, exceptionState);
528 if (exceptionState.hadException()) { 530 if (exceptionState.hadException()) {
529 m_showResolver->reject( 531 m_showResolver->reject(
530 DOMException::create(SyntaxError, exceptionState.message())); 532 DOMException::create(SyntaxError, exceptionState.message()));
531 clearResolversAndCloseMojoConnection(); 533 clearResolversAndCloseMojoConnection();
532 return; 534 return;
533 } 535 }
534 536
535 if (m_options.requestShipping()) 537 if (m_options.requestShipping())
536 m_shippingOption = getSelectedShippingOption(details); 538 m_shippingOption = getSelectedShippingOption(details);
537 539
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
582 return; 584 return;
583 } 585 }
584 586
585 if (!scriptState->domWindow()->frame() || 587 if (!scriptState->domWindow()->frame() ||
586 !scriptState->domWindow()->frame()->isMainFrame()) { 588 !scriptState->domWindow()->frame()->isMainFrame()) {
587 exceptionState.throwSecurityError( 589 exceptionState.throwSecurityError(
588 "Must be in a top-level browsing context"); 590 "Must be in a top-level browsing context");
589 return; 591 return;
590 } 592 }
591 593
592 validatePaymentDetails(details, exceptionState); 594 PaymentDetails fixedDetails(details);
595 validateAndFixupPaymentDetails(fixedDetails, exceptionState);
593 if (exceptionState.hadException()) 596 if (exceptionState.hadException())
594 return; 597 return;
595 598
596 if (details.hasError() && !details.error().isEmpty()) { 599 if (fixedDetails.hasError() && !fixedDetails.error().isEmpty()) {
597 exceptionState.throwTypeError("Error value should be empty"); 600 exceptionState.throwTypeError("Error value should be empty");
598 return; 601 return;
599 } 602 }
600 603
601 if (m_options.requestShipping()) { 604 if (m_options.requestShipping()) {
602 m_shippingOption = getSelectedShippingOption(details); 605 m_shippingOption = getSelectedShippingOption(fixedDetails);
603 m_shippingType = getValidShippingType(m_options.shippingType()); 606 m_shippingType = getValidShippingType(m_options.shippingType());
604 } 607 }
605 608
606 scriptState->domWindow()->frame()->interfaceProvider()->getInterface( 609 scriptState->domWindow()->frame()->interfaceProvider()->getInterface(
607 mojo::GetProxy(&m_paymentProvider)); 610 mojo::GetProxy(&m_paymentProvider));
608 m_paymentProvider.set_connection_error_handler(convertToBaseCallback( 611 m_paymentProvider.set_connection_error_handler(convertToBaseCallback(
609 WTF::bind(&PaymentRequest::OnError, wrapWeakPersistent(this), 612 WTF::bind(&PaymentRequest::OnError, wrapWeakPersistent(this),
610 mojom::blink::PaymentErrorReason::UNKNOWN))); 613 mojom::blink::PaymentErrorReason::UNKNOWN)));
611 m_paymentProvider->Init( 614 m_paymentProvider->Init(
612 m_clientBinding.CreateInterfacePtrAndBind(), 615 m_clientBinding.CreateInterfacePtrAndBind(),
613 mojo::WTFArray<mojom::blink::PaymentMethodDataPtr>::From( 616 mojo::WTFArray<mojom::blink::PaymentMethodDataPtr>::From(
614 validatedMethodData), 617 validatedMethodData),
615 mojom::blink::PaymentDetails::From(details), 618 mojom::blink::PaymentDetails::From(fixedDetails),
616 mojom::blink::PaymentOptions::From(m_options)); 619 mojom::blink::PaymentOptions::From(m_options));
617 } 620 }
618 621
619 void PaymentRequest::contextDestroyed() { 622 void PaymentRequest::contextDestroyed() {
620 clearResolversAndCloseMojoConnection(); 623 clearResolversAndCloseMojoConnection();
621 } 624 }
622 625
623 void PaymentRequest::OnShippingAddressChange( 626 void PaymentRequest::OnShippingAddressChange(
624 mojom::blink::PaymentAddressPtr address) { 627 mojom::blink::PaymentAddressPtr address) {
625 DCHECK(m_showResolver); 628 DCHECK(m_showResolver);
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
783 m_completeTimer.stop(); 786 m_completeTimer.stop();
784 m_completeResolver.clear(); 787 m_completeResolver.clear();
785 m_showResolver.clear(); 788 m_showResolver.clear();
786 m_abortResolver.clear(); 789 m_abortResolver.clear();
787 if (m_clientBinding.is_bound()) 790 if (m_clientBinding.is_bound())
788 m_clientBinding.Close(); 791 m_clientBinding.Close();
789 m_paymentProvider.reset(); 792 m_paymentProvider.reset();
790 } 793 }
791 794
792 } // namespace blink 795 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698