Changeset 241611 in webkit
- Timestamp:
- Feb 15, 2019 1:25:28 PM (5 years ago)
- Location:
- trunk/Source/WebKit
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebKit/ChangeLog
r241609 r241611 1 2019-02-15 Alex Christensen <achristensen@webkit.org> 2 3 Make WebPaymentCoordinatorProxy more robust and modern 4 https://bugs.webkit.org/show_bug.cgi?id=194678 5 6 Reviewed by Andy Estes. 7 8 Use WeakPtr instead of storing raw pointers in lambdas or the global activePaymentCoordinatorProxy to avoid UAF problems. 9 Call CompletionHandlers in all code paths to avoid hangs. 10 Use Delayed instead of LegacySync for synchronous messaging to progress towards removing LegacySync messages. 11 12 * Scripts/webkit/messages.py: 13 * UIProcess/ApplePay/WebPaymentCoordinatorProxy.cpp: 14 (WebKit::activePaymentCoordinatorProxy): 15 (WebKit::WebPaymentCoordinatorProxy::~WebPaymentCoordinatorProxy): 16 (WebKit::WebPaymentCoordinatorProxy::availablePaymentNetworks): 17 (WebKit::WebPaymentCoordinatorProxy::canMakePayments): 18 (WebKit::WebPaymentCoordinatorProxy::showPaymentUI): 19 (WebKit::WebPaymentCoordinatorProxy::didReachFinalState): 20 * UIProcess/ApplePay/WebPaymentCoordinatorProxy.h: 21 * UIProcess/ApplePay/WebPaymentCoordinatorProxy.messages.in: 22 * UIProcess/ApplePay/ios/WebPaymentCoordinatorProxyIOS.mm: 23 (WebKit::WebPaymentCoordinatorProxy::platformShowPaymentUI): 24 * UIProcess/ApplePay/mac/WebPaymentCoordinatorProxyMac.mm: 25 (WebKit::WebPaymentCoordinatorProxy::platformShowPaymentUI): 26 1 27 2019-02-15 Youenn Fablet <youenn@apple.com> 2 28 -
trunk/Source/WebKit/Scripts/webkit/messages.py
r241595 r241611 190 190 ]) 191 191 192 for message in receiver.messages: 193 if message.reply_parameters != None: 194 headers.add('<wtf/ThreadSafeRefCounted.h>') 195 types_by_namespace['IPC'].update([('class', 'Connection')]) 192 headers.add('"Connection.h"') 193 headers.add('<wtf/ThreadSafeRefCounted.h>') 196 194 197 195 no_forward_declaration_types = frozenset([ -
trunk/Source/WebKit/UIProcess/ApplePay/WebPaymentCoordinatorProxy.cpp
r239427 r241611 37 37 namespace WebKit { 38 38 39 static WebPaymentCoordinatorProxy* activePaymentCoordinatorProxy; 39 static WeakPtr<WebPaymentCoordinatorProxy>& activePaymentCoordinatorProxy() 40 { 41 static NeverDestroyed<WeakPtr<WebPaymentCoordinatorProxy>> activePaymentCoordinatorProxy; 42 return activePaymentCoordinatorProxy.get(); 43 } 40 44 41 45 WebPaymentCoordinatorProxy::WebPaymentCoordinatorProxy(WebPageProxy& webPageProxy) … … 50 54 WebPaymentCoordinatorProxy::~WebPaymentCoordinatorProxy() 51 55 { 52 if (activePaymentCoordinatorProxy == this)53 activePaymentCoordinatorProxy = nullptr;54 55 56 if (m_state != State::Idle) 56 57 hidePaymentUI(); … … 59 60 } 60 61 61 void WebPaymentCoordinatorProxy::availablePaymentNetworks( Vector<String>& networks)62 { 63 networks = platformAvailablePaymentNetworks();64 } 65 66 void WebPaymentCoordinatorProxy::canMakePayments( bool& reply)67 { 68 reply = platformCanMakePayments();62 void WebPaymentCoordinatorProxy::availablePaymentNetworks(CompletionHandler<void(Vector<String>&&)>&& completionHandler) 63 { 64 completionHandler(platformAvailablePaymentNetworks()); 65 } 66 67 void WebPaymentCoordinatorProxy::canMakePayments(CompletionHandler<void(bool)>&& reply) 68 { 69 reply(platformCanMakePayments()); 69 70 } 70 71 … … 93 94 } 94 95 95 void WebPaymentCoordinatorProxy::showPaymentUI(const String& originatingURLString, const Vector<String>& linkIconURLStrings, const WebCore::ApplePaySessionPaymentRequest& paymentRequest, bool& result)96 void WebPaymentCoordinatorProxy::showPaymentUI(const String& originatingURLString, const Vector<String>& linkIconURLStrings, const WebCore::ApplePaySessionPaymentRequest& paymentRequest, CompletionHandler<void(bool)>&& completionHandler) 96 97 { 97 98 // FIXME: Make this a message check. 98 99 ASSERT(canBegin()); 99 100 100 if (a ctivePaymentCoordinatorProxy) {101 activePaymentCoordinatorProxy->hidePaymentUI();102 activePaymentCoordinatorProxy->didCancelPaymentSession();103 } 104 105 activePaymentCoordinatorProxy = this;101 if (auto& coordinator = activePaymentCoordinatorProxy()) { 102 coordinator->hidePaymentUI(); 103 coordinator->didCancelPaymentSession(); 104 } 105 106 activePaymentCoordinatorProxy() = makeWeakPtr(this); 106 107 107 108 m_state = State::Activating; … … 113 114 linkIconURLs.append(URL(URL(), linkIconURLString)); 114 115 115 platformShowPaymentUI(originatingURL, linkIconURLs, paymentRequest, [this](bool result) { 116 ASSERT(m_state == State::Activating); 116 platformShowPaymentUI(originatingURL, linkIconURLs, paymentRequest, [weakThis = makeWeakPtr(*this)](bool result) { 117 if (!weakThis) 118 return; 119 120 ASSERT(weakThis->m_state == State::Activating); 117 121 if (!result) { 118 didCancelPaymentSession();122 weakThis->didCancelPaymentSession(); 119 123 return; 120 124 } 121 125 122 m_state = State::Active;126 weakThis->m_state = State::Active; 123 127 }); 124 128 125 result = true;129 completionHandler(true); 126 130 } 127 131 … … 333 337 m_merchantValidationState = MerchantValidationState::Idle; 334 338 335 ASSERT(activePaymentCoordinatorProxy == this);336 activePaymentCoordinatorProxy = nullptr;339 ASSERT(activePaymentCoordinatorProxy() == this); 340 activePaymentCoordinatorProxy() = nullptr; 337 341 } 338 342 -
trunk/Source/WebKit/UIProcess/ApplePay/WebPaymentCoordinatorProxy.h
r239709 r241611 79 79 80 80 // Message handlers. 81 void availablePaymentNetworks( Vector<String>&);82 void canMakePayments( bool& reply);81 void availablePaymentNetworks(CompletionHandler<void(Vector<String>&&)>&&); 82 void canMakePayments(CompletionHandler<void(bool)>&&); 83 83 void canMakePaymentsWithActiveCard(const String& merchantIdentifier, const String& domainName, uint64_t requestID); 84 84 void openPaymentSetup(const String& merchantIdentifier, const String& domainName, uint64_t requestID); 85 void showPaymentUI(const String& originatingURLString, const Vector<String>& linkIconURLStrings, const WebCore::ApplePaySessionPaymentRequest&, bool& result);85 void showPaymentUI(const String& originatingURLString, const Vector<String>& linkIconURLStrings, const WebCore::ApplePaySessionPaymentRequest&, CompletionHandler<void(bool)>&&); 86 86 void completeMerchantValidation(const WebCore::PaymentMerchantSession&); 87 87 void completeShippingMethodSelection(const Optional<WebCore::ShippingMethodUpdate>&); … … 103 103 void platformCanMakePaymentsWithActiveCard(const String& merchantIdentifier, const String& domainName, WTF::Function<void (bool)>&& completionHandler); 104 104 void platformOpenPaymentSetup(const String& merchantIdentifier, const String& domainName, WTF::Function<void (bool)>&& completionHandler); 105 void platformShowPaymentUI(const URL& originatingURL, const Vector<URL>& linkIconURLs, const WebCore::ApplePaySessionPaymentRequest&, WTF::Function<void(bool)>&& completionHandler);105 void platformShowPaymentUI(const URL& originatingURL, const Vector<URL>& linkIconURLs, const WebCore::ApplePaySessionPaymentRequest&, CompletionHandler<void(bool)>&&); 106 106 void platformCompleteMerchantValidation(const WebCore::PaymentMerchantSession&); 107 107 void platformCompleteShippingMethodSelection(const Optional<WebCore::ShippingMethodUpdate>&); -
trunk/Source/WebKit/UIProcess/ApplePay/WebPaymentCoordinatorProxy.messages.in
r239427 r241611 27 27 messages -> WebPaymentCoordinatorProxy { 28 28 29 AvailablePaymentNetworks() -> (Vector<String> availablePaymentNetworks) LegacySync30 CanMakePayments() -> (bool result) LegacySync29 AvailablePaymentNetworks() -> (Vector<String> availablePaymentNetworks) Delayed 30 CanMakePayments() -> (bool result) Delayed 31 31 CanMakePaymentsWithActiveCard(String merchantIdentifier, String domainName, uint64_t requestID) 32 32 OpenPaymentSetup(String merchantIdentifier, String domainName, uint64_t requestID) 33 33 34 ShowPaymentUI(String originatingURLString, Vector<String> linkIconURLStrings, WebCore::ApplePaySessionPaymentRequest paymentRequest) -> (bool result) LegacySync34 ShowPaymentUI(String originatingURLString, Vector<String> linkIconURLStrings, WebCore::ApplePaySessionPaymentRequest paymentRequest) -> (bool result) Delayed 35 35 CompleteMerchantValidation(WebCore::PaymentMerchantSession paymentMerchantSession) 36 36 CompleteShippingMethodSelection(Optional<WebCore::ShippingMethodUpdate> update) -
trunk/Source/WebKit/UIProcess/ApplePay/ios/WebPaymentCoordinatorProxyIOS.mm
r238771 r241611 39 39 namespace WebKit { 40 40 41 void WebPaymentCoordinatorProxy::platformShowPaymentUI(const URL& originatingURL, const Vector<URL>& linkIconURLStrings, const WebCore::ApplePaySessionPaymentRequest& request, WTF::Function<void(bool)>&& completionHandler)41 void WebPaymentCoordinatorProxy::platformShowPaymentUI(const URL& originatingURL, const Vector<URL>& linkIconURLStrings, const WebCore::ApplePaySessionPaymentRequest& request, CompletionHandler<void(bool)>&& completionHandler) 42 42 { 43 43 UIViewController *presentingViewController = m_webPageProxy.uiClient().presentingViewController(); -
trunk/Source/WebKit/UIProcess/ApplePay/mac/WebPaymentCoordinatorProxyMac.mm
r239078 r241611 36 36 namespace WebKit { 37 37 38 void WebPaymentCoordinatorProxy::platformShowPaymentUI(const URL& originatingURL, const Vector<URL>& linkIconURLStrings, const WebCore::ApplePaySessionPaymentRequest& request, WTF::Function<void(bool)>&& completionHandler)38 void WebPaymentCoordinatorProxy::platformShowPaymentUI(const URL& originatingURL, const Vector<URL>& linkIconURLStrings, const WebCore::ApplePaySessionPaymentRequest& request, CompletionHandler<void(bool)>&& completionHandler) 39 39 { 40 40 auto paymentRequest = toPKPaymentRequest(m_webPageProxy, originatingURL, linkIconURLStrings, request); … … 42 42 auto showPaymentUIRequestSeed = m_showPaymentUIRequestSeed; 43 43 auto weakThis = makeWeakPtr(*this); 44 [PAL::getPKPaymentAuthorizationViewControllerClass() requestViewControllerWithPaymentRequest:paymentRequest.get() completion:makeBlockPtr([paymentRequest, showPaymentUIRequestSeed, weakThis, completionHandler = WTFMove(completionHandler)](PKPaymentAuthorizationViewController *viewController, NSError *error) {44 [PAL::getPKPaymentAuthorizationViewControllerClass() requestViewControllerWithPaymentRequest:paymentRequest.get() completion:makeBlockPtr([paymentRequest, showPaymentUIRequestSeed, weakThis, completionHandler = WTFMove(completionHandler)](PKPaymentAuthorizationViewController *viewController, NSError *error) mutable { 45 45 auto paymentCoordinatorProxy = weakThis.get(); 46 46 if (!paymentCoordinatorProxy) 47 return ;47 return completionHandler(false); 48 48 49 49 if (error) { … … 56 56 if (showPaymentUIRequestSeed != paymentCoordinatorProxy->m_showPaymentUIRequestSeed) { 57 57 // We've already been asked to hide the payment UI. Don't attempt to show it. 58 return ;58 return completionHandler(false); 59 59 } 60 60
Note: See TracChangeset
for help on using the changeset viewer.