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

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

Issue 2770193003: Implement request id in PaymentDetailsInit (Closed)
Patch Set: Rebase once more since mojom file moved Created 3 years, 7 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 <stddef.h> 7 #include <stddef.h>
8 #include <utility> 8 #include <utility>
9 #include "bindings/core/v8/ExceptionState.h" 9 #include "bindings/core/v8/ExceptionState.h"
10 #include "bindings/core/v8/ScriptPromiseResolver.h" 10 #include "bindings/core/v8/ScriptPromiseResolver.h"
(...skipping 21 matching lines...) Expand all
32 #include "modules/payments/PaymentAddress.h" 32 #include "modules/payments/PaymentAddress.h"
33 #include "modules/payments/PaymentDetailsInit.h" 33 #include "modules/payments/PaymentDetailsInit.h"
34 #include "modules/payments/PaymentDetailsUpdate.h" 34 #include "modules/payments/PaymentDetailsUpdate.h"
35 #include "modules/payments/PaymentItem.h" 35 #include "modules/payments/PaymentItem.h"
36 #include "modules/payments/PaymentRequestUpdateEvent.h" 36 #include "modules/payments/PaymentRequestUpdateEvent.h"
37 #include "modules/payments/PaymentResponse.h" 37 #include "modules/payments/PaymentResponse.h"
38 #include "modules/payments/PaymentShippingOption.h" 38 #include "modules/payments/PaymentShippingOption.h"
39 #include "modules/payments/PaymentsValidators.h" 39 #include "modules/payments/PaymentsValidators.h"
40 #include "mojo/public/cpp/bindings/interface_request.h" 40 #include "mojo/public/cpp/bindings/interface_request.h"
41 #include "platform/RuntimeEnabledFeatures.h" 41 #include "platform/RuntimeEnabledFeatures.h"
42 #include "platform/UUID.h"
42 #include "platform/mojo/MojoHelper.h" 43 #include "platform/mojo/MojoHelper.h"
43 #include "platform/wtf/HashSet.h" 44 #include "platform/wtf/HashSet.h"
44 #include "public/platform/InterfaceProvider.h" 45 #include "public/platform/InterfaceProvider.h"
45 #include "public/platform/Platform.h" 46 #include "public/platform/Platform.h"
46 #include "public/platform/WebTraceLocation.h" 47 #include "public/platform/WebTraceLocation.h"
47 48
48 namespace { 49 namespace {
49 50
50 using ::payments::mojom::blink::CanMakePaymentQueryResult; 51 using ::payments::mojom::blink::CanMakePaymentQueryResult;
51 using ::payments::mojom::blink::PaymentAddressPtr; 52 using ::payments::mojom::blink::PaymentAddressPtr;
(...skipping 477 matching lines...) Expand 10 before | Expand all | Expand 10 after
529 shipping_option_output, 530 shipping_option_output,
530 execution_context, exception_state); 531 execution_context, exception_state);
531 if (exception_state.HadException()) 532 if (exception_state.HadException())
532 return; 533 return;
533 534
534 if (!input.hasTotal()) { 535 if (!input.hasTotal()) {
535 exception_state.ThrowTypeError("Must specify total"); 536 exception_state.ThrowTypeError("Must specify total");
536 return; 537 return;
537 } 538 }
538 539
540 if (input.hasId())
541 output->id = input.id();
542 else
543 output->id = CreateCanonicalUUIDString();
544
539 ValidateAndConvertTotal(input.total(), output->total, exception_state); 545 ValidateAndConvertTotal(input.total(), output->total, exception_state);
540 } 546 }
541 547
542 void ValidateAndConvertPaymentDetailsUpdate(const PaymentDetailsUpdate& input, 548 void ValidateAndConvertPaymentDetailsUpdate(const PaymentDetailsUpdate& input,
543 bool request_shipping, 549 bool request_shipping,
544 PaymentDetailsPtr& output, 550 PaymentDetailsPtr& output,
545 String& shipping_option_output, 551 String& shipping_option_output,
546 ExecutionContext& execution_context, 552 ExecutionContext& execution_context,
547 ExceptionState& exception_state) { 553 ExceptionState& exception_state) {
548 ValidateAndConvertPaymentDetailsBase(input, request_shipping, output, 554 ValidateAndConvertPaymentDetailsBase(input, request_shipping, output,
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after
873 } 879 }
874 880
875 PaymentDetailsPtr validated_details = 881 PaymentDetailsPtr validated_details =
876 payments::mojom::blink::PaymentDetails::New(); 882 payments::mojom::blink::PaymentDetails::New();
877 ValidateAndConvertPaymentDetailsInit(details, options_.requestShipping(), 883 ValidateAndConvertPaymentDetailsInit(details, options_.requestShipping(),
878 validated_details, shipping_option_, 884 validated_details, shipping_option_,
879 *GetExecutionContext(), exception_state); 885 *GetExecutionContext(), exception_state);
880 if (exception_state.HadException()) 886 if (exception_state.HadException())
881 return; 887 return;
882 888
889 id_ = validated_details->id;
890
883 if (options_.requestShipping()) 891 if (options_.requestShipping())
884 shipping_type_ = GetValidShippingType(options_.shippingType()); 892 shipping_type_ = GetValidShippingType(options_.shippingType());
885 893
886 GetFrame()->GetInterfaceProvider()->GetInterface( 894 GetFrame()->GetInterfaceProvider()->GetInterface(
887 mojo::MakeRequest(&payment_provider_)); 895 mojo::MakeRequest(&payment_provider_));
888 payment_provider_.set_connection_error_handler(ConvertToBaseCallback( 896 payment_provider_.set_connection_error_handler(ConvertToBaseCallback(
889 WTF::Bind(&PaymentRequest::OnError, WrapWeakPersistent(this), 897 WTF::Bind(&PaymentRequest::OnError, WrapWeakPersistent(this),
890 PaymentErrorReason::UNKNOWN))); 898 PaymentErrorReason::UNKNOWN)));
891 payment_provider_->Init( 899 payment_provider_->Init(
892 client_binding_.CreateInterfacePtrAndBind(), 900 client_binding_.CreateInterfacePtrAndBind(),
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
968 (!options_.requestPayerName() && !response->payer_name.IsNull()) || 976 (!options_.requestPayerName() && !response->payer_name.IsNull()) ||
969 (!options_.requestPayerEmail() && !response->payer_email.IsNull()) || 977 (!options_.requestPayerEmail() && !response->payer_email.IsNull()) ||
970 (!options_.requestPayerPhone() && !response->payer_phone.IsNull())) { 978 (!options_.requestPayerPhone() && !response->payer_phone.IsNull())) {
971 show_resolver_->Reject(DOMException::Create(kSyntaxError)); 979 show_resolver_->Reject(DOMException::Create(kSyntaxError));
972 ClearResolversAndCloseMojoConnection(); 980 ClearResolversAndCloseMojoConnection();
973 return; 981 return;
974 } 982 }
975 983
976 complete_timer_.StartOneShot(kCompleteTimeoutSeconds, BLINK_FROM_HERE); 984 complete_timer_.StartOneShot(kCompleteTimeoutSeconds, BLINK_FROM_HERE);
977 985
978 show_resolver_->Resolve(new PaymentResponse(std::move(response), this)); 986 show_resolver_->Resolve(new PaymentResponse(std::move(response), this, id_));
979 987
980 // Do not close the mojo connection here. The merchant website should call 988 // Do not close the mojo connection here. The merchant website should call
981 // PaymentResponse::complete(String), which will be forwarded over the mojo 989 // PaymentResponse::complete(String), which will be forwarded over the mojo
982 // connection to display a success or failure message to the user. 990 // connection to display a success or failure message to the user.
983 show_resolver_.Clear(); 991 show_resolver_.Clear();
984 } 992 }
985 993
986 void PaymentRequest::OnError(PaymentErrorReason error) { 994 void PaymentRequest::OnError(PaymentErrorReason error) {
987 ExceptionCode ec = kUnknownError; 995 ExceptionCode ec = kUnknownError;
988 String message; 996 String message;
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
1080 complete_resolver_.Clear(); 1088 complete_resolver_.Clear();
1081 show_resolver_.Clear(); 1089 show_resolver_.Clear();
1082 abort_resolver_.Clear(); 1090 abort_resolver_.Clear();
1083 can_make_payment_resolver_.Clear(); 1091 can_make_payment_resolver_.Clear();
1084 if (client_binding_.is_bound()) 1092 if (client_binding_.is_bound())
1085 client_binding_.Close(); 1093 client_binding_.Close();
1086 payment_provider_.reset(); 1094 payment_provider_.reset();
1087 } 1095 }
1088 1096
1089 } // namespace blink 1097 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698