Title: [228673] releases/WebKitGTK/webkit-2.20
Revision
228673
Author
carlo...@webkit.org
Date
2018-02-19 05:17:59 -0800 (Mon, 19 Feb 2018)

Log Message

Merge r228430 - REGRESSION (r228299): Broke reader mode in Safari
https://bugs.webkit.org/show_bug.cgi?id=182697
<rdar://problem/37399012>

Reviewed by Ryosuke Niwa.

Source/WebCore:

Rework the fix for r228299 to be more targeted. I moved the policy check
cencelation from FrameLoader::stopLoading() to NavigationScheduler::schedule()
when a pending load is cancelled by another load. I have verified that the
sites fixed by r228299 still work with this more limited change. However,
reader mode is now working again.

The issue seems to be that we tell CFNetwork to continue with the load after
receiving the response, even if the client has not responded to the
decidePolicyForNavigationResponse delegate yet. As a result, CFNetwork sends
us the resource data and we may commit the provisional load before receiving
the policy response from the client. When the provisional load is committed,
we call FrameLoader::stopLoading() which after r228299 cancelled pending
policy checks. Because we did not wait for the policy check response to
commit the load, we would cancel it which would make the load fail.

The real fix here would be to make not tell CFNetwork to continue until after
we've received the policy delegate response. However, this is a larger and
riskier change at this point. I will follow-up on this issue.

Covered by new API test.

* loader/FrameLoader.cpp:
(WebCore::FrameLoader::stopLoading):
* loader/NavigationScheduler.cpp:
(WebCore::NavigationScheduler::schedule):

Tools:

Add API test coverage for responding asynchronously to the decidePolicyForNavigationResponse
delegate.

* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
* TestWebKitAPI/Tests/WebKitCocoa/AsyncPolicyForNavigationResponse.mm: Added.
(-[TestAsyncNavigationDelegate webView:didFinishNavigation:]):
(-[TestAsyncNavigationDelegate webView:didFailNavigation:withError:]):
(-[TestAsyncNavigationDelegate webView:didFailProvisionalNavigation:withError:]):
(-[TestAsyncNavigationDelegate webView:decidePolicyForNavigationAction:decisionHandler:]):
(-[TestAsyncNavigationDelegate webView:decidePolicyForNavigationResponse:decisionHandler:]):
(TestWebKitAPI::TEST):

Modified Paths

Added Paths

Diff

Modified: releases/WebKitGTK/webkit-2.20/Source/WebCore/ChangeLog (228672 => 228673)


--- releases/WebKitGTK/webkit-2.20/Source/WebCore/ChangeLog	2018-02-19 13:17:51 UTC (rev 228672)
+++ releases/WebKitGTK/webkit-2.20/Source/WebCore/ChangeLog	2018-02-19 13:17:59 UTC (rev 228673)
@@ -1,3 +1,37 @@
+2018-02-13  Chris Dumez  <cdu...@apple.com>
+
+        REGRESSION (r228299): Broke reader mode in Safari
+        https://bugs.webkit.org/show_bug.cgi?id=182697
+        <rdar://problem/37399012>
+
+        Reviewed by Ryosuke Niwa.
+
+        Rework the fix for r228299 to be more targeted. I moved the policy check
+        cencelation from FrameLoader::stopLoading() to NavigationScheduler::schedule()
+        when a pending load is cancelled by another load. I have verified that the
+        sites fixed by r228299 still work with this more limited change. However,
+        reader mode is now working again.
+
+        The issue seems to be that we tell CFNetwork to continue with the load after
+        receiving the response, even if the client has not responded to the
+        decidePolicyForNavigationResponse delegate yet. As a result, CFNetwork sends
+        us the resource data and we may commit the provisional load before receiving
+        the policy response from the client. When the provisional load is committed,
+        we call FrameLoader::stopLoading() which after r228299 cancelled pending
+        policy checks. Because we did not wait for the policy check response to
+        commit the load, we would cancel it which would make the load fail.
+
+        The real fix here would be to make not tell CFNetwork to continue until after
+        we've received the policy delegate response. However, this is a larger and
+        riskier change at this point. I will follow-up on this issue.
+
+        Covered by new API test.
+
+        * loader/FrameLoader.cpp:
+        (WebCore::FrameLoader::stopLoading):
+        * loader/NavigationScheduler.cpp:
+        (WebCore::NavigationScheduler::schedule):
+
 2018-02-08  Chris Dumez  <cdu...@apple.com>
 
         Form submission after navigation fails when decidePolicyForNavigationAction is async

Modified: releases/WebKitGTK/webkit-2.20/Source/WebCore/loader/FrameLoader.cpp (228672 => 228673)


--- releases/WebKitGTK/webkit-2.20/Source/WebCore/loader/FrameLoader.cpp	2018-02-19 13:17:51 UTC (rev 228672)
+++ releases/WebKitGTK/webkit-2.20/Source/WebCore/loader/FrameLoader.cpp	2018-02-19 13:17:59 UTC (rev 228673)
@@ -487,8 +487,6 @@
         DatabaseManager::singleton().stopDatabases(*document, nullptr);
     }
 
-    policyChecker().stopCheck();
-
     // FIXME: This will cancel redirection timer, which really needs to be restarted when restoring the frame from b/f cache.
     m_frame.navigationScheduler().cancel();
 }

Modified: releases/WebKitGTK/webkit-2.20/Source/WebCore/loader/NavigationScheduler.cpp (228672 => 228673)


--- releases/WebKitGTK/webkit-2.20/Source/WebCore/loader/NavigationScheduler.cpp	2018-02-19 13:17:51 UTC (rev 228672)
+++ releases/WebKitGTK/webkit-2.20/Source/WebCore/loader/NavigationScheduler.cpp	2018-02-19 13:17:59 UTC (rev 228673)
@@ -50,6 +50,7 @@
 #include "Logging.h"
 #include "NavigationDisabler.h"
 #include "Page.h"
+#include "PolicyChecker.h"
 #include "ScriptController.h"
 #include "UserGestureIndicator.h"
 #include <wtf/CurrentTime.h>
@@ -520,6 +521,7 @@
     if (redirect->wasDuringLoad()) {
         if (DocumentLoader* provisionalDocumentLoader = m_frame.loader().provisionalDocumentLoader())
             provisionalDocumentLoader->stopLoading();
+        m_frame.loader().policyChecker().stopCheck();
         m_frame.loader().stopLoading(UnloadEventPolicyUnloadAndPageHide);
     }
 

Modified: releases/WebKitGTK/webkit-2.20/Tools/ChangeLog (228672 => 228673)


--- releases/WebKitGTK/webkit-2.20/Tools/ChangeLog	2018-02-19 13:17:51 UTC (rev 228672)
+++ releases/WebKitGTK/webkit-2.20/Tools/ChangeLog	2018-02-19 13:17:59 UTC (rev 228673)
@@ -1,3 +1,23 @@
+2018-02-13  Chris Dumez  <cdu...@apple.com>
+
+        REGRESSION (r228299): Broke reader mode in Safari
+        https://bugs.webkit.org/show_bug.cgi?id=182697
+        <rdar://problem/37399012>
+
+        Reviewed by Ryosuke Niwa.
+
+        Add API test coverage for responding asynchronously to the decidePolicyForNavigationResponse
+        delegate.
+
+        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+        * TestWebKitAPI/Tests/WebKitCocoa/AsyncPolicyForNavigationResponse.mm: Added.
+        (-[TestAsyncNavigationDelegate webView:didFinishNavigation:]):
+        (-[TestAsyncNavigationDelegate webView:didFailNavigation:withError:]):
+        (-[TestAsyncNavigationDelegate webView:didFailProvisionalNavigation:withError:]):
+        (-[TestAsyncNavigationDelegate webView:decidePolicyForNavigationAction:decisionHandler:]):
+        (-[TestAsyncNavigationDelegate webView:decidePolicyForNavigationResponse:decisionHandler:]):
+        (TestWebKitAPI::TEST):
+
 2018-02-07  Ms2ger  <ms2...@igalia.com>
 
         [GTK] Enable WebKit.GeolocationTransitionTo{High,Low}Accuracy tests

Added: releases/WebKitGTK/webkit-2.20/Tools/TestWebKitAPI/Tests/WebKitCocoa/AsyncPolicyForNavigationResponse.mm (0 => 228673)


--- releases/WebKitGTK/webkit-2.20/Tools/TestWebKitAPI/Tests/WebKitCocoa/AsyncPolicyForNavigationResponse.mm	                        (rev 0)
+++ releases/WebKitGTK/webkit-2.20/Tools/TestWebKitAPI/Tests/WebKitCocoa/AsyncPolicyForNavigationResponse.mm	2018-02-19 13:17:59 UTC (rev 228673)
@@ -0,0 +1,93 @@
+/*
+ * Copyright (C) 2018 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import "config.h"
+
+#import "PlatformUtilities.h"
+#import "Test.h"
+#import <WebKit/WKWebView.h>
+#import <wtf/RetainPtr.h>
+
+#if WK_API_ENABLED
+static bool navigationComplete = false;
+static bool navigationFailed = false;
+
+@interface TestAsyncNavigationDelegate : NSObject <WKNavigationDelegate, WKUIDelegate>
+@end
+
+@implementation TestAsyncNavigationDelegate
+
+- (void)webView:(WKWebView *)webView didFinishNavigation:(null_unspecified WKNavigation *)navigation
+{
+    navigationComplete = true;
+}
+
+- (void)webView:(WKWebView *)webView didFailNavigation:(null_unspecified WKNavigation *)navigation withError:(NSError *)error
+{
+    navigationFailed = true;
+    navigationComplete = true;
+}
+
+- (void)webView:(WKWebView *)webView didFailProvisionalNavigation:(null_unspecified WKNavigation *)navigation withError:(NSError *)error
+{
+    navigationFailed = true;
+    navigationComplete = true;
+}
+
+- (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler
+{
+    decisionHandler(WKNavigationActionPolicyAllow);
+}
+
+- (void)webView:(WKWebView *)webView decidePolicyForNavigationResponse:(WKNavigationResponse *)navigationResponse decisionHandler:(void (^)(WKNavigationResponsePolicy))decisionHandler
+{
+    int64_t deferredWaitTime = 100 * NSEC_PER_MSEC;
+    dispatch_time_t when = dispatch_time(DISPATCH_TIME_NOW, deferredWaitTime);
+    dispatch_after(when, dispatch_get_main_queue(), ^{
+        decisionHandler(WKNavigationResponsePolicyAllow);
+    });
+}
+@end
+
+namespace TestWebKitAPI {
+
+TEST(WebKit, RespondToPolicyForNavigationResponseAsynchronously)
+{
+    RetainPtr<NSURL> testURL = [[NSBundle mainBundle] URLForResource:@"simple" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"];
+
+    auto webView = adoptNS([[WKWebView alloc] init]);
+    auto delegate = adoptNS([[TestAsyncNavigationDelegate alloc] init]);
+    [webView setNavigationDelegate:delegate.get()];
+    [webView setUIDelegate:delegate.get()];
+
+    [webView loadRequest:[NSURLRequest requestWithURL:testURL.get()]];
+    TestWebKitAPI::Util::run(&navigationComplete);
+
+    EXPECT_FALSE(navigationFailed);
+}
+
+} // namespace TestWebKitAPI
+
+#endif // WK_API_ENABLED
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to