[Apple Pay] Add release logging to PaymentCoordinator
authoraestes@apple.com <aestes@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 9 Apr 2019 19:53:35 +0000 (19:53 +0000)
committeraestes@apple.com <aestes@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 9 Apr 2019 19:53:35 +0000 (19:53 +0000)
https://bugs.webkit.org/show_bug.cgi?id=196738

Reviewed by Alex Christensen.

Source/WebCore:

When allowed, log interactions with PaymentCoordinator to os_log to help diagnose Apple Pay bugs.

The following information might be logged: names of functions called, merchant API versions,
boolean results of canMakePayments(), boolean results of beginPaymentSession(), whether
completePaymentSession() was called with a final state result, boolean results of
shouldAllowApplePay(), whether a document has evaluated user agent scripts or is running
user scripts, and whether a client supports unrestricted Apple Pay.

* Modules/applepay/PaymentCoordinator.cpp:
(WebCore::PaymentCoordinator::supportsVersion const):
(WebCore::PaymentCoordinator::canMakePayments):
(WebCore::PaymentCoordinator::canMakePaymentsWithActiveCard):
(WebCore::PaymentCoordinator::openPaymentSetup):
(WebCore::PaymentCoordinator::beginPaymentSession):
(WebCore::PaymentCoordinator::completeMerchantValidation):
(WebCore::PaymentCoordinator::completeShippingMethodSelection):
(WebCore::PaymentCoordinator::completeShippingContactSelection):
(WebCore::PaymentCoordinator::completePaymentMethodSelection):
(WebCore::PaymentCoordinator::completePaymentSession):
(WebCore::PaymentCoordinator::abortPaymentSession):
(WebCore::PaymentCoordinator::cancelPaymentSession):
(WebCore::PaymentCoordinator::validateMerchant):
(WebCore::PaymentCoordinator::didAuthorizePayment):
(WebCore::PaymentCoordinator::didSelectPaymentMethod):
(WebCore::PaymentCoordinator::didSelectShippingMethod):
(WebCore::PaymentCoordinator::didSelectShippingContact):
(WebCore::PaymentCoordinator::didCancelPaymentSession):
(WebCore::PaymentCoordinator::shouldAllowApplePay const):
(WebCore::PaymentCoordinator::shouldAllowUserAgentScripts const):
* Modules/applepay/PaymentCoordinatorClient.h:
(WebCore::PaymentCoordinatorClient::isAlwaysOnLoggingAllowed const):
* platform/Logging.h:
* testing/MockPaymentCoordinator.h:

Source/WebKit:

* WebProcess/ApplePay/WebPaymentCoordinator.cpp:
(WebKit::WebPaymentCoordinator::isAlwaysOnLoggingAllowed const):
* WebProcess/ApplePay/WebPaymentCoordinator.h:

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

Source/WebCore/ChangeLog
Source/WebCore/Modules/applepay/PaymentCoordinator.cpp
Source/WebCore/Modules/applepay/PaymentCoordinatorClient.h
Source/WebCore/platform/Logging.h
Source/WebCore/testing/MockPaymentCoordinator.h
Source/WebKit/ChangeLog
Source/WebKit/WebProcess/ApplePay/WebPaymentCoordinator.cpp
Source/WebKit/WebProcess/ApplePay/WebPaymentCoordinator.h

index c8e5fbd..97a860e 100644 (file)
@@ -1,3 +1,44 @@
+2019-04-09  Andy Estes  <aestes@apple.com>
+
+        [Apple Pay] Add release logging to PaymentCoordinator
+        https://bugs.webkit.org/show_bug.cgi?id=196738
+
+        Reviewed by Alex Christensen.
+
+        When allowed, log interactions with PaymentCoordinator to os_log to help diagnose Apple Pay bugs.
+
+        The following information might be logged: names of functions called, merchant API versions,
+        boolean results of canMakePayments(), boolean results of beginPaymentSession(), whether
+        completePaymentSession() was called with a final state result, boolean results of
+        shouldAllowApplePay(), whether a document has evaluated user agent scripts or is running
+        user scripts, and whether a client supports unrestricted Apple Pay.
+
+        * Modules/applepay/PaymentCoordinator.cpp:
+        (WebCore::PaymentCoordinator::supportsVersion const):
+        (WebCore::PaymentCoordinator::canMakePayments):
+        (WebCore::PaymentCoordinator::canMakePaymentsWithActiveCard):
+        (WebCore::PaymentCoordinator::openPaymentSetup):
+        (WebCore::PaymentCoordinator::beginPaymentSession):
+        (WebCore::PaymentCoordinator::completeMerchantValidation):
+        (WebCore::PaymentCoordinator::completeShippingMethodSelection):
+        (WebCore::PaymentCoordinator::completeShippingContactSelection):
+        (WebCore::PaymentCoordinator::completePaymentMethodSelection):
+        (WebCore::PaymentCoordinator::completePaymentSession):
+        (WebCore::PaymentCoordinator::abortPaymentSession):
+        (WebCore::PaymentCoordinator::cancelPaymentSession):
+        (WebCore::PaymentCoordinator::validateMerchant):
+        (WebCore::PaymentCoordinator::didAuthorizePayment):
+        (WebCore::PaymentCoordinator::didSelectPaymentMethod):
+        (WebCore::PaymentCoordinator::didSelectShippingMethod):
+        (WebCore::PaymentCoordinator::didSelectShippingContact):
+        (WebCore::PaymentCoordinator::didCancelPaymentSession):
+        (WebCore::PaymentCoordinator::shouldAllowApplePay const):
+        (WebCore::PaymentCoordinator::shouldAllowUserAgentScripts const):
+        * Modules/applepay/PaymentCoordinatorClient.h:
+        (WebCore::PaymentCoordinatorClient::isAlwaysOnLoggingAllowed const):
+        * platform/Logging.h:
+        * testing/MockPaymentCoordinator.h:
+
 2019-04-09  John Wilander  <wilander@apple.com>
 
         Pick up Ad Click Attribution conversions in NetworkResourceLoader::willSendRedirectedRequest()
index f877fde..524f436 100644 (file)
 
 #include "Document.h"
 #include "LinkIconCollector.h"
+#include "Logging.h"
 #include "PaymentAuthorizationStatus.h"
 #include "PaymentCoordinatorClient.h"
 #include "PaymentSession.h"
 #include <wtf/CompletionHandler.h>
 #include <wtf/URL.h>
 
+#undef RELEASE_LOG_ERROR_IF_ALLOWED
+#undef RELEASE_LOG_IF_ALLOWED
+#define RELEASE_LOG_ERROR_IF_ALLOWED(fmt, ...) RELEASE_LOG_ERROR_IF(m_client.isAlwaysOnLoggingAllowed(), ApplePay, "%p - PaymentCoordinator::" fmt, this, ##__VA_ARGS__)
+#define RELEASE_LOG_IF_ALLOWED(fmt, ...) RELEASE_LOG_IF(m_client.isAlwaysOnLoggingAllowed(), ApplePay, "%p - PaymentCoordinator::" fmt, this, ##__VA_ARGS__)
+
 namespace WebCore {
 
 PaymentCoordinator::PaymentCoordinator(PaymentCoordinatorClient& client)
@@ -52,20 +58,28 @@ bool PaymentCoordinator::supportsVersion(Document& document, unsigned version) c
 {
     if (!shouldAllowApplePay(document))
         return false;
-    return m_client.supportsVersion(version);
+
+    auto supportsVersion = m_client.supportsVersion(version);
+    RELEASE_LOG_IF_ALLOWED("supportsVersion(%d) -> %d", version, supportsVersion);
+    return supportsVersion;
 }
 
 bool PaymentCoordinator::canMakePayments(Document& document)
 {
     if (!shouldAllowApplePay(document))
         return false;
-    return m_client.canMakePayments();
+
+    auto canMakePayments = m_client.canMakePayments();
+    RELEASE_LOG_IF_ALLOWED("canMakePayments() -> %d", canMakePayments);
+    return canMakePayments;
 }
 
 void PaymentCoordinator::canMakePaymentsWithActiveCard(Document& document, const String& merchantIdentifier, WTF::Function<void(bool)>&& completionHandler)
 {
     if (!shouldAllowApplePay(document))
         return completionHandler(false);
+
+    RELEASE_LOG_IF_ALLOWED("canMakePaymentsWithActiveCard()");
     m_client.canMakePaymentsWithActiveCard(merchantIdentifier, document.domain(), WTFMove(completionHandler));
 }
 
@@ -73,6 +87,8 @@ void PaymentCoordinator::openPaymentSetup(Document& document, const String& merc
 {
     if (!shouldAllowApplePay(document))
         return completionHandler(false);
+
+    RELEASE_LOG_IF_ALLOWED("openPaymentSetup()");
     m_client.openPaymentSetup(merchantIdentifier, document.domain(), WTFMove(completionHandler));
 }
 
@@ -87,7 +103,9 @@ bool PaymentCoordinator::beginPaymentSession(Document& document, PaymentSession&
     for (auto& icon : LinkIconCollector { document }.iconsOfTypes({ LinkIconType::TouchIcon, LinkIconType::TouchPrecomposedIcon }))
         linkIconURLs.append(icon.url);
 
-    if (!m_client.showPaymentUI(document.url(), linkIconURLs, paymentRequest))
+    auto showPaymentUI = m_client.showPaymentUI(document.url(), linkIconURLs, paymentRequest);
+    RELEASE_LOG_IF_ALLOWED("beginPaymentSession() -> %d", showPaymentUI);
+    if (!showPaymentUI)
         return false;
 
     m_activeSession = &paymentSession;
@@ -98,28 +116,28 @@ bool PaymentCoordinator::beginPaymentSession(Document& document, PaymentSession&
 void PaymentCoordinator::completeMerchantValidation(const PaymentMerchantSession& paymentMerchantSession)
 {
     ASSERT(m_activeSession);
-
+    RELEASE_LOG_IF_ALLOWED("completeMerchantValidation()");
     m_client.completeMerchantValidation(paymentMerchantSession);
 }
 
 void PaymentCoordinator::completeShippingMethodSelection(Optional<ShippingMethodUpdate>&& update)
 {
     ASSERT(m_activeSession);
-
+    RELEASE_LOG_IF_ALLOWED("completeShippingMethodSelection()");
     m_client.completeShippingMethodSelection(WTFMove(update));
 }
 
 void PaymentCoordinator::completeShippingContactSelection(Optional<ShippingContactUpdate>&& update)
 {
     ASSERT(m_activeSession);
-
+    RELEASE_LOG_IF_ALLOWED("completeShippingContactSelection()");
     m_client.completeShippingContactSelection(WTFMove(update));
 }
 
 void PaymentCoordinator::completePaymentMethodSelection(Optional<PaymentMethodUpdate>&& update)
 {
     ASSERT(m_activeSession);
-
+    RELEASE_LOG_IF_ALLOWED("completePaymentMethodSelection()");
     m_client.completePaymentMethodSelection(WTFMove(update));
 }
 
@@ -128,7 +146,7 @@ void PaymentCoordinator::completePaymentSession(Optional<PaymentAuthorizationRes
     ASSERT(m_activeSession);
 
     bool isFinalState = isFinalStateResult(result);
-
+    RELEASE_LOG_IF_ALLOWED("completePaymentSession() (isFinalState: %d)", isFinalState);
     m_client.completePaymentSession(WTFMove(result));
 
     if (!isFinalState)
@@ -140,7 +158,7 @@ void PaymentCoordinator::completePaymentSession(Optional<PaymentAuthorizationRes
 void PaymentCoordinator::abortPaymentSession()
 {
     ASSERT(m_activeSession);
-
+    RELEASE_LOG_IF_ALLOWED("abortPaymentSession()");
     m_client.abortPaymentSession();
     m_activeSession = nullptr;
 }
@@ -148,7 +166,7 @@ void PaymentCoordinator::abortPaymentSession()
 void PaymentCoordinator::cancelPaymentSession()
 {
     ASSERT(m_activeSession);
-
+    RELEASE_LOG_IF_ALLOWED("cancelPaymentSession()");
     m_client.cancelPaymentSession();
 }
 
@@ -159,6 +177,7 @@ void PaymentCoordinator::validateMerchant(URL&& validationURL)
         return;
     }
 
+    RELEASE_LOG_IF_ALLOWED("validateMerchant()");
     m_activeSession->validateMerchant(WTFMove(validationURL));
 }
 
@@ -169,6 +188,7 @@ void PaymentCoordinator::didAuthorizePayment(const Payment& payment)
         return;
     }
 
+    RELEASE_LOG_IF_ALLOWED("validateMerchant()");
     m_activeSession->didAuthorizePayment(payment);
 }
 
@@ -179,6 +199,7 @@ void PaymentCoordinator::didSelectPaymentMethod(const PaymentMethod& paymentMeth
         return;
     }
 
+    RELEASE_LOG_IF_ALLOWED("didSelectPaymentMethod()");
     m_activeSession->didSelectPaymentMethod(paymentMethod);
 }
 
@@ -189,6 +210,7 @@ void PaymentCoordinator::didSelectShippingMethod(const ApplePaySessionPaymentReq
         return;
     }
 
+    RELEASE_LOG_IF_ALLOWED("didSelectShippingMethod()");
     m_activeSession->didSelectShippingMethod(shippingMethod);
 }
 
@@ -199,6 +221,7 @@ void PaymentCoordinator::didSelectShippingContact(const PaymentContact& shipping
         return;
     }
 
+    RELEASE_LOG_IF_ALLOWED("didSelectShippingContact()");
     m_activeSession->didSelectShippingContact(shippingContact);
 }
 
@@ -209,6 +232,7 @@ void PaymentCoordinator::didCancelPaymentSession()
         return;
     }
 
+    RELEASE_LOG_IF_ALLOWED("didCancelPaymentSession()");
     m_activeSession->didCancelPaymentSession();
     m_activeSession = nullptr;
 }
@@ -229,14 +253,20 @@ Optional<String> PaymentCoordinator::validatedPaymentNetwork(Document& document,
 
 bool PaymentCoordinator::shouldAllowApplePay(Document& document) const
 {
-    if (m_client.supportsUnrestrictedApplePay())
+    if (m_client.supportsUnrestrictedApplePay()) {
+        RELEASE_LOG_IF_ALLOWED("shouldAllowApplePay() -> true (unrestricted client)");
         return true;
+    }
 
-    if (document.hasEvaluatedUserAgentScripts() || document.isRunningUserScripts()) {
+    auto hasEvaluatedUserAgentScripts = document.hasEvaluatedUserAgentScripts();
+    auto isRunningUserScripts = document.isRunningUserScripts();
+    if (hasEvaluatedUserAgentScripts || isRunningUserScripts) {
         ASSERT(shouldAllowUserAgentScripts(document));
+        RELEASE_LOG_IF_ALLOWED("shouldAllowApplePay() -> false (hasEvaluatedUserAgentScripts: %d, isRunningUserScripts: %d)", hasEvaluatedUserAgentScripts, isRunningUserScripts);
         return false;
     }
 
+    RELEASE_LOG_IF_ALLOWED("shouldAllowApplePay() -> true");
     return true;
 }
 
@@ -247,6 +277,7 @@ bool PaymentCoordinator::shouldAllowUserAgentScripts(Document& document) const
 
     if (document.hasStartedApplePaySession()) {
         ASSERT(shouldAllowApplePay(document));
+        RELEASE_LOG_ERROR_IF_ALLOWED("shouldAllowUserAgentScripts() -> false (active session)");
         return false;
     }
 
@@ -255,4 +286,7 @@ bool PaymentCoordinator::shouldAllowUserAgentScripts(Document& document) const
 
 } // namespace WebCore
 
+#undef RELEASE_LOG_ERROR_IF_ALLOWED
+#undef RELEASE_LOG_IF_ALLOWED
+
 #endif // ENABLE(APPLE_PAY)
index e812ddb..a2af4f1 100644 (file)
@@ -66,6 +66,7 @@ public:
     virtual bool isMockPaymentCoordinator() const { return false; }
     virtual bool isWebPaymentCoordinator() const { return false; }
 
+    virtual bool isAlwaysOnLoggingAllowed() const { return false; }
     virtual bool supportsUnrestrictedApplePay() const { return true; }
 
 protected:
index f056f96..abf079d 100644 (file)
@@ -39,6 +39,7 @@ namespace WebCore {
 
 #define WEBCORE_LOG_CHANNELS(M) \
     M(Animations) \
+    M(ApplePay) \
     M(Archives) \
     M(Compositing) \
     M(ContentFiltering) \
index 14a0c97..b1f7309 100644 (file)
@@ -83,6 +83,8 @@ private:
 
     bool isMockPaymentCoordinator() const final { return true; }
 
+    bool isAlwaysOnLoggingAllowed() const final { return true; }
+
     void updateTotalAndLineItems(const ApplePaySessionPaymentRequest::TotalAndLineItems&);
 
     Page& m_page;
index 6a714ea..a3806ac 100644 (file)
@@ -1,3 +1,14 @@
+2019-04-09  Andy Estes  <aestes@apple.com>
+
+        [Apple Pay] Add release logging to PaymentCoordinator
+        https://bugs.webkit.org/show_bug.cgi?id=196738
+
+        Reviewed by Alex Christensen.
+
+        * WebProcess/ApplePay/WebPaymentCoordinator.cpp:
+        (WebKit::WebPaymentCoordinator::isAlwaysOnLoggingAllowed const):
+        * WebProcess/ApplePay/WebPaymentCoordinator.h:
+
 2019-04-09  Jer Noble  <jer.noble@apple.com>
 
         [Cocoa] Awaken UIProcess if WebContent process is awakened from suspensions unexpectedly.
index ebe3ec6..ff44934 100644 (file)
@@ -142,6 +142,11 @@ void WebPaymentCoordinator::paymentCoordinatorDestroyed()
     delete this;
 }
 
+bool WebPaymentCoordinator::isAlwaysOnLoggingAllowed() const
+{
+    return m_webPage.isAlwaysOnLoggingAllowed();
+}
+
 bool WebPaymentCoordinator::supportsUnrestrictedApplePay() const
 {
 #if ENABLE(APPLE_PAY_REMOTE_UI)
index 7863672..b6d4a04 100644 (file)
@@ -78,6 +78,7 @@ private:
 
     bool isWebPaymentCoordinator() const override { return true; }
 
+    bool isAlwaysOnLoggingAllowed() const override;
     bool supportsUnrestrictedApplePay() const override;
 
     // IPC::MessageReceiver.