Title: [223021] trunk
Revision
223021
Author
[email protected]
Date
2017-10-07 12:24:04 -0700 (Sat, 07 Oct 2017)

Log Message

[Payment Request] Implement PaymentRequest.show() and PaymentRequest.hide()
https://bugs.webkit.org/show_bug.cgi?id=178043
<rdar://problem/34076639>

Reviewed by Tim Horton.

LayoutTests/imported/w3c:

* web-platform-tests/payment-request/payment-request-abort-method.https-expected.txt: Removed.
* web-platform-tests/payment-request/payment-request-show-method.https-expected.txt: Removed.

Source/WebCore:

Tests: http/tests/paymentrequest/payment-request-abort-method.https.html
       http/tests/paymentrequest/payment-request-show-method.https.html

* Modules/applepay/PaymentSession.h: Virtually inherited from PaymentSessionBase to
accommodate ApplePayPaymentHandler inheriting from both this and PaymentHandler.
(WebCore::PaymentSession::~PaymentSession): Deleted.
* Modules/applepay/paymentrequest/ApplePayPaymentHandler.cpp:
(WebCore::paymentCoordinator): Virtually inherited from PaymentSessionBase to accommodate
ApplePayPaymentHandler inheriting from both this and PaymentSession.
(WebCore::ApplePayPaymentHandler::hasActiveSession): Added. Calls PaymentCoordinator::hasActiveSession().
(WebCore::ApplePayPaymentHandler::show): Added. Calls PaymentCoordinator::beginPaymentSession().
(WebCore::ApplePayPaymentHandler::hide): Added. Calls PaymentCoordinator::abortPaymentSession().
* Modules/applepay/paymentrequest/ApplePayPaymentHandler.h: Inherited from PaymentSession in
addition to PaymentHandler so that this can be PaymentCoordinator active session.
* Modules/paymentrequest/PaymentHandler.cpp:
(WebCore::PaymentHandler::create):
(WebCore::PaymentHandler::hasActiveSession):
* Modules/paymentrequest/PaymentHandler.h:
* Modules/paymentrequest/PaymentRequest.cpp:
(WebCore::PaymentRequest::~PaymentRequest):
(WebCore::PaymentRequest::show): Rejected the promise if PaymentCoordinator has an active session.
(WebCore::PaymentRequest::abort): Called stop().
(WebCore::PaymentRequest::canSuspendForDocumentSuspension const): Returned true if state is
Interactive and there is an active handler showing.
(WebCore::PaymentRequest::stop): Hid the active session if it's showing, then set state to
Closed and rejected the show promise.
* Modules/paymentrequest/PaymentRequest.h:
* Modules/paymentrequest/PaymentSessionBase.h: Added. Inherits from
RefCounted<PaymentSessionBase> and defines a virtual destructor. This allows subclasses to
virtually inherit a single ref-count to support multiple inheritance.
* WebCore.xcodeproj/project.pbxproj:
* bindings/scripts/CodeGeneratorJS.pm:
(GetGnuVTableOffsetForType): Added ApplePaySession to the list of classes that need a vtable
offset of 3.

LayoutTests:

Copied payment-request-abort-method.https.html and payment-request-show-method.https.html
from web-platform-tests/payment-request/ and changed the payment method from basic-card to
Apple Pay. This needs to eventually be upstreamed back to WPT.

* TestExpectations:
* http/tests/paymentrequest/payment-request-abort-method.https-expected.txt: Added.
* http/tests/paymentrequest/payment-request-abort-method.https.html: Added.
* http/tests/paymentrequest/payment-request-show-method.https-expected.txt: Added.
* http/tests/paymentrequest/payment-request-show-method.https.html: Added.
* platform/ios-wk2/TestExpectations:
* platform/mac-wk2/TestExpectations:

Modified Paths

Added Paths

Removed Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (223020 => 223021)


--- trunk/LayoutTests/ChangeLog	2017-10-07 07:04:07 UTC (rev 223020)
+++ trunk/LayoutTests/ChangeLog	2017-10-07 19:24:04 UTC (rev 223021)
@@ -1,3 +1,23 @@
+2017-10-07  Andy Estes  <[email protected]>
+
+        [Payment Request] Implement PaymentRequest.show() and PaymentRequest.hide()
+        https://bugs.webkit.org/show_bug.cgi?id=178043
+        <rdar://problem/34076639>
+
+        Reviewed by Tim Horton.
+
+        Copied payment-request-abort-method.https.html and payment-request-show-method.https.html
+        from web-platform-tests/payment-request/ and changed the payment method from basic-card to
+        Apple Pay. This needs to eventually be upstreamed back to WPT.
+
+        * TestExpectations:
+        * http/tests/paymentrequest/payment-request-abort-method.https-expected.txt: Added.
+        * http/tests/paymentrequest/payment-request-abort-method.https.html: Added.
+        * http/tests/paymentrequest/payment-request-show-method.https-expected.txt: Added.
+        * http/tests/paymentrequest/payment-request-show-method.https.html: Added.
+        * platform/ios-wk2/TestExpectations:
+        * platform/mac-wk2/TestExpectations:
+
 2017-10-06  Sam Weinig  <[email protected]>
 
         Remove global-constructors-attributes tests

Modified: trunk/LayoutTests/TestExpectations (223020 => 223021)


--- trunk/LayoutTests/TestExpectations	2017-10-07 07:04:07 UTC (rev 223020)
+++ trunk/LayoutTests/TestExpectations	2017-10-07 19:24:04 UTC (rev 223021)
@@ -146,6 +146,7 @@
 fast/text/font-lookup-dot-prefix-case-sensitive.html [ Skip ]
 
 # Payment Request is only enabled on Cocoa platforms.
+http/tests/paymentrequest [ Skip ]
 imported/w3c/web-platform-tests/payment-request [ Skip ]
 
 imported/w3c/web-platform-tests/2dcontext/transformations/canvas_transformations_reset_001.html [ ImageOnlyFailure ]

Added: trunk/LayoutTests/http/tests/paymentrequest/payment-request-abort-method.https-expected.txt (0 => 223021)


--- trunk/LayoutTests/http/tests/paymentrequest/payment-request-abort-method.https-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/http/tests/paymentrequest/payment-request-abort-method.https-expected.txt	2017-10-07 19:24:04 UTC (rev 223021)
@@ -0,0 +1,5 @@
+
+PASS Throws if the promise [[state]] is not "interactive" 
+PASS Calling abort must not change the [[state]] until after "interactive" 
+PASS calling .abort() causes acceptPromise to reject and closes the request. 
+

Added: trunk/LayoutTests/http/tests/paymentrequest/payment-request-abort-method.https.html (0 => 223021)


--- trunk/LayoutTests/http/tests/paymentrequest/payment-request-abort-method.https.html	                        (rev 0)
+++ trunk/LayoutTests/http/tests/paymentrequest/payment-request-abort-method.https.html	2017-10-07 19:24:04 UTC (rev 223021)
@@ -0,0 +1,76 @@
+<!DOCTYPE html>
+<!--  Copyright © 2017 Chromium authors and World Wide Web Consortium, (Massachusetts Institute of Technology, ERCIM, Keio University, Beihang).  -->
+<!--  Copyright (C) 2017 Apple Inc. All rights reserved.  -->
+<!-- FIXME: Upstream this test to web-platform-tests/payment-request/. -->
+<meta charset="utf-8">
+<title>Test for PaymentRequest.abort() method</title>
+<link rel="help" href=""
+<script src=""
+<script src=""
+<script>
+"use strict";
+setup(() => {}, {
+  // Ignore unhandled rejections resulting from .show()'s acceptPromise
+  // not being explicitly handled.
+  allow_uncaught_exception: true,
+});
+const applePay = Object.freeze({
+    supportedMethods: "https://apple.com/apple-pay",
+    data: {
+        version: 2,
+        merchantCapabilities: ['supports3DS'],
+        supportedNetworks: ['visa', 'masterCard'],
+        countryCode: 'US',
+        currencyCode: 'USD',
+    },
+});
+const defaultMethods = Object.freeze([applePay]);
+const defaultDetails = Object.freeze({
+  total: {
+    label: "Total",
+    amount: {
+      currency: "USD",
+      value: "1.00",
+    },
+  },
+});
+
+promise_test(async t => {
+  // request is in "created" state
+  const request = new PaymentRequest(defaultMethods, defaultDetails);
+  await promise_rejects(t, "InvalidStateError", request.abort());
+}, `Throws if the promise [[state]] is not "interactive"`);
+
+promise_test(async t => {
+  // request is in "created" state.
+  const request = new PaymentRequest(defaultMethods, defaultDetails);
+  await promise_rejects(t, "InvalidStateError", request.abort());
+  // Call it again, for good measure.
+  await promise_rejects(t, "InvalidStateError", request.abort());
+  // The request's state is "created", so let's show it
+  // which changes the state to "interactive.".
+  request.show();
+  // Let's set request the state to "closed" by calling .abort()
+  try {
+    await request.abort();
+  } catch (err) {
+    assert_true(false, "Unexpected promise rejection: " + err.message);
+  }
+  // The request is now "closed", so...
+  await promise_rejects(t, "InvalidStateError", request.abort());
+}, `Calling abort must not change the [[state]] until after "interactive"`);
+
+promise_test(async t => {
+  const request = new PaymentRequest(defaultMethods, defaultDetails);
+  const acceptPromise = request.show();
+  try {
+    await request.abort();
+  } catch (err) {
+    assert_true(false, "Unexpected promise rejection: " + err.message);
+  }
+  await promise_rejects(t, "AbortError", acceptPromise);
+  // As request is now "closed", trying to show it will fail
+  await promise_rejects(t, "InvalidStateError", request.show());
+}, "calling .abort() causes acceptPromise to reject and closes the request.");
+
+</script>

Added: trunk/LayoutTests/http/tests/paymentrequest/payment-request-show-method.https-expected.txt (0 => 223021)


--- trunk/LayoutTests/http/tests/paymentrequest/payment-request-show-method.https-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/http/tests/paymentrequest/payment-request-show-method.https-expected.txt	2017-10-07 19:24:04 UTC (rev 223021)
@@ -0,0 +1,6 @@
+
+PASS Must be possible to construct a payment request 
+PASS Throws if the promise [[state]] is not "created" 
+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. 
+

Added: trunk/LayoutTests/http/tests/paymentrequest/payment-request-show-method.https.html (0 => 223021)


--- trunk/LayoutTests/http/tests/paymentrequest/payment-request-show-method.https.html	                        (rev 0)
+++ trunk/LayoutTests/http/tests/paymentrequest/payment-request-show-method.https.html	2017-10-07 19:24:04 UTC (rev 223021)
@@ -0,0 +1,68 @@
+<!DOCTYPE html>
+<!--  Copyright © 2017 Chromium authors and World Wide Web Consortium, (Massachusetts Institute of Technology, ERCIM, Keio University, Beihang).  -->
+<!--  Copyright (C) 2017 Apple Inc. All rights reserved.  -->
+<!-- FIXME: Upstream this test to web-platform-tests/payment-request/. -->
+<meta charset="utf-8">
+<title>Test for PaymentRequest.show() method</title>
+<link rel="help" href=""
+<script src=""
+<script src=""
+<script>
+'use strict';
+const applePay = Object.freeze({
+    supportedMethods: "https://apple.com/apple-pay",
+    data: {
+        version: 2,
+        merchantCapabilities: ['supports3DS'],
+        supportedNetworks: ['visa', 'masterCard'],
+        countryCode: 'US',
+        currencyCode: 'USD',
+    },
+});
+const defaultMethods = Object.freeze([applePay]);
+const defaultDetails = Object.freeze({
+  total: {
+    label: "Total",
+    amount: {
+      currency: "USD",
+      value: "1.00",
+    },
+  },
+});
+
+test(() => {
+  try {
+    new PaymentRequest(defaultMethods, defaultDetails);
+  } catch (err) {
+    done();
+    throw err;
+  }
+}, "Must be possible to construct a payment request");
+
+
+promise_test(async t => {
+  const request = new PaymentRequest(defaultMethods, defaultDetails);
+  const acceptPromise = request.show(); // Sets state to "interactive"
+  await promise_rejects(t, "InvalidStateError", request.show());
+  await request.abort();
+  await promise_rejects(t, "AbortError", acceptPromise);
+}, `Throws if the promise [[state]] is not "created"`);
+
+promise_test(async t => {
+  const request1 = new PaymentRequest(defaultMethods, defaultDetails);
+  const request2 = new PaymentRequest(defaultMethods, defaultDetails);
+  const acceptPromise1 = request1.show();
+  const acceptPromise2 = request2.show();
+  await promise_rejects(t, "AbortError", acceptPromise2);
+  await request1.abort();
+  await promise_rejects(t, "AbortError", acceptPromise1);
+}, `If the user agent's "payment request is showing" boolean is true, then return a promise rejected with an "AbortError" DOMException.`);
+
+promise_test(async t => {
+  const request = new PaymentRequest(
+    [{ supportedMethods: "this-is-not-supported" }],
+    defaultDetails);
+  const acceptPromise = request.show();
+  await promise_rejects(t, "NotSupportedError", acceptPromise);
+}, `If payment method consultation produces no supported method of payment, then return a promise rejected with a "NotSupportedError" DOMException.`);
+</script>

Modified: trunk/LayoutTests/imported/w3c/ChangeLog (223020 => 223021)


--- trunk/LayoutTests/imported/w3c/ChangeLog	2017-10-07 07:04:07 UTC (rev 223020)
+++ trunk/LayoutTests/imported/w3c/ChangeLog	2017-10-07 19:24:04 UTC (rev 223021)
@@ -1,3 +1,14 @@
+2017-10-07  Andy Estes  <[email protected]>
+
+        [Payment Request] Implement PaymentRequest.show() and PaymentRequest.hide()
+        https://bugs.webkit.org/show_bug.cgi?id=178043
+        <rdar://problem/34076639>
+
+        Reviewed by Tim Horton.
+
+        * web-platform-tests/payment-request/payment-request-abort-method.https-expected.txt: Removed.
+        * web-platform-tests/payment-request/payment-request-show-method.https-expected.txt: Removed.
+
 2017-10-05  Andy Estes  <[email protected]>
 
         [Payment Request] Add a payment method that supports Apple Pay

Deleted: trunk/LayoutTests/imported/w3c/web-platform-tests/payment-request/payment-request-abort-method.https-expected.txt (223020 => 223021)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/payment-request/payment-request-abort-method.https-expected.txt	2017-10-07 07:04:07 UTC (rev 223020)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/payment-request/payment-request-abort-method.https-expected.txt	2017-10-07 19:24:04 UTC (rev 223021)
@@ -1,5 +0,0 @@
-
-PASS Throws if the promise [[state]] is not "interactive" 
-PASS Calling abort must not change the [[state]] until after "interactive" 
-FAIL calling .abort() causes acceptPromise to reject and closes the request. assert_throws: function "function () { throw e }" threw object "NotSupportedError: The operation is not supported." that is not a DOMException AbortError: property "code" is equal to 9, expected 20
-

Deleted: trunk/LayoutTests/imported/w3c/web-platform-tests/payment-request/payment-request-show-method.https-expected.txt (223020 => 223021)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/payment-request/payment-request-show-method.https-expected.txt	2017-10-07 07:04:07 UTC (rev 223020)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/payment-request/payment-request-show-method.https-expected.txt	2017-10-07 19:24:04 UTC (rev 223021)
@@ -1,6 +0,0 @@
-
-PASS Must be possible to construct a payment request 
-FAIL Throws if the promise [[state]] is not "created" assert_throws: function "function () { throw e }" threw object "NotSupportedError: The operation is not supported." that is not a DOMException AbortError: property "code" is equal to 9, expected 20
-FAIL If the user agent's "payment request is showing" boolean is true, then return a promise rejected with an "AbortError" DOMException. assert_throws: function "function () { throw e }" threw object "NotSupportedError: The operation is not supported." that is not a DOMException AbortError: property "code" is equal to 9, expected 20
-PASS If payment method consultation produces no supported method of payment, then return a promise rejected with a "NotSupportedError" DOMException. 
-

Modified: trunk/LayoutTests/platform/ios-wk2/TestExpectations (223020 => 223021)


--- trunk/LayoutTests/platform/ios-wk2/TestExpectations	2017-10-07 07:04:07 UTC (rev 223020)
+++ trunk/LayoutTests/platform/ios-wk2/TestExpectations	2017-10-07 19:24:04 UTC (rev 223021)
@@ -28,6 +28,7 @@
 fast/viewport/ios/viewport-fit-cover.html [ Skip ]
 fast/viewport/ios/viewport-fit-auto.html [ Skip ]
 
+http/tests/paymentrequest [ Pass ]
 imported/w3c/web-platform-tests/payment-request [ Pass ]
 webkit.org/b/175611 imported/w3c/web-platform-tests/payment-request/allowpaymentrequest/allowpaymentrequest-attribute-cross-origin-bc-containers.https.html [ Skip ]
 webkit.org/b/175611 imported/w3c/web-platform-tests/payment-request/allowpaymentrequest/no-attribute-cross-origin-bc-containers.https.html [ Skip ]
@@ -34,9 +35,11 @@
 webkit.org/b/175611 imported/w3c/web-platform-tests/payment-request/allowpaymentrequest/removing-allowpaymentrequest.https.sub.html [ Skip ]
 webkit.org/b/175611 imported/w3c/web-platform-tests/payment-request/allowpaymentrequest/setting-allowpaymentrequest-timing.https.sub.html [ Skip ]
 webkit.org/b/175611 imported/w3c/web-platform-tests/payment-request/allowpaymentrequest/setting-allowpaymentrequest.https.sub.html [ Skip ]
-webkit.org/b/177391 imported/w3c/web-platform-tests/payment-request/payment-request-show-method.https.html [ Pass Failure ]
-webkit.org/b/177391 imported/w3c/web-platform-tests/payment-request/payment-request-abort-method.https.html [ Pass Failure ]
 
+# skip in favor of tests in http/tests/paymentrequest
+imported/w3c/web-platform-tests/payment-request/payment-request-show-method.https.html [ WontFix ]
+imported/w3c/web-platform-tests/payment-request/payment-request-abort-method.https.html [ WontFix ]
+
  # skip manual payment-request tests
 imported/w3c/web-platform-tests/payment-request/algorithms-manual.https.html [ Skip ]
 imported/w3c/web-platform-tests/payment-request/change-shipping-option-manual.https.html [ Skip ]

Modified: trunk/LayoutTests/platform/mac-wk2/TestExpectations (223020 => 223021)


--- trunk/LayoutTests/platform/mac-wk2/TestExpectations	2017-10-07 07:04:07 UTC (rev 223020)
+++ trunk/LayoutTests/platform/mac-wk2/TestExpectations	2017-10-07 19:24:04 UTC (rev 223021)
@@ -25,7 +25,8 @@
 fast/visual-viewport/rubberbanding-viewport-rects.html [ Pass ]
 fast/visual-viewport/rubberbanding-viewport-rects-header-footer.html  [ Pass ]
 
-imported/w3c/web-platform-tests/payment-request [ Pass ]
+[ Sierra+ ] http/tests/paymentrequest [ Pass ]
+[ Sierra+ ] imported/w3c/web-platform-tests/payment-request [ Pass ]
 webkit.org/b/175611 imported/w3c/web-platform-tests/payment-request/allowpaymentrequest/allowpaymentrequest-attribute-cross-origin-bc-containers.https.html [ Skip ]
 webkit.org/b/175611 imported/w3c/web-platform-tests/payment-request/allowpaymentrequest/no-attribute-cross-origin-bc-containers.https.html [ Skip ]
 webkit.org/b/175611 imported/w3c/web-platform-tests/payment-request/allowpaymentrequest/removing-allowpaymentrequest.https.sub.html [ Skip ]
@@ -32,9 +33,11 @@
 webkit.org/b/175611 imported/w3c/web-platform-tests/payment-request/allowpaymentrequest/setting-allowpaymentrequest-timing.https.sub.html [ Skip ]
 webkit.org/b/175611 imported/w3c/web-platform-tests/payment-request/allowpaymentrequest/setting-allowpaymentrequest.https.sub.html [ Skip ]
 webkit.org/b/177783 imported/w3c/web-platform-tests/payment-request/rejects_if_not_active.https.html [ Skip ]
-webkit.org/b/177391 imported/w3c/web-platform-tests/payment-request/payment-request-show-method.https.html [ Pass Failure ]
-webkit.org/b/177391 imported/w3c/web-platform-tests/payment-request/payment-request-abort-method.https.html [ Pass Failure ]
 
+# skip in favor of tests in http/tests/paymentrequest
+imported/w3c/web-platform-tests/payment-request/payment-request-show-method.https.html [ WontFix ]
+imported/w3c/web-platform-tests/payment-request/payment-request-abort-method.https.html [ WontFix ]
+
 # skip manual payment-request tests
 imported/w3c/web-platform-tests/payment-request/algorithms-manual.https.html [ Skip ]
 imported/w3c/web-platform-tests/payment-request/change-shipping-option-manual.https.html [ Skip ]

Modified: trunk/Source/WebCore/ChangeLog (223020 => 223021)


--- trunk/Source/WebCore/ChangeLog	2017-10-07 07:04:07 UTC (rev 223020)
+++ trunk/Source/WebCore/ChangeLog	2017-10-07 19:24:04 UTC (rev 223021)
@@ -1,3 +1,46 @@
+2017-10-07  Andy Estes  <[email protected]>
+
+        [Payment Request] Implement PaymentRequest.show() and PaymentRequest.hide()
+        https://bugs.webkit.org/show_bug.cgi?id=178043
+        <rdar://problem/34076639>
+
+        Reviewed by Tim Horton.
+
+        Tests: http/tests/paymentrequest/payment-request-abort-method.https.html
+               http/tests/paymentrequest/payment-request-show-method.https.html
+
+        * Modules/applepay/PaymentSession.h: Virtually inherited from PaymentSessionBase to
+        accommodate ApplePayPaymentHandler inheriting from both this and PaymentHandler.
+        (WebCore::PaymentSession::~PaymentSession): Deleted.
+        * Modules/applepay/paymentrequest/ApplePayPaymentHandler.cpp:
+        (WebCore::paymentCoordinator): Virtually inherited from PaymentSessionBase to accommodate
+        ApplePayPaymentHandler inheriting from both this and PaymentSession.
+        (WebCore::ApplePayPaymentHandler::hasActiveSession): Added. Calls PaymentCoordinator::hasActiveSession().
+        (WebCore::ApplePayPaymentHandler::show): Added. Calls PaymentCoordinator::beginPaymentSession().
+        (WebCore::ApplePayPaymentHandler::hide): Added. Calls PaymentCoordinator::abortPaymentSession().
+        * Modules/applepay/paymentrequest/ApplePayPaymentHandler.h: Inherited from PaymentSession in
+        addition to PaymentHandler so that this can be PaymentCoordinator active session.
+        * Modules/paymentrequest/PaymentHandler.cpp:
+        (WebCore::PaymentHandler::create):
+        (WebCore::PaymentHandler::hasActiveSession):
+        * Modules/paymentrequest/PaymentHandler.h:
+        * Modules/paymentrequest/PaymentRequest.cpp:
+        (WebCore::PaymentRequest::~PaymentRequest):
+        (WebCore::PaymentRequest::show): Rejected the promise if PaymentCoordinator has an active session.
+        (WebCore::PaymentRequest::abort): Called stop().
+        (WebCore::PaymentRequest::canSuspendForDocumentSuspension const): Returned true if state is
+        Interactive and there is an active handler showing.
+        (WebCore::PaymentRequest::stop): Hid the active session if it's showing, then set state to
+        Closed and rejected the show promise.
+        * Modules/paymentrequest/PaymentRequest.h:
+        * Modules/paymentrequest/PaymentSessionBase.h: Added. Inherits from
+        RefCounted<PaymentSessionBase> and defines a virtual destructor. This allows subclasses to
+        virtually inherit a single ref-count to support multiple inheritance.
+        * WebCore.xcodeproj/project.pbxproj:
+        * bindings/scripts/CodeGeneratorJS.pm:
+        (GetGnuVTableOffsetForType): Added ApplePaySession to the list of classes that need a vtable
+        offset of 3.
+
 2017-10-07  Ryosuke Niwa  <[email protected]>
 
         WebContentReader::readHTML should be shared between macOS and iOS

Modified: trunk/Source/WebCore/Modules/applepay/PaymentSession.h (223020 => 223021)


--- trunk/Source/WebCore/Modules/applepay/PaymentSession.h	2017-10-07 07:04:07 UTC (rev 223020)
+++ trunk/Source/WebCore/Modules/applepay/PaymentSession.h	2017-10-07 19:24:04 UTC (rev 223021)
@@ -28,7 +28,7 @@
 #if ENABLE(APPLE_PAY)
 
 #include "ApplePaySessionPaymentRequest.h"
-#include <wtf/RefCounted.h>
+#include "PaymentSessionBase.h"
 
 namespace WebCore {
 
@@ -37,10 +37,8 @@
 class PaymentMethod;
 class URL;
 
-class PaymentSession : public RefCounted<PaymentSession> {
+class PaymentSession : public virtual PaymentSessionBase {
 public:
-    virtual ~PaymentSession() { }
-
     virtual void validateMerchant(const URL&) = 0;
     virtual void didAuthorizePayment(const Payment&) = 0;
     virtual void didSelectShippingMethod(const ApplePaySessionPaymentRequest::ShippingMethod&) = 0;

Modified: trunk/Source/WebCore/Modules/applepay/paymentrequest/ApplePayPaymentHandler.cpp (223020 => 223021)


--- trunk/Source/WebCore/Modules/applepay/paymentrequest/ApplePayPaymentHandler.cpp	2017-10-07 07:04:07 UTC (rev 223020)
+++ trunk/Source/WebCore/Modules/applepay/paymentrequest/ApplePayPaymentHandler.cpp	2017-10-07 19:24:04 UTC (rev 223021)
@@ -34,6 +34,7 @@
 #include "Document.h"
 #include "Frame.h"
 #include "JSApplePayRequest.h"
+#include "LinkIconCollector.h"
 #include "MainFrame.h"
 #include "PaymentContact.h"
 #include "PaymentCoordinator.h"
@@ -50,6 +51,16 @@
     return url.host() == "apple.com" && url.path() == "/apple-pay";
 }
 
+static inline PaymentCoordinator& paymentCoordinator(Document& document)
+{
+    return document.frame()->mainFrame().paymentCoordinator();
+}
+
+bool ApplePayPaymentHandler::hasActiveSession(Document& document)
+{
+    return paymentCoordinator(document).hasActiveSession();
+}
+
 ApplePayPaymentHandler::ApplePayPaymentHandler(PaymentRequest& paymentRequest)
     : m_paymentRequest { paymentRequest }
 {
@@ -147,11 +158,20 @@
     return { };
 }
 
-void ApplePayPaymentHandler::show()
+void ApplePayPaymentHandler::show(Document& document)
 {
-    // FIXME: Call PaymentCoordinator::beginPaymentSession() with m_applePayRequest
+    Vector<URL> linkIconURLs;
+    for (auto& icon : LinkIconCollector { document }.iconsOfTypes({ LinkIconType::TouchIcon, LinkIconType::TouchPrecomposedIcon }))
+        linkIconURLs.append(icon.url);
+
+    paymentCoordinator(document).beginPaymentSession(*this, document.url(), linkIconURLs, *m_applePayRequest);
 }
 
+void ApplePayPaymentHandler::hide(Document& document)
+{
+    paymentCoordinator(document).abortPaymentSession();
+}
+
 } // namespace WebCore
 
 #endif // ENABLE(APPLE_PAY) && ENABLE(PAYMENT_REQUEST)

Modified: trunk/Source/WebCore/Modules/applepay/paymentrequest/ApplePayPaymentHandler.h (223020 => 223021)


--- trunk/Source/WebCore/Modules/applepay/paymentrequest/ApplePayPaymentHandler.h	2017-10-07 07:04:07 UTC (rev 223020)
+++ trunk/Source/WebCore/Modules/applepay/paymentrequest/ApplePayPaymentHandler.h	2017-10-07 19:24:04 UTC (rev 223021)
@@ -29,26 +29,36 @@
 
 #include "ApplePaySessionPaymentRequest.h"
 #include "PaymentHandler.h"
+#include "PaymentSession.h"
 #include <wtf/Noncopyable.h>
 #include <wtf/Ref.h>
 
 namespace WebCore {
 
-class Document;
 class PaymentRequest;
 
-class ApplePayPaymentHandler final : public PaymentHandler {
-    WTF_MAKE_NONCOPYABLE(ApplePayPaymentHandler);
+class ApplePayPaymentHandler final : public PaymentHandler, public PaymentSession {
 public:
     static bool handlesIdentifier(const PaymentRequest::MethodIdentifier&);
+    static bool hasActiveSession(Document&);
 
 private:
-    friend std::unique_ptr<ApplePayPaymentHandler> std::make_unique<ApplePayPaymentHandler>(PaymentRequest&);
+    friend class PaymentHandler;
     explicit ApplePayPaymentHandler(PaymentRequest&);
 
+    // PaymentHandler
     ExceptionOr<void> convertData(JSC::ExecState&, JSC::JSValue&&) final;
-    void show() final;
+    void show(Document&) final;
+    void hide(Document&) final;
 
+    // PaymentSession
+    void validateMerchant(const URL&) final { }
+    void didAuthorizePayment(const Payment&) final { }
+    void didSelectShippingMethod(const ApplePaySessionPaymentRequest::ShippingMethod&) final { }
+    void didSelectShippingContact(const PaymentContact&) final { }
+    void didSelectPaymentMethod(const PaymentMethod&) final { }
+    void didCancelPaymentSession() final { }
+
     Ref<PaymentRequest> m_paymentRequest;
     std::optional<ApplePaySessionPaymentRequest> m_applePayRequest;
 };

Modified: trunk/Source/WebCore/Modules/paymentrequest/PaymentHandler.cpp (223020 => 223021)


--- trunk/Source/WebCore/Modules/paymentrequest/PaymentHandler.cpp	2017-10-07 07:04:07 UTC (rev 223020)
+++ trunk/Source/WebCore/Modules/paymentrequest/PaymentHandler.cpp	2017-10-07 19:24:04 UTC (rev 223021)
@@ -34,11 +34,11 @@
 
 namespace WebCore {
 
-std::unique_ptr<PaymentHandler> PaymentHandler::create(PaymentRequest& paymentRequest, const PaymentRequest::MethodIdentifier& identifier)
+RefPtr<PaymentHandler> PaymentHandler::create(PaymentRequest& paymentRequest, const PaymentRequest::MethodIdentifier& identifier)
 {
 #if ENABLE(APPLE_PAY)
     if (ApplePayPaymentHandler::handlesIdentifier(identifier))
-        return std::make_unique<ApplePayPaymentHandler>(paymentRequest);
+        return adoptRef(new ApplePayPaymentHandler(paymentRequest));
 #else
     UNUSED_PARAM(paymentRequest);
     UNUSED_PARAM(identifier);
@@ -47,6 +47,16 @@
     return nullptr;
 }
 
+bool PaymentHandler::hasActiveSession(Document& document)
+{
+#if ENABLE(APPLE_PAY)
+    return ApplePayPaymentHandler::hasActiveSession(document);
+#else
+    UNUSED_PARAM(document);
+    return false;
+#endif
+}
+
 } // namespace WebCore
 
 #endif // ENABLE(PAYMENT_REQUEST)

Modified: trunk/Source/WebCore/Modules/paymentrequest/PaymentHandler.h (223020 => 223021)


--- trunk/Source/WebCore/Modules/paymentrequest/PaymentHandler.h	2017-10-07 07:04:07 UTC (rev 223020)
+++ trunk/Source/WebCore/Modules/paymentrequest/PaymentHandler.h	2017-10-07 19:24:04 UTC (rev 223021)
@@ -28,6 +28,7 @@
 #if ENABLE(PAYMENT_REQUEST)
 
 #include "PaymentRequest.h"
+#include "PaymentSessionBase.h"
 
 namespace JSC {
 class ExecState;
@@ -36,13 +37,16 @@
 
 namespace WebCore {
 
-class PaymentHandler {
+class Document;
+
+class PaymentHandler : public virtual PaymentSessionBase {
 public:
-    static std::unique_ptr<PaymentHandler> create(PaymentRequest&, const PaymentRequest::MethodIdentifier&);
-    virtual ~PaymentHandler() = default;
+    static RefPtr<PaymentHandler> create(PaymentRequest&, const PaymentRequest::MethodIdentifier&);
+    static bool hasActiveSession(Document&);
 
     virtual ExceptionOr<void> convertData(JSC::ExecState&, JSC::JSValue&&) = 0;
-    virtual void show() = 0;
+    virtual void show(Document&) = 0;
+    virtual void hide(Document&) = 0;
 };
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/Modules/paymentrequest/PaymentRequest.cpp (223020 => 223021)


--- trunk/Source/WebCore/Modules/paymentrequest/PaymentRequest.cpp	2017-10-07 07:04:07 UTC (rev 223020)
+++ trunk/Source/WebCore/Modules/paymentrequest/PaymentRequest.cpp	2017-10-07 19:24:04 UTC (rev 223021)
@@ -336,6 +336,7 @@
 
 PaymentRequest::~PaymentRequest()
 {
+    ASSERT(!m_activePaymentHandler);
 }
 
 // https://www.w3.org/TR/payment-request/#show()-method
@@ -349,16 +350,20 @@
         return;
     }
 
-    // FIXME: Reject promise with AbortError if PaymentCoordinator already has an active session.
+    auto& document = downcast<Document>(*scriptExecutionContext());
+    if (PaymentHandler::hasActiveSession(document)) {
+        promise.reject(Exception { AbortError });
+        return;
+    }
 
     m_state = State::Interactive;
     ASSERT(!m_showPromise);
     m_showPromise = WTFMove(promise);
 
-    std::unique_ptr<PaymentHandler> selectedPaymentHandler;
+    RefPtr<PaymentHandler> selectedPaymentHandler;
     for (auto& paymentMethod : m_serializedMethodData) {
-        auto scope = DECLARE_THROW_SCOPE(scriptExecutionContext()->vm());
-        JSC::JSValue data = "" paymentMethod.serializedData);
+        auto scope = DECLARE_THROW_SCOPE(document.vm());
+        JSC::JSValue data = "" paymentMethod.serializedData);
         if (scope.exception()) {
             m_showPromise->reject(Exception { ExistingExceptionError });
             return;
@@ -368,7 +373,7 @@
         if (!handler)
             continue;
 
-        auto result = handler->convertData(*scriptExecutionContext()->execState(), WTFMove(data));
+        auto result = handler->convertData(*document.execState(), WTFMove(data));
         if (result.hasException()) {
             m_showPromise->reject(result.releaseException());
             return;
@@ -383,7 +388,11 @@
         return;
     }
 
-    selectedPaymentHandler->show();
+    ASSERT(!m_activePaymentHandler);
+    m_activePaymentHandler = WTFMove(selectedPaymentHandler);
+
+    m_activePaymentHandler->show(document);
+    setPendingActivity(this);
 }
 
 // https://www.w3.org/TR/payment-request/#abort()-method
@@ -392,9 +401,7 @@
     if (m_state != State::Interactive)
         return Exception { InvalidStateError };
 
-    m_state = State::Closed;
-    ASSERT(m_showPromise);
-    m_showPromise->reject(Exception { AbortError });
+    stop();
     promise.resolve();
     return { };
 }
@@ -423,6 +430,33 @@
     return std::nullopt;
 }
 
+bool PaymentRequest::canSuspendForDocumentSuspension() const
+{
+    switch (m_state) {
+    case State::Created:
+    case State::Closed:
+        ASSERT(!m_activePaymentHandler);
+        return true;
+    case State::Interactive:
+        return !m_activePaymentHandler;
+    }
+}
+
+void PaymentRequest::stop()
+{
+    if (m_state != State::Interactive)
+        return;
+
+    if (auto paymentHandler = std::exchange(m_activePaymentHandler, nullptr)) {
+        unsetPendingActivity(this);
+        paymentHandler->hide(downcast<Document>(*scriptExecutionContext()));
+    }
+
+    ASSERT(m_state == State::Interactive);
+    m_state = State::Closed;
+    m_showPromise->reject(Exception { AbortError });
+}
+
 } // namespace WebCore
 
 #endif // ENABLE(PAYMENT_REQUEST)

Modified: trunk/Source/WebCore/Modules/paymentrequest/PaymentRequest.h (223020 => 223021)


--- trunk/Source/WebCore/Modules/paymentrequest/PaymentRequest.h	2017-10-07 07:04:07 UTC (rev 223020)
+++ trunk/Source/WebCore/Modules/paymentrequest/PaymentRequest.h	2017-10-07 19:24:04 UTC (rev 223021)
@@ -40,6 +40,7 @@
 
 class Document;
 class PaymentAddress;
+class PaymentHandler;
 class PaymentResponse;
 enum class PaymentShippingType;
 struct PaymentMethodData;
@@ -85,8 +86,8 @@
 
     // ActiveDOMObject
     const char* activeDOMObjectName() const final { return "PaymentRequest"; }
-    bool canSuspendForDocumentSuspension() const final { return true; }
-    void stop() final { }
+    bool canSuspendForDocumentSuspension() const final;
+    void stop() final;
 
     // EventTarget
     EventTargetInterface eventTargetInterface() const final { return PaymentRequestEventTargetInterfaceType; }
@@ -102,8 +103,8 @@
     RefPtr<PaymentAddress> m_shippingAddress;
     State m_state { State::Created };
     std::optional<ShowPromise> m_showPromise;
-    std::optional<AbortPromise> m_abortPromise;
     std::optional<CanMakePaymentPromise> m_canMakePaymentPromise;
+    RefPtr<PaymentHandler> m_activePaymentHandler;
 };
 
 std::optional<PaymentRequest::MethodIdentifier> convertAndValidatePaymentMethodIdentifier(const String& identifier);

Copied: trunk/Source/WebCore/Modules/paymentrequest/PaymentSessionBase.h (from rev 223020, trunk/Source/WebCore/Modules/paymentrequest/PaymentHandler.h) (0 => 223021)


--- trunk/Source/WebCore/Modules/paymentrequest/PaymentSessionBase.h	                        (rev 0)
+++ trunk/Source/WebCore/Modules/paymentrequest/PaymentSessionBase.h	2017-10-07 19:24:04 UTC (rev 223021)
@@ -0,0 +1,40 @@
+/*
+ * Copyright (C) 2017 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.
+ */
+
+#pragma once
+
+#if ENABLE(APPLE_PAY) || ENABLE(PAYMENT_REQUEST)
+
+#include <wtf/RefCounted.h>
+
+namespace WebCore {
+
+struct PaymentSessionBase : RefCounted<PaymentSessionBase> {
+    virtual ~PaymentSessionBase() = default;
+};
+
+} // namespace WebCore
+
+#endif // ENABLE(APPLE_PAY) || ENABLE(PAYMENT_REQUEST)

Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (223020 => 223021)


--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2017-10-07 07:04:07 UTC (rev 223020)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2017-10-07 19:24:04 UTC (rev 223021)
@@ -4438,6 +4438,7 @@
 		A17C81220F2A5CF7005DAAEB /* HTMLElementFactory.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A17C81200F2A5CF7005DAAEB /* HTMLElementFactory.cpp */; };
 		A17C81230F2A5CF7005DAAEB /* HTMLElementFactory.h in Headers */ = {isa = PBXBuildFile; fileRef = A17C81210F2A5CF7005DAAEB /* HTMLElementFactory.h */; };
 		A17D275E1EAC579800BF01E7 /* MediaSelectionOption.h in Headers */ = {isa = PBXBuildFile; fileRef = A17D275D1EAC579800BF01E7 /* MediaSelectionOption.h */; settings = {ATTRIBUTES = (Private, ); }; };
+		A17FEE641F8893220021E811 /* PaymentSessionBase.h in Headers */ = {isa = PBXBuildFile; fileRef = A17FEE631F8893220021E811 /* PaymentSessionBase.h */; };
 		A182D5B71BE722670087A7CC /* SettingsCocoa.mm in Sources */ = {isa = PBXBuildFile; fileRef = A182D5B61BE722620087A7CC /* SettingsCocoa.mm */; };
 		A185B4291E8211A100DC9118 /* PreviewLoader.mm in Sources */ = {isa = PBXBuildFile; fileRef = A185B4271E8211A100DC9118 /* PreviewLoader.mm */; };
 		A185B42A1E8211A100DC9118 /* PreviewLoader.h in Headers */ = {isa = PBXBuildFile; fileRef = A185B4281E8211A100DC9118 /* PreviewLoader.h */; settings = {ATTRIBUTES = (Private, ); }; };
@@ -12922,6 +12923,7 @@
 		A17C81200F2A5CF7005DAAEB /* HTMLElementFactory.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = HTMLElementFactory.cpp; sourceTree = "<group>"; };
 		A17C81210F2A5CF7005DAAEB /* HTMLElementFactory.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HTMLElementFactory.h; sourceTree = "<group>"; };
 		A17D275D1EAC579800BF01E7 /* MediaSelectionOption.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MediaSelectionOption.h; sourceTree = "<group>"; };
+		A17FEE631F8893220021E811 /* PaymentSessionBase.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = PaymentSessionBase.h; sourceTree = "<group>"; };
 		A182D5B61BE722620087A7CC /* SettingsCocoa.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = SettingsCocoa.mm; sourceTree = "<group>"; };
 		A185B4271E8211A100DC9118 /* PreviewLoader.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = PreviewLoader.mm; sourceTree = "<group>"; };
 		A185B4281E8211A100DC9118 /* PreviewLoader.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PreviewLoader.h; sourceTree = "<group>"; };
@@ -21764,6 +21766,7 @@
 				A1F76B3B1F44CF240014C318 /* PaymentResponse.cpp */,
 				A1F76B3A1F44CF240014C318 /* PaymentResponse.h */,
 				A1F76B3C1F44CF240014C318 /* PaymentResponse.idl */,
+				A17FEE631F8893220021E811 /* PaymentSessionBase.h */,
 				A1F76B521F44D2C70014C318 /* PaymentShippingOption.h */,
 				A1F76B541F44D2C70014C318 /* PaymentShippingOption.idl */,
 				A1F76B461F44D07A0014C318 /* PaymentShippingType.h */,
@@ -29658,6 +29661,7 @@
 				1A8A64681D19FDFF00D0E00F /* PaymentRequestValidator.h in Headers */,
 				A1F76B3D1F44CF240014C318 /* PaymentResponse.h in Headers */,
 				A1491DA31F859D870095F5D4 /* PaymentSession.h in Headers */,
+				A17FEE641F8893220021E811 /* PaymentSessionBase.h in Headers */,
 				A1F76B551F44D2C70014C318 /* PaymentShippingOption.h in Headers */,
 				A1F76B491F44D07A0014C318 /* PaymentShippingType.h in Headers */,
 				B27535650B053814002CE64F /* PDFDocumentImage.h in Headers */,

Modified: trunk/Source/WebCore/bindings/scripts/CodeGeneratorJS.pm (223020 => 223021)


--- trunk/Source/WebCore/bindings/scripts/CodeGeneratorJS.pm	2017-10-07 07:04:07 UTC (rev 223020)
+++ trunk/Source/WebCore/bindings/scripts/CodeGeneratorJS.pm	2017-10-07 19:24:04 UTC (rev 223021)
@@ -3522,7 +3522,8 @@
 sub GetGnuVTableOffsetForType
 {
     my $typename = shift;
-    if ($typename eq "SVGAElement"
+    if ($typename eq "ApplePaySession"
+        || $typename eq "SVGAElement"
         || $typename eq "SVGCircleElement"
         || $typename eq "SVGClipPathElement"
         || $typename eq "SVGDefsElement"
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to