Changeset 246056 in webkit
- Timestamp:
- Jun 3, 2019 11:36:05 PM (5 years ago)
- Location:
- trunk
- Files:
-
- 5 added
- 16 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r246052 r246056 1 2019-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 1 48 2019-06-03 Robin Morisset <rmorisset@apple.com> 2 49 -
trunk/Source/WebCore/Modules/applepay/PaymentCoordinator.cpp
r245314 r246056 57 57 } 58 58 59 bool PaymentCoordinator::supportsVersion(Document& document, unsigned version) const 60 { 61 if (!shouldAllowApplePay(document)) 62 return false; 63 59 bool PaymentCoordinator::supportsVersion(Document&, unsigned version) const 60 { 64 61 auto supportsVersion = m_client.supportsVersion(version); 65 62 RELEASE_LOG_IF_ALLOWED("supportsVersion(%d) -> %d", version, supportsVersion); … … 69 66 bool PaymentCoordinator::canMakePayments(Document& document) 70 67 { 71 if (!shouldAllowApplePay(document))72 return false;73 74 68 auto canMakePayments = m_client.canMakePayments(); 75 69 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; 77 78 } 78 79 79 80 void PaymentCoordinator::canMakePaymentsWithActiveCard(Document& document, const String& merchantIdentifier, WTF::Function<void(bool)>&& completionHandler) 80 81 { 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 }); 86 96 } 87 97 88 98 void PaymentCoordinator::openPaymentSetup(Document& document, const String& merchantIdentifier, WTF::Function<void(bool)>&& completionHandler) 89 99 { 90 if (!shouldAllowApplePay(document))91 return completionHandler(false);92 93 100 RELEASE_LOG_IF_ALLOWED("openPaymentSetup()"); 94 101 m_client.openPaymentSetup(merchantIdentifier, document.domain(), WTFMove(completionHandler)); … … 99 106 ASSERT(!m_activeSession); 100 107 101 if (!s houldAllowApplePay(document))108 if (!setApplePayIsActiveIfAllowed(document)) 102 109 return false; 103 110 … … 112 119 113 120 m_activeSession = &paymentSession; 114 document.setHasStartedApplePaySession();115 121 return true; 116 122 } … … 240 246 } 241 247 242 Optional<String> PaymentCoordinator::validatedPaymentNetwork(Document& document, unsigned version, const String& paymentNetwork) const 243 { 244 if (!shouldAllowApplePay(document)) 245 return WTF::nullopt; 246 248 Optional<String> PaymentCoordinator::validatedPaymentNetwork(Document&, unsigned version, const String& paymentNetwork) const 249 { 247 250 if (version < 2 && equalIgnoringASCIICase(paymentNetwork, "jcb")) 248 251 return WTF::nullopt; … … 270 273 } 271 274 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 275 bool PaymentCoordinator::setApplePayIsActiveIfAllowed(Document& document) const 276 { 279 277 auto hasEvaluatedUserAgentScripts = document.hasEvaluatedUserAgentScripts(); 280 278 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(); 288 289 return true; 289 290 } … … 291 292 bool PaymentCoordinator::shouldAllowUserAgentScripts(Document& document) const 292 293 { 293 if (m_client.supportsUnrestrictedApplePay() )294 if (m_client.supportsUnrestrictedApplePay() || !document.isApplePayActive()) 294 295 return true; 295 296 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; 303 301 } 304 302 -
trunk/Source/WebCore/Modules/applepay/PaymentCoordinator.h
r245314 r246056 30 30 #include "ApplePaySessionPaymentRequest.h" 31 31 #include <wtf/Function.h> 32 #include <wtf/WeakPtr.h> 32 33 33 34 namespace WebCore { … … 46 47 struct ShippingMethodUpdate; 47 48 48 class PaymentCoordinator {49 class PaymentCoordinator : public CanMakeWeakPtr<PaymentCoordinator> { 49 50 WTF_MAKE_FAST_ALLOCATED; 50 51 public: … … 80 81 81 82 bool shouldEnableApplePayAPIs(Document&) const; 82 WEBCORE_EXPORT bool shouldAllowApplePay(Document&) const;83 83 WEBCORE_EXPORT bool shouldAllowUserAgentScripts(Document&) const; 84 84 85 85 private: 86 bool setApplePayIsActiveIfAllowed(Document&) const; 87 86 88 PaymentCoordinatorClient& m_client; 87 88 89 RefPtr<PaymentSession> m_activeSession; 89 90 }; -
trunk/Source/WebCore/dom/Document.cpp
r246002 r246056 8250 8250 #if ENABLE(APPLE_PAY) 8251 8251 8252 bool Document:: hasStartedApplePaySession() const8252 bool Document::isApplePayActive() const 8253 8253 { 8254 8254 auto& top = topDocument(); 8255 return this == &top ? m_hasStartedApplePaySession : top. hasStartedApplePaySession();8256 } 8257 8258 void Document::set HasStartedApplePaySession()8255 return this == &top ? m_hasStartedApplePaySession : top.isApplePayActive(); 8256 } 8257 8258 void Document::setApplePayIsActive() 8259 8259 { 8260 8260 auto& top = topDocument(); … … 8262 8262 m_hasStartedApplePaySession = true; 8263 8263 else 8264 top.set HasStartedApplePaySession();8264 top.setApplePayIsActive(); 8265 8265 } 8266 8266 -
trunk/Source/WebCore/dom/Document.h
r245958 r246056 1523 1523 void setHasEvaluatedUserAgentScripts(); 1524 1524 #if ENABLE(APPLE_PAY) 1525 WEBCORE_EXPORT bool hasStartedApplePaySession() const;1526 WEBCORE_EXPORT void set HasStartedApplePaySession();1525 WEBCORE_EXPORT bool isApplePayActive() const; 1526 WEBCORE_EXPORT void setApplePayIsActive(); 1527 1527 #endif 1528 1528 -
trunk/Source/WebCore/testing/Internals.cpp
r246002 r246056 4604 4604 4605 4605 #if ENABLE(APPLE_PAY) 4606 void Internals::set HasStartedApplePaySession(Document& document)4607 { 4608 document.set HasStartedApplePaySession();4606 void Internals::setApplePayIsActive(Document& document) 4607 { 4608 document.setApplePayIsActive(); 4609 4609 } 4610 4610 #endif -
trunk/Source/WebCore/testing/Internals.h
r246002 r246056 682 682 void setAsRunningUserScripts(Document&); 683 683 #if ENABLE(APPLE_PAY) 684 void set HasStartedApplePaySession(Document&);684 void setApplePayIsActive(Document&); 685 685 #endif 686 686 -
trunk/Source/WebCore/testing/Internals.idl
r246002 r246056 658 658 659 659 [CallWith=Document] void setAsRunningUserScripts(); 660 [CallWith=Document, Conditional=APPLE_PAY] void set HasStartedApplePaySession();660 [CallWith=Document, Conditional=APPLE_PAY] void setApplePayIsActive(); 661 661 662 662 void disableTileSizeUpdateDelay(); -
trunk/Tools/ChangeLog
r246050 r246056 1 2019-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 1 31 2019-06-03 Sihui Liu <sihui_liu@apple.com> 2 32 -
trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj
r245998 r246056 731 731 A1DF74321C41B65800A2F4D0 /* AlwaysRevalidatedURLSchemes.mm in Sources */ = {isa = PBXBuildFile; fileRef = A1DF74301C41B65800A2F4D0 /* AlwaysRevalidatedURLSchemes.mm */; }; 732 732 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 */; }; 733 738 A310827221F296FF00C28B97 /* FileSystem.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A310827121F296EC00C28B97 /* FileSystem.cpp */; }; 734 739 A57A34F216AF6B2B00C2501F /* PageVisibilityStateWithWindowChanges.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = A57A34F116AF69E200C2501F /* PageVisibilityStateWithWindowChanges.html */; }; … … 1050 1055 F4A9202F1FEE34E900F59590 /* apple-data-url.html in Copy Resources */, 1051 1056 A1798B8B224361A4000764BD /* apple-pay-active-session.html in Copy Resources */, 1057 A1FB503D22A1CBE200D4D979 /* apple-pay-availability-existing-object.html in Copy Resources */, 1052 1058 A1798B8922435E29000764BD /* apple-pay-availability-in-iframe.html in Copy Resources */, 1053 1059 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 */, 1054 1064 F46A095A1ED8A6E600D4AA55 /* apple.gif in Copy Resources */, 1055 1065 5C9E59411D3EB5AC00E3C62E /* ApplicationCache.db in Copy Resources */, … … 2029 2039 A1DF74301C41B65800A2F4D0 /* AlwaysRevalidatedURLSchemes.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = AlwaysRevalidatedURLSchemes.mm; sourceTree = "<group>"; }; 2030 2040 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>"; }; 2031 2046 A1FDFD2E19C288BB005148A4 /* WKImageCreateCGImageCrash.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WKImageCreateCGImageCrash.cpp; sourceTree = "<group>"; }; 2032 2047 A310827121F296EC00C28B97 /* FileSystem.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = FileSystem.cpp; sourceTree = "<group>"; }; … … 2960 2975 F4A9202E1FEE34C800F59590 /* apple-data-url.html */, 2961 2976 A1798B8A2243611A000764BD /* apple-pay-active-session.html */, 2977 A1FB503C22A1C24400D4D979 /* apple-pay-availability-existing-object.html */, 2962 2978 A1798B8822435D2E000764BD /* apple-pay-availability-in-iframe.html */, 2963 2979 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 */, 2964 2984 F47D30EB1ED28619000482E1 /* apple.gif */, 2965 2985 5C9E593E1D3EB1DE00E3C62E /* ApplicationCache.db */, -
trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/ApplePay.mm
r245314 r246056 38 38 39 39 static bool isDone; 40 41 @interface TestApplePayScriptMessageHandler : NSObject <WKScriptMessageHandler> 40 static NSString * const userScriptSource = @"window.wkUserScriptInjected = true"; 41 42 @interface TestApplePayAvailableScriptMessageHandler : NSObject <WKScriptMessageHandler> 42 43 43 44 - (instancetype)init NS_UNAVAILABLE; … … 49 50 @end 50 51 51 @implementation TestApplePay ScriptMessageHandler52 @implementation TestApplePayAvailableScriptMessageHandler 52 53 53 54 - (instancetype)initWithAPIsAvailableExpectation:(BOOL)apisAvailableExpectation canMakePaymentsExpectation:(BOOL)canMakePaymentsExpectation … … 65 66 EXPECT_EQ(_apisAvailableExpectation, [[message.body objectForKey:@"applePaySessionAvailable"] boolValue]); 66 67 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]); 68 69 EXPECT_EQ(_canMakePaymentsExpectation, [[message.body objectForKey:@"canMakePayments"] boolValue]); 69 70 EXPECT_EQ(_canMakePaymentsExpectation, [[message.body objectForKey:@"canMakePaymentsWithActiveCard"] boolValue]); … … 74 75 @end 75 76 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 76 89 namespace TestWebKitAPI { 77 90 … … 80 93 [TestProtocol registerWithScheme:@"https"]; 81 94 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 108 TEST(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]); 91 127 92 128 [TestProtocol unregister]; … … 97 133 [TestProtocol registerWithScheme:@"https"]; 98 134 99 auto messageHandler = adoptNS([[TestApplePay ScriptMessageHandler 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]); 101 137 102 138 WKWebViewConfiguration *configuration = [WKWebViewConfiguration _test_configurationWithTestPlugInClassName:@"WebProcessPlugInWithInternals"]; … … 105 141 106 142 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"]]]; 108 144 109 145 Util::run(&isDone); … … 118 154 [TestProtocol registerWithScheme:@"https"]; 119 155 120 auto messageHandler = adoptNS([[TestApplePay ScriptMessageHandler 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]); 122 158 123 159 WKWebViewConfiguration *configuration = [WKWebViewConfiguration _test_configurationWithTestPlugInClassName:@"WebProcessPlugInWithInternals"]; … … 126 162 127 163 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"]]]; 129 165 130 166 Util::run(&isDone); … … 139 175 [TestProtocol registerWithScheme:@"https"]; 140 176 141 auto messageHandler = adoptNS([[TestApplePay ScriptMessageHandler 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"]]]; 148 184 [webView _test_waitForDidFinishNavigation]; 149 185 [webView evaluateJavaScript:@"window.wkScriptEvaluated = true; loadApplePayFrame();" completionHandler:nil]; … … 160 196 [TestProtocol registerWithScheme:@"https"]; 161 197 162 auto messageHandler = adoptNS([[TestApplePay ScriptMessageHandler 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"]]]; 169 205 170 206 Util::run(&isDone); … … 179 215 } 180 216 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]; 217 static 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); 192 230 193 231 [configuration.userContentController _addUserScriptImmediately:userScript.get()]; 194 232 [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); 197 235 isDone = true; 198 236 }]; 199 Util::run(&isDone); 200 201 [TestProtocol unregister]; 237 238 isDone = false; 239 Util::run(&isDone); 240 241 [TestProtocol unregister]; 242 } 243 244 TEST(ApplePay, ActiveSessionBlocksUserAgentScripts) 245 { 246 runActiveSessionTest([NSURL URLWithString:@"https://bundle-file/apple-pay-active-session.html"], YES); 247 } 248 249 TEST(ApplePay, CanMakePaymentsBlocksUserAgentScripts) 250 { 251 runActiveSessionTest([NSURL URLWithString:@"https://bundle-file/apple-pay-can-make-payments.html"], YES); 252 } 253 254 TEST(ApplePay, CanMakePaymentsFalseDoesNotBlockUserAgentScripts) 255 { 256 runActiveSessionTest([NSURL URLWithString:@"https://bundle-file/apple-pay-can-make-payments.html?false"], NO); 257 } 258 259 TEST(ApplePay, CanMakePaymentsWithActiveCardBlocksUserAgentScripts) 260 { 261 runActiveSessionTest([NSURL URLWithString:@"https://bundle-file/apple-pay-can-make-payments-with-active-card.html"], YES); 262 } 263 264 TEST(ApplePay, CanMakePaymentsWithActiveCardFalseDoesNotBlockUserAgentScripts) 265 { 266 runActiveSessionTest([NSURL URLWithString:@"https://bundle-file/apple-pay-can-make-payments-with-active-card.html?false"], NO); 267 } 268 269 TEST(ApplePay, CanMakePaymentBlocksUserAgentScripts) 270 { 271 runActiveSessionTest([NSURL URLWithString:@"https://bundle-file/apple-pay-can-make-payment.html"], YES); 272 } 273 274 TEST(ApplePay, CanMakePaymentFalseDoesNotBlockUserAgentScripts) 275 { 276 runActiveSessionTest([NSURL URLWithString:@"https://bundle-file/apple-pay-can-make-payment.html?false"], NO); 202 277 } 203 278 -
trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/Download.mm
r246043 r246056 974 974 [webView configuration].processPool._downloadDelegate = delegate.get(); 975 975 976 NSURL *firstURL = [NSURL URLWithString:@"http://bundle- html-file/simple"];976 NSURL *firstURL = [NSURL URLWithString:@"http://bundle-file/simple.html"]; 977 977 [delegate setResponsePolicy:WKNavigationResponsePolicyAllow]; 978 978 [webView loadRequest:[NSURLRequest requestWithURL:firstURL]]; … … 984 984 EXPECT_WK_STREQ(firstURL.absoluteString, [webView URL].absoluteString); 985 985 986 NSURL *secondURL = [NSURL URLWithString:@"http://bundle- html-file/simple2"];986 NSURL *secondURL = [NSURL URLWithString:@"http://bundle-file/simple2.html"]; 987 987 [delegate setResponsePolicy:_WKNavigationResponsePolicyBecomeDownload]; 988 988 [webView loadRequest:[NSURLRequest requestWithURL:secondURL]]; -
trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/apple-pay-active-session.html
r243324 r246056 3 3 <script> 4 4 internals.mockPaymentCoordinator.supportsUnrestrictedApplePay = false; 5 internals.setHasStartedApplePaySession(); 5 internals.setApplePayIsActive(); 6 window.webkit.messageHandlers.testApplePay.postMessage("done"); 6 7 </script> -
trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/apple-pay-availability-in-iframe.html
r243324 r246056 2 2 <body> 3 3 <script> 4 internals.mockPaymentCoordinator.supportsUnrestrictedApplePay = window.location.search === "?unrestricted" ? true : false; 4 5 loadApplePayFrame = () => { 5 6 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; 7 8 document.body.appendChild(iframe); 8 9 }; -
trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/apple-pay-availability.html
r245314 r246056 1 1 <!DOCTYPE html> 2 2 <body> 3 <script src="apple-pay.js"></script> 3 4 <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; 31 7 32 8 const applePaySessionAvailable = !!window.ApplePaySession; … … 41 17 const canMakePaymentsWithActiveCard = await ApplePaySession.canMakePaymentsWithActiveCard(''); 42 18 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(); 53 21 54 22 window.webkit.messageHandlers.testApplePay.postMessage({ … … 60 28 canMakePayment, 61 29 }); 62 }; 63 64 window.addEventListener('load', eventListener); 65 window.addEventListener('hashchange', eventListener); 30 }); 66 31 </script> -
trunk/Tools/TestWebKitAPI/cocoa/TestProtocol.mm
r246043 r246056 29 29 #import <WebKit/WKBrowsingContextController.h> 30 30 #import <wtf/RetainPtr.h> 31 32 #if PLATFORM(IOS_FAMILY) 33 #include <MobileCoreServices/MobileCoreServices.h> 34 #endif 31 35 32 36 static NSString *testScheme; … … 87 91 } 88 92 93 static 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 89 100 - (void)startLoading 90 101 { … … 107 118 } 108 119 120 NSString *contentType; 109 121 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"; 113 129 data = [@"PASS" dataUsingEncoding:NSASCIIStringEncoding]; 130 } 114 131 115 132 NSMutableDictionary *responseHeaders = [NSMutableDictionary dictionaryWithCapacity:2]; 116 responseHeaders[@"Content-Type"] = @"text/html";133 responseHeaders[@"Content-Type"] = contentType; 117 134 responseHeaders[@"Content-Length"] = [NSString stringWithFormat:@"%tu", data.length]; 118 135 if (additionalResponseHeaders)
Note: See TracChangeset
for help on using the changeset viewer.