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

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

Issue 1994913002: PaymentRequest: Remove id attribute from PaymentItem. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 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 "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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 output->value = input.value(); 49 output->value = input.value();
50 return output; 50 return output;
51 } 51 }
52 }; 52 };
53 53
54 template <> 54 template <>
55 struct TypeConverter<PaymentItemPtr, blink::PaymentItem> { 55 struct TypeConverter<PaymentItemPtr, blink::PaymentItem> {
56 static PaymentItemPtr Convert(const blink::PaymentItem& input) 56 static PaymentItemPtr Convert(const blink::PaymentItem& input)
57 { 57 {
58 PaymentItemPtr output = PaymentItem::New(); 58 PaymentItemPtr output = PaymentItem::New();
59 output->id = input.id();
60 output->label = input.label(); 59 output->label = input.label();
61 output->amount = CurrencyAmount::From(input.amount()); 60 output->amount = CurrencyAmount::From(input.amount());
62 return output; 61 return output;
63 } 62 }
64 }; 63 };
65 64
66 template <> 65 template <>
67 struct TypeConverter<ShippingOptionPtr, blink::ShippingOption> { 66 struct TypeConverter<ShippingOptionPtr, blink::ShippingOption> {
68 static ShippingOptionPtr Convert(const blink::ShippingOption& input) 67 static ShippingOptionPtr Convert(const blink::ShippingOption& input)
69 { 68 {
(...skipping 27 matching lines...) Expand all
97 output->request_shipping = input.requestShipping(); 96 output->request_shipping = input.requestShipping();
98 return output; 97 return output;
99 } 98 }
100 }; 99 };
101 100
102 } // namespace mojo 101 } // namespace mojo
103 102
104 namespace blink { 103 namespace blink {
105 namespace { 104 namespace {
106 105
107 // Validates ShippingOption and PaymentItem dictionaries, which happen to have i dentical fields. 106 // Validates ShippingOption and PaymentItem dictionaries, which happen to have i dentical fields.
please use gerrit instead 2016/05/19 17:48:21 ..except for "id", which is present only in Shippi
zino 2016/05/19 19:11:40 Done.
108 template <typename T> 107 template <typename T>
109 void validateShippingOptionsOrPaymentItems(HeapVector<T> items, ExceptionState& exceptionState) 108 void validateShippingOptionsOrPaymentItems(HeapVector<T> items, ExceptionState& exceptionState)
110 { 109 {
111 String errorMessage; 110 String errorMessage;
112 for (const auto& item : items) { 111 for (const auto& item : items) {
113 if (!item.hasId() || item.id().isEmpty()) {
please use gerrit instead 2016/05/19 17:48:20 Move this clause into validateShippingOptionIds().
zino 2016/05/19 19:11:40 Done.
114 exceptionState.throwTypeError("Item id required");
115 return;
116 }
117
118 if (!item.hasLabel() || item.label().isEmpty()) { 112 if (!item.hasLabel() || item.label().isEmpty()) {
119 exceptionState.throwTypeError("Item label required"); 113 exceptionState.throwTypeError("Item label required");
120 return; 114 return;
121 } 115 }
122 116
123 if (!item.hasAmount()) { 117 if (!item.hasAmount()) {
124 exceptionState.throwTypeError("Currency amount required"); 118 exceptionState.throwTypeError("Currency amount required");
125 return; 119 return;
126 } 120 }
127 121
(...skipping 29 matching lines...) Expand all
157 if (details.items().isEmpty()) { 151 if (details.items().isEmpty()) {
158 exceptionState.throwTypeError("Must specify at least one item"); 152 exceptionState.throwTypeError("Must specify at least one item");
159 return; 153 return;
160 } 154 }
161 155
162 validateShippingOptionsOrPaymentItems(details.items(), exceptionState); 156 validateShippingOptionsOrPaymentItems(details.items(), exceptionState);
163 if (exceptionState.hadException()) 157 if (exceptionState.hadException())
164 return; 158 return;
165 159
166 if (details.hasShippingOptions()) 160 if (details.hasShippingOptions())
167 validateShippingOptionsOrPaymentItems(details.shippingOptions(), excepti onState); 161 validateShippingOptionsOrPaymentItems(details.shippingOptions(), excepti onState);
please use gerrit instead 2016/05/19 17:48:21 Also call validateShippingOptionIds() here.
zino 2016/05/19 19:11:40 Done.
168 } 162 }
169 163
170 } // namespace 164 } // namespace
171 165
172 PaymentRequest* PaymentRequest::create(ScriptState* scriptState, const Vector<St ring>& supportedMethods, const PaymentDetails& details, ExceptionState& exceptio nState) 166 PaymentRequest* PaymentRequest::create(ScriptState* scriptState, const Vector<St ring>& supportedMethods, const PaymentDetails& details, ExceptionState& exceptio nState)
173 { 167 {
174 return new PaymentRequest(scriptState, supportedMethods, details, PaymentOpt ions(), ScriptValue(), exceptionState); 168 return new PaymentRequest(scriptState, supportedMethods, details, PaymentOpt ions(), ScriptValue(), exceptionState);
175 } 169 }
176 170
177 PaymentRequest* PaymentRequest::create(ScriptState* scriptState, const Vector<St ring>& supportedMethods, const PaymentDetails& details, const PaymentOptions& op tions, ExceptionState& exceptionState) 171 PaymentRequest* PaymentRequest::create(ScriptState* scriptState, const Vector<St ring>& supportedMethods, const PaymentDetails& details, const PaymentOptions& op tions, ExceptionState& exceptionState)
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after
433 void PaymentRequest::clearResolversAndCloseMojoConnection() 427 void PaymentRequest::clearResolversAndCloseMojoConnection()
434 { 428 {
435 m_completeResolver.clear(); 429 m_completeResolver.clear();
436 m_showResolver.clear(); 430 m_showResolver.clear();
437 if (m_clientBinding.is_bound()) 431 if (m_clientBinding.is_bound())
438 m_clientBinding.Close(); 432 m_clientBinding.Close();
439 m_paymentProvider.reset(); 433 m_paymentProvider.reset();
440 } 434 }
441 435
442 } // namespace blink 436 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698