Changeset 246056 in webkit


Ignore:
Timestamp:
Jun 3, 2019 11:36:05 PM (5 years ago)
Author:
aestes@apple.com
Message:

[Apple Pay] Disable script injection when canMakePayment APIs are called and return true
https://bugs.webkit.org/show_bug.cgi?id=198448
<rdar://problem/51323694>

Reviewed by Alex Christensen.

Source/WebCore:

Previously, only an active Apple Pay session would disable script injection in restricted
WKWebViews. However, this can result in websites rendering non-functional Apple Pay buttons
due to the race between the hosting app calling -evaluateJavaScript:completionHandler: and
the website calling canMakePayment APIs to determine whether to draw a button.

This patch makes it so that, if a website calls ApplePaySession's canMakePayments or
canMakePaymentsWithActiveCard, or PaymentRequest's canMakePayment, in a web view that has no
injected scripts, and those calls return true, future script injections from the hosting app
will be blocked.

Also, this patch removes the restrictions on the openPaymentSetup, supportsVersion, and
validatedPaymentNetwork APIs, since those APIs do not reveal transaction information and are
not used to determine whether to draw buttons.

Added new API tests.

  • Modules/applepay/PaymentCoordinator.cpp:

(WebCore::PaymentCoordinator::supportsVersion const):
(WebCore::PaymentCoordinator::canMakePayments):
(WebCore::PaymentCoordinator::canMakePaymentsWithActiveCard):
(WebCore::PaymentCoordinator::openPaymentSetup):
(WebCore::PaymentCoordinator::beginPaymentSession):
(WebCore::PaymentCoordinator::validatedPaymentNetwork const):
(WebCore::PaymentCoordinator::setApplePayIsActiveIfAllowed const):
(WebCore::PaymentCoordinator::shouldAllowUserAgentScripts const):
(WebCore::PaymentCoordinator::shouldAllowApplePay const): Deleted.

  • Modules/applepay/PaymentCoordinator.h:
  • dom/Document.cpp:

(WebCore::Document::isApplePayActive const):
(WebCore::Document::setApplePayIsActive):
(WebCore::Document::hasStartedApplePaySession const): Deleted.
(WebCore::Document::setHasStartedApplePaySession): Deleted.

  • dom/Document.h:
  • testing/Internals.cpp:

(WebCore::Internals::setApplePayIsActive):
(WebCore::Internals::setHasStartedApplePaySession): Deleted.

  • testing/Internals.h:
  • testing/Internals.idl:

Tools:

  • TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
  • TestWebKitAPI/Tests/WebKitCocoa/ApplePay.mm:

(-[TestApplePayAvailableScriptMessageHandler userContentController:didReceiveScriptMessage:]):
(-[TestApplePayActiveSessionScriptMessageHandler userContentController:didReceiveScriptMessage:]):
(TestWebKitAPI::TEST):
(TestWebKitAPI::runActiveSessionTest):
(-[TestApplePayScriptMessageHandler initWithAPIsAvailableExpectation:canMakePaymentsExpectation:]): Deleted.
(-[TestApplePayScriptMessageHandler userContentController:didReceiveScriptMessage:]): Deleted.

  • TestWebKitAPI/Tests/WebKitCocoa/apple-pay-active-session.html:
  • TestWebKitAPI/Tests/WebKitCocoa/apple-pay-availability-existing-object.html: Added.
  • TestWebKitAPI/Tests/WebKitCocoa/apple-pay-availability-in-iframe.html:
  • TestWebKitAPI/Tests/WebKitCocoa/apple-pay-availability.html:
  • TestWebKitAPI/Tests/WebKitCocoa/apple-pay-can-make-payment.html: Added.
  • TestWebKitAPI/Tests/WebKitCocoa/apple-pay-can-make-payments-with-active-card.html: Added.
  • TestWebKitAPI/Tests/WebKitCocoa/apple-pay-can-make-payments.html: Added.
  • TestWebKitAPI/Tests/WebKitCocoa/apple-pay.js: Added.

(applePayRequestBase):
(applePayPaymentRequest):
(applePayMethod):

  • TestWebKitAPI/cocoa/TestProtocol.mm:

(-[TestProtocol startLoading]):

Location:
trunk
Files:
5 added
16 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r246052 r246056  
     12019-06-03  Andy Estes  <aestes@apple.com>
     2
     3        [Apple Pay] Disable script injection when canMakePayment APIs are called and return true
     4        https://bugs.webkit.org/show_bug.cgi?id=198448
     5        <rdar://problem/51323694>
     6
     7        Reviewed by Alex Christensen.
     8
     9        Previously, only an active Apple Pay session would disable script injection in restricted
     10        WKWebViews. However, this can result in websites rendering non-functional Apple Pay buttons
     11        due to the race between the hosting app calling -evaluateJavaScript:completionHandler: and
     12        the website calling canMakePayment APIs to determine whether to draw a button.
     13
     14        This patch makes it so that, if a website calls ApplePaySession's canMakePayments or
     15        canMakePaymentsWithActiveCard, or PaymentRequest's canMakePayment, in a web view that has no
     16        injected scripts, and those calls return true, future script injections from the hosting app
     17        will be blocked.
     18
     19        Also, this patch removes the restrictions on the openPaymentSetup, supportsVersion, and
     20        validatedPaymentNetwork APIs, since those APIs do not reveal transaction information and are
     21        not used to determine whether to draw buttons.
     22
     23        Added new API tests.
     24
     25        * Modules/applepay/PaymentCoordinator.cpp:
     26        (WebCore::PaymentCoordinator::supportsVersion const):
     27        (WebCore::PaymentCoordinator::canMakePayments):
     28        (WebCore::PaymentCoordinator::canMakePaymentsWithActiveCard):
     29        (WebCore::PaymentCoordinator::openPaymentSetup):
     30        (WebCore::PaymentCoordinator::beginPaymentSession):
     31        (WebCore::PaymentCoordinator::validatedPaymentNetwork const):
     32        (WebCore::PaymentCoordinator::setApplePayIsActiveIfAllowed const):
     33        (WebCore::PaymentCoordinator::shouldAllowUserAgentScripts const):
     34        (WebCore::PaymentCoordinator::shouldAllowApplePay const): Deleted.
     35        * Modules/applepay/PaymentCoordinator.h:
     36        * dom/Document.cpp:
     37        (WebCore::Document::isApplePayActive const):
     38        (WebCore::Document::setApplePayIsActive):
     39        (WebCore::Document::hasStartedApplePaySession const): Deleted.
     40        (WebCore::Document::setHasStartedApplePaySession): Deleted.
     41        * dom/Document.h:
     42        * testing/Internals.cpp:
     43        (WebCore::Internals::setApplePayIsActive):
     44        (WebCore::Internals::setHasStartedApplePaySession): Deleted.
     45        * testing/Internals.h:
     46        * testing/Internals.idl:
     47
    1482019-06-03  Robin Morisset  <rmorisset@apple.com>
    249
  • trunk/Source/WebCore/Modules/applepay/PaymentCoordinator.cpp

    r245314 r246056  
    5757}
    5858
    59 bool PaymentCoordinator::supportsVersion(Document& document, unsigned version) const
    60 {
    61     if (!shouldAllowApplePay(document))
    62         return false;
    63 
     59bool PaymentCoordinator::supportsVersion(Document&, unsigned version) const
     60{
    6461    auto supportsVersion = m_client.supportsVersion(version);
    6562    RELEASE_LOG_IF_ALLOWED("supportsVersion(%d) -> %d", version, supportsVersion);
     
    6966bool PaymentCoordinator::canMakePayments(Document& document)
    7067{
    71     if (!shouldAllowApplePay(document))
    72         return false;
    73 
    7468    auto canMakePayments = m_client.canMakePayments();
    7569    RELEASE_LOG_IF_ALLOWED("canMakePayments() -> %d", canMakePayments);
    76     return canMakePayments;
     70
     71    if (!canMakePayments)
     72        return false;
     73
     74    if (!setApplePayIsActiveIfAllowed(document))
     75        return false;
     76
     77    return true;
    7778}
    7879
    7980void PaymentCoordinator::canMakePaymentsWithActiveCard(Document& document, const String& merchantIdentifier, WTF::Function<void(bool)>&& completionHandler)
    8081{
    81     if (!shouldAllowApplePay(document))
    82         return completionHandler(false);
    83 
    84     RELEASE_LOG_IF_ALLOWED("canMakePaymentsWithActiveCard()");
    85     m_client.canMakePaymentsWithActiveCard(merchantIdentifier, document.domain(), WTFMove(completionHandler));
     82    m_client.canMakePaymentsWithActiveCard(merchantIdentifier, document.domain(), [this, weakThis = makeWeakPtr(*this), document = makeWeakPtr(document), completionHandler = WTFMove(completionHandler)](bool canMakePayments) {
     83        if (!weakThis)
     84            return completionHandler(false);
     85
     86        RELEASE_LOG_IF_ALLOWED("canMakePaymentsWithActiveCard() -> %d", canMakePayments);
     87
     88        if (!canMakePayments)
     89            return completionHandler(false);
     90
     91        if (!document || !setApplePayIsActiveIfAllowed(*document))
     92            return completionHandler(false);
     93
     94        completionHandler(true);
     95    });
    8696}
    8797
    8898void PaymentCoordinator::openPaymentSetup(Document& document, const String& merchantIdentifier, WTF::Function<void(bool)>&& completionHandler)
    8999{
    90     if (!shouldAllowApplePay(document))
    91         return completionHandler(false);
    92 
    93100    RELEASE_LOG_IF_ALLOWED("openPaymentSetup()");
    94101    m_client.openPaymentSetup(merchantIdentifier, document.domain(), WTFMove(completionHandler));
     
    99106    ASSERT(!m_activeSession);
    100107
    101     if (!shouldAllowApplePay(document))
     108    if (!setApplePayIsActiveIfAllowed(document))
    102109        return false;
    103110
     
    112119
    113120    m_activeSession = &paymentSession;
    114     document.setHasStartedApplePaySession();
    115121    return true;
    116122}
     
    240246}
    241247
    242 Optional<String> PaymentCoordinator::validatedPaymentNetwork(Document& document, unsigned version, const String& paymentNetwork) const
    243 {
    244     if (!shouldAllowApplePay(document))
    245         return WTF::nullopt;
    246 
     248Optional<String> PaymentCoordinator::validatedPaymentNetwork(Document&, unsigned version, const String& paymentNetwork) const
     249{
    247250    if (version < 2 && equalIgnoringASCIICase(paymentNetwork, "jcb"))
    248251        return WTF::nullopt;
     
    270273}
    271274
    272 bool PaymentCoordinator::shouldAllowApplePay(Document& document) const
    273 {
    274     if (m_client.supportsUnrestrictedApplePay()) {
    275         RELEASE_LOG_IF_ALLOWED("shouldAllowApplePay() -> true (unrestricted client)");
    276         return true;
    277     }
    278 
     275bool PaymentCoordinator::setApplePayIsActiveIfAllowed(Document& document) const
     276{
    279277    auto hasEvaluatedUserAgentScripts = document.hasEvaluatedUserAgentScripts();
    280278    auto isRunningUserScripts = document.isRunningUserScripts();
    281     if (hasEvaluatedUserAgentScripts || isRunningUserScripts) {
    282         ASSERT(shouldAllowUserAgentScripts(document));
    283         RELEASE_LOG_IF_ALLOWED("shouldAllowApplePay() -> false (hasEvaluatedUserAgentScripts: %d, isRunningUserScripts: %d)", hasEvaluatedUserAgentScripts, isRunningUserScripts);
    284         return false;
    285     }
    286 
    287     RELEASE_LOG_IF_ALLOWED("shouldAllowApplePay() -> true");
     279    auto supportsUnrestrictedApplePay = m_client.supportsUnrestrictedApplePay();
     280
     281    if (!supportsUnrestrictedApplePay && (hasEvaluatedUserAgentScripts || isRunningUserScripts)) {
     282        ASSERT(!document.isApplePayActive());
     283        RELEASE_LOG_IF_ALLOWED("setApplePayIsActiveIfAllowed() -> false (hasEvaluatedUserAgentScripts: %d, isRunningUserScripts: %d)", hasEvaluatedUserAgentScripts, isRunningUserScripts);
     284        return false;
     285    }
     286
     287    RELEASE_LOG_IF_ALLOWED("setApplePayIsActiveIfAllowed() -> true (supportsUnrestrictedApplePay: %d)", supportsUnrestrictedApplePay);
     288    document.setApplePayIsActive();
    288289    return true;
    289290}
     
    291292bool PaymentCoordinator::shouldAllowUserAgentScripts(Document& document) const
    292293{
    293     if (m_client.supportsUnrestrictedApplePay())
     294    if (m_client.supportsUnrestrictedApplePay() || !document.isApplePayActive())
    294295        return true;
    295296
    296     if (document.hasStartedApplePaySession()) {
    297         ASSERT(shouldAllowApplePay(document));
    298         RELEASE_LOG_ERROR_IF_ALLOWED("shouldAllowUserAgentScripts() -> false (active session)");
    299         return false;
    300     }
    301 
    302     return true;
     297    ASSERT(!document.hasEvaluatedUserAgentScripts());
     298    ASSERT(!document.isRunningUserScripts());
     299    RELEASE_LOG_ERROR_IF_ALLOWED("shouldAllowUserAgentScripts() -> false (active session)");
     300    return false;
    303301}
    304302
  • trunk/Source/WebCore/Modules/applepay/PaymentCoordinator.h

    r245314 r246056  
    3030#include "ApplePaySessionPaymentRequest.h"
    3131#include <wtf/Function.h>
     32#include <wtf/WeakPtr.h>
    3233
    3334namespace WebCore {
     
    4647struct ShippingMethodUpdate;
    4748
    48 class PaymentCoordinator {
     49class PaymentCoordinator : public CanMakeWeakPtr<PaymentCoordinator> {
    4950    WTF_MAKE_FAST_ALLOCATED;
    5051public:
     
    8081
    8182    bool shouldEnableApplePayAPIs(Document&) const;
    82     WEBCORE_EXPORT bool shouldAllowApplePay(Document&) const;
    8383    WEBCORE_EXPORT bool shouldAllowUserAgentScripts(Document&) const;
    8484
    8585private:
     86    bool setApplePayIsActiveIfAllowed(Document&) const;
     87
    8688    PaymentCoordinatorClient& m_client;
    87 
    8889    RefPtr<PaymentSession> m_activeSession;
    8990};
  • trunk/Source/WebCore/dom/Document.cpp

    r246002 r246056  
    82508250#if ENABLE(APPLE_PAY)
    82518251
    8252 bool Document::hasStartedApplePaySession() const
     8252bool Document::isApplePayActive() const
    82538253{
    82548254    auto& top = topDocument();
    8255     return this == &top ? m_hasStartedApplePaySession : top.hasStartedApplePaySession();
    8256 }
    8257 
    8258 void Document::setHasStartedApplePaySession()
     8255    return this == &top ? m_hasStartedApplePaySession : top.isApplePayActive();
     8256}
     8257
     8258void Document::setApplePayIsActive()
    82598259{
    82608260    auto& top = topDocument();
     
    82628262        m_hasStartedApplePaySession = true;
    82638263    else
    8264         top.setHasStartedApplePaySession();
     8264        top.setApplePayIsActive();
    82658265}
    82668266
  • trunk/Source/WebCore/dom/Document.h

    r245958 r246056  
    15231523    void setHasEvaluatedUserAgentScripts();
    15241524#if ENABLE(APPLE_PAY)
    1525     WEBCORE_EXPORT bool hasStartedApplePaySession() const;
    1526     WEBCORE_EXPORT void setHasStartedApplePaySession();
     1525    WEBCORE_EXPORT bool isApplePayActive() const;
     1526    WEBCORE_EXPORT void setApplePayIsActive();
    15271527#endif
    15281528
  • trunk/Source/WebCore/testing/Internals.cpp

    r246002 r246056  
    46044604
    46054605#if ENABLE(APPLE_PAY)
    4606 void Internals::setHasStartedApplePaySession(Document& document)
    4607 {
    4608     document.setHasStartedApplePaySession();
     4606void Internals::setApplePayIsActive(Document& document)
     4607{
     4608    document.setApplePayIsActive();
    46094609}
    46104610#endif
  • trunk/Source/WebCore/testing/Internals.h

    r246002 r246056  
    682682    void setAsRunningUserScripts(Document&);
    683683#if ENABLE(APPLE_PAY)
    684     void setHasStartedApplePaySession(Document&);
     684    void setApplePayIsActive(Document&);
    685685#endif
    686686
  • trunk/Source/WebCore/testing/Internals.idl

    r246002 r246056  
    658658
    659659    [CallWith=Document] void setAsRunningUserScripts();
    660     [CallWith=Document, Conditional=APPLE_PAY] void setHasStartedApplePaySession();
     660    [CallWith=Document, Conditional=APPLE_PAY] void setApplePayIsActive();
    661661
    662662    void disableTileSizeUpdateDelay();
  • trunk/Tools/ChangeLog

    r246050 r246056  
     12019-06-03  Andy Estes  <aestes@apple.com>
     2
     3        [Apple Pay] Disable script injection when canMakePayment APIs are called and return true
     4        https://bugs.webkit.org/show_bug.cgi?id=198448
     5        <rdar://problem/51323694>
     6
     7        Reviewed by Alex Christensen.
     8
     9        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
     10        * TestWebKitAPI/Tests/WebKitCocoa/ApplePay.mm:
     11        (-[TestApplePayAvailableScriptMessageHandler userContentController:didReceiveScriptMessage:]):
     12        (-[TestApplePayActiveSessionScriptMessageHandler userContentController:didReceiveScriptMessage:]):
     13        (TestWebKitAPI::TEST):
     14        (TestWebKitAPI::runActiveSessionTest):
     15        (-[TestApplePayScriptMessageHandler initWithAPIsAvailableExpectation:canMakePaymentsExpectation:]): Deleted.
     16        (-[TestApplePayScriptMessageHandler userContentController:didReceiveScriptMessage:]): Deleted.
     17        * TestWebKitAPI/Tests/WebKitCocoa/apple-pay-active-session.html:
     18        * TestWebKitAPI/Tests/WebKitCocoa/apple-pay-availability-existing-object.html: Added.
     19        * TestWebKitAPI/Tests/WebKitCocoa/apple-pay-availability-in-iframe.html:
     20        * TestWebKitAPI/Tests/WebKitCocoa/apple-pay-availability.html:
     21        * TestWebKitAPI/Tests/WebKitCocoa/apple-pay-can-make-payment.html: Added.
     22        * TestWebKitAPI/Tests/WebKitCocoa/apple-pay-can-make-payments-with-active-card.html: Added.
     23        * TestWebKitAPI/Tests/WebKitCocoa/apple-pay-can-make-payments.html: Added.
     24        * TestWebKitAPI/Tests/WebKitCocoa/apple-pay.js: Added.
     25        (applePayRequestBase):
     26        (applePayPaymentRequest):
     27        (applePayMethod):
     28        * TestWebKitAPI/cocoa/TestProtocol.mm:
     29        (-[TestProtocol startLoading]):
     30
    1312019-06-03  Sihui Liu  <sihui_liu@apple.com>
    232
  • trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj

    r245998 r246056  
    731731                A1DF74321C41B65800A2F4D0 /* AlwaysRevalidatedURLSchemes.mm in Sources */ = {isa = PBXBuildFile; fileRef = A1DF74301C41B65800A2F4D0 /* AlwaysRevalidatedURLSchemes.mm */; };
    732732                A1EC11881F42541200D0146E /* PreviewConverter.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A1EC11871F42541200D0146E /* PreviewConverter.cpp */; };
     733                A1FB503D22A1CBE200D4D979 /* apple-pay-availability-existing-object.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = A1FB503C22A1C24400D4D979 /* apple-pay-availability-existing-object.html */; };
     734                A1FB503F22A20F6400D4D979 /* apple-pay-can-make-payments.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = A1FB503E22A1E3B300D4D979 /* apple-pay-can-make-payments.html */; };
     735                A1FB504122A212A900D4D979 /* apple-pay-can-make-payments-with-active-card.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = A1FB504022A2128400D4D979 /* apple-pay-can-make-payments-with-active-card.html */; };
     736                A1FB504322A213A300D4D979 /* apple-pay-can-make-payment.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = A1FB504222A2138F00D4D979 /* apple-pay-can-make-payment.html */; };
     737                A1FB504522A2157100D4D979 /* apple-pay.js in Copy Resources */ = {isa = PBXBuildFile; fileRef = A1FB504422A2154B00D4D979 /* apple-pay.js */; };
    733738                A310827221F296FF00C28B97 /* FileSystem.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A310827121F296EC00C28B97 /* FileSystem.cpp */; };
    734739                A57A34F216AF6B2B00C2501F /* PageVisibilityStateWithWindowChanges.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = A57A34F116AF69E200C2501F /* PageVisibilityStateWithWindowChanges.html */; };
     
    10501055                                F4A9202F1FEE34E900F59590 /* apple-data-url.html in Copy Resources */,
    10511056                                A1798B8B224361A4000764BD /* apple-pay-active-session.html in Copy Resources */,
     1057                                A1FB503D22A1CBE200D4D979 /* apple-pay-availability-existing-object.html in Copy Resources */,
    10521058                                A1798B8922435E29000764BD /* apple-pay-availability-in-iframe.html in Copy Resources */,
    10531059                                A1798B872243449B000764BD /* apple-pay-availability.html in Copy Resources */,
     1060                                A1FB504322A213A300D4D979 /* apple-pay-can-make-payment.html in Copy Resources */,
     1061                                A1FB504122A212A900D4D979 /* apple-pay-can-make-payments-with-active-card.html in Copy Resources */,
     1062                                A1FB503F22A20F6400D4D979 /* apple-pay-can-make-payments.html in Copy Resources */,
     1063                                A1FB504522A2157100D4D979 /* apple-pay.js in Copy Resources */,
    10541064                                F46A095A1ED8A6E600D4AA55 /* apple.gif in Copy Resources */,
    10551065                                5C9E59411D3EB5AC00E3C62E /* ApplicationCache.db in Copy Resources */,
     
    20292039                A1DF74301C41B65800A2F4D0 /* AlwaysRevalidatedURLSchemes.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = AlwaysRevalidatedURLSchemes.mm; sourceTree = "<group>"; };
    20302040                A1EC11871F42541200D0146E /* PreviewConverter.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = PreviewConverter.cpp; sourceTree = "<group>"; };
     2041                A1FB503C22A1C24400D4D979 /* apple-pay-availability-existing-object.html */ = {isa = PBXFileReference; lastKnownFileType = text.html; path = "apple-pay-availability-existing-object.html"; sourceTree = "<group>"; };
     2042                A1FB503E22A1E3B300D4D979 /* apple-pay-can-make-payments.html */ = {isa = PBXFileReference; lastKnownFileType = text.html; path = "apple-pay-can-make-payments.html"; sourceTree = "<group>"; };
     2043                A1FB504022A2128400D4D979 /* apple-pay-can-make-payments-with-active-card.html */ = {isa = PBXFileReference; lastKnownFileType = text.html; path = "apple-pay-can-make-payments-with-active-card.html"; sourceTree = "<group>"; };
     2044                A1FB504222A2138F00D4D979 /* apple-pay-can-make-payment.html */ = {isa = PBXFileReference; lastKnownFileType = text.html; path = "apple-pay-can-make-payment.html"; sourceTree = "<group>"; };
     2045                A1FB504422A2154B00D4D979 /* apple-pay.js */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.javascript; path = "apple-pay.js"; sourceTree = "<group>"; };
    20312046                A1FDFD2E19C288BB005148A4 /* WKImageCreateCGImageCrash.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WKImageCreateCGImageCrash.cpp; sourceTree = "<group>"; };
    20322047                A310827121F296EC00C28B97 /* FileSystem.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = FileSystem.cpp; sourceTree = "<group>"; };
     
    29602975                                F4A9202E1FEE34C800F59590 /* apple-data-url.html */,
    29612976                                A1798B8A2243611A000764BD /* apple-pay-active-session.html */,
     2977                                A1FB503C22A1C24400D4D979 /* apple-pay-availability-existing-object.html */,
    29622978                                A1798B8822435D2E000764BD /* apple-pay-availability-in-iframe.html */,
    29632979                                A1798B862243446B000764BD /* apple-pay-availability.html */,
     2980                                A1FB504222A2138F00D4D979 /* apple-pay-can-make-payment.html */,
     2981                                A1FB504022A2128400D4D979 /* apple-pay-can-make-payments-with-active-card.html */,
     2982                                A1FB503E22A1E3B300D4D979 /* apple-pay-can-make-payments.html */,
     2983                                A1FB504422A2154B00D4D979 /* apple-pay.js */,
    29642984                                F47D30EB1ED28619000482E1 /* apple.gif */,
    29652985                                5C9E593E1D3EB1DE00E3C62E /* ApplicationCache.db */,
  • trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/ApplePay.mm

    r245314 r246056  
    3838
    3939static bool isDone;
    40 
    41 @interface TestApplePayScriptMessageHandler : NSObject <WKScriptMessageHandler>
     40static NSString * const userScriptSource = @"window.wkUserScriptInjected = true";
     41
     42@interface TestApplePayAvailableScriptMessageHandler : NSObject <WKScriptMessageHandler>
    4243
    4344- (instancetype)init NS_UNAVAILABLE;
     
    4950@end
    5051
    51 @implementation TestApplePayScriptMessageHandler
     52@implementation TestApplePayAvailableScriptMessageHandler
    5253
    5354- (instancetype)initWithAPIsAvailableExpectation:(BOOL)apisAvailableExpectation canMakePaymentsExpectation:(BOOL)canMakePaymentsExpectation
     
    6566    EXPECT_EQ(_apisAvailableExpectation, [[message.body objectForKey:@"applePaySessionAvailable"] boolValue]);
    6667    EXPECT_EQ(_apisAvailableExpectation, [[message.body objectForKey:@"paymentRequestAvailable"] boolValue]);
    67     EXPECT_EQ(_canMakePaymentsExpectation, [[message.body objectForKey:@"supportsVersion"] boolValue]);
     68    EXPECT_EQ(_apisAvailableExpectation, [[message.body objectForKey:@"supportsVersion"] boolValue]);
    6869    EXPECT_EQ(_canMakePaymentsExpectation, [[message.body objectForKey:@"canMakePayments"] boolValue]);
    6970    EXPECT_EQ(_canMakePaymentsExpectation, [[message.body objectForKey:@"canMakePaymentsWithActiveCard"] boolValue]);
     
    7475@end
    7576
     77@interface TestApplePayActiveSessionScriptMessageHandler : NSObject <WKScriptMessageHandler>
     78@end
     79
     80@implementation TestApplePayActiveSessionScriptMessageHandler
     81
     82- (void)userContentController:(WKUserContentController *)userContentController didReceiveScriptMessage:(WKScriptMessage *)message
     83{
     84    isDone = true;
     85}
     86
     87@end
     88
    7689namespace TestWebKitAPI {
    7790   
     
    8093    [TestProtocol registerWithScheme:@"https"];
    8194
    82     auto messageHandler = adoptNS([[TestApplePayScriptMessageHandler alloc] initWithAPIsAvailableExpectation:YES canMakePaymentsExpectation:YES]);
    83 
    84     WKWebViewConfiguration *configuration = [WKWebViewConfiguration _test_configurationWithTestPlugInClassName:@"WebProcessPlugInWithInternals"];
    85     [configuration.userContentController addScriptMessageHandler:messageHandler.get() name:@"testApplePay"];
    86 
    87     auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectZero configuration:configuration]);
    88     [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"https://bundle-html-file/apple-pay-availability"]]];
    89 
    90     Util::run(&isDone);
     95    auto messageHandler = adoptNS([[TestApplePayAvailableScriptMessageHandler alloc] initWithAPIsAvailableExpectation:YES canMakePaymentsExpectation:YES]);
     96
     97    WKWebViewConfiguration *configuration = [WKWebViewConfiguration _test_configurationWithTestPlugInClassName:@"WebProcessPlugInWithInternals"];
     98    [configuration.userContentController addScriptMessageHandler:messageHandler.get() name:@"testApplePay"];
     99
     100    auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectZero configuration:configuration]);
     101    [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"https://bundle-file/apple-pay-availability.html"]]];
     102
     103    Util::run(&isDone);
     104
     105    [TestProtocol unregister];
     106}
     107
     108TEST(ApplePay, ApplePayAvailableInUnrestrictedClients)
     109{
     110    [TestProtocol registerWithScheme:@"https"];
     111
     112    auto messageHandler = adoptNS([[TestApplePayAvailableScriptMessageHandler alloc] initWithAPIsAvailableExpectation:YES canMakePaymentsExpectation:YES]);
     113    auto userScript = adoptNS([[WKUserScript alloc] initWithSource:userScriptSource injectionTime:WKUserScriptInjectionTimeAtDocumentStart forMainFrameOnly:YES]);
     114
     115    WKWebViewConfiguration *configuration = [WKWebViewConfiguration _test_configurationWithTestPlugInClassName:@"WebProcessPlugInWithInternals"];
     116    [configuration.userContentController addUserScript:userScript.get()];
     117    [configuration.userContentController addScriptMessageHandler:messageHandler.get() name:@"testApplePay"];
     118
     119    auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectZero configuration:configuration]);
     120    [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"https://bundle-file/apple-pay-availability-in-iframe.html?unrestricted"]]];
     121    [webView _test_waitForDidFinishNavigation];
     122    [webView evaluateJavaScript:@"loadApplePayFrame();" completionHandler:nil];
     123
     124    Util::run(&isDone);
     125
     126    EXPECT_EQ(YES, [[webView objectByEvaluatingJavaScript:@"window.wkUserScriptInjected"] boolValue]);
    91127
    92128    [TestProtocol unregister];
     
    97133    [TestProtocol registerWithScheme:@"https"];
    98134
    99     auto messageHandler = adoptNS([[TestApplePayScriptMessageHandler alloc] initWithAPIsAvailableExpectation:NO canMakePaymentsExpectation:NO]);
    100     auto userScript = adoptNS([[WKUserScript alloc] initWithSource:@"window.wkUserScriptInjected = true" injectionTime:WKUserScriptInjectionTimeAtDocumentStart forMainFrameOnly:YES]);
     135    auto messageHandler = adoptNS([[TestApplePayAvailableScriptMessageHandler alloc] initWithAPIsAvailableExpectation:NO canMakePaymentsExpectation:NO]);
     136    auto userScript = adoptNS([[WKUserScript alloc] initWithSource:userScriptSource injectionTime:WKUserScriptInjectionTimeAtDocumentStart forMainFrameOnly:YES]);
    101137
    102138    WKWebViewConfiguration *configuration = [WKWebViewConfiguration _test_configurationWithTestPlugInClassName:@"WebProcessPlugInWithInternals"];
     
    105141
    106142    auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectZero configuration:configuration]);
    107     [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"https://bundle-html-file/apple-pay-availability"]]];
     143    [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"https://bundle-file/apple-pay-availability.html"]]];
    108144
    109145    Util::run(&isDone);
     
    118154    [TestProtocol registerWithScheme:@"https"];
    119155   
    120     auto messageHandler = adoptNS([[TestApplePayScriptMessageHandler alloc] initWithAPIsAvailableExpectation:NO canMakePaymentsExpectation:NO]);
    121     auto userScript = adoptNS([[WKUserScript alloc] initWithSource:@"window.wkUserScriptInjected = true" injectionTime:WKUserScriptInjectionTimeAtDocumentEnd forMainFrameOnly:YES]);
     156    auto messageHandler = adoptNS([[TestApplePayAvailableScriptMessageHandler alloc] initWithAPIsAvailableExpectation:NO canMakePaymentsExpectation:NO]);
     157    auto userScript = adoptNS([[WKUserScript alloc] initWithSource:userScriptSource injectionTime:WKUserScriptInjectionTimeAtDocumentEnd forMainFrameOnly:YES]);
    122158   
    123159    WKWebViewConfiguration *configuration = [WKWebViewConfiguration _test_configurationWithTestPlugInClassName:@"WebProcessPlugInWithInternals"];
     
    126162   
    127163    auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectZero configuration:configuration]);
    128     [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"https://bundle-html-file/apple-pay-availability"]]];
     164    [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"https://bundle-file/apple-pay-availability.html"]]];
    129165   
    130166    Util::run(&isDone);
     
    139175    [TestProtocol registerWithScheme:@"https"];
    140176
    141     auto messageHandler = adoptNS([[TestApplePayScriptMessageHandler alloc] initWithAPIsAvailableExpectation:YES canMakePaymentsExpectation:NO]);
    142 
    143     WKWebViewConfiguration *configuration = [WKWebViewConfiguration _test_configurationWithTestPlugInClassName:@"WebProcessPlugInWithInternals"];
    144     [configuration.userContentController addScriptMessageHandler:messageHandler.get() name:@"testApplePay"];
    145 
    146     auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectZero configuration:configuration]);
    147     [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"https://bundle-html-file/apple-pay-availability-in-iframe"]]];
     177    auto messageHandler = adoptNS([[TestApplePayAvailableScriptMessageHandler alloc] initWithAPIsAvailableExpectation:YES canMakePaymentsExpectation:NO]);
     178
     179    WKWebViewConfiguration *configuration = [WKWebViewConfiguration _test_configurationWithTestPlugInClassName:@"WebProcessPlugInWithInternals"];
     180    [configuration.userContentController addScriptMessageHandler:messageHandler.get() name:@"testApplePay"];
     181
     182    auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectZero configuration:configuration]);
     183    [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"https://bundle-file/apple-pay-availability-in-iframe.html"]]];
    148184    [webView _test_waitForDidFinishNavigation];
    149185    [webView evaluateJavaScript:@"window.wkScriptEvaluated = true; loadApplePayFrame();" completionHandler:nil];
     
    160196    [TestProtocol registerWithScheme:@"https"];
    161197
    162     auto messageHandler = adoptNS([[TestApplePayScriptMessageHandler alloc] initWithAPIsAvailableExpectation:YES canMakePaymentsExpectation:YES]);
    163 
    164     WKWebViewConfiguration *configuration = [WKWebViewConfiguration _test_configurationWithTestPlugInClassName:@"WebProcessPlugInWithInternals"];
    165     [configuration.userContentController addScriptMessageHandler:messageHandler.get() name:@"testApplePay"];
    166 
    167     auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectZero configuration:configuration]);
    168     [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"https://bundle-html-file/apple-pay-availability"]]];
     198    auto messageHandler = adoptNS([[TestApplePayAvailableScriptMessageHandler alloc] initWithAPIsAvailableExpectation:YES canMakePaymentsExpectation:NO]);
     199
     200    WKWebViewConfiguration *configuration = [WKWebViewConfiguration _test_configurationWithTestPlugInClassName:@"WebProcessPlugInWithInternals"];
     201    [configuration.userContentController addScriptMessageHandler:messageHandler.get() name:@"testApplePay"];
     202
     203    auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectZero configuration:configuration]);
     204    [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"https://bundle-file/apple-pay-availability-existing-object.html"]]];
    169205
    170206    Util::run(&isDone);
     
    179215}
    180216
    181 TEST(ApplePay, ActiveSessionBlocksUserAgentScripts)
    182 {
    183     [TestProtocol registerWithScheme:@"https"];
    184 
    185     auto userScript = adoptNS([[WKUserScript alloc] initWithSource:@"window.wkUserScriptInjected = true" injectionTime:WKUserScriptInjectionTimeAtDocumentStart forMainFrameOnly:YES]);
    186 
    187     WKWebViewConfiguration *configuration = [WKWebViewConfiguration _test_configurationWithTestPlugInClassName:@"WebProcessPlugInWithInternals"];
    188 
    189     auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectZero configuration:configuration]);
    190     [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"https://bundle-html-file/apple-pay-active-session"]]];
    191     [webView _test_waitForDidFinishNavigation];
     217static void runActiveSessionTest(NSURL *url, BOOL shouldBlockScripts)
     218{
     219    [TestProtocol registerWithScheme:@"https"];
     220
     221    auto messageHandler = adoptNS([[TestApplePayActiveSessionScriptMessageHandler alloc] init]);
     222    auto userScript = adoptNS([[WKUserScript alloc] initWithSource:userScriptSource injectionTime:WKUserScriptInjectionTimeAtDocumentStart forMainFrameOnly:YES]);
     223
     224    WKWebViewConfiguration *configuration = [WKWebViewConfiguration _test_configurationWithTestPlugInClassName:@"WebProcessPlugInWithInternals"];
     225    [configuration.userContentController addScriptMessageHandler:messageHandler.get() name:@"testApplePay"];
     226
     227    auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectZero configuration:configuration]);
     228    [webView loadRequest:[NSURLRequest requestWithURL:url]];
     229    Util::run(&isDone);
    192230
    193231    [configuration.userContentController _addUserScriptImmediately:userScript.get()];
    194232    [webView evaluateJavaScript:@"window.wkUserScriptInjected" completionHandler:^(id _Nullable result, NSError * _Nullable error) {
    195         EXPECT_NULL(result);
    196         EXPECT_NOT_NULL(error);
     233        EXPECT_EQ(shouldBlockScripts, !result);
     234        EXPECT_EQ(shouldBlockScripts, !!error);
    197235        isDone = true;
    198236    }];
    199     Util::run(&isDone);
    200 
    201     [TestProtocol unregister];
     237
     238    isDone = false;
     239    Util::run(&isDone);
     240
     241    [TestProtocol unregister];
     242}
     243
     244TEST(ApplePay, ActiveSessionBlocksUserAgentScripts)
     245{
     246    runActiveSessionTest([NSURL URLWithString:@"https://bundle-file/apple-pay-active-session.html"], YES);
     247}
     248
     249TEST(ApplePay, CanMakePaymentsBlocksUserAgentScripts)
     250{
     251    runActiveSessionTest([NSURL URLWithString:@"https://bundle-file/apple-pay-can-make-payments.html"], YES);
     252}
     253
     254TEST(ApplePay, CanMakePaymentsFalseDoesNotBlockUserAgentScripts)
     255{
     256    runActiveSessionTest([NSURL URLWithString:@"https://bundle-file/apple-pay-can-make-payments.html?false"], NO);
     257}
     258
     259TEST(ApplePay, CanMakePaymentsWithActiveCardBlocksUserAgentScripts)
     260{
     261    runActiveSessionTest([NSURL URLWithString:@"https://bundle-file/apple-pay-can-make-payments-with-active-card.html"], YES);
     262}
     263
     264TEST(ApplePay, CanMakePaymentsWithActiveCardFalseDoesNotBlockUserAgentScripts)
     265{
     266    runActiveSessionTest([NSURL URLWithString:@"https://bundle-file/apple-pay-can-make-payments-with-active-card.html?false"], NO);
     267}
     268
     269TEST(ApplePay, CanMakePaymentBlocksUserAgentScripts)
     270{
     271    runActiveSessionTest([NSURL URLWithString:@"https://bundle-file/apple-pay-can-make-payment.html"], YES);
     272}
     273
     274TEST(ApplePay, CanMakePaymentFalseDoesNotBlockUserAgentScripts)
     275{
     276    runActiveSessionTest([NSURL URLWithString:@"https://bundle-file/apple-pay-can-make-payment.html?false"], NO);
    202277}
    203278
  • trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/Download.mm

    r246043 r246056  
    974974    [webView configuration].processPool._downloadDelegate = delegate.get();
    975975
    976     NSURL *firstURL = [NSURL URLWithString:@"http://bundle-html-file/simple"];
     976    NSURL *firstURL = [NSURL URLWithString:@"http://bundle-file/simple.html"];
    977977    [delegate setResponsePolicy:WKNavigationResponsePolicyAllow];
    978978    [webView loadRequest:[NSURLRequest requestWithURL:firstURL]];
     
    984984    EXPECT_WK_STREQ(firstURL.absoluteString, [webView URL].absoluteString);
    985985
    986     NSURL *secondURL = [NSURL URLWithString:@"http://bundle-html-file/simple2"];
     986    NSURL *secondURL = [NSURL URLWithString:@"http://bundle-file/simple2.html"];
    987987    [delegate setResponsePolicy:_WKNavigationResponsePolicyBecomeDownload];
    988988    [webView loadRequest:[NSURLRequest requestWithURL:secondURL]];
  • trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/apple-pay-active-session.html

    r243324 r246056  
    33<script>
    44    internals.mockPaymentCoordinator.supportsUnrestrictedApplePay = false;
    5     internals.setHasStartedApplePaySession();
     5    internals.setApplePayIsActive();
     6    window.webkit.messageHandlers.testApplePay.postMessage("done");
    67</script>
  • trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/apple-pay-availability-in-iframe.html

    r243324 r246056  
    22<body>
    33<script>
     4    internals.mockPaymentCoordinator.supportsUnrestrictedApplePay = window.location.search === "?unrestricted" ? true : false;
    45    loadApplePayFrame = () => {
    56        const iframe = document.createElement('iframe');
    6         iframe.src = 'https://bundle-html-file/apple-pay-availability';
     7        iframe.src = 'apple-pay-availability.html' + window.location.search;
    78        document.body.appendChild(iframe);
    89    };
  • trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/apple-pay-availability.html

    r245314 r246056  
    11<!DOCTYPE html>
    22<body>
     3<script src="apple-pay.js"></script>
    34<script>
    4     const applePayRequestBase = () => {
    5         return {
    6             merchantCapabilities: ['supports3DS'],
    7             supportedNetworks: ['visa'],
    8             countryCode: 'US',
    9         };
    10     };
    11 
    12     const applePayPaymentRequest = () => {
    13         const request = applePayRequestBase();
    14         request.total = { label: 'total', amount: '0.00' };
    15         request.currencyCode = 'USD';
    16         return request;
    17     };
    18 
    19     const applePayMethod = () => {
    20         const request = applePayRequestBase();
    21         request.version = 1;
    22         request.merchantIdentifier = '';
    23         return {
    24             supportedMethods: 'https://apple.com/apple-pay',
    25             data: request,
    26         };
    27     };
    28 
    29     const eventListener = async () => {
    30         internals.mockPaymentCoordinator.supportsUnrestrictedApplePay = false;
     5    window.addEventListener('load', async () => {
     6        internals.mockPaymentCoordinator.supportsUnrestrictedApplePay = window.location.search === "?unrestricted" ? true : false;
    317
    328        const applePaySessionAvailable = !!window.ApplePaySession;
     
    4117        const canMakePaymentsWithActiveCard = await ApplePaySession.canMakePaymentsWithActiveCard('');
    4218
    43         if (!window.wkPaymentRequest) {
    44             wkPaymentRequest = new PaymentRequest([applePayMethod()], {
    45                 total: {
    46                     label: 'total',
    47                     amount: { currency: 'USD', value: '0.00' },
    48                 },
    49             });
    50         }
    51 
    52         const canMakePayment = await wkPaymentRequest.canMakePayment();
     19        const paymentRequest = new PaymentRequest([applePayMethod()], applePayDetails);
     20        const canMakePayment = await paymentRequest.canMakePayment();
    5321
    5422        window.webkit.messageHandlers.testApplePay.postMessage({
     
    6028            canMakePayment,
    6129        });
    62     };
    63 
    64     window.addEventListener('load', eventListener);
    65     window.addEventListener('hashchange', eventListener);
     30    });
    6631</script>
  • trunk/Tools/TestWebKitAPI/cocoa/TestProtocol.mm

    r246043 r246056  
    2929#import <WebKit/WKBrowsingContextController.h>
    3030#import <wtf/RetainPtr.h>
     31
     32#if PLATFORM(IOS_FAMILY)
     33#include <MobileCoreServices/MobileCoreServices.h>
     34#endif
    3135
    3236static NSString *testScheme;
     
    8791}
    8892
     93static NSString *contentTypeForFileExtension(NSString *fileExtension)
     94{
     95    auto identifier = adoptCF(UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, (__bridge CFStringRef)fileExtension, nullptr));
     96    auto mimeType = adoptCF(UTTypeCopyPreferredTagWithClass(identifier.get(), kUTTagClassMIMEType));
     97    return (__bridge NSString *)mimeType.autorelease();
     98}
     99
    89100- (void)startLoading
    90101{
     
    107118    }
    108119
     120    NSString *contentType;
    109121    NSData *data;
    110     if ([requestURL.host isEqualToString:@"bundle-html-file"])
    111         data = [NSData dataWithContentsOfURL:[NSBundle.mainBundle URLForResource:requestURL.lastPathComponent.stringByDeletingPathExtension withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"]];
    112     else
     122    if ([requestURL.host isEqualToString:@"bundle-file"]) {
     123        NSString *fileName = requestURL.lastPathComponent;
     124        NSString *fileExtension = fileName.pathExtension;
     125        contentType = contentTypeForFileExtension(fileExtension);
     126        data = [NSData dataWithContentsOfURL:[NSBundle.mainBundle URLForResource:fileName.stringByDeletingPathExtension withExtension:fileExtension subdirectory:@"TestWebKitAPI.resources"]];
     127    } else {
     128        contentType = @"text/html";
    113129        data = [@"PASS" dataUsingEncoding:NSASCIIStringEncoding];
     130    }
    114131
    115132    NSMutableDictionary *responseHeaders = [NSMutableDictionary dictionaryWithCapacity:2];
    116     responseHeaders[@"Content-Type"] = @"text/html";
     133    responseHeaders[@"Content-Type"] = contentType;
    117134    responseHeaders[@"Content-Length"] = [NSString stringWithFormat:@"%tu", data.length];
    118135    if (additionalResponseHeaders)
Note: See TracChangeset for help on using the changeset viewer.