[Payment Request] Implement PaymentRequest.show() and PaymentRequest.hide()
authoraestes@apple.com <aestes@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 9 Oct 2017 22:40:58 +0000 (22:40 +0000)
committeraestes@apple.com <aestes@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 9 Oct 2017 22:40:58 +0000 (22:40 +0000)
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/PaymentCoordinator.h:
* 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.
* page/MainFrame.cpp:
(WebCore::MainFrame::setPaymentCoordinator): Added a setter for m_paymentCoordinator.
* page/MainFrame.h:
* testing/Internals.cpp:
(WebCore::Internals::Internals): Set the main frame's payment coordinator to a new
PaymentCoordinator with MockPaymentCoordinator as its client.
* testing/MockPaymentCoordinator.cpp: Added a mock PaymentCoordinatorClient for testing.
(WebCore::MockPaymentCoordinator::supportsVersion):
(WebCore::MockPaymentCoordinator::canMakePayments):
(WebCore::MockPaymentCoordinator::canMakePaymentsWithActiveCard):
(WebCore::MockPaymentCoordinator::openPaymentSetup):
(WebCore::MockPaymentCoordinator::showPaymentUI):
(WebCore::MockPaymentCoordinator::paymentCoordinatorDestroyed):
* testing/MockPaymentCoordinator.h: Added.

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:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@223076 268f45cc-cd09-0410-ab3c-d52691b4dbfc

28 files changed:
LayoutTests/ChangeLog
LayoutTests/TestExpectations
LayoutTests/http/tests/paymentrequest/payment-request-abort-method.https-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/paymentrequest/payment-request-abort-method.https.html [new file with mode: 0644]
LayoutTests/http/tests/paymentrequest/payment-request-show-method.https-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/paymentrequest/payment-request-show-method.https.html [new file with mode: 0644]
LayoutTests/imported/w3c/ChangeLog
LayoutTests/imported/w3c/web-platform-tests/payment-request/payment-request-abort-method.https-expected.txt [deleted file]
LayoutTests/imported/w3c/web-platform-tests/payment-request/payment-request-show-method.https-expected.txt [deleted file]
LayoutTests/platform/ios-wk2/TestExpectations
LayoutTests/platform/mac-wk2/TestExpectations
Source/WebCore/ChangeLog
Source/WebCore/Modules/applepay/PaymentCoordinator.h
Source/WebCore/Modules/applepay/PaymentSession.h
Source/WebCore/Modules/applepay/paymentrequest/ApplePayPaymentHandler.cpp
Source/WebCore/Modules/applepay/paymentrequest/ApplePayPaymentHandler.h
Source/WebCore/Modules/paymentrequest/PaymentHandler.cpp
Source/WebCore/Modules/paymentrequest/PaymentHandler.h
Source/WebCore/Modules/paymentrequest/PaymentRequest.cpp
Source/WebCore/Modules/paymentrequest/PaymentRequest.h
Source/WebCore/Modules/paymentrequest/PaymentSessionBase.h [new file with mode: 0644]
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/bindings/scripts/CodeGeneratorJS.pm
Source/WebCore/page/MainFrame.cpp
Source/WebCore/page/MainFrame.h
Source/WebCore/testing/Internals.cpp
Source/WebCore/testing/MockPaymentCoordinator.cpp [new file with mode: 0644]
Source/WebCore/testing/MockPaymentCoordinator.h [new file with mode: 0644]

index e9c7a6e..b958787 100644 (file)
@@ -1,3 +1,23 @@
+2017-10-09  Andy Estes  <aestes@apple.com>
+
+        [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-09  Youenn Fablet  <youenn@apple.com>
 
         Add quota to cache API
index 38c3017..7295066 100644 (file)
@@ -148,6 +148,7 @@ fast/text/accessibility-bold-system-font-2.html [ Skip ]
 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 ]
diff --git a/LayoutTests/http/tests/paymentrequest/payment-request-abort-method.https-expected.txt b/LayoutTests/http/tests/paymentrequest/payment-request-abort-method.https-expected.txt
new file mode 100644 (file)
index 0000000..0f138b5
--- /dev/null
@@ -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. 
+
diff --git a/LayoutTests/http/tests/paymentrequest/payment-request-abort-method.https.html b/LayoutTests/http/tests/paymentrequest/payment-request-abort-method.https.html
new file mode 100644 (file)
index 0000000..1834ad7
--- /dev/null
@@ -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="https://w3c.github.io/browser-payment-api/#abort-method">
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<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>
diff --git a/LayoutTests/http/tests/paymentrequest/payment-request-show-method.https-expected.txt b/LayoutTests/http/tests/paymentrequest/payment-request-show-method.https-expected.txt
new file mode 100644 (file)
index 0000000..0c71560
--- /dev/null
@@ -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. 
+
diff --git a/LayoutTests/http/tests/paymentrequest/payment-request-show-method.https.html b/LayoutTests/http/tests/paymentrequest/payment-request-show-method.https.html
new file mode 100644 (file)
index 0000000..b3f4b0a
--- /dev/null
@@ -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="https://w3c.github.io/browser-payment-api/#show-method">
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<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>
index 35127c9..b019977 100644 (file)
@@ -1,3 +1,14 @@
+2017-10-09  Andy Estes  <aestes@apple.com>
+
+        [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-09  Youenn Fablet  <youenn@apple.com>
 
         REGRESSION: Some bots fail to run LayoutTests due to a WPT Server error
diff --git a/LayoutTests/imported/w3c/web-platform-tests/payment-request/payment-request-abort-method.https-expected.txt b/LayoutTests/imported/w3c/web-platform-tests/payment-request/payment-request-abort-method.https-expected.txt
deleted file mode 100644 (file)
index e7d4295..0000000
+++ /dev/null
@@ -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
-
diff --git a/LayoutTests/imported/w3c/web-platform-tests/payment-request/payment-request-show-method.https-expected.txt b/LayoutTests/imported/w3c/web-platform-tests/payment-request/payment-request-show-method.https-expected.txt
deleted file mode 100644 (file)
index bf4b1c3..0000000
+++ /dev/null
@@ -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. 
-
index 41666d1..996eb0b 100644 (file)
@@ -28,14 +28,17 @@ fast/viewport/ios/viewport-fit-contain.html [ Skip ]
 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 ]
 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 ]
index f5c57c9..3088530 100644 (file)
@@ -25,15 +25,18 @@ fast/media/mq-prefers-reduced-motion-live-update.html [ Pass ]
 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 ]
 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 ]
index 569877d..f8ff2ee 100644 (file)
@@ -1,3 +1,61 @@
+2017-10-09  Andy Estes  <aestes@apple.com>
+
+        [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/PaymentCoordinator.h:
+        * 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.
+        * page/MainFrame.cpp:
+        (WebCore::MainFrame::setPaymentCoordinator): Added a setter for m_paymentCoordinator.
+        * page/MainFrame.h:
+        * testing/Internals.cpp:
+        (WebCore::Internals::Internals): Set the main frame's payment coordinator to a new
+        PaymentCoordinator with MockPaymentCoordinator as its client.
+        * testing/MockPaymentCoordinator.cpp: Added a mock PaymentCoordinatorClient for testing.
+        (WebCore::MockPaymentCoordinator::supportsVersion):
+        (WebCore::MockPaymentCoordinator::canMakePayments):
+        (WebCore::MockPaymentCoordinator::canMakePaymentsWithActiveCard):
+        (WebCore::MockPaymentCoordinator::openPaymentSetup):
+        (WebCore::MockPaymentCoordinator::showPaymentUI):
+        (WebCore::MockPaymentCoordinator::paymentCoordinatorDestroyed):
+        * testing/MockPaymentCoordinator.h: Added.
+
 2017-10-09  Youenn Fablet  <youenn@apple.com>
 
         Add quota to cache API
index 27e4fb5..8067748 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2015, 2016 Apple Inc. All rights reserved.
+ * Copyright (C) 2015-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
@@ -47,8 +47,8 @@ struct ShippingMethodUpdate;
 
 class PaymentCoordinator {
 public:
-    explicit PaymentCoordinator(PaymentCoordinatorClient&);
-    ~PaymentCoordinator();
+    WEBCORE_EXPORT explicit PaymentCoordinator(PaymentCoordinatorClient&);
+    WEBCORE_EXPORT ~PaymentCoordinator();
 
     bool supportsVersion(unsigned version);
     bool canMakePayments();
index cb700d0..1a30a1d 100644 (file)
@@ -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 PaymentContact;
 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;
index 4240682..9c5a209 100644 (file)
@@ -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 @@ bool ApplePayPaymentHandler::handlesIdentifier(const PaymentRequest::MethodIdent
     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,9 +158,18 @@ ExceptionOr<void> ApplePayPaymentHandler::convertData(JSC::ExecState& execState,
     return { };
 }
 
-void ApplePayPaymentHandler::show()
+void ApplePayPaymentHandler::show(Document& document)
+{
+    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)
 {
-    // FIXME: Call PaymentCoordinator::beginPaymentSession() with m_applePayRequest
+    paymentCoordinator(document).abortPaymentSession();
 }
 
 } // namespace WebCore
index b56c987..31820d1 100644 (file)
 
 #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;
index eb5f2e9..e7ecd14 100644 (file)
 
 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 @@ std::unique_ptr<PaymentHandler> PaymentHandler::create(PaymentRequest& paymentRe
     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)
index 8822202..5dee546 100644 (file)
@@ -28,6 +28,7 @@
 #if ENABLE(PAYMENT_REQUEST)
 
 #include "PaymentRequest.h"
+#include "PaymentSessionBase.h"
 
 namespace JSC {
 class ExecState;
@@ -36,13 +37,16 @@ class JSValue;
 
 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
index 966f812..0ca7d49 100644 (file)
@@ -336,6 +336,8 @@ PaymentRequest::PaymentRequest(Document& document, PaymentOptions&& options, Pay
 
 PaymentRequest::~PaymentRequest()
 {
+    ASSERT(!hasPendingActivity());
+    ASSERT(!m_activePaymentHandler);
 }
 
 // https://www.w3.org/TR/payment-request/#show()-method
@@ -349,16 +351,20 @@ void PaymentRequest::show(ShowPromise&& promise)
         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 = JSONParse(scriptExecutionContext()->execState(), paymentMethod.serializedData);
+        auto scope = DECLARE_THROW_SCOPE(document.vm());
+        JSC::JSValue data = JSONParse(document.execState(), paymentMethod.serializedData);
         if (scope.exception()) {
             m_showPromise->reject(Exception { ExistingExceptionError });
             return;
@@ -368,7 +374,7 @@ void PaymentRequest::show(ShowPromise&& promise)
         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 +389,11 @@ void PaymentRequest::show(ShowPromise&& promise)
         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 +402,7 @@ ExceptionOr<void> PaymentRequest::abort(AbortPromise&& promise)
     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 +431,33 @@ std::optional<PaymentShippingType> PaymentRequest::shippingType() const
     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)
index 9ceae38..ffa213f 100644 (file)
@@ -40,6 +40,7 @@ namespace WebCore {
 
 class Document;
 class PaymentAddress;
+class PaymentHandler;
 class PaymentResponse;
 enum class PaymentShippingType;
 struct PaymentMethodData;
@@ -85,8 +86,8 @@ private:
 
     // 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 @@ private:
     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);
diff --git a/Source/WebCore/Modules/paymentrequest/PaymentSessionBase.h b/Source/WebCore/Modules/paymentrequest/PaymentSessionBase.h
new file mode 100644 (file)
index 0000000..cdfa03e
--- /dev/null
@@ -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)
index a1ae459..de92a89 100644 (file)
                517A534E1F54A8BA00DCDC0A /* ServiceWorkerRegistrationData.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 517A534B1F549D4A00DCDC0A /* ServiceWorkerRegistrationData.cpp */; };
                517A534F1F54A8BA00DCDC0A /* ServiceWorkerRegistrationData.h in Headers */ = {isa = PBXBuildFile; fileRef = 517A534C1F549D4A00DCDC0A /* ServiceWorkerRegistrationData.h */; settings = {ATTRIBUTES = (Private, ); }; };
                517A53581F5889E800DCDC0A /* FetchLoaderClient.h in Headers */ = {isa = PBXBuildFile; fileRef = 4147E2B61C89912600A7E715 /* FetchLoaderClient.h */; settings = {ATTRIBUTES = (Private, ); }; };
-               517A535A1F5889EF00DCDC0A /* FetchLoader.h in Headers */ = {isa = PBXBuildFile; fileRef = 4147E2B51C89912600A7E715 /* FetchLoader.h */; settings = {ATTRIBUTES = (Private, ); }; };
                517A535B1F588A4C00DCDC0A /* FetchBodyConsumer.h in Headers */ = {isa = PBXBuildFile; fileRef = 41CF8BE51D46222000707DC9 /* FetchBodyConsumer.h */; settings = {ATTRIBUTES = (Private, ); }; };
                517A535D1F5899FE00DCDC0A /* ServiceWorkerFetchResult.h in Headers */ = {isa = PBXBuildFile; fileRef = 517A535C1F5899F200DCDC0A /* ServiceWorkerFetchResult.h */; settings = {ATTRIBUTES = (Private, ); }; };
                517A63C31B74318700E7DCDC /* KeyedDecoderCF.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 517A63BF1B74317E00E7DCDC /* KeyedDecoderCF.cpp */; };
                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, ); }; };
                A19D934A1AA11B1E00B46C24 /* NetworkExtensionContentFilter.mm in Sources */ = {isa = PBXBuildFile; fileRef = A19D93481AA11B1E00B46C24 /* NetworkExtensionContentFilter.mm */; };
                A19D934B1AA11B1E00B46C24 /* NetworkExtensionContentFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = A19D93491AA11B1E00B46C24 /* NetworkExtensionContentFilter.h */; };
                A1AA9AB91D23911500FEADB3 /* ContentFilterBlockedPage.html in Resources */ = {isa = PBXBuildFile; fileRef = A1AA9AB81D23911500FEADB3 /* ContentFilterBlockedPage.html */; };
+               A1AFEDE61F8BFF6D0087013F /* MockPaymentCoordinator.h in Headers */ = {isa = PBXBuildFile; fileRef = A1AFEDE41F8BFF6D0087013F /* MockPaymentCoordinator.h */; };
+               A1AFEDE71F8BFF6D0087013F /* MockPaymentCoordinator.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A1AFEDE51F8BFF6D0087013F /* MockPaymentCoordinator.cpp */; };
                A1B5B29E1AAA846E008B6042 /* MockContentFilterSettings.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A1B5B29C1AAA846E008B6042 /* MockContentFilterSettings.cpp */; };
                A1B5B29F1AAA846F008B6042 /* MockContentFilterSettings.h in Headers */ = {isa = PBXBuildFile; fileRef = A1B5B29D1AAA846E008B6042 /* MockContentFilterSettings.h */; settings = {ATTRIBUTES = (Private, ); }; };
                A1BF6B821AA96C7D00AF4A8A /* MockContentFilter.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A1BF6B801AA96C7D00AF4A8A /* MockContentFilter.cpp */; };
                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>"; };
                A19D93481AA11B1E00B46C24 /* NetworkExtensionContentFilter.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = NetworkExtensionContentFilter.mm; sourceTree = "<group>"; };
                A19D93491AA11B1E00B46C24 /* NetworkExtensionContentFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NetworkExtensionContentFilter.h; sourceTree = "<group>"; };
                A1AA9AB81D23911500FEADB3 /* ContentFilterBlockedPage.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = ContentFilterBlockedPage.html; sourceTree = "<group>"; };
+               A1AFEDE41F8BFF6D0087013F /* MockPaymentCoordinator.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MockPaymentCoordinator.h; sourceTree = "<group>"; };
+               A1AFEDE51F8BFF6D0087013F /* MockPaymentCoordinator.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = MockPaymentCoordinator.cpp; sourceTree = "<group>"; };
                A1B5B29C1AAA846E008B6042 /* MockContentFilterSettings.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MockContentFilterSettings.cpp; sourceTree = "<group>"; };
                A1B5B29D1AAA846E008B6042 /* MockContentFilterSettings.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MockContentFilterSettings.h; sourceTree = "<group>"; };
                A1BF6B801AA96C7D00AF4A8A /* MockContentFilter.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MockContentFilter.cpp; sourceTree = "<group>"; };
                                2D6F3E8C1C1ECB1C0061DBD4 /* MockPageOverlay.idl */,
                                2DAAE32C19DCAF6000E002D2 /* MockPageOverlayClient.cpp */,
                                2DAAE32D19DCAF6000E002D2 /* MockPageOverlayClient.h */,
+                               A1AFEDE51F8BFF6D0087013F /* MockPaymentCoordinator.cpp */,
+                               A1AFEDE41F8BFF6D0087013F /* MockPaymentCoordinator.h */,
                                A14061891E2ECA0A0032B34E /* MockPreviewLoaderClient.cpp */,
                                A140618A1E2ECA0A0032B34E /* MockPreviewLoaderClient.h */,
                                EB081CD81696084400553730 /* TypeConversions.h */,
                                A1F76B3B1F44CF240014C318 /* PaymentResponse.cpp */,
                                A1F76B3A1F44CF240014C318 /* PaymentResponse.h */,
                                A1F76B3C1F44CF240014C318 /* PaymentResponse.idl */,
+                               A17FEE631F8893220021E811 /* PaymentSessionBase.h */,
                                A1F76B521F44D2C70014C318 /* PaymentShippingOption.h */,
                                A1F76B541F44D2C70014C318 /* PaymentShippingOption.idl */,
                                A1F76B461F44D07A0014C318 /* PaymentShippingType.h */,
                                6E4ABCD3138EA0B70071D291 /* JSHTMLUnknownElement.h */,
                                E446140E0CD6826900FADA75 /* JSHTMLVideoElement.cpp */,
                                E446140F0CD6826900FADA75 /* JSHTMLVideoElement.h */,
-                               7C7903B71F86FDE400463A70 /* JSImageBitmapRenderingContext.cpp */,
-                               7C7903B81F86FDE600463A70 /* JSImageBitmapRenderingContext.h */,
                                31D26BC61F86D269008FF255 /* JSImageBitmap.cpp */,
                                31D26BC31F86D265008FF255 /* JSImageBitmap.h */,
                                31D26BC41F86D266008FF255 /* JSImageBitmapOptions.cpp */,
                                31D26BC51F86D268008FF255 /* JSImageBitmapOptions.h */,
+                               7C7903B71F86FDE400463A70 /* JSImageBitmapRenderingContext.cpp */,
+                               7C7903B81F86FDE600463A70 /* JSImageBitmapRenderingContext.h */,
                                A77979240D6B9E64003851B9 /* JSImageData.cpp */,
                                A77979250D6B9E64003851B9 /* JSImageData.h */,
                                7C193BFB1F5E10C40088F3E6 /* JSImageSmoothingQuality.cpp */,
                                4157EBFB1E3AB67F00AC9FE9 /* MockLibWebRTCPeerConnection.h in Headers */,
                                2D6F3E911C1ECB2F0061DBD4 /* MockPageOverlay.h in Headers */,
                                2D97F04819DD4140001EE9C3 /* MockPageOverlayClient.h in Headers */,
+                               A1AFEDE61F8BFF6D0087013F /* MockPaymentCoordinator.h in Headers */,
                                A140618C1E2ECA0A0032B34E /* MockPreviewLoaderClient.h in Headers */,
                                AA5F3B8D16CC33D100455EB0 /* PlatformSpeechSynthesizerMock.h in Headers */,
                                A1763F3F1E205234001D58DE /* WebArchiveDumpSupport.h in Headers */,
                                84730D851248F0B300D3A9C9 /* FEMorphology.h in Headers */,
                                84730D871248F0B300D3A9C9 /* FEOffset.h in Headers */,
                                84730D891248F0B300D3A9C9 /* FESpecularLighting.h in Headers */,
+                               517A535B1F588A4C00DCDC0A /* FetchBodyConsumer.h in Headers */,
                                4129C9971F59B963009D7403 /* FetchBodySource.h in Headers */,
                                41D129DB1F3D143800D15E47 /* FetchHeaders.h in Headers */,
+                               517A53581F5889E800DCDC0A /* FetchLoaderClient.h in Headers */,
                                41AD753A1CEF6BD100A31486 /* FetchOptions.h in Headers */,
                                7CE1914D1F2A9AFB00272F78 /* FetchReferrerPolicy.h in Headers */,
                                7CE1915A1F2A9B3400272F78 /* FetchRequestCache.h in Headers */,
                                93F198E508245E59001E9ABC /* HTMLDocument.h in Headers */,
                                977B3867122883E900B81FF8 /* HTMLDocumentParser.h in Headers */,
                                93F198E608245E59001E9ABC /* HTMLElement.h in Headers */,
-                               517A53581F5889E800DCDC0A /* FetchLoaderClient.h in Headers */,
                                A17C81230F2A5CF7005DAAEB /* HTMLElementFactory.h in Headers */,
                                977B37241228721700B81FF8 /* HTMLElementStack.h in Headers */,
                                B562DB6017D3CD630010AF96 /* HTMLElementTypeHelpers.h in Headers */,
                                B6566270120B1227006EA85C /* JSIDBTransaction.h in Headers */,
                                838EF53C1DC14A7C008F0C39 /* JSIDBTransactionMode.h in Headers */,
                                269239961505E1AA009E57FC /* JSIDBVersionChangeEvent.h in Headers */,
+                               7C7761AA1F878AA500F869FC /* JSImageBitmapRenderingContext.h in Headers */,
                                A77979290D6B9E64003851B9 /* JSImageData.h in Headers */,
                                7C193C011F5E11050088F3E6 /* JSImageSmoothingQuality.h in Headers */,
                                A86629D309DA2B48009633A6 /* JSInputEvent.h in Headers */,
                                FA654A6C1108ABED002626F1 /* MathMLUnderOverElement.h in Headers */,
                                37C738EF1EDBD71B003F2B0B /* MathMLUnknownElement.h in Headers */,
                                439046EA12DA25E812AF80AC /* MathOperator.h in Headers */,
-                               517A535B1F588A4C00DCDC0A /* FetchBodyConsumer.h in Headers */,
                                49D5DC2C0F423A73008F20FD /* Matrix3DTransformOperation.h in Headers */,
                                49E911C70EF86D47009D0CAF /* MatrixTransformOperation.h in Headers */,
                                5CBC8DAD1AAA302200E1C803 /* MediaAccessibilitySoftLink.h in Headers */,
                                CDC8B5A7180474F70016E685 /* MediaSourcePrivateAVFObjC.h in Headers */,
                                CDDC1E7A18A952F30027A9D4 /* MediaSourcePrivateClient.h in Headers */,
                                CD61FE681794AADB004101EB /* MediaSourceRegistry.h in Headers */,
-                               7C7761AA1F878AA500F869FC /* JSImageBitmapRenderingContext.h in Headers */,
                                078E091517D14D1C00420AA1 /* MediaStream.h in Headers */,
                                078E094C17D1709600420AA1 /* MediaStreamAudioDestinationNode.h in Headers */,
                                0783228518013ED800999E0C /* MediaStreamAudioSource.h in Headers */,
                                656D37430ADBA5DE00A4554D /* NetscapePlugInStreamLoader.h in Headers */,
                                A19D934B1AA11B1E00B46C24 /* NetworkExtensionContentFilter.h in Headers */,
                                628D214C12131ED10055DCFC /* NetworkingContext.h in Headers */,
-                               517A535D1F5899FE00DCDC0A /* ServiceWorkerFetchResult.h in Headers */,
                                8A81BF8511DCFD9000DA2B98 /* NetworkLoadMetrics.h in Headers */,
                                59C27F07138D28CF0079B7E2 /* NetworkResourcesData.h in Headers */,
                                1A7FA6190DDA3B3A0028F8A5 /* NetworkStateNotifier.h in Headers */,
                                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 */,
                                2D93AEE319DF5641002A86C3 /* ServicesOverlayController.h in Headers */,
                                51F1755D1F3EBC8300C74950 /* ServiceWorker.h in Headers */,
                                51F1755F1F3EBC8300C74950 /* ServiceWorkerContainer.h in Headers */,
+                               517A535D1F5899FE00DCDC0A /* ServiceWorkerFetchResult.h in Headers */,
                                51F175611F3EBC8300C74950 /* ServiceWorkerGlobalScope.h in Headers */,
                                51F175631F3EBC8300C74950 /* ServiceWorkerJob.h in Headers */,
                                51F175641F3EBC8300C74950 /* ServiceWorkerJobClient.h in Headers */,
                                4157EBFA1E3AB67900AC9FE9 /* MockLibWebRTCPeerConnection.cpp in Sources */,
                                2D6F3E901C1ECB270061DBD4 /* MockPageOverlay.cpp in Sources */,
                                2D97F04719DD413C001EE9C3 /* MockPageOverlayClient.cpp in Sources */,
+                               A1AFEDE71F8BFF6D0087013F /* MockPaymentCoordinator.cpp in Sources */,
                                A140618B1E2ECA0A0032B34E /* MockPreviewLoaderClient.cpp in Sources */,
                                AA5F3B8F16CC4B3900455EB0 /* PlatformSpeechSynthesizerMock.cpp in Sources */,
                                A1763F3E1E205234001D58DE /* WebArchiveDumpSupport.mm in Sources */,
                                4A6E9FC313C17D1D0046A7F8 /* CSSFontFeatureValue.cpp in Sources */,
                                BC64B4DB0CB4298A005F2B62 /* CSSFontSelector.cpp in Sources */,
                                C2E38F011E84573500CA3ADF /* CSSFontStyleRangeValue.cpp in Sources */,
-                               7C7761A81F878A8B00F869FC /* JSImageBitmapRenderingContext.cpp in Sources */,
                                C2E38EFD1E8396FD00CA3ADF /* CSSFontStyleValue.cpp in Sources */,
                                A80E6CF10A1989CA007FB8C5 /* CSSFontValue.cpp in Sources */,
                                C21DF2E91D9E4E9900F5B24C /* CSSFontVariationValue.cpp in Sources */,
                                C3CF17A415B0063F00276D39 /* IdTargetObserver.cpp in Sources */,
                                C3CF17A615B0063F00276D39 /* IdTargetObserverRegistry.cpp in Sources */,
                                B275356F0B053814002CE64F /* Image.cpp in Sources */,
-                               7C7903B41F86F95C00463A70 /* ImageBitmapRenderingContext.cpp in Sources */,
                                31D26BCB1F87065B008FF255 /* ImageBitmap.cpp in Sources */,
+                               7C7903B41F86F95C00463A70 /* ImageBitmapRenderingContext.cpp in Sources */,
                                43D2597713C816F400608559 /* ImageBuffer.cpp in Sources */,
                                B2A10B940B3818D700099AA4 /* ImageBufferCG.cpp in Sources */,
                                2292B27C1356669400CF11EF /* ImageBufferDataCG.cpp in Sources */,
                                511EF2CB17F0FD3500E4FA16 /* JSIDBVersionChangeEvent.cpp in Sources */,
                                31D26BC81F87063D008FF255 /* JSImageBitmap.cpp in Sources */,
                                31D26BCA1F870645008FF255 /* JSImageBitmapOptions.cpp in Sources */,
+                               7C7761A81F878A8B00F869FC /* JSImageBitmapRenderingContext.cpp in Sources */,
                                A77979280D6B9E64003851B9 /* JSImageData.cpp in Sources */,
                                A7D0318E0E93540300E24ACD /* JSImageDataCustom.cpp in Sources */,
                                7C193C001F5E11050088F3E6 /* JSImageSmoothingQuality.cpp in Sources */,
index c5a87c2..c7d8eea 100644 (file)
@@ -3522,7 +3522,8 @@ sub GetGnuMangledNameForInterface
 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"
index 5544ab0..7209926 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2013-2016 Apple Inc. All rights reserved.
+ * Copyright (C) 2013-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
@@ -137,4 +137,11 @@ void MainFrame::removeLatchingStateForTarget(Element& targetNode)
 }
 #endif
 
+#if ENABLE(APPLE_PAY)
+void MainFrame::setPaymentCoordinator(std::unique_ptr<PaymentCoordinator>&& paymentCoordinator)
+{
+    m_paymentCoordinator = WTFMove(paymentCoordinator);
+}
+#endif
+
 }
index 5a75c5a..42cc739 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2013-2014 Apple Inc. All rights reserved.
+ * Copyright (C) 2013-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
@@ -64,6 +64,7 @@ public:
 
 #if ENABLE(APPLE_PAY)
     PaymentCoordinator& paymentCoordinator() const { return *m_paymentCoordinator; }
+    WEBCORE_EXPORT void setPaymentCoordinator(std::unique_ptr<PaymentCoordinator>&&);
 #endif
 
     PerformanceLogging& performanceLogging() const { return *m_performanceLogging; }
index 9725869..0500d14 100644 (file)
 #include "PreviewLoader.h"
 #endif
 
+#if ENABLE(APPLE_PAY)
+#include "MockPaymentCoordinator.h"
+#include "PaymentCoordinator.h"
+#endif
+
 using JSC::CallData;
 using JSC::CallType;
 using JSC::CodeBlock;
@@ -500,6 +505,10 @@ Internals::Internals(Document& document)
     }
 
     setConsoleMessageListener(nullptr);
+
+#if ENABLE(APPLE_PAY)
+    document.frame()->mainFrame().setPaymentCoordinator(std::make_unique<PaymentCoordinator>(*new MockPaymentCoordinator()));
+#endif
 }
 
 Document* Internals::contextDocument() const
diff --git a/Source/WebCore/testing/MockPaymentCoordinator.cpp b/Source/WebCore/testing/MockPaymentCoordinator.cpp
new file mode 100644 (file)
index 0000000..ff7a4a4
--- /dev/null
@@ -0,0 +1,79 @@
+/*
+ * 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.
+ */
+
+#include "config.h"
+#include "MockPaymentCoordinator.h"
+
+#if ENABLE(APPLE_PAY)
+
+#include <wtf/RunLoop.h>
+
+namespace WebCore {
+
+bool MockPaymentCoordinator::supportsVersion(unsigned version)
+{
+    ASSERT(version > 0);
+
+#if !ENABLE(APPLE_PAY_SESSION_V3)
+    static const unsigned currentVersion = 2;
+#else
+    static const unsigned currentVersion = 3;
+#endif
+
+    return version <= currentVersion;
+}
+
+bool MockPaymentCoordinator::canMakePayments()
+{
+    return true;
+}
+
+void MockPaymentCoordinator::canMakePaymentsWithActiveCard(const String&, const String&, WTF::Function<void(bool)>&& completionHandler)
+{
+    RunLoop::main().dispatch([completionHandler = WTFMove(completionHandler)]() {
+        completionHandler(true);
+    });
+}
+
+void MockPaymentCoordinator::openPaymentSetup(const String&, const String&, WTF::Function<void(bool)>&& completionHandler)
+{
+    RunLoop::main().dispatch([completionHandler = WTFMove(completionHandler)]() {
+        completionHandler(true);
+    });
+}
+
+bool MockPaymentCoordinator::showPaymentUI(const URL&, const Vector<URL>&, const ApplePaySessionPaymentRequest&)
+{
+    return true;
+}
+
+void MockPaymentCoordinator::paymentCoordinatorDestroyed()
+{
+    delete this;
+}
+
+} // namespace WebCore
+
+#endif // ENABLE(APPLE_PAY)
diff --git a/Source/WebCore/testing/MockPaymentCoordinator.h b/Source/WebCore/testing/MockPaymentCoordinator.h
new file mode 100644 (file)
index 0000000..a9ca7ee
--- /dev/null
@@ -0,0 +1,53 @@
+/*
+ * 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)
+
+#include "PaymentCoordinatorClient.h"
+
+namespace WebCore {
+
+class MockPaymentCoordinator final : public PaymentCoordinatorClient {
+private:
+    bool supportsVersion(unsigned) final;
+    bool canMakePayments() final;
+    void canMakePaymentsWithActiveCard(const String&, const String&, WTF::Function<void(bool)>&&);
+    void openPaymentSetup(const String&, const String&, WTF::Function<void(bool)>&&);
+    bool showPaymentUI(const URL&, const Vector<URL>&, const ApplePaySessionPaymentRequest&) final;
+    void completeMerchantValidation(const PaymentMerchantSession&) final { }
+    void completeShippingMethodSelection(std::optional<ShippingMethodUpdate>&&) final { }
+    void completeShippingContactSelection(std::optional<ShippingContactUpdate>&&) final { }
+    void completePaymentMethodSelection(std::optional<PaymentMethodUpdate>&&) final { }
+    void completePaymentSession(std::optional<PaymentAuthorizationResult>&&) final { }
+    void abortPaymentSession() final { }
+    void cancelPaymentSession() final { }
+    void paymentCoordinatorDestroyed() final;
+};
+
+} // namespace WebCore
+
+#endif // ENABLE(APPLE_PAY)