Bug 221096 - [macOS] Observe color preference changes in the UI process
Summary: [macOS] Observe color preference changes in the UI process
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebKit Misc. (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Per Arne Vollan
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2021-01-28 13:09 PST by Per Arne Vollan
Modified: 2021-02-01 12:06 PST (History)
2 users (show)

See Also:


Attachments
Patch (7.46 KB, patch)
2021-01-28 13:22 PST, Per Arne Vollan
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Per Arne Vollan 2021-01-28 13:09:34 PST
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.
Comment 1 Radar WebKit Bug Importer 2021-01-28 13:11:02 PST
<rdar://problem/73721275>
Comment 2 Per Arne Vollan 2021-01-28 13:22:38 PST
Created attachment 418666 [details]
Patch
Comment 3 Brent Fulgham 2021-01-29 10:05:38 PST
Comment on attachment 418666 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=418666&action=review

> Source/WebKit/UIProcess/Cocoa/WebProcessPoolCocoa.mm:107
> +static CFStringRef AppleColorPreferencesChangedNotification = CFSTR("AppleColorPreferencesChangedNotification");

Should this be in one of our PAL SPI files?

> Source/WebKit/UIProcess/Cocoa/WebProcessPoolCocoa.mm:595
> +    auto* pool = reinterpret_cast<WebProcessPool*>(observer);

Could pool be null (perhaps during launch or shutdown)? Maybe this should be:
if (auto* pool = ....)
    pool->sendToAllProcesses

This might apply to the 'backlightLevelDidChangeCallback', too.

> Source/WebKit/WebProcess/cocoa/WebProcessCocoa.mm:1022
> +    CFNotificationCenterPostNotification(CFNotificationCenterGetLocalCenter(), CFSTR("NSColorLocalPreferencesChangedNotification"), nullptr, nullptr, true);

Should 'NSColorLocalPreferencesChangedNotification' be something we put in PAL SPI somewhere? Is this a real thing used elsewhere in the system?
Comment 4 Per Arne Vollan 2021-01-29 13:19:43 PST
(In reply to Brent Fulgham from comment #3)
> Comment on attachment 418666 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=418666&action=review
> 
> > Source/WebKit/UIProcess/Cocoa/WebProcessPoolCocoa.mm:107
> > +static CFStringRef AppleColorPreferencesChangedNotification = CFSTR("AppleColorPreferencesChangedNotification");
> 
> Should this be in one of our PAL SPI files?
> 

The constant has not been assigned an official name in the system. Even so, should we add this to an SPI file?

> > Source/WebKit/UIProcess/Cocoa/WebProcessPoolCocoa.mm:595
> > +    auto* pool = reinterpret_cast<WebProcessPool*>(observer);
> 
> Could pool be null (perhaps during launch or shutdown)? Maybe this should be:
> if (auto* pool = ....)
>     pool->sendToAllProcesses
> 
> This might apply to the 'backlightLevelDidChangeCallback', too.
> 

That is a good point. In this particular case it seems pool cannot be null, since it is being initialized with 'this' in 'CFNotificationCenterAddObserver(CFNotificationCenterGetDistributedCenter(), this, colorPreferencesDidChangeCallback, AppleColorPreferencesChangedNotification, nullptr, CFNotificationSuspensionBehaviorCoalesce)'.

> > Source/WebKit/WebProcess/cocoa/WebProcessCocoa.mm:1022
> > +    CFNotificationCenterPostNotification(CFNotificationCenterGetLocalCenter(), CFSTR("NSColorLocalPreferencesChangedNotification"), nullptr, nullptr, true);
> 
> Should 'NSColorLocalPreferencesChangedNotification' be something we put in
> PAL SPI somewhere? Is this a real thing used elsewhere in the system?

It is used in the system, but it seems it has not been assigned an official name. Would you prefer it being added to an SPI file?

Thanks for reviewing!
Comment 5 Brent Fulgham 2021-02-01 09:47:34 PST
Comment on attachment 418666 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=418666&action=review

r=me

>>> Source/WebKit/UIProcess/Cocoa/WebProcessPoolCocoa.mm:107
>>> +static CFStringRef AppleColorPreferencesChangedNotification = CFSTR("AppleColorPreferencesChangedNotification");
>> 
>> Should this be in one of our PAL SPI files?
> 
> The constant has not been assigned an official name in the system. Even so, should we add this to an SPI file?

No, not if it's our own thing.

>>> Source/WebKit/UIProcess/Cocoa/WebProcessPoolCocoa.mm:595
>>> +    auto* pool = reinterpret_cast<WebProcessPool*>(observer);
>> 
>> Could pool be null (perhaps during launch or shutdown)? Maybe this should be:
>> if (auto* pool = ....)
>>     pool->sendToAllProcesses
>> 
>> This might apply to the 'backlightLevelDidChangeCallback', too.
> 
> That is a good point. In this particular case it seems pool cannot be null, since it is being initialized with 'this' in 'CFNotificationCenterAddObserver(CFNotificationCenterGetDistributedCenter(), this, colorPreferencesDidChangeCallback, AppleColorPreferencesChangedNotification, nullptr, CFNotificationSuspensionBehaviorCoalesce)'.

Makes sense.
Comment 6 Per Arne Vollan 2021-02-01 09:54:23 PST
Comment on attachment 418666 [details]
Patch

Thanks for reviewing!
Comment 7 EWS 2021-02-01 12:06:32 PST
Committed r272154: <https://trac.webkit.org/changeset/272154>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 418666 [details].