Changeset 261727 in webkit
- Timestamp:
- May 14, 2020 6:21:20 PM (4 years ago)
- Location:
- trunk
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebKit/ChangeLog
r261726 r261727 1 2020-05-14 Kate Cheney <katherine_cheney@apple.com> 2 3 Attribute non-network loads and loads with html strings as automatically app-bound 4 https://bugs.webkit.org/show_bug.cgi?id=211913 5 <rdar://problem/63157801 6 7 Reviewed by Brent Fulgham. 8 9 Move logic from WebsiteDataStoreCocoa to WebPageProxy to check for 10 special app-bound protocols and set m_limitsNavigationToAppBoundDomains 11 to force these WebViews into app-bound mode. 12 13 * UIProcess/API/Cocoa/WKWebView.mm: 14 (-[WKWebView _isForcedIntoAppBoundMode:]): 15 * UIProcess/API/Cocoa/WKWebViewPrivate.h: 16 Testing SPI to see whether m_limitsNavigationsToAppBoundDomains was 17 set. 18 19 * UIProcess/WebPageProxy.cpp: 20 (WebKit::WebPageProxy::loadData): 21 Check for html string loads and force WebView into app-bound mode if needed. 22 No need to worry about setting this variable even if the app hasn't 23 opted in because setIsNavigatingToAppBoundDomainAndCheckIfPermitted 24 does an early return before checking this variable if 25 WKAppBoundDomains does not exist. 26 27 (WebKit::shouldTreatURLProtocolAsAppBound): 28 Adds javascript protocols to this check. 29 30 (WebKit::WebPageProxy::setIsNavigatingToAppBoundDomainAndCheckIfPermitted): 31 Check for special protocols here and force WebView into app-bound mode. 32 33 (WebKit::WebPageProxy::isForcedIntoAppBoundModeTesting): 34 * UIProcess/WebPageProxy.h: 35 * UIProcess/WebsiteData/Cocoa/WebsiteDataStoreCocoa.mm: 36 (WebKit::WebsiteDataStore::beginAppBoundDomainCheck): 37 (WebKit::shouldTreatURLProtocolAsAppBound): Deleted. 38 1 39 2020-05-14 Timothy Hatcher <timothy@apple.com> 2 40 -
trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm
r261718 r261727 2622 2622 } 2623 2623 2624 - (void)_isForcedIntoAppBoundMode:(void(^)(BOOL))completionHandler 2625 { 2626 _page->isForcedIntoAppBoundModeTesting([completionHandler = makeBlockPtr(completionHandler)] (bool isForcedIntoAppBoundMode) { 2627 completionHandler(isForcedIntoAppBoundMode); 2628 }); 2629 } 2630 2624 2631 - (void)_serviceWorkersEnabled:(void(^)(BOOL))completionHandler 2625 2632 { -
trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebViewPrivate.h
r261718 r261727 343 343 344 344 - (void)_isNavigatingToAppBoundDomain:(void(^)(BOOL))completionHandler WK_API_AVAILABLE(macos(WK_MAC_TBA), ios(WK_IOS_TBA)); 345 - (void)_isForcedIntoAppBoundMode:(void(^)(BOOL))completionHandler WK_API_AVAILABLE(macos(WK_MAC_TBA), ios(WK_IOS_TBA)); 345 346 346 347 - (void)_grantAccessToPreferenceService WK_API_AVAILABLE(macos(WK_MAC_TBA), ios(WK_IOS_TBA)); -
trunk/Source/WebKit/UIProcess/WebPageProxy.cpp
r261640 r261727 1392 1392 RELEASE_LOG_IF_ALLOWED(Loading, "loadData:"); 1393 1393 1394 if (MIMEType == "text/html"_s && !WEB_PAGE_PROXY_ADDITIONS_SETISNAVIGATINGTOAPPBOUNDDOMAIN) 1395 m_limitsNavigationsToAppBoundDomains = true; 1396 1394 1397 if (m_isClosed) { 1395 1398 RELEASE_LOG_IF_ALLOWED(Loading, "loadData: page is closed"); … … 3112 3115 }; 3113 3116 3117 #if PLATFORM(IOS_FAMILY) 3118 static bool shouldTreatURLProtocolAsAppBound(const URL& requestURL) 3119 { 3120 return requestURL.protocolIsAbout() || requestURL.protocolIsData() || requestURL.protocolIsBlob() || requestURL.isLocalFile() || requestURL.protocolIsJavaScript(); 3121 } 3122 #endif 3123 3114 3124 bool WebPageProxy::setIsNavigatingToAppBoundDomainAndCheckIfPermitted(bool isMainFrame, const URL& requestURL, Optional<NavigatingToAppBoundDomain> isNavigatingToAppBoundDomain) 3115 3125 { … … 3125 3135 return true; 3126 3136 3137 if (shouldTreatURLProtocolAsAppBound(requestURL)) { 3138 isNavigatingToAppBoundDomain = NavigatingToAppBoundDomain::Yes; 3139 m_limitsNavigationsToAppBoundDomains = true; 3140 } 3127 3141 if (m_limitsNavigationsToAppBoundDomains) { 3128 3142 if (*isNavigatingToAppBoundDomain == NavigatingToAppBoundDomain::No) … … 3148 3162 { 3149 3163 completionHandler(m_isNavigatingToAppBoundDomain && (*m_isNavigatingToAppBoundDomain == NavigatingToAppBoundDomain::Yes)); 3164 } 3165 3166 void WebPageProxy::isForcedIntoAppBoundModeTesting(CompletionHandler<void(bool)>&& completionHandler) 3167 { 3168 completionHandler(m_limitsNavigationsToAppBoundDomains); 3150 3169 } 3151 3170 -
trunk/Source/WebKit/UIProcess/WebPageProxy.h
r261640 r261727 1748 1748 1749 1749 void isNavigatingToAppBoundDomainTesting(CompletionHandler<void(bool)>&&); 1750 void isForcedIntoAppBoundModeTesting(CompletionHandler<void(bool)>&&); 1751 1750 1752 Optional<NavigatingToAppBoundDomain> isNavigatingToAppBoundDomain() const { return m_isNavigatingToAppBoundDomain; } 1751 1753 -
trunk/Source/WebKit/UIProcess/WebsiteData/Cocoa/WebsiteDataStoreCocoa.mm
r261242 r261727 460 460 } 461 461 462 static bool shouldTreatURLProtocolAsAppBound(const URL& requestURL)463 {464 return requestURL.protocolIsAbout() || requestURL.protocolIsData() || requestURL.protocolIsBlob() || requestURL.isLocalFile();465 }466 467 462 void WebsiteDataStore::beginAppBoundDomainCheck(const URL& requestURL, WebFramePolicyListenerProxy& listener) 468 463 { … … 477 472 return; 478 473 } 479 if (shouldTreatURLProtocolAsAppBound(requestURL)) {480 listener->didReceiveAppBoundDomainResult(NavigatingToAppBoundDomain::Yes);481 return;482 }483 474 listener->didReceiveAppBoundDomainResult(domains.contains(WebCore::RegistrableDomain(requestURL)) ? NavigatingToAppBoundDomain::Yes : NavigatingToAppBoundDomain::No); 484 475 }); -
trunk/Tools/ChangeLog
r261723 r261727 1 2020-05-14 Kate Cheney <katherine_cheney@apple.com> 2 3 Attribute non-network loads and loads with html strings as automatically app-bound 4 https://bugs.webkit.org/show_bug.cgi?id=211913 5 <rdar://problem/63157801 6 7 Reviewed by Brent Fulgham. 8 9 Adds new tests to check that WebView loads with HTML strings have 10 proper behavior. 11 12 Some tests need to test behavior on app-bound domains on webviews which do not specify 13 limitsNavigationsToAppBoundDomains. Since local files now do this 14 automatically, this patch updates those to use actual app-bound 15 domains from the WKAppBoundDomains list instead to maintain behavior. 16 17 Remove limitsNavigationsToAppBoundDomains for local files to make sure 18 they are forced into this mode automatically. 19 20 * TestWebKitAPI/Tests/WebKitCocoa/InAppBrowserPrivacy.mm: 21 (-[InAppBrowserSchemeHandler webView:startURLSchemeTask:]): 22 (TEST): 23 1 24 2020-05-14 Jiewen Tan <jiewen_tan@apple.com> 2 25 -
trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/InAppBrowserPrivacy.mm
r261506 r261727 103 103 else if ([task.request.URL.path isEqualToString:@"/in-app-browser-privacy-test-message-handler"]) 104 104 response = @"<body style='background-color: green;'></body><script>if (window.webkit.messageHandlers)\nwindow.webkit.messageHandlers.testHandler.postMessage('Failed'); \nelse \n document.body.style.background = 'red';</script>"; 105 else if ([task.request.URL.path isEqualToString:@"/app-bound-domain-load"]) 106 response = @"<body></body>"; 105 107 106 108 [task didReceiveResponse:[[[NSURLResponse alloc] initWithURL:task.request.URL MIMEType:@"text/html" expectedContentLength:response.length textEncodingName:nil] autorelease]]; … … 273 275 initializeInAppBrowserPrivacyTestSettings(); 274 276 auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]); 275 [configuration setLimitsNavigationsToAppBoundDomains:YES];276 277 277 278 auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectZero configuration:configuration.get()]); … … 281 282 282 283 isDone = false; 283 [webView _is NavigatingToAppBoundDomain:^(BOOL isAppBound) {284 EXPECT_TRUE(is AppBound);284 [webView _isForcedIntoAppBoundMode:^(BOOL isForcedIntoAppBoundMode) { 285 EXPECT_TRUE(isForcedIntoAppBoundMode); 285 286 cleanUpInAppBrowserPrivacyTestSettings(); 286 287 isDone = true; … … 293 294 initializeInAppBrowserPrivacyTestSettings(); 294 295 auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]); 295 [configuration setLimitsNavigationsToAppBoundDomains:YES];296 296 297 297 auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectZero configuration:configuration.get()]); … … 300 300 301 301 isDone = false; 302 [webView _is NavigatingToAppBoundDomain:^(BOOL isAppBound) {303 EXPECT_TRUE(is AppBound);302 [webView _isForcedIntoAppBoundMode:^(BOOL isForcedIntoAppBoundMode) { 303 EXPECT_TRUE(isForcedIntoAppBoundMode); 304 304 cleanUpInAppBrowserPrivacyTestSettings(); 305 305 isDone = true; … … 312 312 initializeInAppBrowserPrivacyTestSettings(); 313 313 auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]); 314 [configuration setLimitsNavigationsToAppBoundDomains:YES];315 314 316 315 auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectZero configuration:configuration.get()]); … … 319 318 320 319 isDone = false; 321 [webView _is NavigatingToAppBoundDomain:^(BOOL isAppBound) {322 EXPECT_TRUE(is AppBound);320 [webView _isForcedIntoAppBoundMode:^(BOOL isForcedIntoAppBoundMode) { 321 EXPECT_TRUE(isForcedIntoAppBoundMode); 323 322 cleanUpInAppBrowserPrivacyTestSettings(); 324 323 isDone = true; … … 895 894 896 895 // Navigate to an app-bound domain and expect a successful load. 897 NSURLRequest *request = [NSURLRequest requestWithURL:[ [NSBundle mainBundle] URLForResource:@"in-app-browser-privacy-local-file" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"]];896 NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"in-app-browser://apple.com/app-bound-domain-load"]]; 898 897 [webView loadRequest:request]; 899 898 [delegate waitForDidFinishNavigation]; … … 925 924 926 925 // Navigate to an app-bound domain and expect a successful load. 927 NSURLRequest *request = [NSURLRequest requestWithURL:[ [NSBundle mainBundle] URLForResource:@"in-app-browser-privacy-local-file" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"]];926 NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"in-app-browser://apple.com/app-bound-domain-load"]]; 928 927 [webView loadRequest:request]; 929 928 [delegate waitForDidFinishNavigation]; … … 954 953 955 954 // Navigate to an app-bound domain and expect a successful load. 956 NSURLRequest *request = [NSURLRequest requestWithURL:[ [NSBundle mainBundle] URLForResource:@"in-app-browser-privacy-local-file" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"]];955 NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"in-app-browser://apple.com/app-bound-domain-load"]]; 957 956 [webView loadRequest:request]; 958 957 [delegate waitForDidFinishNavigation]; … … 966 965 967 966 // Navigate to an non app-bound domain and expect a successful load. 968 request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"in-app-browser:// /in-app-browser-privacy-test-user-style-sheets"]];967 request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"in-app-browser://in-app-browser-privacy-test-user-style-sheets"]]; 969 968 [webView loadRequest:request]; 970 969 [delegate waitForDidFinishNavigation]; … … 1003 1002 1004 1003 // Navigate to an app-bound domain and expect a successful load. 1005 NSURLRequest *request = [NSURLRequest requestWithURL:[ [NSBundle mainBundle] URLForResource:@"in-app-browser-privacy-local-file" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"]];1004 NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"in-app-browser://apple.com/app-bound-domain-load"]]; 1006 1005 [webView loadRequest:request]; 1007 1006 [delegate waitForDidFinishNavigation]; … … 1074 1073 } 1075 1074 1075 TEST(InAppBrowserPrivacy, LoadFromHTMLStringsSucceedsIfAppBound) 1076 { 1077 initializeInAppBrowserPrivacyTestSettings(); 1078 isDone = false; 1079 1080 auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]); 1081 auto schemeHandler = adoptNS([[InAppBrowserSchemeHandler alloc] init]); 1082 [configuration setURLSchemeHandler:schemeHandler.get() forURLScheme:@"in-app-browser"]; 1083 1084 auto delegate = adoptNS([AppBoundDomainDelegate new]); 1085 1086 NSString *HTML = @"<html><head></head><body><img src='in-app-browser:///in-app-browser-privacy-test-user-style-sheets/'></img></body></html>"; 1087 auto webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]); 1088 [webView setNavigationDelegate:delegate.get()]; 1089 1090 [webView loadHTMLString:HTML baseURL:[NSURL URLWithString:@"in-app-browser://apple.com/"]]; 1091 [delegate waitForDidFinishNavigation]; 1092 1093 cleanUpInAppBrowserPrivacyTestSettings(); 1094 } 1095 1096 TEST(InAppBrowserPrivacy, LoadFromHTMLStringNoBaseURLIsAppBound) 1097 { 1098 initializeInAppBrowserPrivacyTestSettings(); 1099 isDone = false; 1100 1101 auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]); 1102 auto schemeHandler = adoptNS([[InAppBrowserSchemeHandler alloc] init]); 1103 [configuration setURLSchemeHandler:schemeHandler.get() forURLScheme:@"in-app-browser"]; 1104 1105 auto delegate = adoptNS([AppBoundDomainDelegate new]); 1106 1107 NSString *HTML = @"<html><head></head><body><img src='in-app-browser:///in-app-browser-privacy-test-user-style-sheets/'></img></body></html>"; 1108 auto webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]); 1109 [webView setNavigationDelegate:delegate.get()]; 1110 1111 [webView loadHTMLString:HTML baseURL:nil]; 1112 [delegate waitForDidFinishNavigation]; 1113 1114 isDone = false; 1115 [webView _isForcedIntoAppBoundMode:^(BOOL isForcedIntoAppBoundMode) { 1116 EXPECT_TRUE(isForcedIntoAppBoundMode); 1117 cleanUpInAppBrowserPrivacyTestSettings(); 1118 isDone = true; 1119 }]; 1120 TestWebKitAPI::Util::run(&isDone); 1121 } 1122 1123 TEST(InAppBrowserPrivacy, LoadFromHTMLStringsFailsIfNotAppBound) 1124 { 1125 initializeInAppBrowserPrivacyTestSettings(); 1126 isDone = false; 1127 1128 auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]); 1129 auto schemeHandler = adoptNS([[InAppBrowserSchemeHandler alloc] init]); 1130 [configuration setURLSchemeHandler:schemeHandler.get() forURLScheme:@"in-app-browser"]; 1131 1132 auto delegate = adoptNS([AppBoundDomainDelegate new]); 1133 1134 NSString *HTML = @"<html><head></head><body><img src='in-app-browser:///in-app-browser-privacy-test-user-style-sheets/'></img></body></html>"; 1135 auto webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]); 1136 [webView setNavigationDelegate:delegate.get()]; 1137 1138 [webView loadHTMLString:HTML baseURL:[NSURL URLWithString:@"in-app-browser:///in-app-browser-privacy-test-user-agent-script"]]; 1139 NSError *error = [delegate waitForDidFailProvisionalNavigationError]; 1140 EXPECT_WK_STREQ(error.localizedDescription, @"App-bound domain failure"); 1141 1142 isDone = false; 1143 [webView _isForcedIntoAppBoundMode:^(BOOL isForcedIntoAppBoundMode) { 1144 EXPECT_TRUE(isForcedIntoAppBoundMode); 1145 cleanUpInAppBrowserPrivacyTestSettings(); 1146 isDone = true; 1147 }]; 1148 TestWebKitAPI::Util::run(&isDone); 1149 } 1150 1076 1151 #endif // USE(APPLE_INTERNAL_SDK) 1077 1152
Note: See TracChangeset
for help on using the changeset viewer.