Changeset 220520 in webkit
- Timestamp:
- Aug 10, 2017 12:30:04 AM (7 years ago)
- Location:
- branches/safari-604-branch
- Files:
-
- 21 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/safari-604-branch/Source/WebCore/ChangeLog
r220514 r220520 1 2017-08-09 Jason Marcell <jmarcell@apple.com> 2 3 Cherry-pick r220459. rdar://problem/33820790 4 5 2017-08-09 Daniel Bates <dabates@apple.com> 6 7 REGRESSION (r219013): OAuth flows are broken when redirecting back to application after authentication 8 https://bugs.webkit.org/show_bug.cgi?id=175247 9 <rdar://problem/33679804> 10 11 Reviewed by Brady Eidson. 12 13 Add SPI so that Safari can differentiate between a form submission and a redirected form submission 14 and have PolicyCheck notify the frame loader client if the navigation was in response to receiving a 15 redirect response. This is the WebKit portion to fix an issue when a native app makes use of an OAuth 16 OAuth flow that bounces to Safari for user login and then bounce back to the app. Microsoft Graph's 17 OAuth flow is one example. 18 19 Safari was differentiating between a form submission and a redirected form submission based on the 20 nullity of WKNavigationAction.sourceFrame because in both cases the navigation type was WKNavigationTypeFormSubmitted. 21 The navigation type is the same for both navigations because WebKit always used the navigation 22 action from the original request for the redirect request when the original request redirected. 23 Prior to r219013, WKNavigationAction.sourceFrame would be nil for a form submission that redirects. 24 Following r219013, WKNavigationAction.sourceFrame is non-nil unless the navigation was initiated by 25 API. In particular, WKNavigationAction.sourceFrame is non-nil for the redirect navigation corresponding 26 to a form submission that redirects. 27 28 * loader/EmptyClients.cpp: 29 (WebCore::EmptyFrameLoaderClient::dispatchDecidePolicyForNavigationAction): 30 * loader/FrameLoaderClient.h: 31 Have dispatchDecidePolicyForNavigationAction() take a boolean as to whether the navigation was in 32 response to receiving a redirect response. 33 * loader/PolicyChecker.cpp: 34 (WebCore::PolicyChecker::checkNavigationPolicy): Notify the frame loader client whether the navigation 35 is in response to receiving a redirect response. 36 1 37 2017-08-09 Jason Marcell <jmarcell@apple.com> 2 38 -
branches/safari-604-branch/Source/WebCore/loader/EmptyClients.cpp
r219099 r220520 340 340 void dispatchDecidePolicyForResponse(const ResourceResponse&, const ResourceRequest&, FramePolicyFunction&&) final { } 341 341 void dispatchDecidePolicyForNewWindowAction(const NavigationAction&, const ResourceRequest&, FormState*, const String&, FramePolicyFunction&&) final; 342 void dispatchDecidePolicyForNavigationAction(const NavigationAction&, const ResourceRequest&, FormState*, FramePolicyFunction&&) final;342 void dispatchDecidePolicyForNavigationAction(const NavigationAction&, const ResourceRequest&, bool didReceiveRedirectResponse, FormState*, FramePolicyFunction&&) final; 343 343 void cancelPolicyCheck() final { } 344 344 … … 610 610 } 611 611 612 void EmptyFrameLoaderClient::dispatchDecidePolicyForNavigationAction(const NavigationAction&, const ResourceRequest&, FormState*, FramePolicyFunction&&)612 void EmptyFrameLoaderClient::dispatchDecidePolicyForNavigationAction(const NavigationAction&, const ResourceRequest&, bool, FormState*, FramePolicyFunction&&) 613 613 { 614 614 } -
branches/safari-604-branch/Source/WebCore/loader/FrameLoaderClient.h
r219786 r220520 180 180 virtual void dispatchDecidePolicyForResponse(const ResourceResponse&, const ResourceRequest&, FramePolicyFunction&&) = 0; 181 181 virtual void dispatchDecidePolicyForNewWindowAction(const NavigationAction&, const ResourceRequest&, FormState*, const String& frameName, FramePolicyFunction&&) = 0; 182 virtual void dispatchDecidePolicyForNavigationAction(const NavigationAction&, const ResourceRequest&, FormState*, FramePolicyFunction&&) = 0;182 virtual void dispatchDecidePolicyForNavigationAction(const NavigationAction&, const ResourceRequest&, bool didReceiveRedirectResponse, FormState*, FramePolicyFunction&&) = 0; 183 183 virtual void cancelPolicyCheck() = 0; 184 184 -
branches/safari-604-branch/Source/WebCore/loader/PolicyChecker.cpp
r219407 r220520 148 148 m_delegateIsDecidingNavigationPolicy = true; 149 149 m_suggestedFilename = action.downloadAttribute().isEmpty() ? nullAtom() : action.downloadAttribute(); 150 m_frame.loader().client().dispatchDecidePolicyForNavigationAction(action, request, formState, [this](PolicyAction action) {150 m_frame.loader().client().dispatchDecidePolicyForNavigationAction(action, request, didReceiveRedirectResponse, formState, [this](PolicyAction action) { 151 151 continueAfterNavigationPolicy(action); 152 152 }); -
branches/safari-604-branch/Source/WebKit/ChangeLog
r220514 r220520 1 2017-08-09 Jason Marcell <jmarcell@apple.com> 2 3 Cherry-pick r220459. rdar://problem/33820790 4 5 2017-08-09 Daniel Bates <dabates@apple.com> 6 7 REGRESSION (r219013): OAuth flows are broken when redirecting back to application after authentication 8 https://bugs.webkit.org/show_bug.cgi?id=175247 9 <rdar://problem/33679804> 10 11 Reviewed by Brady Eidson. 12 13 Add SPI WKNavigationAction._isRedirect to query whether the navigation was in response to receiving 14 a redirect response. The majority of the WebKit change is plumbing this knowledge through to connect 15 it with the SPI. 16 17 * Shared/NavigationActionData.cpp: 18 (WebKit::NavigationActionData::encode const): 19 (WebKit::NavigationActionData::decode): 20 Encode and decode the boolean NavigationActionData::isRedirect. 21 * Shared/NavigationActionData.h: 22 * UIProcess/API/APINavigationAction.h: 23 * UIProcess/API/Cocoa/WKNavigationAction.mm: 24 (-[WKNavigationAction _isRedirect]): Added. 25 * UIProcess/API/Cocoa/WKNavigationActionPrivate.h: 26 * WebProcess/WebCoreSupport/WebFrameLoaderClient.cpp: 27 (WebKit::WebFrameLoaderClient::dispatchDecidePolicyForNavigationAction): Set NavigationActionData::isRedirect 28 depending on whether the navigation is in response to receiving a redirect response. 29 * WebProcess/WebCoreSupport/WebFrameLoaderClient.h: 30 1 31 2017-08-09 Jason Marcell <jmarcell@apple.com> 2 32 -
branches/safari-604-branch/Source/WebKit/Shared/NavigationActionData.cpp
r219304 r220520 47 47 encoder << downloadAttribute; 48 48 encoder << clickLocationInRootViewCoordinates; 49 encoder << isRedirect; 49 50 } 50 51 … … 69 70 if (!decoder.decode(result.clickLocationInRootViewCoordinates)) 70 71 return false; 72 if (!decoder.decode(result.isRedirect)) 73 return false; 71 74 72 75 return true; -
branches/safari-604-branch/Source/WebKit/Shared/NavigationActionData.h
r219304 r220520 51 51 WTF::String downloadAttribute; 52 52 WebCore::FloatPoint clickLocationInRootViewCoordinates; 53 bool isRedirect { false }; 53 54 }; 54 55 -
branches/safari-604-branch/Source/WebKit/UIProcess/API/APINavigationAction.h
r219304 r220520 69 69 bool shouldOpenAppLinks() const { return m_shouldOpenAppLinks && m_navigationActionData.shouldOpenExternalURLsPolicy == WebCore::ShouldOpenExternalURLsPolicy::ShouldAllow; } 70 70 bool shouldPerformDownload() const { return !m_navigationActionData.downloadAttribute.isNull(); } 71 bool isRedirect() const { return m_navigationActionData.isRedirect; } 71 72 72 73 bool isProcessingUserGesture() const { return m_userInitiatedAction; } -
branches/safari-604-branch/Source/WebKit/UIProcess/API/Cocoa/WKNavigationAction.mm
r219304 r220520 232 232 } 233 233 234 - (BOOL)_isRedirect 235 { 236 return _navigationAction->isRedirect(); 237 } 238 234 239 @end 235 240 -
branches/safari-604-branch/Source/WebKit/UIProcess/API/Cocoa/WKNavigationActionPrivate.h
r219304 r220520 55 55 #endif 56 56 57 @property (nonatomic, readonly) BOOL _isRedirect WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA)); 58 57 59 @end 58 60 -
branches/safari-604-branch/Source/WebKit/WebProcess/WebCoreSupport/WebFrameLoaderClient.cpp
r219786 r220520 759 759 } 760 760 761 void WebFrameLoaderClient::dispatchDecidePolicyForNavigationAction(const NavigationAction& navigationAction, const ResourceRequest& request, FormState* formState, FramePolicyFunction&& function)761 void WebFrameLoaderClient::dispatchDecidePolicyForNavigationAction(const NavigationAction& navigationAction, const ResourceRequest& request, bool didReceiveRedirectResponse, FormState* formState, FramePolicyFunction&& function) 762 762 { 763 763 WebPage* webPage = m_frame->page(); … … 810 810 navigationActionData.shouldOpenExternalURLsPolicy = navigationAction.shouldOpenExternalURLsPolicy(); 811 811 navigationActionData.downloadAttribute = navigationAction.downloadAttribute(); 812 navigationActionData.isRedirect = didReceiveRedirectResponse; 812 813 813 814 WebCore::Frame* coreFrame = m_frame->coreFrame(); -
branches/safari-604-branch/Source/WebKit/WebProcess/WebCoreSupport/WebFrameLoaderClient.h
r219786 r220520 114 114 void dispatchDecidePolicyForResponse(const WebCore::ResourceResponse&, const WebCore::ResourceRequest&, WebCore::FramePolicyFunction&&) final; 115 115 void dispatchDecidePolicyForNewWindowAction(const WebCore::NavigationAction&, const WebCore::ResourceRequest&, WebCore::FormState*, const String& frameName, WebCore::FramePolicyFunction&&) final; 116 void dispatchDecidePolicyForNavigationAction(const WebCore::NavigationAction&, const WebCore::ResourceRequest&, WebCore::FormState*, WebCore::FramePolicyFunction&&) final;116 void dispatchDecidePolicyForNavigationAction(const WebCore::NavigationAction&, const WebCore::ResourceRequest&, bool didReceiveRedirectResponse, WebCore::FormState*, WebCore::FramePolicyFunction&&) final; 117 117 void cancelPolicyCheck() final; 118 118 -
branches/safari-604-branch/Source/WebKitLegacy/mac/ChangeLog
r220514 r220520 1 2017-08-09 Jason Marcell <jmarcell@apple.com> 2 3 Cherry-pick r220459. rdar://problem/33820790 4 5 2017-08-09 Daniel Bates <dabates@apple.com> 6 7 REGRESSION (r219013): OAuth flows are broken when redirecting back to application after authentication 8 https://bugs.webkit.org/show_bug.cgi?id=175247 9 <rdar://problem/33679804> 10 11 Reviewed by Brady Eidson. 12 13 Plumb knowledge of whether a navigation was in response to receiving a redirect response. 14 We do not actually make use of this knowledge in WebKitLegacy because we do not know of any 15 clients that need to make use of this information at this time. If such a needs comes up 16 then we can expose API/SPI similar to what we do for WebKit. 17 18 * WebCoreSupport/WebFrameLoaderClient.h: 19 * WebCoreSupport/WebFrameLoaderClient.mm: 20 (WebFrameLoaderClient::dispatchDecidePolicyForNavigationAction): 21 1 22 2017-08-09 Jason Marcell <jmarcell@apple.com> 2 23 -
branches/safari-604-branch/Source/WebKitLegacy/mac/WebCoreSupport/WebFrameLoaderClient.h
r219099 r220520 121 121 void dispatchDecidePolicyForResponse(const WebCore::ResourceResponse&, const WebCore::ResourceRequest&, WebCore::FramePolicyFunction&&) final; 122 122 void dispatchDecidePolicyForNewWindowAction(const WebCore::NavigationAction&, const WebCore::ResourceRequest&, WebCore::FormState*, const WTF::String& frameName, WebCore::FramePolicyFunction&&) final; 123 void dispatchDecidePolicyForNavigationAction(const WebCore::NavigationAction&, const WebCore::ResourceRequest&, WebCore::FormState*, WebCore::FramePolicyFunction&&) final;123 void dispatchDecidePolicyForNavigationAction(const WebCore::NavigationAction&, const WebCore::ResourceRequest&, bool didReceiveRedirectResponse, WebCore::FormState*, WebCore::FramePolicyFunction&&) final; 124 124 void cancelPolicyCheck() final; 125 125 -
branches/safari-604-branch/Source/WebKitLegacy/mac/WebCoreSupport/WebFrameLoaderClient.mm
r220512 r220520 895 895 } 896 896 897 void WebFrameLoaderClient::dispatchDecidePolicyForNavigationAction(const NavigationAction& action, const ResourceRequest& request, FormState* formState, FramePolicyFunction&& function)897 void WebFrameLoaderClient::dispatchDecidePolicyForNavigationAction(const NavigationAction& action, const ResourceRequest& request, bool, FormState* formState, FramePolicyFunction&& function) 898 898 { 899 899 WebView *webView = getWebView(m_webFrame.get()); -
branches/safari-604-branch/Source/WebKitLegacy/win/ChangeLog
r219956 r220520 1 2017-08-09 Jason Marcell <jmarcell@apple.com> 2 3 Cherry-pick r220459. rdar://problem/33820790 4 5 2017-08-09 Daniel Bates <dabates@apple.com> 6 7 REGRESSION (r219013): OAuth flows are broken when redirecting back to application after authentication 8 https://bugs.webkit.org/show_bug.cgi?id=175247 9 <rdar://problem/33679804> 10 11 Reviewed by Brady Eidson. 12 13 Plumb knowledge of whether a navigation was in response to receiving a redirect response. 14 We do not actually make use of this knowledge in WebKitLegacy because we do not know of any 15 clients that need to make use of this information at this time. If such a needs comes up 16 then we can expose API/SPI similar to what we do for WebKit. 17 18 * WebCoreSupport/WebFrameLoaderClient.cpp: 19 (WebFrameLoaderClient::dispatchDecidePolicyForNavigationAction): 20 * WebCoreSupport/WebFrameLoaderClient.h: 21 1 22 2017-07-26 Jason Marcell <jmarcell@apple.com> 2 23 -
branches/safari-604-branch/Source/WebKitLegacy/win/WebCoreSupport/WebFrameLoaderClient.cpp
r219099 r220520 550 550 } 551 551 552 void WebFrameLoaderClient::dispatchDecidePolicyForNavigationAction(const NavigationAction& action, const ResourceRequest& request, FormState* formState, FramePolicyFunction&& function)552 void WebFrameLoaderClient::dispatchDecidePolicyForNavigationAction(const NavigationAction& action, const ResourceRequest& request, bool, FormState* formState, FramePolicyFunction&& function) 553 553 { 554 554 WebView* webView = m_webFrame->webView(); -
branches/safari-604-branch/Source/WebKitLegacy/win/WebCoreSupport/WebFrameLoaderClient.h
r219099 r220520 99 99 void dispatchDecidePolicyForResponse(const WebCore::ResourceResponse&, const WebCore::ResourceRequest&, WebCore::FramePolicyFunction&&) override; 100 100 void dispatchDecidePolicyForNewWindowAction(const WebCore::NavigationAction&, const WebCore::ResourceRequest&, WebCore::FormState*, const WTF::String& frameName, WebCore::FramePolicyFunction&&) override; 101 void dispatchDecidePolicyForNavigationAction(const WebCore::NavigationAction&, const WebCore::ResourceRequest&, WebCore::FormState*, WebCore::FramePolicyFunction&&) override;101 void dispatchDecidePolicyForNavigationAction(const WebCore::NavigationAction&, const WebCore::ResourceRequest&, bool didReceiveRedirectResponse, WebCore::FormState*, WebCore::FramePolicyFunction&&) override; 102 102 void cancelPolicyCheck() override; 103 103 -
branches/safari-604-branch/Tools/ChangeLog
r220514 r220520 1 2017-08-09 Jason Marcell <jmarcell@apple.com> 2 3 Cherry-pick r220459. rdar://problem/33820790 4 5 2017-08-09 Daniel Bates <dabates@apple.com> 6 7 REGRESSION (r219013): OAuth flows are broken when redirecting back to application after authentication 8 https://bugs.webkit.org/show_bug.cgi?id=175247 9 <rdar://problem/33679804> 10 11 Reviewed by Brady Eidson. 12 13 Add tests for redirects. 14 15 * TestWebKitAPI/Tests/WebKit2Cocoa/DecidePolicyForNavigationAction.mm: 16 (TEST): 17 * TestWebKitAPI/cocoa/TestProtocol.mm: 18 (createRedirectURL): 19 (-[TestProtocol startLoading]): 20 1 21 2017-08-09 Jason Marcell <jmarcell@apple.com> 2 22 -
branches/safari-604-branch/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/DecidePolicyForNavigationAction.mm
r219149 r220520 29 29 30 30 #import "PlatformUtilities.h" 31 #import "TestProtocol.h" 32 #import <WebKit/WKNavigationActionPrivate.h> 31 33 #import <wtf/RetainPtr.h> 32 34 #import <wtf/mac/AppKitCompatibilityDeclarations.h> … … 381 383 } 382 384 385 TEST(WebKit2, DecidePolicyForNavigationActionForHyperlinkThatRedirects) 386 { 387 auto webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600)]); 388 389 auto window = adoptNS([[NSWindow alloc] initWithContentRect:[webView frame] styleMask:NSWindowStyleMaskBorderless backing:NSBackingStoreBuffered defer:YES]); 390 [[window contentView] addSubview:webView.get()]; 391 392 auto controller = adoptNS([[DecidePolicyForNavigationActionController alloc] init]); 393 [webView setNavigationDelegate:controller.get()]; 394 [webView setUIDelegate:controller.get()]; 395 396 [TestProtocol registerWithScheme:@"http"]; 397 finishedNavigation = false; 398 [webView loadHTMLString:@"<a style=\"display: block; height: 100%\" href=\"http://redirect/?result\">" baseURL:[NSURL URLWithString:@"http://webkit.org"]]; 399 TestWebKitAPI::Util::run(&finishedNavigation); 400 401 decidedPolicy = false; 402 [newWebView setNavigationDelegate:controller.get()]; 403 NSPoint clickPoint = NSMakePoint(100, 100); 404 [[webView hitTest:clickPoint] mouseDown:[NSEvent mouseEventWithType:NSEventTypeLeftMouseDown location:clickPoint modifierFlags:0 timestamp:0 windowNumber:[window windowNumber] context:nil eventNumber:0 clickCount:1 pressure:1]]; 405 [[webView hitTest:clickPoint] mouseUp:[NSEvent mouseEventWithType:NSEventTypeLeftMouseUp location:clickPoint modifierFlags:0 timestamp:0 windowNumber:[window windowNumber] context:nil eventNumber:0 clickCount:1 pressure:1]]; 406 TestWebKitAPI::Util::run(&decidedPolicy); 407 408 EXPECT_EQ(WKNavigationTypeLinkActivated, [action navigationType]); 409 EXPECT_TRUE([action sourceFrame] == [action targetFrame]); 410 EXPECT_WK_STREQ("GET", [[action request] HTTPMethod]); 411 EXPECT_WK_STREQ("http://redirect/?result", [[[action request] URL] absoluteString]); 412 EXPECT_EQ(webView.get(), [[action sourceFrame] webView]); 413 EXPECT_WK_STREQ("http", [[[action sourceFrame] securityOrigin] protocol]); 414 EXPECT_WK_STREQ("webkit.org", [[[action sourceFrame] securityOrigin] host]); 415 EXPECT_FALSE([action _isRedirect]); 416 417 // Wait to decide policy for redirect. 418 decidedPolicy = false; 419 TestWebKitAPI::Util::run(&decidedPolicy); 420 421 EXPECT_EQ(WKNavigationTypeLinkActivated, [action navigationType]); 422 EXPECT_TRUE([action sourceFrame] == [action targetFrame]); 423 EXPECT_WK_STREQ("GET", [[action request] HTTPMethod]); 424 EXPECT_WK_STREQ("http://result/", [[[action request] URL] absoluteString]); 425 EXPECT_EQ(webView.get(), [[action sourceFrame] webView]); 426 EXPECT_WK_STREQ("http", [[[action sourceFrame] securityOrigin] protocol]); 427 EXPECT_WK_STREQ("webkit.org", [[[action sourceFrame] securityOrigin] host]); 428 EXPECT_TRUE([action _isRedirect]); 429 430 [TestProtocol unregister]; 431 newWebView = nullptr; 432 action = nullptr; 433 } 434 435 TEST(WebKit2, DecidePolicyForNavigationActionForPOSTFormSubmissionThatRedirectsToGET) 436 { 437 auto webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600)]); 438 439 auto window = adoptNS([[NSWindow alloc] initWithContentRect:[webView frame] styleMask:NSWindowStyleMaskBorderless backing:NSBackingStoreBuffered defer:YES]); 440 [[window contentView] addSubview:webView.get()]; 441 442 auto controller = adoptNS([[DecidePolicyForNavigationActionController alloc] init]); 443 [webView setNavigationDelegate:controller.get()]; 444 [webView setUIDelegate:controller.get()]; 445 446 finishedNavigation = false; 447 [webView loadHTMLString:@"<form action=\"http://redirect/?result\" method=\"POST\"><input type=\"submit\" name=\"submitButton\" value=\"Submit\"></form>" baseURL:[NSURL URLWithString:@"http://webkit.org"]]; 448 TestWebKitAPI::Util::run(&finishedNavigation); 449 450 [TestProtocol registerWithScheme:@"http"]; 451 decidedPolicy = false; 452 [webView evaluateJavaScript:@"document.forms[0].submit()" completionHandler:nil]; 453 TestWebKitAPI::Util::run(&decidedPolicy); 454 455 EXPECT_EQ(WKNavigationTypeFormSubmitted, [action navigationType]); 456 EXPECT_TRUE([action sourceFrame] == [action targetFrame]); 457 EXPECT_WK_STREQ("POST", [[action request] HTTPMethod]); 458 EXPECT_WK_STREQ("http://redirect/?result", [[[action request] URL] absoluteString]); 459 EXPECT_EQ(webView.get(), [[action sourceFrame] webView]); 460 EXPECT_WK_STREQ("http", [[[action sourceFrame] securityOrigin] protocol]); 461 EXPECT_WK_STREQ("webkit.org", [[[action sourceFrame] securityOrigin] host]); 462 EXPECT_FALSE([action _isRedirect]); 463 464 // Wait to decide policy for redirect. 465 decidedPolicy = false; 466 TestWebKitAPI::Util::run(&decidedPolicy); 467 468 EXPECT_EQ(WKNavigationTypeFormSubmitted, [action navigationType]); 469 EXPECT_TRUE([action sourceFrame] == [action targetFrame]); 470 EXPECT_WK_STREQ("GET", [[action request] HTTPMethod]); 471 EXPECT_WK_STREQ("http://result/", [[[action request] URL] absoluteString]); 472 EXPECT_EQ(webView.get(), [[action sourceFrame] webView]); 473 EXPECT_WK_STREQ("http", [[[action sourceFrame] securityOrigin] protocol]); 474 EXPECT_WK_STREQ("webkit.org", [[[action sourceFrame] securityOrigin] host]); 475 EXPECT_TRUE([action _isRedirect]); 476 477 [TestProtocol unregister]; 478 newWebView = nullptr; 479 action = nullptr; 480 } 481 482 TEST(WebKit2, DecidePolicyForNavigationActionForPOSTFormSubmissionThatRedirectsToPOST) 483 { 484 auto webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600)]); 485 486 auto window = adoptNS([[NSWindow alloc] initWithContentRect:[webView frame] styleMask:NSWindowStyleMaskBorderless backing:NSBackingStoreBuffered defer:YES]); 487 [[window contentView] addSubview:webView.get()]; 488 489 auto controller = adoptNS([[DecidePolicyForNavigationActionController alloc] init]); 490 [webView setNavigationDelegate:controller.get()]; 491 [webView setUIDelegate:controller.get()]; 492 493 finishedNavigation = false; 494 [webView loadHTMLString:@"<form action=\"http://307-redirect/?result\" method=\"POST\"><input type=\"submit\" name=\"submitButton\" value=\"Submit\"></form>" baseURL:[NSURL URLWithString:@"http://webkit.org"]]; 495 TestWebKitAPI::Util::run(&finishedNavigation); 496 497 [TestProtocol registerWithScheme:@"http"]; 498 decidedPolicy = false; 499 [webView evaluateJavaScript:@"document.forms[0].submit()" completionHandler:nil]; 500 TestWebKitAPI::Util::run(&decidedPolicy); 501 502 EXPECT_EQ(WKNavigationTypeFormSubmitted, [action navigationType]); 503 EXPECT_TRUE([action sourceFrame] == [action targetFrame]); 504 EXPECT_WK_STREQ("POST", [[action request] HTTPMethod]); 505 EXPECT_WK_STREQ("http://307-redirect/?result", [[[action request] URL] absoluteString]); 506 EXPECT_EQ(webView.get(), [[action sourceFrame] webView]); 507 EXPECT_WK_STREQ("http", [[[action sourceFrame] securityOrigin] protocol]); 508 EXPECT_WK_STREQ("webkit.org", [[[action sourceFrame] securityOrigin] host]); 509 EXPECT_FALSE([action _isRedirect]); 510 511 // Wait to decide policy for redirect. 512 decidedPolicy = false; 513 TestWebKitAPI::Util::run(&decidedPolicy); 514 515 EXPECT_EQ(WKNavigationTypeFormSubmitted, [action navigationType]); 516 EXPECT_TRUE([action sourceFrame] == [action targetFrame]); 517 EXPECT_WK_STREQ("POST", [[action request] HTTPMethod]); 518 EXPECT_WK_STREQ("http://result/", [[[action request] URL] absoluteString]); 519 EXPECT_EQ(webView.get(), [[action sourceFrame] webView]); 520 EXPECT_WK_STREQ("http", [[[action sourceFrame] securityOrigin] protocol]); 521 EXPECT_WK_STREQ("webkit.org", [[[action sourceFrame] securityOrigin] host]); 522 EXPECT_TRUE([action _isRedirect]); 523 524 [TestProtocol unregister]; 525 newWebView = nullptr; 526 action = nullptr; 527 } 528 383 529 #endif 384 530 -
branches/safari-604-branch/Tools/TestWebKitAPI/cocoa/TestProtocol.mm
r194950 r220520 73 73 } 74 74 75 static NSURL *createRedirectURL(NSString *query) 76 { 77 return [NSURL URLWithString:[NSString stringWithFormat:@"%@://%@", testScheme, query]]; 78 } 79 75 80 - (void)startLoading 76 81 { … … 78 83 EXPECT_TRUE([requestURL.scheme isEqualToString:testScheme]); 79 84 85 if ([requestURL.host isEqualToString:@"307-redirect"]) { 86 RetainPtr<NSHTTPURLResponse> response = adoptNS([[NSHTTPURLResponse alloc] initWithURL:requestURL statusCode:307 HTTPVersion:@"HTTP/1.1" headerFields:@{@"Content-Type" : @"text/html"}]); 87 NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:createRedirectURL(requestURL.query)]; 88 request.HTTPMethod = self.request.HTTPMethod; 89 [self.client URLProtocol:self wasRedirectedToRequest:request redirectResponse:response.get()]; 90 return; 91 } 92 80 93 NSData *data = [@"PASS" dataUsingEncoding:NSASCIIStringEncoding]; 81 94 RetainPtr<NSURLResponse> response = adoptNS([[NSURLResponse alloc] initWithURL:requestURL MIMEType:@"text/html" expectedContentLength:data.length textEncodingName:nil]); 82 95 83 96 if ([requestURL.host isEqualToString:@"redirect"]) { 84 NSURL *redirectURL = [NSURL URLWithString:[NSString stringWithFormat:@"%@://%@", testScheme, requestURL.query]]; 85 [self.client URLProtocol:self wasRedirectedToRequest:[NSURLRequest requestWithURL:redirectURL] redirectResponse:response.get()]; 97 [self.client URLProtocol:self wasRedirectedToRequest:[NSURLRequest requestWithURL:createRedirectURL(requestURL.query)] redirectResponse:response.get()]; 86 98 return; 87 99 }
Note: See TracChangeset
for help on using the changeset viewer.