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/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 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
354 | 354 |
355 for (int i = details.shippingOptions().size() - 1; i >= 0; --i) { | 355 for (int i = details.shippingOptions().size() - 1; i >= 0; --i) { |
356 if (details.shippingOptions()[i].hasSelected() && details.shippingOption s()[i].selected()) { | 356 if (details.shippingOptions()[i].hasSelected() && details.shippingOption s()[i].selected()) { |
357 return details.shippingOptions()[i].id(); | 357 return details.shippingOptions()[i].id(); |
358 } | 358 } |
359 } | 359 } |
360 | 360 |
361 return result; | 361 return result; |
362 } | 362 } |
363 | 363 |
364 String getValidShippingType(const String& shippingType) | |
365 { | |
366 const char* validValues[] = { | |
367 "shipping", | |
368 "delivery", | |
369 "pickup", | |
370 }; | |
please use gerrit instead
2016/09/18 16:54:56
Is this allocated on the stack? We would not want
zino
2016/09/18 18:57:40
Good point.
I changed it to static const char* con
| |
371 for (size_t i = 0; i < WTF_ARRAY_LENGTH(validValues); i++) { | |
372 if (shippingType == validValues[i]) | |
373 return shippingType; | |
374 } | |
375 return validValues[0]; | |
376 } | |
377 | |
364 } // namespace | 378 } // namespace |
365 | 379 |
366 PaymentRequest* PaymentRequest::create(ScriptState* scriptState, const HeapVecto r<PaymentMethodData>& methodData, const PaymentDetails& details, ExceptionState& exceptionState) | 380 PaymentRequest* PaymentRequest::create(ScriptState* scriptState, const HeapVecto r<PaymentMethodData>& methodData, const PaymentDetails& details, ExceptionState& exceptionState) |
367 { | 381 { |
368 return new PaymentRequest(scriptState, methodData, details, PaymentOptions() , exceptionState); | 382 return new PaymentRequest(scriptState, methodData, details, PaymentOptions() , exceptionState); |
369 } | 383 } |
370 | 384 |
371 PaymentRequest* PaymentRequest::create(ScriptState* scriptState, const HeapVecto r<PaymentMethodData>& methodData, const PaymentDetails& details, const PaymentOp tions& options, ExceptionState& exceptionState) | 385 PaymentRequest* PaymentRequest::create(ScriptState* scriptState, const HeapVecto r<PaymentMethodData>& methodData, const PaymentDetails& details, const PaymentOp tions& options, ExceptionState& exceptionState) |
372 { | 386 { |
373 return new PaymentRequest(scriptState, methodData, details, options, excepti onState); | 387 return new PaymentRequest(scriptState, methodData, details, options, excepti onState); |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
512 | 526 |
513 if (!scriptState->domWindow()->frame() || !scriptState->domWindow()->frame() ->isMainFrame()) { | 527 if (!scriptState->domWindow()->frame() || !scriptState->domWindow()->frame() ->isMainFrame()) { |
514 exceptionState.throwSecurityError("Must be in a top-level browsing conte xt"); | 528 exceptionState.throwSecurityError("Must be in a top-level browsing conte xt"); |
515 return; | 529 return; |
516 } | 530 } |
517 | 531 |
518 validatePaymentDetails(details, exceptionState); | 532 validatePaymentDetails(details, exceptionState); |
519 if (exceptionState.hadException()) | 533 if (exceptionState.hadException()) |
520 return; | 534 return; |
521 | 535 |
522 if (m_options.requestShipping()) | 536 if (m_options.requestShipping()) { |
523 m_shippingOption = getSelectedShippingOption(details); | 537 m_shippingOption = getSelectedShippingOption(details); |
538 m_shippingType = getValidShippingType(m_options.shippingType()); | |
539 } | |
524 | 540 |
525 scriptState->domWindow()->frame()->interfaceProvider()->getInterface(mojo::G etProxy(&m_paymentProvider)); | 541 scriptState->domWindow()->frame()->interfaceProvider()->getInterface(mojo::G etProxy(&m_paymentProvider)); |
526 m_paymentProvider.set_connection_error_handler(convertToBaseCallback(WTF::bi nd(&PaymentRequest::OnError, wrapWeakPersistent(this), mojom::blink::PaymentErro rReason::UNKNOWN))); | 542 m_paymentProvider.set_connection_error_handler(convertToBaseCallback(WTF::bi nd(&PaymentRequest::OnError, wrapWeakPersistent(this), mojom::blink::PaymentErro rReason::UNKNOWN))); |
527 m_paymentProvider->Init(m_clientBinding.CreateInterfacePtrAndBind(), mojo::W TFArray<mojom::blink::PaymentMethodDataPtr>::From(validatedMethodData), mojom::b link::PaymentDetails::From(details), mojom::blink::PaymentOptions::From(m_option s)); | 543 m_paymentProvider->Init(m_clientBinding.CreateInterfacePtrAndBind(), mojo::W TFArray<mojom::blink::PaymentMethodDataPtr>::From(validatedMethodData), mojom::b link::PaymentDetails::From(details), mojom::blink::PaymentOptions::From(m_option s)); |
528 } | 544 } |
529 | 545 |
530 void PaymentRequest::contextDestroyed() | 546 void PaymentRequest::contextDestroyed() |
531 { | 547 { |
532 clearResolversAndCloseMojoConnection(); | 548 clearResolversAndCloseMojoConnection(); |
533 } | 549 } |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
696 m_completeTimer.stop(); | 712 m_completeTimer.stop(); |
697 m_completeResolver.clear(); | 713 m_completeResolver.clear(); |
698 m_showResolver.clear(); | 714 m_showResolver.clear(); |
699 m_abortResolver.clear(); | 715 m_abortResolver.clear(); |
700 if (m_clientBinding.is_bound()) | 716 if (m_clientBinding.is_bound()) |
701 m_clientBinding.Close(); | 717 m_clientBinding.Close(); |
702 m_paymentProvider.reset(); | 718 m_paymentProvider.reset(); |
703 } | 719 } |
704 | 720 |
705 } // namespace blink | 721 } // namespace blink |
OLD | NEW |