Changeset 260962 in webkit
- Timestamp:
- Apr 30, 2020, 1:03:26 PM (5 years ago)
- Location:
- trunk
- Files:
-
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r260960 r260962 1 2020-04-30 Alex Christensen <achristensen@webkit.org> 2 3 Add SPI to change a WKWebView's CORS disabling pattern after initialization 4 https://bugs.webkit.org/show_bug.cgi?id=211211 5 <rdar://problem/61837474> 6 7 Reviewed by Chris Dumez. 8 9 * page/Page.h: 10 (WebCore::Page::setCORSDisablingPatterns): 11 1 12 2020-04-30 Chris Dumez <cdumez@apple.com> 2 13 -
trunk/Source/WebCore/page/Page.h
r260684 r260962 522 522 double customHTMLTokenizerTimeDelay() const; 523 523 524 void setCORSDisablingPatterns(Vector<UserContentURLPattern>&& patterns) { m_corsDisablingPatterns = WTFMove(patterns); } 525 524 526 WEBCORE_EXPORT void setMemoryCacheClientCallsEnabled(bool); 525 527 bool areMemoryCacheClientCallsEnabled() const { return m_areMemoryCacheClientCallsEnabled; } -
trunk/Source/WebKit/ChangeLog
r260952 r260962 1 2020-04-30 Alex Christensen <achristensen@webkit.org> 2 3 Add SPI to change a WKWebView's CORS disabling pattern after initialization 4 https://bugs.webkit.org/show_bug.cgi?id=211211 5 <rdar://problem/61837474> 6 7 Reviewed by Chris Dumez. 8 9 * UIProcess/API/Cocoa/WKWebView.mm: 10 (-[WKWebView _corsDisablingPatterns]): 11 (-[WKWebView _setCORSDisablingPatterns:]): 12 * UIProcess/API/Cocoa/WKWebViewPrivate.h: 13 * UIProcess/WebPageProxy.cpp: 14 * UIProcess/WebPageProxy.h: 15 (WebKit::WebPageProxy::corsDisablingPatterns const): 16 * WebProcess/WebPage/WebPage.cpp: 17 (WebKit::parseAndAllowAccessToCORSDisablingPatterns): 18 (WebKit::m_isNavigatingToAppBoundDomain): 19 (WebKit::WebPage::updateCORSDisablingPatterns): 20 * WebProcess/WebPage/WebPage.h: 21 * WebProcess/WebPage/WebPage.messages.in: 22 1 23 2020-04-30 Daniel Bates <dabates@apple.com> 2 24 -
trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm
r260865 r260962 2813 2813 } 2814 2814 2815 - (NSArray<NSString *> *)_corsDisablingPatterns 2816 { 2817 return createNSArray(_page->corsDisablingPatterns()).autorelease(); 2818 } 2819 2820 - (void)_setCORSDisablingPatterns:(NSArray<NSString *> *)patterns 2821 { 2822 _page->setCORSDisablingPatterns(makeVector<String>(patterns)); 2823 } 2824 2815 2825 - (void)_getProcessDisplayNameWithCompletionHandler:(void (^)(NSString *))completionHandler 2816 2826 { -
trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebViewPrivate.h
r260334 r260962 222 222 @property (nonatomic, setter=_setViewScale:) CGFloat _viewScale WK_API_AVAILABLE(macos(10.11), ios(9.0)); 223 223 224 @property (nonatomic, copy, setter=_setCORSDisablingPatterns:) NSArray<NSString *> *_corsDisablingPatterns WK_API_AVAILABLE(macos(WK_MAC_TBA), ios(WK_IOS_TBA)); 225 224 226 @property (nonatomic, setter=_setMinimumEffectiveDeviceWidth:) CGFloat _minimumEffectiveDeviceWidth WK_API_AVAILABLE(macos(10.14.4), ios(12.2)); 225 227 -
trunk/Source/WebKit/UIProcess/WebPageProxy.cpp
r260932 r260962 484 484 , m_resetRecentCrashCountTimer(RunLoop::main(), this, &WebPageProxy::resetRecentCrashCount) 485 485 , m_tryCloseTimeoutTimer(RunLoop::main(), this, &WebPageProxy::tryCloseTimedOut) 486 , m_corsDisablingPatterns(m_configuration->corsDisablingPatterns()) 486 487 #if PLATFORM(COCOA) 487 488 , m_ignoresAppBoundDomains(m_configuration->ignoresAppBoundDomains() || WTF::processHasEntitlement("com.apple.private.applemediaservices")) … … 7823 7824 7824 7825 parameters.overriddenMediaType = m_overriddenMediaType; 7825 parameters.corsDisablingPatterns = m_configuration->corsDisablingPatterns();7826 parameters.corsDisablingPatterns = corsDisablingPatterns(); 7826 7827 parameters.userScriptsShouldWaitUntilNotification = m_configuration->userScriptsShouldWaitUntilNotification(); 7827 7828 parameters.loadsFromNetwork = m_configuration->loadsFromNetwork(); … … 10086 10087 } 10087 10088 10089 void WebPageProxy::setCORSDisablingPatterns(Vector<String>&& patterns) 10090 { 10091 m_corsDisablingPatterns = WTFMove(patterns); 10092 send(Messages::WebPage::UpdateCORSDisablingPatterns(m_corsDisablingPatterns)); 10093 } 10094 10088 10095 void WebPageProxy::setOverriddenMediaType(const String& mediaType) 10089 10096 { -
trunk/Source/WebKit/UIProcess/WebPageProxy.h
r260857 r260962 1714 1714 void setOverriddenMediaType(const String&); 1715 1715 1716 void setCORSDisablingPatterns(Vector<String>&&); 1717 const Vector<String>& corsDisablingPatterns() const { return m_corsDisablingPatterns; } 1718 1716 1719 void getProcessDisplayName(CompletionHandler<void(String&&)>&&); 1717 1720 … … 2791 2794 String m_overriddenMediaType; 2792 2795 2796 Vector<String> m_corsDisablingPatterns; 2797 2793 2798 struct InjectedBundleMessage { 2794 2799 String messageName; -
trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp
r260932 r260962 394 394 } 395 395 396 static Vector<UserContentURLPattern> parseAndAllowAccessToCORSDisablingPatterns(Vector<String>&& input) 397 { 398 Vector<UserContentURLPattern> parsedPatterns; 399 parsedPatterns.reserveInitialCapacity(input.size()); 400 for (auto&& pattern : WTFMove(input)) { 401 UserContentURLPattern parsedPattern(WTFMove(pattern)); 402 if (parsedPattern.isValid()) { 403 WebCore::SecurityPolicy::allowAccessTo(parsedPattern); 404 parsedPatterns.uncheckedAppend(WTFMove(parsedPattern)); 405 } 406 } 407 parsedPatterns.shrinkToFit(); 408 return parsedPatterns; 409 } 410 396 411 WebPage::WebPage(PageIdentifier pageID, WebPageCreationParameters&& parameters) 397 412 : m_identifier(pageID) … … 531 546 pageConfiguration.deviceOrientationUpdateProvider = WebDeviceOrientationUpdateProvider::create(*this); 532 547 #endif 533 534 Vector<UserContentURLPattern> parsedPatterns;535 parsedPatterns.reserveInitialCapacity(parameters.corsDisablingPatterns.size());536 for (auto&& pattern : WTFMove(parameters.corsDisablingPatterns)) {537 UserContentURLPattern parsedPattern(WTFMove(pattern));538 if (parsedPattern.isValid()) {539 WebCore::SecurityPolicy::allowAccessTo(parsedPattern);540 parsedPatterns.uncheckedAppend(WTFMove(parsedPattern));541 }542 }543 parsedPatterns.shrinkToFit();544 548 545 pageConfiguration.corsDisablingPatterns = WTFMove(parsedPatterns);549 pageConfiguration.corsDisablingPatterns = parseAndAllowAccessToCORSDisablingPatterns(WTFMove(parameters.corsDisablingPatterns)); 546 550 pageConfiguration.userScriptsShouldWaitUntilNotification = parameters.userScriptsShouldWaitUntilNotification; 547 551 pageConfiguration.loadsSubresources = parameters.loadsSubresources; … … 7051 7055 } 7052 7056 7057 void WebPage::updateCORSDisablingPatterns(Vector<String>&& patterns) 7058 { 7059 if (m_page) 7060 m_page->setCORSDisablingPatterns(parseAndAllowAccessToCORSDisablingPatterns(WTFMove(patterns))); 7061 } 7062 7053 7063 bool WebPage::shouldUseRemoteRenderingFor(RenderingPurpose purpose) 7054 7064 { -
trunk/Source/WebKit/WebProcess/WebPage/WebPage.h
r260857 r260962 1302 1302 void setOverriddenMediaType(const String&); 1303 1303 1304 void updateCORSDisablingPatterns(Vector<String>&&); 1305 1304 1306 void getProcessDisplayName(CompletionHandler<void(String&&)>&&); 1305 1307 -
trunk/Source/WebKit/WebProcess/WebPage/WebPage.messages.in
r260857 r260962 602 602 GetProcessDisplayName() -> (String displayName) Async 603 603 604 UpdateCORSDisablingPatterns(Vector<String> patterns) 605 604 606 SetShouldFireEvents(bool shouldFireEvents) 605 607 SetNeedsDOMWindowResizeEvent() -
trunk/Tools/ChangeLog
r260961 r260962 1 2020-04-30 Alex Christensen <achristensen@webkit.org> 2 3 Add SPI to change a WKWebView's CORS disabling pattern after initialization 4 https://bugs.webkit.org/show_bug.cgi?id=211211 5 <rdar://problem/61837474> 6 7 Reviewed by Chris Dumez. 8 9 * TestWebKitAPI/Tests/WebKitCocoa/WKURLSchemeHandler-1.mm: 10 1 11 2020-04-30 Alex Christensen <achristensen@webkit.org> 2 12 -
trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKURLSchemeHandler-1.mm
r259772 r260962 849 849 [configuration setURLSchemeHandler:handler.get() forURLScheme:@"cors"]; 850 850 851 NSString *testJS = [NSString stringWithFormat: 852 @"fetch('http://127.0.0.1:%d/subresource').then(function(r){" 853 "r.json().then(function(object) {" 854 "if (object.testkey == 'testvalue') {" 855 "fetch('/corssuccess')" 856 "} else {" 857 "fetch('/corsfailure')" 858 "}" 859 "}).catch(function(){fetch('/corsfailure')})" 860 "}).catch(function(){fetch('/corsfailure')})" 861 , server.port()]; 862 851 863 [handler setStartURLSchemeTaskHandler:[&](WKWebView *, id<WKURLSchemeTask> task) { 852 864 if ([task.request.URL.path isEqualToString:@"/main.html"]) { 853 865 NSData *data = [[NSString stringWithFormat: 854 @"<script>" 855 "fetch('http://127.0.0.1:%d/subresource').then(function(r){" 856 "r.json().then(function(object) {" 857 "if (object.testkey == 'testvalue') {" 858 "fetch('/corssuccess')" 859 "} else {" 860 "fetch('/corsfailure')" 861 "}" 862 "}).catch(function(){fetch('/corsfailure')})" 863 "}).catch(function(){fetch('/corsfailure')})" 864 "</script>", server.port()] dataUsingEncoding:NSUTF8StringEncoding]; 866 @"<script>%@</script>", testJS] dataUsingEncoding:NSUTF8StringEncoding]; 865 867 [task didReceiveResponse:[[[NSURLResponse alloc] initWithURL:task.request.URL MIMEType:@"text/html" expectedContentLength:data.length textEncodingName:nil] autorelease]]; 866 868 [task didReceiveData:data]; … … 889 891 890 892 configuration._corsDisablingPatterns = @[@"*://*/*"]; 891 { 892 auto webView = adoptNS([[WKWebView alloc] initWithFrame:CGRectMake(0, 0, 800, 600) configuration:configuration]); 893 [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"cors://host1/main.html"]]]; 894 TestWebKitAPI::Util::run(&done); 895 } 893 auto webView = adoptNS([[WKWebView alloc] initWithFrame:CGRectMake(0, 0, 800, 600) configuration:configuration]); 894 [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"cors://host1/main.html"]]]; 895 TestWebKitAPI::Util::run(&done); 896 EXPECT_TRUE(corssuccess); 897 EXPECT_FALSE(corsfailure); 898 899 corssuccess = false; 900 corsfailure = false; 901 done = false; 902 903 webView.get()._corsDisablingPatterns = @[]; 904 [webView evaluateJavaScript:testJS completionHandler:nil]; 905 TestWebKitAPI::Util::run(&done); 906 EXPECT_FALSE(corssuccess); 907 EXPECT_TRUE(corsfailure); 908 909 corssuccess = false; 910 corsfailure = false; 911 done = false; 912 913 webView.get()._corsDisablingPatterns = @[@"*://*/*"]; 914 [webView evaluateJavaScript:testJS completionHandler:nil]; 915 TestWebKitAPI::Util::run(&done); 896 916 EXPECT_TRUE(corssuccess); 897 917 EXPECT_FALSE(corsfailure);
Note:
See TracChangeset
for help on using the changeset viewer.