Changeset 246829 in webkit


Ignore:
Timestamp:
Jun 25, 2019 8:11:36 PM (5 years ago)
Author:
jiewen_tan@apple.com
Message:

Implement a new SPI to inform clients about AppSSO
https://bugs.webkit.org/show_bug.cgi?id=199085
<rdar://problem/50028246>

Reviewed by Geoffrey Garen.

Source/WebKit:

This patch implements a new SPI to inform clients about incoming AppSSO interceptions during
navigations. Therefore, clients can make an informed decision about whether this is the right
moment to do the interception as interceptions often show native UI. Also, the SPI is designed
to pass along a human readable name for the extension such that clients can do whatever they
want to inform users about what's going on.

Here is the new SPI:

  • (void)_webView:(WKWebView *)webView decidePolicyForSOAuthorizationLoadWithCurrentPolicy:(_WKSOAuthorizationLoadPolicy)policy forExtension:(NSString *)extension completionHandler:(void ()(_WKSOAuthorizationLoadPolicy policy))completionHandler;
  • UIProcess/API/APINavigationClient.h:

(API::NavigationClient::decidePolicyForSOAuthorizationLoad):

  • UIProcess/API/Cocoa/WKNavigationDelegatePrivate.h:
  • UIProcess/Cocoa/NavigationState.h:
  • UIProcess/Cocoa/NavigationState.mm:

(WebKit::NavigationState::setNavigationDelegate):
(WebKit::soAuthorizationLoadPolicy):
(WebKit::wkSOAuthorizationLoadPolicy):
(WebKit::NavigationState::NavigationClient::decidePolicyForSOAuthorizationLoad):

  • UIProcess/Cocoa/SOAuthorization/SOAuthorizationLoadPolicy.h: Added.
  • UIProcess/Cocoa/SOAuthorization/SOAuthorizationSession.mm:

(WebKit::SOAuthorizationSession::start):

  • UIProcess/WebPageProxy.cpp:

(WebKit::WebPageProxy::decidePolicyForSOAuthorizationLoad):

  • UIProcess/WebPageProxy.h:
  • WebKit.xcodeproj/project.pbxproj:

Tools:

  • TestWebKitAPI/Tests/WebKitCocoa/TestSOAuthorization.mm:

(-[TestSOAuthorizationBasicDelegate webView:didFinishNavigation:]):
(-[TestSOAuthorizationNavigationDelegate init]):
(-[TestSOAuthorizationNavigationDelegate _webView:decidePolicyForSOAuthorizationLoadWithCurrentPolicy:forExtension:completionHandler:]):
(TestWebKitAPI::TEST):

Location:
trunk
Files:
1 added
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/ChangeLog

    r246828 r246829  
     12019-06-25  Jiewen Tan  <jiewen_tan@apple.com>
     2
     3        Implement a new SPI to inform clients about AppSSO
     4        https://bugs.webkit.org/show_bug.cgi?id=199085
     5        <rdar://problem/50028246>
     6
     7        Reviewed by Geoffrey Garen.
     8
     9        This patch implements a new SPI to inform clients about incoming AppSSO interceptions during
     10        navigations. Therefore, clients can make an informed decision about whether this is the right
     11        moment to do the interception as interceptions often show native UI. Also, the SPI is designed
     12        to pass along a human readable name for the extension such that clients can do whatever they
     13        want to inform users about what's going on.
     14
     15        Here is the new SPI:
     16        - (void)_webView:(WKWebView *)webView decidePolicyForSOAuthorizationLoadWithCurrentPolicy:(_WKSOAuthorizationLoadPolicy)policy forExtension:(NSString *)extension completionHandler:(void (^)(_WKSOAuthorizationLoadPolicy policy))completionHandler;
     17
     18        * UIProcess/API/APINavigationClient.h:
     19        (API::NavigationClient::decidePolicyForSOAuthorizationLoad):
     20        * UIProcess/API/Cocoa/WKNavigationDelegatePrivate.h:
     21        * UIProcess/Cocoa/NavigationState.h:
     22        * UIProcess/Cocoa/NavigationState.mm:
     23        (WebKit::NavigationState::setNavigationDelegate):
     24        (WebKit::soAuthorizationLoadPolicy):
     25        (WebKit::wkSOAuthorizationLoadPolicy):
     26        (WebKit::NavigationState::NavigationClient::decidePolicyForSOAuthorizationLoad):
     27        * UIProcess/Cocoa/SOAuthorization/SOAuthorizationLoadPolicy.h: Added.
     28        * UIProcess/Cocoa/SOAuthorization/SOAuthorizationSession.mm:
     29        (WebKit::SOAuthorizationSession::start):
     30        * UIProcess/WebPageProxy.cpp:
     31        (WebKit::WebPageProxy::decidePolicyForSOAuthorizationLoad):
     32        * UIProcess/WebPageProxy.h:
     33        * WebKit.xcodeproj/project.pbxproj:
     34
    1352019-06-25  Simon Fraser  <simon.fraser@apple.com>
    236
  • trunk/Source/WebKit/UIProcess/API/APINavigationClient.h

    r246118 r246829  
    4040#include <WebCore/LayoutMilestone.h>
    4141#include <wtf/Forward.h>
     42
     43#if HAVE(APP_SSO)
     44#include "SOAuthorizationLoadPolicy.h"
     45#endif
    4246
    4347namespace WebCore {
     
    141145    virtual void didRemoveNavigationGestureSnapshot(WebKit::WebPageProxy&) { }
    142146    virtual bool didChangeBackForwardList(WebKit::WebPageProxy&, WebKit::WebBackForwardListItem*, const Vector<Ref<WebKit::WebBackForwardListItem>>&) { return false; }
     147
     148#if HAVE(APP_SSO)
     149    virtual void decidePolicyForSOAuthorizationLoad(WebKit::WebPageProxy&, WebKit::SOAuthorizationLoadPolicy currentSOAuthorizationLoadPolicy, const WTF::String&, CompletionHandler<void(WebKit::SOAuthorizationLoadPolicy)>&& completionHandler)
     150    {
     151        completionHandler(currentSOAuthorizationLoadPolicy);
     152    }
     153#endif
    143154};
    144155
  • trunk/Source/WebKit/UIProcess/API/Cocoa/WKNavigationDelegatePrivate.h

    r245294 r246829  
    5454    _WKProcessTerminationReasonCrash,
    5555} WK_API_AVAILABLE(macos(10.14), ios(12.0));
     56
     57typedef NS_ENUM(NSInteger, _WKSOAuthorizationLoadPolicy) {
     58    _WKSOAuthorizationLoadPolicyAllow,
     59    _WKSOAuthorizationLoadPolicyIgnore,
     60} WK_API_AVAILABLE(macos(10.15), ios(13.0));
    5661
    5762static const WKNavigationActionPolicy _WKNavigationActionPolicyDownload = (WKNavigationActionPolicy)(WKNavigationActionPolicyAllow + 1);
     
    112117#endif
    113118
     119- (void)_webView:(WKWebView *)webView decidePolicyForSOAuthorizationLoadWithCurrentPolicy:(_WKSOAuthorizationLoadPolicy)policy forExtension:(NSString *)extension completionHandler:(void (^)(_WKSOAuthorizationLoadPolicy policy))completionHandler WK_API_AVAILABLE(macos(10.15), ios(13.0));
     120
    114121@end
  • trunk/Source/WebKit/UIProcess/Cocoa/NavigationState.h

    r246118 r246829  
    140140        void decidePolicyForNavigationResponse(WebPageProxy&, Ref<API::NavigationResponse>&&, Ref<WebFramePolicyListenerProxy>&&, API::Object* userData) override;
    141141
     142#if HAVE(APP_SSO)
     143        void decidePolicyForSOAuthorizationLoad(WebPageProxy&, SOAuthorizationLoadPolicy, const String&, CompletionHandler<void(SOAuthorizationLoadPolicy)>&&) override;
     144#endif
     145
    142146        NavigationState& m_navigationState;
    143147    };
     
    239243        bool webViewDecidePolicyForPluginLoadWithCurrentPolicyPluginInfoCompletionHandler : 1;
    240244#endif
     245
     246#if HAVE(APP_SSO)
     247        bool webViewDecidePolicyForSOAuthorizationLoadWithCurrentPolicyForExtensionCompletionHandler : 1;
     248#endif
    241249    } m_navigationDelegateMethods;
    242250
  • trunk/Source/WebKit/UIProcess/Cocoa/NavigationState.mm

    r246514 r246829  
    197197    m_navigationDelegateMethods.webViewDecidePolicyForPluginLoadWithCurrentPolicyPluginInfoCompletionHandler = [delegate respondsToSelector:@selector(_webView:decidePolicyForPluginLoadWithCurrentPolicy:pluginInfo:completionHandler:)];
    198198#endif
     199#if HAVE(APP_SSO)
     200    m_navigationDelegateMethods.webViewDecidePolicyForSOAuthorizationLoadWithCurrentPolicyForExtensionCompletionHandler = [delegate respondsToSelector:@selector(_webView:decidePolicyForSOAuthorizationLoadWithCurrentPolicy:forExtension:completionHandler:)];
     201#endif
    199202}
    200203
     
    11021105#endif
    11031106
     1107#if HAVE(APP_SSO)
     1108static SOAuthorizationLoadPolicy soAuthorizationLoadPolicy(_WKSOAuthorizationLoadPolicy policy)
     1109{
     1110    switch (policy) {
     1111    case _WKSOAuthorizationLoadPolicyAllow:
     1112        return SOAuthorizationLoadPolicy::Allow;
     1113    case _WKSOAuthorizationLoadPolicyIgnore:
     1114        return SOAuthorizationLoadPolicy::Ignore;
     1115    }
     1116    ASSERT_NOT_REACHED();
     1117    return SOAuthorizationLoadPolicy::Allow;
     1118}
     1119
     1120static _WKSOAuthorizationLoadPolicy wkSOAuthorizationLoadPolicy(SOAuthorizationLoadPolicy policy)
     1121{
     1122    switch (policy) {
     1123    case SOAuthorizationLoadPolicy::Allow:
     1124        return _WKSOAuthorizationLoadPolicyAllow;
     1125    case SOAuthorizationLoadPolicy::Ignore:
     1126        return _WKSOAuthorizationLoadPolicyIgnore;
     1127    }
     1128    ASSERT_NOT_REACHED();
     1129    return _WKSOAuthorizationLoadPolicyAllow;
     1130}
     1131
     1132void NavigationState::NavigationClient::decidePolicyForSOAuthorizationLoad(WebPageProxy&, SOAuthorizationLoadPolicy currentSOAuthorizationLoadPolicy, const String& extension, CompletionHandler<void(SOAuthorizationLoadPolicy)>&& completionHandler)
     1133{
     1134    if (!m_navigationState.m_navigationDelegateMethods.webViewDecidePolicyForSOAuthorizationLoadWithCurrentPolicyForExtensionCompletionHandler) {
     1135        completionHandler(currentSOAuthorizationLoadPolicy);
     1136        return;
     1137    }
     1138
     1139    auto navigationDelegate = m_navigationState.m_navigationDelegate.get();
     1140    if (!navigationDelegate) {
     1141        completionHandler(currentSOAuthorizationLoadPolicy);
     1142        return;
     1143    }
     1144
     1145    auto checker = CompletionHandlerCallChecker::create(navigationDelegate.get(), @selector(_webView:decidePolicyForSOAuthorizationLoadWithCurrentPolicy:forExtension:completionHandler:));
     1146    [(id <WKNavigationDelegatePrivate>)navigationDelegate _webView:m_navigationState.m_webView decidePolicyForSOAuthorizationLoadWithCurrentPolicy:wkSOAuthorizationLoadPolicy(currentSOAuthorizationLoadPolicy) forExtension:extension completionHandler:makeBlockPtr([completionHandler = WTFMove(completionHandler), checker = WTFMove(checker)](_WKSOAuthorizationLoadPolicy policy) mutable {
     1147        if (checker->completionHandlerHasBeenCalled())
     1148            return;
     1149        checker->didCallCompletionHandler();
     1150        completionHandler(soAuthorizationLoadPolicy(policy));
     1151    }).get()];
     1152}
     1153#endif
     1154
    11041155// HistoryDelegatePrivate support
    11051156   
  • trunk/Source/WebKit/UIProcess/Cocoa/SOAuthorization/SOAuthorizationSession.mm

    r246701 r246829  
    3333#import "APINavigationAction.h"
    3434#import "APIUIClient.h"
     35#import "SOAuthorizationLoadPolicy.h"
    3536#import "WKUIDelegate.h"
    3637#import "WebPageProxy.h"
     
    103104    ASSERT((m_state == State::Idle || m_state == State::Waiting) && m_page && m_navigationAction);
    104105    m_state = State::Active;
    105     if (!m_soAuthorization)
    106         return;
    107 
    108     // FIXME<rdar://problem/48909336>: Replace the below with AppSSO constants.
    109     auto initiatorOrigin = emptyString();
    110     if (m_navigationAction->sourceFrame())
    111         initiatorOrigin = m_navigationAction->sourceFrame()->securityOrigin().securityOrigin().toString();
    112     if (m_action == InitiatingAction::SubFrame && m_page->mainFrame())
    113         initiatorOrigin = WebCore::SecurityOrigin::create(m_page->mainFrame()->url())->toString();
    114     NSDictionary *authorizationOptions = @{
    115         SOAuthorizationOptionUserActionInitiated: @(m_navigationAction->isProcessingUserGesture()),
    116         @"initiatorOrigin": (NSString *)initiatorOrigin,
    117         @"initiatingAction": @(static_cast<NSInteger>(m_action))
    118     };
    119     [m_soAuthorization setAuthorizationOptions:authorizationOptions];
    120 
    121     auto *nsRequest = m_navigationAction->request().nsURLRequest(WebCore::HTTPBodyUpdatePolicy::UpdateHTTPBody);
    122     [m_soAuthorization beginAuthorizationWithURL:nsRequest.URL httpHeaders:nsRequest.allHTTPHeaderFields httpBody:nsRequest.HTTPBody];
     106
     107    m_page->decidePolicyForSOAuthorizationLoad(emptyString(), [this, weakThis = makeWeakPtr(*this)] (SOAuthorizationLoadPolicy policy) {
     108        if (!weakThis)
     109            return;
     110
     111        if (policy == SOAuthorizationLoadPolicy::Ignore) {
     112            fallBackToWebPath();
     113            return;
     114        }
     115
     116        if (!m_soAuthorization || !m_page || !m_navigationAction)
     117            return;
     118
     119        // FIXME: <rdar://problem/48909336> Replace the below with AppSSO constants.
     120        auto initiatorOrigin = emptyString();
     121        if (m_navigationAction->sourceFrame())
     122            initiatorOrigin = m_navigationAction->sourceFrame()->securityOrigin().securityOrigin().toString();
     123        if (m_action == InitiatingAction::SubFrame && m_page->mainFrame())
     124            initiatorOrigin = WebCore::SecurityOrigin::create(m_page->mainFrame()->url())->toString();
     125        NSDictionary *authorizationOptions = @{
     126            SOAuthorizationOptionUserActionInitiated: @(m_navigationAction->isProcessingUserGesture()),
     127            @"initiatorOrigin": (NSString *)initiatorOrigin,
     128            @"initiatingAction": @(static_cast<NSInteger>(m_action))
     129        };
     130        [m_soAuthorization setAuthorizationOptions:authorizationOptions];
     131
     132        auto *nsRequest = m_navigationAction->request().nsURLRequest(WebCore::HTTPBodyUpdatePolicy::UpdateHTTPBody);
     133        [m_soAuthorization beginAuthorizationWithURL:nsRequest.URL httpHeaders:nsRequest.allHTTPHeaderFields httpBody:nsRequest.HTTPBody];
     134    });
    123135}
    124136
  • trunk/Source/WebKit/UIProcess/WebPageProxy.cpp

    r246701 r246829  
    92489248}
    92499249
     9250#if HAVE(APP_SSO)
     9251void WebPageProxy::decidePolicyForSOAuthorizationLoad(const String& extension, CompletionHandler<void(SOAuthorizationLoadPolicy)>&& completionHandler)
     9252{
     9253    m_navigationClient->decidePolicyForSOAuthorizationLoad(*this, SOAuthorizationLoadPolicy::Allow, extension, WTFMove(completionHandler));
     9254}
     9255#endif
     9256
    92509257} // namespace WebKit
    92519258
  • trunk/Source/WebKit/UIProcess/WebPageProxy.h

    r246701 r246829  
    142142#endif
    143143
     144#if HAVE(APP_SSO)
     145#include "SOAuthorizationLoadPolicy.h"
     146#endif
     147
    144148#if ENABLE(MEDIA_SESSION)
    145149namespace WebCore {
     
    15461550    void setShouldSuppressSOAuthorizationInAllNavigationPolicyDecision() { m_shouldSuppressSOAuthorizationInAllNavigationPolicyDecision = true; }
    15471551    void setShouldSuppressSOAuthorizationInNextNavigationPolicyDecision() { m_shouldSuppressSOAuthorizationInNextNavigationPolicyDecision = true; }
     1552    void decidePolicyForSOAuthorizationLoad(const String&, CompletionHandler<void(SOAuthorizationLoadPolicy)>&&);
    15481553#endif
    15491554
  • trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj

    r246527 r246829  
    10431043                57AC8F50217FEED90055438C /* HidConnection.h in Headers */ = {isa = PBXBuildFile; fileRef = 57AC8F4E217FEED90055438C /* HidConnection.h */; };
    10441044                57B4B46020B504AC00D4AD79 /* ClientCertificateAuthenticationXPCConstants.h in Headers */ = {isa = PBXBuildFile; fileRef = 57B4B45E20B504AB00D4AD79 /* ClientCertificateAuthenticationXPCConstants.h */; };
     1045                57BBEA6D22BC0BFE00273995 /* SOAuthorizationLoadPolicy.h in Headers */ = {isa = PBXBuildFile; fileRef = 57BBEA6C22BC0BFE00273995 /* SOAuthorizationLoadPolicy.h */; };
    10451046                57DCED6E2142EE5E0016B847 /* WebAuthenticatorCoordinatorMessageReceiver.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 57DCED6B2142EAE20016B847 /* WebAuthenticatorCoordinatorMessageReceiver.cpp */; };
    10461047                57DCED6F2142EE630016B847 /* WebAuthenticatorCoordinatorMessages.h in Headers */ = {isa = PBXBuildFile; fileRef = 57DCED6A2142EAE20016B847 /* WebAuthenticatorCoordinatorMessages.h */; };
     
    34813482                57B4B45D20B504AB00D4AD79 /* AuthenticationManagerCocoa.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = AuthenticationManagerCocoa.mm; sourceTree = "<group>"; };
    34823483                57B4B45E20B504AB00D4AD79 /* ClientCertificateAuthenticationXPCConstants.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ClientCertificateAuthenticationXPCConstants.h; sourceTree = "<group>"; };
     3484                57BBEA6C22BC0BFE00273995 /* SOAuthorizationLoadPolicy.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SOAuthorizationLoadPolicy.h; sourceTree = "<group>"; };
    34833485                57DCED6A2142EAE20016B847 /* WebAuthenticatorCoordinatorMessages.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = WebAuthenticatorCoordinatorMessages.h; path = DerivedSources/WebKit2/WebAuthenticatorCoordinatorMessages.h; sourceTree = BUILT_PRODUCTS_DIR; };
    34843486                57DCED6B2142EAE20016B847 /* WebAuthenticatorCoordinatorMessageReceiver.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = WebAuthenticatorCoordinatorMessageReceiver.cpp; path = DerivedSources/WebKit2/WebAuthenticatorCoordinatorMessageReceiver.cpp; sourceTree = BUILT_PRODUCTS_DIR; };
     
    70417043                                57FD317222B35148008D0E8B /* SOAuthorizationCoordinator.h */,
    70427044                                57FD317922B35149008D0E8B /* SOAuthorizationCoordinator.mm */,
     7045                                57BBEA6C22BC0BFE00273995 /* SOAuthorizationLoadPolicy.h */,
    70437046                                57FD317322B35148008D0E8B /* SOAuthorizationNSURLExtras.h */,
    70447047                                57FD317622B35149008D0E8B /* SOAuthorizationNSURLExtras.mm */,
     
    96379640                                1D67B339212E1F6100FAA786 /* ShareSheetCallbackID.h in Headers */,
    96389641                                7A41E9FB21F81DAD00B88CDB /* ShouldGrandfatherStatistics.h in Headers */,
    9639                                 576CA9D722B862180030143C /* SOAuthorizationNSURLExtras.h in Headers */,
    96409642                                995226D6207D184600F78420 /* SimulatedInputDispatcher.h in Headers */,
    96419643                                2DAF06D618BD1A470081CEB1 /* SmartMagnificationController.h in Headers */,
    96429644                                2DE6943E18BD2A68005C15E5 /* SmartMagnificationControllerMessages.h in Headers */,
    96439645                                57FD318322B35162008D0E8B /* SOAuthorizationCoordinator.h in Headers */,
     9646                                57BBEA6D22BC0BFE00273995 /* SOAuthorizationLoadPolicy.h in Headers */,
     9647                                576CA9D722B862180030143C /* SOAuthorizationNSURLExtras.h in Headers */,
    96449648                                57FD318522B35169008D0E8B /* SOAuthorizationSession.h in Headers */,
    96459649                                5272B28B1406985D0096A5D0 /* StatisticsData.h in Headers */,
  • trunk/Tools/ChangeLog

    r246823 r246829  
     12019-06-25  Jiewen Tan  <jiewen_tan@apple.com>
     2
     3        Implement a new SPI to inform clients about AppSSO
     4        https://bugs.webkit.org/show_bug.cgi?id=199085
     5        <rdar://problem/50028246>
     6
     7        Reviewed by Geoffrey Garen.
     8
     9        * TestWebKitAPI/Tests/WebKitCocoa/TestSOAuthorization.mm:
     10        (-[TestSOAuthorizationBasicDelegate webView:didFinishNavigation:]):
     11        (-[TestSOAuthorizationNavigationDelegate init]):
     12        (-[TestSOAuthorizationNavigationDelegate _webView:decidePolicyForSOAuthorizationLoadWithCurrentPolicy:forExtension:completionHandler:]):
     13        (TestWebKitAPI::TEST):
     14
    1152019-06-25  Aakash Jain  <aakash_jain@apple.com>
    216
  • trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/TestSOAuthorization.mm

    r246701 r246829  
    121121"</html>";
    122122
     123@interface TestSOAuthorizationBasicDelegate : NSObject <WKNavigationDelegate>
     124@end
     125
     126@implementation TestSOAuthorizationBasicDelegate
     127
     128- (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation
     129{
     130    EXPECT_FALSE(navigationCompleted);
     131    navigationCompleted = true;
     132    finalURL = navigation._request.URL.absoluteString;
     133}
     134
     135@end
     136
    123137@interface TestSOAuthorizationNavigationDelegate : NSObject <WKNavigationDelegate, WKUIDelegate>
    124138@property bool isDefaultPolicy;
    125139@property bool shouldOpenExternalSchemes;
     140@property bool allowSOAuthorizationLoad;
     141@property bool isAsyncExecution;
    126142- (instancetype)init;
    127143@end
     
    134150        self.isDefaultPolicy = true;
    135151        self.shouldOpenExternalSchemes = false;
     152        self.allowSOAuthorizationLoad = true;
     153        self.isAsyncExecution = false;
    136154    }
    137155    return self;
     
    162180    [gNewWindow setNavigationDelegate:self];
    163181    return gNewWindow.get();
     182}
     183
     184- (void)_webView:(WKWebView *)webView decidePolicyForSOAuthorizationLoadWithCurrentPolicy:(_WKSOAuthorizationLoadPolicy)policy forExtension:(NSString *)extension completionHandler:(void (^)(_WKSOAuthorizationLoadPolicy policy))completionHandler
     185{
     186    EXPECT_EQ(policy, _WKSOAuthorizationLoadPolicyAllow);
     187    EXPECT_TRUE([extension isEqual:@""]);
     188    if (!self.isAsyncExecution) {
     189        if (self.allowSOAuthorizationLoad)
     190            completionHandler(policy);
     191        else
     192            completionHandler(_WKSOAuthorizationLoadPolicyIgnore);
     193        return;
     194    }
     195
     196    auto allowSOAuthorizationLoad = self.allowSOAuthorizationLoad;
     197    dispatch_async(dispatch_get_main_queue(), ^() {
     198        if (allowSOAuthorizationLoad)
     199            completionHandler(_WKSOAuthorizationLoadPolicyAllow);
     200        else
     201            completionHandler(_WKSOAuthorizationLoadPolicyIgnore);
     202    });
    164203}
    165204
     
    417456
    418457    auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 500)]);
    419     auto delegate = adoptNS([[TestSOAuthorizationNavigationDelegate alloc] init]);
    420     configureSOAuthorizationWebView(webView.get(), delegate.get(), OpenExternalSchemesPolicy::Allow);
     458    auto delegate = adoptNS([[TestSOAuthorizationBasicDelegate alloc] init]);
     459    [webView setNavigationDelegate:delegate.get()];
    421460
    422461    [webView loadRequest:[NSURLRequest requestWithURL:testURL.get()]];
     
    444483
    445484    auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 500)]);
    446     auto delegate = adoptNS([[TestSOAuthorizationNavigationDelegate alloc] init]);
    447     configureSOAuthorizationWebView(webView.get(), delegate.get(), OpenExternalSchemesPolicy::Allow);
     485    auto delegate = adoptNS([[TestSOAuthorizationBasicDelegate alloc] init]);
     486    [webView setNavigationDelegate:delegate.get()];
    448487
    449488    // Force App Links with a request.URL that has a different host than the current one (empty host) and ShouldOpenExternalURLsPolicy::ShouldAllow.
     
    957996    [gDelegate authorization:gAuthorization didCompleteWithHTTPResponse:response.get() httpBody:adoptNS([[NSData alloc] init]).get()];
    958997}
     998
     999TEST(SOAuthorizationRedirect, SOAuthorizationLoadPolicyIgnore)
     1000{
     1001    resetState();
     1002    ClassMethodSwizzler swizzler(PAL::getSOAuthorizationClass(), @selector(canPerformAuthorizationWithURL:responseCode:), reinterpret_cast<IMP>(overrideCanPerformAuthorizationWithURL));
     1003
     1004    RetainPtr<NSURL> testURL = [[NSBundle mainBundle] URLForResource:@"simple" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"];
     1005
     1006    auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 500)]);
     1007    auto delegate = adoptNS([[TestSOAuthorizationNavigationDelegate alloc] init]);
     1008    configureSOAuthorizationWebView(webView.get(), delegate.get(), OpenExternalSchemesPolicy::Allow);
     1009    [delegate setAllowSOAuthorizationLoad:false];
     1010
     1011    [webView loadRequest:[NSURLRequest requestWithURL:testURL.get()]];
     1012    Util::run(&navigationCompleted);
     1013
     1014    EXPECT_WK_STREQ(testURL.get().absoluteString, finalURL);
     1015}
     1016
     1017TEST(SOAuthorizationRedirect, SOAuthorizationLoadPolicyAllowAsync)
     1018{
     1019    resetState();
     1020    ClassMethodSwizzler swizzler1(PAL::getSOAuthorizationClass(), @selector(canPerformAuthorizationWithURL:responseCode:), reinterpret_cast<IMP>(overrideCanPerformAuthorizationWithURL));
     1021    InstanceMethodSwizzler swizzler2(PAL::getSOAuthorizationClass(), @selector(setDelegate:), reinterpret_cast<IMP>(overrideSetDelegate));
     1022    InstanceMethodSwizzler swizzler3(PAL::getSOAuthorizationClass(), @selector(beginAuthorizationWithURL:httpHeaders:httpBody:), reinterpret_cast<IMP>(overrideBeginAuthorizationWithURL));
     1023
     1024    RetainPtr<NSURL> testURL = [[NSBundle mainBundle] URLForResource:@"simple" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"];
     1025
     1026    auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 500)]);
     1027    auto delegate = adoptNS([[TestSOAuthorizationNavigationDelegate alloc] init]);
     1028    configureSOAuthorizationWebView(webView.get(), delegate.get(), OpenExternalSchemesPolicy::Allow);
     1029
     1030    [webView loadRequest:[NSURLRequest requestWithURL:testURL.get()]];
     1031    Util::run(&authorizationPerformed);
     1032    checkAuthorizationOptions(false, "", 0);
     1033
     1034    RetainPtr<NSURL> redirectURL = [[NSBundle mainBundle] URLForResource:@"simple2" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"];
     1035    auto response = adoptNS([[NSHTTPURLResponse alloc] initWithURL:testURL.get() statusCode:302 HTTPVersion:@"HTTP/1.1" headerFields:@{ @"Location" : [redirectURL absoluteString] }]);
     1036    [gDelegate authorization:gAuthorization didCompleteWithHTTPResponse:response.get() httpBody:adoptNS([[NSData alloc] init]).get()];
     1037    Util::run(&navigationCompleted);
     1038#if PLATFORM(IOS)
     1039    navigationCompleted = false;
     1040    Util::run(&navigationCompleted);
     1041#endif
     1042    EXPECT_WK_STREQ(redirectURL.get().absoluteString, finalURL);
     1043}
     1044
     1045TEST(SOAuthorizationRedirect, SOAuthorizationLoadPolicyIgnoreAsync)
     1046{
     1047    resetState();
     1048    ClassMethodSwizzler swizzler(PAL::getSOAuthorizationClass(), @selector(canPerformAuthorizationWithURL:responseCode:), reinterpret_cast<IMP>(overrideCanPerformAuthorizationWithURL));
     1049
     1050    RetainPtr<NSURL> testURL = [[NSBundle mainBundle] URLForResource:@"simple" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"];
     1051
     1052    auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 500)]);
     1053    auto delegate = adoptNS([[TestSOAuthorizationNavigationDelegate alloc] init]);
     1054    configureSOAuthorizationWebView(webView.get(), delegate.get(), OpenExternalSchemesPolicy::Allow);
     1055    [delegate setAllowSOAuthorizationLoad:false];
     1056    [delegate setIsAsyncExecution:true];
     1057
     1058    [webView loadRequest:[NSURLRequest requestWithURL:testURL.get()]];
     1059    Util::run(&navigationCompleted);
     1060
     1061    EXPECT_WK_STREQ(testURL.get().absoluteString, finalURL);
     1062}
     1063
    9591064
    9601065// FIXME(175204): Enable the iOS tests once the bug is fixed.
     
    16531758    Util::run(&authorizationPerformed);
    16541759    checkAuthorizationOptions(true, "http://www.webkit.org", 1);
     1760}
     1761
     1762TEST(SOAuthorizationPopUp, SOAuthorizationLoadPolicyIgnore)
     1763{
     1764    resetState();
     1765    ClassMethodSwizzler swizzler(PAL::getSOAuthorizationClass(), @selector(canPerformAuthorizationWithURL:responseCode:), reinterpret_cast<IMP>(overrideCanPerformAuthorizationWithURL));
     1766
     1767    auto testURL = URL(URL(), "http://www.example.com");
     1768    auto testHtml = generateHtml(openerTemplate, testURL.string());
     1769
     1770    auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 500)]);
     1771    auto delegate = adoptNS([[TestSOAuthorizationNavigationDelegate alloc] init]);
     1772    configureSOAuthorizationWebView(webView.get(), delegate.get());
     1773    [delegate setAllowSOAuthorizationLoad:false];
     1774
     1775    [webView loadHTMLString:testHtml baseURL:(NSURL *)URL(URL(), "http://www.webkit.org")];
     1776    Util::run(&navigationCompleted);
     1777
     1778#if PLATFORM(MAC)
     1779    [webView sendClicksAtPoint:NSMakePoint(200, 200) numberOfClicks:1];
     1780#elif PLATFORM(IOS)
     1781    [webView evaluateJavaScript: @"clickMe()" completionHandler:nil];
     1782#endif
     1783    Util::run(&newWindowCreated);
     1784    EXPECT_FALSE(authorizationPerformed);
     1785}
     1786
     1787TEST(SOAuthorizationPopUp, SOAuthorizationLoadPolicyAllowAsync)
     1788{
     1789    resetState();
     1790    ClassMethodSwizzler swizzler1(PAL::getSOAuthorizationClass(), @selector(canPerformAuthorizationWithURL:responseCode:), reinterpret_cast<IMP>(overrideCanPerformAuthorizationWithURL));
     1791    InstanceMethodSwizzler swizzler2(PAL::getSOAuthorizationClass(), @selector(setDelegate:), reinterpret_cast<IMP>(overrideSetDelegate));
     1792    InstanceMethodSwizzler swizzler3(PAL::getSOAuthorizationClass(), @selector(beginAuthorizationWithURL:httpHeaders:httpBody:), reinterpret_cast<IMP>(overrideBeginAuthorizationWithURL));
     1793
     1794    RetainPtr<NSURL> baseURL = [[NSBundle mainBundle] URLForResource:@"simple2" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"];
     1795    auto testURL = URL(URL(), "http://www.example.com");
     1796    auto testHtml = generateHtml(openerTemplate, testURL.string());
     1797
     1798    auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 400, 400)]);
     1799    auto delegate = adoptNS([[TestSOAuthorizationNavigationDelegate alloc] init]);
     1800    configureSOAuthorizationWebView(webView.get(), delegate.get());
     1801    [delegate setIsAsyncExecution:true];
     1802
     1803    [webView loadHTMLString:testHtml baseURL:baseURL.get()];
     1804    Util::run(&navigationCompleted);
     1805
     1806#if PLATFORM(MAC)
     1807    [webView sendClicksAtPoint:NSMakePoint(200, 200) numberOfClicks:1];
     1808#elif PLATFORM(IOS)
     1809    [webView evaluateJavaScript: @"clickMe()" completionHandler:nil];
     1810#endif
     1811    Util::run(&authorizationPerformed);
     1812    checkAuthorizationOptions(true, "file://", 1);
     1813
     1814    auto response = adoptNS([[NSHTTPURLResponse alloc] initWithURL:testURL statusCode:200 HTTPVersion:@"HTTP/1.1" headerFields:nil]);
     1815    auto resonseHtmlCString = generateHtml(newWindowResponseTemplate, "window.close();").utf8(); // The pop up closes itself.
     1816    // The secret WKWebView needs to be destroyed right the way.
     1817    @autoreleasepool {
     1818        [gDelegate authorization:gAuthorization didCompleteWithHTTPResponse:response.get() httpBody:adoptNS([[NSData alloc] initWithBytes:resonseHtmlCString.data() length:resonseHtmlCString.length()]).get()];
     1819    }
     1820    [webView waitForMessage:@"Hello."];
     1821    [webView waitForMessage:@"WindowClosed."];
     1822}
     1823
     1824
     1825TEST(SOAuthorizationPopUp, SOAuthorizationLoadPolicyIgnoreAsync)
     1826{
     1827    resetState();
     1828    ClassMethodSwizzler swizzler(PAL::getSOAuthorizationClass(), @selector(canPerformAuthorizationWithURL:responseCode:), reinterpret_cast<IMP>(overrideCanPerformAuthorizationWithURL));
     1829
     1830    auto testURL = URL(URL(), "http://www.example.com");
     1831    auto testHtml = generateHtml(openerTemplate, testURL.string());
     1832
     1833    auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 500)]);
     1834    auto delegate = adoptNS([[TestSOAuthorizationNavigationDelegate alloc] init]);
     1835    configureSOAuthorizationWebView(webView.get(), delegate.get());
     1836    [delegate setAllowSOAuthorizationLoad:false];
     1837    [delegate setIsAsyncExecution:true];
     1838
     1839    [webView loadHTMLString:testHtml baseURL:(NSURL *)URL(URL(), "http://www.webkit.org")];
     1840    Util::run(&navigationCompleted);
     1841
     1842#if PLATFORM(MAC)
     1843    [webView sendClicksAtPoint:NSMakePoint(200, 200) numberOfClicks:1];
     1844#elif PLATFORM(IOS)
     1845    [webView evaluateJavaScript: @"clickMe()" completionHandler:nil];
     1846#endif
     1847    Util::run(&newWindowCreated);
     1848    EXPECT_FALSE(authorizationPerformed);
    16551849}
    16561850
     
    18622056}
    18632057
     2058TEST(SOAuthorizationSubFrame, SOAuthorizationLoadPolicyIgnore)
     2059{
     2060    resetState();
     2061    ClassMethodSwizzler swizzler(PAL::getSOAuthorizationClass(), @selector(canPerformAuthorizationWithURL:responseCode:), reinterpret_cast<IMP>(overrideCanPerformAuthorizationWithURL));
     2062
     2063    auto testURL = URL(URL(), "http://www.example.com");
     2064    auto testHtml = generateHtml(parentTemplate, testURL.string());
     2065
     2066    auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 500)]);
     2067    auto delegate = adoptNS([[TestSOAuthorizationNavigationDelegate alloc] init]);
     2068    configureSOAuthorizationWebView(webView.get(), delegate.get());
     2069    [delegate setAllowSOAuthorizationLoad:false];
     2070
     2071    [webView loadHTMLString:testHtml baseURL:(NSURL *)URL(URL(), "http://www.apple.com")];
     2072    // Try to wait until the iframe load is finished.
     2073    Util::sleep(0.5);
     2074    // Make sure we don't intercept the iframe.
     2075    EXPECT_FALSE(authorizationPerformed);
     2076}
     2077
     2078TEST(SOAuthorizationSubFrame, SOAuthorizationLoadPolicyAllowAsync)
     2079{
     2080    resetState();
     2081    ClassMethodSwizzler swizzler1(PAL::getSOAuthorizationClass(), @selector(canPerformAuthorizationWithURL:responseCode:), reinterpret_cast<IMP>(overrideCanPerformAuthorizationWithURL));
     2082    InstanceMethodSwizzler swizzler2(PAL::getSOAuthorizationClass(), @selector(setDelegate:), reinterpret_cast<IMP>(overrideSetDelegate));
     2083    InstanceMethodSwizzler swizzler3(PAL::getSOAuthorizationClass(), @selector(beginAuthorizationWithURL:httpHeaders:httpBody:), reinterpret_cast<IMP>(overrideBeginAuthorizationWithURL));
     2084    ClassMethodSwizzler swizzler4([AKAuthorizationController class], @selector(isURLFromAppleOwnedDomain:), reinterpret_cast<IMP>(overrideIsURLFromAppleOwnedDomain));
     2085
     2086    auto testURL = URL(URL(), "http://www.example.com");
     2087    auto testHtml = generateHtml(parentTemplate, testURL.string());
     2088
     2089    auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 500)]);
     2090    auto delegate = adoptNS([[TestSOAuthorizationNavigationDelegate alloc] init]);
     2091    configureSOAuthorizationWebView(webView.get(), delegate.get());
     2092    [delegate setIsAsyncExecution:true];
     2093
     2094    [webView loadHTMLString:testHtml baseURL:nil];
     2095    [webView waitForMessage:@"http://www.example.com"];
     2096    [webView waitForMessage:@"SOAuthorizationDidStart"];
     2097    checkAuthorizationOptions(false, "null", 2);
     2098
     2099    auto response = adoptNS([[NSHTTPURLResponse alloc] initWithURL:testURL statusCode:200 HTTPVersion:@"HTTP/1.1" headerFields:nil]);
     2100    auto iframeHtmlCString = generateHtml(iframeTemplate, "").utf8();
     2101    [gDelegate authorization:gAuthorization didCompleteWithHTTPResponse:response.get() httpBody:adoptNS([[NSData alloc] initWithBytes:iframeHtmlCString.data() length:iframeHtmlCString.length()]).get()];
     2102    [webView waitForMessage:@"http://www.example.com"];
     2103    [webView waitForMessage:@"Hello."];
     2104}
     2105
     2106TEST(SOAuthorizationSubFrame, SOAuthorizationLoadPolicyIgnoreAsync)
     2107{
     2108    resetState();
     2109    ClassMethodSwizzler swizzler(PAL::getSOAuthorizationClass(), @selector(canPerformAuthorizationWithURL:responseCode:), reinterpret_cast<IMP>(overrideCanPerformAuthorizationWithURL));
     2110
     2111    auto testURL = URL(URL(), "http://www.example.com");
     2112    auto testHtml = generateHtml(parentTemplate, testURL.string());
     2113
     2114    auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 500)]);
     2115    auto delegate = adoptNS([[TestSOAuthorizationNavigationDelegate alloc] init]);
     2116    configureSOAuthorizationWebView(webView.get(), delegate.get());
     2117    [delegate setAllowSOAuthorizationLoad:false];
     2118    [delegate setIsAsyncExecution:true];
     2119
     2120    [webView loadHTMLString:testHtml baseURL:(NSURL *)URL(URL(), "http://www.apple.com")];
     2121    // Try to wait until the iframe load is finished.
     2122    Util::sleep(0.5);
     2123    // Make sure we don't intercept the iframe.
     2124    EXPECT_FALSE(authorizationPerformed);
     2125}
     2126
    18642127} // namespace TestWebKitAPI
    18652128
Note: See TracChangeset for help on using the changeset viewer.