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" |
11 #include "bindings/modules/v8/V8PaymentDetails.h" | 11 #include "bindings/modules/v8/V8PaymentDetails.h" |
12 #include "core/EventTypeNames.h" | 12 #include "core/EventTypeNames.h" |
13 #include "core/dom/DOMException.h" | 13 #include "core/dom/DOMException.h" |
14 #include "core/dom/ExceptionCode.h" | 14 #include "core/dom/ExceptionCode.h" |
15 #include "core/events/Event.h" | 15 #include "core/events/Event.h" |
16 #include "core/events/EventQueue.h" | 16 #include "core/events/EventQueue.h" |
17 #include "modules/EventTargetModulesNames.h" | 17 #include "modules/EventTargetModulesNames.h" |
| 18 #include "modules/payments/PaymentAddress.h" |
18 #include "modules/payments/PaymentItem.h" | 19 #include "modules/payments/PaymentItem.h" |
19 #include "modules/payments/PaymentRequestUpdateEvent.h" | 20 #include "modules/payments/PaymentRequestUpdateEvent.h" |
20 #include "modules/payments/PaymentResponse.h" | 21 #include "modules/payments/PaymentResponse.h" |
21 #include "modules/payments/PaymentsValidators.h" | 22 #include "modules/payments/PaymentsValidators.h" |
22 #include "modules/payments/ShippingAddress.h" | |
23 #include "modules/payments/ShippingOption.h" | 23 #include "modules/payments/ShippingOption.h" |
24 #include "mojo/public/cpp/bindings/interface_request.h" | 24 #include "mojo/public/cpp/bindings/interface_request.h" |
25 #include "mojo/public/cpp/bindings/wtf_array.h" | 25 #include "mojo/public/cpp/bindings/wtf_array.h" |
26 #include "platform/mojo/MojoHelper.h" | 26 #include "platform/mojo/MojoHelper.h" |
27 #include "public/platform/ServiceRegistry.h" | 27 #include "public/platform/ServiceRegistry.h" |
28 #include <utility> | 28 #include <utility> |
29 | 29 |
30 namespace mojo { | 30 namespace mojo { |
31 | 31 |
32 using blink::mojom::blink::CurrencyAmount; | 32 using blink::mojom::blink::CurrencyAmount; |
(...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
358 void PaymentRequest::contextDestroyed() | 358 void PaymentRequest::contextDestroyed() |
359 { | 359 { |
360 clearResolversAndCloseMojoConnection(); | 360 clearResolversAndCloseMojoConnection(); |
361 } | 361 } |
362 | 362 |
363 bool PaymentRequest::hasPendingActivity() const | 363 bool PaymentRequest::hasPendingActivity() const |
364 { | 364 { |
365 return m_showResolver || m_completeResolver; | 365 return m_showResolver || m_completeResolver; |
366 } | 366 } |
367 | 367 |
368 void PaymentRequest::OnShippingAddressChange(mojom::blink::ShippingAddressPtr ad
dress) | 368 void PaymentRequest::OnShippingAddressChange(mojom::blink::PaymentAddressPtr add
ress) |
369 { | 369 { |
370 DCHECK(m_showResolver); | 370 DCHECK(m_showResolver); |
371 DCHECK(!m_completeResolver); | 371 DCHECK(!m_completeResolver); |
372 | 372 |
373 String errorMessage; | 373 String errorMessage; |
374 if (!PaymentsValidators::isValidShippingAddress(address, &errorMessage)) { | 374 if (!PaymentsValidators::isValidShippingAddress(address, &errorMessage)) { |
375 m_showResolver->reject(DOMException::create(SyntaxError, errorMessage)); | 375 m_showResolver->reject(DOMException::create(SyntaxError, errorMessage)); |
376 clearResolversAndCloseMojoConnection(); | 376 clearResolversAndCloseMojoConnection(); |
377 return; | 377 return; |
378 } | 378 } |
379 | 379 |
380 m_shippingAddress = new ShippingAddress(std::move(address)); | 380 m_shippingAddress = new PaymentAddress(std::move(address)); |
381 PaymentRequestUpdateEvent* event = PaymentRequestUpdateEvent::create(EventTy
peNames::shippingaddresschange); | 381 PaymentRequestUpdateEvent* event = PaymentRequestUpdateEvent::create(EventTy
peNames::shippingaddresschange); |
382 event->setTarget(this); | 382 event->setTarget(this); |
383 event->setPaymentDetailsUpdater(this); | 383 event->setPaymentDetailsUpdater(this); |
384 bool success = getExecutionContext()->getEventQueue()->enqueueEvent(event); | 384 bool success = getExecutionContext()->getEventQueue()->enqueueEvent(event); |
385 DCHECK(success); | 385 DCHECK(success); |
386 ALLOW_UNUSED_LOCAL(success); | 386 ALLOW_UNUSED_LOCAL(success); |
387 } | 387 } |
388 | 388 |
389 void PaymentRequest::OnShippingOptionChange(const String& shippingOptionId) | 389 void PaymentRequest::OnShippingOptionChange(const String& shippingOptionId) |
390 { | 390 { |
(...skipping 14 matching lines...) Expand all Loading... |
405 DCHECK(!m_completeResolver); | 405 DCHECK(!m_completeResolver); |
406 | 406 |
407 if (response->shipping_address) { | 407 if (response->shipping_address) { |
408 String errorMessage; | 408 String errorMessage; |
409 if (!PaymentsValidators::isValidShippingAddress(response->shipping_addre
ss, &errorMessage)) { | 409 if (!PaymentsValidators::isValidShippingAddress(response->shipping_addre
ss, &errorMessage)) { |
410 m_showResolver->reject(DOMException::create(SyntaxError, errorMessag
e)); | 410 m_showResolver->reject(DOMException::create(SyntaxError, errorMessag
e)); |
411 clearResolversAndCloseMojoConnection(); | 411 clearResolversAndCloseMojoConnection(); |
412 return; | 412 return; |
413 } | 413 } |
414 | 414 |
415 m_shippingAddress = new ShippingAddress(std::move(response->shipping_add
ress)); | 415 m_shippingAddress = new PaymentAddress(std::move(response->shipping_addr
ess)); |
416 m_shippingOption = response->shipping_option_id; | 416 m_shippingOption = response->shipping_option_id; |
417 } | 417 } |
418 | 418 |
419 m_showResolver->resolve(new PaymentResponse(std::move(response), this)); | 419 m_showResolver->resolve(new PaymentResponse(std::move(response), this)); |
420 | 420 |
421 // Do not close the mojo connection here. The merchant website should call | 421 // Do not close the mojo connection here. The merchant website should call |
422 // PaymentResponse::complete(boolean), which will be forwarded over the mojo | 422 // PaymentResponse::complete(boolean), which will be forwarded over the mojo |
423 // connection to display a success or failure message to the user. | 423 // connection to display a success or failure message to the user. |
424 m_showResolver.clear(); | 424 m_showResolver.clear(); |
425 } | 425 } |
(...skipping 17 matching lines...) Expand all Loading... |
443 void PaymentRequest::clearResolversAndCloseMojoConnection() | 443 void PaymentRequest::clearResolversAndCloseMojoConnection() |
444 { | 444 { |
445 m_completeResolver.clear(); | 445 m_completeResolver.clear(); |
446 m_showResolver.clear(); | 446 m_showResolver.clear(); |
447 if (m_clientBinding.is_bound()) | 447 if (m_clientBinding.is_bound()) |
448 m_clientBinding.Close(); | 448 m_clientBinding.Close(); |
449 m_paymentProvider.reset(); | 449 m_paymentProvider.reset(); |
450 } | 450 } |
451 | 451 |
452 } // namespace blink | 452 } // namespace blink |
OLD | NEW |