<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[237594] trunk</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/237594">237594</a></dd>
<dt>Author</dt> <dd>aestes@apple.com</dd>
<dt>Date</dt> <dd>2018-10-30 11:12:21 -0700 (Tue, 30 Oct 2018)</dd>
</dl>

<h3>Log Message</h3>
<pre>[Apple Pay] PaymentRequest.canMakePayment() should resolve to true whenever Apple Pay is available
https://bugs.webkit.org/show_bug.cgi?id=191039

Reviewed by Megan Gardner.

Source/WebCore:

During a recent Web Payments WG F2F, we decided that canMakePayment() should return true
whenever the user agent supports one or more of the specified payment methods, even if those
payment methods do not have active instruments.

Change WebKit's implementation of canMakePayment() for Apple Pay to resolve with the value
of ApplePaySession.canMakePayments() rather than ApplePaySession.canMakePaymentsWithActiveCard().

Added a test case to http/tests/paymentrequest/payment-request-canmakepayment-method.https.html.

* Modules/applepay/paymentrequest/ApplePayPaymentHandler.cpp:
(WebCore::ApplePayPaymentHandler::canMakePayment):
(WebCore::shouldDiscloseApplePayCapability): Deleted.
* testing/MockPaymentCoordinator.cpp:
(WebCore::MockPaymentCoordinator::canMakePayments):
(WebCore::MockPaymentCoordinator::canMakePaymentsWithActiveCard):
* testing/MockPaymentCoordinator.h:
* testing/MockPaymentCoordinator.idl:

LayoutTests:

* http/tests/paymentrequest/payment-request-canmakepayment-method.https-expected.txt:
* http/tests/paymentrequest/payment-request-canmakepayment-method.https.html:</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsChangeLog">trunk/LayoutTests/ChangeLog</a></li>
<li><a href="#trunkLayoutTestshttptestspaymentrequestpaymentrequestcanmakepaymentmethodhttpsexpectedtxt">trunk/LayoutTests/http/tests/paymentrequest/payment-request-canmakepayment-method.https-expected.txt</a></li>
<li><a href="#trunkLayoutTestshttptestspaymentrequestpaymentrequestcanmakepaymentmethodhttpshtml">trunk/LayoutTests/http/tests/paymentrequest/payment-request-canmakepayment-method.https.html</a></li>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreModulesapplepaypaymentrequestApplePayPaymentHandlercpp">trunk/Source/WebCore/Modules/applepay/paymentrequest/ApplePayPaymentHandler.cpp</a></li>
<li><a href="#trunkSourceWebCoretestingMockPaymentCoordinatorcpp">trunk/Source/WebCore/testing/MockPaymentCoordinator.cpp</a></li>
<li><a href="#trunkSourceWebCoretestingMockPaymentCoordinatorh">trunk/Source/WebCore/testing/MockPaymentCoordinator.h</a></li>
<li><a href="#trunkSourceWebCoretestingMockPaymentCoordinatoridl">trunk/Source/WebCore/testing/MockPaymentCoordinator.idl</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkLayoutTestsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/ChangeLog (237593 => 237594)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/ChangeLog      2018-10-30 17:48:15 UTC (rev 237593)
+++ trunk/LayoutTests/ChangeLog 2018-10-30 18:12:21 UTC (rev 237594)
</span><span class="lines">@@ -1,3 +1,13 @@
</span><ins>+2018-10-30  Andy Estes  <aestes@apple.com>
+
+        [Apple Pay] PaymentRequest.canMakePayment() should resolve to true whenever Apple Pay is available
+        https://bugs.webkit.org/show_bug.cgi?id=191039
+
+        Reviewed by Megan Gardner.
+
+        * http/tests/paymentrequest/payment-request-canmakepayment-method.https-expected.txt:
+        * http/tests/paymentrequest/payment-request-canmakepayment-method.https.html:
+
</ins><span class="cx"> 2018-10-30  Dawei Fenton  <realdawei@apple.com>
</span><span class="cx"> 
</span><span class="cx">         [ Mojave Debug ] Layout Test http/tests/workers/service/self_registration.html is flaky
</span></span></pre></div>
<a id="trunkLayoutTestshttptestspaymentrequestpaymentrequestcanmakepaymentmethodhttpsexpectedtxt"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/http/tests/paymentrequest/payment-request-canmakepayment-method.https-expected.txt (237593 => 237594)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/http/tests/paymentrequest/payment-request-canmakepayment-method.https-expected.txt     2018-10-30 17:48:15 UTC (rev 237593)
+++ trunk/LayoutTests/http/tests/paymentrequest/payment-request-canmakepayment-method.https-expected.txt        2018-10-30 18:12:21 UTC (rev 237594)
</span><span class="lines">@@ -6,4 +6,5 @@
</span><span class="cx"> PASS If a payment method identifier is supported but its serialized parts are not, resolve promise with false. 
</span><span class="cx"> PASS If payment method identifier is unknown, resolve promise with false. 
</span><span class="cx"> PASS Optionally, at the user agent's discretion, return a promise rejected with a "NotAllowedError" DOMException. 
</span><ins>+PASS Return a promise that resolves to true when Apple Pay is available, even if there isn't an active card. 
</ins><span class="cx"> 
</span></span></pre></div>
<a id="trunkLayoutTestshttptestspaymentrequestpaymentrequestcanmakepaymentmethodhttpshtml"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/http/tests/paymentrequest/payment-request-canmakepayment-method.https.html (237593 => 237594)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/http/tests/paymentrequest/payment-request-canmakepayment-method.https.html     2018-10-30 17:48:15 UTC (rev 237593)
+++ trunk/LayoutTests/http/tests/paymentrequest/payment-request-canmakepayment-method.https.html        2018-10-30 18:12:21 UTC (rev 237594)
</span><span class="lines">@@ -9,6 +9,7 @@
</span><span class="cx"> <script src="/resources/payment-request.js"></script>
</span><span class="cx"> <script src="/resources/testharness.js"></script>
</span><span class="cx"> <script src="/resources/testharnessreport.js"></script>
</span><ins>+<body>
</ins><span class="cx"> <script>
</span><span class="cx"> const applePay = Object.freeze({
</span><span class="cx">     supportedMethods: "https://apple.com/apple-pay",
</span><span class="lines">@@ -182,4 +183,14 @@
</span><span class="cx">     }
</span><span class="cx">   }
</span><span class="cx"> }, `Optionally, at the user agent's discretion, return a promise rejected with a "NotAllowedError" DOMException.`);
</span><ins>+
+promise_test(async t => {
+  internals.mockPaymentCoordinator.setCanMakePaymentsWithActiveCard(false);
+  const request = new PaymentRequest(defaultMethods, defaultDetails);
+  assert_true(
+    await request.canMakePayment(),
+    `canMakePaymentPromise should be true`
+  );
+  internals.mockPaymentCoordinator.setCanMakePaymentsWithActiveCard(true);
+}, `Return a promise that resolves to true when Apple Pay is available, even if there isn't an active card.`);
</ins><span class="cx"> </script>
</span></span></pre></div>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (237593 => 237594)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog   2018-10-30 17:48:15 UTC (rev 237593)
+++ trunk/Source/WebCore/ChangeLog      2018-10-30 18:12:21 UTC (rev 237594)
</span><span class="lines">@@ -1,3 +1,28 @@
</span><ins>+2018-10-30  Andy Estes  <aestes@apple.com>
+
+        [Apple Pay] PaymentRequest.canMakePayment() should resolve to true whenever Apple Pay is available
+        https://bugs.webkit.org/show_bug.cgi?id=191039
+
+        Reviewed by Megan Gardner.
+
+        During a recent Web Payments WG F2F, we decided that canMakePayment() should return true
+        whenever the user agent supports one or more of the specified payment methods, even if those
+        payment methods do not have active instruments.
+
+        Change WebKit's implementation of canMakePayment() for Apple Pay to resolve with the value
+        of ApplePaySession.canMakePayments() rather than ApplePaySession.canMakePaymentsWithActiveCard().
+
+        Added a test case to http/tests/paymentrequest/payment-request-canmakepayment-method.https.html.
+
+        * Modules/applepay/paymentrequest/ApplePayPaymentHandler.cpp:
+        (WebCore::ApplePayPaymentHandler::canMakePayment):
+        (WebCore::shouldDiscloseApplePayCapability): Deleted.
+        * testing/MockPaymentCoordinator.cpp:
+        (WebCore::MockPaymentCoordinator::canMakePayments):
+        (WebCore::MockPaymentCoordinator::canMakePaymentsWithActiveCard):
+        * testing/MockPaymentCoordinator.h:
+        * testing/MockPaymentCoordinator.idl:
+
</ins><span class="cx"> 2018-10-30  Sihui Liu  <sihui_liu@apple.com>
</span><span class="cx"> 
</span><span class="cx">         Add a deprecation warning to console for Web SQL
</span></span></pre></div>
<a id="trunkSourceWebCoreModulesapplepaypaymentrequestApplePayPaymentHandlercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/applepay/paymentrequest/ApplePayPaymentHandler.cpp (237593 => 237594)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/applepay/paymentrequest/ApplePayPaymentHandler.cpp  2018-10-30 17:48:15 UTC (rev 237593)
+++ trunk/Source/WebCore/Modules/applepay/paymentrequest/ApplePayPaymentHandler.cpp     2018-10-30 18:12:21 UTC (rev 237594)
</span><span class="lines">@@ -225,25 +225,11 @@
</span><span class="cx">     paymentCoordinator().abortPaymentSession();
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-static bool shouldDiscloseApplePayCapability(Document& document)
</del><ins>+void ApplePayPaymentHandler::canMakePayment(Function<void(bool)>&& completionHandler)
</ins><span class="cx"> {
</span><del>-    auto* page = document.page();
-    if (!page || page->usesEphemeralSession())
-        return false;
-
-    return document.settings().applePayCapabilityDisclosureAllowed();
</del><ins>+    completionHandler(paymentCoordinator().canMakePayments());
</ins><span class="cx"> }
</span><span class="cx"> 
</span><del>-void ApplePayPaymentHandler::canMakePayment(Function<void(bool)>&& completionHandler)
-{
-    if (!shouldDiscloseApplePayCapability(document())) {
-        completionHandler(paymentCoordinator().canMakePayments());
-        return;
-    }
-
-    paymentCoordinator().canMakePaymentsWithActiveCard(m_applePayRequest->merchantIdentifier, document().domain(), WTFMove(completionHandler));
-}
-    
</del><span class="cx"> ExceptionOr<Vector<ApplePaySessionPaymentRequest::ShippingMethod>> ApplePayPaymentHandler::computeShippingMethods()
</span><span class="cx"> {
</span><span class="cx">     auto& details = m_paymentRequest->paymentDetails();
</span></span></pre></div>
<a id="trunkSourceWebCoretestingMockPaymentCoordinatorcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/testing/MockPaymentCoordinator.cpp (237593 => 237594)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/testing/MockPaymentCoordinator.cpp  2018-10-30 17:48:15 UTC (rev 237593)
+++ trunk/Source/WebCore/testing/MockPaymentCoordinator.cpp     2018-10-30 18:12:21 UTC (rev 237594)
</span><span class="lines">@@ -77,13 +77,13 @@
</span><span class="cx"> 
</span><span class="cx"> bool MockPaymentCoordinator::canMakePayments()
</span><span class="cx"> {
</span><del>-    return true;
</del><ins>+    return m_canMakePayments;
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void MockPaymentCoordinator::canMakePaymentsWithActiveCard(const String&, const String&, Function<void(bool)>&& completionHandler)
</span><span class="cx"> {
</span><del>-    RunLoop::main().dispatch([completionHandler = WTFMove(completionHandler)] {
-        completionHandler(true);
</del><ins>+    RunLoop::main().dispatch([completionHandler = WTFMove(completionHandler), canMakePaymentsWithActiveCard = m_canMakePaymentsWithActiveCard] {
+        completionHandler(canMakePaymentsWithActiveCard);
</ins><span class="cx">     });
</span><span class="cx"> }
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCoretestingMockPaymentCoordinatorh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/testing/MockPaymentCoordinator.h (237593 => 237594)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/testing/MockPaymentCoordinator.h    2018-10-30 17:48:15 UTC (rev 237593)
+++ trunk/Source/WebCore/testing/MockPaymentCoordinator.h       2018-10-30 18:12:21 UTC (rev 237594)
</span><span class="lines">@@ -44,6 +44,8 @@
</span><span class="cx"> public:
</span><span class="cx">     explicit MockPaymentCoordinator(Page&);
</span><span class="cx"> 
</span><ins>+    void setCanMakePayments(bool canMakePayments) { m_canMakePayments = canMakePayments; }
+    void setCanMakePaymentsWithActiveCard(bool canMakePaymentsWithActiveCard) { m_canMakePaymentsWithActiveCard = canMakePaymentsWithActiveCard; }
</ins><span class="cx">     void setShippingAddress(MockPaymentAddress&& shippingAddress) { m_shippingAddress = WTFMove(shippingAddress); }
</span><span class="cx">     void changeShippingOption(String&& shippingOption);
</span><span class="cx">     void changePaymentMethod(ApplePayPaymentMethod&&);
</span><span class="lines">@@ -77,6 +79,8 @@
</span><span class="cx">     void updateTotalAndLineItems(const ApplePaySessionPaymentRequest::TotalAndLineItems&);
</span><span class="cx"> 
</span><span class="cx">     Page& m_page;
</span><ins>+    bool m_canMakePayments { true };
+    bool m_canMakePaymentsWithActiveCard { true };
</ins><span class="cx">     ApplePayPaymentContact m_shippingAddress;
</span><span class="cx">     ApplePayLineItem m_total;
</span><span class="cx">     Vector<ApplePayLineItem> m_lineItems;
</span></span></pre></div>
<a id="trunkSourceWebCoretestingMockPaymentCoordinatoridl"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/testing/MockPaymentCoordinator.idl (237593 => 237594)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/testing/MockPaymentCoordinator.idl  2018-10-30 17:48:15 UTC (rev 237593)
+++ trunk/Source/WebCore/testing/MockPaymentCoordinator.idl     2018-10-30 18:12:21 UTC (rev 237594)
</span><span class="lines">@@ -27,6 +27,8 @@
</span><span class="cx">     Conditional=APPLE_PAY,
</span><span class="cx">     NoInterfaceObject,
</span><span class="cx"> ] interface MockPaymentCoordinator {
</span><ins>+    void setCanMakePayments(boolean canMakePayments);
+    void setCanMakePaymentsWithActiveCard(boolean canMakePaymentsWithActiveCard);
</ins><span class="cx">     void setShippingAddress(MockPaymentAddress shippingAddress);
</span><span class="cx">     void changeShippingOption(DOMString shippingOption);
</span><span class="cx">     void changePaymentMethod(ApplePayPaymentMethod paymentMethod);
</span></span></pre>
</div>
</div>

</body>
</html>