⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 286602 in webkit


Ignore:
Timestamp:
Dec 7, 2021, 11:35:52 AM (5 years ago)
Author:
Chris Dumez
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:
Location:
trunk/Source/WebKit
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/ChangeLog

    r286601 r286602  
     12021-12-07  Chris Dumez  <cdumez@apple.com>
     2
     3        Reload web views when toggling the captive portal mode at system level
     4        https://bugs.webkit.org/show_bug.cgi?id=233900
     5
     6        Reviewed by Brent Fulgham.
     7
     8        Reload web views when toggling the captive portal mode at system level, so that the views end up
     9        being backed by WebProcesses with the proper captive portal mode.
     10
     11        * UIProcess/Cocoa/WebProcessPoolCocoa.mm:
     12        (WebKit::cachedCaptivePortalModeEnabledGlobally):
     13        (WebKit::WebProcessPool::captivePortalModeStateChanged):
     14        (WebKit::captivePortalModeEnabledBySystem):
     15        (WebKit::WebProcessPool::notifyPreferencesChanged):
     16        * UIProcess/WebProcessPool.h:
     17
    1182021-12-07  Sihui Liu  <sihui_liu@apple.com>
    219
  • trunk/Source/WebKit/UIProcess/API/APIPageConfiguration.cpp

    r285594 r286602  
    205205}
    206206
     207bool PageConfiguration::isCaptivePortalModeExplicitlySet() const
     208{
     209    return m_defaultWebsitePolicies && m_defaultWebsitePolicies->isCaptivePortalModeExplicitlySet();
     210}
     211
    207212#if ENABLE(APPLICATION_MANIFEST)
    208213ApplicationManifest* PageConfiguration::applicationManifest() const
  • trunk/Source/WebKit/UIProcess/API/APIPageConfiguration.h

    r285594 r286602  
    190190#endif
    191191
     192    bool isCaptivePortalModeExplicitlySet() const;
    192193    bool captivePortalModeEnabled() const;
    193194
  • trunk/Source/WebKit/UIProcess/API/APIWebsitePolicies.h

    r286545 r286602  
    131131    bool captivePortalModeEnabled() const;
    132132    void setCaptivePortalModeEnabled(std::optional<bool> captivePortalModeEnabled) { m_captivePortalModeEnabled = captivePortalModeEnabled; }
     133    bool isCaptivePortalModeExplicitlySet() const { return !!m_captivePortalModeEnabled; }
    133134
    134135    WebCore::MouseEventPolicy mouseEventPolicy() const { return m_mouseEventPolicy; }
  • trunk/Source/WebKit/UIProcess/Cocoa/WebProcessPoolCocoa.mm

    r286590 r286602  
    2727#import "WebProcessPool.h"
    2828
     29#import "APINavigation.h"
    2930#import "AccessibilityPreferences.h"
    3031#import "AccessibilitySupportSPI.h"
     
    128129static CFStringRef AppleColorPreferencesChangedNotification = CFSTR("AppleColorPreferencesChangedNotification");
    129130#endif
     131static const char* const WebKitCaptivePortalModeChangedNotification = "WebKitCaptivePortalModeEnabled";
    130132
    131133static NSString * const WebKitSuppressMemoryPressureHandlerDefaultsKey = @"WebKitSuppressMemoryPressureHandler";
     
    181183
    182184    [[NSUserDefaults standardUserDefaults] registerDefaults:registrationDictionary];
     185}
     186
     187static std::optional<bool>& cachedCaptivePortalModeEnabledGlobally()
     188{
     189    static std::optional<bool> cachedCaptivePortalModeEnabledGlobally;
     190    return cachedCaptivePortalModeEnabledGlobally;
    183191}
    184192
     
    938946}
    939947
     948void WebProcessPool::captivePortalModeStateChanged()
     949{
     950    cachedCaptivePortalModeEnabledGlobally() = std::nullopt;
     951    auto isNowEnabled = captivePortalModeEnabledBySystem();
     952
     953    WEBPROCESSPOOL_RELEASE_LOG(Loading, "WebProcessPool::captivePortalModeStateChanged() isNowEnabled=%d", isNowEnabled);
     954
     955    for (auto& process : m_processes) {
     956        bool processHasCaptivePortalModeEnabled = process->captivePortalMode() == WebProcessProxy::CaptivePortalMode::Enabled;
     957        if (processHasCaptivePortalModeEnabled == isNowEnabled)
     958            continue;
     959
     960        for (auto& page : process->pages()) {
     961            // When the captive portal mode changes globally at system level, we reload every page that relied on the system setting (rather
     962            // than being explicitly opted in/out by the client app at navigation or PageConfiguration level).
     963            if (page->isCaptivePortalModeExplicitlySet())
     964                continue;
     965
     966            WEBPROCESSPOOL_RELEASE_LOG(Loading, "WebProcessPool::captivePortalModeStateChanged() Reloading page with pageProxyID=%" PRIu64 " due to captive portal mode change", page->identifier().toUInt64());
     967            page->reload({ });
     968        }
     969    }
     970}
     971
    940972bool captivePortalModeEnabledBySystem()
    941973{
    942     static std::optional<bool> cachedCaptivePortalModeEnabledGlobally;
    943     // FIXME: We should invalidate the cached value when the NSUserDefault changes.
    944     if (!cachedCaptivePortalModeEnabledGlobally) {
     974    auto& cachedState = cachedCaptivePortalModeEnabledGlobally();
     975    if (!cachedState) {
    945976        // FIXME: Using NSUserDefaults is a temporary workaround. This setting should be stored elsewhere (TCC?).
    946         cachedCaptivePortalModeEnabledGlobally = [[NSUserDefaults standardUserDefaults] boolForKey:@"WebKitCaptivePortalModeEnabled"];
    947     }
    948     return *cachedCaptivePortalModeEnabledGlobally;
     977        cachedState = [[NSUserDefaults standardUserDefaults] boolForKey:[NSString stringWithUTF8String:WebKitCaptivePortalModeChangedNotification]];
     978    }
     979    return *cachedState;
    949980}
    950981
     
    10161047        webAuthnProcess->send(Messages::WebAuthnProcess::NotifyPreferencesChanged(domain, key, encodedValue), 0);
    10171048#endif
     1049
     1050    if (key == WebKitCaptivePortalModeChangedNotification)
     1051        captivePortalModeStateChanged();
    10181052}
    10191053#endif // ENABLE(CFPREFS_DIRECT_MODE)
  • trunk/Source/WebKit/UIProcess/WebPageProxy.cpp

    r286590 r286602  
    863863    else
    864864        m_process = processPool.processForRegistrableDomain(m_websiteDataStore.get(), registrableDomain, shouldEnableCaptivePortalMode() ? WebProcessProxy::CaptivePortalMode::Enabled : WebProcessProxy::CaptivePortalMode::Disabled);
     865
    865866    m_hasRunningProcess = true;
     867    m_isCaptivePortalModeExplicitlySet = m_configuration->isCaptivePortalModeExplicitlySet();
    866868
    867869    m_process->addExistingWebPage(*this, WebProcessProxy::BeginsUsingDataStore::Yes);
     
    34513453    }
    34523454
     3455    m_isCaptivePortalModeExplicitlySet = policies ? policies->isCaptivePortalModeExplicitlySet() : m_configuration->isCaptivePortalModeExplicitlySet();
    34533456    auto captivePortalMode = (policies ? policies->captivePortalModeEnabled() : shouldEnableCaptivePortalMode()) ? WebProcessProxy::CaptivePortalMode::Enabled : WebProcessProxy::CaptivePortalMode::Disabled;
    34543457    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(),
  • trunk/Source/WebKit/UIProcess/WebPageProxy.h

    r286505 r286602  
    497497    void addPreviouslyVisitedPath(const String&);
    498498
     499    bool isCaptivePortalModeExplicitlySet() const { return m_isCaptivePortalModeExplicitlySet; }
    499500    bool shouldEnableCaptivePortalMode() const;
    500501
     
    31403141    bool m_isRunningModalJavaScriptDialog { false };
    31413142    bool m_isSuspended { false };
     3143    bool m_isCaptivePortalModeExplicitlySet { false };
    31423144
    31433145    std::optional<PrivateClickMeasurementAndMetadata> m_privateClickMeasurement;
  • trunk/Source/WebKit/UIProcess/WebProcessPool.h

    r286012 r286602  
    549549    void registerNotificationObservers();
    550550    void unregisterNotificationObservers();
     551
     552    void captivePortalModeStateChanged();
    551553#endif
    552554
Note: See TracChangeset for help on using the changeset viewer.