Changeset 246829 in webkit
- Timestamp:
- Jun 25, 2019 8:11:36 PM (5 years ago)
- Location:
- trunk
- Files:
-
- 1 added
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebKit/ChangeLog
r246828 r246829 1 2019-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 1 35 2019-06-25 Simon Fraser <simon.fraser@apple.com> 2 36 -
trunk/Source/WebKit/UIProcess/API/APINavigationClient.h
r246118 r246829 40 40 #include <WebCore/LayoutMilestone.h> 41 41 #include <wtf/Forward.h> 42 43 #if HAVE(APP_SSO) 44 #include "SOAuthorizationLoadPolicy.h" 45 #endif 42 46 43 47 namespace WebCore { … … 141 145 virtual void didRemoveNavigationGestureSnapshot(WebKit::WebPageProxy&) { } 142 146 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 143 154 }; 144 155 -
trunk/Source/WebKit/UIProcess/API/Cocoa/WKNavigationDelegatePrivate.h
r245294 r246829 54 54 _WKProcessTerminationReasonCrash, 55 55 } WK_API_AVAILABLE(macos(10.14), ios(12.0)); 56 57 typedef NS_ENUM(NSInteger, _WKSOAuthorizationLoadPolicy) { 58 _WKSOAuthorizationLoadPolicyAllow, 59 _WKSOAuthorizationLoadPolicyIgnore, 60 } WK_API_AVAILABLE(macos(10.15), ios(13.0)); 56 61 57 62 static const WKNavigationActionPolicy _WKNavigationActionPolicyDownload = (WKNavigationActionPolicy)(WKNavigationActionPolicyAllow + 1); … … 112 117 #endif 113 118 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 114 121 @end -
trunk/Source/WebKit/UIProcess/Cocoa/NavigationState.h
r246118 r246829 140 140 void decidePolicyForNavigationResponse(WebPageProxy&, Ref<API::NavigationResponse>&&, Ref<WebFramePolicyListenerProxy>&&, API::Object* userData) override; 141 141 142 #if HAVE(APP_SSO) 143 void decidePolicyForSOAuthorizationLoad(WebPageProxy&, SOAuthorizationLoadPolicy, const String&, CompletionHandler<void(SOAuthorizationLoadPolicy)>&&) override; 144 #endif 145 142 146 NavigationState& m_navigationState; 143 147 }; … … 239 243 bool webViewDecidePolicyForPluginLoadWithCurrentPolicyPluginInfoCompletionHandler : 1; 240 244 #endif 245 246 #if HAVE(APP_SSO) 247 bool webViewDecidePolicyForSOAuthorizationLoadWithCurrentPolicyForExtensionCompletionHandler : 1; 248 #endif 241 249 } m_navigationDelegateMethods; 242 250 -
trunk/Source/WebKit/UIProcess/Cocoa/NavigationState.mm
r246514 r246829 197 197 m_navigationDelegateMethods.webViewDecidePolicyForPluginLoadWithCurrentPolicyPluginInfoCompletionHandler = [delegate respondsToSelector:@selector(_webView:decidePolicyForPluginLoadWithCurrentPolicy:pluginInfo:completionHandler:)]; 198 198 #endif 199 #if HAVE(APP_SSO) 200 m_navigationDelegateMethods.webViewDecidePolicyForSOAuthorizationLoadWithCurrentPolicyForExtensionCompletionHandler = [delegate respondsToSelector:@selector(_webView:decidePolicyForSOAuthorizationLoadWithCurrentPolicy:forExtension:completionHandler:)]; 201 #endif 199 202 } 200 203 … … 1102 1105 #endif 1103 1106 1107 #if HAVE(APP_SSO) 1108 static 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 1120 static _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 1132 void 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 1104 1155 // HistoryDelegatePrivate support 1105 1156 -
trunk/Source/WebKit/UIProcess/Cocoa/SOAuthorization/SOAuthorizationSession.mm
r246701 r246829 33 33 #import "APINavigationAction.h" 34 34 #import "APIUIClient.h" 35 #import "SOAuthorizationLoadPolicy.h" 35 36 #import "WKUIDelegate.h" 36 37 #import "WebPageProxy.h" … … 103 104 ASSERT((m_state == State::Idle || m_state == State::Waiting) && m_page && m_navigationAction); 104 105 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 }); 123 135 } 124 136 -
trunk/Source/WebKit/UIProcess/WebPageProxy.cpp
r246701 r246829 9248 9248 } 9249 9249 9250 #if HAVE(APP_SSO) 9251 void WebPageProxy::decidePolicyForSOAuthorizationLoad(const String& extension, CompletionHandler<void(SOAuthorizationLoadPolicy)>&& completionHandler) 9252 { 9253 m_navigationClient->decidePolicyForSOAuthorizationLoad(*this, SOAuthorizationLoadPolicy::Allow, extension, WTFMove(completionHandler)); 9254 } 9255 #endif 9256 9250 9257 } // namespace WebKit 9251 9258 -
trunk/Source/WebKit/UIProcess/WebPageProxy.h
r246701 r246829 142 142 #endif 143 143 144 #if HAVE(APP_SSO) 145 #include "SOAuthorizationLoadPolicy.h" 146 #endif 147 144 148 #if ENABLE(MEDIA_SESSION) 145 149 namespace WebCore { … … 1546 1550 void setShouldSuppressSOAuthorizationInAllNavigationPolicyDecision() { m_shouldSuppressSOAuthorizationInAllNavigationPolicyDecision = true; } 1547 1551 void setShouldSuppressSOAuthorizationInNextNavigationPolicyDecision() { m_shouldSuppressSOAuthorizationInNextNavigationPolicyDecision = true; } 1552 void decidePolicyForSOAuthorizationLoad(const String&, CompletionHandler<void(SOAuthorizationLoadPolicy)>&&); 1548 1553 #endif 1549 1554 -
trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj
r246527 r246829 1043 1043 57AC8F50217FEED90055438C /* HidConnection.h in Headers */ = {isa = PBXBuildFile; fileRef = 57AC8F4E217FEED90055438C /* HidConnection.h */; }; 1044 1044 57B4B46020B504AC00D4AD79 /* ClientCertificateAuthenticationXPCConstants.h in Headers */ = {isa = PBXBuildFile; fileRef = 57B4B45E20B504AB00D4AD79 /* ClientCertificateAuthenticationXPCConstants.h */; }; 1045 57BBEA6D22BC0BFE00273995 /* SOAuthorizationLoadPolicy.h in Headers */ = {isa = PBXBuildFile; fileRef = 57BBEA6C22BC0BFE00273995 /* SOAuthorizationLoadPolicy.h */; }; 1045 1046 57DCED6E2142EE5E0016B847 /* WebAuthenticatorCoordinatorMessageReceiver.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 57DCED6B2142EAE20016B847 /* WebAuthenticatorCoordinatorMessageReceiver.cpp */; }; 1046 1047 57DCED6F2142EE630016B847 /* WebAuthenticatorCoordinatorMessages.h in Headers */ = {isa = PBXBuildFile; fileRef = 57DCED6A2142EAE20016B847 /* WebAuthenticatorCoordinatorMessages.h */; }; … … 3481 3482 57B4B45D20B504AB00D4AD79 /* AuthenticationManagerCocoa.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = AuthenticationManagerCocoa.mm; sourceTree = "<group>"; }; 3482 3483 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>"; }; 3483 3485 57DCED6A2142EAE20016B847 /* WebAuthenticatorCoordinatorMessages.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = WebAuthenticatorCoordinatorMessages.h; path = DerivedSources/WebKit2/WebAuthenticatorCoordinatorMessages.h; sourceTree = BUILT_PRODUCTS_DIR; }; 3484 3486 57DCED6B2142EAE20016B847 /* WebAuthenticatorCoordinatorMessageReceiver.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = WebAuthenticatorCoordinatorMessageReceiver.cpp; path = DerivedSources/WebKit2/WebAuthenticatorCoordinatorMessageReceiver.cpp; sourceTree = BUILT_PRODUCTS_DIR; }; … … 7041 7043 57FD317222B35148008D0E8B /* SOAuthorizationCoordinator.h */, 7042 7044 57FD317922B35149008D0E8B /* SOAuthorizationCoordinator.mm */, 7045 57BBEA6C22BC0BFE00273995 /* SOAuthorizationLoadPolicy.h */, 7043 7046 57FD317322B35148008D0E8B /* SOAuthorizationNSURLExtras.h */, 7044 7047 57FD317622B35149008D0E8B /* SOAuthorizationNSURLExtras.mm */, … … 9637 9640 1D67B339212E1F6100FAA786 /* ShareSheetCallbackID.h in Headers */, 9638 9641 7A41E9FB21F81DAD00B88CDB /* ShouldGrandfatherStatistics.h in Headers */, 9639 576CA9D722B862180030143C /* SOAuthorizationNSURLExtras.h in Headers */,9640 9642 995226D6207D184600F78420 /* SimulatedInputDispatcher.h in Headers */, 9641 9643 2DAF06D618BD1A470081CEB1 /* SmartMagnificationController.h in Headers */, 9642 9644 2DE6943E18BD2A68005C15E5 /* SmartMagnificationControllerMessages.h in Headers */, 9643 9645 57FD318322B35162008D0E8B /* SOAuthorizationCoordinator.h in Headers */, 9646 57BBEA6D22BC0BFE00273995 /* SOAuthorizationLoadPolicy.h in Headers */, 9647 576CA9D722B862180030143C /* SOAuthorizationNSURLExtras.h in Headers */, 9644 9648 57FD318522B35169008D0E8B /* SOAuthorizationSession.h in Headers */, 9645 9649 5272B28B1406985D0096A5D0 /* StatisticsData.h in Headers */, -
trunk/Tools/ChangeLog
r246823 r246829 1 2019-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 1 15 2019-06-25 Aakash Jain <aakash_jain@apple.com> 2 16 -
trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/TestSOAuthorization.mm
r246701 r246829 121 121 "</html>"; 122 122 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 123 137 @interface TestSOAuthorizationNavigationDelegate : NSObject <WKNavigationDelegate, WKUIDelegate> 124 138 @property bool isDefaultPolicy; 125 139 @property bool shouldOpenExternalSchemes; 140 @property bool allowSOAuthorizationLoad; 141 @property bool isAsyncExecution; 126 142 - (instancetype)init; 127 143 @end … … 134 150 self.isDefaultPolicy = true; 135 151 self.shouldOpenExternalSchemes = false; 152 self.allowSOAuthorizationLoad = true; 153 self.isAsyncExecution = false; 136 154 } 137 155 return self; … … 162 180 [gNewWindow setNavigationDelegate:self]; 163 181 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 }); 164 203 } 165 204 … … 417 456 418 457 auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 500)]); 419 auto delegate = adoptNS([[TestSOAuthorization NavigationDelegate alloc] init]);420 configureSOAuthorizationWebView(webView.get(), delegate.get(), OpenExternalSchemesPolicy::Allow);458 auto delegate = adoptNS([[TestSOAuthorizationBasicDelegate alloc] init]); 459 [webView setNavigationDelegate:delegate.get()]; 421 460 422 461 [webView loadRequest:[NSURLRequest requestWithURL:testURL.get()]]; … … 444 483 445 484 auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 500)]); 446 auto delegate = adoptNS([[TestSOAuthorization NavigationDelegate alloc] init]);447 configureSOAuthorizationWebView(webView.get(), delegate.get(), OpenExternalSchemesPolicy::Allow);485 auto delegate = adoptNS([[TestSOAuthorizationBasicDelegate alloc] init]); 486 [webView setNavigationDelegate:delegate.get()]; 448 487 449 488 // Force App Links with a request.URL that has a different host than the current one (empty host) and ShouldOpenExternalURLsPolicy::ShouldAllow. … … 957 996 [gDelegate authorization:gAuthorization didCompleteWithHTTPResponse:response.get() httpBody:adoptNS([[NSData alloc] init]).get()]; 958 997 } 998 999 TEST(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 1017 TEST(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 1045 TEST(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 959 1064 960 1065 // FIXME(175204): Enable the iOS tests once the bug is fixed. … … 1653 1758 Util::run(&authorizationPerformed); 1654 1759 checkAuthorizationOptions(true, "http://www.webkit.org", 1); 1760 } 1761 1762 TEST(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 1787 TEST(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 1825 TEST(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); 1655 1849 } 1656 1850 … … 1862 2056 } 1863 2057 2058 TEST(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 2078 TEST(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 2106 TEST(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 1864 2127 } // namespace TestWebKitAPI 1865 2128
Note: See TracChangeset
for help on using the changeset viewer.