/* * Copyright (C) 2016-2018 Apple Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF * THE POSSIBILITY OF SUCH DAMAGE. */ #import "config.h" #import "WebCoreArgumentCoders.h" #if ENABLE(APPLE_PAY) #import "ArgumentCodersCocoa.h" #import "DataReference.h" #import #import #import namespace IPC { using namespace WebCore; void ArgumentCoder::encode(Encoder& encoder, const WebCore::Payment& payment) { encoder << payment.pkPayment(); } Optional ArgumentCoder::decode(Decoder& decoder) { auto payment = IPC::decode(decoder, PAL::getPKPaymentClass()); if (!payment) return WTF::nullopt; return Payment { WTFMove(*payment) }; } void ArgumentCoder::encode(Encoder& encoder, const WebCore::PaymentAuthorizationResult& result) { encoder << result.status; encoder << result.errors; } Optional ArgumentCoder::decode(Decoder& decoder) { Optional status; decoder >> status; if (!status) return WTF::nullopt; Optional> errors; decoder >> errors; if (!errors) return WTF::nullopt; return {{ WTFMove(*status), WTFMove(*errors) }}; } void ArgumentCoder::encode(Encoder& encoder, const WebCore::PaymentContact& paymentContact) { encoder << paymentContact.pkContact(); } Optional ArgumentCoder::decode(Decoder& decoder) { auto contact = IPC::decode(decoder, PAL::getPKContactClass()); if (!contact) return WTF::nullopt; return WebCore::PaymentContact { WTFMove(*contact) }; } void ArgumentCoder::encode(Encoder& encoder, const WebCore::PaymentError& error) { encoder << error.code; encoder << error.message; encoder << error.contactField; } Optional ArgumentCoder::decode(Decoder& decoder) { Optional code; decoder >> code; if (!code) return WTF::nullopt; Optional message; decoder >> message; if (!message) return WTF::nullopt; Optional> contactField; decoder >> contactField; if (!contactField) return WTF::nullopt; return {{ WTFMove(*code), WTFMove(*message), WTFMove(*contactField) }}; } void ArgumentCoder::encode(Encoder& encoder, const WebCore::PaymentMerchantSession& paymentMerchantSession) { encoder << paymentMerchantSession.pkPaymentMerchantSession(); } Optional ArgumentCoder::decode(Decoder& decoder) { auto paymentMerchantSession = IPC::decode(decoder, PAL::getPKPaymentMerchantSessionClass()); if (!paymentMerchantSession) return WTF::nullopt; return WebCore::PaymentMerchantSession { WTFMove(*paymentMerchantSession) }; } void ArgumentCoder::encode(Encoder& encoder, const WebCore::PaymentMethod& paymentMethod) { encoder << paymentMethod.pkPaymentMethod(); } Optional ArgumentCoder::decode(Decoder& decoder) { auto paymentMethod = IPC::decode(decoder, PAL::getPKPaymentMethodClass()); if (!paymentMethod) return WTF::nullopt; return PaymentMethod { WTFMove(*paymentMethod) }; } void ArgumentCoder::encode(Encoder& encoder, const WebCore::PaymentMethodUpdate& update) { encoder << update.newTotalAndLineItems; } Optional ArgumentCoder::decode(Decoder& decoder) { Optional newTotalAndLineItems; decoder >> newTotalAndLineItems; if (!newTotalAndLineItems) return WTF::nullopt; return {{ WTFMove(*newTotalAndLineItems) }}; } void ArgumentCoder::encode(Encoder& encoder, const ApplePaySessionPaymentRequest& request) { encoder << request.countryCode(); encoder << request.currencyCode(); encoder << request.requiredBillingContactFields(); encoder << request.billingContact(); encoder << request.requiredShippingContactFields(); encoder << request.shippingContact(); encoder << request.merchantCapabilities(); encoder << request.supportedNetworks(); encoder.encodeEnum(request.shippingType()); encoder << request.shippingMethods(); encoder << request.lineItems(); encoder << request.total(); encoder << request.applicationData(); encoder << request.supportedCountries(); encoder.encodeEnum(request.requester()); } bool ArgumentCoder::decode(Decoder& decoder, ApplePaySessionPaymentRequest& request) { String countryCode; if (!decoder.decode(countryCode)) return false; request.setCountryCode(countryCode); String currencyCode; if (!decoder.decode(currencyCode)) return false; request.setCurrencyCode(currencyCode); ApplePaySessionPaymentRequest::ContactFields requiredBillingContactFields; if (!decoder.decode((requiredBillingContactFields))) return false; request.setRequiredBillingContactFields(requiredBillingContactFields); Optional billingContact; decoder >> billingContact; if (!billingContact) return false; request.setBillingContact(*billingContact); ApplePaySessionPaymentRequest::ContactFields requiredShippingContactFields; if (!decoder.decode((requiredShippingContactFields))) return false; request.setRequiredShippingContactFields(requiredShippingContactFields); Optional shippingContact; decoder >> shippingContact; if (!shippingContact) return false; request.setShippingContact(*shippingContact); ApplePaySessionPaymentRequest::MerchantCapabilities merchantCapabilities; if (!decoder.decode(merchantCapabilities)) return false; request.setMerchantCapabilities(merchantCapabilities); Vector supportedNetworks; if (!decoder.decode(supportedNetworks)) return false; request.setSupportedNetworks(supportedNetworks); ApplePaySessionPaymentRequest::ShippingType shippingType; if (!decoder.decodeEnum(shippingType)) return false; request.setShippingType(shippingType); Vector shippingMethods; if (!decoder.decode(shippingMethods)) return false; request.setShippingMethods(shippingMethods); Vector lineItems; if (!decoder.decode(lineItems)) return false; request.setLineItems(lineItems); Optional total; decoder >> total; if (!total) return false; request.setTotal(*total); String applicationData; if (!decoder.decode(applicationData)) return false; request.setApplicationData(applicationData); Vector supportedCountries; if (!decoder.decode(supportedCountries)) return false; request.setSupportedCountries(WTFMove(supportedCountries)); ApplePaySessionPaymentRequest::Requester requester; if (!decoder.decodeEnum(requester)) return false; request.setRequester(requester); return true; } void ArgumentCoder::encode(Encoder& encoder, const ApplePaySessionPaymentRequest::ContactFields& contactFields) { encoder << contactFields.postalAddress; encoder << contactFields.phone; encoder << contactFields.email; encoder << contactFields.name; encoder << contactFields.phoneticName; } bool ArgumentCoder::decode(Decoder& decoder, ApplePaySessionPaymentRequest::ContactFields& contactFields) { if (!decoder.decode(contactFields.postalAddress)) return false; if (!decoder.decode(contactFields.phone)) return false; if (!decoder.decode(contactFields.email)) return false; if (!decoder.decode(contactFields.name)) return false; if (!decoder.decode(contactFields.phoneticName)) return false; return true; } void ArgumentCoder::encode(Encoder& encoder, const ApplePaySessionPaymentRequest::LineItem& lineItem) { encoder.encodeEnum(lineItem.type); encoder << lineItem.label; encoder << lineItem.amount; } Optional ArgumentCoder::decode(Decoder& decoder) { WebCore::ApplePaySessionPaymentRequest::LineItem lineItem; if (!decoder.decodeEnum(lineItem.type)) return WTF::nullopt; if (!decoder.decode(lineItem.label)) return WTF::nullopt; if (!decoder.decode(lineItem.amount)) return WTF::nullopt; return WTFMove(lineItem); } void ArgumentCoder::encode(Encoder& encoder, const ApplePaySessionPaymentRequest::MerchantCapabilities& merchantCapabilities) { encoder << merchantCapabilities.supports3DS; encoder << merchantCapabilities.supportsEMV; encoder << merchantCapabilities.supportsCredit; encoder << merchantCapabilities.supportsDebit; } bool ArgumentCoder::decode(Decoder& decoder, ApplePaySessionPaymentRequest::MerchantCapabilities& merchantCapabilities) { if (!decoder.decode(merchantCapabilities.supports3DS)) return false; if (!decoder.decode(merchantCapabilities.supportsEMV)) return false; if (!decoder.decode(merchantCapabilities.supportsCredit)) return false; if (!decoder.decode(merchantCapabilities.supportsDebit)) return false; return true; } void ArgumentCoder::encode(Encoder& encoder, const ApplePaySessionPaymentRequest::ShippingMethod& shippingMethod) { encoder << shippingMethod.label; encoder << shippingMethod.detail; encoder << shippingMethod.amount; encoder << shippingMethod.identifier; } Optional ArgumentCoder::decode(Decoder& decoder) { ApplePaySessionPaymentRequest::ShippingMethod shippingMethod; if (!decoder.decode(shippingMethod.label)) return WTF::nullopt; if (!decoder.decode(shippingMethod.detail)) return WTF::nullopt; if (!decoder.decode(shippingMethod.amount)) return WTF::nullopt; if (!decoder.decode(shippingMethod.identifier)) return WTF::nullopt; return WTFMove(shippingMethod); } void ArgumentCoder::encode(Encoder& encoder, const ApplePaySessionPaymentRequest::TotalAndLineItems& totalAndLineItems) { encoder << totalAndLineItems.total; encoder << totalAndLineItems.lineItems; } Optional ArgumentCoder::decode(Decoder& decoder) { Optional total; decoder >> total; if (!total) return WTF::nullopt; Optional> lineItems; decoder >> lineItems; if (!lineItems) return WTF::nullopt; return {{ WTFMove(*total), WTFMove(*lineItems) }}; } void ArgumentCoder::encode(Encoder& encoder, const WebCore::ShippingContactUpdate& update) { encoder << update.errors; encoder << update.newShippingMethods; encoder << update.newTotalAndLineItems; } Optional ArgumentCoder::decode(Decoder& decoder) { Optional> errors; decoder >> errors; if (!errors) return WTF::nullopt; Optional> newShippingMethods; decoder >> newShippingMethods; if (!newShippingMethods) return WTF::nullopt; Optional newTotalAndLineItems; decoder >> newTotalAndLineItems; if (!newTotalAndLineItems) return WTF::nullopt; return {{ WTFMove(*errors), WTFMove(*newShippingMethods), WTFMove(*newTotalAndLineItems) }}; } void ArgumentCoder::encode(Encoder& encoder, const WebCore::ShippingMethodUpdate& update) { encoder << update.newTotalAndLineItems; } Optional ArgumentCoder::decode(Decoder& decoder) { Optional newTotalAndLineItems; decoder >> newTotalAndLineItems; if (!newTotalAndLineItems) return WTF::nullopt; return {{ WTFMove(*newTotalAndLineItems) }}; } } #endif