Changeset 260408 in webkit


Ignore:
Timestamp:
Apr 20, 2020 7:36:27 PM (4 years ago)
Author:
Kate Cheney
Message:

App-bound domain behavior should abide by the limitsNavigationsToAppBoundDomains argument in WKWebView configuration
https://bugs.webkit.org/show_bug.cgi?id=210769
<rdar://problem/62065241>

Reviewed by Brent Fulgham.

Source/WebKit:

Changes app-bound domain behavior to be triggered by the value of
limitsNavigationsToAppBoundDomains, a WebView configuration flag.
If the WebView has this parameter set and is currently navigating to
an app bound domain, then app-bound privileges will be granted.

  • UIProcess/WebPageProxy.cpp:

(WebKit::WebPageProxy::setIsNavigatingToAppBoundDomainAndCheckIfPermitted):
Update this function to return a boolean to indicate whether the
navigation should fail. A failure should occur if a WebView has set
the limitsNavigationsToAppBoundDomains flag and attempts to navigate
away from an app-bound domain.

If the limitsNavigationsToAppBoundDomains value has not been set to
true, maintain non-app bound behavior regardless of whether the domain
is app-bound or not.

(WebKit::WebPageProxy::decidePolicyForNavigationAction):
Check the result of setIsNavigatingToAppBoundDomainAndCheckIfPermitted and fail the
navigation if needed, with both RELEASE logging and an appropriate
error message.

(WebKit::WebPageProxy::setIsNavigatingToAppBoundDomain): Deleted.

  • UIProcess/WebPageProxy.h:

Renamed for clarity.

Tools:

Removes any tests for swapping between app-bound and non app-bound
domains as this behavior is no longer supported.

Sets the limitsNavigationsToAppBoundDomains flag for tests which should
have app-bound behavior to maintain test functionality.

Adds 5 new tests for new behavior.

  • TestWebKitAPI/Tests/WebKitCocoa/InAppBrowserPrivacy.mm:

(TEST):
(-[AppBoundDomainDelegate webView:didFinishNavigation:]):
(-[AppBoundDomainDelegate webView:didFailProvisionalNavigation:withError:]):
(-[AppBoundDomainDelegate waitForDidFinishNavigation]):
(-[AppBoundDomainDelegate waitForDidFailProvisionalNavigationError]):

Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/ChangeLog

    r260407 r260408  
     12020-04-20  Kate Cheney  <katherine_cheney@apple.com>
     2
     3        App-bound domain behavior should abide by the limitsNavigationsToAppBoundDomains argument in WKWebView configuration
     4        https://bugs.webkit.org/show_bug.cgi?id=210769
     5        <rdar://problem/62065241>
     6
     7        Reviewed by Brent Fulgham.
     8
     9        Changes app-bound domain behavior to be triggered by the value of
     10        limitsNavigationsToAppBoundDomains, a WebView configuration flag.
     11        If the WebView has this parameter set and is currently navigating to
     12        an app bound domain, then app-bound privileges will be granted.
     13
     14        * UIProcess/WebPageProxy.cpp:
     15        (WebKit::WebPageProxy::setIsNavigatingToAppBoundDomainAndCheckIfPermitted):
     16        Update this function to return a boolean to indicate whether the
     17        navigation should fail. A failure should occur if a WebView has set
     18        the limitsNavigationsToAppBoundDomains flag and attempts to navigate
     19        away from an app-bound domain.
     20
     21        If the limitsNavigationsToAppBoundDomains value has not been set to
     22        true, maintain non-app bound behavior regardless of whether the domain
     23        is app-bound or not.
     24
     25        (WebKit::WebPageProxy::decidePolicyForNavigationAction):
     26        Check the result of setIsNavigatingToAppBoundDomainAndCheckIfPermitted and fail the
     27        navigation if needed, with both RELEASE logging and an appropriate
     28        error message.
     29
     30        (WebKit::WebPageProxy::setIsNavigatingToAppBoundDomain): Deleted.
     31        * UIProcess/WebPageProxy.h:
     32        Renamed for clarity.
     33
    1342020-04-20  Nikos Mouchtaris  <nmouchtaris@apple.com>
    235
  • trunk/Source/WebKit/UIProcess/WebPageProxy.cpp

    r260407 r260408  
    31283128};
    31293129
    3130 void WebPageProxy::setIsNavigatingToAppBoundDomain(bool isMainFrame, const URL& requestURL, Optional<NavigatingToAppBoundDomain> isNavigatingToAppBoundDomain)
     3130bool WebPageProxy::setIsNavigatingToAppBoundDomainAndCheckIfPermitted(bool isMainFrame, const URL& requestURL, Optional<NavigatingToAppBoundDomain> isNavigatingToAppBoundDomain)
    31313131{
    31323132#if PLATFORM(IOS_FAMILY)
    31333133    if (isMainFrame) {
    31343134        if (WEB_PAGE_PROXY_ADDITIONS_SETISNAVIGATINGTOAPPBOUNDDOMAIN)
    3135             return;
     3135            return true;
    31363136        if (!isNavigatingToAppBoundDomain) {
    31373137            m_isNavigatingToAppBoundDomain = WTF::nullopt;
    3138             return;
     3138            return true;
    31393139        }
    31403140        if (m_ignoresAppBoundDomains)
    3141             return;
    3142         if (*isNavigatingToAppBoundDomain == NavigatingToAppBoundDomain::No) {
     3141            return true;
     3142       
     3143        if (m_limitsNavigationsToAppBoundDomains) {
     3144            if (*isNavigatingToAppBoundDomain == NavigatingToAppBoundDomain::No)
     3145                return false;
     3146            m_configuration->setWebViewCategory(WebViewCategory::AppBoundDomain);
     3147            m_isNavigatingToAppBoundDomain = NavigatingToAppBoundDomain::Yes;
     3148        } else {
    31433149            m_configuration->setWebViewCategory(WebViewCategory::InAppBrowser);
    31443150            m_isNavigatingToAppBoundDomain = NavigatingToAppBoundDomain::No;
    31453151            m_hasNavigatedAwayFromAppBoundDomain = NavigatedAwayFromAppBoundDomain::Yes;
    3146             return;
    31473152        }
    3148         m_configuration->setWebViewCategory(WebViewCategory::AppBoundDomain);
    3149         m_isNavigatingToAppBoundDomain = NavigatingToAppBoundDomain::Yes;
    31503153    }
    31513154#else
     
    31543157    UNUSED_PARAM(isNavigatingToAppBoundDomain);
    31553158#endif
     3159    return true;
    31563160}
    31573161
     
    51565160#endif
    51575161   
    5158     auto listener = makeRef(frame.setUpPolicyListenerProxy([this, protectedThis = makeRef(*this), frame = makeRef(frame), sender = WTFMove(sender), navigation] (PolicyAction policyAction, API::WebsitePolicies* policies, ProcessSwapRequestedByClient processSwapRequestedByClient, RefPtr<SafeBrowsingWarning>&& safeBrowsingWarning, Optional<NavigatingToAppBoundDomain> isAppBoundDomain) mutable {
    5159 
    5160         if (policyAction != PolicyAction::Ignore)
    5161             setIsNavigatingToAppBoundDomain(frame->isMainFrame(), navigation->currentRequest().url(), isAppBoundDomain);
     5162    auto listener = makeRef(frame.setUpPolicyListenerProxy([this, protectedThis = makeRef(*this), frame = makeRef(frame), sender = WTFMove(sender), navigation, frameInfo, userDataObject = process->transformHandlesToObjects(userData.object()).get()] (PolicyAction policyAction, API::WebsitePolicies* policies, ProcessSwapRequestedByClient processSwapRequestedByClient, RefPtr<SafeBrowsingWarning>&& safeBrowsingWarning, Optional<NavigatingToAppBoundDomain> isAppBoundDomain) mutable {
    51625163
    51635164        auto completionHandler = [this, protectedThis = protectedThis.copyRef(), frame = frame.copyRef(), sender = WTFMove(sender), navigation, processSwapRequestedByClient, policies = makeRefPtr(policies)] (PolicyAction policyAction) mutable {
     
    51725173            receivedNavigationPolicyDecision(policyAction, navigation.get(), processSwapRequestedByClient, frame, WTFMove(policies), WTFMove(sender));
    51735174        };
     5175       
     5176        if (policyAction != PolicyAction::Ignore) {
     5177            if (!setIsNavigatingToAppBoundDomainAndCheckIfPermitted(frame->isMainFrame(), navigation->currentRequest().url(), isAppBoundDomain)) {
     5178                auto error = ResourceError { String { }, 0, navigation->currentRequest().url(), "Attempted navigation away from app-bound domain"_s };
     5179                m_navigationClient->didFailProvisionalNavigationWithError(*this, FrameInfoData { frameInfo }, navigation.get(), error, userDataObject);
     5180                RELEASE_LOG_ERROR_IF_ALLOWED(Loading, "Ignoring request to load this main resource because it is attempting to navigate away from an app-bound domain");
     5181                completionHandler(PolicyAction::Ignore);
     5182                return;
     5183            }
     5184        }
    51745185
    51755186        if (!m_pageClient)
  • trunk/Source/WebKit/UIProcess/WebPageProxy.h

    r260407 r260408  
    23122312    void makeStorageSpaceRequest(WebCore::FrameIdentifier, const String& originIdentifier, const String& databaseName, const String& displayName, uint64_t currentQuota, uint64_t currentOriginUsage, uint64_t currentDatabaseUsage, uint64_t expectedUsage, CompletionHandler<void(uint64_t)>&&);
    23132313       
    2314     void setIsNavigatingToAppBoundDomain(bool isMainFrame, const URL&, Optional<NavigatingToAppBoundDomain>);
     2314    bool setIsNavigatingToAppBoundDomainAndCheckIfPermitted(bool isMainFrame, const URL&, Optional<NavigatingToAppBoundDomain>);
    23152315    NavigatedAwayFromAppBoundDomain hasNavigatedAwayFromAppBoundDomain() const { return m_hasNavigatedAwayFromAppBoundDomain; }
    23162316       
  • trunk/Tools/ChangeLog

    r260402 r260408  
     12020-04-20  Kate Cheney  <katherine_cheney@apple.com>
     2
     3        App-bound domain behavior should abide by the limitsNavigationsToAppBoundDomains argument in WKWebView configuration
     4        https://bugs.webkit.org/show_bug.cgi?id=210769
     5        <rdar://problem/62065241>
     6
     7        Reviewed by Brent Fulgham.
     8
     9        Removes any tests for swapping between app-bound and non app-bound
     10        domains as this behavior is no longer supported.
     11
     12        Sets the limitsNavigationsToAppBoundDomains flag for tests which should
     13        have app-bound behavior to maintain test functionality.
     14
     15        Adds 5 new tests for new behavior.
     16
     17        * TestWebKitAPI/Tests/WebKitCocoa/InAppBrowserPrivacy.mm:
     18        (TEST):
     19        (-[AppBoundDomainDelegate webView:didFinishNavigation:]):
     20        (-[AppBoundDomainDelegate webView:didFailProvisionalNavigation:withError:]):
     21        (-[AppBoundDomainDelegate waitForDidFinishNavigation]):
     22        (-[AppBoundDomainDelegate waitForDidFailProvisionalNavigationError]):
     23
    1242020-04-20  Megan Gardner  <megan_gardner@apple.com>
    225
  • trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/InAppBrowserPrivacy.mm

    r260366 r260408  
    221221}
    222222
    223 TEST(InAppBrowserPrivacy, SwapBackToAppBoundRejectsUserScript)
    224 {
    225     initializeInAppBrowserPrivacyTestSettings();
    226     auto userScript = adoptNS([[WKUserScript alloc] initWithSource:userScriptSource injectionTime:WKUserScriptInjectionTimeAtDocumentStart forMainFrameOnly:YES]);
    227 
    228     WKWebViewConfiguration *configuration = [WKWebViewConfiguration _test_configurationWithTestPlugInClassName:@"WebProcessPlugInWithInternals" configureJSCForTesting:YES];
    229     [[configuration preferences] _setNeedsInAppBrowserPrivacyQuirks:NO];
    230     [[configuration preferences] _setInAppBrowserPrivacyEnabled:YES];
    231 
    232     auto schemeHandler = adoptNS([[InAppBrowserSchemeHandler alloc] init]);
    233     [configuration setURLSchemeHandler:schemeHandler.get() forURLScheme:@"in-app-browser"];
    234    
    235     auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectZero configuration:configuration]);
    236     NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"in-app-browser:///in-app-browser-privacy-test-user-script"]];
    237     [webView loadRequest:request];
    238     [webView _test_waitForDidFinishNavigation];
    239 
    240     [configuration.userContentController _addUserScriptImmediately:userScript.get()];
    241     [webView evaluateJavaScript:@"window.wkUserScriptInjected" completionHandler:^(id _Nullable result, NSError * _Nullable error) {
    242         EXPECT_FALSE(result);
    243         EXPECT_TRUE(!!error);
    244         isDone = true;
    245     }];
    246 
    247     isDone = false;
    248     TestWebKitAPI::Util::run(&isDone);
    249 
    250     request = [NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@"in-app-browser-privacy-local-file" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"]];
    251     [webView loadRequest:request];
    252     [webView _test_waitForDidFinishNavigation];
    253    
    254     isDone = false;
    255     [configuration.userContentController _addUserScriptImmediately:userScript.get()];
    256     [webView evaluateJavaScript:@"window.wkUserScriptInjected" completionHandler:^(id _Nullable result, NSError * _Nullable error) {
    257         EXPECT_FALSE(result);
    258         EXPECT_TRUE(!!error);
    259         cleanUpInAppBrowserPrivacyTestSettings();
    260         isDone = true;
    261     }];
    262 
    263     TestWebKitAPI::Util::run(&isDone);
    264 }
    265 
    266223TEST(InAppBrowserPrivacy, AppBoundDomains)
    267224{
     
    289246    auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
    290247    [[configuration preferences] _setInAppBrowserPrivacyEnabled:YES];
     248    [configuration setLimitsNavigationsToAppBoundDomains:YES];
    291249
    292250    auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectZero configuration:configuration.get()]);
     
    309267    auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
    310268    [[configuration preferences] _setInAppBrowserPrivacyEnabled:YES];
     269    [configuration setLimitsNavigationsToAppBoundDomains:YES];
    311270
    312271    auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectZero configuration:configuration.get()]);
     
    328287    auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
    329288    [[configuration preferences] _setInAppBrowserPrivacyEnabled:YES];
     289    [configuration setLimitsNavigationsToAppBoundDomains:YES];
    330290
    331291    auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectZero configuration:configuration.get()]);
     
    346306static NSString *frameBackgroundColorScript = @"window.getComputedStyle(document.getElementsByTagName('iframe')[0].contentDocument.body, null).getPropertyValue('background-color')";
    347307static const char* redInRGB = "rgb(255, 0, 0)";
     308static const char* blackInRGB = "rgba(0, 0, 0, 0)";
    348309
    349310static void expectScriptEvaluatesToColor(WKWebView *webView, NSString *script, const char* color)
     
    459420}
    460421
    461 TEST(InAppBrowserPrivacy, AppBoundToNonAppBoundDomainCannotAccessMessageHandlers)
     422TEST(InAppBrowserPrivacy, AppBoundDomainCanAccessMessageHandlers)
    462423{
    463424    initializeInAppBrowserPrivacyTestSettings();
     
    469430    [configuration setURLSchemeHandler:schemeHandler.get() forURLScheme:@"in-app-browser"];
    470431    [[configuration preferences] _setInAppBrowserPrivacyEnabled:YES];
     432    [configuration setLimitsNavigationsToAppBoundDomains:YES];
    471433
    472434    auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectZero configuration:configuration.get()]);
     
    487449    }];
    488450
    489     // Navigate away from an app-bound domain.
    490     NSURLRequest *request2 = [NSURLRequest requestWithURL:[NSURL URLWithString:@"in-app-browser:///in-app-browser-privacy-test-message-handler"]];
    491     [webView loadRequest:request2];
    492     [webView _test_waitForDidFinishNavigation];
    493 
    494     // Set the background color to red if message handlers returned null so we can
    495     // check without needing a message handler.
    496     expectScriptEvaluatesToColor(webView.get(), backgroundColorScript, redInRGB);
    497451    cleanUpInAppBrowserPrivacyTestSettings();
    498452}
     
    876830}
    877831
     832@interface AppBoundDomainDelegate : NSObject <WKNavigationDelegate>
     833- (void)waitForDidFinishNavigation;
     834- (NSError *)waitForDidFailProvisionalNavigationError;
     835@end
     836
     837@implementation AppBoundDomainDelegate {
     838    bool _navigationFinished;
     839    RetainPtr<NSError> _provisionalNavigationFailedError;
     840}
     841
     842- (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation
     843{
     844    _navigationFinished = true;
     845}
     846
     847- (void)webView:(WKWebView *)webView didFailProvisionalNavigation:(null_unspecified WKNavigation *)navigation withError:(NSError *)error
     848{
     849    _provisionalNavigationFailedError = error;
     850}
     851
     852- (void)waitForDidFinishNavigation
     853{
     854    TestWebKitAPI::Util::run(&_navigationFinished);
     855}
     856
     857- (NSError *)waitForDidFailProvisionalNavigationError
     858{
     859    while (!_provisionalNavigationFailedError)
     860        TestWebKitAPI::Util::spinRunLoop();
     861    return _provisionalNavigationFailedError.autorelease();
     862}
     863
     864@end
     865
     866TEST(InAppBrowserPrivacy, AppBoundFlagForNonAppBoundDomainFails)
     867{
     868    initializeInAppBrowserPrivacyTestSettings();
     869    isDone = false;
     870
     871    auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
     872    auto schemeHandler = adoptNS([[InAppBrowserSchemeHandler alloc] init]);
     873    [configuration setURLSchemeHandler:schemeHandler.get() forURLScheme:@"in-app-browser"];
     874    [configuration setLimitsNavigationsToAppBoundDomains:YES];
     875
     876    auto webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]);
     877    auto delegate = adoptNS([AppBoundDomainDelegate new]);
     878    [webView setNavigationDelegate:delegate.get()];
     879
     880    // Load a non-app bound domain.
     881    NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"in-app-browser:///in-app-browser-privacy-test-user-style-sheets"]];
     882    [webView loadRequest:request];
     883    NSError *error = [delegate waitForDidFailProvisionalNavigationError];
     884    EXPECT_WK_STREQ(error.localizedDescription, @"Attempted navigation away from app-bound domain");
     885
     886    // Make sure the load didn't complete by checking the background color.
     887    // Red would indicate it finished loading.
     888    expectScriptEvaluatesToColor(webView.get(), backgroundColorScript, blackInRGB);
     889    cleanUpInAppBrowserPrivacyTestSettings();
     890}
     891
     892TEST(InAppBrowserPrivacy, NavigateAwayFromAppBoundDomainWithAppBoundFlagFails)
     893{
     894    initializeInAppBrowserPrivacyTestSettings();
     895    isDone = false;
     896
     897    auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
     898    auto schemeHandler = adoptNS([[InAppBrowserSchemeHandler alloc] init]);
     899    [configuration setURLSchemeHandler:schemeHandler.get() forURLScheme:@"in-app-browser"];
     900    [configuration setLimitsNavigationsToAppBoundDomains:YES];
     901
     902    auto webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]);
     903    auto delegate = adoptNS([AppBoundDomainDelegate new]);
     904    [webView setNavigationDelegate:delegate.get()];
     905   
     906    // Navigate to an app-bound domain and expect a successful load.
     907    NSURLRequest *request = [NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@"in-app-browser-privacy-local-file" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"]];
     908    [webView loadRequest:request];
     909    [delegate waitForDidFinishNavigation];
     910   
     911    // Now try to load a non-app bound domain and make sure it fails.
     912    request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"in-app-browser:///in-app-browser-privacy-test-user-style-sheets"]];
     913    [webView loadRequest:request];
     914    NSError *error = [delegate waitForDidFailProvisionalNavigationError];
     915    EXPECT_WK_STREQ(error.localizedDescription, @"Attempted navigation away from app-bound domain");
     916
     917    // Make sure the load didn't complete by checking the background color.
     918    // Red would indicate it finished loading.
     919    expectScriptEvaluatesToColor(webView.get(), backgroundColorScript, blackInRGB);
     920    cleanUpInAppBrowserPrivacyTestSettings();
     921}
     922
     923TEST(InAppBrowserPrivacy, AppBoundDomainWithoutFlagTreatedAsNonAppBound)
     924{
     925    initializeInAppBrowserPrivacyTestSettings();
     926    isDone = false;
     927
     928    auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
     929    auto schemeHandler = adoptNS([[InAppBrowserSchemeHandler alloc] init]);
     930    [configuration setURLSchemeHandler:schemeHandler.get() forURLScheme:@"in-app-browser"];
     931
     932    auto webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]);
     933    auto delegate = adoptNS([AppBoundDomainDelegate new]);
     934    [webView setNavigationDelegate:delegate.get()];
     935   
     936    // Navigate to an app-bound domain and expect a successful load.
     937    NSURLRequest *request = [NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@"in-app-browser-privacy-local-file" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"]];
     938    [webView loadRequest:request];
     939    [delegate waitForDidFinishNavigation];
     940
     941    // But the navigation should not have been considered app-bound because the WebView configuration
     942    // specification was not set.
     943    isDone = false;
     944    [webView _isNavigatingToAppBoundDomain:^(BOOL isAppBound) {
     945        EXPECT_FALSE(isAppBound);
     946        cleanUpInAppBrowserPrivacyTestSettings();
     947        isDone = true;
     948    }];
     949    TestWebKitAPI::Util::run(&isDone);
     950}
     951
     952TEST(InAppBrowserPrivacy, WebViewWithoutAppBoundFlagCanFreelyNavigate)
     953{
     954    initializeInAppBrowserPrivacyTestSettings();
     955    isDone = false;
     956
     957    auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
     958    auto schemeHandler = adoptNS([[InAppBrowserSchemeHandler alloc] init]);
     959    [configuration setURLSchemeHandler:schemeHandler.get() forURLScheme:@"in-app-browser"];
     960
     961    auto webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]);
     962    auto delegate = adoptNS([AppBoundDomainDelegate new]);
     963    [webView setNavigationDelegate:delegate.get()];
     964   
     965    // Navigate to an app-bound domain and expect a successful load.
     966    NSURLRequest *request = [NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@"in-app-browser-privacy-local-file" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"]];
     967    [webView loadRequest:request];
     968    [delegate waitForDidFinishNavigation];
     969
     970    isDone = false;
     971    [webView _isNavigatingToAppBoundDomain:^(BOOL isAppBound) {
     972        EXPECT_FALSE(isAppBound);
     973        isDone = true;
     974    }];
     975    TestWebKitAPI::Util::run(&isDone);
     976
     977    // Navigate to an non app-bound domain and expect a successful load.
     978    request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"in-app-browser:///in-app-browser-privacy-test-user-style-sheets"]];
     979    [webView loadRequest:request];
     980    [delegate waitForDidFinishNavigation];
     981   
     982    isDone = false;
     983    [webView _isNavigatingToAppBoundDomain:^(BOOL isAppBound) {
     984        EXPECT_FALSE(isAppBound);
     985        isDone = true;
     986    }];
     987    TestWebKitAPI::Util::run(&isDone);
     988
     989    // Navigation should be successful, but this WebView should not get app-bound domain
     990    // privileges like user style sheets.
     991    expectScriptEvaluatesToColor(webView.get(), backgroundColorScript, blackInRGB);
     992    cleanUpInAppBrowserPrivacyTestSettings();
     993}
     994
     995TEST(InAppBrowserPrivacy, WebViewCannotUpdateAppBoundFlagOnceSet)
     996{
     997    initializeInAppBrowserPrivacyTestSettings();
     998    isDone = false;
     999
     1000    auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
     1001    auto schemeHandler = adoptNS([[InAppBrowserSchemeHandler alloc] init]);
     1002    [configuration setURLSchemeHandler:schemeHandler.get() forURLScheme:@"in-app-browser"];
     1003    [configuration setLimitsNavigationsToAppBoundDomains:YES];
     1004
     1005    auto webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]);
     1006    auto delegate = adoptNS([AppBoundDomainDelegate new]);
     1007    [webView setNavigationDelegate:delegate.get()];
     1008   
     1009    // Navigate to an app-bound domain and expect a successful load.
     1010    NSURLRequest *request = [NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@"in-app-browser-privacy-local-file" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"]];
     1011    [webView loadRequest:request];
     1012    [delegate waitForDidFinishNavigation];
     1013
     1014    isDone = false;
     1015    [webView _isNavigatingToAppBoundDomain:^(BOOL isAppBound) {
     1016        EXPECT_TRUE(isAppBound);
     1017        isDone = true;
     1018    }];
     1019    TestWebKitAPI::Util::run(&isDone);
     1020
     1021    [[webView configuration] setLimitsNavigationsToAppBoundDomains:NO];
     1022    // Now try to load a non-app bound domain and make sure it fails.
     1023    request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"in-app-browser:///in-app-browser-privacy-test-user-style-sheets"]];
     1024    [webView loadRequest:request];
     1025    NSError *error = [delegate waitForDidFailProvisionalNavigationError];
     1026    EXPECT_WK_STREQ(error.localizedDescription, @"Attempted navigation away from app-bound domain");
     1027
     1028    cleanUpInAppBrowserPrivacyTestSettings();
     1029}
     1030
    8781031#endif // USE(APPLE_INTERNAL_SDK)
    8791032
Note: See TracChangeset for help on using the changeset viewer.