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

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

Issue 2473533002: Make NFC.cpp use JSON::Stringify (Closed)
Patch Set: Fix logic error Created 4 years, 1 month 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
« no previous file with comments | « third_party/WebKit/Source/modules/nfc/NFC.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/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 330 matching lines...) Expand 10 before | Expand all | Expand 10 after
341 String errorMessage; 341 String errorMessage;
342 if (!PaymentsValidators::isValidErrorMsgFormat(details.error(), 342 if (!PaymentsValidators::isValidErrorMsgFormat(details.error(),
343 &errorMessage)) { 343 &errorMessage)) {
344 exceptionState.throwTypeError(errorMessage); 344 exceptionState.throwTypeError(errorMessage);
345 } 345 }
346 346
347 return keepShippingOptions; 347 return keepShippingOptions;
348 } 348 }
349 349
350 void validateAndConvertPaymentMethodData( 350 void validateAndConvertPaymentMethodData(
351 const HeapVector<PaymentMethodData>& paymentMethodData, 351 const HeapVector<PaymentMethodData>& paymentMethodDataVector,
352 Vector<PaymentRequest::MethodData>* methodData, 352 Vector<PaymentRequest::MethodData>* methodData,
353 ExceptionState& exceptionState) { 353 ExceptionState& exceptionState) {
354 if (paymentMethodData.isEmpty()) { 354 if (paymentMethodDataVector.isEmpty()) {
355 exceptionState.throwTypeError( 355 exceptionState.throwTypeError(
356 "Must specify at least one payment method identifier"); 356 "Must specify at least one payment method identifier");
357 return; 357 return;
358 } 358 }
359 359
360 for (const auto& pmd : paymentMethodData) { 360 for (const auto& paymentMethodData : paymentMethodDataVector) {
361 if (pmd.supportedMethods().isEmpty()) { 361 if (paymentMethodData.supportedMethods().isEmpty()) {
362 exceptionState.throwTypeError( 362 exceptionState.throwTypeError(
363 "Must specify at least one payment method identifier"); 363 "Must specify at least one payment method identifier");
364 return; 364 return;
365 } 365 }
366 366
367 String stringifiedData = ""; 367 String stringifiedData = "";
368 if (pmd.hasData() && !pmd.data().isEmpty()) { 368 if (paymentMethodData.hasData() && !paymentMethodData.data().isEmpty()) {
369 if (!pmd.data().v8Value()->IsObject() || 369 if (!paymentMethodData.data().v8Value()->IsObject() ||
370 pmd.data().v8Value()->IsArray()) { 370 paymentMethodData.data().v8Value()->IsArray()) {
371 exceptionState.throwTypeError( 371 exceptionState.throwTypeError(
372 "Data should be a JSON-serializable object"); 372 "Data should be a JSON-serializable object");
373 return; 373 return;
374 } 374 }
375 375
376 v8::MaybeLocal<v8::String> value = v8::JSON::Stringify( 376 v8::Local<v8::String> value;
377 pmd.data().context(), pmd.data().v8Value().As<v8::Object>()); 377 if (!v8::JSON::Stringify(
378 if (value.IsEmpty()) { 378 paymentMethodData.data().context(),
379 paymentMethodData.data().v8Value().As<v8::Object>())
380 .ToLocal(&value)) {
379 exceptionState.throwTypeError( 381 exceptionState.throwTypeError(
380 "Unable to parse payment method specific data"); 382 "Unable to parse payment method specific data");
381 return; 383 return;
382 } 384 }
383 stringifiedData = v8StringToWebCoreString<String>(value.ToLocalChecked(), 385 stringifiedData =
384 DoNotExternalize); 386 v8StringToWebCoreString<String>(value, DoNotExternalize);
385 } 387 }
386 methodData->append( 388 methodData->append(PaymentRequest::MethodData(
387 PaymentRequest::MethodData(pmd.supportedMethods(), stringifiedData)); 389 paymentMethodData.supportedMethods(), stringifiedData));
388 } 390 }
389 } 391 }
390 392
391 String getSelectedShippingOption(const PaymentDetails& details) { 393 String getSelectedShippingOption(const PaymentDetails& details) {
392 String result; 394 String result;
393 if (!details.hasShippingOptions()) 395 if (!details.hasShippingOptions())
394 return result; 396 return result;
395 397
396 for (int i = details.shippingOptions().size() - 1; i >= 0; --i) { 398 for (int i = details.shippingOptions().size() - 1; i >= 0; --i) {
397 if (details.shippingOptions()[i].hasSelected() && 399 if (details.shippingOptions()[i].hasSelected() &&
(...skipping 454 matching lines...) Expand 10 before | Expand all | Expand 10 after
852 m_completeTimer.stop(); 854 m_completeTimer.stop();
853 m_completeResolver.clear(); 855 m_completeResolver.clear();
854 m_showResolver.clear(); 856 m_showResolver.clear();
855 m_abortResolver.clear(); 857 m_abortResolver.clear();
856 if (m_clientBinding.is_bound()) 858 if (m_clientBinding.is_bound())
857 m_clientBinding.Close(); 859 m_clientBinding.Close();
858 m_paymentProvider.reset(); 860 m_paymentProvider.reset();
859 } 861 }
860 862
861 } // namespace blink 863 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/modules/nfc/NFC.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698