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

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

Issue 2541663003: Remove [ConstructorCallWith=ScriptState] from Payments (Closed)
Patch Set: temp Created 4 years 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/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 478 matching lines...) Expand 10 before | Expand all | Expand 10 after
489 return allowedToUsePaymentRequest(frame->tree().parent()); 489 return allowedToUsePaymentRequest(frame->tree().parent());
490 } 490 }
491 491
492 // 4. Return false. 492 // 4. Return false.
493 return false; 493 return false;
494 } 494 }
495 495
496 } // namespace 496 } // namespace
497 497
498 PaymentRequest* PaymentRequest::create( 498 PaymentRequest* PaymentRequest::create(
499 ScriptState* scriptState, 499 Document& document,
500 const HeapVector<PaymentMethodData>& methodData, 500 const HeapVector<PaymentMethodData>& methodData,
501 const PaymentDetails& details, 501 const PaymentDetails& details,
502 ExceptionState& exceptionState) { 502 ExceptionState& exceptionState) {
503 return new PaymentRequest(scriptState, methodData, details, PaymentOptions(), 503 return new PaymentRequest(document, methodData, details, PaymentOptions(),
504 exceptionState); 504 exceptionState);
505 } 505 }
506 506
507 PaymentRequest* PaymentRequest::create( 507 PaymentRequest* PaymentRequest::create(
508 ScriptState* scriptState, 508 Document& document,
509 const HeapVector<PaymentMethodData>& methodData, 509 const HeapVector<PaymentMethodData>& methodData,
510 const PaymentDetails& details, 510 const PaymentDetails& details,
511 const PaymentOptions& options, 511 const PaymentOptions& options,
512 ExceptionState& exceptionState) { 512 ExceptionState& exceptionState) {
513 return new PaymentRequest(scriptState, methodData, details, options, 513 return new PaymentRequest(document, methodData, details, options,
514 exceptionState); 514 exceptionState);
515 } 515 }
516 516
517 PaymentRequest::~PaymentRequest() {} 517 PaymentRequest::~PaymentRequest() {}
518 518
519 ScriptPromise PaymentRequest::show(ScriptState* scriptState) { 519 ScriptPromise PaymentRequest::show(ScriptState* scriptState) {
520 if (!m_paymentProvider.is_bound() || m_showResolver) 520 if (!m_paymentProvider.is_bound() || m_showResolver)
521 return ScriptPromise::rejectWithDOMException( 521 return ScriptPromise::rejectWithDOMException(
522 scriptState, 522 scriptState,
523 DOMException::create(InvalidStateError, "Already called show() once")); 523 DOMException::create(InvalidStateError, "Already called show() once"));
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
656 visitor->trace(m_canMakeActivePaymentResolver); 656 visitor->trace(m_canMakeActivePaymentResolver);
657 EventTargetWithInlineData::trace(visitor); 657 EventTargetWithInlineData::trace(visitor);
658 ContextLifecycleObserver::trace(visitor); 658 ContextLifecycleObserver::trace(visitor);
659 } 659 }
660 660
661 void PaymentRequest::onCompleteTimeoutForTesting() { 661 void PaymentRequest::onCompleteTimeoutForTesting() {
662 m_completeTimer.stop(); 662 m_completeTimer.stop();
663 onCompleteTimeout(0); 663 onCompleteTimeout(0);
664 } 664 }
665 665
666 PaymentRequest::PaymentRequest(ScriptState* scriptState, 666 PaymentRequest::PaymentRequest(Document& document,
667 const HeapVector<PaymentMethodData>& methodData, 667 const HeapVector<PaymentMethodData>& methodData,
668 const PaymentDetails& details, 668 const PaymentDetails& details,
669 const PaymentOptions& options, 669 const PaymentOptions& options,
670 ExceptionState& exceptionState) 670 ExceptionState& exceptionState)
671 : ContextLifecycleObserver(scriptState->getExecutionContext()), 671 : ContextLifecycleObserver(&document),
672 ActiveScriptWrappable(this), 672 ActiveScriptWrappable(this),
673 m_options(options), 673 m_options(options),
674 m_clientBinding(this), 674 m_clientBinding(this),
675 m_completeTimer(this, &PaymentRequest::onCompleteTimeout) { 675 m_completeTimer(this, &PaymentRequest::onCompleteTimeout) {
676 Vector<payments::mojom::blink::PaymentMethodDataPtr> validatedMethodData; 676 Vector<payments::mojom::blink::PaymentMethodDataPtr> validatedMethodData;
677 validateAndConvertPaymentMethodData(methodData, validatedMethodData, 677 validateAndConvertPaymentMethodData(methodData, validatedMethodData,
678 exceptionState); 678 exceptionState);
679 if (exceptionState.hadException()) 679 if (exceptionState.hadException())
680 return; 680 return;
681 681
682 if (!scriptState->getExecutionContext()->isSecureContext()) { 682 if (!document.isSecureContext()) {
683 exceptionState.throwSecurityError("Must be in a secure context"); 683 exceptionState.throwSecurityError("Must be in a secure context");
684 return; 684 return;
685 } 685 }
686 686
687 if (!allowedToUsePaymentRequest(scriptState->domWindow()->frame())) { 687 if (!allowedToUsePaymentRequest(document.frame())) {
688 exceptionState.throwSecurityError( 688 exceptionState.throwSecurityError(
689 RuntimeEnabledFeatures::paymentRequestIFrameEnabled() 689 RuntimeEnabledFeatures::paymentRequestIFrameEnabled()
690 ? "Must be in a top-level browsing context or an iframe needs to " 690 ? "Must be in a top-level browsing context or an iframe needs to "
691 "specify 'allowpaymentrequest' explicitly" 691 "specify 'allowpaymentrequest' explicitly"
692 : "Must be in a top-level browsing context"); 692 : "Must be in a top-level browsing context");
693 return; 693 return;
694 } 694 }
695 695
696 PaymentDetailsPtr validatedDetails = 696 PaymentDetailsPtr validatedDetails =
697 payments::mojom::blink::PaymentDetails::New(); 697 payments::mojom::blink::PaymentDetails::New();
698 validateAndConvertPaymentDetails(details, m_options.requestShipping(), 698 validateAndConvertPaymentDetails(details, m_options.requestShipping(),
699 validatedDetails, m_shippingOption, 699 validatedDetails, m_shippingOption,
700 exceptionState); 700 exceptionState);
701 if (exceptionState.hadException()) 701 if (exceptionState.hadException())
702 return; 702 return;
703 703
704 if (details.hasError()) { 704 if (details.hasError()) {
705 exceptionState.throwTypeError("Error message not allowed in constructor"); 705 exceptionState.throwTypeError("Error message not allowed in constructor");
706 return; 706 return;
707 } 707 }
708 708
709 if (m_options.requestShipping()) 709 if (m_options.requestShipping())
710 m_shippingType = getValidShippingType(m_options.shippingType()); 710 m_shippingType = getValidShippingType(m_options.shippingType());
711 711
712 scriptState->domWindow()->frame()->interfaceProvider()->getInterface( 712 document.frame()->interfaceProvider()->getInterface(
713 mojo::GetProxy(&m_paymentProvider)); 713 mojo::GetProxy(&m_paymentProvider));
714 m_paymentProvider.set_connection_error_handler(convertToBaseCallback( 714 m_paymentProvider.set_connection_error_handler(convertToBaseCallback(
715 WTF::bind(&PaymentRequest::OnError, wrapWeakPersistent(this), 715 WTF::bind(&PaymentRequest::OnError, wrapWeakPersistent(this),
716 PaymentErrorReason::UNKNOWN))); 716 PaymentErrorReason::UNKNOWN)));
717 m_paymentProvider->Init( 717 m_paymentProvider->Init(
718 m_clientBinding.CreateInterfacePtrAndBind(), 718 m_clientBinding.CreateInterfacePtrAndBind(),
719 std::move(validatedMethodData), std::move(validatedDetails), 719 std::move(validatedMethodData), std::move(validatedDetails),
720 payments::mojom::blink::PaymentOptions::From(m_options)); 720 payments::mojom::blink::PaymentOptions::From(m_options));
721 } 721 }
722 722
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
916 m_completeResolver.clear(); 916 m_completeResolver.clear();
917 m_showResolver.clear(); 917 m_showResolver.clear();
918 m_abortResolver.clear(); 918 m_abortResolver.clear();
919 m_canMakeActivePaymentResolver.clear(); 919 m_canMakeActivePaymentResolver.clear();
920 if (m_clientBinding.is_bound()) 920 if (m_clientBinding.is_bound())
921 m_clientBinding.Close(); 921 m_clientBinding.Close();
922 m_paymentProvider.reset(); 922 m_paymentProvider.reset();
923 } 923 }
924 924
925 } // namespace blink 925 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698