Title: [285634] trunk
Revision
285634
Author
[email protected]
Date
2021-11-11 09:18:22 -0800 (Thu, 11 Nov 2021)

Log Message

Turn off various preferences when in captive portal mode
https://bugs.webkit.org/show_bug.cgi?id=232958
<rdar://84622396>

Reviewed by Brent Fulgham.

Source/WebKit:

Disable the following settings when in captive portal mode:
- WebGL
- WebGL2
- Gamepads
- RemotePlayback
- FileSystemAccess
- AllowsPictureInPictureMediaPlayback
- PictureInPictureAPI
- SpeechRecognition
- Notifications
- WebXR
- WebXRAugmentedRealityModule
- WebAudio
- DownloadableBinaryFonts
- PeerConnection (WebRTC)

Covered by updated API tests.

* Shared/WebProcessCreationParameters.cpp:
(WebKit::WebProcessCreationParameters::encode const):
(WebKit::WebProcessCreationParameters::decode):
* Shared/WebProcessCreationParameters.h:
* UIProcess/WebProcessPool.cpp:
(WebKit::WebProcessPool::initializeNewWebProcess):
* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::updatePreferences):
* WebProcess/WebProcess.cpp:
(WebKit::WebProcess::initializeWebProcess):
* WebProcess/WebProcess.h:
(WebKit::WebProcess::isCaptivePortalModeEnabled const):

Tools:

Add API test coverage.

* TestWebKitAPI/Tests/WebKitCocoa/ProcessSwapOnNavigation.mm:

Modified Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (285633 => 285634)


--- trunk/Source/WebKit/ChangeLog	2021-11-11 16:10:08 UTC (rev 285633)
+++ trunk/Source/WebKit/ChangeLog	2021-11-11 17:18:22 UTC (rev 285634)
@@ -1,3 +1,42 @@
+2021-11-11  Chris Dumez  <[email protected]>
+
+        Turn off various preferences when in captive portal mode
+        https://bugs.webkit.org/show_bug.cgi?id=232958
+        <rdar://84622396>
+
+        Reviewed by Brent Fulgham.
+
+        Disable the following settings when in captive portal mode:
+        - WebGL
+        - WebGL2
+        - Gamepads
+        - RemotePlayback
+        - FileSystemAccess
+        - AllowsPictureInPictureMediaPlayback
+        - PictureInPictureAPI
+        - SpeechRecognition
+        - Notifications
+        - WebXR
+        - WebXRAugmentedRealityModule
+        - WebAudio
+        - DownloadableBinaryFonts
+        - PeerConnection (WebRTC)
+
+        Covered by updated API tests.
+
+        * Shared/WebProcessCreationParameters.cpp:
+        (WebKit::WebProcessCreationParameters::encode const):
+        (WebKit::WebProcessCreationParameters::decode):
+        * Shared/WebProcessCreationParameters.h:
+        * UIProcess/WebProcessPool.cpp:
+        (WebKit::WebProcessPool::initializeNewWebProcess):
+        * WebProcess/WebPage/WebPage.cpp:
+        (WebKit::WebPage::updatePreferences):
+        * WebProcess/WebProcess.cpp:
+        (WebKit::WebProcess::initializeWebProcess):
+        * WebProcess/WebProcess.h:
+        (WebKit::WebProcess::isCaptivePortalModeEnabled const):
+
 2021-11-11  Per Arne Vollan <[email protected]>
 
         [macOS][GPUP] Allow access to power logging service

Modified: trunk/Source/WebKit/Shared/WebProcessCreationParameters.cpp (285633 => 285634)


--- trunk/Source/WebKit/Shared/WebProcessCreationParameters.cpp	2021-11-11 16:10:08 UTC (rev 285633)
+++ trunk/Source/WebKit/Shared/WebProcessCreationParameters.cpp	2021-11-11 17:18:22 UTC (rev 285634)
@@ -123,6 +123,7 @@
     encoder << attrStyleEnabled;
     encoder << shouldThrowExceptionForGlobalConstantRedeclaration;
     encoder << crossOriginMode;
+    encoder << isCaptivePortalModeEnabled;
 
 #if ENABLE(SERVICE_CONTROLS)
     encoder << hasImageServices;
@@ -400,6 +401,8 @@
         return false;
     if (!decoder.decode(parameters.crossOriginMode))
         return false;
+    if (!decoder.decode(parameters.isCaptivePortalModeEnabled))
+        return false;
 
 #if ENABLE(SERVICE_CONTROLS)
     if (!decoder.decode(parameters.hasImageServices))

Modified: trunk/Source/WebKit/Shared/WebProcessCreationParameters.h (285633 => 285634)


--- trunk/Source/WebKit/Shared/WebProcessCreationParameters.h	2021-11-11 16:10:08 UTC (rev 285633)
+++ trunk/Source/WebKit/Shared/WebProcessCreationParameters.h	2021-11-11 17:18:22 UTC (rev 285634)
@@ -133,6 +133,7 @@
     bool attrStyleEnabled { false };
     bool shouldThrowExceptionForGlobalConstantRedeclaration { true };
     WebCore::CrossOriginMode crossOriginMode { WebCore::CrossOriginMode::Shared }; // Cross-origin isolation via COOP+COEP headers.
+    bool isCaptivePortalModeEnabled { false };
 
 #if ENABLE(SERVICE_CONTROLS)
     bool hasImageServices { false };

Modified: trunk/Source/WebKit/UIProcess/WebProcessPool.cpp (285633 => 285634)


--- trunk/Source/WebKit/UIProcess/WebProcessPool.cpp	2021-11-11 16:10:08 UTC (rev 285633)
+++ trunk/Source/WebKit/UIProcess/WebProcessPool.cpp	2021-11-11 17:18:22 UTC (rev 285634)
@@ -830,6 +830,7 @@
     parameters.attrStyleEnabled = m_configuration->attrStyleEnabled();
     parameters.shouldThrowExceptionForGlobalConstantRedeclaration = m_configuration->shouldThrowExceptionForGlobalConstantRedeclaration();
     parameters.crossOriginMode = process.crossOriginMode();
+    parameters.isCaptivePortalModeEnabled = process.captivePortalMode() == WebProcessProxy::CaptivePortalMode::Enabled;
 
 #if ENABLE(SERVICE_CONTROLS)
     auto& serviceController = ServicesController::singleton();

Modified: trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp (285633 => 285634)


--- trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp	2021-11-11 16:10:08 UTC (rev 285633)
+++ trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp	2021-11-11 17:18:22 UTC (rev 285634)
@@ -4041,6 +4041,39 @@
     PlatformMediaSessionManager::setOpusDecoderEnabled(RuntimeEnabledFeatures::sharedFeatures().opusDecoderEnabled());
 #endif
 
+    if (WebProcess::singleton().isCaptivePortalModeEnabled()) {
+        settings.setWebGLEnabled(false);
+#if ENABLE(WEBGL2)
+        settings.setWebGL2Enabled(false);
+#endif
+#if ENABLE(GAMEPAD)
+        settings.setGamepadsEnabled(false);
+#endif
+#if ENABLE(WIRELESS_PLAYBACK_TARGET)
+        settings.setRemotePlaybackEnabled(false);
+#endif
+        settings.setFileSystemAccessEnabled(false);
+        settings.setAllowsPictureInPictureMediaPlayback(false);
+#if ENABLE(PICTURE_IN_PICTURE_API)
+        settings.setPictureInPictureAPIEnabled(false);
+#endif
+        settings.setSpeechRecognitionEnabled(false);
+#if ENABLE(NOTIFICATIONS)
+        settings.setNotificationsEnabled(false);
+#endif
+#if ENABLE(WEBXR)
+        settings.setWebXREnabled(false);
+        settings.setWebXRAugmentedRealityModuleEnabled(false);
+#endif
+#if ENABLE(WEB_AUDIO)
+        settings.setWebAudioEnabled(false);
+#endif
+        settings.setDownloadableBinaryFontsEnabled(false);
+#if ENABLE(WEB_RTC)
+        settings.setPeerConnectionEnabled(false);
+#endif
+    }
+
     m_page->settingsDidChange();
 }
 

Modified: trunk/Source/WebKit/WebProcess/WebProcess.cpp (285633 => 285634)


--- trunk/Source/WebKit/WebProcess/WebProcess.cpp	2021-11-11 16:10:08 UTC (rev 285633)
+++ trunk/Source/WebKit/WebProcess/WebProcess.cpp	2021-11-11 17:18:22 UTC (rev 285634)
@@ -524,6 +524,7 @@
     commonVM().setGlobalConstRedeclarationShouldThrow(parameters.shouldThrowExceptionForGlobalConstantRedeclaration);
 
     ScriptExecutionContext::setCrossOriginMode(parameters.crossOriginMode);
+    m_isCaptivePortalModeEnabled = parameters.isCaptivePortalModeEnabled;
 
 #if ENABLE(SERVICE_CONTROLS)
     setEnabledServices(parameters.hasImageServices, parameters.hasSelectionServices, parameters.hasRichContentServices);

Modified: trunk/Source/WebKit/WebProcess/WebProcess.h (285633 => 285634)


--- trunk/Source/WebKit/WebProcess/WebProcess.h	2021-11-11 16:10:08 UTC (rev 285633)
+++ trunk/Source/WebKit/WebProcess/WebProcess.h	2021-11-11 17:18:22 UTC (rev 285634)
@@ -403,6 +403,8 @@
     WebCore::AccessibilityAtspi& accessibilityAtspi() const { return *m_accessibility; }
 #endif
 
+    bool isCaptivePortalModeEnabled() const { return m_isCaptivePortalModeEnabled; }
+
 private:
     WebProcess();
     ~WebProcess();
@@ -732,6 +734,7 @@
 
     bool m_hasSuspendedPageProxy { false };
     bool m_isSuspending { false };
+    bool m_isCaptivePortalModeEnabled { false };
 
 #if ENABLE(MEDIA_STREAM) && ENABLE(SANDBOX_EXTENSIONS)
     HashMap<String, RefPtr<SandboxExtension>> m_mediaCaptureSandboxExtensions;

Modified: trunk/Tools/ChangeLog (285633 => 285634)


--- trunk/Tools/ChangeLog	2021-11-11 16:10:08 UTC (rev 285633)
+++ trunk/Tools/ChangeLog	2021-11-11 17:18:22 UTC (rev 285634)
@@ -1,3 +1,15 @@
+2021-11-11  Chris Dumez  <[email protected]>
+
+        Turn off various preferences when in captive portal mode
+        https://bugs.webkit.org/show_bug.cgi?id=232958
+        <rdar://84622396>
+
+        Reviewed by Brent Fulgham.
+
+        Add API test coverage.
+
+        * TestWebKitAPI/Tests/WebKitCocoa/ProcessSwapOnNavigation.mm:
+
 2021-11-11  Philippe Normand  <[email protected]>
 
         [Flatpak] http server is not properly tear down

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/ProcessSwapOnNavigation.mm (285633 => 285634)


--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/ProcessSwapOnNavigation.mm	2021-11-11 16:10:08 UTC (rev 285633)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/ProcessSwapOnNavigation.mm	2021-11-11 17:18:22 UTC (rev 285634)
@@ -7638,6 +7638,34 @@
     return isJITEnabledResult;
 }
 
+enum class ShouldBeEnabled : bool { No, Yes };
+enum class IsShowingInitialEmptyDocument : bool { No, Yes };
+static void checkSettingsControlledByCaptivePortalMode(WKWebView *webView, ShouldBeEnabled shouldBeEnabled, IsShowingInitialEmptyDocument isShowingInitialEmptyDocument = IsShowingInitialEmptyDocument::No)
+{
+    auto checkWindowPropertyExists = [&](ASCIILiteral property) -> bool {
+        bool finishedRunningScript = false;
+        bool propertyExists = false;
+        [webView evaluateJavaScript:makeString("!!window.", property) completionHandler:[&] (id result, NSError *error) {
+            EXPECT_NULL(error);
+            propertyExists = [result boolValue];
+            finishedRunningScript = true;
+        }];
+        TestWebKitAPI::Util::run(&finishedRunningScript);
+        return propertyExists;
+    };
+
+    EXPECT_EQ(checkWindowPropertyExists("WebGL2RenderingContext"_s), shouldBeEnabled == ShouldBeEnabled::Yes); // WebGL2.
+    EXPECT_EQ(checkWindowPropertyExists("Gamepad"_s), shouldBeEnabled == ShouldBeEnabled::Yes); // Gamepad API.
+    EXPECT_EQ(checkWindowPropertyExists("RemotePlayback"_s), shouldBeEnabled == ShouldBeEnabled::Yes); // Remote Playback.
+    EXPECT_EQ(checkWindowPropertyExists("FileSystemHandle"_s), isShowingInitialEmptyDocument != IsShowingInitialEmptyDocument::Yes && shouldBeEnabled == ShouldBeEnabled::Yes); // File System Access.
+    EXPECT_EQ(checkWindowPropertyExists("EnterPictureInPictureEvent"_s), shouldBeEnabled == ShouldBeEnabled::Yes); // Picture in Picture API.
+    EXPECT_EQ(checkWindowPropertyExists("SpeechRecognitionEvent"_s), shouldBeEnabled == ShouldBeEnabled::Yes); // Speech recognition.
+    EXPECT_EQ(checkWindowPropertyExists("Notification"_s), shouldBeEnabled == ShouldBeEnabled::Yes); // Notification API.
+    EXPECT_EQ(checkWindowPropertyExists("WebXRSystem"_s), false); // WebXR (currently always disabled).
+    EXPECT_EQ(checkWindowPropertyExists("AudioContext"_s), shouldBeEnabled == ShouldBeEnabled::Yes); // WebAudio.
+    EXPECT_EQ(checkWindowPropertyExists("RTCPeerConnection"_s), shouldBeEnabled == ShouldBeEnabled::Yes); // WebRTC Peer Connection.
+}
+
 TEST(ProcessSwap, NavigatingToCaptivePortalMode)
 {
     auto webView = adoptNS([WKWebView new]);
@@ -7645,6 +7673,7 @@
     [webView setNavigationDelegate:delegate.get()];
 
     EXPECT_TRUE(isJITEnabled(webView.get()));
+    checkSettingsControlledByCaptivePortalMode(webView.get(), ShouldBeEnabled::Yes, IsShowingInitialEmptyDocument::Yes);
 
     __block bool finishedNavigation = false;
     delegate.get().didFinishNavigation = ^(WKWebView *, WKNavigation *) {
@@ -7659,6 +7688,7 @@
     EXPECT_NE(pid1, 0);
 
     EXPECT_TRUE(isJITEnabled(webView.get()));
+    checkSettingsControlledByCaptivePortalMode(webView.get(), ShouldBeEnabled::Yes);
 
     delegate.get().decidePolicyForNavigationActionWithPreferences = ^(WKNavigationAction *action, WKWebpagePreferences *preferences, void (^completionHandler)(WKNavigationActionPolicy, WKWebpagePreferences *)) {
         EXPECT_FALSE(preferences.captivePortalModeEnabled);
@@ -7674,6 +7704,7 @@
     // We should have process-swap for transitioning to captive portal mode.
     EXPECT_NE(pid1, [webView _webProcessIdentifier]);
     EXPECT_FALSE(isJITEnabled(webView.get()));
+    checkSettingsControlledByCaptivePortalMode(webView.get(), ShouldBeEnabled::No);
 }
 
 TEST(ProcessSwap, CaptivePortalModeEnabledByDefaultThenOptOut)
@@ -7687,6 +7718,7 @@
     [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;
@@ -7704,6 +7736,7 @@
     TestWebKitAPI::Util::run(&finishedNavigation);
 
     EXPECT_FALSE(isJITEnabled(webView.get()));
+    checkSettingsControlledByCaptivePortalMode(webView.get(), ShouldBeEnabled::No);
     EXPECT_EQ(pid1, [webView _webProcessIdentifier]);
 
     finishedNavigation = false;
@@ -7713,6 +7746,7 @@
 
     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);
 
     delegate.get().decidePolicyForNavigationActionWithPreferences = ^(WKNavigationAction *action, WKWebpagePreferences *preferences, void (^completionHandler)(WKNavigationActionPolicy, WKWebpagePreferences *)) {
         EXPECT_TRUE(preferences.captivePortalModeEnabled);
@@ -7728,11 +7762,13 @@
     // We should have process-swapped to get out of captive portal mode.
     EXPECT_NE(pid1, [webView _webProcessIdentifier]);
     EXPECT_TRUE(isJITEnabled(webView.get()));
+    checkSettingsControlledByCaptivePortalMode(webView.get(), ShouldBeEnabled::Yes);
 
     // captive portal mode should be disabled in new WebViews since it is not enabled globally.
     auto webView2 = adoptNS([WKWebView new]);
     [webView2 setNavigationDelegate:delegate.get()];
     EXPECT_TRUE(isJITEnabled(webView2.get()));
+    checkSettingsControlledByCaptivePortalMode(webView2.get(), ShouldBeEnabled::Yes, IsShowingInitialEmptyDocument::Yes);
     pid_t pid2 = [webView2 _webProcessIdentifier];
 
     delegate.get().decidePolicyForNavigationActionWithPreferences = nil;
@@ -7742,5 +7778,6 @@
     [webView2 loadRequest:[NSURLRequest requestWithURL:url]];
     TestWebKitAPI::Util::run(&finishedNavigation);
     EXPECT_TRUE(isJITEnabled(webView2.get()));
+    checkSettingsControlledByCaptivePortalMode(webView2.get(), ShouldBeEnabled::Yes);
     EXPECT_EQ(pid2, [webView2 _webProcessIdentifier]);
 }
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to