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

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

Issue 2117213003: Duplicate payment method identifiers in methodData and details.modififiers should throw TypeError. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 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"
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/PaymentAddress.h"
19 #include "modules/payments/PaymentItem.h" 19 #include "modules/payments/PaymentItem.h"
20 #include "modules/payments/PaymentRequestUpdateEvent.h" 20 #include "modules/payments/PaymentRequestUpdateEvent.h"
21 #include "modules/payments/PaymentResponse.h" 21 #include "modules/payments/PaymentResponse.h"
22 #include "modules/payments/PaymentShippingOption.h" 22 #include "modules/payments/PaymentShippingOption.h"
23 #include "modules/payments/PaymentsValidators.h" 23 #include "modules/payments/PaymentsValidators.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"
please use gerrit instead 2016/07/06 07:31:56 #include "wtf/HashSet.h"
pals 2016/07/07 05:14:13 Done.
28 #include <utility> 28 #include <utility>
29 29
30 namespace mojo { 30 namespace mojo {
31 31
32 using blink::mojom::blink::PaymentCurrencyAmount; 32 using blink::mojom::blink::PaymentCurrencyAmount;
33 using blink::mojom::blink::PaymentCurrencyAmountPtr; 33 using blink::mojom::blink::PaymentCurrencyAmountPtr;
34 using blink::mojom::blink::PaymentDetails; 34 using blink::mojom::blink::PaymentDetails;
35 using blink::mojom::blink::PaymentDetailsModifier; 35 using blink::mojom::blink::PaymentDetailsModifier;
36 using blink::mojom::blink::PaymentDetailsModifierPtr; 36 using blink::mojom::blink::PaymentDetailsModifierPtr;
37 using blink::mojom::blink::PaymentDetailsPtr; 37 using blink::mojom::blink::PaymentDetailsPtr;
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 } 217 }
218 } 218 }
219 219
220 void validatePaymentDetailsModifiers(const HeapVector<PaymentDetailsModifier>& m odifiers, ExceptionState& exceptionState) 220 void validatePaymentDetailsModifiers(const HeapVector<PaymentDetailsModifier>& m odifiers, ExceptionState& exceptionState)
221 { 221 {
222 if (modifiers.isEmpty()) { 222 if (modifiers.isEmpty()) {
223 exceptionState.throwTypeError("Must specify at least one payment details modifier"); 223 exceptionState.throwTypeError("Must specify at least one payment details modifier");
224 return; 224 return;
225 } 225 }
226 226
227 HashSet<String> uniqueMethods;
227 for (const auto& modifier : modifiers) { 228 for (const auto& modifier : modifiers) {
228 if (modifier.supportedMethods().isEmpty()) { 229 if (modifier.supportedMethods().isEmpty()) {
229 exceptionState.throwTypeError("Must specify at least one payment met hod identifier"); 230 exceptionState.throwTypeError("Must specify at least one payment met hod identifier");
230 return; 231 return;
232 } else {
please use gerrit instead 2016/07/06 07:31:56 No need for "else", because the previous clause re
pals 2016/07/07 05:14:13 Done.
233 for (const auto& method : modifier.supportedMethods()) {
234 if (uniqueMethods.contains(method)) {
235 exceptionState.throwTypeError("Duplicate payment method iden tifiers are not allowed");
236 return;
237 }
238 uniqueMethods.add(method);
239 }
231 } 240 }
232 241
233 if (modifier.hasTotal()) { 242 if (modifier.hasTotal()) {
234 validateShippingOptionOrPaymentItem(modifier.total(), exceptionState ); 243 validateShippingOptionOrPaymentItem(modifier.total(), exceptionState );
235 if (exceptionState.hadException()) 244 if (exceptionState.hadException())
236 return; 245 return;
237 246
238 if (modifier.total().amount().value()[0] == '-') { 247 if (modifier.total().amount().value()[0] == '-') {
239 exceptionState.throwTypeError("Total amount value should be non- negative"); 248 exceptionState.throwTypeError("Total amount value should be non- negative");
240 return; 249 return;
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
282 } 291 }
283 } 292 }
284 293
285 void validateAndConvertPaymentMethodData(const HeapVector<PaymentMethodData>& pa ymentMethodData, Vector<PaymentRequest::MethodData>* methodData, ExceptionState& exceptionState) 294 void validateAndConvertPaymentMethodData(const HeapVector<PaymentMethodData>& pa ymentMethodData, Vector<PaymentRequest::MethodData>* methodData, ExceptionState& exceptionState)
286 { 295 {
287 if (paymentMethodData.isEmpty()) { 296 if (paymentMethodData.isEmpty()) {
288 exceptionState.throwTypeError("Must specify at least one payment method identifier"); 297 exceptionState.throwTypeError("Must specify at least one payment method identifier");
289 return; 298 return;
290 } 299 }
291 300
301 HashSet<String> uniqueMethods;
292 for (const auto& pmd : paymentMethodData) { 302 for (const auto& pmd : paymentMethodData) {
293 if (pmd.supportedMethods().isEmpty()) { 303 if (pmd.supportedMethods().isEmpty()) {
294 exceptionState.throwTypeError("Must specify at least one payment met hod identifier"); 304 exceptionState.throwTypeError("Must specify at least one payment met hod identifier");
295 return; 305 return;
306 } else {
please use gerrit instead 2016/07/06 07:31:56 Ditto.
pals 2016/07/07 05:14:13 Done.
307 for (const auto& method : pmd.supportedMethods()) {
308 if (uniqueMethods.contains(method)) {
309 exceptionState.throwTypeError("Duplicate payment method iden tifiers are not allowed");
310 return;
311 }
312 uniqueMethods.add(method);
313 }
296 } 314 }
297 315
298 String stringifiedData = ""; 316 String stringifiedData = "";
299 if (pmd.hasData() && !pmd.data().isEmpty()) { 317 if (pmd.hasData() && !pmd.data().isEmpty()) {
300 RefPtr<JSONValue> value = toJSONValue(pmd.data().context(), pmd.data ().v8Value()); 318 RefPtr<JSONValue> value = toJSONValue(pmd.data().context(), pmd.data ().v8Value());
301 if (!value) { 319 if (!value) {
302 exceptionState.throwTypeError("Unable to parse payment method sp ecific data"); 320 exceptionState.throwTypeError("Unable to parse payment method sp ecific data");
303 return; 321 return;
304 } 322 }
305 if (!value->isNull()) { 323 if (!value->isNull()) {
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after
607 { 625 {
608 m_completeResolver.clear(); 626 m_completeResolver.clear();
609 m_showResolver.clear(); 627 m_showResolver.clear();
610 m_abortResolver.clear(); 628 m_abortResolver.clear();
611 if (m_clientBinding.is_bound()) 629 if (m_clientBinding.is_bound())
612 m_clientBinding.Close(); 630 m_clientBinding.Close();
613 m_paymentProvider.reset(); 631 m_paymentProvider.reset();
614 } 632 }
615 633
616 } // namespace blink 634 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698