Bug 206478 - [Cocoa] Media mime types map should be created in the UI process
Summary: [Cocoa] Media mime types map should be created 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: 2020-01-18 17:34 PST by Per Arne Vollan
Modified: 2020-02-06 10:03 PST (History)
6 users (show)

See Also:


Attachments
Patch (18.92 KB, patch)
2020-01-18 17:44 PST, Per Arne Vollan
no flags Details | Formatted Diff | Diff
Patch (18.92 KB, patch)
2020-01-18 17:53 PST, Per Arne Vollan
no flags Details | Formatted Diff | Diff
Patch (18.92 KB, patch)
2020-01-18 18:09 PST, Per Arne Vollan
no flags Details | Formatted Diff | Diff
Patch (19.63 KB, patch)
2020-01-18 18:21 PST, Per Arne Vollan
no flags Details | Formatted Diff | Diff
Patch (19.19 KB, patch)
2020-01-18 18:34 PST, Per Arne Vollan
darin: review+
Details | Formatted Diff | Diff
Patch (23.28 KB, patch)
2020-01-23 14:55 PST, Per Arne Vollan
no flags Details | Formatted Diff | Diff
Patch (23.31 KB, patch)
2020-01-23 15:31 PST, Per Arne Vollan
no flags Details | Formatted Diff | Diff
Patch (23.26 KB, patch)
2020-01-24 11:56 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 2020-01-18 17:34:09 PST
Creating this map in the WebContent process will access the launch services daemon, which will be blocked.
Comment 1 Radar WebKit Bug Importer 2020-01-18 17:34:33 PST
<rdar://problem/58714891>
Comment 2 Per Arne Vollan 2020-01-18 17:44:34 PST
Created attachment 388163 [details]
Patch
Comment 3 Per Arne Vollan 2020-01-18 17:53:44 PST
Created attachment 388164 [details]
Patch
Comment 4 Per Arne Vollan 2020-01-18 18:09:49 PST
Created attachment 388165 [details]
Patch
Comment 5 Per Arne Vollan 2020-01-18 18:21:58 PST
Created attachment 388166 [details]
Patch
Comment 6 Per Arne Vollan 2020-01-18 18:34:17 PST
Created attachment 388167 [details]
Patch
Comment 7 Sam Weinig 2020-01-19 10:51:46 PST
What happens if the mapping of mime types reported by launch services changes during the lifetime of the process?
Comment 8 Darin Adler 2020-01-20 11:38:43 PST
Comment on attachment 388167 [details]
Patch

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

Not sure what the Windows failure on EWS is about.

> Source/WebCore/platform/MIMETypeRegistry.cpp:285
> +    // A table of common media MIME types and file extentions used when a platform's

Spelling error here. It’s extensions, not "extentions".

> Source/WebCore/platform/MIMETypeRegistry.cpp:287
> +    static NeverDestroyed<std::initializer_list<TypeExtensionPair>> commonMediaTypes;

Should be able to use constexpr for this whole thing rather than needing code to initialize it.

> Source/WebCore/platform/MIMETypeRegistry.cpp:290
> +    static std::once_flag onceFlag;
> +    std::call_once(

Surprised we need this. Is this called from multiple threads? If not then we should just be able to use "= [] {" instead of all the call_once stuff as is done in many other places in WebKit such as canAtttachAuthorShadowRoot, hasEffectiveDisplayNoneForDisplayContents, etc.

> Source/WebCore/platform/MIMETypeRegistry.cpp:381
> +    static std::once_flag onceFlag;
> +    std::call_once(

Ditto.
Comment 9 Per Arne Vollan 2020-01-21 12:06:16 PST
(In reply to Sam Weinig from comment #7)
> What happens if the mapping of mime types reported by launch services
> changes during the lifetime of the process?

Good point! There should be no behavior change with this patch. The only difference is that we create the cached map in the UI process instead of in the WebContent process.

Thanks for reviewing!
Comment 10 Per Arne Vollan 2020-01-21 12:08:18 PST
(In reply to Darin Adler from comment #8)
> Comment on attachment 388167 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=388167&action=review
> 
> Not sure what the Windows failure on EWS is about.
> 
> > Source/WebCore/platform/MIMETypeRegistry.cpp:285
> > +    // A table of common media MIME types and file extentions used when a platform's
> 
> Spelling error here. It’s extensions, not "extentions".
> 
> > Source/WebCore/platform/MIMETypeRegistry.cpp:287
> > +    static NeverDestroyed<std::initializer_list<TypeExtensionPair>> commonMediaTypes;
> 
> Should be able to use constexpr for this whole thing rather than needing
> code to initialize it.
> 
> > Source/WebCore/platform/MIMETypeRegistry.cpp:290
> > +    static std::once_flag onceFlag;
> > +    std::call_once(
> 
> Surprised we need this. Is this called from multiple threads? If not then we
> should just be able to use "= [] {" instead of all the call_once stuff as is
> done in many other places in WebKit such as canAtttachAuthorShadowRoot,
> hasEffectiveDisplayNoneForDisplayContents, etc.
> 
> > Source/WebCore/platform/MIMETypeRegistry.cpp:381
> > +    static std::once_flag onceFlag;
> > +    std::call_once(
> 
> Ditto.

You're right. I don't believe we need this, since the function did not use call_once originally. I will update the patch, possibly asserting that this code is being run on the main thread.

Thanks for reviewing!
Comment 11 Sam Weinig 2020-01-22 14:45:19 PST
(In reply to Per Arne Vollan from comment #9)
> (In reply to Sam Weinig from comment #7)
> > What happens if the mapping of mime types reported by launch services
> > changes during the lifetime of the process?
> 
> Good point! There should be no behavior change with this patch. The only
> difference is that we create the cached map in the UI process instead of in
> the WebContent process.
> 

Sounds like there would be a subtle behavior change then, since the cache will now not be invalidated for the life of the UIProcess, whereas, on each WebProcess creation we used to get a fresh copy.
Comment 12 Per Arne Vollan 2020-01-22 14:58:36 PST
(In reply to Sam Weinig from comment #11)
> (In reply to Per Arne Vollan from comment #9)
> > (In reply to Sam Weinig from comment #7)
> > > What happens if the mapping of mime types reported by launch services
> > > changes during the lifetime of the process?
> > 
> > Good point! There should be no behavior change with this patch. The only
> > difference is that we create the cached map in the UI process instead of in
> > the WebContent process.
> > 
> 
> Sounds like there would be a subtle behavior change then, since the cache
> will now not be invalidated for the life of the UIProcess, whereas, on each
> WebProcess creation we used to get a fresh copy.

Ah, yes, that is a good point! We could possibly recreate the map every time we create a new WebContent process, but that would be less performant than just using the previous one.
Comment 13 Per Arne Vollan 2020-01-23 14:55:38 PST
Created attachment 388595 [details]
Patch
Comment 14 Per Arne Vollan 2020-01-23 15:31:41 PST
Created attachment 388601 [details]
Patch
Comment 15 WebKit Commit Bot 2020-01-23 19:19:00 PST
Comment on attachment 388601 [details]
Patch

Clearing flags on attachment: 388601

Committed r255050: <https://trac.webkit.org/changeset/255050>
Comment 16 Sam Weinig 2020-01-24 08:07:53 PST
Probably worth investigating whether one already exists / filing a radar for a callback from launch services that tells you if it changes.a
Comment 17 Per Arne Vollan 2020-01-24 10:53:07 PST
Reverted r255050 for reason:

Introduced crashes on bots

Committed r255081: <https://trac.webkit.org/changeset/255081>
Comment 18 Per Arne Vollan 2020-01-24 11:56:51 PST
Created attachment 388714 [details]
Patch
Comment 19 Per Arne Vollan 2020-01-24 12:43:10 PST
(In reply to Sam Weinig from comment #16)
> Probably worth investigating whether one already exists / filing a radar for
> a callback from launch services that tells you if it changes.a

Thanks! I am looking into this now.
Comment 20 Per Arne Vollan 2020-01-24 13:23:53 PST
(In reply to Per Arne Vollan from comment #19)
> (In reply to Sam Weinig from comment #16)
> > Probably worth investigating whether one already exists / filing a radar for
> > a callback from launch services that tells you if it changes.a
> 
> Thanks! I am looking into this now.

There appears to be an existing mechanism for this.
Comment 21 WebKit Commit Bot 2020-01-25 08:51:40 PST
Comment on attachment 388714 [details]
Patch

Clearing flags on attachment: 388714

Committed r255119: <https://trac.webkit.org/changeset/255119>