OLD | NEW |
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 409 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
420 bool success = getExecutionContext()->getEventQueue()->enqueueEvent(event); | 420 bool success = getExecutionContext()->getEventQueue()->enqueueEvent(event); |
421 DCHECK(success); | 421 DCHECK(success); |
422 ALLOW_UNUSED_LOCAL(success); | 422 ALLOW_UNUSED_LOCAL(success); |
423 } | 423 } |
424 | 424 |
425 void PaymentRequest::OnPaymentResponse(mojom::blink::PaymentResponsePtr response
) | 425 void PaymentRequest::OnPaymentResponse(mojom::blink::PaymentResponsePtr response
) |
426 { | 426 { |
427 DCHECK(m_showResolver); | 427 DCHECK(m_showResolver); |
428 DCHECK(!m_completeResolver); | 428 DCHECK(!m_completeResolver); |
429 | 429 |
430 if (response->shipping_address) { | 430 if (m_options.requestShipping()) { |
| 431 if (!response->shipping_address) { |
| 432 m_showResolver->reject(DOMException::create(SyntaxError)); |
| 433 clearResolversAndCloseMojoConnection(); |
| 434 return; |
| 435 } |
| 436 |
431 String errorMessage; | 437 String errorMessage; |
432 if (!PaymentsValidators::isValidShippingAddress(response->shipping_addre
ss, &errorMessage)) { | 438 if (!PaymentsValidators::isValidShippingAddress(response->shipping_addre
ss, &errorMessage)) { |
433 m_showResolver->reject(DOMException::create(SyntaxError, errorMessag
e)); | 439 m_showResolver->reject(DOMException::create(SyntaxError, errorMessag
e)); |
434 clearResolversAndCloseMojoConnection(); | 440 clearResolversAndCloseMojoConnection(); |
435 return; | 441 return; |
436 } | 442 } |
437 | 443 |
438 m_shippingAddress = new PaymentAddress(std::move(response->shipping_addr
ess)); | 444 m_shippingAddress = new PaymentAddress(response->shipping_address.Clone(
)); |
439 m_shippingOption = response->shipping_option_id; | 445 m_shippingOption = response->shipping_option_id; |
| 446 } else { |
| 447 if (response->shipping_address) { |
| 448 m_showResolver->reject(DOMException::create(SyntaxError)); |
| 449 clearResolversAndCloseMojoConnection(); |
| 450 return; |
| 451 } |
440 } | 452 } |
441 | 453 |
442 m_showResolver->resolve(new PaymentResponse(std::move(response), this)); | 454 m_showResolver->resolve(new PaymentResponse(std::move(response), this)); |
443 | 455 |
444 // Do not close the mojo connection here. The merchant website should call | 456 // Do not close the mojo connection here. The merchant website should call |
445 // PaymentResponse::complete(boolean), which will be forwarded over the mojo | 457 // PaymentResponse::complete(boolean), which will be forwarded over the mojo |
446 // connection to display a success or failure message to the user. | 458 // connection to display a success or failure message to the user. |
447 m_showResolver.clear(); | 459 m_showResolver.clear(); |
448 } | 460 } |
449 | 461 |
(...skipping 16 matching lines...) Expand all Loading... |
466 void PaymentRequest::clearResolversAndCloseMojoConnection() | 478 void PaymentRequest::clearResolversAndCloseMojoConnection() |
467 { | 479 { |
468 m_completeResolver.clear(); | 480 m_completeResolver.clear(); |
469 m_showResolver.clear(); | 481 m_showResolver.clear(); |
470 if (m_clientBinding.is_bound()) | 482 if (m_clientBinding.is_bound()) |
471 m_clientBinding.Close(); | 483 m_clientBinding.Close(); |
472 m_paymentProvider.reset(); | 484 m_paymentProvider.reset(); |
473 } | 485 } |
474 | 486 |
475 } // namespace blink | 487 } // namespace blink |
OLD | NEW |