chromium/third_party/blink/renderer/modules/payments/payment_request.cc

// Copyright 2016 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "third_party/blink/renderer/modules/payments/payment_request.h"

#include <stddef.h>

#include <utility>

#include "base/functional/bind.h"
#include "base/location.h"
#include "base/logging.h"
#include "base/task/single_thread_task_runner.h"
#include "third_party/blink/public/mojom/devtools/console_message.mojom-blink.h"
#include "third_party/blink/public/mojom/permissions_policy/permissions_policy.mojom-blink.h"
#include "third_party/blink/public/mojom/use_counter/metrics/web_feature.mojom-blink.h"
#include "third_party/blink/public/platform/browser_interface_broker_proxy.h"
#include "third_party/blink/public/platform/platform.h"
#include "third_party/blink/public/platform/task_type.h"
#include "third_party/blink/renderer/bindings/core/v8/native_value_traits_impl.h"
#include "third_party/blink/renderer/bindings/core/v8/script_promise_resolver.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_string_resource.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_address_errors.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_android_pay_method_data.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_google_play_billing_method_data.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_payer_errors.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_payment_details_init.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_payment_details_modifier.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_payment_details_update.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_payment_item.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_payment_shipping_option.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_payment_validation_errors.h"
#include "third_party/blink/renderer/core/dom/document.h"
#include "third_party/blink/renderer/core/dom/dom_exception.h"
#include "third_party/blink/renderer/core/dom/events/event.h"
#include "third_party/blink/renderer/core/dom/events/event_queue.h"
#include "third_party/blink/renderer/core/event_type_names.h"
#include "third_party/blink/renderer/core/frame/csp/content_security_policy.h"
#include "third_party/blink/renderer/core/frame/frame_owner.h"
#include "third_party/blink/renderer/core/frame/local_dom_window.h"
#include "third_party/blink/renderer/core/frame/local_frame.h"
#include "third_party/blink/renderer/core/frame/settings.h"
#include "third_party/blink/renderer/core/frame/web_feature.h"
#include "third_party/blink/renderer/core/html/html_iframe_element.h"
#include "third_party/blink/renderer/core/inspector/console_message.h"
#include "third_party/blink/renderer/modules/event_target_modules_names.h"
#include "third_party/blink/renderer/modules/payments/payment_address.h"
#include "third_party/blink/renderer/modules/payments/payment_method_change_event.h"
#include "third_party/blink/renderer/modules/payments/payment_request_update_event.h"
#include "third_party/blink/renderer/modules/payments/payment_response.h"
#include "third_party/blink/renderer/modules/payments/payments_validators.h"
#include "third_party/blink/renderer/modules/payments/secure_payment_confirmation_helper.h"
#include "third_party/blink/renderer/modules/payments/update_payment_details_function.h"
#include "third_party/blink/renderer/platform/bindings/exception_state.h"
#include "third_party/blink/renderer/platform/bindings/script_state.h"
#include "third_party/blink/renderer/platform/heap/garbage_collected.h"
#include "third_party/blink/renderer/platform/instrumentation/use_counter.h"
#include "third_party/blink/renderer/platform/runtime_enabled_features.h"
#include "third_party/blink/renderer/platform/weborigin/reporting_disposition.h"
#include "third_party/blink/renderer/platform/wtf/functional.h"
#include "third_party/blink/renderer/platform/wtf/hash_set.h"
#include "third_party/blink/renderer/platform/wtf/text/string_builder.h"
#include "third_party/blink/renderer/platform/wtf/uuid.h"

namespace {

AddressErrors;
AddressErrorsPtr;
CanMakePaymentQueryResult;
HasEnrolledInstrumentQueryResult;
PayerErrors;
PayerErrorsPtr;
PaymentAddress;
PaymentAddressPtr;
PaymentCurrencyAmount;
PaymentCurrencyAmountPtr;
PaymentDetailsModifierPtr;
PaymentDetailsPtr;
PaymentErrorReason;
PaymentItemPtr;
PaymentMethodDataPtr;
PaymentOptionsPtr;
PaymentResponsePtr;
PaymentShippingOptionPtr;
PaymentShippingType;
PaymentValidationErrors;
PaymentValidationErrorsPtr;

const char kHasEnrolledInstrumentDebugName[] =;
const char kGooglePayMethod[] =;
const char kGooglePayAuthenticationMethod[] =;
const char kAndroidPayMethod[] =;
const char kGooglePlayBillingMethod[] =;
const char kUnknownCurrency[] =;
const char kAppStoreBillingLabelPlaceHolder[] =;
const char kSecurePaymentConfirmationMethod[] =;

}  // namespace

namespace mojo {

template <>
struct TypeConverter<PaymentCurrencyAmountPtr, blink::PaymentCurrencyAmount> {};

template <>
struct TypeConverter<PaymentItemPtr, blink::PaymentItem> {};

template <>
struct TypeConverter<PaymentShippingOptionPtr, blink::PaymentShippingOption> {};

template <>
struct TypeConverter<PaymentOptionsPtr, blink::PaymentOptions> {};

template <>
struct TypeConverter<PaymentValidationErrorsPtr,
                     blink::PaymentValidationErrors> {};

template <>
struct TypeConverter<PayerErrorsPtr, blink::PayerErrors> {};

template <>
struct TypeConverter<AddressErrorsPtr, blink::AddressErrors> {};

}  // namespace mojo

namespace blink {
namespace {

// Validates ShippingOption or PaymentItem, which happen to have identical
// fields, except for "id", which is present only in ShippingOption.
template <typename T>
void ValidateShippingOptionOrPaymentItem(const T* item,
                                         const String& item_name,
                                         ExecutionContext& execution_context,
                                         ExceptionState& exception_state) {}

bool IsAppStoreBillingMethod(const StringView& billing_method) {}

bool RequestingOnlyAppStoreBillingMethods(
    const Vector<payments::mojom::blink::PaymentMethodDataPtr>& method_data) {}

void ValidateAndConvertDisplayItems(
    const HeapVector<Member<PaymentItem>>& input,
    const String& item_names,
    Vector<PaymentItemPtr>& output,
    ExecutionContext& execution_context,
    ExceptionState& exception_state) {}

// Validates and converts |input| shipping options into |output|. Throws an
// exception if the data is not valid, except for duplicate identifiers, which
// returns an empty |output| instead of throwing an exception. There's no need
// to clear |output| when an exception is thrown, because the caller takes care
// of deleting |output|.
void ValidateAndConvertShippingOptions(
    const HeapVector<Member<PaymentShippingOption>>& input,
    Vector<PaymentShippingOptionPtr>& output,
    String& shipping_option_output,
    ExecutionContext& execution_context,
    ExceptionState& exception_state) {}

void ValidateAndConvertTotal(const PaymentItem* input,
                             const String& item_name,
                             PaymentItemPtr& output,
                             ExecutionContext& execution_context,
                             ExceptionState& exception_state) {}

// Parses Android Pay data to avoid parsing JSON in the browser.
void SetAndroidPayMethodData(v8::Isolate* isolate,
                             const ScriptValue& input,
                             PaymentMethodDataPtr& output,
                             ExceptionState& exception_state) {}

void MeasureGooglePlayBillingPriceChangeConfirmation(
    ExecutionContext& execution_context,
    const ScriptValue& input,
    ExceptionState& exception_state) {}

void StringifyAndParseMethodSpecificData(ExecutionContext& execution_context,
                                         const String& supported_method,
                                         const ScriptValue& input,
                                         PaymentMethodDataPtr& output,
                                         ExceptionState& exception_state) {}

void ValidateAndConvertPaymentDetailsModifiers(
    const HeapVector<Member<PaymentDetailsModifier>>& input,
    Vector<PaymentDetailsModifierPtr>& output,
    ExecutionContext& execution_context,
    ExceptionState& exception_state) {}

void ValidateAndConvertPaymentDetailsBase(const PaymentDetailsBase* input,
                                          const PaymentOptions* options,
                                          PaymentDetailsPtr& output,
                                          String& shipping_option_output,
                                          ExecutionContext& execution_context,
                                          ExceptionState& exception_state) {}

PaymentItemPtr CreateTotalPlaceHolderForAppStoreBilling(
    ExecutionContext& execution_context) {}

void ValidateAndConvertPaymentDetailsInit(const PaymentDetailsInit* input,
                                          const PaymentOptions* options,
                                          PaymentDetailsPtr& output,
                                          String& shipping_option_output,
                                          bool ignore_total,
                                          ExecutionContext& execution_context,
                                          ExceptionState& exception_state) {}

void ValidateAndConvertPaymentDetailsUpdate(const PaymentDetailsUpdate* input,
                                            const PaymentOptions* options,
                                            PaymentDetailsPtr& output,
                                            String& shipping_option_output,
                                            bool ignore_total,
                                            ExecutionContext& execution_context,
                                            ExceptionState& exception_state) {}

// Checks whether Content Security Policy (CSP) allows a connection to the
// given `url`. If it does not, then a CSP violation will be reported in the
// developer console.
bool CSPAllowsConnectToSource(const KURL& url,
                              const KURL& url_before_redirects,
                              bool did_follow_redirect,
                              ExecutionContext& context) {}

void ValidateAndConvertPaymentMethodData(
    const HeapVector<Member<PaymentMethodData>>& input,
    const PaymentOptions* options,
    Vector<payments::mojom::blink::PaymentMethodDataPtr>& output,
    HashSet<String>& method_names,
    ExecutionContext& execution_context,
    ExceptionState& exception_state) {}

bool AllowedToUsePaymentRequest(ExecutionContext* execution_context) {}

void WarnIgnoringQueryQuotaForCanMakePayment(
    ExecutionContext& execution_context,
    const char* method_name) {}

// Records metrics for an activationless Show() call based on the request
// method.
void RecordActivationlessShow(ExecutionContext* execution_context,
                              const HashSet<String>& method_names) {}

}  // namespace

PaymentRequest* PaymentRequest::Create(
    ExecutionContext* execution_context,
    const HeapVector<Member<PaymentMethodData>>& method_data,
    const PaymentDetailsInit* details,
    ExceptionState& exception_state) {}

PaymentRequest* PaymentRequest::Create(
    ExecutionContext* execution_context,
    const HeapVector<Member<PaymentMethodData>>& method_data,
    const PaymentDetailsInit* details,
    const PaymentOptions* options,
    ExceptionState& exception_state) {}

PaymentRequest::~PaymentRequest() = default;

ScriptPromise<PaymentResponse> PaymentRequest::show(
    ScriptState* script_state,
    ExceptionState& exception_state) {}

ScriptPromise<PaymentResponse> PaymentRequest::show(
    ScriptState* script_state,
    ScriptPromiseUntyped details_promise,
    ExceptionState& exception_state) {}

ScriptPromise<IDLUndefined> PaymentRequest::abort(
    ScriptState* script_state,
    ExceptionState& exception_state) {}

ScriptPromise<IDLBoolean> PaymentRequest::canMakePayment(
    ScriptState* script_state,
    ExceptionState& exception_state) {}

ScriptPromise<IDLBoolean> PaymentRequest::hasEnrolledInstrument(
    ScriptState* script_state,
    ExceptionState& exception_state) {}

bool PaymentRequest::HasPendingActivity() const {}

const AtomicString& PaymentRequest::InterfaceName() const {}

ExecutionContext* PaymentRequest::GetExecutionContext() const {}

ScriptPromise<IDLUndefined> PaymentRequest::Retry(
    ScriptState* script_state,
    const PaymentValidationErrors* errors,
    ExceptionState& exception_state) {}

ScriptPromise<IDLUndefined> PaymentRequest::Complete(
    ScriptState* script_state,
    PaymentComplete result,
    ExceptionState& exception_state) {}

void PaymentRequest::OnUpdatePaymentDetails(
    const ScriptValue& details_script_value) {}

void PaymentRequest::OnUpdatePaymentDetailsFailure(const String& error) {}

bool PaymentRequest::IsInteractive() const {}

void PaymentRequest::Trace(Visitor* visitor) const {}

void PaymentRequest::OnCompleteTimeoutForTesting() {}

void PaymentRequest::OnUpdatePaymentDetailsTimeoutForTesting() {}

void PaymentRequest::OnConnectionError() {}

PaymentRequest::PaymentRequest(
    ExecutionContext* execution_context,
    const HeapVector<Member<PaymentMethodData>>& method_data,
    const PaymentDetailsInit* details,
    const PaymentOptions* options,
    mojo::PendingRemote<payments::mojom::blink::PaymentRequest>
        mock_payment_provider,
    ExceptionState& exception_state)
    :{}

void PaymentRequest::ContextDestroyed() {}

void PaymentRequest::OnPaymentMethodChange(const String& method_name,
                                           const String& stringified_details) {}

void PaymentRequest::OnShippingAddressChange(PaymentAddressPtr address) {}

void PaymentRequest::OnShippingOptionChange(const String& shipping_option_id) {}

void PaymentRequest::OnPayerDetailChange(
    payments::mojom::blink::PayerDetailPtr detail) {}

void PaymentRequest::OnPaymentResponse(PaymentResponsePtr response) {}

void PaymentRequest::OnError(PaymentErrorReason error,
                             const String& error_message) {}

void PaymentRequest::OnComplete() {}

void PaymentRequest::OnAbort(bool aborted_successfully) {}

void PaymentRequest::OnCanMakePayment(CanMakePaymentQueryResult result) {}

void PaymentRequest::OnHasEnrolledInstrument(
    HasEnrolledInstrumentQueryResult result) {}

void PaymentRequest::WarnNoFavicon() {}

void PaymentRequest::AllowConnectToSource(
    const KURL& url,
    const KURL& url_before_redirects,
    bool did_follow_redirect,
    AllowConnectToSourceCallback response_callback) {}

void PaymentRequest::OnCompleteTimeout(TimerBase*) {}

void PaymentRequest::OnUpdatePaymentDetailsTimeout(TimerBase*) {}

void PaymentRequest::ClearResolversAndCloseMojoConnection() {}

ScriptPromiseResolverBase* PaymentRequest::GetPendingAcceptPromiseResolver()
    const {}

void PaymentRequest::DispatchPaymentRequestUpdateEvent(
    EventTarget* event_target,
    PaymentRequestUpdateEvent* event) {}

}  // namespace blink