Bug 212783

Summary: [Cocoa] CFPrefs synchronization does not always work for global preference changes
Product: WebKit Reporter: Per Arne Vollan <pvollan>
Component: WebKit Misc.Assignee: Per Arne Vollan <pvollan>
Status: RESOLVED FIXED    
Severity: Normal CC: bfulgham, darin, thorton, webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   
Attachments:
Description Flags
Patch
none
Patch
thorton: review+
Patch none

Description Per Arne Vollan 2020-06-04 14:44:22 PDT
In CFPrefs direct mode, synchronization of global preference changes from the UI process to the WebContent process does not always work. This is caused by the KVO notification being sent to the incorrect NSUserDefault object, which leads us to believe a non-global preference was changed. Since a global preference change always leads to some NSUserDefaults object receiving the notification, we can work around this by checking if the preference being changed really belongs to the domain of the NSUserDefaults object, or if it is a global preference.
Comment 1 Per Arne Vollan 2020-06-04 14:44:59 PDT
rdar://problem/63862153
Comment 2 Per Arne Vollan 2020-06-04 15:03:25 PDT
Created attachment 401078 [details]
Patch
Comment 3 Tim Horton 2020-06-04 15:07:48 PDT
Comment on attachment 401078 [details]
Patch

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

> Source/WebKit/ChangeLog:9
> +        This is caused by the KVO notification being sent to the incorrect NSUserDefault object, which leads us to believe a non-global preference

It's not incorrect! Global changes affect all domains. We're just inferring too much :D

> Source/WebKit/WebProcess/cocoa/WebProcessCocoa.mm:923
> +        if (domain.isEmpty())

I think you need to merge this with my change.
Comment 4 Per Arne Vollan 2020-06-04 15:18:00 PDT
(In reply to Tim Horton from comment #3)
> Comment on attachment 401078 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=401078&action=review
> 
> > Source/WebKit/ChangeLog:9
> > +        This is caused by the KVO notification being sent to the incorrect NSUserDefault object, which leads us to believe a non-global preference
> 
> It's not incorrect! Global changes affect all domains. We're just inferring
> too much :D
> 

Right :)

> > Source/WebKit/WebProcess/cocoa/WebProcessCocoa.mm:923
> > +        if (domain.isEmpty())
> 
> I think you need to merge this with my change.

Ah, yes, this needs a rebase.

Thanks for reviewing!
Comment 5 Per Arne Vollan 2020-06-05 14:58:30 PDT
Created attachment 401203 [details]
Patch
Comment 6 Per Arne Vollan 2020-06-08 09:10:18 PDT
Created attachment 401343 [details]
Patch
Comment 7 EWS 2020-06-08 10:40:30 PDT
Committed r262724: <https://trac.webkit.org/changeset/262724>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 401343 [details].
Comment 8 Tim Horton 2020-06-10 11:04:57 PDT
*** Bug 212627 has been marked as a duplicate of this bug. ***
Comment 9 Darin Adler 2020-06-10 11:26:21 PDT
Comment on attachment 401203 [details]
Patch

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

> Source/WebKit/UIProcess/Cocoa/PreferenceObserver.mm:72
> +        if (!m_observer)
> +            return;

Don’t we want "continue" here instead of return? If we want return, then why not do this outside the loop?
Comment 10 Per Arne Vollan 2020-06-10 14:21:49 PDT
(In reply to Darin Adler from comment #9)
> Comment on attachment 401203 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=401203&action=review
> 
> > Source/WebKit/UIProcess/Cocoa/PreferenceObserver.mm:72
> > +        if (!m_observer)
> > +            return;
> 
> Don’t we want "continue" here instead of return? If we want return, then why
> not do this outside the loop?

You're right! This check should be moved outside the loop.