Title: [228207] branches/safari-605-branch

Diff

Modified: branches/safari-605-branch/LayoutTests/ChangeLog (228206 => 228207)


--- branches/safari-605-branch/LayoutTests/ChangeLog	2018-02-07 00:53:42 UTC (rev 228206)
+++ branches/safari-605-branch/LayoutTests/ChangeLog	2018-02-07 00:53:46 UTC (rev 228207)
@@ -1,5 +1,20 @@
 2018-02-06  Jason Marcell  <jmarc...@apple.com>
 
+        Cherry-pick r228195. rdar://problem/37292905
+
+    2018-02-06  Andy Estes  <aes...@apple.com>
+
+            [Payment Request] show() should take an optional PaymentDetailsUpdate promise
+            https://bugs.webkit.org/show_bug.cgi?id=182538
+            <rdar://problem/36754552>
+
+            Reviewed by Tim Horton.
+
+            * http/tests/paymentrequest/payment-request-show-method.https-expected.txt:
+            * http/tests/paymentrequest/payment-request-show-method.https.html:
+
+2018-02-06  Jason Marcell  <jmarc...@apple.com>
+
         Cherry-pick r228001. rdar://problem/37264547
 
     2018-02-02  Fujii Hironori  <hironori.fu...@sony.com>

Modified: branches/safari-605-branch/LayoutTests/http/tests/paymentrequest/payment-request-show-method.https-expected.txt (228206 => 228207)


--- branches/safari-605-branch/LayoutTests/http/tests/paymentrequest/payment-request-show-method.https-expected.txt	2018-02-07 00:53:42 UTC (rev 228206)
+++ branches/safari-605-branch/LayoutTests/http/tests/paymentrequest/payment-request-show-method.https-expected.txt	2018-02-07 00:53:46 UTC (rev 228207)
@@ -4,4 +4,6 @@
 PASS If the user agent's "payment request is showing" boolean is true, then return a promise rejected with an "AbortError" DOMException. 
 PASS If payment method consultation produces no supported method of payment, then return a promise rejected with a "NotSupportedError" DOMException. 
 PASS If the user aborts the payment request algorithm, then return a promise rejected with an "AbortError" DOMException. 
+PASS A request is updated when show()'s detail promise resolves. 
+PASS Change events do not occur until show()'s detail promise resolves. 
 

Modified: branches/safari-605-branch/LayoutTests/http/tests/paymentrequest/payment-request-show-method.https.html (228206 => 228207)


--- branches/safari-605-branch/LayoutTests/http/tests/paymentrequest/payment-request-show-method.https.html	2018-02-07 00:53:42 UTC (rev 228206)
+++ branches/safari-605-branch/LayoutTests/http/tests/paymentrequest/payment-request-show-method.https.html	2018-02-07 00:53:46 UTC (rev 228207)
@@ -75,4 +75,64 @@
   internals.mockPaymentCoordinator.cancelPayment();
   await promise_rejects(t, "AbortError", acceptPromise);
 }, `If the user aborts the payment request algorithm, then return a promise rejected with an "AbortError" DOMException.`);
+
+user_activation_test(async t => {
+  const request = new PaymentRequest(defaultMethods, defaultDetails);
+  const expectedLabel = "Updated Total";
+  const expectedAmount = "2.00";
+  const details = {
+      total: {
+          label: expectedLabel,
+          amount: {
+              currency: "USD",
+              value: expectedAmount,
+          },
+      },
+  };
+  const acceptPromise = request.show(details);
+  internals.mockPaymentCoordinator.changePaymentMethod({ type: 'credit' });
+  internals.mockPaymentCoordinator.acceptPayment();
+  const result = await acceptPromise;
+  assert_equals(internals.mockPaymentCoordinator.total.label, expectedLabel);
+  assert_equals(internals.mockPaymentCoordinator.total.amount, expectedAmount);
+  result.complete("success");
+}, `A request is updated when show()'s detail promise resolves.`);
+
+user_activation_test(async t => {
+  const request = new PaymentRequest(defaultMethods, defaultDetails);
+  const expectedLabel = "Updated Total";
+  const expectedAmount = "2.00";
+
+  var shippingAddressChanged = false;
+  const shippingAddressChangedPromise = new Promise((resolve) => {
+    request._onshippingaddresschange_ = () => {
+      shippingAddressChanged = true;
+      resolve();
+    };
+  });
+
+  const detailsPromise = new Promise((resolve) => {
+    const details = {
+      total: {
+        label: expectedLabel,
+        amount: {
+          currency: "USD",
+          value: expectedAmount,
+        },
+      },
+    };
+
+    request._onmerchantvalidation_ = (event) => {
+      const sessionPromise = new Promise((resolve) => resolve({ }));
+      event.complete(sessionPromise);
+      sessionPromise.then(() => window.setTimeout(() => {
+        assert_equals(shippingAddressChanged, false, "shippingaddresschange does not fire before the details promise resolves.");
+        resolve(details);
+      }));
+    };
+  });
+
+  request.show(detailsPromise).catch(() => {});
+  await shippingAddressChangedPromise;
+}, `Change events do not occur until show()'s detail promise resolves.`);
 </script>

Modified: branches/safari-605-branch/Source/WebCore/ChangeLog (228206 => 228207)


--- branches/safari-605-branch/Source/WebCore/ChangeLog	2018-02-07 00:53:42 UTC (rev 228206)
+++ branches/safari-605-branch/Source/WebCore/ChangeLog	2018-02-07 00:53:46 UTC (rev 228207)
@@ -1,5 +1,75 @@
 2018-02-06  Jason Marcell  <jmarc...@apple.com>
 
+        Cherry-pick r228195. rdar://problem/37292905
+
+    2018-02-06  Andy Estes  <aes...@apple.com>
+
+            [Payment Request] show() should take an optional PaymentDetailsUpdate promise
+            https://bugs.webkit.org/show_bug.cgi?id=182538
+            <rdar://problem/36754552>
+
+            Reviewed by Tim Horton.
+
+            Taught show() to take an optional promise for a PaymentDetailsUpdate.
+
+            Added test cases to http/tests/paymentrequest/payment-request-show-method.https.html.
+
+            * Modules/applepay/paymentrequest/ApplePayPaymentHandler.cpp:
+            (WebCore::ApplePayPaymentHandler::detailsUpdated):
+
+            Changed to take a PaymentRequest::UpdateReason instead of a eventType string.
+
+            (WebCore::ApplePayPaymentHandler::shippingAddressUpdated):
+            (WebCore::ApplePayPaymentHandler::shippingOptionUpdated):
+            (WebCore::ApplePayPaymentHandler::paymentMethodUpdated):
+            (WebCore::ApplePayPaymentHandler::didAuthorizePayment):
+            (WebCore::ApplePayPaymentHandler::didSelectShippingMethod):
+            (WebCore::ApplePayPaymentHandler::didSelectShippingContact):
+            (WebCore::ApplePayPaymentHandler::didSelectPaymentMethod):
+
+            Asserted that only one of the PaymentSession delegates is executing at a time.
+
+            * Modules/applepay/paymentrequest/ApplePayPaymentHandler.h:
+            * Modules/paymentrequest/PaymentHandler.h:
+
+            Changed detailsUpdated to take a PaymentRequest::UpdateReason instead of a eventType string.
+
+            * Modules/paymentrequest/PaymentRequest.cpp:
+            (WebCore::PaymentRequest::show):
+
+            If there is a details promise, call updateWith() with UpdateReason::ShowDetailsResolved.
+
+            (WebCore::PaymentRequest::shippingAddressChanged):
+            (WebCore::PaymentRequest::shippingOptionChanged):
+            (WebCore::PaymentRequest::paymentMethodChanged):
+
+            Used whenDetailsSettled() to ensure that update events do not start before the show()
+            details promise settles.
+
+            (WebCore::PaymentRequest::updateWith):
+            (WebCore::PaymentRequest::settleDetailsPromise):
+
+            Changed to use a PaymentRequest::UpdateReason instead of a eventType string.
+
+            (WebCore::PaymentRequest::whenDetailsSettled):
+
+            If there is a details promise, wait for it to settle before executing the callback.
+
+            * Modules/paymentrequest/PaymentRequest.h:
+
+            Defined enum class UpdateReason.
+
+            * Modules/paymentrequest/PaymentRequest.idl:
+
+            Updated show() to take an optional Promise<PaymentDetailsUpdate>.
+
+            * Modules/paymentrequest/PaymentRequestUpdateEvent.cpp:
+            (WebCore::PaymentRequestUpdateEvent::updateWith):
+
+            Map the event type to a PaymentRequest::UpdateReason.
+
+2018-02-06  Jason Marcell  <jmarc...@apple.com>
+
         Cherry-pick r228191. rdar://problem/37292910
 
     2018-02-06  Dean Jackson  <d...@apple.com>

Modified: branches/safari-605-branch/Source/WebCore/Modules/applepay/paymentrequest/ApplePayPaymentHandler.cpp (228206 => 228207)


--- branches/safari-605-branch/Source/WebCore/Modules/applepay/paymentrequest/ApplePayPaymentHandler.cpp	2018-02-07 00:53:42 UTC (rev 228206)
+++ branches/safari-605-branch/Source/WebCore/Modules/applepay/paymentrequest/ApplePayPaymentHandler.cpp	2018-02-07 00:53:46 UTC (rev 228207)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2017 Apple Inc. All rights reserved.
+ * Copyright (C) 2017-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
@@ -307,13 +307,19 @@
     return ApplePaySessionPaymentRequest::TotalAndLineItems { WTFMove(total), WTFMove(lineItems) };
 }
 
-ExceptionOr<void> ApplePayPaymentHandler::detailsUpdated(const AtomicString& eventType, const String& error)
+ExceptionOr<void> ApplePayPaymentHandler::detailsUpdated(PaymentRequest::UpdateReason reason, const String& error)
 {
-    if (eventType == eventNames().shippingaddresschangeEvent)
+    using Reason = PaymentRequest::UpdateReason;
+    switch (reason) {
+    case Reason::ShowDetailsResolved:
+        return { };
+    case Reason::ShippingAddressChanged:
         return shippingAddressUpdated(error);
-
-    if (eventType == eventNames().shippingoptionchangeEvent)
+    case Reason::ShippingOptionChanged:
         return shippingOptionUpdated();
+    case Reason::PaymentMethodChanged:
+        return paymentMethodUpdated();
+    }
 
     ASSERT_NOT_REACHED();
     return { };
@@ -338,6 +344,9 @@
 
 ExceptionOr<void> ApplePayPaymentHandler::shippingAddressUpdated(const String& error)
 {
+    ASSERT(m_isUpdating);
+    m_isUpdating = false;
+
     ShippingContactUpdate update;
 
     if (m_paymentRequest->paymentOptions().requestShipping && m_paymentRequest->paymentDetails().shippingOptions.isEmpty()) {
@@ -358,6 +367,9 @@
 
 ExceptionOr<void> ApplePayPaymentHandler::shippingOptionUpdated()
 {
+    ASSERT(m_isUpdating);
+    m_isUpdating = false;
+
     ShippingMethodUpdate update;
 
     auto newTotalAndLineItems = computeTotalAndLineItems();
@@ -371,6 +383,9 @@
 
 ExceptionOr<void> ApplePayPaymentHandler::paymentMethodUpdated()
 {
+    ASSERT(m_isUpdating);
+    m_isUpdating = false;
+
     PaymentMethodUpdate update;
 
     auto newTotalAndLineItems = computeTotalAndLineItems();
@@ -427,6 +442,8 @@
 
 void ApplePayPaymentHandler::didAuthorizePayment(const Payment& payment)
 {
+    ASSERT(!m_isUpdating);
+
     auto applePayPayment = payment.toApplePayPayment(version());
     auto& execState = *document().execState();
     auto lock = JSC::JSLockHolder { &execState };
@@ -437,18 +454,27 @@
 
 void ApplePayPaymentHandler::didSelectShippingMethod(const ApplePaySessionPaymentRequest::ShippingMethod& shippingMethod)
 {
+    ASSERT(!m_isUpdating);
+    m_isUpdating = true;
+
     m_paymentRequest->shippingOptionChanged(shippingMethod.identifier);
 }
 
 void ApplePayPaymentHandler::didSelectShippingContact(const PaymentContact& shippingContact)
 {
+    ASSERT(!m_isUpdating);
+    m_isUpdating = true;
+
     m_paymentRequest->shippingAddressChanged(convert(shippingContact.toApplePayPaymentContact(version())));
 }
 
 void ApplePayPaymentHandler::didSelectPaymentMethod(const PaymentMethod& paymentMethod)
 {
+    ASSERT(!m_isUpdating);
+    m_isUpdating = true;
+
     m_selectedPaymentMethodType = paymentMethod.toApplePayPaymentMethod().type;
-    paymentMethodUpdated();
+    m_paymentRequest->paymentMethodChanged();
 }
 
 void ApplePayPaymentHandler::didCancelPaymentSession()

Modified: branches/safari-605-branch/Source/WebCore/Modules/applepay/paymentrequest/ApplePayPaymentHandler.h (228206 => 228207)


--- branches/safari-605-branch/Source/WebCore/Modules/applepay/paymentrequest/ApplePayPaymentHandler.h	2018-02-07 00:53:42 UTC (rev 228206)
+++ branches/safari-605-branch/Source/WebCore/Modules/applepay/paymentrequest/ApplePayPaymentHandler.h	2018-02-07 00:53:46 UTC (rev 228207)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2017 Apple Inc. All rights reserved.
+ * Copyright (C) 2017-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
@@ -63,7 +63,7 @@
     ExceptionOr<void> show() final;
     void hide() final;
     void canMakePayment(WTF::Function<void(bool)>&& completionHandler) final;
-    ExceptionOr<void> detailsUpdated(const AtomicString& eventType, const String& error) final;
+    ExceptionOr<void> detailsUpdated(PaymentRequest::UpdateReason, const String& error) final;
     ExceptionOr<void> merchantValidationCompleted(JSC::JSValue&&) final;
     void complete(std::optional<PaymentComplete>&&) final;
 
@@ -80,6 +80,7 @@
     Ref<PaymentRequest> m_paymentRequest;
     std::optional<ApplePayRequest> m_applePayRequest;
     std::optional<ApplePayPaymentMethodType> m_selectedPaymentMethodType;
+    bool m_isUpdating { false };
 };
 
 } // namespace WebCore

Modified: branches/safari-605-branch/Source/WebCore/Modules/paymentrequest/PaymentHandler.h (228206 => 228207)


--- branches/safari-605-branch/Source/WebCore/Modules/paymentrequest/PaymentHandler.h	2018-02-07 00:53:42 UTC (rev 228206)
+++ branches/safari-605-branch/Source/WebCore/Modules/paymentrequest/PaymentHandler.h	2018-02-07 00:53:46 UTC (rev 228207)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2017 Apple Inc. All rights reserved.
+ * Copyright (C) 2017-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
@@ -49,7 +49,7 @@
     virtual ExceptionOr<void> show() = 0;
     virtual void hide() = 0;
     virtual void canMakePayment(WTF::Function<void(bool)>&& completionHandler) = 0;
-    virtual ExceptionOr<void> detailsUpdated(const AtomicString& eventType, const String& error) = 0;
+    virtual ExceptionOr<void> detailsUpdated(PaymentRequest::UpdateReason, const String& error) = 0;
     virtual ExceptionOr<void> merchantValidationCompleted(JSC::JSValue&&) = 0;
     virtual void complete(std::optional<PaymentComplete>&&) = 0;
 };

Modified: branches/safari-605-branch/Source/WebCore/Modules/paymentrequest/PaymentRequest.cpp (228206 => 228207)


--- branches/safari-605-branch/Source/WebCore/Modules/paymentrequest/PaymentRequest.cpp	2018-02-07 00:53:42 UTC (rev 228206)
+++ branches/safari-605-branch/Source/WebCore/Modules/paymentrequest/PaymentRequest.cpp	2018-02-07 00:53:46 UTC (rev 228207)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2017 Apple Inc. All rights reserved.
+ * Copyright (C) 2017-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
@@ -380,7 +380,7 @@
 }
 
 // https://www.w3.org/TR/payment-request/#show()-method
-void PaymentRequest::show(Document& document, ShowPromise&& promise)
+void PaymentRequest::show(Document& document, RefPtr<DOMPromise>&& detailsPromise, ShowPromise&& promise)
 {
     if (!document.frame()) {
         promise.reject(Exception { AbortError });
@@ -442,6 +442,12 @@
     ASSERT(!m_activePaymentHandler);
     m_activePaymentHandler = WTFMove(selectedPaymentHandler);
     setPendingActivity(this); // unsetPendingActivity() is called below in stop()
+
+    if (!detailsPromise)
+        return;
+
+    exception = updateWith(UpdateReason::ShowDetailsResolved, detailsPromise.releaseNonNull());
+    ASSERT(!exception.hasException());
 }
 
 void PaymentRequest::abortWithException(Exception&& exception)
@@ -531,24 +537,29 @@
 
 void PaymentRequest::shippingAddressChanged(Ref<PaymentAddress>&& shippingAddress)
 {
-    ASSERT(m_state == State::Interactive);
-    m_shippingAddress = WTFMove(shippingAddress);
-    if (m_isUpdating)
-        return;
-    dispatchEvent(PaymentRequestUpdateEvent::create(eventNames().shippingaddresschangeEvent, *this));
+    whenDetailsSettled([this, protectedThis = makeRefPtr(this), shippingAddress = makeRefPtr(shippingAddress.get())]() mutable {
+        m_shippingAddress = WTFMove(shippingAddress);
+        dispatchEvent(PaymentRequestUpdateEvent::create(eventNames().shippingaddresschangeEvent, *this));
+    });
 }
 
 void PaymentRequest::shippingOptionChanged(const String& shippingOption)
 {
-    ASSERT(m_state == State::Interactive);
-    m_shippingOption = shippingOption;
-    if (m_isUpdating)
-        return;
-    dispatchEvent(PaymentRequestUpdateEvent::create(eventNames().shippingoptionchangeEvent, *this));
+    whenDetailsSettled([this, protectedThis = makeRefPtr(this), shippingOption]() mutable {
+        m_shippingOption = shippingOption;
+        dispatchEvent(PaymentRequestUpdateEvent::create(eventNames().shippingoptionchangeEvent, *this));
+    });
 }
 
-ExceptionOr<void> PaymentRequest::updateWith(Event& event, Ref<DOMPromise>&& promise)
+void PaymentRequest::paymentMethodChanged()
 {
+    whenDetailsSettled([this, protectedThis = makeRefPtr(this)] {
+        m_activePaymentHandler->detailsUpdated(UpdateReason::PaymentMethodChanged, { });
+    });
+}
+
+ExceptionOr<void> PaymentRequest::updateWith(UpdateReason reason, Ref<DOMPromise>&& promise)
+{
     if (m_state != State::Interactive)
         return Exception { InvalidStateError };
 
@@ -555,13 +566,12 @@
     if (m_isUpdating)
         return Exception { InvalidStateError };
 
-    event.stopPropagation();
-    event.stopImmediatePropagation();
     m_isUpdating = true;
 
+    ASSERT(!m_detailsPromise);
     m_detailsPromise = WTFMove(promise);
-    m_detailsPromise->whenSettled([this, protectedThis = makeRefPtr(this), type = event.type()]() {
-        settleDetailsPromise(type);
+    m_detailsPromise->whenSettled([this, protectedThis = makeRefPtr(this), reason]() {
+        settleDetailsPromise(reason);
     });
 
     return { };
@@ -595,10 +605,11 @@
     return { };
 }
 
-void PaymentRequest::settleDetailsPromise(const AtomicString& type)
+void PaymentRequest::settleDetailsPromise(UpdateReason reason)
 {
     auto scopeExit = makeScopeExit([&] {
         m_isUpdating = false;
+        m_detailsPromise = nullptr;
     });
 
     if (m_state != State::Interactive)
@@ -641,7 +652,7 @@
     m_details.modifiers = WTFMove(paymentDetailsUpdate.modifiers);
     m_serializedModifierData = WTFMove(std::get<1>(shippingOptionAndModifierData));
 
-    auto result = m_activePaymentHandler->detailsUpdated(type, paymentDetailsUpdate.error);
+    auto result = m_activePaymentHandler->detailsUpdated(reason, paymentDetailsUpdate.error);
     if (result.hasException()) {
         abortWithException(result.releaseException());
         return;
@@ -648,6 +659,24 @@
     }
 }
 
+void PaymentRequest::whenDetailsSettled(std::function<void()>&& callback)
+{
+    if (!m_detailsPromise) {
+        ASSERT(m_state == State::Interactive);
+        ASSERT(!m_isUpdating);
+        callback();
+        return;
+    }
+
+    m_detailsPromise->whenSettled([this, protectedThis = makeRefPtr(this), callback = WTFMove(callback)] {
+        if (m_state != State::Interactive)
+            return;
+
+        ASSERT(!m_isUpdating);
+        callback();
+    });
+}
+
 void PaymentRequest::accept(const String& methodName, JSC::Strong<JSC::JSObject>&& details, Ref<PaymentAddress>&& shippingAddress, const String& payerName, const String& payerEmail, const String& payerPhone)
 {
     ASSERT(m_state == State::Interactive);

Modified: branches/safari-605-branch/Source/WebCore/Modules/paymentrequest/PaymentRequest.h (228206 => 228207)


--- branches/safari-605-branch/Source/WebCore/Modules/paymentrequest/PaymentRequest.h	2018-02-07 00:53:42 UTC (rev 228206)
+++ branches/safari-605-branch/Source/WebCore/Modules/paymentrequest/PaymentRequest.h	2018-02-07 00:53:46 UTC (rev 228207)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2017 Apple Inc. All rights reserved.
+ * Copyright (C) 2017-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
@@ -45,18 +45,19 @@
 class PaymentResponse;
 enum class PaymentComplete;
 enum class PaymentShippingType;
+struct PaymentDetailsUpdate;
 struct PaymentMethodData;
 
 class PaymentRequest final : public RefCounted<PaymentRequest>, public ActiveDOMObject, public EventTargetWithInlineData {
 public:
-    using ShowPromise = DOMPromiseDeferred<IDLInterface<PaymentResponse>>;
     using AbortPromise = DOMPromiseDeferred<void>;
     using CanMakePaymentPromise = DOMPromiseDeferred<IDLBoolean>;
+    using ShowPromise = DOMPromiseDeferred<IDLInterface<PaymentResponse>>;
 
     static ExceptionOr<Ref<PaymentRequest>> create(Document&, Vector<PaymentMethodData>&&, PaymentDetailsInit&&, PaymentOptions&&);
     ~PaymentRequest();
 
-    void show(Document&, ShowPromise&&);
+    void show(Document&, RefPtr<DOMPromise>&& detailsPromise, ShowPromise&&);
     ExceptionOr<void> abort(AbortPromise&&);
     void canMakePayment(Document&, CanMakePaymentPromise&&);
 
@@ -71,6 +72,13 @@
         Closed,
     };
 
+    enum class UpdateReason {
+        ShowDetailsResolved,
+        ShippingAddressChanged,
+        ShippingOptionChanged,
+        PaymentMethodChanged,
+    };
+
     State state() const { return m_state; }
 
     const PaymentOptions& paymentOptions() const { return m_options; }
@@ -79,7 +87,8 @@
 
     void shippingAddressChanged(Ref<PaymentAddress>&&);
     void shippingOptionChanged(const String& shippingOption);
-    ExceptionOr<void> updateWith(Event&, Ref<DOMPromise>&&);
+    void paymentMethodChanged();
+    ExceptionOr<void> updateWith(UpdateReason, Ref<DOMPromise>&&);
     ExceptionOr<void> completeMerchantValidation(Event&, Ref<DOMPromise>&&);
     void accept(const String& methodName, JSC::Strong<JSC::JSObject>&& details, Ref<PaymentAddress>&& shippingAddress, const String& payerName, const String& payerEmail, const String& payerPhone);
     void complete(std::optional<PaymentComplete>&&);
@@ -97,7 +106,8 @@
 
     PaymentRequest(Document&, PaymentOptions&&, PaymentDetailsInit&&, Vector<String>&& serializedModifierData, Vector<Method>&& serializedMethodData, String&& selectedShippingOption);
 
-    void settleDetailsPromise(const AtomicString& type);
+    void settleDetailsPromise(UpdateReason);
+    void whenDetailsSettled(std::function<void()>&&);
     void abortWithException(Exception&&);
 
     // ActiveDOMObject

Modified: branches/safari-605-branch/Source/WebCore/Modules/paymentrequest/PaymentRequest.idl (228206 => 228207)


--- branches/safari-605-branch/Source/WebCore/Modules/paymentrequest/PaymentRequest.idl	2018-02-07 00:53:42 UTC (rev 228206)
+++ branches/safari-605-branch/Source/WebCore/Modules/paymentrequest/PaymentRequest.idl	2018-02-07 00:53:46 UTC (rev 228207)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2017 Apple Inc. All rights reserved.
+ * Copyright (C) 2017-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
@@ -30,9 +30,9 @@
     ConstructorCallWith=Document,
     ConstructorMayThrowException,
     EnabledBySetting=PaymentRequest,
-    SecureContext
+    SecureContext,
 ] interface PaymentRequest : EventTarget {
-    [CallWith=Document] Promise<PaymentResponse> show();
+    [CallWith=Document] Promise<PaymentResponse> show(optional Promise<PaymentDetailsUpdate> detailsPromise);
     [MayThrowException] Promise<void> abort();
     [CallWith=Document] Promise<boolean> canMakePayment();
 

Modified: branches/safari-605-branch/Source/WebCore/Modules/paymentrequest/PaymentRequestUpdateEvent.cpp (228206 => 228207)


--- branches/safari-605-branch/Source/WebCore/Modules/paymentrequest/PaymentRequestUpdateEvent.cpp	2018-02-07 00:53:42 UTC (rev 228206)
+++ branches/safari-605-branch/Source/WebCore/Modules/paymentrequest/PaymentRequestUpdateEvent.cpp	2018-02-07 00:53:46 UTC (rev 228207)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2017 Apple Inc. All rights reserved.
+ * Copyright (C) 2017-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
@@ -53,7 +53,20 @@
     if (m_waitForUpdate)
         return Exception { InvalidStateError };
 
-    auto exception = m_paymentRequest->updateWith(*this, WTFMove(detailsPromise));
+    stopPropagation();
+    stopImmediatePropagation();
+
+    PaymentRequest::UpdateReason reason;
+    if (type() == eventNames().shippingaddresschangeEvent)
+        reason = PaymentRequest::UpdateReason::ShippingAddressChanged;
+    else if (type() == eventNames().shippingoptionchangeEvent)
+        reason = PaymentRequest::UpdateReason::ShippingOptionChanged;
+    else {
+        ASSERT_NOT_REACHED();
+        return Exception { TypeError };
+    }
+
+    auto exception = m_paymentRequest->updateWith(reason, WTFMove(detailsPromise));
     if (exception.hasException())
         return exception.releaseException();
 
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to