Diff
Modified: trunk/Source/WebKit/ChangeLog (279304 => 279305)
--- trunk/Source/WebKit/ChangeLog 2021-06-26 00:49:17 UTC (rev 279304)
+++ trunk/Source/WebKit/ChangeLog 2021-06-26 01:47:28 UTC (rev 279305)
@@ -1,3 +1,65 @@
+2021-06-25 Brent Fulgham <[email protected]>
+
+ [macOS] Add logging and clean up AppSSO flows
+ https://bugs.webkit.org/show_bug.cgi?id=227379
+
+ Reviewed by Kate Cheney.
+
+ This patch adds detailed logging to understand the flows through the AppSSO authentication code,
+ and adds clean-up code in more places to ensure that the modal sheet used by AppSSO is dismissed
+ in cases where the authentication has completed (or failed).
+
+ * UIProcess/Cocoa/SOAuthorization/NavigationSOAuthorizationSession.mm:
+ (WebKit::NavigationSOAuthorizationSession::shouldStartInternal): Adds new logging.
+ (WebKit::NavigationSOAuthorizationSession::webViewDidMoveToWindow): Ditto.
+ (WebKit::NavigationSOAuthorizationSession::pageActiveURLDidChangeDuringWaiting const): Ditto.
+ * UIProcess/Cocoa/SOAuthorization/PopUpSOAuthorizationSession.mm:
+ (WebKit::PopUpSOAuthorizationSession::shouldStartInternal): Adds new logging.
+ (WebKit::PopUpSOAuthorizationSession::fallBackToWebPathInternal): Ditto.
+ (WebKit::PopUpSOAuthorizationSession::abortInternal): Ditto.
+ (WebKit::PopUpSOAuthorizationSession::completeInternal): Ditto.
+ (WebKit::PopUpSOAuthorizationSession::close): Ditto.
+ (WebKit::PopUpSOAuthorizationSession::initSecretWebView): Ditto.
+ * UIProcess/Cocoa/SOAuthorization/RedirectSOAuthorizationSession.mm:
+ (WebKit::RedirectSOAuthorizationSession::fallBackToWebPathInternal): Adds new logging.
+ (WebKit::RedirectSOAuthorizationSession::abortInternal): Ditto.
+ (WebKit::RedirectSOAuthorizationSession::completeInternal): Ditto.
+ (WebKit::RedirectSOAuthorizationSession::beforeStart): Ditto.
+ * UIProcess/Cocoa/SOAuthorization/SOAuthorizationCoordinator.mm:
+ (WebKit::SOAuthorizationCoordinator::tryAuthorize): Adds new logging.
+ * UIProcess/Cocoa/SOAuthorization/SOAuthorizationSession.h:
+ * UIProcess/Cocoa/SOAuthorization/SOAuthorizationSession.mm:
+ (WebKit::SOAuthorizationSession::stateString const): Added.
+ (WebKit::SOAuthorizationSession::~SOAuthorizationSession): Add new logging, and ensure modal sheet is dismissed.
+ (WebKit::SOAuthorizationSession::becomeCompleted): Added new logging.
+ (WebKit::SOAuthorizationSession::shouldStart): Ditto.
+ (WebKit::SOAuthorizationSession::start): Ditto.
+ (WebKit::SOAuthorizationSession::continueStartAfterGetAuthorizationHints): Ditto.
+ (WebKit::SOAuthorizationSession::continueStartAfterDecidePolicy): Ditto.
+ (WebKit::SOAuthorizationSession::fallBackToWebPath): Add new logging, and ensure modal sheet is dismissed.
+ (WebKit::SOAuthorizationSession::abort): Ditto.
+ (WebKit::SOAuthorizationSession::complete): Ditto.
+ (WebKit::SOAuthorizationSession::presentViewController): Added new logging, and dismiss modal if an existing
+ view is in place.
+ (WebKit::SOAuthorizationSession::dismissModalSheetIfNecessary): Added.
+ (WebKit::SOAuthorizationSession::dismissViewController): Use new helper function.
+ * UIProcess/Cocoa/SOAuthorization/SubFrameSOAuthorizationSession.mm:
+ (WebKit::SubFrameSOAuthorizationSession::fallBackToWebPathInternal): Adds new logging.
+ (WebKit::SubFrameSOAuthorizationSession::abortInternal): Ditto.
+ (WebKit::SubFrameSOAuthorizationSession::completeInternal): Ditto.
+ (WebKit::SubFrameSOAuthorizationSession::beforeStart): Ditto.
+ (WebKit::SubFrameSOAuthorizationSession::didFinishLoad): Ditto.
+ (WebKit::SubFrameSOAuthorizationSession::loadRequestToFrame): Ditto.
+ * UIProcess/Cocoa/SOAuthorization/WKSOAuthorizationDelegate.mm:
+ (-[WKSOAuthorizationDelegate authorization:presentViewController:withCompletion:]): Adds new logging.
+ (-[WKSOAuthorizationDelegate authorizationDidNotHandle:]): Ditto.
+ (-[WKSOAuthorizationDelegate authorizationDidCancel:]): Ditto.
+ (-[WKSOAuthorizationDelegate authorizationDidComplete:]): Ditto.
+ (-[WKSOAuthorizationDelegate authorization:didCompleteWithHTTPAuthorizationHeaders:]): Ditto.
+ (-[WKSOAuthorizationDelegate authorization:didCompleteWithHTTPResponse:httpBody:]): Ditto.
+ (-[WKSOAuthorizationDelegate authorization:didCompleteWithError:]): Ditto.
+ (-[WKSOAuthorizationDelegate setSession:]): Ditto.
+
2021-06-25 Wenson Hsieh <[email protected]>
[iOS] Web process sometimes crashes under findDataDetectionResultElementInImageOverlay
Modified: trunk/Source/WebKit/UIProcess/Cocoa/SOAuthorization/NavigationSOAuthorizationSession.mm (279304 => 279305)
--- trunk/Source/WebKit/UIProcess/Cocoa/SOAuthorization/NavigationSOAuthorizationSession.mm 2021-06-26 00:49:17 UTC (rev 279304)
+++ trunk/Source/WebKit/UIProcess/Cocoa/SOAuthorization/NavigationSOAuthorizationSession.mm 2021-06-26 01:47:28 UTC (rev 279305)
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2019 Apple Inc. All rights reserved.
+ * Copyright (C) 2019-2021 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -31,6 +31,8 @@
#import "WebPageProxy.h"
#import <WebCore/ResourceResponse.h>
+#define AUTHORIZATIONSESSION_RELEASE_LOG(fmt, ...) RELEASE_LOG(AppSSO, "%p - [InitiatingAction=%s][State=%s] NavigationSOAuthorizationSession::" fmt, this, initiatingActionString(), stateString(), ##__VA_ARGS__)
+
namespace WebKit {
NavigationSOAuthorizationSession::NavigationSOAuthorizationSession(SOAuthorization *soAuthorization, Ref<API::NavigationAction>&& navigationAction, WebPageProxy& page, InitiatingAction action, Callback&& completionHandler)
@@ -49,6 +51,8 @@
void NavigationSOAuthorizationSession::shouldStartInternal()
{
+ AUTHORIZATIONSESSION_RELEASE_LOG("shouldStartInternal: m_page=%p", page());
+
auto* page = this->page();
ASSERT(page);
beforeStart();
@@ -64,6 +68,7 @@
void NavigationSOAuthorizationSession::webViewDidMoveToWindow()
{
+ AUTHORIZATIONSESSION_RELEASE_LOG("webViewDidMoveToWindow");
auto* page = this->page();
if (state() != State::Waiting || !page || !page->isInWindow())
return;
@@ -78,6 +83,7 @@
bool NavigationSOAuthorizationSession::pageActiveURLDidChangeDuringWaiting() const
{
+ AUTHORIZATIONSESSION_RELEASE_LOG("pageActiveURLDidChangeDuringWaiting");
auto* page = this->page();
return !page || page->pageLoadState().activeURL() != m_waitingPageActiveURL;
}
@@ -84,4 +90,6 @@
} // namespace WebKit
+#undef AUTHORIZATIONSESSION_RELEASE_LOG
+
#endif
Modified: trunk/Source/WebKit/UIProcess/Cocoa/SOAuthorization/PopUpSOAuthorizationSession.mm (279304 => 279305)
--- trunk/Source/WebKit/UIProcess/Cocoa/SOAuthorization/PopUpSOAuthorizationSession.mm 2021-06-26 00:49:17 UTC (rev 279304)
+++ trunk/Source/WebKit/UIProcess/Cocoa/SOAuthorization/PopUpSOAuthorizationSession.mm 2021-06-26 01:47:28 UTC (rev 279305)
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2019 Apple Inc. All rights reserved.
+ * Copyright (C) 2019-2021 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -89,6 +89,8 @@
@end
+#define AUTHORIZATIONSESSION_RELEASE_LOG(fmt, ...) RELEASE_LOG(AppSSO, "%p - [InitiatingAction=%s][State=%s] PopUpSOAuthorizationSession::" fmt, this, initiatingActionString(), stateString(), ##__VA_ARGS__)
+
namespace WebKit {
Ref<SOAuthorizationSession> PopUpSOAuthorizationSession::create(SOAuthorization *soAuthorization, WebPageProxy& page, Ref<API::NavigationAction>&& navigationAction, NewPageCallback&& newPageCallback, UIClientCallback&& uiClientCallback)
@@ -112,6 +114,7 @@
void PopUpSOAuthorizationSession::shouldStartInternal()
{
+ AUTHORIZATIONSESSION_RELEASE_LOG("shouldStartInternal: m_page=%p", page());
ASSERT(page() && page()->isInWindow());
start();
}
@@ -118,11 +121,13 @@
void PopUpSOAuthorizationSession::fallBackToWebPathInternal()
{
+ AUTHORIZATIONSESSION_RELEASE_LOG("fallBackToWebPathInternal");
m_uiClientCallback(releaseNavigationAction(), WTFMove(m_newPageCallback));
}
void PopUpSOAuthorizationSession::abortInternal()
{
+ AUTHORIZATIONSESSION_RELEASE_LOG("abortInternal: m_page=%p", page());
if (!page()) {
m_newPageCallback(nullptr);
return;
@@ -140,6 +145,7 @@
void PopUpSOAuthorizationSession::completeInternal(const WebCore::ResourceResponse& response, NSData *data)
{
+ AUTHORIZATIONSESSION_RELEASE_LOG("completeInternal: httpState=%d", response.httpStatusCode());
if (response.httpStatusCode() != 200 || !page()) {
fallBackToWebPathInternal();
return;
@@ -157,6 +163,7 @@
void PopUpSOAuthorizationSession::close(WKWebView *webView)
{
+ AUTHORIZATIONSESSION_RELEASE_LOG("close");
if (!m_secretWebView)
return;
if (state() != State::Completed || webView != m_secretWebView.get()) {
@@ -169,6 +176,7 @@
void PopUpSOAuthorizationSession::initSecretWebView()
{
+ AUTHORIZATIONSESSION_RELEASE_LOG("initSecretWebView");
ASSERT(page());
auto initiatorWebView = page()->cocoaView();
if (!initiatorWebView)
@@ -187,4 +195,6 @@
} // namespace WebKit
+#undef AUTHORIZATIONSESSION_RELEASE_LOG
+
#endif
Modified: trunk/Source/WebKit/UIProcess/Cocoa/SOAuthorization/RedirectSOAuthorizationSession.mm (279304 => 279305)
--- trunk/Source/WebKit/UIProcess/Cocoa/SOAuthorization/RedirectSOAuthorizationSession.mm 2021-06-26 00:49:17 UTC (rev 279304)
+++ trunk/Source/WebKit/UIProcess/Cocoa/SOAuthorization/RedirectSOAuthorizationSession.mm 2021-06-26 01:47:28 UTC (rev 279305)
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2019 Apple Inc. All rights reserved.
+ * Copyright (C) 2019-2021 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -33,6 +33,8 @@
#import "WebPageProxy.h"
#import <WebCore/ResourceResponse.h>
+#define AUTHORIZATIONSESSION_RELEASE_LOG(fmt, ...) RELEASE_LOG(AppSSO, "%p - [InitiatingAction=%s][State=%s] RedirectSOAuthorizationSession::" fmt, this, initiatingActionString(), stateString(), ##__VA_ARGS__)
+
namespace WebKit {
using namespace WebCore;
@@ -48,20 +50,25 @@
void RedirectSOAuthorizationSession::fallBackToWebPathInternal()
{
+ AUTHORIZATIONSESSION_RELEASE_LOG("fallBackToWebPathInternal: navigationAction=%p", navigationAction());
invokeCallback(false);
}
void RedirectSOAuthorizationSession::abortInternal()
{
+ AUTHORIZATIONSESSION_RELEASE_LOG("abortInternal");
invokeCallback(true);
}
void RedirectSOAuthorizationSession::completeInternal(const ResourceResponse& response, NSData *data)
{
+ AUTHORIZATIONSESSION_RELEASE_LOG("completeInternal: httpState=%d, navigationAction=%p", response.httpStatusCode(), navigationAction());
+
auto* navigationAction = this->navigationAction();
ASSERT(navigationAction);
auto* page = this->page();
if ((response.httpStatusCode() != 302 && response.httpStatusCode() != 200) || !page) {
+ AUTHORIZATIONSESSION_RELEASE_LOG("completeInternal: httpState=%d page=%d, so falling back to web path.", response.httpStatusCode(), !!page);
fallBackToWebPathInternal();
return;
}
@@ -92,8 +99,11 @@
void RedirectSOAuthorizationSession::beforeStart()
{
+ AUTHORIZATIONSESSION_RELEASE_LOG("beforeStart");
}
} // namespace WebKit
+#undef AUTHORIZATIONSESSION_RELEASE_LOG
+
#endif
Modified: trunk/Source/WebKit/UIProcess/Cocoa/SOAuthorization/SOAuthorizationCoordinator.mm (279304 => 279305)
--- trunk/Source/WebKit/UIProcess/Cocoa/SOAuthorization/SOAuthorizationCoordinator.mm 2021-06-26 00:49:17 UTC (rev 279304)
+++ trunk/Source/WebKit/UIProcess/Cocoa/SOAuthorization/SOAuthorizationCoordinator.mm 2021-06-26 01:47:28 UTC (rev 279305)
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2019 Apple Inc. All rights reserved.
+ * Copyright (C) 2019-2021 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -41,6 +41,8 @@
#import <pal/spi/cocoa/AuthKitSPI.h>
#import <wtf/Function.h>
+#define AUTHORIZATIONCOORDINATOR_RELEASE_LOG(fmt, ...) RELEASE_LOG(AppSSO, "%p - SOAuthorizationCoordinator::" fmt, this, ##__VA_ARGS__)
+
namespace WebKit {
SOAuthorizationCoordinator::SOAuthorizationCoordinator()
@@ -63,7 +65,9 @@
void SOAuthorizationCoordinator::tryAuthorize(Ref<API::NavigationAction>&& navigationAction, WebPageProxy& page, Function<void(bool)>&& completionHandler)
{
+ AUTHORIZATIONCOORDINATOR_RELEASE_LOG("tryAuthorize");
if (!canAuthorize(navigationAction->request().url())) {
+ AUTHORIZATIONCOORDINATOR_RELEASE_LOG("tryAuthorize: Cannot authorize the requested URL.");
completionHandler(false);
return;
}
@@ -72,6 +76,7 @@
auto* targetFrame = navigationAction->targetFrame();
bool subframeNavigation = targetFrame && !targetFrame->isMainFrame();
if (subframeNavigation && (!page.mainFrame() || ![AKAuthorizationController isURLFromAppleOwnedDomain:page.mainFrame()->url()])) {
+ AUTHORIZATIONCOORDINATOR_RELEASE_LOG("tryAuthorize: Attempting to perform subframe navigation for non-Apple authorization URL.");
completionHandler(false);
return;
}
@@ -82,8 +87,10 @@
void SOAuthorizationCoordinator::tryAuthorize(Ref<API::NavigationAction>&& navigationAction, WebPageProxy& page, NewPageCallback&& newPageCallback, UIClientCallback&& uiClientCallback)
{
+ AUTHORIZATIONCOORDINATOR_RELEASE_LOG("tryAuthorize (2)");
bool subframeNavigation = navigationAction->sourceFrame() && !navigationAction->sourceFrame()->isMainFrame();
if (subframeNavigation || !navigationAction->isProcessingUserGesture() || !canAuthorize(navigationAction->request().url())) {
+ AUTHORIZATIONCOORDINATOR_RELEASE_LOG("tryAuthorize (2): Attempting to perform invalid auth.");
uiClientCallback(WTFMove(navigationAction), WTFMove(newPageCallback));
return;
}
@@ -94,4 +101,6 @@
} // namespace WebKit
+#undef AUTHORIZATIONCOORDINATOR_RELEASE_LOG
+
#endif
Modified: trunk/Source/WebKit/UIProcess/Cocoa/SOAuthorization/SOAuthorizationSession.h (279304 => 279305)
--- trunk/Source/WebKit/UIProcess/Cocoa/SOAuthorization/SOAuthorizationSession.h 2021-06-26 00:49:17 UTC (rev 279304)
+++ trunk/Source/WebKit/UIProcess/Cocoa/SOAuthorization/SOAuthorizationSession.h 2021-06-26 01:47:28 UTC (rev 279305)
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2019 Apple Inc. All rights reserved.
+ * Copyright (C) 2019-2021 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -92,6 +92,8 @@
void start();
WebPageProxy* page() const { return m_page.get(); }
State state() const { return m_state; }
+ const char* stateString() const;
+ const char* initiatingActionString() const;
void setState(State state) { m_state = state; }
const API::NavigationAction* navigationAction() { return m_navigationAction.get(); }
Ref<API::NavigationAction> releaseNavigationAction();
@@ -104,6 +106,9 @@
void becomeCompleted();
void dismissViewController();
+#if PLATFORM(MAC)
+ void dismissModalSheetIfNecessary();
+#endif
void continueStartAfterGetAuthorizationHints(const String&);
void continueStartAfterDecidePolicy(const SOAuthorizationLoadPolicy&);
Modified: trunk/Source/WebKit/UIProcess/Cocoa/SOAuthorization/SOAuthorizationSession.mm (279304 => 279305)
--- trunk/Source/WebKit/UIProcess/Cocoa/SOAuthorization/SOAuthorizationSession.mm 2021-06-26 00:49:17 UTC (rev 279304)
+++ trunk/Source/WebKit/UIProcess/Cocoa/SOAuthorization/SOAuthorizationSession.mm 2021-06-26 01:47:28 UTC (rev 279305)
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2019 Apple Inc. All rights reserved.
+ * Copyright (C) 2019-2021 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -44,7 +44,7 @@
#import <wtf/BlockPtr.h>
#import <wtf/Vector.h>
-#define AUTHORIZATIONSESSION_RELEASE_LOG(fmt, ...) RELEASE_LOG(AppSSO, "%p - [InitiatingAction=%s] SOAuthorizationSession::" fmt, this, toString(m_action), ##__VA_ARGS__)
+#define AUTHORIZATIONSESSION_RELEASE_LOG(fmt, ...) RELEASE_LOG(AppSSO, "%p - [InitiatingAction=%s][State=%s] SOAuthorizationSession::" fmt, this, toString(m_action), stateString(), ##__VA_ARGS__)
namespace WebKit {
@@ -96,12 +96,47 @@
SOAuthorizationSession::~SOAuthorizationSession()
{
+ AUTHORIZATIONSESSION_RELEASE_LOG("~SOAuthorizationSession: m_viewController=%p", m_viewController.get());
+#if PLATFORM(MAC)
+ AUTHORIZATIONSESSION_RELEASE_LOG("~SOAuthorizationSession: m_sheetWindow=%p", m_sheetWindow.get());
+#endif
+
if (m_state == State::Active && !!m_soAuthorization)
[m_soAuthorization cancelAuthorization];
if (m_state != State::Idle && m_state != State::Completed)
becomeCompleted();
+ else
+ dismissViewController();
}
+const char* SOAuthorizationSession::initiatingActionString() const
+{
+ return toString(m_action);
+}
+
+const char* SOAuthorizationSession::stateString() const
+{
+ static const char* Idle = "Idle";
+ static const char* Active = "Active";
+ static const char* Waiting = "Waiting";
+ static const char* Completed = "Completed";
+
+ switch (m_state) {
+ case State::Idle:
+ return Idle;
+ case State::Active:
+ return Active;
+ case State::Waiting:
+ return Waiting;
+ case State::Completed:
+ return Completed;
+ }
+
+ ASSERT_NOT_REACHED();
+ return nullptr;
+}
+
+
Ref<API::NavigationAction> SOAuthorizationSession::releaseNavigationAction()
{
return m_navigationAction.releaseNonNull();
@@ -109,15 +144,19 @@
void SOAuthorizationSession::becomeCompleted()
{
+ AUTHORIZATIONSESSION_RELEASE_LOG("becomeCompleted: m_viewController=%p", m_viewController.get());
+
ASSERT(m_state == State::Active || m_state == State::Waiting);
m_state = State::Completed;
- if (m_viewController)
- dismissViewController();
+ dismissViewController();
+#if PLATFORM(MAC)
+ ASSERT(!m_sheetWindow);
+#endif
}
void SOAuthorizationSession::shouldStart()
{
- AUTHORIZATIONSESSION_RELEASE_LOG("shouldStart:");
+ AUTHORIZATIONSESSION_RELEASE_LOG("shouldStart: m_page=%p", page());
ASSERT(m_state == State::Idle);
if (!m_page)
@@ -127,15 +166,25 @@
void SOAuthorizationSession::start()
{
- AUTHORIZATIONSESSION_RELEASE_LOG("start:");
+ AUTHORIZATIONSESSION_RELEASE_LOG("start: navigationAction=%p", navigationAction());
ASSERT((m_state == State::Idle || m_state == State::Waiting) && m_navigationAction);
m_state = State::Active;
+ AUTHORIZATIONSESSION_RELEASE_LOG("start: Moving m_state to Active.");
[m_soAuthorization getAuthorizationHintsWithURL:m_navigationAction->request().url() responseCode:0 completion:makeBlockPtr([this, weakThis = makeWeakPtr(*this)] (SOAuthorizationHints *authorizationHints, NSError *error) {
AUTHORIZATIONSESSION_RELEASE_LOG("start: Receive SOAuthorizationHints (error=%ld)", error ? error.code : 0);
- if (!weakThis || error || !authorizationHints)
+ if (!weakThis) {
+ RELEASE_LOG_ERROR(AppSSO, "SOAuthorizationSession::start (getAuthorizationHintsWithURL completion handler): Returning early because weakThis is now null.");
return;
+ }
+
+ if (error || !authorizationHints) {
+ AUTHORIZATIONSESSION_RELEASE_LOG("start (getAuthorizationHintsWithURL completion handler): Returning early due to error or lack of hints.");
+ return;
+ }
+
+ AUTHORIZATIONSESSION_RELEASE_LOG("start (getAuthorizationHintsWithURL completion handler): Receive SOAuthorizationHints.");
continueStartAfterGetAuthorizationHints(authorizationHints.localizedExtensionBundleDisplayName);
}).get()];
}
@@ -145,9 +194,12 @@
AUTHORIZATIONSESSION_RELEASE_LOG("continueStartAfterGetAuthorizationHints: (hints=%s)", hints.utf8().data());
ASSERT(m_state == State::Active);
- if (!m_page)
+ if (!m_page) {
+ AUTHORIZATIONSESSION_RELEASE_LOG("continueStartAfterGetAuthorizationHints: Early return due to null m_page");
return;
+ }
+ AUTHORIZATIONSESSION_RELEASE_LOG("continueStartAfterGetAuthorizationHints: Checking page for policy choice.");
m_page->decidePolicyForSOAuthorizationLoad(hints, [this, weakThis = makeWeakPtr(*this)] (SOAuthorizationLoadPolicy policy) {
if (!weakThis)
return;
@@ -158,8 +210,7 @@
void SOAuthorizationSession::continueStartAfterDecidePolicy(const SOAuthorizationLoadPolicy& policy)
{
if (policy == SOAuthorizationLoadPolicy::Ignore) {
- AUTHORIZATIONSESSION_RELEASE_LOG("continueStartAfterDecidePolicy: Receive SOAuthorizationLoadPolicy::Ignore");
-
+ AUTHORIZATIONSESSION_RELEASE_LOG("continueStartAfterDecidePolicy: Receive SOAuthorizationLoadPolicy::Ignore. Falling back to web path.");
fallBackToWebPath();
return;
}
@@ -166,8 +217,10 @@
AUTHORIZATIONSESSION_RELEASE_LOG("continueStartAfterDecidePolicy: Receive SOAuthorizationLoadPolicy::Allow");
- if (!m_soAuthorization || !m_page || !m_navigationAction)
+ if (!m_soAuthorization || !m_page || !m_navigationAction) {
+ AUTHORIZATIONSESSION_RELEASE_LOG("continueStartAfterGetAuthorizationHints: Early return m_soAuthorization=%d, m_page=%p, navigationAction=%p.", !!m_soAuthorization, page(), navigationAction());
return;
+ }
auto initiatorOrigin = emptyString();
if (m_navigationAction->sourceFrame())
@@ -187,15 +240,20 @@
#endif
auto *nsRequest = m_navigationAction->request().nsURLRequest(WebCore::HTTPBodyUpdatePolicy::UpdateHTTPBody);
+ AUTHORIZATIONSESSION_RELEASE_LOG("continueStartAfterGetAuthorizationHints: Beginning authorization with AppSSO.");
[m_soAuthorization beginAuthorizationWithURL:nsRequest.URL httpHeaders:nsRequest.allHTTPHeaderFields httpBody:nsRequest.HTTPBody];
}
void SOAuthorizationSession::fallBackToWebPath()
{
- AUTHORIZATIONSESSION_RELEASE_LOG("fallBackToWebPath:");
+ AUTHORIZATIONSESSION_RELEASE_LOG("fallBackToWebPath");
- if (m_state != State::Active)
+ if (m_state != State::Active) {
+ AUTHORIZATIONSESSION_RELEASE_LOG("fallBackToWebPath: Returning early since not active.");
+ dismissViewController();
return;
+ }
+
becomeCompleted();
fallBackToWebPathInternal();
}
@@ -202,10 +260,17 @@
void SOAuthorizationSession::abort()
{
- AUTHORIZATIONSESSION_RELEASE_LOG("abort:");
+ AUTHORIZATIONSESSION_RELEASE_LOG("abort: m_viewController=%p", m_viewController.get());
+#if PLATFORM(MAC)
+ AUTHORIZATIONSESSION_RELEASE_LOG("abort: m_sheetWindow=%p", m_sheetWindow.get());
+#endif
- if (m_state == State::Idle || m_state == State::Completed)
+ if (m_state == State::Idle || m_state == State::Completed) {
+ AUTHORIZATIONSESSION_RELEASE_LOG("abort: Returning early since idle or already completed.");
+ dismissViewController();
return;
+ }
+
becomeCompleted();
abortInternal();
}
@@ -212,13 +277,23 @@
void SOAuthorizationSession::complete(NSHTTPURLResponse *httpResponse, NSData *data)
{
- if (m_state != State::Active)
+ AUTHORIZATIONSESSION_RELEASE_LOG("complete: httpState=%d, m_viewController=%p", static_cast<int>(httpResponse.statusCode), m_viewController.get());
+#if PLATFORM(MAC)
+ AUTHORIZATIONSESSION_RELEASE_LOG("complete: m_sheetWindow=%p", m_sheetWindow.get());
+#endif
+
+ if (m_state != State::Active) {
+ AUTHORIZATIONSESSION_RELEASE_LOG("complete: Returning early since not active.");
+ dismissViewController();
return;
+ }
+
ASSERT(m_navigationAction);
becomeCompleted();
auto response = WebCore::ResourceResponse(httpResponse);
if (!isSameOrigin(m_navigationAction->request(), response)) {
+ AUTHORIZATIONSESSION_RELEASE_LOG("complete: Origins don't match. Falling back to web path.");
fallBackToWebPathInternal();
return;
}
@@ -229,12 +304,16 @@
AUTHORIZATIONSESSION_RELEASE_LOG("complete: (httpStatusCode=%d, hasCookies=%d, hasData=%d)", response.httpStatusCode(), !cookies.isEmpty(), !!data.length);
if (cookies.isEmpty()) {
+ AUTHORIZATIONSESSION_RELEASE_LOG("complete: No cookies to set. Completing (internal).");
completeInternal(response, data);
return;
}
- if (!m_page)
+ if (!m_page) {
+ AUTHORIZATIONSESSION_RELEASE_LOG("complete: Returning early because m_page is null.");
return;
+ }
+
m_page->websiteDataStore().cookieStore().setCookies(WTFMove(cookies), [this, weakThis = makeWeakPtr(*this), response = WTFMove(response), data = "" alloc] initWithData:data])] () mutable {
if (!weakThis)
return;
@@ -247,11 +326,15 @@
void SOAuthorizationSession::presentViewController(SOAuthorizationViewController viewController, UICallback uiCallback)
{
- AUTHORIZATIONSESSION_RELEASE_LOG("presentViewController:");
+ AUTHORIZATIONSESSION_RELEASE_LOG("presentViewController: m_viewController=%p", m_viewController.get());
+#if PLATFORM(MAC)
+ AUTHORIZATIONSESSION_RELEASE_LOG("presentViewController: m_sheetWindow=%p", m_sheetWindow.get());
+#endif
ASSERT(m_state == State::Active);
// Only expect at most one UI session for the whole authorization session.
if (!m_page || m_page->isClosed() || m_viewController) {
+ AUTHORIZATIONSESSION_RELEASE_LOG("presentViewController: m_page=%p, m_page->isClosed=%d, m_viewController=%p", m_page.get(), m_page ? m_page->isClosed() : 0, m_viewController.get());
uiCallback(NO, adoptNS([[NSError alloc] initWithDomain:SOErrorDomain code:kSOErrorAuthorizationPresentationFailed userInfo:nil]).get());
return;
}
@@ -259,9 +342,12 @@
m_viewController = viewController;
#if PLATFORM(MAC)
ASSERT(!m_sheetWindow);
+ ASSERT(!m_sheetWindowWillCloseObserver);
+
+ dismissModalSheetIfNecessary();
+
m_sheetWindow = [NSWindow windowWithContentViewController:m_viewController.get()];
- ASSERT(!m_sheetWindowWillCloseObserver);
m_sheetWindowWillCloseObserver = [[NSNotificationCenter defaultCenter] addObserverForName:NSWindowWillCloseNotification object:m_sheetWindow.get() queue:nil usingBlock:[weakThis = makeWeakPtr(*this)] (NSNotification *) {
if (!weakThis)
return;
@@ -268,9 +354,11 @@
RELEASE_LOG(AppSSO, "presentViewController: Received NSWindowWillCloseNotification. Dismissing the view controller.");
weakThis->dismissViewController();
}];
+ AUTHORIZATIONSESSION_RELEASE_LOG("presentViewController: Added m_sheetWindowWillCloseObserver (%p)", m_sheetWindowWillCloseObserver.get());
NSWindow *presentingWindow = m_page->platformWindow();
if (!presentingWindow) {
+ AUTHORIZATIONSESSION_RELEASE_LOG("presentViewController: No presenting window. Returning early.");
uiCallback(NO, adoptNS([[NSError alloc] initWithDomain:SOErrorDomain code:kSOErrorAuthorizationPresentationFailed userInfo:nil]).get());
return;
}
@@ -290,14 +378,40 @@
uiCallback(YES, nil);
}
+#if PLATFORM(MAC)
+void SOAuthorizationSession::dismissModalSheetIfNecessary()
+{
+ if (auto *presentingWindow = m_sheetWindow.get().sheetParent) {
+ AUTHORIZATIONSESSION_RELEASE_LOG("dismissModalSheetIfNecessary: Calling endSheet on %p for sheet %p.", presentingWindow, m_sheetWindow.get());
+ [presentingWindow endSheet:m_sheetWindow.get()];
+ }
+ m_sheetWindow = nullptr;
+
+ if (m_sheetWindowWillCloseObserver.get()) {
+ AUTHORIZATIONSESSION_RELEASE_LOG("dismissModalSheetIfNecessary: Removing m_sheetWindowWillCloseObserver (%p)", m_sheetWindowWillCloseObserver.get());
+ [[NSNotificationCenter defaultCenter] removeObserver:m_sheetWindowWillCloseObserver.get()];
+ }
+ m_sheetWindowWillCloseObserver = nullptr;
+}
+#endif
+
void SOAuthorizationSession::dismissViewController()
{
- AUTHORIZATIONSESSION_RELEASE_LOG("dismissViewController:");
+ AUTHORIZATIONSESSION_RELEASE_LOG("dismissViewController: m_viewController=%p", m_viewController.get());
+ if (!m_viewController) {
+ AUTHORIZATIONSESSION_RELEASE_LOG("dismissViewController: No view controller, so returning early.");
+ return;
+ }
- ASSERT(m_viewController);
#if PLATFORM(MAC)
- ASSERT(m_sheetWindow && m_sheetWindowWillCloseObserver);
+ if (!m_sheetWindow) {
+ ASSERT(!m_sheetWindowWillCloseObserver);
+ AUTHORIZATIONSESSION_RELEASE_LOG("dismissViewController: No view controller or sheet window, so returning early.");
+ return;
+ }
+ ASSERT(m_sheetWindowWillCloseObserver);
+
// This is a workaround for an AppKit issue: <rdar://problem/59125329>.
// [m_sheetWindow sheetParent] is null if the parent is minimized or the host app is hidden.
if (m_page && m_page->platformWindow()) {
@@ -333,13 +447,7 @@
return;
}
- [[NSNotificationCenter defaultCenter] removeObserver:m_sheetWindowWillCloseObserver.get()];
- m_sheetWindowWillCloseObserver = nullptr;
-
- auto *presentingWindow = m_sheetWindow.get().sheetParent;
- AUTHORIZATIONSESSION_RELEASE_LOG("dismissViewController: Calling endSheet on %p for sheet %p.", presentingWindow, m_sheetWindow.get());
- [presentingWindow endSheet:m_sheetWindow.get()];
- m_sheetWindow = nullptr;
+ dismissModalSheetIfNecessary();
AUTHORIZATIONSESSION_RELEASE_LOG("dismissViewController: Finished call with deminiaturized observer (%p) and Hidden observer (%p)", m_presentingWindowDidDeminiaturizeObserver.get(), m_applicationDidUnhideObserver.get());
#elif PLATFORM(IOS)
[[m_viewController presentingViewController] dismissViewControllerAnimated:YES completion:nil];
Modified: trunk/Source/WebKit/UIProcess/Cocoa/SOAuthorization/SubFrameSOAuthorizationSession.mm (279304 => 279305)
--- trunk/Source/WebKit/UIProcess/Cocoa/SOAuthorization/SubFrameSOAuthorizationSession.mm 2021-06-26 00:49:17 UTC (rev 279304)
+++ trunk/Source/WebKit/UIProcess/Cocoa/SOAuthorization/SubFrameSOAuthorizationSession.mm 2021-06-26 01:47:28 UTC (rev 279305)
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2019 Apple Inc. All rights reserved.
+ * Copyright (C) 2019-2021 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -38,6 +38,8 @@
namespace WebKit {
using namespace WebCore;
+#define AUTHORIZATIONSESSION_RELEASE_LOG(fmt, ...) RELEASE_LOG(AppSSO, "%p - [InitiatingAction=%s][State=%s] SubFrameSOAuthorizationSession::" fmt, this, initiatingActionString(), stateString(), ##__VA_ARGS__)
+
namespace {
const char* soAuthorizationPostDidStartMessageToParent = "<script>parent.postMessage('SOAuthorizationDidStart', '*');</script>";
@@ -69,6 +71,7 @@
void SubFrameSOAuthorizationSession::fallBackToWebPathInternal()
{
+ AUTHORIZATIONSESSION_RELEASE_LOG("fallBackToWebPathInternal: navigationAction=%p", navigationAction());
ASSERT(navigationAction());
appendRequestToLoad(URL(navigationAction()->request().url()), Vector { reinterpret_cast<const uint8_t*>(soAuthorizationPostDidCancelMessageToParent), strlen(soAuthorizationPostDidCancelMessageToParent) });
appendRequestToLoad(URL(navigationAction()->request().url()), String(navigationAction()->request().httpReferrer()));
@@ -76,11 +79,13 @@
void SubFrameSOAuthorizationSession::abortInternal()
{
+ AUTHORIZATIONSESSION_RELEASE_LOG("abortInternal");
fallBackToWebPathInternal();
}
void SubFrameSOAuthorizationSession::completeInternal(const WebCore::ResourceResponse& response, NSData *data)
{
+ AUTHORIZATIONSESSION_RELEASE_LOG("completeInternal: httpState=%d", response.httpStatusCode());
if (response.httpStatusCode() != 200) {
fallBackToWebPathInternal();
return;
@@ -90,6 +95,7 @@
void SubFrameSOAuthorizationSession::beforeStart()
{
+ AUTHORIZATIONSESSION_RELEASE_LOG("beforeStart");
// Cancelled the current load before loading the data to post SOAuthorizationDidStart to the parent frame.
invokeCallback(true);
ASSERT(navigationAction());
@@ -98,6 +104,7 @@
void SubFrameSOAuthorizationSession::didFinishLoad()
{
+ AUTHORIZATIONSESSION_RELEASE_LOG("didFinishLoad");
auto* page = this->page();
if (!page)
return;
@@ -118,6 +125,7 @@
void SubFrameSOAuthorizationSession::loadRequestToFrame()
{
+ AUTHORIZATIONSESSION_RELEASE_LOG("loadRequestToFrame");
auto* page = this->page();
if (!page || m_requestsToLoad.isEmpty())
return;
@@ -135,4 +143,6 @@
} // namespace WebKit
+#undef AUTHORIZATIONSESSION_RELEASE_LOG
+
#endif
Modified: trunk/Source/WebKit/UIProcess/Cocoa/SOAuthorization/WKSOAuthorizationDelegate.mm (279304 => 279305)
--- trunk/Source/WebKit/UIProcess/Cocoa/SOAuthorization/WKSOAuthorizationDelegate.mm 2021-06-26 00:49:17 UTC (rev 279304)
+++ trunk/Source/WebKit/UIProcess/Cocoa/SOAuthorization/WKSOAuthorizationDelegate.mm 2021-06-26 01:47:28 UTC (rev 279305)
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2019 Apple Inc. All rights reserved.
+ * Copyright (C) 2019-2021 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -32,16 +32,21 @@
#import "WebPageProxy.h"
#import <wtf/RunLoop.h>
+#define WKSOAUTHORIZATIONDELEGATE_RELEASE_LOG(fmt, ...) RELEASE_LOG(AppSSO, "%p - WKSOAuthorizationDelegate::" fmt, &self, ##__VA_ARGS__)
+
@implementation WKSOAuthorizationDelegate
- (void)authorization:(SOAuthorization *)authorization presentViewController:(SOAuthorizationViewController)viewController withCompletion:(void (^)(BOOL success, NSError *error))completion
{
ASSERT(RunLoop::isMain() && completion);
+ WKSOAUTHORIZATIONDELEGATE_RELEASE_LOG("authorization (authorization = %p, _session = %p)", authorization, _session.get());
if (!_session) {
+ WKSOAUTHORIZATIONDELEGATE_RELEASE_LOG("authorization: No session, so completing with NO as success state.");
ASSERT_NOT_REACHED();
completion(NO, nil);
return;
}
+ WKSOAUTHORIZATIONDELEGATE_RELEASE_LOG("authorization: presentingViewController %p", viewController);
_session->presentViewController(viewController, completion);
}
@@ -48,11 +53,14 @@
- (void)authorizationDidNotHandle:(SOAuthorization *)authorization
{
ASSERT(RunLoop::isMain());
+ WKSOAUTHORIZATIONDELEGATE_RELEASE_LOG("authorizationDidNotHandle: (authorization = %p, _session = %p)", authorization, _session.get());
LOG_ERROR("Could not handle AppSSO.");
if (!_session) {
+ WKSOAUTHORIZATIONDELEGATE_RELEASE_LOG("authorizationDidNotHandle: No session, so returning early.");
ASSERT_NOT_REACHED();
return;
}
+ WKSOAUTHORIZATIONDELEGATE_RELEASE_LOG("authorizationDidNotHandle: Falling back to web path.");
_session->fallBackToWebPath();
}
@@ -59,10 +67,13 @@
- (void)authorizationDidCancel:(SOAuthorization *)authorization
{
ASSERT(RunLoop::isMain());
+ WKSOAUTHORIZATIONDELEGATE_RELEASE_LOG("authorizationDidCancel: (authorization = %p, _session = %p)", authorization, _session.get());
if (!_session) {
+ WKSOAUTHORIZATIONDELEGATE_RELEASE_LOG("authorizationDidCancel: No session, so returning early.");
ASSERT_NOT_REACHED();
return;
}
+ WKSOAUTHORIZATIONDELEGATE_RELEASE_LOG("authorizationDidCancel: Aborting session.");
_session->abort();
}
@@ -69,11 +80,14 @@
- (void)authorizationDidComplete:(SOAuthorization *)authorization
{
ASSERT(RunLoop::isMain());
+ WKSOAUTHORIZATIONDELEGATE_RELEASE_LOG("authorizationDidComplete: (authorization = %p, _session = %p)", authorization, _session.get());
LOG_ERROR("Complete AppSSO without any data.");
if (!_session) {
+ WKSOAUTHORIZATIONDELEGATE_RELEASE_LOG("authorizationDidComplete: No session, so returning early.");
ASSERT_NOT_REACHED();
return;
}
+ WKSOAUTHORIZATIONDELEGATE_RELEASE_LOG("authorizationDidComplete: Falling back to web path.");
_session->fallBackToWebPath();
}
@@ -80,11 +94,14 @@
- (void)authorization:(SOAuthorization *)authorization didCompleteWithHTTPAuthorizationHeaders:(NSDictionary *)httpAuthorizationHeaders
{
ASSERT(RunLoop::isMain());
+ WKSOAUTHORIZATIONDELEGATE_RELEASE_LOG("authorization:didCompleteWithHTTPAuthorizationHeaders: (authorization = %p, _session = %p)", authorization, _session.get());
LOG_ERROR("Complete AppSSO with unexpected callback.");
if (!_session) {
+ WKSOAUTHORIZATIONDELEGATE_RELEASE_LOG("authorization:didCompleteWithHTTPAuthorizationHeaders: No session, so returning early.");
ASSERT_NOT_REACHED();
return;
}
+ WKSOAUTHORIZATIONDELEGATE_RELEASE_LOG("authorization:didCompleteWithHTTPAuthorizationHeaders: Falling back to web path.");
_session->fallBackToWebPath();
}
@@ -91,10 +108,13 @@
- (void)authorization:(SOAuthorization *)authorization didCompleteWithHTTPResponse:(NSHTTPURLResponse *)httpResponse httpBody:(NSData *)httpBody
{
ASSERT(RunLoop::isMain());
+ WKSOAUTHORIZATIONDELEGATE_RELEASE_LOG("authorization:didCompleteWithHTTPResponse: (authorization = %p, _session = %p)", authorization, _session.get());
if (!_session) {
+ WKSOAUTHORIZATIONDELEGATE_RELEASE_LOG("authorization:didCompleteWithHTTPResponse: No session, so returning early.");
ASSERT_NOT_REACHED();
return;
}
+ WKSOAUTHORIZATIONDELEGATE_RELEASE_LOG("authorization:didCompleteWithHTTPResponse: Completing.");
_session->complete(httpResponse, httpBody);
}
@@ -101,21 +121,27 @@
- (void)authorization:(SOAuthorization *)authorization didCompleteWithError:(NSError *)error
{
ASSERT(RunLoop::isMain());
+ WKSOAUTHORIZATIONDELEGATE_RELEASE_LOG("authorization:didCompleteWithError: (authorization = %p, _session = %p)", authorization, _session.get());
LOG_ERROR("Could not complete AppSSO: %d", error.code);
if (!_session) {
+ WKSOAUTHORIZATIONDELEGATE_RELEASE_LOG("authorization:didCompleteWithError: No session, so returning early.");
ASSERT_NOT_REACHED();
return;
}
+ WKSOAUTHORIZATIONDELEGATE_RELEASE_LOG("authorization:didCompleteWithError: Falling back to web path.");
_session->fallBackToWebPath();
}
- (void)setSession:(RefPtr<WebKit::SOAuthorizationSession>&&)session
{
+ RELEASE_ASSERT(RunLoop::isMain());
+ WKSOAUTHORIZATIONDELEGATE_RELEASE_LOG("setSession: (existing session = %p, new session = %p)", _session.get(), session.get());
_session = WTFMove(session);
if (_session)
_session->shouldStart();
}
-
@end
+#undef WKSOAUTHORIZATIONDELEGATE_RELEASE_LOG
+
#endif