Title: [285873] trunk
Revision
285873
Author
[email protected]
Date
2021-11-16 10:27:57 -0800 (Tue, 16 Nov 2021)

Log Message

[iOS] Do not require the web browser entitlement to opt into captive portal mode
https://bugs.webkit.org/show_bug.cgi?id=233191

Reviewed by Brent Fulgham.

Source/WebKit:

Do not require the web browser entitlement to opt into captive portal mode on iOS, only require
it to opt out.

* UIProcess/API/Cocoa/WKWebpagePreferences.mm:
(-[WKWebpagePreferences _setCaptivePortalModeEnabled:]):

Tools:

Update API test coverage accordingly.

* TestWebKitAPI/Tests/WebKitCocoa/ProcessSwapOnNavigation.mm:

Modified Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (285872 => 285873)


--- trunk/Source/WebKit/ChangeLog	2021-11-16 18:14:09 UTC (rev 285872)
+++ trunk/Source/WebKit/ChangeLog	2021-11-16 18:27:57 UTC (rev 285873)
@@ -1,3 +1,16 @@
+2021-11-16  Chris Dumez  <[email protected]>
+
+        [iOS] Do not require the web browser entitlement to opt into captive portal mode
+        https://bugs.webkit.org/show_bug.cgi?id=233191
+
+        Reviewed by Brent Fulgham.
+
+        Do not require the web browser entitlement to opt into captive portal mode on iOS, only require
+        it to opt out.
+
+        * UIProcess/API/Cocoa/WKWebpagePreferences.mm:
+        (-[WKWebpagePreferences _setCaptivePortalModeEnabled:]):
+
 2021-11-16  Per Arne Vollan <[email protected]>
 
         [macOS][GPUP] Add telemetry for syscalls

Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebpagePreferences.mm (285872 => 285873)


--- trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebpagePreferences.mm	2021-11-16 18:14:09 UTC (rev 285872)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebpagePreferences.mm	2021-11-16 18:27:57 UTC (rev 285873)
@@ -393,10 +393,15 @@
 
 - (void)_setCaptivePortalModeEnabled:(BOOL)captivePortalModeEnabled
 {
+    if (_websitePolicies->captivePortalModeEnabled() == captivePortalModeEnabled)
+        return;
+
 #if PLATFORM(IOS_FAMILY)
-    if (!WTF::processHasEntitlement("com.apple.developer.web-browser"))
-        return;
+    // On iOS, the web browser entitlement is required to disable captive portal mode.
+    if (!captivePortalModeEnabled && !WTF::processHasEntitlement("com.apple.developer.web-browser"))
+        [NSException raise:NSInternalInconsistencyException format:@"The 'com.apple.developer.web-browser' restricted entitlement is required to disable captive portal mode"];
 #endif
+
     _websitePolicies->setCaptivePortalModeEnabled(!!captivePortalModeEnabled);
 }
 

Modified: trunk/Tools/ChangeLog (285872 => 285873)


--- trunk/Tools/ChangeLog	2021-11-16 18:14:09 UTC (rev 285872)
+++ trunk/Tools/ChangeLog	2021-11-16 18:27:57 UTC (rev 285873)
@@ -1,3 +1,14 @@
+2021-11-16  Chris Dumez  <[email protected]>
+
+        [iOS] Do not require the web browser entitlement to opt into captive portal mode
+        https://bugs.webkit.org/show_bug.cgi?id=233191
+
+        Reviewed by Brent Fulgham.
+
+        Update API test coverage accordingly.
+
+        * TestWebKitAPI/Tests/WebKitCocoa/ProcessSwapOnNavigation.mm:
+
 2021-11-16  Andres Gonzalez  <[email protected]>
 
         Fix for accessibility/mac/replace-text-with-range-on-webarea-element.html in isolated tree mode.

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/ProcessSwapOnNavigation.mm (285872 => 285873)


--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/ProcessSwapOnNavigation.mm	2021-11-16 18:14:09 UTC (rev 285872)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/ProcessSwapOnNavigation.mm	2021-11-16 18:27:57 UTC (rev 285873)
@@ -7626,10 +7626,6 @@
     runCOOPProcessSwapTest("same-origin-allow-popup", "unsafe-none", "unsafe-none", "unsafe-none", IsSameOrigin::No, DoServerSideRedirect::No, ExpectSwap::No);
 }
 
-// On iOS, toggling the captive portal mode requires the browser entitlement, which TestWebKit API doesn't have.
-// Also, some API tests rely on the browser entitlement not being present.
-#if !PLATFORM(IOS)
-
 static bool isJITEnabled(WKWebView *webView)
 {
     __block bool gotResponse = false;
@@ -7723,6 +7719,53 @@
     checkSettingsControlledByCaptivePortalMode(webView.get(), ShouldBeEnabled::No);
 }
 
+#if PLATFORM(IOS)
+
+TEST(ProcessSwap, CannotDisableCaptivePortalModeWithoutBrowserEntitlement)
+{
+    auto webViewConfiguration = adoptNS([WKWebViewConfiguration new]);
+    EXPECT_FALSE(webViewConfiguration.get().defaultWebpagePreferences._captivePortalModeEnabled);
+    [webViewConfiguration.get().defaultWebpagePreferences _setCaptivePortalModeEnabled:YES];
+    [webViewConfiguration.get().preferences _setMediaDevicesEnabled:YES];
+    webViewConfiguration.get().preferences._mediaCaptureRequiresSecureConnection = NO;
+
+    auto webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:webViewConfiguration.get()]);
+    auto delegate = adoptNS([TestNavigationDelegate new]);
+    [webView setNavigationDelegate:delegate.get()];
+
+    EXPECT_FALSE(isJITEnabled(webView.get()));
+    checkSettingsControlledByCaptivePortalMode(webView.get(), ShouldBeEnabled::No, IsShowingInitialEmptyDocument::Yes);
+    pid_t pid1 = [webView _webProcessIdentifier];
+
+    __block bool finishedNavigation = false;
+    delegate.get().didFinishNavigation = ^(WKWebView *, WKNavigation *) {
+        finishedNavigation = true;
+    };
+
+    delegate.get().decidePolicyForNavigationActionWithPreferences = ^(WKNavigationAction *action, WKWebpagePreferences *preferences, void (^completionHandler)(WKNavigationActionPolicy, WKWebpagePreferences *)) {
+        EXPECT_TRUE(preferences._captivePortalModeEnabled);
+        bool didThrowWhenTryingToDisableCaptivePortalMode = false;
+        // TestWebKitAPI doesn't have the web browser entitlement and thus shouldn't be able to disable captive portal mode.
+        @try {
+            [preferences _setCaptivePortalModeEnabled:NO];
+        } @catch (NSException *exception) {
+            didThrowWhenTryingToDisableCaptivePortalMode = true;
+        }
+        EXPECT_TRUE(didThrowWhenTryingToDisableCaptivePortalMode);
+        completionHandler(WKNavigationActionPolicyAllow, preferences);
+    };
+
+    NSURL *url = "" mainBundle] URLForResource:@"simple" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"];
+    [webView loadRequest:[NSURLRequest requestWithURL:url]];
+    TestWebKitAPI::Util::run(&finishedNavigation);
+
+    EXPECT_EQ(pid1, [webView _webProcessIdentifier]); // Shouldn't have process-swapped since we're staying in captive portal mode.
+    EXPECT_FALSE(isJITEnabled(webView.get()));
+    checkSettingsControlledByCaptivePortalMode(webView.get(), ShouldBeEnabled::No);
+}
+
+#else
+
 TEST(ProcessSwap, CaptivePortalModeEnabledByDefaultThenOptOut)
 {
     auto webViewConfiguration = adoptNS([WKWebViewConfiguration new]);
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to