Title: [218892] trunk
- Revision
- 218892
- Author
- [email protected]
- Date
- 2017-06-28 14:04:26 -0700 (Wed, 28 Jun 2017)
Log Message
WebsitePolicies given with navigation policy for redirects should apply to the provisional document
https://bugs.webkit.org/show_bug.cgi?id=173886
<rdar://problem/32543191>
Reviewed by Andy Estes.
Source/WebKit2:
If, for example, we deny video autoplay for the initial request but allow it for the redirect destination
location, the document should allow video autoplay. We were putting these settings onto the wrong DocumentLoader.
When a navigation policy is given to a response of a redirect location, we currently have the DocumentLoader
for the loading document in the FrameLoader's provisionalDocumentLoader, not the documentLoader.
Covered by a new API test.
* WebProcess/WebCoreSupport/WebFrameLoaderClient.cpp:
(WebKit::WebFrameLoaderClient::dispatchDecidePolicyForNavigationAction):
Tools:
* TestWebKitAPI/Tests/WebKit2Cocoa/WebsitePolicies.mm:
(ParsedRange::ParsedRange):
(-[TestSchemeHandler initWithVideoData:]):
(-[TestSchemeHandler webView:startURLSchemeTask:]):
(-[TestSchemeHandler webView:stopURLSchemeTask:]):
(TEST):
Modified Paths
Diff
Modified: trunk/Source/WebKit2/ChangeLog (218891 => 218892)
--- trunk/Source/WebKit2/ChangeLog 2017-06-28 20:59:06 UTC (rev 218891)
+++ trunk/Source/WebKit2/ChangeLog 2017-06-28 21:04:26 UTC (rev 218892)
@@ -1,3 +1,21 @@
+2017-06-28 Alex Christensen <[email protected]>
+
+ WebsitePolicies given with navigation policy for redirects should apply to the provisional document
+ https://bugs.webkit.org/show_bug.cgi?id=173886
+ <rdar://problem/32543191>
+
+ Reviewed by Andy Estes.
+
+ If, for example, we deny video autoplay for the initial request but allow it for the redirect destination
+ location, the document should allow video autoplay. We were putting these settings onto the wrong DocumentLoader.
+ When a navigation policy is given to a response of a redirect location, we currently have the DocumentLoader
+ for the loading document in the FrameLoader's provisionalDocumentLoader, not the documentLoader.
+
+ Covered by a new API test.
+
+ * WebProcess/WebCoreSupport/WebFrameLoaderClient.cpp:
+ (WebKit::WebFrameLoaderClient::dispatchDecidePolicyForNavigationAction):
+
2017-06-28 Konstantin Tokarev <[email protected]>
[cmake] Improve configuration tests for librt and libatomic
Modified: trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebFrameLoaderClient.cpp (218891 => 218892)
--- trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebFrameLoaderClient.cpp 2017-06-28 20:59:06 UTC (rev 218891)
+++ trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebFrameLoaderClient.cpp 2017-06-28 21:04:26 UTC (rev 218892)
@@ -812,6 +812,11 @@
WebCore::Frame* coreFrame = m_frame->coreFrame();
WebDocumentLoader* documentLoader = static_cast<WebDocumentLoader*>(coreFrame->loader().policyDocumentLoader());
+ if (!documentLoader) {
+ // FIXME: When we receive a redirect after the navigation policy has been decided for the initial request,
+ // the provisional load's DocumentLoader needs to receive navigation policy decisions. We need a better model for this state.
+ documentLoader = static_cast<WebDocumentLoader*>(coreFrame->loader().provisionalDocumentLoader());
+ }
if (!documentLoader)
documentLoader = static_cast<WebDocumentLoader*>(coreFrame->loader().documentLoader());
Modified: trunk/Tools/ChangeLog (218891 => 218892)
--- trunk/Tools/ChangeLog 2017-06-28 20:59:06 UTC (rev 218891)
+++ trunk/Tools/ChangeLog 2017-06-28 21:04:26 UTC (rev 218892)
@@ -1,3 +1,18 @@
+2017-06-28 Alex Christensen <[email protected]>
+
+ WebsitePolicies given with navigation policy for redirects should apply to the provisional document
+ https://bugs.webkit.org/show_bug.cgi?id=173886
+ <rdar://problem/32543191>
+
+ Reviewed by Andy Estes.
+
+ * TestWebKitAPI/Tests/WebKit2Cocoa/WebsitePolicies.mm:
+ (ParsedRange::ParsedRange):
+ (-[TestSchemeHandler initWithVideoData:]):
+ (-[TestSchemeHandler webView:startURLSchemeTask:]):
+ (-[TestSchemeHandler webView:stopURLSchemeTask:]):
+ (TEST):
+
2017-06-27 JF Bastien <[email protected]>
WebAssembly: running out of executable memory should throw OoM
Modified: trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/WebsitePolicies.mm (218891 => 218892)
--- trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/WebsitePolicies.mm 2017-06-28 20:59:06 UTC (rev 218891)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/WebsitePolicies.mm 2017-06-28 21:04:26 UTC (rev 218892)
@@ -29,6 +29,7 @@
#import "TestWKWebView.h"
#import <WebKit/WKPagePrivate.h>
#import <WebKit/WKPreferencesRefPrivate.h>
+#import <WebKit/WKURLSchemeTaskPrivate.h>
#import <WebKit/WKUserContentControllerPrivate.h>
#import <WebKit/WKWebViewPrivate.h>
#import <WebKit/_WKUserContentExtensionStorePrivate.h>
@@ -35,6 +36,7 @@
#import <WebKit/_WKWebsitePolicies.h>
#import <wtf/MainThread.h>
#import <wtf/RetainPtr.h>
+#import <wtf/text/WTFString.h>
#if PLATFORM(IOS)
#import <WebKit/WKWebViewConfigurationPrivate.h>
@@ -445,6 +447,111 @@
ASSERT_TRUE(*receivedAutoplayEventFlags & kWKAutoplayEventFlagsHasAudio);
}
+struct ParsedRange {
+ ParsedRange(String string)
+ {
+ // This is a strict and unsafe Range header parser adequate only for tests.
+ bool parsingMin = true;
+ size_t min = 0;
+ size_t max = 0;
+ ASSERT(string.length() > 6);
+ ASSERT(string.startsWith("bytes="));
+ for (size_t i = 6; i < string.length(); ++i) {
+ if (isASCIIDigit(string[i])) {
+ if (parsingMin)
+ min = min * 10 + string[i] - '0';
+ else
+ max = max * 10 + string[i] - '0';
+ } else if (string[i] == '-') {
+ if (parsingMin)
+ parsingMin = false;
+ else
+ return;
+ } else
+ return;
+ }
+ if (min <= max)
+ range = std::make_pair(min, max);
+ }
+ std::optional<std::pair<size_t, size_t>> range;
+};
+
+@interface TestSchemeHandler : NSObject <WKURLSchemeHandler>
+- (instancetype)initWithVideoData:(RetainPtr<NSData>&&)data;
+@end
+
+@implementation TestSchemeHandler {
+ RetainPtr<NSData> videoData;
+}
+
+- (instancetype)initWithVideoData:(RetainPtr<NSData>&&)data
+{
+ self = [super init];
+ if (!self)
+ return nil;
+
+ videoData = WTFMove(data);
+
+ return self;
+}
+
+- (void)webView:(WKWebView *)webView startURLSchemeTask:(id <WKURLSchemeTask>)task
+{
+ if ([task.request.URL.path isEqualToString:@"/should-redirect"]) {
+ [(id<WKURLSchemeTaskPrivate>)task _didPerformRedirection:[[[NSURLResponse alloc] initWithURL:task.request.URL MIMEType:nil expectedContentLength:0 textEncodingName:nil] autorelease] newRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"test:///autoplay-check.html"]]];
+
+ NSData *data = "" dataWithContentsOfURL:[[NSBundle mainBundle] URLForResource:@"autoplay-check" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"]];
+ [task didReceiveResponse:[[[NSURLResponse alloc] initWithURL:task.request.URL MIMEType:@"text/html" expectedContentLength:data.length textEncodingName:nil] autorelease]];
+ [task didReceiveData:data];
+ [task didFinish];
+ return;
+ }
+
+ ASSERT_TRUE([task.request.URL.path isEqualToString:@"/test.mp4"]);
+ ParsedRange parsedRange([task.request valueForHTTPHeaderField:@"Range"]);
+ ASSERT_TRUE(!!parsedRange.range);
+ auto& range = *parsedRange.range;
+
+ NSDictionary *headerFields = @{ @"Content-Length": [@(range.second - range.first) stringValue], @"Content-Range": [NSString stringWithFormat:@"bytes %lu-%lu/%lu", range.first, range.second, [videoData length]] };
+ NSURLResponse *response = [[[NSHTTPURLResponse alloc] initWithURL:task.request.URL statusCode:200 HTTPVersion:(NSString *)kCFHTTPVersion1_1 headerFields:headerFields] autorelease];
+ [task didReceiveResponse:response];
+ [task didReceiveData:[videoData subdataWithRange:NSMakeRange(range.first, range.second - range.first)]];
+ [task didFinish];
+
+}
+
+- (void)webView:(WKWebView *)webView stopURLSchemeTask:(id <WKURLSchemeTask>)task
+{
+}
+
+@end
+
+TEST(WebKit2, WebsitePoliciesDuringRedirect)
+{
+ auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
+ auto videoData = adoptNS([[NSData alloc] initWithContentsOfURL:[[NSBundle mainBundle] URLForResource:@"test" withExtension:@"mp4" subdirectory:@"TestWebKitAPI.resources"]]);
+ [configuration setURLSchemeHandler:[[[TestSchemeHandler alloc] initWithVideoData:WTFMove(videoData)] autorelease] forURLScheme:@"test"];
+ auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]);
+
+ auto delegate = adoptNS([[AutoplayPoliciesDelegate alloc] init]);
+ [delegate setAutoplayPolicyForURL:^(NSURL *url) {
+ if ([url.path isEqualToString:@"/should-redirect"])
+ return _WKWebsiteAutoplayPolicyDeny;
+ return _WKWebsiteAutoplayPolicyAllow;
+ }];
+ [webView setNavigationDelegate:delegate.get()];
+
+ WKPageUIClientV9 uiClient;
+ memset(&uiClient, 0, sizeof(uiClient));
+ uiClient.base.version = 9;
+ uiClient.handleAutoplayEvent = handleAutoplayEvent;
+
+ WKPageSetPageUIClient([webView _pageForTesting], &uiClient.base);
+
+ [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"test:///should-redirect"]]];
+ [webView waitForMessage:@"autoplayed"];
+}
+
TEST(WebKit2, WebsitePoliciesAutoplayQuirks)
{
auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes