Skip to content

Commit

Permalink
[macOS] Toggling AX preferences does not update form control appearance
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=264170
rdar://117914468

Reviewed by Wenson Hsieh.

cfprefsd is blocked in the GPU process. Consequently, any changes to
preferences are not automatically reflected to the process. For this reason,
there is existing logic for the UI process to notify the child processes of
preference changes.

Note that AppKit caches the value of some accessibility settings. The WebContent
process already works around this by invalidating the cache whenever an
accessibility setting is modified. However, the GPU process does not currently
use the same logic. Consequently, the AppKit's cache of accessibility settings
remains frozen in the GPU process.

To fix, ensure the cache is invalidated, by moving logic from `WebProcessCocoa`
into `AuxiliaryProcessCocoa`. This approach ensures that all child processes
invalidate the relevant cache.

* Source/WebCore/PAL/pal/spi/mac/HIServicesSPI.h:
* Source/WebKit/Shared/AuxiliaryProcess.h:
(WebKit::AuxiliaryProcess::accessibilitySettingsDidChange):
* Source/WebKit/Shared/Cocoa/AuxiliaryProcessCocoa.mm:
(WebKit::invertColorsPreferenceKey):
(WebKit::AuxiliaryProcess::handleAXPreferenceChange):

Additionally invalidate the cache when the "Differentiate without color"
setting is toggled.

(WebKit::handleAXPreferenceChange): Deleted.
* Source/WebKit/WebProcess/WebProcess.h:
* Source/WebKit/WebProcess/cocoa/WebProcessCocoa.mm:
(WebKit::WebProcess::handlePreferenceChange):
(WebKit::WebProcess::accessibilitySettingsDidChange):
(WebKit::invertColorsPreferenceKey): Deleted.

Canonical link: https://commits.webkit.org/270221@main
  • Loading branch information
pxlcoder committed Nov 4, 2023
1 parent d6e83e4 commit f8db138
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 16 deletions.
2 changes: 2 additions & 0 deletions Source/WebCore/PAL/pal/spi/mac/HIServicesSPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,8 @@ extern CFStringRef kAXInterfaceReduceMotionStatusDidChangeNotification;

extern CFStringRef kAXInterfaceIncreaseContrastKey;

extern CFStringRef kAXInterfaceDifferentiateWithoutColorKey;

WTF_EXTERN_C_END

#endif // USE(APPLE_INTERNAL_SDK)
Expand Down
6 changes: 6 additions & 0 deletions Source/WebKit/Shared/AuxiliaryProcess.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@ class AuxiliaryProcess : public IPC::Connection::Client, public IPC::MessageSend
virtual void preferenceDidUpdate(const String& domain, const String& key, const std::optional<String>& encodedValue);
virtual void handlePreferenceChange(const String& domain, const String& key, id value);
virtual void dispatchSimulatedNotificationsForPreferenceChange(const String& key) { }

virtual void accessibilitySettingsDidChange() { }
#endif
void applyProcessCreationParameters(const AuxiliaryProcessCreationParameters&);

Expand All @@ -169,6 +171,10 @@ class AuxiliaryProcess : public IPC::Connection::Client, public IPC::MessageSend
bool allowsFirstPartyForCookies(const WebCore::RegistrableDomain&, HashSet<WebCore::RegistrableDomain>&);

private:
#if ENABLE(CFPREFS_DIRECT_MODE)
void handleAXPreferenceChange(const String& domain, const String& key, id value);
#endif

virtual bool shouldOverrideQuarantine() { return true; }

// IPC::MessageSender
Expand Down
19 changes: 18 additions & 1 deletion Source/WebKit/Shared/Cocoa/AuxiliaryProcessCocoa.mm
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
#endif

#if PLATFORM(MAC)
#import "AppKitSPI.h"
#import <pal/spi/mac/HIServicesSPI.h>
#endif

Expand Down Expand Up @@ -208,7 +209,15 @@ static void initializeTimerCoalescingPolicy()
}
#endif

static void handleAXPreferenceChange(const String& domain, const String& key, id value)
#if USE(APPKIT)
static const WTF::String& invertColorsPreferenceKey()
{
static NeverDestroyed<WTF::String> key(MAKE_STATIC_STRING_IMPL("whiteOnBlack"));
return key;
}
#endif

void AuxiliaryProcess::handleAXPreferenceChange(const String& domain, const String& key, id value)
{
#if HAVE(UPDATE_WEB_ACCESSIBILITY_SETTINGS)
if (!libAccessibilityLibrary())
Expand All @@ -228,6 +237,14 @@ static void handleAXPreferenceChange(const String& domain, const String& key, id
_AXSSetDarkenSystemColors([(NSNumber *)value boolValue]);
#endif
}

#if USE(APPKIT)
auto cfKey = key.createCFString();
if (CFEqual(cfKey.get(), kAXInterfaceReduceMotionKey) || CFEqual(cfKey.get(), kAXInterfaceIncreaseContrastKey) || CFEqual(cfKey.get(), kAXInterfaceDifferentiateWithoutColorKey) || key == invertColorsPreferenceKey()) {
[NSWorkspace _invalidateAccessibilityDisplayValues];
accessibilitySettingsDidChange();
}
#endif
}

void AuxiliaryProcess::handlePreferenceChange(const String& domain, const String& key, id value)
Expand Down
2 changes: 2 additions & 0 deletions Source/WebKit/WebProcess/WebProcess.h
Original file line number Diff line number Diff line change
Expand Up @@ -649,6 +649,8 @@ class WebProcess : public AuxiliaryProcess
#if ENABLE(CFPREFS_DIRECT_MODE)
void handlePreferenceChange(const String& domain, const String& key, id value) final;
void dispatchSimulatedNotificationsForPreferenceChange(const String& key) final;

void accessibilitySettingsDidChange() final;
#endif

void setNetworkProcessConnectionID(IPC::Connection::UniqueID);
Expand Down
21 changes: 6 additions & 15 deletions Source/WebKit/WebProcess/cocoa/WebProcessCocoa.mm
Original file line number Diff line number Diff line change
Expand Up @@ -1294,12 +1294,6 @@ static float currentBacklightLevel()
static NeverDestroyed<WTF::String> userHighlightColorPreferenceKey(MAKE_STATIC_STRING_IMPL("AppleHighlightColor"));
return userHighlightColorPreferenceKey;
}

static const WTF::String& invertColorsPreferenceKey()
{
static NeverDestroyed<WTF::String> key(MAKE_STATIC_STRING_IMPL("whiteOnBlack"));
return key;
}
#endif

static const WTF::String& captionProfilePreferenceKey()
Expand Down Expand Up @@ -1344,22 +1338,19 @@ static float currentBacklightLevel()
WTF::languageDidChange();
}

#if USE(APPKIT)
auto cfKey = key.createCFString();
if (CFEqual(cfKey.get(), kAXInterfaceReduceMotionKey) || CFEqual(cfKey.get(), kAXInterfaceIncreaseContrastKey) || key == invertColorsPreferenceKey()) {
[NSWorkspace _invalidateAccessibilityDisplayValues];
for (auto& page : m_pageMap.values())
page->accessibilitySettingsDidChange();
}
#endif

AuxiliaryProcess::handlePreferenceChange(domain, key, value);
}

void WebProcess::notifyPreferencesChanged(const String& domain, const String& key, const std::optional<String>& encodedValue)
{
preferenceDidUpdate(domain, key, encodedValue);
}

void WebProcess::accessibilitySettingsDidChange()
{
for (auto& page : m_pageMap.values())
page->accessibilitySettingsDidChange();
}
#endif

void WebProcess::grantAccessToAssetServices(Vector<WebKit::SandboxExtension::Handle>&& assetServicesHandles)
Expand Down

0 comments on commit f8db138

Please sign in to comment.