2 * Copyright (C) 2018 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23 * THE POSSIBILITY OF SUCH DAMAGE.
27 #include "MerchantValidationEvent.h"
29 #if ENABLE(PAYMENT_REQUEST)
32 #include "PaymentRequest.h"
36 Ref<MerchantValidationEvent> MerchantValidationEvent::create(const AtomString& type, const String& methodName, URL&& validationURL)
38 return adoptRef(*new MerchantValidationEvent(type, methodName, WTFMove(validationURL)));
41 ExceptionOr<Ref<MerchantValidationEvent>> MerchantValidationEvent::create(Document& document, const AtomString& type, Init&& eventInit)
43 URL validationURL { document.url(), eventInit.validationURL };
44 if (!validationURL.isValid())
45 return Exception { TypeError };
47 auto methodName = WTFMove(eventInit.methodName);
48 if (!methodName.isEmpty()) {
49 auto validatedMethodName = convertAndValidatePaymentMethodIdentifier(methodName);
50 if (!validatedMethodName)
51 return Exception { RangeError, makeString('"', methodName, "\" is an invalid payment method identifier.") };
54 return adoptRef(*new MerchantValidationEvent(type, WTFMove(methodName), WTFMove(validationURL), WTFMove(eventInit)));
57 MerchantValidationEvent::MerchantValidationEvent(const AtomString& type, const String& methodName, URL&& validationURL)
58 : Event { type, Event::CanBubble::No, Event::IsCancelable::No }
59 , m_methodName { methodName }
60 , m_validationURL { WTFMove(validationURL) }
63 ASSERT(m_validationURL.isValid());
66 MerchantValidationEvent::MerchantValidationEvent(const AtomString& type, String&& methodName, URL&& validationURL, Init&& eventInit)
67 : Event { type, WTFMove(eventInit), IsTrusted::No }
68 , m_methodName { WTFMove(methodName) }
69 , m_validationURL { WTFMove(validationURL) }
72 ASSERT(m_validationURL.isValid());
75 EventInterface MerchantValidationEvent::eventInterface() const
77 return MerchantValidationEventInterfaceType;
80 ExceptionOr<void> MerchantValidationEvent::complete(Ref<DOMPromise>&& merchantSessionPromise)
83 return Exception { InvalidStateError };
86 return Exception { InvalidStateError };
88 auto exception = downcast<PaymentRequest>(target())->completeMerchantValidation(*this, WTFMove(merchantSessionPromise));
89 if (exception.hasException())
90 return exception.releaseException();
96 } // namespace WebCore
98 #endif // ENABLE(PAYMENT_REQUEST)