Chromium Code Reviews| 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 18 matching lines...) Expand all Loading... | |
| 29 #include <utility> | 29 #include <utility> |
| 30 | 30 |
| 31 namespace mojo { | 31 namespace mojo { |
| 32 | 32 |
| 33 using blink::mojom::blink::PaymentCurrencyAmount; | 33 using blink::mojom::blink::PaymentCurrencyAmount; |
| 34 using blink::mojom::blink::PaymentCurrencyAmountPtr; | 34 using blink::mojom::blink::PaymentCurrencyAmountPtr; |
| 35 using blink::mojom::blink::PaymentDetails; | 35 using blink::mojom::blink::PaymentDetails; |
| 36 using blink::mojom::blink::PaymentDetailsModifier; | 36 using blink::mojom::blink::PaymentDetailsModifier; |
| 37 using blink::mojom::blink::PaymentDetailsModifierPtr; | 37 using blink::mojom::blink::PaymentDetailsModifierPtr; |
| 38 using blink::mojom::blink::PaymentDetailsPtr; | 38 using blink::mojom::blink::PaymentDetailsPtr; |
| 39 using blink::mojom::blink::PaymentErrorReason; | |
| 39 using blink::mojom::blink::PaymentItem; | 40 using blink::mojom::blink::PaymentItem; |
| 40 using blink::mojom::blink::PaymentItemPtr; | 41 using blink::mojom::blink::PaymentItemPtr; |
| 41 using blink::mojom::blink::PaymentMethodData; | 42 using blink::mojom::blink::PaymentMethodData; |
| 42 using blink::mojom::blink::PaymentMethodDataPtr; | 43 using blink::mojom::blink::PaymentMethodDataPtr; |
| 43 using blink::mojom::blink::PaymentOptions; | 44 using blink::mojom::blink::PaymentOptions; |
| 44 using blink::mojom::blink::PaymentOptionsPtr; | 45 using blink::mojom::blink::PaymentOptionsPtr; |
| 45 using blink::mojom::blink::PaymentShippingOption; | 46 using blink::mojom::blink::PaymentShippingOption; |
| 46 using blink::mojom::blink::PaymentShippingOptionPtr; | 47 using blink::mojom::blink::PaymentShippingOptionPtr; |
| 47 | 48 |
| 48 template <> | 49 template <> |
| (...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 365 ScriptPromise PaymentRequest::show(ScriptState* scriptState) | 366 ScriptPromise PaymentRequest::show(ScriptState* scriptState) |
| 366 { | 367 { |
| 367 if (m_showResolver) | 368 if (m_showResolver) |
| 368 return ScriptPromise::rejectWithDOMException(scriptState, DOMException:: create(InvalidStateError, "Already called show() once")); | 369 return ScriptPromise::rejectWithDOMException(scriptState, DOMException:: create(InvalidStateError, "Already called show() once")); |
| 369 | 370 |
| 370 if (!scriptState->domWindow() || !scriptState->domWindow()->frame()) | 371 if (!scriptState->domWindow() || !scriptState->domWindow()->frame()) |
| 371 return ScriptPromise::rejectWithDOMException(scriptState, DOMException:: create(InvalidStateError, "Cannot show the payment request")); | 372 return ScriptPromise::rejectWithDOMException(scriptState, DOMException:: create(InvalidStateError, "Cannot show the payment request")); |
| 372 | 373 |
| 373 DCHECK(!m_paymentProvider.is_bound()); | 374 DCHECK(!m_paymentProvider.is_bound()); |
| 374 scriptState->domWindow()->frame()->serviceRegistry()->connectToRemoteService (mojo::GetProxy(&m_paymentProvider)); | 375 scriptState->domWindow()->frame()->serviceRegistry()->connectToRemoteService (mojo::GetProxy(&m_paymentProvider)); |
| 375 m_paymentProvider.set_connection_error_handler(convertToBaseCallback(WTF::bi nd(&PaymentRequest::OnError, wrapWeakPersistent(this)))); | 376 m_paymentProvider.set_connection_error_handler(convertToBaseCallback(WTF::bi nd(&PaymentRequest::OnError, wrapWeakPersistent(this), mojom::blink::PaymentErro rReason::UNKNOWN))); |
| 376 m_paymentProvider->SetClient(m_clientBinding.CreateInterfacePtrAndBind()); | 377 m_paymentProvider->SetClient(m_clientBinding.CreateInterfacePtrAndBind()); |
| 377 m_paymentProvider->Show(mojo::WTFArray<mojom::blink::PaymentMethodDataPtr>:: From(m_methodData), mojom::blink::PaymentDetails::From(m_details), mojom::blink: :PaymentOptions::From(m_options)); | 378 m_paymentProvider->Show(mojo::WTFArray<mojom::blink::PaymentMethodDataPtr>:: From(m_methodData), mojom::blink::PaymentDetails::From(m_details), mojom::blink: :PaymentOptions::From(m_options)); |
| 378 | 379 |
| 379 m_showResolver = ScriptPromiseResolver::create(scriptState); | 380 m_showResolver = ScriptPromiseResolver::create(scriptState); |
| 380 return m_showResolver->promise(); | 381 return m_showResolver->promise(); |
| 381 } | 382 } |
| 382 | 383 |
| 383 ScriptPromise PaymentRequest::abort(ScriptState* scriptState) | 384 ScriptPromise PaymentRequest::abort(ScriptState* scriptState) |
| 384 { | 385 { |
| 385 if (m_abortResolver) | 386 if (m_abortResolver) |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 579 } | 580 } |
| 580 | 581 |
| 581 m_showResolver->resolve(new PaymentResponse(std::move(response), this)); | 582 m_showResolver->resolve(new PaymentResponse(std::move(response), this)); |
| 582 | 583 |
| 583 // Do not close the mojo connection here. The merchant website should call | 584 // Do not close the mojo connection here. The merchant website should call |
| 584 // PaymentResponse::complete(boolean), which will be forwarded over the mojo | 585 // PaymentResponse::complete(boolean), which will be forwarded over the mojo |
| 585 // connection to display a success or failure message to the user. | 586 // connection to display a success or failure message to the user. |
| 586 m_showResolver.clear(); | 587 m_showResolver.clear(); |
| 587 } | 588 } |
| 588 | 589 |
| 589 void PaymentRequest::OnError() | 590 void PaymentRequest::OnError(mojo::PaymentErrorReason error) |
| 590 { | 591 { |
| 592 ExceptionCode ec = SyntaxError; | |
| 593 String message = "The payment request is cancelled due to unknown reasons."; | |
|
please use gerrit instead
2016/07/12 15:57:35
Other error messages in this file do not have a pe
pals
2016/07/13 05:54:27
Done.
| |
| 594 switch (error) { | |
| 595 case mojom::blink::PaymentErrorReason::USER_CANCEL: | |
| 596 message = "User cancelled the payment request."; | |
|
please use gerrit instead
2016/07/12 15:57:35
Remove the period.
pals
2016/07/13 05:54:27
Done.
| |
| 597 break; | |
| 598 case mojom::blink::PaymentErrorReason::NOT_SUPPORTED: | |
| 599 ec = NotSupportedError; | |
| 600 message = "The payment method is not supported."; | |
|
please use gerrit instead
2016/07/12 15:57:35
Remove the period.
pals
2016/07/13 05:54:27
Done.
| |
| 601 break; | |
| 602 default: | |
|
please use gerrit instead
2016/07/12 15:57:35
Instead of "default", put the "UNKNOWN" enum value
pals
2016/07/13 05:54:27
Done.
| |
| 603 break; | |
| 604 } | |
| 591 if (m_completeResolver) | 605 if (m_completeResolver) |
| 592 m_completeResolver->reject(DOMException::create(SyntaxError, "Request ca ncelled")); | 606 m_completeResolver->reject(DOMException::create(ec, message)); |
| 593 if (m_showResolver) | 607 if (m_showResolver) |
| 594 m_showResolver->reject(DOMException::create(SyntaxError, "Request cancel led")); | 608 m_showResolver->reject(DOMException::create(ec, message)); |
| 595 if (m_abortResolver) | 609 if (m_abortResolver) |
| 596 m_abortResolver->reject(DOMException::create(SyntaxError, "Request cance lled")); | 610 m_abortResolver->reject(DOMException::create(ec, message)); |
| 597 clearResolversAndCloseMojoConnection(); | 611 clearResolversAndCloseMojoConnection(); |
| 598 } | 612 } |
| 599 | 613 |
| 600 void PaymentRequest::OnComplete() | 614 void PaymentRequest::OnComplete() |
| 601 { | 615 { |
| 602 DCHECK(m_completeResolver); | 616 DCHECK(m_completeResolver); |
| 603 m_completeResolver->resolve(); | 617 m_completeResolver->resolve(); |
| 604 clearResolversAndCloseMojoConnection(); | 618 clearResolversAndCloseMojoConnection(); |
| 605 } | 619 } |
| 606 | 620 |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 624 { | 638 { |
| 625 m_completeResolver.clear(); | 639 m_completeResolver.clear(); |
| 626 m_showResolver.clear(); | 640 m_showResolver.clear(); |
| 627 m_abortResolver.clear(); | 641 m_abortResolver.clear(); |
| 628 if (m_clientBinding.is_bound()) | 642 if (m_clientBinding.is_bound()) |
| 629 m_clientBinding.Close(); | 643 m_clientBinding.Close(); |
| 630 m_paymentProvider.reset(); | 644 m_paymentProvider.reset(); |
| 631 } | 645 } |
| 632 | 646 |
| 633 } // namespace blink | 647 } // namespace blink |
| OLD | NEW |