Changeset 261727 in webkit


Ignore:
Timestamp:
May 14, 2020 6:21:20 PM (4 years ago)
Author:
Kate Cheney
Message:

Attribute non-network loads and loads with html strings as automatically app-bound
https://bugs.webkit.org/show_bug.cgi?id=211913
<rdar://problem/63157801

Reviewed by Brent Fulgham.

Source/WebKit:

Move logic from WebsiteDataStoreCocoa to WebPageProxy to check for
special app-bound protocols and set m_limitsNavigationToAppBoundDomains
to force these WebViews into app-bound mode.

  • UIProcess/API/Cocoa/WKWebView.mm:

(-[WKWebView _isForcedIntoAppBoundMode:]):

  • UIProcess/API/Cocoa/WKWebViewPrivate.h:

Testing SPI to see whether m_limitsNavigationsToAppBoundDomains was
set.

  • UIProcess/WebPageProxy.cpp:

(WebKit::WebPageProxy::loadData):
Check for html string loads and force WebView into app-bound mode if needed.
No need to worry about setting this variable even if the app hasn't
opted in because setIsNavigatingToAppBoundDomainAndCheckIfPermitted
does an early return before checking this variable if
WKAppBoundDomains does not exist.

(WebKit::shouldTreatURLProtocolAsAppBound):
Adds javascript protocols to this check.

(WebKit::WebPageProxy::setIsNavigatingToAppBoundDomainAndCheckIfPermitted):
Check for special protocols here and force WebView into app-bound mode.

(WebKit::WebPageProxy::isForcedIntoAppBoundModeTesting):

  • UIProcess/WebPageProxy.h:
  • UIProcess/WebsiteData/Cocoa/WebsiteDataStoreCocoa.mm:

(WebKit::WebsiteDataStore::beginAppBoundDomainCheck):
(WebKit::shouldTreatURLProtocolAsAppBound): Deleted.

Tools:

Adds new tests to check that WebView loads with HTML strings have
proper behavior.

Some tests need to test behavior on app-bound domains on webviews which do not specify
limitsNavigationsToAppBoundDomains. Since local files now do this
automatically, this patch updates those to use actual app-bound
domains from the WKAppBoundDomains list instead to maintain behavior.

Remove limitsNavigationsToAppBoundDomains for local files to make sure
they are forced into this mode automatically.

  • TestWebKitAPI/Tests/WebKitCocoa/InAppBrowserPrivacy.mm:

(-[InAppBrowserSchemeHandler webView:startURLSchemeTask:]):
(TEST):

Location:
trunk
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/ChangeLog

    r261726 r261727  
     12020-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
    1392020-05-14  Timothy Hatcher  <timothy@apple.com>
    240
  • trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm

    r261718 r261727  
    26222622}
    26232623
     2624- (void)_isForcedIntoAppBoundMode:(void(^)(BOOL))completionHandler
     2625{
     2626    _page->isForcedIntoAppBoundModeTesting([completionHandler = makeBlockPtr(completionHandler)] (bool isForcedIntoAppBoundMode) {
     2627        completionHandler(isForcedIntoAppBoundMode);
     2628    });
     2629}
     2630
    26242631- (void)_serviceWorkersEnabled:(void(^)(BOOL))completionHandler
    26252632{
  • trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebViewPrivate.h

    r261718 r261727  
    343343
    344344- (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));
    345346
    346347- (void)_grantAccessToPreferenceService WK_API_AVAILABLE(macos(WK_MAC_TBA), ios(WK_IOS_TBA));
  • trunk/Source/WebKit/UIProcess/WebPageProxy.cpp

    r261640 r261727  
    13921392    RELEASE_LOG_IF_ALLOWED(Loading, "loadData:");
    13931393
     1394    if (MIMEType == "text/html"_s && !WEB_PAGE_PROXY_ADDITIONS_SETISNAVIGATINGTOAPPBOUNDDOMAIN)
     1395        m_limitsNavigationsToAppBoundDomains = true;
     1396
    13941397    if (m_isClosed) {
    13951398        RELEASE_LOG_IF_ALLOWED(Loading, "loadData: page is closed");
     
    31123115};
    31133116
     3117#if PLATFORM(IOS_FAMILY)
     3118static bool shouldTreatURLProtocolAsAppBound(const URL& requestURL)
     3119{
     3120    return requestURL.protocolIsAbout() || requestURL.protocolIsData() || requestURL.protocolIsBlob() || requestURL.isLocalFile() || requestURL.protocolIsJavaScript();
     3121}
     3122#endif
     3123
    31143124bool WebPageProxy::setIsNavigatingToAppBoundDomainAndCheckIfPermitted(bool isMainFrame, const URL& requestURL, Optional<NavigatingToAppBoundDomain> isNavigatingToAppBoundDomain)
    31153125{
     
    31253135            return true;
    31263136       
     3137        if (shouldTreatURLProtocolAsAppBound(requestURL)) {
     3138            isNavigatingToAppBoundDomain = NavigatingToAppBoundDomain::Yes;
     3139            m_limitsNavigationsToAppBoundDomains = true;
     3140        }
    31273141        if (m_limitsNavigationsToAppBoundDomains) {
    31283142            if (*isNavigatingToAppBoundDomain == NavigatingToAppBoundDomain::No)
     
    31483162{
    31493163    completionHandler(m_isNavigatingToAppBoundDomain && (*m_isNavigatingToAppBoundDomain == NavigatingToAppBoundDomain::Yes));
     3164}
     3165
     3166void WebPageProxy::isForcedIntoAppBoundModeTesting(CompletionHandler<void(bool)>&& completionHandler)
     3167{
     3168    completionHandler(m_limitsNavigationsToAppBoundDomains);
    31503169}
    31513170
  • trunk/Source/WebKit/UIProcess/WebPageProxy.h

    r261640 r261727  
    17481748
    17491749    void isNavigatingToAppBoundDomainTesting(CompletionHandler<void(bool)>&&);
     1750    void isForcedIntoAppBoundModeTesting(CompletionHandler<void(bool)>&&);
     1751
    17501752    Optional<NavigatingToAppBoundDomain> isNavigatingToAppBoundDomain() const { return m_isNavigatingToAppBoundDomain; }
    17511753
  • trunk/Source/WebKit/UIProcess/WebsiteData/Cocoa/WebsiteDataStoreCocoa.mm

    r261242 r261727  
    460460}
    461461
    462 static bool shouldTreatURLProtocolAsAppBound(const URL& requestURL)
    463 {
    464     return requestURL.protocolIsAbout() || requestURL.protocolIsData() || requestURL.protocolIsBlob() || requestURL.isLocalFile();
    465 }
    466 
    467462void WebsiteDataStore::beginAppBoundDomainCheck(const URL& requestURL, WebFramePolicyListenerProxy& listener)
    468463{
     
    477472            return;
    478473        }
    479         if (shouldTreatURLProtocolAsAppBound(requestURL)) {
    480             listener->didReceiveAppBoundDomainResult(NavigatingToAppBoundDomain::Yes);
    481             return;
    482         }
    483474        listener->didReceiveAppBoundDomainResult(domains.contains(WebCore::RegistrableDomain(requestURL)) ? NavigatingToAppBoundDomain::Yes : NavigatingToAppBoundDomain::No);
    484475    });
  • trunk/Tools/ChangeLog

    r261723 r261727  
     12020-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
    1242020-05-14  Jiewen Tan  <jiewen_tan@apple.com>
    225
  • trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/InAppBrowserPrivacy.mm

    r261506 r261727  
    103103    else if ([task.request.URL.path isEqualToString:@"/in-app-browser-privacy-test-message-handler"])
    104104        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>";
    105107
    106108    [task didReceiveResponse:[[[NSURLResponse alloc] initWithURL:task.request.URL MIMEType:@"text/html" expectedContentLength:response.length textEncodingName:nil] autorelease]];
     
    273275    initializeInAppBrowserPrivacyTestSettings();
    274276    auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
    275     [configuration setLimitsNavigationsToAppBoundDomains:YES];
    276277
    277278    auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectZero configuration:configuration.get()]);
     
    281282
    282283    isDone = false;
    283     [webView _isNavigatingToAppBoundDomain:^(BOOL isAppBound) {
    284         EXPECT_TRUE(isAppBound);
     284    [webView _isForcedIntoAppBoundMode:^(BOOL isForcedIntoAppBoundMode) {
     285        EXPECT_TRUE(isForcedIntoAppBoundMode);
    285286        cleanUpInAppBrowserPrivacyTestSettings();
    286287        isDone = true;
     
    293294    initializeInAppBrowserPrivacyTestSettings();
    294295    auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
    295     [configuration setLimitsNavigationsToAppBoundDomains:YES];
    296296
    297297    auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectZero configuration:configuration.get()]);
     
    300300
    301301    isDone = false;
    302     [webView _isNavigatingToAppBoundDomain:^(BOOL isAppBound) {
    303         EXPECT_TRUE(isAppBound);
     302    [webView _isForcedIntoAppBoundMode:^(BOOL isForcedIntoAppBoundMode) {
     303        EXPECT_TRUE(isForcedIntoAppBoundMode);
    304304        cleanUpInAppBrowserPrivacyTestSettings();
    305305        isDone = true;
     
    312312    initializeInAppBrowserPrivacyTestSettings();
    313313    auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
    314     [configuration setLimitsNavigationsToAppBoundDomains:YES];
    315314
    316315    auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectZero configuration:configuration.get()]);
     
    319318
    320319    isDone = false;
    321     [webView _isNavigatingToAppBoundDomain:^(BOOL isAppBound) {
    322         EXPECT_TRUE(isAppBound);
     320    [webView _isForcedIntoAppBoundMode:^(BOOL isForcedIntoAppBoundMode) {
     321        EXPECT_TRUE(isForcedIntoAppBoundMode);
    323322        cleanUpInAppBrowserPrivacyTestSettings();
    324323        isDone = true;
     
    895894   
    896895    // 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"]];
    898897    [webView loadRequest:request];
    899898    [delegate waitForDidFinishNavigation];
     
    925924   
    926925    // 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"]];
    928927    [webView loadRequest:request];
    929928    [delegate waitForDidFinishNavigation];
     
    954953   
    955954    // 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"]];
    957956    [webView loadRequest:request];
    958957    [delegate waitForDidFinishNavigation];
     
    966965
    967966    // 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"]];
    969968    [webView loadRequest:request];
    970969    [delegate waitForDidFinishNavigation];
     
    10031002   
    10041003    // 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"]];
    10061005    [webView loadRequest:request];
    10071006    [delegate waitForDidFinishNavigation];
     
    10741073}
    10751074
     1075TEST(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
     1096TEST(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
     1123TEST(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
    10761151#endif // USE(APPLE_INTERNAL_SDK)
    10771152
Note: See TracChangeset for help on using the changeset viewer.