Skip to content

Commit

Permalink
[Apple Pay] Populate PKPaymentRequest with originating user agent whe…
Browse files Browse the repository at this point in the history
…n possible

https://bugs.webkit.org/show_bug.cgi?id=264244
rdar://113974599

Reviewed by Megan Gardner.

This patch queries for the UA string corresponding to the originating
web page of a payment request and populates the `PKPaymentRequest`
object with said data when possible.

* Source/WTF/wtf/PlatformHave.h:
* Source/WebCore/PAL/pal/spi/cocoa/PassKitSPI.h:
* Source/WebKit/Shared/ApplePay/WebPaymentCoordinatorProxy.h:
* Source/WebKit/Shared/ApplePay/cocoa/WebPaymentCoordinatorProxyCocoa.mm:
(WebKit::WebPaymentCoordinatorProxy::platformPaymentRequest):
* Source/WebKit/Shared/ApplePay/ios/WebPaymentCoordinatorProxyIOS.mm:
(WebKit::WebPaymentCoordinatorProxy::platformShowPaymentUI):
* Source/WebKit/Shared/ApplePay/mac/WebPaymentCoordinatorProxyMac.mm:
(WebKit::WebPaymentCoordinatorProxy::platformShowPaymentUI):

Canonical link: https://commits.webkit.org/270312@main
  • Loading branch information
aprotyas committed Nov 7, 2023
1 parent f915246 commit 12b91c5
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 6 deletions.
1 change: 0 additions & 1 deletion Source/WTF/wtf/PlatformHave.h
Original file line number Diff line number Diff line change
Expand Up @@ -688,7 +688,6 @@
#define HAVE_PASSKIT_APPLE_PAY_LATER_AVAILABILITY 1
#endif


#if PLATFORM(IOS) || PLATFORM(MAC) || PLATFORM(VISION)
#define HAVE_DISPLAY_LAYER_BIPLANAR_SUPPORT 1
#endif
Expand Down
7 changes: 7 additions & 0 deletions Source/WebCore/PAL/pal/spi/cocoa/PassKitSPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,13 @@ typedef void(^PKCanMakePaymentsCompletion)(BOOL isValid, NSError *);
@end
#endif

#if HAVE(PKPAYMENTREQUEST_USERAGENT)
// FIXME: <rdar://116640656> Remove `PKPaymentRequest.userAgent` staging code
@interface PKPaymentRequest (Staging_110687914)
@property (nonatomic, copy) NSString *userAgent;
@end
#endif

NS_ASSUME_NONNULL_END

#define PAL_PASSKIT_SPI_GUARD_AGAINST_INDIRECT_INCLUSION
Expand Down
2 changes: 1 addition & 1 deletion Source/WebKit/Shared/ApplePay/WebPaymentCoordinatorProxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ class WebPaymentCoordinatorProxy
void platformCompletePaymentSession(WebCore::ApplePayPaymentAuthorizationResult&&);
void platformHidePaymentUI();
#if PLATFORM(COCOA)
RetainPtr<PKPaymentRequest> platformPaymentRequest(const URL& originatingURL, const Vector<URL>& linkIconURLs, const WebCore::ApplePaySessionPaymentRequest&);
RetainPtr<PKPaymentRequest> platformPaymentRequest(WebPageProxyIdentifier, const URL& originatingURL, const Vector<URL>& linkIconURLs, const WebCore::ApplePaySessionPaymentRequest&);
#endif

Client& m_client;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ static PKPaymentRequestAPIType toAPIType(WebCore::ApplePaySessionPaymentRequest:
}
}

RetainPtr<PKPaymentRequest> WebPaymentCoordinatorProxy::platformPaymentRequest(const URL& originatingURL, const Vector<URL>& linkIconURLs, const WebCore::ApplePaySessionPaymentRequest& paymentRequest)
RetainPtr<PKPaymentRequest> WebPaymentCoordinatorProxy::platformPaymentRequest(WebPageProxyIdentifier webPageProxyID, const URL& originatingURL, const Vector<URL>& linkIconURLs, const WebCore::ApplePaySessionPaymentRequest& paymentRequest)
{
auto result = adoptNS([PAL::allocPKPaymentRequestInstance() init]);

Expand Down Expand Up @@ -390,6 +390,19 @@ static PKPaymentRequestAPIType toAPIType(WebCore::ApplePaySessionPaymentRequest:
[result setDeferredPaymentRequest:platformDeferredPaymentRequest(*deferredPaymentRequest).get()];
#endif

#if HAVE(PKPAYMENTREQUEST_USERAGENT)
auto userAgent = [webPageProxyID] {
if (auto page = WebProcessProxy::webPage(webPageProxyID))
return page->userAgent();
return WebPageProxy::standardUserAgent();
}();
// FIXME: <rdar://116640656> Remove this selector check when its corresponding staging declaration is removed.
if ([result respondsToSelector:@selector(setUserAgent:)])
[result setUserAgent:userAgent];
#else
UNUSED_PARAM(webPageProxyID);
#endif // HAVE(PKPAYMENTREQUEST_USERAGENT)

return result;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@

void WebPaymentCoordinatorProxy::platformShowPaymentUI(WebPageProxyIdentifier webPageProxyID, const URL& originatingURL, const Vector<URL>& linkIconURLStrings, const WebCore::ApplePaySessionPaymentRequest& request, CompletionHandler<void(bool)>&& completionHandler)
{
auto paymentRequest = platformPaymentRequest(originatingURL, linkIconURLStrings, request);
auto paymentRequest = platformPaymentRequest(webPageProxyID, originatingURL, linkIconURLStrings, request);

ASSERT(!m_authorizationPresenter);
m_authorizationPresenter = m_client.paymentCoordinatorAuthorizationPresenter(*this, paymentRequest.get());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
});
}

void WebPaymentCoordinatorProxy::platformShowPaymentUI(WebPageProxyIdentifier, const URL& originatingURL, const Vector<URL>& linkIconURLStrings, const WebCore::ApplePaySessionPaymentRequest& request, CompletionHandler<void(bool)>&& completionHandler)
void WebPaymentCoordinatorProxy::platformShowPaymentUI(WebPageProxyIdentifier webPageProxyID, const URL& originatingURL, const Vector<URL>& linkIconURLStrings, const WebCore::ApplePaySessionPaymentRequest& request, CompletionHandler<void(bool)>&& completionHandler)
{
#if HAVE(PASSKIT_MODULARIZATION) && HAVE(PASSKIT_MAC_HELPER_TEMP)
if (!PAL::isPassKitMacHelperTempFrameworkAvailable())
Expand All @@ -64,7 +64,7 @@
#endif
return completionHandler(false);

auto paymentRequest = platformPaymentRequest(originatingURL, linkIconURLStrings, request);
auto paymentRequest = platformPaymentRequest(webPageProxyID, originatingURL, linkIconURLStrings, request);

auto showPaymentUIRequestSeed = m_showPaymentUIRequestSeed;
WeakPtr weakThis { *this };
Expand Down

0 comments on commit 12b91c5

Please sign in to comment.