Changeset 220518 in webkit


Ignore:
Timestamp:
Aug 9, 2017 11:52:52 PM (7 years ago)
Author:
jmarcell@apple.com
Message:

Cherry-pick r220459. rdar://problem/33820786

Location:
branches/safari-604.1.38.1-branch
Files:
21 edited

Legend:

Unmodified
Added
Removed
  • branches/safari-604.1.38.1-branch/Source/WebCore/ChangeLog

    r220438 r220518  
     12017-08-09  Jason Marcell  <jmarcell@apple.com>
     2
     3        Cherry-pick r220459. rdar://problem/33820786
     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
    1372017-08-08  Jason Marcell  <jmarcell@apple.com>
    238
  • branches/safari-604.1.38.1-branch/Source/WebCore/loader/EmptyClients.cpp

    r219099 r220518  
    340340    void dispatchDecidePolicyForResponse(const ResourceResponse&, const ResourceRequest&, FramePolicyFunction&&) final { }
    341341    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;
    343343    void cancelPolicyCheck() final { }
    344344
     
    610610}
    611611
    612 void EmptyFrameLoaderClient::dispatchDecidePolicyForNavigationAction(const NavigationAction&, const ResourceRequest&, FormState*, FramePolicyFunction&&)
     612void EmptyFrameLoaderClient::dispatchDecidePolicyForNavigationAction(const NavigationAction&, const ResourceRequest&, bool, FormState*, FramePolicyFunction&&)
    613613{
    614614}
  • branches/safari-604.1.38.1-branch/Source/WebCore/loader/FrameLoaderClient.h

    r219786 r220518  
    180180    virtual void dispatchDecidePolicyForResponse(const ResourceResponse&, const ResourceRequest&, FramePolicyFunction&&) = 0;
    181181    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;
    183183    virtual void cancelPolicyCheck() = 0;
    184184
  • branches/safari-604.1.38.1-branch/Source/WebCore/loader/PolicyChecker.cpp

    r219407 r220518  
    148148    m_delegateIsDecidingNavigationPolicy = true;
    149149    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) {
    151151        continueAfterNavigationPolicy(action);
    152152    });
  • branches/safari-604.1.38.1-branch/Source/WebKit/ChangeLog

    r220348 r220518  
     12017-08-09  Jason Marcell  <jmarcell@apple.com>
     2
     3        Cherry-pick r220459. rdar://problem/33820786
     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
    1312017-08-07  Jason Marcell  <jmarcell@apple.com>
    232
  • branches/safari-604.1.38.1-branch/Source/WebKit/Shared/NavigationActionData.cpp

    r219304 r220518  
    4747    encoder << downloadAttribute;
    4848    encoder << clickLocationInRootViewCoordinates;
     49    encoder << isRedirect;
    4950}
    5051
     
    6970    if (!decoder.decode(result.clickLocationInRootViewCoordinates))
    7071        return false;
     72    if (!decoder.decode(result.isRedirect))
     73        return false;
    7174
    7275    return true;
  • branches/safari-604.1.38.1-branch/Source/WebKit/Shared/NavigationActionData.h

    r219304 r220518  
    5151    WTF::String downloadAttribute;
    5252    WebCore::FloatPoint clickLocationInRootViewCoordinates;
     53    bool isRedirect { false };
    5354};
    5455
  • branches/safari-604.1.38.1-branch/Source/WebKit/UIProcess/API/APINavigationAction.h

    r219304 r220518  
    6969    bool shouldOpenAppLinks() const { return m_shouldOpenAppLinks && m_navigationActionData.shouldOpenExternalURLsPolicy == WebCore::ShouldOpenExternalURLsPolicy::ShouldAllow; }
    7070    bool shouldPerformDownload() const { return !m_navigationActionData.downloadAttribute.isNull(); }
     71    bool isRedirect() const { return m_navigationActionData.isRedirect; }
    7172
    7273    bool isProcessingUserGesture() const { return m_userInitiatedAction; }
  • branches/safari-604.1.38.1-branch/Source/WebKit/UIProcess/API/Cocoa/WKNavigationAction.mm

    r219304 r220518  
    232232}
    233233
     234- (BOOL)_isRedirect
     235{
     236    return _navigationAction->isRedirect();
     237}
     238
    234239@end
    235240
  • branches/safari-604.1.38.1-branch/Source/WebKit/UIProcess/API/Cocoa/WKNavigationActionPrivate.h

    r219304 r220518  
    5555#endif
    5656
     57@property (nonatomic, readonly) BOOL _isRedirect WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
     58
    5759@end
    5860
  • branches/safari-604.1.38.1-branch/Source/WebKit/WebProcess/WebCoreSupport/WebFrameLoaderClient.cpp

    r219786 r220518  
    759759}
    760760
    761 void WebFrameLoaderClient::dispatchDecidePolicyForNavigationAction(const NavigationAction& navigationAction, const ResourceRequest& request, FormState* formState, FramePolicyFunction&& function)
     761void WebFrameLoaderClient::dispatchDecidePolicyForNavigationAction(const NavigationAction& navigationAction, const ResourceRequest& request, bool didReceiveRedirectResponse, FormState* formState, FramePolicyFunction&& function)
    762762{
    763763    WebPage* webPage = m_frame->page();
     
    810810    navigationActionData.shouldOpenExternalURLsPolicy = navigationAction.shouldOpenExternalURLsPolicy();
    811811    navigationActionData.downloadAttribute = navigationAction.downloadAttribute();
     812    navigationActionData.isRedirect = didReceiveRedirectResponse;
    812813
    813814    WebCore::Frame* coreFrame = m_frame->coreFrame();
  • branches/safari-604.1.38.1-branch/Source/WebKit/WebProcess/WebCoreSupport/WebFrameLoaderClient.h

    r219786 r220518  
    114114    void dispatchDecidePolicyForResponse(const WebCore::ResourceResponse&, const WebCore::ResourceRequest&, WebCore::FramePolicyFunction&&) final;
    115115    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;
    117117    void cancelPolicyCheck() final;
    118118   
  • branches/safari-604.1.38.1-branch/Source/WebKitLegacy/mac/ChangeLog

    r220439 r220518  
     12017-08-09  Jason Marcell  <jmarcell@apple.com>
     2
     3        Cherry-pick r220459. rdar://problem/33820786
     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
    1222017-08-08  Jason Marcell  <jmarcell@apple.com>
    223
  • branches/safari-604.1.38.1-branch/Source/WebKitLegacy/mac/WebCoreSupport/WebFrameLoaderClient.h

    r219099 r220518  
    121121    void dispatchDecidePolicyForResponse(const WebCore::ResourceResponse&, const WebCore::ResourceRequest&, WebCore::FramePolicyFunction&&) final;
    122122    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;
    124124    void cancelPolicyCheck() final;
    125125
  • branches/safari-604.1.38.1-branch/Source/WebKitLegacy/mac/WebCoreSupport/WebFrameLoaderClient.mm

    r220439 r220518  
    895895}
    896896
    897 void WebFrameLoaderClient::dispatchDecidePolicyForNavigationAction(const NavigationAction& action, const ResourceRequest& request, FormState* formState, FramePolicyFunction&& function)
     897void WebFrameLoaderClient::dispatchDecidePolicyForNavigationAction(const NavigationAction& action, const ResourceRequest& request, bool, FormState* formState, FramePolicyFunction&& function)
    898898{
    899899    WebView *webView = getWebView(m_webFrame.get());
  • branches/safari-604.1.38.1-branch/Source/WebKitLegacy/win/ChangeLog

    r219956 r220518  
     12017-08-09  Jason Marcell  <jmarcell@apple.com>
     2
     3        Cherry-pick r220459. rdar://problem/33820786
     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
    1222017-07-26  Jason Marcell  <jmarcell@apple.com>
    223
  • branches/safari-604.1.38.1-branch/Source/WebKitLegacy/win/WebCoreSupport/WebFrameLoaderClient.cpp

    r219099 r220518  
    550550}
    551551
    552 void WebFrameLoaderClient::dispatchDecidePolicyForNavigationAction(const NavigationAction& action, const ResourceRequest& request, FormState* formState, FramePolicyFunction&& function)
     552void WebFrameLoaderClient::dispatchDecidePolicyForNavigationAction(const NavigationAction& action, const ResourceRequest& request, bool, FormState* formState, FramePolicyFunction&& function)
    553553{
    554554    WebView* webView = m_webFrame->webView();
  • branches/safari-604.1.38.1-branch/Source/WebKitLegacy/win/WebCoreSupport/WebFrameLoaderClient.h

    r219099 r220518  
    9999    void dispatchDecidePolicyForResponse(const WebCore::ResourceResponse&, const WebCore::ResourceRequest&, WebCore::FramePolicyFunction&&) override;
    100100    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;
    102102    void cancelPolicyCheck() override;
    103103
  • branches/safari-604.1.38.1-branch/Tools/ChangeLog

    r220064 r220518  
     12017-08-09  Jason Marcell  <jmarcell@apple.com>
     2
     3        Cherry-pick r220459. rdar://problem/33820786
     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
    1212017-07-31  Jason Marcell  <jmarcell@apple.com>
    222
  • branches/safari-604.1.38.1-branch/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/DecidePolicyForNavigationAction.mm

    r219149 r220518  
    2929
    3030#import "PlatformUtilities.h"
     31#import "TestProtocol.h"
     32#import <WebKit/WKNavigationActionPrivate.h>
    3133#import <wtf/RetainPtr.h>
    3234#import <wtf/mac/AppKitCompatibilityDeclarations.h>
     
    381383}
    382384
     385TEST(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
     435TEST(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
     482TEST(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
    383529#endif
    384530
  • branches/safari-604.1.38.1-branch/Tools/TestWebKitAPI/cocoa/TestProtocol.mm

    r194950 r220518  
    7373}
    7474
     75static NSURL *createRedirectURL(NSString *query)
     76{
     77    return [NSURL URLWithString:[NSString stringWithFormat:@"%@://%@", testScheme, query]];
     78}
     79
    7580- (void)startLoading
    7681{
     
    7883    EXPECT_TRUE([requestURL.scheme isEqualToString:testScheme]);
    7984
     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
    8093    NSData *data = [@"PASS" dataUsingEncoding:NSASCIIStringEncoding];
    8194    RetainPtr<NSURLResponse> response = adoptNS([[NSURLResponse alloc] initWithURL:requestURL MIMEType:@"text/html" expectedContentLength:data.length textEncodingName:nil]);
    8295
    8396    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()];
    8698        return;
    8799    }
Note: See TracChangeset for help on using the changeset viewer.