Title: [286602] trunk/Source/WebKit
Revision
286602
Author
[email protected]
Date
2021-12-07 11:35:52 -0800 (Tue, 07 Dec 2021)

Log Message

Reload web views when toggling the captive portal mode at system level
https://bugs.webkit.org/show_bug.cgi?id=233900

Reviewed by Brent Fulgham.

Reload web views when toggling the captive portal mode at system level, so that the views end up
being backed by WebProcesses with the proper captive portal mode.

* UIProcess/Cocoa/WebProcessPoolCocoa.mm:
(WebKit::cachedCaptivePortalModeEnabledGlobally):
(WebKit::WebProcessPool::captivePortalModeStateChanged):
(WebKit::captivePortalModeEnabledBySystem):
(WebKit::WebProcessPool::notifyPreferencesChanged):
* UIProcess/WebProcessPool.h:

Modified Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (286601 => 286602)


--- trunk/Source/WebKit/ChangeLog	2021-12-07 19:33:16 UTC (rev 286601)
+++ trunk/Source/WebKit/ChangeLog	2021-12-07 19:35:52 UTC (rev 286602)
@@ -1,3 +1,20 @@
+2021-12-07  Chris Dumez  <[email protected]>
+
+        Reload web views when toggling the captive portal mode at system level
+        https://bugs.webkit.org/show_bug.cgi?id=233900
+
+        Reviewed by Brent Fulgham.
+
+        Reload web views when toggling the captive portal mode at system level, so that the views end up
+        being backed by WebProcesses with the proper captive portal mode.
+
+        * UIProcess/Cocoa/WebProcessPoolCocoa.mm:
+        (WebKit::cachedCaptivePortalModeEnabledGlobally):
+        (WebKit::WebProcessPool::captivePortalModeStateChanged):
+        (WebKit::captivePortalModeEnabledBySystem):
+        (WebKit::WebProcessPool::notifyPreferencesChanged):
+        * UIProcess/WebProcessPool.h:
+
 2021-12-07  Sihui Liu  <[email protected]>
 
         Fetch and remove file system data via WKWebsiteDataStore

Modified: trunk/Source/WebKit/UIProcess/API/APIPageConfiguration.cpp (286601 => 286602)


--- trunk/Source/WebKit/UIProcess/API/APIPageConfiguration.cpp	2021-12-07 19:33:16 UTC (rev 286601)
+++ trunk/Source/WebKit/UIProcess/API/APIPageConfiguration.cpp	2021-12-07 19:35:52 UTC (rev 286602)
@@ -204,6 +204,11 @@
     return captivePortalModeEnabledBySystem();
 }
 
+bool PageConfiguration::isCaptivePortalModeExplicitlySet() const
+{
+    return m_defaultWebsitePolicies && m_defaultWebsitePolicies->isCaptivePortalModeExplicitlySet();
+}
+
 #if ENABLE(APPLICATION_MANIFEST)
 ApplicationManifest* PageConfiguration::applicationManifest() const
 {

Modified: trunk/Source/WebKit/UIProcess/API/APIPageConfiguration.h (286601 => 286602)


--- trunk/Source/WebKit/UIProcess/API/APIPageConfiguration.h	2021-12-07 19:33:16 UTC (rev 286601)
+++ trunk/Source/WebKit/UIProcess/API/APIPageConfiguration.h	2021-12-07 19:35:52 UTC (rev 286602)
@@ -189,6 +189,7 @@
     void setRequiresUserActionForEditingControlsManager(bool value) { m_requiresUserActionForEditingControlsManager = value; }
 #endif
 
+    bool isCaptivePortalModeExplicitlySet() const;
     bool captivePortalModeEnabled() const;
 
 private:

Modified: trunk/Source/WebKit/UIProcess/API/APIWebsitePolicies.h (286601 => 286602)


--- trunk/Source/WebKit/UIProcess/API/APIWebsitePolicies.h	2021-12-07 19:33:16 UTC (rev 286601)
+++ trunk/Source/WebKit/UIProcess/API/APIWebsitePolicies.h	2021-12-07 19:35:52 UTC (rev 286602)
@@ -130,6 +130,7 @@
 
     bool captivePortalModeEnabled() const;
     void setCaptivePortalModeEnabled(std::optional<bool> captivePortalModeEnabled) { m_captivePortalModeEnabled = captivePortalModeEnabled; }
+    bool isCaptivePortalModeExplicitlySet() const { return !!m_captivePortalModeEnabled; }
 
     WebCore::MouseEventPolicy mouseEventPolicy() const { return m_mouseEventPolicy; }
     void setMouseEventPolicy(WebCore::MouseEventPolicy policy) { m_mouseEventPolicy = policy; }

Modified: trunk/Source/WebKit/UIProcess/Cocoa/WebProcessPoolCocoa.mm (286601 => 286602)


--- trunk/Source/WebKit/UIProcess/Cocoa/WebProcessPoolCocoa.mm	2021-12-07 19:33:16 UTC (rev 286601)
+++ trunk/Source/WebKit/UIProcess/Cocoa/WebProcessPoolCocoa.mm	2021-12-07 19:35:52 UTC (rev 286602)
@@ -26,6 +26,7 @@
 #import "config.h"
 #import "WebProcessPool.h"
 
+#import "APINavigation.h"
 #import "AccessibilityPreferences.h"
 #import "AccessibilitySupportSPI.h"
 #import "CookieStorageUtilsCF.h"
@@ -127,6 +128,7 @@
 static NSString *WebKitApplicationDidChangeAccessibilityEnhancedUserInterfaceNotification = @"NSApplicationDidChangeAccessibilityEnhancedUserInterfaceNotification";
 static CFStringRef AppleColorPreferencesChangedNotification = CFSTR("AppleColorPreferencesChangedNotification");
 #endif
+static const char* const WebKitCaptivePortalModeChangedNotification = "WebKitCaptivePortalModeEnabled";
 
 static NSString * const WebKitSuppressMemoryPressureHandlerDefaultsKey = @"WebKitSuppressMemoryPressureHandler";
 
@@ -182,6 +184,12 @@
     [[NSUserDefaults standardUserDefaults] registerDefaults:registrationDictionary];
 }
 
+static std::optional<bool>& cachedCaptivePortalModeEnabledGlobally()
+{
+    static std::optional<bool> cachedCaptivePortalModeEnabledGlobally;
+    return cachedCaptivePortalModeEnabledGlobally;
+}
+
 void WebProcessPool::updateProcessSuppressionState()
 {
     WebsiteDataStore::forEachWebsiteDataStore([enabled = processSuppressionEnabled()] (WebsiteDataStore& dataStore) {
@@ -937,15 +945,38 @@
     return qos;
 }
 
+void WebProcessPool::captivePortalModeStateChanged()
+{
+    cachedCaptivePortalModeEnabledGlobally() = std::nullopt;
+    auto isNowEnabled = captivePortalModeEnabledBySystem();
+
+    WEBPROCESSPOOL_RELEASE_LOG(Loading, "WebProcessPool::captivePortalModeStateChanged() isNowEnabled=%d", isNowEnabled);
+
+    for (auto& process : m_processes) {
+        bool processHasCaptivePortalModeEnabled = process->captivePortalMode() == WebProcessProxy::CaptivePortalMode::Enabled;
+        if (processHasCaptivePortalModeEnabled == isNowEnabled)
+            continue;
+
+        for (auto& page : process->pages()) {
+            // When the captive portal mode changes globally at system level, we reload every page that relied on the system setting (rather
+            // than being explicitly opted in/out by the client app at navigation or PageConfiguration level).
+            if (page->isCaptivePortalModeExplicitlySet())
+                continue;
+
+            WEBPROCESSPOOL_RELEASE_LOG(Loading, "WebProcessPool::captivePortalModeStateChanged() Reloading page with pageProxyID=%" PRIu64 " due to captive portal mode change", page->identifier().toUInt64());
+            page->reload({ });
+        }
+    }
+}
+
 bool captivePortalModeEnabledBySystem()
 {
-    static std::optional<bool> cachedCaptivePortalModeEnabledGlobally;
-    // FIXME: We should invalidate the cached value when the NSUserDefault changes.
-    if (!cachedCaptivePortalModeEnabledGlobally) {
+    auto& cachedState = cachedCaptivePortalModeEnabledGlobally();
+    if (!cachedState) {
         // FIXME: Using NSUserDefaults is a temporary workaround. This setting should be stored elsewhere (TCC?).
-        cachedCaptivePortalModeEnabledGlobally = [[NSUserDefaults standardUserDefaults] boolForKey:@"WebKitCaptivePortalModeEnabled"];
+        cachedState = [[NSUserDefaults standardUserDefaults] boolForKey:[NSString stringWithUTF8String:WebKitCaptivePortalModeChangedNotification]];
     }
-    return *cachedCaptivePortalModeEnabledGlobally;
+    return *cachedState;
 }
 
 #if PLATFORM(IOS_FAMILY)
@@ -1015,6 +1046,9 @@
     if (auto webAuthnProcess = WebAuthnProcessProxy::singletonIfCreated())
         webAuthnProcess->send(Messages::WebAuthnProcess::NotifyPreferencesChanged(domain, key, encodedValue), 0);
 #endif
+
+    if (key == WebKitCaptivePortalModeChangedNotification)
+        captivePortalModeStateChanged();
 }
 #endif // ENABLE(CFPREFS_DIRECT_MODE)
 

Modified: trunk/Source/WebKit/UIProcess/WebPageProxy.cpp (286601 => 286602)


--- trunk/Source/WebKit/UIProcess/WebPageProxy.cpp	2021-12-07 19:33:16 UTC (rev 286601)
+++ trunk/Source/WebKit/UIProcess/WebPageProxy.cpp	2021-12-07 19:35:52 UTC (rev 286602)
@@ -862,7 +862,9 @@
         m_process = relatedPage->ensureRunningProcess();
     else
         m_process = processPool.processForRegistrableDomain(m_websiteDataStore.get(), registrableDomain, shouldEnableCaptivePortalMode() ? WebProcessProxy::CaptivePortalMode::Enabled : WebProcessProxy::CaptivePortalMode::Disabled);
+
     m_hasRunningProcess = true;
+    m_isCaptivePortalModeExplicitlySet = m_configuration->isCaptivePortalModeExplicitlySet();
 
     m_process->addExistingWebPage(*this, WebProcessProxy::BeginsUsingDataStore::Yes);
     addAllMessageReceivers();
@@ -3450,6 +3452,7 @@
         }
     }
 
+    m_isCaptivePortalModeExplicitlySet = policies ? policies->isCaptivePortalModeExplicitlySet() : m_configuration->isCaptivePortalModeExplicitlySet();
     auto captivePortalMode = (policies ? policies->captivePortalModeEnabled() : shouldEnableCaptivePortalMode()) ? WebProcessProxy::CaptivePortalMode::Enabled : WebProcessProxy::CaptivePortalMode::Disabled;
     process().processPool().processForNavigation(*this, *navigation, sourceProcess.copyRef(), sourceURL, processSwapRequestedByClient, captivePortalMode, frameInfo, WTFMove(websiteDataStore), [this, protectedThis = Ref { *this }, policyAction, navigation = Ref { *navigation }, navigationAction = WTFMove(navigationAction), sourceProcess = sourceProcess.copyRef(),
         policies = WTFMove(policies), sender = WTFMove(sender), processSwapRequestedByClient] (Ref<WebProcessProxy>&& processForNavigation, SuspendedPageProxy* destinationSuspendedPage, const String& reason) mutable {

Modified: trunk/Source/WebKit/UIProcess/WebPageProxy.h (286601 => 286602)


--- trunk/Source/WebKit/UIProcess/WebPageProxy.h	2021-12-07 19:33:16 UTC (rev 286601)
+++ trunk/Source/WebKit/UIProcess/WebPageProxy.h	2021-12-07 19:35:52 UTC (rev 286602)
@@ -496,6 +496,7 @@
 
     void addPreviouslyVisitedPath(const String&);
 
+    bool isCaptivePortalModeExplicitlySet() const { return m_isCaptivePortalModeExplicitlySet; }
     bool shouldEnableCaptivePortalMode() const;
 
 #if ENABLE(DATA_DETECTION)
@@ -3139,6 +3140,7 @@
     bool m_lastNavigationWasAppInitiated { true };
     bool m_isRunningModalJavaScriptDialog { false };
     bool m_isSuspended { false };
+    bool m_isCaptivePortalModeExplicitlySet { false };
 
     std::optional<PrivateClickMeasurementAndMetadata> m_privateClickMeasurement;
 

Modified: trunk/Source/WebKit/UIProcess/WebProcessPool.h (286601 => 286602)


--- trunk/Source/WebKit/UIProcess/WebProcessPool.h	2021-12-07 19:33:16 UTC (rev 286601)
+++ trunk/Source/WebKit/UIProcess/WebProcessPool.h	2021-12-07 19:35:52 UTC (rev 286602)
@@ -548,6 +548,8 @@
 
     void registerNotificationObservers();
     void unregisterNotificationObservers();
+
+    void captivePortalModeStateChanged();
 #endif
 
     void setApplicationIsActive(bool);
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to