Title: [272154] trunk/Source/WebKit
Revision
272154
Author
pvol...@apple.com
Date
2021-02-01 12:06:26 -0800 (Mon, 01 Feb 2021)

Log Message

[macOS] Observe color preference changes in the UI process
https://bugs.webkit.org/show_bug.cgi?id=221096
<rdar://problem/73721275>

Reviewed by Brent Fulgham.

As a step towards blocking the distributed notifications daemon in the WebContent process, color preference changes should be observed in the UI process.
The UI process should notify the WebContent process about color preference changes. In order to be able to notify the AppKit observer in the WebContent
process about changes with a local notification, a specific key/value needs to added to the Info.plist of the WebContent process.

* UIProcess/Cocoa/WebProcessPoolCocoa.mm:
(WebKit::WebProcessPool::colorPreferencesDidChangeCallback):
(WebKit::WebProcessPool::registerNotificationObservers):
(WebKit::WebProcessPool::unregisterNotificationObservers):
* UIProcess/WebProcessPool.h:
* WebProcess/EntryPoint/Cocoa/XPCService/WebContentService/Info-OSX.plist:
* WebProcess/WebProcess.h:
* WebProcess/WebProcess.messages.in:
* WebProcess/cocoa/WebProcessCocoa.mm:
(WebKit::WebProcess::colorPreferencesDidChange):

Modified Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (272153 => 272154)


--- trunk/Source/WebKit/ChangeLog	2021-02-01 19:43:40 UTC (rev 272153)
+++ trunk/Source/WebKit/ChangeLog	2021-02-01 20:06:26 UTC (rev 272154)
@@ -1,5 +1,28 @@
 2021-02-01  Per Arne  <pvol...@apple.com>
 
+        [macOS] Observe color preference changes in the UI process
+        https://bugs.webkit.org/show_bug.cgi?id=221096
+        <rdar://problem/73721275>
+
+        Reviewed by Brent Fulgham.
+
+        As a step towards blocking the distributed notifications daemon in the WebContent process, color preference changes should be observed in the UI process.
+        The UI process should notify the WebContent process about color preference changes. In order to be able to notify the AppKit observer in the WebContent
+        process about changes with a local notification, a specific key/value needs to added to the Info.plist of the WebContent process.
+
+        * UIProcess/Cocoa/WebProcessPoolCocoa.mm:
+        (WebKit::WebProcessPool::colorPreferencesDidChangeCallback):
+        (WebKit::WebProcessPool::registerNotificationObservers):
+        (WebKit::WebProcessPool::unregisterNotificationObservers):
+        * UIProcess/WebProcessPool.h:
+        * WebProcess/EntryPoint/Cocoa/XPCService/WebContentService/Info-OSX.plist:
+        * WebProcess/WebProcess.h:
+        * WebProcess/WebProcess.messages.in:
+        * WebProcess/cocoa/WebProcessCocoa.mm:
+        (WebKit::WebProcess::colorPreferencesDidChange):
+
+2021-02-01  Per Arne  <pvol...@apple.com>
+
         [macOS] Remove write access to some IOKit properties
         https://bugs.webkit.org/show_bug.cgi?id=221137
         <rdar://problem/73473658>

Modified: trunk/Source/WebKit/UIProcess/Cocoa/WebProcessPoolCocoa.mm (272153 => 272154)


--- trunk/Source/WebKit/UIProcess/Cocoa/WebProcessPoolCocoa.mm	2021-02-01 19:43:40 UTC (rev 272153)
+++ trunk/Source/WebKit/UIProcess/Cocoa/WebProcessPoolCocoa.mm	2021-02-01 20:06:26 UTC (rev 272154)
@@ -104,6 +104,7 @@
 
 #if !PLATFORM(IOS_FAMILY) || PLATFORM(MACCATALYST)
 static NSString *WebKitApplicationDidChangeAccessibilityEnhancedUserInterfaceNotification = @"NSApplicationDidChangeAccessibilityEnhancedUserInterfaceNotification";
+static CFStringRef AppleColorPreferencesChangedNotification = CFSTR("AppleColorPreferencesChangedNotification");
 #endif
 
 static NSString * const WebKitSuppressMemoryPressureHandlerDefaultsKey = @"WebKitSuppressMemoryPressureHandler";
@@ -588,6 +589,14 @@
 }
 #endif
 
+#if PLATFORM(MAC) || PLATFORM(MACCATALYST)
+void WebProcessPool::colorPreferencesDidChangeCallback(CFNotificationCenterRef center, void *observer, CFStringRef name, const void *object, CFDictionaryRef userInfo)
+{
+    auto* pool = reinterpret_cast<WebProcessPool*>(observer);
+    pool->sendToAllProcesses(Messages::WebProcess::ColorPreferencesDidChange());
+}
+#endif
+
 #if ENABLE(REMOTE_INSPECTOR) && PLATFORM(IOS_FAMILY) && !PLATFORM(MACCATALYST)
 void WebProcessPool::remoteWebInspectorEnabledCallback(CFNotificationCenterRef, void *observer, CFStringRef name, const void *, CFDictionaryRef userInfo)
 {
@@ -667,6 +676,8 @@
     m_deactivationObserver = [[NSNotificationCenter defaultCenter] addObserverForName:NSApplicationDidResignActiveNotification object:NSApp queue:[NSOperationQueue currentQueue] usingBlock:^(NSNotification *notification) {
         setApplicationIsActive(false);
     }];
+    
+    CFNotificationCenterAddObserver(CFNotificationCenterGetDistributedCenter(), this, colorPreferencesDidChangeCallback, AppleColorPreferencesChangedNotification, nullptr, CFNotificationSuspensionBehaviorCoalesce);
 #elif !PLATFORM(MACCATALYST)
     CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), this, backlightLevelDidChangeCallback, static_cast<CFStringRef>(UIBacklightLevelChangedNotification), nullptr, CFNotificationSuspensionBehaviorCoalesce);
 #if PLATFORM(IOS)
@@ -720,6 +731,7 @@
     [[NSNotificationCenter defaultCenter] removeObserver:m_scrollerStyleNotificationObserver.get()];
 #endif
     [[NSNotificationCenter defaultCenter] removeObserver:m_deactivationObserver.get()];
+    CFNotificationCenterRemoveObserver(CFNotificationCenterGetDistributedCenter(), this, AppleColorPreferencesChangedNotification, nullptr);
 #elif !PLATFORM(MACCATALYST)
     CFNotificationCenterRemoveObserver(CFNotificationCenterGetDarwinNotifyCenter(), this, static_cast<CFStringRef>(UIBacklightLevelChangedNotification) , nullptr);
 #if PLATFORM(IOS)

Modified: trunk/Source/WebKit/UIProcess/WebProcessPool.h (272153 => 272154)


--- trunk/Source/WebKit/UIProcess/WebProcessPool.h	2021-02-01 19:43:40 UTC (rev 272153)
+++ trunk/Source/WebKit/UIProcess/WebProcessPool.h	2021-02-01 20:06:26 UTC (rev 272154)
@@ -565,6 +565,10 @@
 #endif
 #endif
 
+#if PLATFORM(MAC)
+    static void colorPreferencesDidChangeCallback(CFNotificationCenterRef, void *observer, CFStringRef name, const void *, CFDictionaryRef userInfo);
+#endif
+    
 #if ENABLE(CFPREFS_DIRECT_MODE)
     void startObservingPreferenceChanges();
 #endif

Modified: trunk/Source/WebKit/WebProcess/EntryPoint/Cocoa/XPCService/WebContentService/Info-OSX.plist (272153 => 272154)


--- trunk/Source/WebKit/WebProcess/EntryPoint/Cocoa/XPCService/WebContentService/Info-OSX.plist	2021-02-01 19:43:40 UTC (rev 272153)
+++ trunk/Source/WebKit/WebProcess/EntryPoint/Cocoa/XPCService/WebContentService/Info-OSX.plist	2021-02-01 20:06:26 UTC (rev 272154)
@@ -46,12 +46,14 @@
 		<string>Application</string>
 		<key>RunLoopType</key>
 		<string>${RUNLOOP_TYPE}</string>
-                <key>_ProcessType</key>
-                <string>App</string>
+		<key>_ProcessType</key>
+		<string>App</string>
 		<key>_MultipleInstances</key>
 		<true/>
 		<key>_HighBitsASLR</key>
 		<true/>
 	</dict>
+	<key>NSColorPreferLocalNotifications</key>
+	<integer>1</integer>
 </dict>
 </plist>

Modified: trunk/Source/WebKit/WebProcess/WebProcess.h (272153 => 272154)


--- trunk/Source/WebKit/WebProcess/WebProcess.h	2021-02-01 19:43:40 UTC (rev 272153)
+++ trunk/Source/WebKit/WebProcess/WebProcess.h	2021-02-01 20:06:26 UTC (rev 272154)
@@ -535,6 +535,10 @@
     void backlightLevelDidChange(float backlightLevel);
 #endif
 
+#if PLATFORM(MAC) || PLATFORM(MACCATALYST)
+    void colorPreferencesDidChange();
+#endif
+
 #if PLATFORM(IOS_FAMILY)
     void userInterfaceIdiomDidChange(bool);
 

Modified: trunk/Source/WebKit/WebProcess/WebProcess.messages.in (272153 => 272154)


--- trunk/Source/WebKit/WebProcess/WebProcess.messages.in	2021-02-01 19:43:40 UTC (rev 272153)
+++ trunk/Source/WebKit/WebProcess/WebProcess.messages.in	2021-02-01 20:06:26 UTC (rev 272154)
@@ -128,6 +128,10 @@
     BacklightLevelDidChange(float backlightLevel)
 #endif
 
+#if PLATFORM(MAC) || PLATFORM(MACCATALYST)
+    ColorPreferencesDidChange()
+#endif
+
     IsJITEnabled() -> (bool enabled) Async
 
 #if PLATFORM(COCOA)

Modified: trunk/Source/WebKit/WebProcess/cocoa/WebProcessCocoa.mm (272153 => 272154)


--- trunk/Source/WebKit/WebProcess/cocoa/WebProcessCocoa.mm	2021-02-01 19:43:40 UTC (rev 272153)
+++ trunk/Source/WebKit/WebProcess/cocoa/WebProcessCocoa.mm	2021-02-01 20:06:26 UTC (rev 272154)
@@ -1016,6 +1016,13 @@
 }
 #endif
 
+#if PLATFORM(MAC) || PLATFORM(MACCATALYST)
+void WebProcess::colorPreferencesDidChange()
+{
+    CFNotificationCenterPostNotification(CFNotificationCenterGetLocalCenter(), CFSTR("NSColorLocalPreferencesChangedNotification"), nullptr, nullptr, true);
+}
+#endif
+
 #if ENABLE(REMOTE_INSPECTOR)
 void WebProcess::enableRemoteWebInspector()
 {
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to