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/ScriptPromiseResolver.h" | 8 #include "bindings/core/v8/ScriptPromiseResolver.h" |
9 #include "bindings/core/v8/ScriptState.h" | 9 #include "bindings/core/v8/ScriptState.h" |
10 #include "bindings/core/v8/V8StringResource.h" | 10 #include "bindings/core/v8/V8StringResource.h" |
(...skipping 15 matching lines...) Expand all Loading... | |
26 #include "modules/payments/PaymentsValidators.h" | 26 #include "modules/payments/PaymentsValidators.h" |
27 #include "mojo/public/cpp/bindings/interface_request.h" | 27 #include "mojo/public/cpp/bindings/interface_request.h" |
28 #include "mojo/public/cpp/bindings/wtf_array.h" | 28 #include "mojo/public/cpp/bindings/wtf_array.h" |
29 #include "platform/mojo/MojoHelper.h" | 29 #include "platform/mojo/MojoHelper.h" |
30 #include "public/platform/InterfaceProvider.h" | 30 #include "public/platform/InterfaceProvider.h" |
31 #include "public/platform/Platform.h" | 31 #include "public/platform/Platform.h" |
32 #include "public/platform/WebTraceLocation.h" | 32 #include "public/platform/WebTraceLocation.h" |
33 #include "wtf/HashSet.h" | 33 #include "wtf/HashSet.h" |
34 #include <utility> | 34 #include <utility> |
35 | 35 |
36 namespace mojo { | 36 using payments::mojom::blink::ActivePaymentQueryResult; |
37 | 37 using payments::mojom::blink::PaymentAddressPtr; |
38 using payments::mojom::blink::PaymentCurrencyAmount; | 38 using payments::mojom::blink::PaymentCurrencyAmount; |
39 using payments::mojom::blink::PaymentCurrencyAmountPtr; | 39 using payments::mojom::blink::PaymentCurrencyAmountPtr; |
40 using payments::mojom::blink::PaymentDetails; | 40 using payments::mojom::blink::PaymentDetails; |
41 using payments::mojom::blink::PaymentDetailsModifier; | 41 using payments::mojom::blink::PaymentDetailsModifier; |
42 using payments::mojom::blink::PaymentDetailsModifierPtr; | 42 using payments::mojom::blink::PaymentDetailsModifierPtr; |
43 using payments::mojom::blink::PaymentDetailsPtr; | 43 using payments::mojom::blink::PaymentDetailsPtr; |
44 using payments::mojom::blink::PaymentDetailsPtr; | |
44 using payments::mojom::blink::PaymentErrorReason; | 45 using payments::mojom::blink::PaymentErrorReason; |
45 using payments::mojom::blink::PaymentItem; | 46 using payments::mojom::blink::PaymentItem; |
46 using payments::mojom::blink::PaymentItemPtr; | 47 using payments::mojom::blink::PaymentItemPtr; |
47 using payments::mojom::blink::PaymentMethodData; | 48 using payments::mojom::blink::PaymentMethodData; |
48 using payments::mojom::blink::PaymentMethodDataPtr; | 49 using payments::mojom::blink::PaymentMethodDataPtr; |
49 using payments::mojom::blink::PaymentOptions; | 50 using payments::mojom::blink::PaymentOptions; |
50 using payments::mojom::blink::PaymentOptionsPtr; | 51 using payments::mojom::blink::PaymentOptionsPtr; |
52 using payments::mojom::blink::PaymentResponsePtr; | |
51 using payments::mojom::blink::PaymentShippingOption; | 53 using payments::mojom::blink::PaymentShippingOption; |
52 using payments::mojom::blink::PaymentShippingOptionPtr; | 54 using payments::mojom::blink::PaymentShippingOptionPtr; |
53 using payments::mojom::blink::PaymentShippingType; | 55 using payments::mojom::blink::PaymentShippingType; |
54 | 56 |
57 namespace mojo { | |
58 | |
55 template <> | 59 template <> |
56 struct TypeConverter<PaymentCurrencyAmountPtr, blink::PaymentCurrencyAmount> { | 60 struct TypeConverter<PaymentCurrencyAmountPtr, blink::PaymentCurrencyAmount> { |
57 static PaymentCurrencyAmountPtr Convert( | 61 static PaymentCurrencyAmountPtr Convert( |
58 const blink::PaymentCurrencyAmount& input) { | 62 const blink::PaymentCurrencyAmount& input) { |
59 PaymentCurrencyAmountPtr output = PaymentCurrencyAmount::New(); | 63 PaymentCurrencyAmountPtr output = PaymentCurrencyAmount::New(); |
60 output->currency = input.currency(); | 64 output->currency = input.currency(); |
61 output->value = input.value(); | 65 output->value = input.value(); |
62 if (input.hasCurrencySystem()) | 66 if (input.hasCurrencySystem()) |
63 output->currencySystem = input.currencySystem(); | 67 output->currencySystem = input.currencySystem(); |
64 return output; | 68 return output; |
(...skipping 22 matching lines...) Expand all Loading... | |
87 output->selected = input.hasSelected() && input.selected(); | 91 output->selected = input.hasSelected() && input.selected(); |
88 return output; | 92 return output; |
89 } | 93 } |
90 }; | 94 }; |
91 | 95 |
92 template <> | 96 template <> |
93 struct TypeConverter<PaymentDetailsModifierPtr, blink::PaymentDetailsModifier> { | 97 struct TypeConverter<PaymentDetailsModifierPtr, blink::PaymentDetailsModifier> { |
94 static PaymentDetailsModifierPtr Convert( | 98 static PaymentDetailsModifierPtr Convert( |
95 const blink::PaymentDetailsModifier& input) { | 99 const blink::PaymentDetailsModifier& input) { |
96 PaymentDetailsModifierPtr output = PaymentDetailsModifier::New(); | 100 PaymentDetailsModifierPtr output = PaymentDetailsModifier::New(); |
97 output->supported_methods = | 101 output->supported_methods = input.supportedMethods(); |
98 WTF::Vector<WTF::String>(input.supportedMethods()); | |
99 | 102 |
100 if (input.hasTotal()) | 103 if (input.hasTotal()) |
101 output->total = PaymentItem::From(input.total()); | 104 output->total = PaymentItem::From(input.total()); |
102 | 105 |
103 if (input.hasAdditionalDisplayItems()) { | 106 if (input.hasAdditionalDisplayItems()) { |
104 for (size_t i = 0; i < input.additionalDisplayItems().size(); ++i) { | 107 for (size_t i = 0; i < input.additionalDisplayItems().size(); ++i) { |
105 output->additional_display_items.append( | 108 output->additional_display_items.append( |
106 PaymentItem::From(input.additionalDisplayItems()[i])); | 109 PaymentItem::From(input.additionalDisplayItems()[i])); |
107 } | 110 } |
108 } | 111 } |
(...skipping 24 matching lines...) Expand all Loading... | |
133 if (input.hasModifiers()) { | 136 if (input.hasModifiers()) { |
134 for (size_t i = 0; i < input.modifiers().size(); ++i) { | 137 for (size_t i = 0; i < input.modifiers().size(); ++i) { |
135 output->modifiers.append( | 138 output->modifiers.append( |
136 PaymentDetailsModifier::From(input.modifiers()[i])); | 139 PaymentDetailsModifier::From(input.modifiers()[i])); |
137 } | 140 } |
138 } | 141 } |
139 | 142 |
140 if (input.hasError()) | 143 if (input.hasError()) |
141 output->error = input.error(); | 144 output->error = input.error(); |
142 else | 145 else |
143 output->error = WTF::emptyString(); | 146 output->error = emptyString(); |
144 | 147 |
145 return output; | 148 return output; |
146 } | 149 } |
147 }; | 150 }; |
148 | 151 |
149 template <> | 152 template <> |
150 struct TypeConverter<PaymentOptionsPtr, blink::PaymentOptions> { | 153 struct TypeConverter<PaymentOptionsPtr, blink::PaymentOptions> { |
151 static PaymentOptionsPtr Convert(const blink::PaymentOptions& input) { | 154 static PaymentOptionsPtr Convert(const blink::PaymentOptions& input) { |
152 PaymentOptionsPtr output = PaymentOptions::New(); | 155 PaymentOptionsPtr output = PaymentOptions::New(); |
153 output->request_payer_name = input.requestPayerName(); | 156 output->request_payer_name = input.requestPayerName(); |
154 output->request_payer_email = input.requestPayerEmail(); | 157 output->request_payer_email = input.requestPayerEmail(); |
155 output->request_payer_phone = input.requestPayerPhone(); | 158 output->request_payer_phone = input.requestPayerPhone(); |
156 output->request_shipping = input.requestShipping(); | 159 output->request_shipping = input.requestShipping(); |
157 | 160 |
158 if (input.shippingType() == "delivery") | 161 if (input.shippingType() == "delivery") |
159 output->shipping_type = PaymentShippingType::DELIVERY; | 162 output->shipping_type = PaymentShippingType::DELIVERY; |
160 else if (input.shippingType() == "pickup") | 163 else if (input.shippingType() == "pickup") |
161 output->shipping_type = PaymentShippingType::PICKUP; | 164 output->shipping_type = PaymentShippingType::PICKUP; |
162 else | 165 else |
163 output->shipping_type = PaymentShippingType::SHIPPING; | 166 output->shipping_type = PaymentShippingType::SHIPPING; |
164 | 167 |
165 return output; | 168 return output; |
166 } | 169 } |
167 }; | 170 }; |
168 | 171 |
169 template <> | 172 template <> |
170 struct TypeConverter<WTFArray<PaymentMethodDataPtr>, | 173 struct TypeConverter<WTFArray<PaymentMethodDataPtr>, |
171 WTF::Vector<blink::PaymentRequest::MethodData>> { | 174 Vector<blink::PaymentRequest::MethodData>> { |
172 static WTFArray<PaymentMethodDataPtr> Convert( | 175 static WTFArray<PaymentMethodDataPtr> Convert( |
173 const WTF::Vector<blink::PaymentRequest::MethodData>& input) { | 176 const Vector<blink::PaymentRequest::MethodData>& input) { |
174 WTFArray<PaymentMethodDataPtr> output(input.size()); | 177 WTFArray<PaymentMethodDataPtr> output(input.size()); |
175 for (size_t i = 0; i < input.size(); ++i) { | 178 for (size_t i = 0; i < input.size(); ++i) { |
176 output[i] = PaymentMethodData::New(); | 179 output[i] = PaymentMethodData::New(); |
177 output[i]->supported_methods = | 180 output[i]->supported_methods = input[i].supportedMethods; |
178 WTF::Vector<WTF::String>(input[i].supportedMethods); | |
179 output[i]->stringified_data = input[i].stringifiedData; | 181 output[i]->stringified_data = input[i].stringifiedData; |
180 } | 182 } |
181 return output; | 183 return output; |
182 } | 184 } |
183 }; | 185 }; |
184 | 186 |
185 } // namespace mojo | 187 } // namespace mojo |
186 | 188 |
187 namespace blink { | 189 namespace blink { |
188 namespace { | 190 namespace { |
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
411 static const char* const validValues[] = { | 413 static const char* const validValues[] = { |
412 "shipping", "delivery", "pickup", | 414 "shipping", "delivery", "pickup", |
413 }; | 415 }; |
414 for (size_t i = 0; i < WTF_ARRAY_LENGTH(validValues); i++) { | 416 for (size_t i = 0; i < WTF_ARRAY_LENGTH(validValues); i++) { |
415 if (shippingType == validValues[i]) | 417 if (shippingType == validValues[i]) |
416 return shippingType; | 418 return shippingType; |
417 } | 419 } |
418 return validValues[0]; | 420 return validValues[0]; |
419 } | 421 } |
420 | 422 |
421 payments::mojom::blink::PaymentDetailsPtr maybeKeepShippingOptions( | 423 PaymentDetailsPtr maybeKeepShippingOptions(PaymentDetailsPtr details, |
422 payments::mojom::blink::PaymentDetailsPtr details, | 424 bool keep) { |
423 bool keep) { | |
424 if (!keep) | 425 if (!keep) |
425 details->shipping_options.resize(0); | 426 details->shipping_options.resize(0); |
426 | 427 |
427 return details; | 428 return details; |
428 } | 429 } |
429 | 430 |
430 bool allowedToUsePaymentRequest(const Frame* frame) { | 431 bool allowedToUsePaymentRequest(const Frame* frame) { |
431 // To determine whether a Document object |document| is allowed to use the | 432 // To determine whether a Document object |document| is allowed to use the |
432 // feature indicated by attribute name |allowpaymentrequest|, run these steps: | 433 // feature indicated by attribute name |allowpaymentrequest|, run these steps: |
433 | 434 |
(...skipping 14 matching lines...) Expand all Loading... | |
448 if (ownerElement && isHTMLIFrameElement(ownerElement)) { | 449 if (ownerElement && isHTMLIFrameElement(ownerElement)) { |
449 HTMLIFrameElement* iframe = toHTMLIFrameElement(ownerElement); | 450 HTMLIFrameElement* iframe = toHTMLIFrameElement(ownerElement); |
450 if (HTMLIFrameElementPayments::from(*iframe).allowPaymentRequest(*iframe)) | 451 if (HTMLIFrameElementPayments::from(*iframe).allowPaymentRequest(*iframe)) |
451 return allowedToUsePaymentRequest(frame->tree().parent()); | 452 return allowedToUsePaymentRequest(frame->tree().parent()); |
452 } | 453 } |
453 | 454 |
454 // 4. Return false. | 455 // 4. Return false. |
455 return false; | 456 return false; |
456 } | 457 } |
457 | 458 |
458 WTF::Vector<payments::mojom::blink::PaymentMethodDataPtr> | 459 Vector<PaymentMethodDataPtr> ConvertPaymentMethodData( |
459 ConvertPaymentMethodData( | |
460 const Vector<PaymentRequest::MethodData>& blinkMethods) { | 460 const Vector<PaymentRequest::MethodData>& blinkMethods) { |
461 WTF::Vector<payments::mojom::blink::PaymentMethodDataPtr> mojoMethods( | 461 Vector<PaymentMethodDataPtr> mojoMethods(blinkMethods.size()); |
462 blinkMethods.size()); | |
463 for (size_t i = 0; i < blinkMethods.size(); ++i) { | 462 for (size_t i = 0; i < blinkMethods.size(); ++i) { |
464 mojoMethods[i] = payments::mojom::blink::PaymentMethodData::New(); | 463 mojoMethods[i] = payments::mojom::blink::PaymentMethodData::New(); |
465 mojoMethods[i]->supported_methods = | 464 mojoMethods[i]->supported_methods = blinkMethods[i].supportedMethods; |
466 WTF::Vector<WTF::String>(blinkMethods[i].supportedMethods); | |
467 mojoMethods[i]->stringified_data = blinkMethods[i].stringifiedData; | 465 mojoMethods[i]->stringified_data = blinkMethods[i].stringifiedData; |
468 } | 466 } |
469 return mojoMethods; | 467 return mojoMethods; |
470 } | 468 } |
471 | 469 |
472 } // namespace | 470 } // namespace |
473 | 471 |
474 PaymentRequest* PaymentRequest::create( | 472 PaymentRequest* PaymentRequest::create( |
475 ScriptState* scriptState, | 473 ScriptState* scriptState, |
476 const HeapVector<PaymentMethodData>& methodData, | 474 const HeapVector<PaymentMethodData>& methodData, |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
521 return ScriptPromise::rejectWithDOMException( | 519 return ScriptPromise::rejectWithDOMException( |
522 scriptState, | 520 scriptState, |
523 DOMException::create(InvalidStateError, | 521 DOMException::create(InvalidStateError, |
524 "Never called show(), so nothing to abort")); | 522 "Never called show(), so nothing to abort")); |
525 | 523 |
526 m_abortResolver = ScriptPromiseResolver::create(scriptState); | 524 m_abortResolver = ScriptPromiseResolver::create(scriptState); |
527 m_paymentProvider->Abort(); | 525 m_paymentProvider->Abort(); |
528 return m_abortResolver->promise(); | 526 return m_abortResolver->promise(); |
529 } | 527 } |
530 | 528 |
529 ScriptPromise PaymentRequest::canMakeActivePayment(ScriptState* scriptState) { | |
530 if (!m_paymentProvider.is_bound() || m_canMakeActivePaymentResolver || | |
531 !scriptState->contextIsValid()) { | |
532 return ScriptPromise::rejectWithDOMException( | |
533 scriptState, DOMException::create(InvalidStateError, | |
534 "Cannot query payment request")); | |
535 } | |
536 | |
537 m_paymentProvider->CanMakeActivePayment(); | |
538 | |
539 m_canMakeActivePaymentResolver = ScriptPromiseResolver::create(scriptState); | |
540 return m_canMakeActivePaymentResolver->promise(); | |
541 } | |
542 | |
531 bool PaymentRequest::hasPendingActivity() const { | 543 bool PaymentRequest::hasPendingActivity() const { |
532 return m_showResolver || m_completeResolver; | 544 return m_showResolver || m_completeResolver; |
533 } | 545 } |
534 | 546 |
535 const AtomicString& PaymentRequest::interfaceName() const { | 547 const AtomicString& PaymentRequest::interfaceName() const { |
536 return EventTargetNames::PaymentRequest; | 548 return EventTargetNames::PaymentRequest; |
537 } | 549 } |
538 | 550 |
539 ExecutionContext* PaymentRequest::getExecutionContext() const { | 551 ExecutionContext* PaymentRequest::getExecutionContext() const { |
540 return ContextLifecycleObserver::getExecutionContext(); | 552 return ContextLifecycleObserver::getExecutionContext(); |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
613 m_completeResolver->reject(DOMException::create(AbortError, error)); | 625 m_completeResolver->reject(DOMException::create(AbortError, error)); |
614 clearResolversAndCloseMojoConnection(); | 626 clearResolversAndCloseMojoConnection(); |
615 } | 627 } |
616 | 628 |
617 DEFINE_TRACE(PaymentRequest) { | 629 DEFINE_TRACE(PaymentRequest) { |
618 visitor->trace(m_options); | 630 visitor->trace(m_options); |
619 visitor->trace(m_shippingAddress); | 631 visitor->trace(m_shippingAddress); |
620 visitor->trace(m_showResolver); | 632 visitor->trace(m_showResolver); |
621 visitor->trace(m_completeResolver); | 633 visitor->trace(m_completeResolver); |
622 visitor->trace(m_abortResolver); | 634 visitor->trace(m_abortResolver); |
635 visitor->trace(m_canMakeActivePaymentResolver); | |
623 EventTargetWithInlineData::trace(visitor); | 636 EventTargetWithInlineData::trace(visitor); |
624 ContextLifecycleObserver::trace(visitor); | 637 ContextLifecycleObserver::trace(visitor); |
625 } | 638 } |
626 | 639 |
627 void PaymentRequest::onCompleteTimeoutForTesting() { | 640 void PaymentRequest::onCompleteTimeoutForTesting() { |
628 m_completeTimer.stop(); | 641 m_completeTimer.stop(); |
629 onCompleteTimeout(0); | 642 onCompleteTimeout(0); |
630 } | 643 } |
631 | 644 |
632 PaymentRequest::PaymentRequest(ScriptState* scriptState, | 645 PaymentRequest::PaymentRequest(ScriptState* scriptState, |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
669 if (m_options.requestShipping()) { | 682 if (m_options.requestShipping()) { |
670 if (keepShippingOptions) | 683 if (keepShippingOptions) |
671 m_shippingOption = getSelectedShippingOption(details); | 684 m_shippingOption = getSelectedShippingOption(details); |
672 m_shippingType = getValidShippingType(m_options.shippingType()); | 685 m_shippingType = getValidShippingType(m_options.shippingType()); |
673 } | 686 } |
674 | 687 |
675 scriptState->domWindow()->frame()->interfaceProvider()->getInterface( | 688 scriptState->domWindow()->frame()->interfaceProvider()->getInterface( |
676 mojo::GetProxy(&m_paymentProvider)); | 689 mojo::GetProxy(&m_paymentProvider)); |
677 m_paymentProvider.set_connection_error_handler(convertToBaseCallback( | 690 m_paymentProvider.set_connection_error_handler(convertToBaseCallback( |
678 WTF::bind(&PaymentRequest::OnError, wrapWeakPersistent(this), | 691 WTF::bind(&PaymentRequest::OnError, wrapWeakPersistent(this), |
679 payments::mojom::blink::PaymentErrorReason::UNKNOWN))); | 692 PaymentErrorReason::UNKNOWN))); |
680 m_paymentProvider->Init( | 693 m_paymentProvider->Init( |
681 m_clientBinding.CreateInterfacePtrAndBind(), | 694 m_clientBinding.CreateInterfacePtrAndBind(), |
682 ConvertPaymentMethodData(validatedMethodData), | 695 ConvertPaymentMethodData(validatedMethodData), |
683 maybeKeepShippingOptions( | 696 maybeKeepShippingOptions( |
684 payments::mojom::blink::PaymentDetails::From(details), | 697 payments::mojom::blink::PaymentDetails::From(details), |
685 keepShippingOptions && m_options.requestShipping()), | 698 keepShippingOptions && m_options.requestShipping()), |
686 payments::mojom::blink::PaymentOptions::From(m_options)); | 699 payments::mojom::blink::PaymentOptions::From(m_options)); |
687 } | 700 } |
688 | 701 |
689 void PaymentRequest::contextDestroyed() { | 702 void PaymentRequest::contextDestroyed() { |
690 clearResolversAndCloseMojoConnection(); | 703 clearResolversAndCloseMojoConnection(); |
691 } | 704 } |
692 | 705 |
693 void PaymentRequest::OnShippingAddressChange( | 706 void PaymentRequest::OnShippingAddressChange(PaymentAddressPtr address) { |
694 payments::mojom::blink::PaymentAddressPtr address) { | |
695 DCHECK(m_showResolver); | 707 DCHECK(m_showResolver); |
696 DCHECK(!m_completeResolver); | 708 DCHECK(!m_completeResolver); |
697 | 709 |
698 String errorMessage; | 710 String errorMessage; |
699 if (!PaymentsValidators::isValidShippingAddress(address, &errorMessage)) { | 711 if (!PaymentsValidators::isValidShippingAddress(address, &errorMessage)) { |
700 m_showResolver->reject(DOMException::create(SyntaxError, errorMessage)); | 712 m_showResolver->reject(DOMException::create(SyntaxError, errorMessage)); |
701 clearResolversAndCloseMojoConnection(); | 713 clearResolversAndCloseMojoConnection(); |
702 return; | 714 return; |
703 } | 715 } |
704 | 716 |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
770 m_completeTimer.startOneShot(completeTimeoutSeconds, BLINK_FROM_HERE); | 782 m_completeTimer.startOneShot(completeTimeoutSeconds, BLINK_FROM_HERE); |
771 | 783 |
772 m_showResolver->resolve(new PaymentResponse(std::move(response), this)); | 784 m_showResolver->resolve(new PaymentResponse(std::move(response), this)); |
773 | 785 |
774 // Do not close the mojo connection here. The merchant website should call | 786 // Do not close the mojo connection here. The merchant website should call |
775 // PaymentResponse::complete(String), which will be forwarded over the mojo | 787 // PaymentResponse::complete(String), which will be forwarded over the mojo |
776 // connection to display a success or failure message to the user. | 788 // connection to display a success or failure message to the user. |
777 m_showResolver.clear(); | 789 m_showResolver.clear(); |
778 } | 790 } |
779 | 791 |
780 void PaymentRequest::OnError(mojo::PaymentErrorReason error) { | 792 void PaymentRequest::OnError(PaymentErrorReason error) { |
781 if (!Platform::current()) { | 793 if (!Platform::current()) { |
782 // TODO(rockot): Clean this up once renderer shutdown sequence is fixed. | 794 // TODO(rockot): Clean this up once renderer shutdown sequence is fixed. |
783 return; | 795 return; |
784 } | 796 } |
785 | 797 |
786 bool isError = false; | 798 bool isError = false; |
787 ExceptionCode ec = UnknownError; | 799 ExceptionCode ec = UnknownError; |
788 String message; | 800 String message; |
789 | 801 |
790 switch (error) { | 802 switch (error) { |
791 case payments::mojom::blink::PaymentErrorReason::USER_CANCEL: | 803 case PaymentErrorReason::USER_CANCEL: |
792 message = "Request cancelled"; | 804 message = "Request cancelled"; |
793 break; | 805 break; |
794 case payments::mojom::blink::PaymentErrorReason::NOT_SUPPORTED: | 806 case PaymentErrorReason::NOT_SUPPORTED: |
795 isError = true; | 807 isError = true; |
796 ec = NotSupportedError; | 808 ec = NotSupportedError; |
797 message = "The payment method is not supported"; | 809 message = "The payment method is not supported"; |
798 break; | 810 break; |
799 case payments::mojom::blink::PaymentErrorReason::UNKNOWN: | 811 case PaymentErrorReason::UNKNOWN: |
800 isError = true; | 812 isError = true; |
801 ec = UnknownError; | 813 ec = UnknownError; |
802 message = "Request failed"; | 814 message = "Request failed"; |
803 break; | 815 break; |
804 } | 816 } |
805 | 817 |
806 DCHECK(!message.isEmpty()); | 818 DCHECK(!message.isEmpty()); |
807 | 819 |
808 if (isError) { | 820 if (isError) { |
809 if (m_completeResolver) | 821 if (m_completeResolver) |
810 m_completeResolver->reject(DOMException::create(ec, message)); | 822 m_completeResolver->reject(DOMException::create(ec, message)); |
811 | 823 |
812 if (m_showResolver) | 824 if (m_showResolver) |
813 m_showResolver->reject(DOMException::create(ec, message)); | 825 m_showResolver->reject(DOMException::create(ec, message)); |
814 | 826 |
815 if (m_abortResolver) | 827 if (m_abortResolver) |
816 m_abortResolver->reject(DOMException::create(ec, message)); | 828 m_abortResolver->reject(DOMException::create(ec, message)); |
829 | |
830 if (m_canMakeActivePaymentResolver) | |
831 m_canMakeActivePaymentResolver->reject(DOMException::create(ec, message)); | |
817 } else { | 832 } else { |
818 if (m_completeResolver) | 833 if (m_completeResolver) |
819 m_completeResolver->reject(message); | 834 m_completeResolver->reject(message); |
820 | 835 |
821 if (m_showResolver) | 836 if (m_showResolver) |
822 m_showResolver->reject(message); | 837 m_showResolver->reject(message); |
823 | 838 |
824 if (m_abortResolver) | 839 if (m_abortResolver) |
825 m_abortResolver->reject(message); | 840 m_abortResolver->reject(message); |
841 | |
842 if (m_canMakeActivePaymentResolver) | |
843 m_canMakeActivePaymentResolver->reject(message); | |
826 } | 844 } |
827 | 845 |
828 clearResolversAndCloseMojoConnection(); | 846 clearResolversAndCloseMojoConnection(); |
829 } | 847 } |
830 | 848 |
831 void PaymentRequest::OnComplete() { | 849 void PaymentRequest::OnComplete() { |
832 DCHECK(m_completeResolver); | 850 DCHECK(m_completeResolver); |
833 m_completeResolver->resolve(); | 851 m_completeResolver->resolve(); |
834 clearResolversAndCloseMojoConnection(); | 852 clearResolversAndCloseMojoConnection(); |
835 } | 853 } |
836 | 854 |
837 void PaymentRequest::OnAbort(bool abortedSuccessfully) { | 855 void PaymentRequest::OnAbort(bool abortedSuccessfully) { |
838 DCHECK(m_abortResolver); | 856 DCHECK(m_abortResolver); |
839 DCHECK(m_showResolver); | 857 DCHECK(m_showResolver); |
840 | 858 |
841 if (!abortedSuccessfully) { | 859 if (!abortedSuccessfully) { |
842 m_abortResolver->reject(DOMException::create(InvalidStateError)); | 860 m_abortResolver->reject(DOMException::create(InvalidStateError)); |
843 m_abortResolver.clear(); | 861 m_abortResolver.clear(); |
844 return; | 862 return; |
845 } | 863 } |
846 | 864 |
847 m_showResolver->reject(DOMException::create(AbortError)); | 865 m_showResolver->reject(DOMException::create(AbortError)); |
848 m_abortResolver->resolve(); | 866 m_abortResolver->resolve(); |
849 clearResolversAndCloseMojoConnection(); | 867 clearResolversAndCloseMojoConnection(); |
850 } | 868 } |
851 | 869 |
870 void PaymentRequest::OnCanMakeActivePayment(ActivePaymentQueryResult result) { | |
871 DCHECK(m_canMakeActivePaymentResolver); | |
872 | |
873 switch (result) { | |
874 case ActivePaymentQueryResult::CAN_MAKE_ACTIVE_PAYMENT: | |
875 m_canMakeActivePaymentResolver->resolve(true); | |
876 break; | |
877 case ActivePaymentQueryResult::CANNOT_MAKE_ACTIVE_PAYMENT: | |
878 m_canMakeActivePaymentResolver->resolve(false); | |
879 break; | |
880 case ActivePaymentQueryResult::QUERY_QUOTA_EXCEEDED: | |
881 m_canMakeActivePaymentResolver->reject("Query quota exceeded"); | |
Marijn Kruisselbrink
2016/11/17 18:06:21
I would expect the spec to say to reject with a Qu
please use gerrit instead
2016/11/17 20:07:21
Done.
| |
882 break; | |
883 } | |
884 | |
885 m_canMakeActivePaymentResolver.clear(); | |
886 } | |
887 | |
852 void PaymentRequest::onCompleteTimeout(TimerBase*) { | 888 void PaymentRequest::onCompleteTimeout(TimerBase*) { |
853 m_paymentProvider->Complete(payments::mojom::blink::PaymentComplete(Fail)); | 889 m_paymentProvider->Complete(payments::mojom::blink::PaymentComplete(Fail)); |
854 clearResolversAndCloseMojoConnection(); | 890 clearResolversAndCloseMojoConnection(); |
855 } | 891 } |
856 | 892 |
857 void PaymentRequest::clearResolversAndCloseMojoConnection() { | 893 void PaymentRequest::clearResolversAndCloseMojoConnection() { |
858 m_completeTimer.stop(); | 894 m_completeTimer.stop(); |
859 m_completeResolver.clear(); | 895 m_completeResolver.clear(); |
860 m_showResolver.clear(); | 896 m_showResolver.clear(); |
861 m_abortResolver.clear(); | 897 m_abortResolver.clear(); |
898 m_canMakeActivePaymentResolver.clear(); | |
862 if (m_clientBinding.is_bound()) | 899 if (m_clientBinding.is_bound()) |
863 m_clientBinding.Close(); | 900 m_clientBinding.Close(); |
864 m_paymentProvider.reset(); | 901 m_paymentProvider.reset(); |
865 } | 902 } |
866 | 903 |
867 } // namespace blink | 904 } // namespace blink |
OLD | NEW |