Bug 163502

Summary: [Modern Media Controls] Add a MediaControlsHost API to retrieve images as base64
Product: WebKit Reporter: Antoine Quint <graouts>
Component: MediaAssignee: Antoine Quint <graouts>
Status: RESOLVED FIXED    
Severity: Normal CC: commit-queue, graouts, webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: Safari 10   
Hardware: Unspecified   
OS: Unspecified   
Bug Depends on: 163500    
Bug Blocks:    
Attachments:
Description Flags
Patch
none
Patch for landing none

Description Antoine Quint 2016-10-16 06:44:13 PDT
The previous media controls codebase would inline images as base64 in stylesheets, making it hard to version those resources. We could add a new method to MediaControlsHost to obtain the base64 encoded version of a given image so that we could obtain images at runtime from the WebCore bundle.
Comment 1 Radar WebKit Bug Importer 2016-10-16 06:44:36 PDT
<rdar://problem/28792017>
Comment 2 Antoine Quint 2016-10-16 06:57:59 PDT
Created attachment 291747 [details]
Patch
Comment 3 Darin Adler 2016-10-16 10:12:39 PDT
Comment on attachment 291747 [details]
Patch

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

> Source/WebCore/Modules/mediacontrols/MediaControlsHost.cpp:292
> +    if (page)
> +        return RenderTheme::themeForPage(page)->mediaControlsBase64StringForIconAndPlatform(iconName, platform);
> +    return "";

Early return means error case comes first. Please use emptyString(), rather than "".

> Source/WebCore/Modules/mediacontrols/MediaControlsHost.h:85
> +    String base64StringForIconAndPlatform(String iconName, String platform) const;

Argument types should be const String&, not String.

> Source/WebCore/Modules/mediacontrols/MediaControlsHost.idl:63
> +    [EnabledAtRuntime=ModernMediaControls] DOMString base64StringForIconAndPlatform(DOMString iconName, DOMString platform);

Could be a dangerous API for performance because it loads the file from disk and encodes it every time with no caching.
Comment 4 Antoine Quint 2016-10-16 14:51:28 PDT
(In reply to comment #3)
> Comment on attachment 291747 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=291747&action=review
> 
> > Source/WebCore/Modules/mediacontrols/MediaControlsHost.cpp:292
> > +    if (page)
> > +        return RenderTheme::themeForPage(page)->mediaControlsBase64StringForIconAndPlatform(iconName, platform);
> > +    return "";
> 
> Early return means error case comes first. Please use emptyString(), rather
> than "".

Sure thing, will change when landing.

> > Source/WebCore/Modules/mediacontrols/MediaControlsHost.h:85
> > +    String base64StringForIconAndPlatform(String iconName, String platform) const;
> 
> Argument types should be const String&, not String.

Thanks, will change when landing.

> > Source/WebCore/Modules/mediacontrols/MediaControlsHost.idl:63
> > +    [EnabledAtRuntime=ModernMediaControls] DOMString base64StringForIconAndPlatform(DOMString iconName, DOMString platform);
> 
> Could be a dangerous API for performance because it loads the file from disk
> and encodes it every time with no caching.

True. I will add caching on the JS side as part of the iconService singleton (see Source/WebCore/Modules/modern-media-controls/controls/icon-service.js). Currently caching is done based on the image URL, but we need to do it based on the iconName / platform pair.
Comment 5 Antoine Quint 2016-10-17 12:22:58 PDT
Created attachment 291856 [details]
Patch for landing
Comment 6 WebKit Commit Bot 2016-10-17 12:56:45 PDT
Comment on attachment 291856 [details]
Patch for landing

Clearing flags on attachment: 291856

Committed r207423: <http://trac.webkit.org/changeset/207423>
Comment 7 WebKit Commit Bot 2016-10-17 12:56:48 PDT
All reviewed patches have been landed.  Closing bug.