[Modern Media Controls] Add a MediaControlsHost API to retrieve images as base64
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 17 Oct 2016 19:54:04 +0000 (19:54 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 17 Oct 2016 19:54:04 +0000 (19:54 +0000)
https://bugs.webkit.org/show_bug.cgi?id=163502
<rdar://problem/28792017>

Patch by Antoine Quint <graouts@apple.com> on 2016-10-17
Reviewed by Darin Adler.

Add a new `base64StringForIconAndPlatform()` method to MediaControlsHost such that we
may load images from the modern-media-controls directory in the WebCore.framework bundle.
We use this new method in the iconService singleton when a `mediaControlsHost` is set,
which will be set in a later patch.

* Modules/mediacontrols/MediaControlsHost.cpp:
(WebCore::MediaControlsHost::base64StringForIconAndPlatform):
* Modules/mediacontrols/MediaControlsHost.h:
* Modules/mediacontrols/MediaControlsHost.idl:
* Modules/modern-media-controls/controls/icon-service.js:
(const.iconService.new.IconService.prototype.urlForIconNameAndLayoutTraits):
(const.iconService.new.IconService):
* rendering/RenderTheme.h:
(WebCore::RenderTheme::mediaControlsBase64StringForIconAndPlatform):
(WebCore::RenderTheme::mediaControlsScript): Deleted.
* rendering/RenderThemeMac.h:
* rendering/RenderThemeMac.mm:
(WebCore::RenderThemeMac::mediaControlsBase64StringForIconAndPlatform):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@207423 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/media/modern-media-controls/icon-service/icon-service-expected.txt
LayoutTests/media/modern-media-controls/icon-service/icon-service.html
Source/WebCore/ChangeLog
Source/WebCore/Modules/mediacontrols/MediaControlsHost.cpp
Source/WebCore/Modules/mediacontrols/MediaControlsHost.h
Source/WebCore/Modules/mediacontrols/MediaControlsHost.idl
Source/WebCore/Modules/modern-media-controls/controls/icon-service.js
Source/WebCore/Modules/modern-media-controls/controls/start-button.js
Source/WebCore/rendering/RenderTheme.h
Source/WebCore/rendering/RenderThemeMac.h
Source/WebCore/rendering/RenderThemeMac.mm

index 36359eb..944fa69 100644 (file)
@@ -4,9 +4,9 @@ On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE
 
 
 Checking path to images is computed according to traits
-PASS iconService.urlForIconNameAndLayoutTraits(Icons.Pause, LayoutTraits.macOS).includes("macOS/pause") is true
-PASS iconService.urlForIconNameAndLayoutTraits(Icons.Pause, LayoutTraits.iOS).includes("iOS/pause") is true
-PASS iconService.urlForIconNameAndLayoutTraits(Icons.Pause, LayoutTraits.macOS | LayoutTraits.Fullscreen).includes("macOS/pause-fullscreen") is true
+PASS iconService.imageForIconNameAndLayoutTraits(Icons.Pause, LayoutTraits.macOS).src.includes("macOS/pause@") is true
+PASS iconService.imageForIconNameAndLayoutTraits(Icons.Pause, LayoutTraits.iOS).src.includes("iOS/pause@") is true
+PASS iconService.imageForIconNameAndLayoutTraits(Icons.Pause, LayoutTraits.macOS | LayoutTraits.Fullscreen).src.includes("macOS/pause-fullscreen@") is true
 
 Checking requested images are cached
 PASS iconService.imageForIconNameAndLayoutTraits(Icons.Pause, LayoutTraits.macOS) === iconService.imageForIconNameAndLayoutTraits(Icons.Pause, LayoutTraits.macOS) is true
index 38a7a29..eb5491b 100644 (file)
@@ -10,9 +10,9 @@ description("Testing the <code>iconService</code> singleton.");
 iconService.directoryPath = "../../../../Source/WebCore/Modules/modern-media-controls/images";
 
 debug("Checking path to images is computed according to traits");
-shouldBeTrue('iconService.urlForIconNameAndLayoutTraits(Icons.Pause, LayoutTraits.macOS).includes("macOS/pause")');
-shouldBeTrue('iconService.urlForIconNameAndLayoutTraits(Icons.Pause, LayoutTraits.iOS).includes("iOS/pause")');
-shouldBeTrue('iconService.urlForIconNameAndLayoutTraits(Icons.Pause, LayoutTraits.macOS | LayoutTraits.Fullscreen).includes("macOS/pause-fullscreen")');
+shouldBeTrue('iconService.imageForIconNameAndLayoutTraits(Icons.Pause, LayoutTraits.macOS).src.includes("macOS/pause@")');
+shouldBeTrue('iconService.imageForIconNameAndLayoutTraits(Icons.Pause, LayoutTraits.iOS).src.includes("iOS/pause@")');
+shouldBeTrue('iconService.imageForIconNameAndLayoutTraits(Icons.Pause, LayoutTraits.macOS | LayoutTraits.Fullscreen).src.includes("macOS/pause-fullscreen@")');
 
 debug("");
 debug("Checking requested images are cached");
index f6c31c8..1a12964 100644 (file)
@@ -1,5 +1,32 @@
 2016-10-17  Antoine Quint  <graouts@apple.com>
 
+        [Modern Media Controls] Add a MediaControlsHost API to retrieve images as base64
+        https://bugs.webkit.org/show_bug.cgi?id=163502
+        <rdar://problem/28792017>
+
+        Reviewed by Darin Adler.
+
+        Add a new `base64StringForIconAndPlatform()` method to MediaControlsHost such that we
+        may load images from the modern-media-controls directory in the WebCore.framework bundle.
+        We use this new method in the iconService singleton when a `mediaControlsHost` is set,
+        which will be set in a later patch.
+
+        * Modules/mediacontrols/MediaControlsHost.cpp:
+        (WebCore::MediaControlsHost::base64StringForIconAndPlatform):
+        * Modules/mediacontrols/MediaControlsHost.h:
+        * Modules/mediacontrols/MediaControlsHost.idl:
+        * Modules/modern-media-controls/controls/icon-service.js:
+        (const.iconService.new.IconService.prototype.urlForIconNameAndLayoutTraits):
+        (const.iconService.new.IconService):
+        * rendering/RenderTheme.h:
+        (WebCore::RenderTheme::mediaControlsBase64StringForIconAndPlatform):
+        (WebCore::RenderTheme::mediaControlsScript): Deleted.
+        * rendering/RenderThemeMac.h:
+        * rendering/RenderThemeMac.mm:
+        (WebCore::RenderThemeMac::mediaControlsBase64StringForIconAndPlatform):
+
+2016-10-17  Antoine Quint  <graouts@apple.com>
+
         [Modern Media Controls] Add a MediaControlsHost API to retrieve the shadow root CSS
         https://bugs.webkit.org/show_bug.cgi?id=163501
         <rdar://problem/28792014>
index ed0cb58..faf51cf 100644 (file)
@@ -292,6 +292,14 @@ String MediaControlsHost::shadowRootCSSText() const
     return RenderTheme::themeForPage(page)->mediaControlsStyleSheet();
 }
 
+String MediaControlsHost::base64StringForIconAndPlatform(const String& iconName, const String& platform) const
+{
+    Page* page = m_mediaElement->document().page();
+    if (!page)
+        return emptyString();
+    return RenderTheme::themeForPage(page)->mediaControlsBase64StringForIconAndPlatform(iconName, platform);
+}
+
 }
 
 #endif
index e8646f8..6f20b3b 100644 (file)
@@ -83,6 +83,7 @@ public:
     String generateUUID() const;
 
     String shadowRootCSSText() const;
+    String base64StringForIconAndPlatform(const String& iconName, const String& platform) const;
 
 private:
     MediaControlsHost(HTMLMediaElement*);
index 48289aa..a6e304e 100644 (file)
@@ -61,4 +61,5 @@ enum DeviceType {
     DOMString generateUUID();
 
     [EnabledAtRuntime=ModernMediaControls] readonly attribute DOMString shadowRootCSSText;
+    [EnabledAtRuntime=ModernMediaControls] DOMString base64StringForIconAndPlatform(DOMString iconName, DOMString platform);
 };
index da931fb..c7a8bb7 100644 (file)
@@ -52,20 +52,30 @@ const iconService = new class IconService {
         this.images = {};
     }
 
+    // Public
+
     imageForIconNameAndLayoutTraits(iconName, layoutTraits)
     {
-        const path = this.urlForIconNameAndLayoutTraits(iconName, layoutTraits);
-        
+        const [fileName, platform] = this._fileNameAndPlatformForIconNameAndLayoutTraits(iconName, layoutTraits);
+        const path = `${platform}/${fileName}.png`;
+
         let image = this.images[path];
         if (image)
             return image;
 
         image = this.images[path] = new Image;
-        image.src = path;
+
+        if (this.mediaControlsHost)
+            image.src = "data:image/png;base64," + this.mediaControlsHost.base64StringForIconAndPlatform(fileName, platform);
+        else
+            image.src = `${this.directoryPath}/${path}`;
+
         return image;
     }
 
-    urlForIconNameAndLayoutTraits(iconName, layoutTraits)
+    // Private
+
+    _fileNameAndPlatformForIconNameAndLayoutTraits(iconName, layoutTraits)
     {
         let platform;
         if (layoutTraits & LayoutTraits.macOS)
@@ -78,7 +88,9 @@ const iconService = new class IconService {
         if (layoutTraits & LayoutTraits.Fullscreen && IconsWithFullScreenVariants.includes(iconName))
             iconName += "-fullscreen";
 
-        return `${this.directoryPath}/${platform}/${iconName}@${window.devicePixelRatio}x.png`;
+        const fileName = `${iconName}@${window.devicePixelRatio}x`;
+
+        return [fileName, platform];
     }
 
 };
index 25b7830..9860c7e 100644 (file)
@@ -36,7 +36,7 @@ class StartButton extends Button
         background.className = "background";
 
         const image = this.element.appendChild(new Image);
-        image.src = iconService.urlForIconNameAndLayoutTraits(Icons.Start, this.layoutTraits);
+        image.src = iconService.imageForIconNameAndLayoutTraits(Icons.Start, this.layoutTraits).src;
     }
 
 }
index 39b97c8..7c6f544 100644 (file)
@@ -101,6 +101,7 @@ public:
     virtual String mediaControlsStyleSheet() { return String(); }
     virtual String extraMediaControlsStyleSheet() { return String(); }
     virtual String mediaControlsScript() { return String(); }
+    virtual String mediaControlsBase64StringForIconAndPlatform(const String&, const String&) { return String(); }
 #endif
 #if ENABLE(FULLSCREEN_API)
     virtual String extraFullScreenStyleSheet() { return String(); }
index 658f883..c594e9b 100644 (file)
@@ -108,6 +108,7 @@ protected:
     // Media controls
     String mediaControlsStyleSheet() override;
     String mediaControlsScript() override;
+    String mediaControlsBase64StringForIconAndPlatform(const String&, const String&) override;
 #endif
 
 #if ENABLE(SERVICE_CONTROLS)
index 244c685..7cb6a17 100644 (file)
@@ -272,6 +272,20 @@ String RenderThemeMac::mediaControlsScript()
 #endif
 }
 
+String RenderThemeMac::mediaControlsBase64StringForIconAndPlatform(const String& iconName, const String& platform)
+{
+#if ENABLE(MEDIA_CONTROLS_SCRIPT)
+    if (!RuntimeEnabledFeatures::sharedFeatures().modernMediaControlsEnabled())
+        return emptyString();
+
+    String directory = "modern-media-controls/images/" + platform;
+    NSBundle *bundle = [NSBundle bundleForClass:[WebCoreRenderThemeBundle class]];
+    return [[NSData dataWithContentsOfFile:[bundle pathForResource:iconName ofType:@"png" inDirectory:directory]] base64EncodedStringWithOptions:0];
+#else
+    return emptyString();
+#endif
+}
+
 #endif // ENABLE(VIDEO)