Skip to content

Commit

Permalink
Cherry-pick dfd64c8. rdar://123659147
Browse files Browse the repository at this point in the history
Identifier: 272448.580@safari-7618.1.15.11-branch
  • Loading branch information
MyahCobbs committed Feb 28, 2024
1 parent e02793f commit ecc7415
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -299,13 +299,24 @@ static inline ASAuthorizationPublicKeyCredentialLargeBlobSupportRequirement toAS
return requests;
}

void WebAuthenticatorCoordinatorProxy::pauseConditionalAssertion()
WeakPtr<WebAuthenticatorCoordinatorProxy>& WebAuthenticatorCoordinatorProxy::activeConditionalMediationProxy()
{
if (m_paused)
static MainThreadNeverDestroyed<WeakPtr<WebAuthenticatorCoordinatorProxy>> proxy;
return proxy.get();
}

void WebAuthenticatorCoordinatorProxy::pauseConditionalAssertion(CompletionHandler<void()>&& completionHandler)
{
if (m_paused) {
completionHandler();
return;
}
m_paused = true;
if (m_isConditionalAssertion)
m_cancelHandler = WTFMove(completionHandler);
[m_controller cancel];
} else
completionHandler();
}

void WebAuthenticatorCoordinatorProxy::unpauseConditionalAssertion()
Expand All @@ -318,6 +329,19 @@ static inline ASAuthorizationPublicKeyCredentialLargeBlobSupportRequirement toAS
m_paused = false;
}

void WebAuthenticatorCoordinatorProxy::makeActiveConditionalAssertion()
{
if (auto& activeProxy = activeConditionalMediationProxy()) {
if (activeProxy == this)
return;
activeProxy->pauseConditionalAssertion([weakThis = WeakPtr { *this }] () {
if (!weakThis)
return;
weakThis->unpauseConditionalAssertion();
});
}
}

#endif // HAVE(WEB_AUTHN_AS_MODERN)

void WebAuthenticatorCoordinatorProxy::performRequest(WebAuthenticationRequestData &&requestData, RequestCompletionHandler &&handler)
Expand All @@ -339,6 +363,8 @@ static inline ASAuthorizationPublicKeyCredentialLargeBlobSupportRequirement toAS
handler(WebCore::AuthenticatorResponseData { }, AuthenticatorAttachment::Platform, { ExceptionCode::NotAllowedError, @"" });
return;
}
if (m_isConditionalMediation)
activeConditionalMediationProxy() = *this;
m_controller = WTFMove(controller);
m_completionHandler = WTFMove(handler);
m_delegate = adoptNS([[_WKASDelegate alloc] initWithPage:WTFMove(requestData.page) completionHandler:makeBlockPtr([weakThis = WeakPtr { *this }](ASAuthorization *auth, NSError *error) mutable {
Expand Down Expand Up @@ -385,11 +411,17 @@ static inline ASAuthorizationPublicKeyCredentialLargeBlobSupportRequirement toAS
response.userHandle = toArrayBuffer(credential.get().userID);
response.clientDataJSON = toArrayBuffer(credential.get().rawClientDataJSON);
}
if (!weakThis->m_paused) {
weakThis->m_completionHandler(response, attachment, exceptionData);
weakThis->m_delegate.clear();
weakThis->m_controller.clear();
weakThis->m_isConditionalAssertion = false;
if (weakThis) {
if (activeConditionalMediationProxy() == weakThis)
activeConditionalMediationProxy() = nullptr;
if (auto cancelHandler = WTFMove(weakThis->m_cancelHandler))
cancelHandler();
if (!weakThis->m_paused) {
weakThis->m_completionHandler(response, attachment, exceptionData);
weakThis->m_delegate.clear();
weakThis->m_controller.clear();
weakThis->m_isConditionalAssertion = false;
}
}
});
}).get()]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,10 @@ class WebAuthenticatorCoordinatorProxy : public IPC::MessageReceiver {
~WebAuthenticatorCoordinatorProxy();

#if HAVE(WEB_AUTHN_AS_MODERN)
void pauseConditionalAssertion();
static WeakPtr<WebAuthenticatorCoordinatorProxy>& activeConditionalMediationProxy();
void pauseConditionalAssertion(CompletionHandler<void()>&&);
void unpauseConditionalAssertion();
void makeActiveConditionalAssertion();
#endif

private:
Expand Down Expand Up @@ -124,6 +126,7 @@ class WebAuthenticatorCoordinatorProxy : public IPC::MessageReceiver {

RetainPtr<ASCAuthorizationRemotePresenter> m_presenter;
RetainPtr<ASCAgentProxy> m_proxy;
CompletionHandler<void()> m_cancelHandler;
#endif // HAVE(UNIFIED_ASC_AUTH_UI)
};

Expand Down
4 changes: 1 addition & 3 deletions Source/WebKit/UIProcess/WebPageProxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2725,9 +2725,7 @@ void WebPageProxy::dispatchActivityStateChange()
#if ENABLE(WEB_AUTHN) && HAVE(WEB_AUTHN_AS_MODERN)
if ((changed & ActivityState::WindowIsActive) && m_credentialsMessenger) {
if (pageClient().isViewWindowActive())
m_credentialsMessenger->unpauseConditionalAssertion();
else
m_credentialsMessenger->pauseConditionalAssertion();
m_credentialsMessenger->makeActiveConditionalAssertion();
}
#endif

Expand Down

0 comments on commit ecc7415

Please sign in to comment.