Bug 227031

Summary: Update Media Accessibility preferences in the WebContent process from the UI process
Product: WebKit Reporter: Per Arne Vollan <pvollan>
Component: WebKit Misc.Assignee: Per Arne Vollan <pvollan>
Status: RESOLVED FIXED    
Severity: Normal CC: bfulgham, eric.carlson, ews-watchlist, glenn, jer.noble, philipj, sergio, webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   
Attachments:
Description Flags
Patch
eric.carlson: review+, ews-feeder: commit-queue-
Patch none

Description Per Arne Vollan 2021-06-15 09:24:08 PDT
Due to stricter sandboxing in the WebContent process, Media Accessibility preferences should be updated from the UI process.
Comment 1 Per Arne Vollan 2021-06-15 09:25:19 PDT
<rdar://78614882>
Comment 2 Per Arne Vollan 2021-06-15 09:32:44 PDT
Created attachment 431447 [details]
Patch
Comment 3 Eric Carlson 2021-06-15 10:26:55 PDT
Comment on attachment 431447 [details]
Patch

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

> Source/WebCore/page/CaptionUserPreferencesMediaAF.cpp:222
> +    case kMACaptionAppearanceDisplayTypeForcedOnly:
> +        return ForcedOnly;
> +
> +    case kMACaptionAppearanceDisplayTypeAutomatic:
> +        return Automatic;
> +
> +    case kMACaptionAppearanceDisplayTypeAlwaysOn:
> +        return AlwaysOn;
> +    }

I think it is a mistake to have the one method sometimes return the cached value and sometimes call the system because the caller always knows if it to do one thing or the other, so I would split this into two methods.

> Source/WebCore/page/CaptionUserPreferencesMediaAF.cpp:527
> +    if (cachedPreferredLanguages().has_value())
> +        return cachedPreferredLanguages().value();
> +
> +    auto captionLanguages = adoptCF(MACaptionAppearanceCopySelectedLanguages(kMACaptionAppearanceDomainUser));
> +    CFIndex captionLanguagesCount = captionLanguages ? CFArrayGetCount(captionLanguages.get()) : 0;
> +
> +    Vector<String> preferredLanguages;
> +    preferredLanguages.reserveInitialCapacity(captionLanguagesCount);
> +    for (CFIndex i = 0; i < captionLanguagesCount; i++)
> +        preferredLanguages.uncheckedAppend(static_cast<CFStringRef>(CFArrayGetValueAtIndex(captionLanguages.get(), i)));
> +
> +    return preferredLanguages;

Ditto.
Comment 4 Per Arne Vollan 2021-06-16 01:07:16 PDT
Created attachment 431524 [details]
Patch
Comment 5 EWS 2021-06-16 01:56:37 PDT
Committed r278927 (238858@main): <https://commits.webkit.org/238858@main>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 431524 [details].
Comment 6 Per Arne Vollan 2021-06-16 02:05:07 PDT
(In reply to Eric Carlson from comment #3)
> Comment on attachment 431447 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=431447&action=review
> 
> > Source/WebCore/page/CaptionUserPreferencesMediaAF.cpp:222
> > +    case kMACaptionAppearanceDisplayTypeForcedOnly:
> > +        return ForcedOnly;
> > +
> > +    case kMACaptionAppearanceDisplayTypeAutomatic:
> > +        return Automatic;
> > +
> > +    case kMACaptionAppearanceDisplayTypeAlwaysOn:
> > +        return AlwaysOn;
> > +    }
> 
> I think it is a mistake to have the one method sometimes return the cached
> value and sometimes call the system because the caller always knows if it to
> do one thing or the other, so I would split this into two methods.
> 
> > Source/WebCore/page/CaptionUserPreferencesMediaAF.cpp:527
> > +    if (cachedPreferredLanguages().has_value())
> > +        return cachedPreferredLanguages().value();
> > +
> > +    auto captionLanguages = adoptCF(MACaptionAppearanceCopySelectedLanguages(kMACaptionAppearanceDomainUser));
> > +    CFIndex captionLanguagesCount = captionLanguages ? CFArrayGetCount(captionLanguages.get()) : 0;
> > +
> > +    Vector<String> preferredLanguages;
> > +    preferredLanguages.reserveInitialCapacity(captionLanguagesCount);
> > +    for (CFIndex i = 0; i < captionLanguagesCount; i++)
> > +        preferredLanguages.uncheckedAppend(static_cast<CFStringRef>(CFArrayGetValueAtIndex(captionLanguages.get(), i)));
> > +
> > +    return preferredLanguages;
> 
> Ditto.

Fixed by moving the check outside the method.

Thanks for reviewing!