Changeset 218892 in webkit
- Timestamp:
- Jun 28, 2017, 2:04:26 PM (8 years ago)
- Location:
- trunk
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebKit2/ChangeLog
r218888 r218892 1 2017-06-28 Alex Christensen <achristensen@webkit.org> 2 3 WebsitePolicies given with navigation policy for redirects should apply to the provisional document 4 https://bugs.webkit.org/show_bug.cgi?id=173886 5 <rdar://problem/32543191> 6 7 Reviewed by Andy Estes. 8 9 If, for example, we deny video autoplay for the initial request but allow it for the redirect destination 10 location, the document should allow video autoplay. We were putting these settings onto the wrong DocumentLoader. 11 When a navigation policy is given to a response of a redirect location, we currently have the DocumentLoader 12 for the loading document in the FrameLoader's provisionalDocumentLoader, not the documentLoader. 13 14 Covered by a new API test. 15 16 * WebProcess/WebCoreSupport/WebFrameLoaderClient.cpp: 17 (WebKit::WebFrameLoaderClient::dispatchDecidePolicyForNavigationAction): 18 1 19 2017-06-28 Konstantin Tokarev <annulen@yandex.ru> 2 20 -
trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebFrameLoaderClient.cpp
r218775 r218892 813 813 WebCore::Frame* coreFrame = m_frame->coreFrame(); 814 814 WebDocumentLoader* documentLoader = static_cast<WebDocumentLoader*>(coreFrame->loader().policyDocumentLoader()); 815 if (!documentLoader) { 816 // FIXME: When we receive a redirect after the navigation policy has been decided for the initial request, 817 // the provisional load's DocumentLoader needs to receive navigation policy decisions. We need a better model for this state. 818 documentLoader = static_cast<WebDocumentLoader*>(coreFrame->loader().provisionalDocumentLoader()); 819 } 815 820 if (!documentLoader) 816 821 documentLoader = static_cast<WebDocumentLoader*>(coreFrame->loader().documentLoader()); -
trunk/Tools/ChangeLog
r218868 r218892 1 2017-06-28 Alex Christensen <achristensen@webkit.org> 2 3 WebsitePolicies given with navigation policy for redirects should apply to the provisional document 4 https://bugs.webkit.org/show_bug.cgi?id=173886 5 <rdar://problem/32543191> 6 7 Reviewed by Andy Estes. 8 9 * TestWebKitAPI/Tests/WebKit2Cocoa/WebsitePolicies.mm: 10 (ParsedRange::ParsedRange): 11 (-[TestSchemeHandler initWithVideoData:]): 12 (-[TestSchemeHandler webView:startURLSchemeTask:]): 13 (-[TestSchemeHandler webView:stopURLSchemeTask:]): 14 (TEST): 15 1 16 2017-06-27 JF Bastien <jfbastien@apple.com> 2 17 -
trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/WebsitePolicies.mm
r218229 r218892 30 30 #import <WebKit/WKPagePrivate.h> 31 31 #import <WebKit/WKPreferencesRefPrivate.h> 32 #import <WebKit/WKURLSchemeTaskPrivate.h> 32 33 #import <WebKit/WKUserContentControllerPrivate.h> 33 34 #import <WebKit/WKWebViewPrivate.h> … … 36 37 #import <wtf/MainThread.h> 37 38 #import <wtf/RetainPtr.h> 39 #import <wtf/text/WTFString.h> 38 40 39 41 #if PLATFORM(IOS) … … 446 448 } 447 449 450 struct ParsedRange { 451 ParsedRange(String string) 452 { 453 // This is a strict and unsafe Range header parser adequate only for tests. 454 bool parsingMin = true; 455 size_t min = 0; 456 size_t max = 0; 457 ASSERT(string.length() > 6); 458 ASSERT(string.startsWith("bytes=")); 459 for (size_t i = 6; i < string.length(); ++i) { 460 if (isASCIIDigit(string[i])) { 461 if (parsingMin) 462 min = min * 10 + string[i] - '0'; 463 else 464 max = max * 10 + string[i] - '0'; 465 } else if (string[i] == '-') { 466 if (parsingMin) 467 parsingMin = false; 468 else 469 return; 470 } else 471 return; 472 } 473 if (min <= max) 474 range = std::make_pair(min, max); 475 } 476 std::optional<std::pair<size_t, size_t>> range; 477 }; 478 479 @interface TestSchemeHandler : NSObject <WKURLSchemeHandler> 480 - (instancetype)initWithVideoData:(RetainPtr<NSData>&&)data; 481 @end 482 483 @implementation TestSchemeHandler { 484 RetainPtr<NSData> videoData; 485 } 486 487 - (instancetype)initWithVideoData:(RetainPtr<NSData>&&)data 488 { 489 self = [super init]; 490 if (!self) 491 return nil; 492 493 videoData = WTFMove(data); 494 495 return self; 496 } 497 498 - (void)webView:(WKWebView *)webView startURLSchemeTask:(id <WKURLSchemeTask>)task 499 { 500 if ([task.request.URL.path isEqualToString:@"/should-redirect"]) { 501 [(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"]]]; 502 503 NSData *data = [NSData dataWithContentsOfURL:[[NSBundle mainBundle] URLForResource:@"autoplay-check" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"]]; 504 [task didReceiveResponse:[[[NSURLResponse alloc] initWithURL:task.request.URL MIMEType:@"text/html" expectedContentLength:data.length textEncodingName:nil] autorelease]]; 505 [task didReceiveData:data]; 506 [task didFinish]; 507 return; 508 } 509 510 ASSERT_TRUE([task.request.URL.path isEqualToString:@"/test.mp4"]); 511 ParsedRange parsedRange([task.request valueForHTTPHeaderField:@"Range"]); 512 ASSERT_TRUE(!!parsedRange.range); 513 auto& range = *parsedRange.range; 514 515 NSDictionary *headerFields = @{ @"Content-Length": [@(range.second - range.first) stringValue], @"Content-Range": [NSString stringWithFormat:@"bytes %lu-%lu/%lu", range.first, range.second, [videoData length]] }; 516 NSURLResponse *response = [[[NSHTTPURLResponse alloc] initWithURL:task.request.URL statusCode:200 HTTPVersion:(NSString *)kCFHTTPVersion1_1 headerFields:headerFields] autorelease]; 517 [task didReceiveResponse:response]; 518 [task didReceiveData:[videoData subdataWithRange:NSMakeRange(range.first, range.second - range.first)]]; 519 [task didFinish]; 520 521 } 522 523 - (void)webView:(WKWebView *)webView stopURLSchemeTask:(id <WKURLSchemeTask>)task 524 { 525 } 526 527 @end 528 529 TEST(WebKit2, WebsitePoliciesDuringRedirect) 530 { 531 auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]); 532 auto videoData = adoptNS([[NSData alloc] initWithContentsOfURL:[[NSBundle mainBundle] URLForResource:@"test" withExtension:@"mp4" subdirectory:@"TestWebKitAPI.resources"]]); 533 [configuration setURLSchemeHandler:[[[TestSchemeHandler alloc] initWithVideoData:WTFMove(videoData)] autorelease] forURLScheme:@"test"]; 534 auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]); 535 536 auto delegate = adoptNS([[AutoplayPoliciesDelegate alloc] init]); 537 [delegate setAutoplayPolicyForURL:^(NSURL *url) { 538 if ([url.path isEqualToString:@"/should-redirect"]) 539 return _WKWebsiteAutoplayPolicyDeny; 540 return _WKWebsiteAutoplayPolicyAllow; 541 }]; 542 [webView setNavigationDelegate:delegate.get()]; 543 544 WKPageUIClientV9 uiClient; 545 memset(&uiClient, 0, sizeof(uiClient)); 546 uiClient.base.version = 9; 547 uiClient.handleAutoplayEvent = handleAutoplayEvent; 548 549 WKPageSetPageUIClient([webView _pageForTesting], &uiClient.base); 550 551 [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"test:///should-redirect"]]]; 552 [webView waitForMessage:@"autoplayed"]; 553 } 554 448 555 TEST(WebKit2, WebsitePoliciesAutoplayQuirks) 449 556 {
Note:
See TracChangeset
for help on using the changeset viewer.