[Cocoa] Register Alternate WebM Player skeleton
https://bugs.webkit.org/show_bug.cgi?id=241769
<rdar://95542551>

Patch by Youssef Soliman <youssefdevelops@gmail.com> on 2022-06-22
Reviewed by Eric Carlson.

Added the alternate WebM player skeleton and registered it behind
the internal feature flag.

* Source/WTF/Scripts/Preferences/WebPreferencesInternal.yaml:
* Source/WebCore/PlatformMac.cmake:
* Source/WebCore/SourcesCocoa.txt:
* Source/WebCore/WebCore.xcodeproj/project.pbxproj:
* Source/WebCore/page/RuntimeEnabledFeatures.cpp:
(WebCore::RuntimeEnabledFeatures::setAlternateWebMPlayerEnabled):
* Source/WebCore/page/RuntimeEnabledFeatures.h:
(WebCore::RuntimeEnabledFeatures::alternateWebMPlayerEnabled const):
* Source/WebCore/platform/audio/PlatformMediaSessionManager.cpp:
(WebCore::PlatformMediaSessionManager::setAlternateWebMPlayerEnabled):
(WebCore::PlatformMediaSessionManager::alternateWebMPlayerEnabled):
* Source/WebCore/platform/audio/PlatformMediaSessionManager.h:
* Source/WebCore/platform/graphics/MediaPlayer.cpp:
(WebCore::WTF_REQUIRES_LOCK):
* Source/WebCore/platform/graphics/MediaPlayerEnums.h:
* Source/WebCore/platform/graphics/cocoa/MediaPlayerPrivateWebM.h: Added.
* Source/WebCore/platform/graphics/cocoa/MediaPlayerPrivateWebM.mm: Added.
(WebCore::MediaPlayerPrivateWebM::MediaPlayerPrivateWebM):
(WebCore::MediaPlayerPrivateWebM::~MediaPlayerPrivateWebM):
(WebCore::mimeTypeCache):
(WebCore::MediaPlayerPrivateWebM::getSupportedTypes):
(WebCore::MediaPlayerPrivateWebM::supportsType):
(WebCore::MediaPlayerPrivateWebM::load):
(WebCore::MediaPlayerPrivateWebM::cancelLoad):
(WebCore::MediaPlayerPrivateWebM::platformLayer const):
(WebCore::MediaPlayerPrivateWebM::play):
(WebCore::MediaPlayerPrivateWebM::pause):
(WebCore::MediaPlayerPrivateWebM::setPageIsVisible):
(WebCore::MediaPlayerPrivateWebM::currentMediaTime const):
(WebCore::MediaPlayerPrivateWebM::buffered const):
(WebCore::MediaPlayerPrivateWebM::didLoadingProgress const):
(WebCore::MediaPlayerPrivateWebM::logChannel const):
(WebCore::MediaPlayerPrivateWebM::registerMediaEngine):

Changes were done to the GPUProcessPreferences object to consolidate
all changes when adding a new feature to just one file.

* Source/WebKit/GPUProcess/GPUProcess.cpp:
(WebKit::GPUProcess::updateGPUProcessPreferences):
* Source/WebKit/GPUProcess/GPUProcessPreferences.cpp:
(WebKit::GPUProcessPreferences::GPUProcessPreferences):
(WebKit::GPUProcessPreferences::copyEnabledWebPreferences):
(WebKit::GPUProcessPreferences::encode const):
(WebKit::GPUProcessPreferences::decode):
* Source/WebKit/GPUProcess/GPUProcessPreferences.h:
* Source/WebKit/UIProcess/GPU/GPUProcessProxy.cpp:
(WebKit::GPUProcessProxy::updatePreferences):
* Source/WebKit/WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::updatePreferences):
* Source/WebKit/WebProcess/cocoa/WebProcessCocoa.mm:
(WebKit::WebProcess::platformInitializeWebProcess):

Canonical link: https://commits.webkit.org/251767@main

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@295762 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/Source/WebCore/PlatformMac.cmake b/Source/WebCore/PlatformMac.cmake
index c5eb6c9..24185fd 100644
--- a/Source/WebCore/PlatformMac.cmake
+++ b/Source/WebCore/PlatformMac.cmake
@@ -666,6 +666,7 @@
     platform/graphics/cocoa/GraphicsContextGLIOSurfaceSwapChain.h
     platform/graphics/cocoa/IOSurface.h
     platform/graphics/cocoa/MediaPlaybackTargetContext.h
+    platform/graphics/cocoa/MediaPlayerPrivateWebM.h
     platform/graphics/cocoa/SourceBufferParser.h
     platform/graphics/cocoa/SourceBufferParserWebM.h
     platform/graphics/cocoa/VP9UtilitiesCocoa.h
diff --git a/Source/WebCore/SourcesCocoa.txt b/Source/WebCore/SourcesCocoa.txt
index d63c1d2..0c77d35 100644
--- a/Source/WebCore/SourcesCocoa.txt
+++ b/Source/WebCore/SourcesCocoa.txt
@@ -408,6 +408,7 @@
 platform/graphics/cocoa/IntRectCocoa.mm
 platform/graphics/cocoa/MediaEngineConfigurationFactoryCocoa.cpp
 platform/graphics/cocoa/MediaPlaybackTargetContext.mm
+platform/graphics/cocoa/MediaPlayerPrivateWebM.mm
 platform/graphics/cocoa/SourceBufferParser.cpp
 platform/graphics/cocoa/SourceBufferParserWebM.cpp
 platform/graphics/cocoa/SystemFontDatabaseCocoa.mm
diff --git a/Source/WebCore/WebCore.xcodeproj/project.pbxproj b/Source/WebCore/WebCore.xcodeproj/project.pbxproj
index 0bde451..63bc51d 100644
--- a/Source/WebCore/WebCore.xcodeproj/project.pbxproj
+++ b/Source/WebCore/WebCore.xcodeproj/project.pbxproj
@@ -10671,6 +10671,8 @@
 		5A67F23B284966AC00964D2E /* TrackBuffer.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = TrackBuffer.cpp; sourceTree = "<group>"; };
 		5A67F23C284966AC00964D2E /* TrackBuffer.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = TrackBuffer.h; sourceTree = "<group>"; };
 		5A91469E8E9F8485C37A2876 /* JSSVGGraphicsElement.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = JSSVGGraphicsElement.cpp; sourceTree = "<group>"; };
+		5AEBAD8A283583AE0069741F /* MediaPlayerPrivateWebM.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = MediaPlayerPrivateWebM.mm; sourceTree = "<group>"; };
+		5AEBAD8B283583AE0069741F /* MediaPlayerPrivateWebM.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MediaPlayerPrivateWebM.h; sourceTree = "<group>"; };
 		5B1E0E4325D1629B00272281 /* ScrollingEffectsController.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = ScrollingEffectsController.mm; sourceTree = "<group>"; };
 		5B30695A18B3D3450099D5E8 /* WebGLDrawBuffers.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WebGLDrawBuffers.cpp; sourceTree = "<group>"; };
 		5B30695B18B3D3450099D5E8 /* WebGLDrawBuffers.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebGLDrawBuffers.h; sourceTree = "<group>"; };
@@ -29620,6 +29622,8 @@
 				CDC48AC72149CF2A0024FD59 /* MediaEngineConfigurationFactoryCocoa.h */,
 				07F876831AD4A94500905849 /* MediaPlaybackTargetContext.h */,
 				1D008AA5262108C000EE3ADE /* MediaPlaybackTargetContext.mm */,
+				5AEBAD8B283583AE0069741F /* MediaPlayerPrivateWebM.h */,
+				5AEBAD8A283583AE0069741F /* MediaPlayerPrivateWebM.mm */,
 				31647FA8251616BD0010F8FB /* OpenGLSoftLinkCocoa.h */,
 				31647FA9251616BD0010F8FB /* OpenGLSoftLinkCocoa.mm */,
 				CDEB3D7224C41A6E001FBEEF /* SourceBufferParser.cpp */,
diff --git a/Source/WebCore/platform/audio/PlatformMediaSessionManager.cpp b/Source/WebCore/platform/audio/PlatformMediaSessionManager.cpp
index fa61cde..cea5068 100644
--- a/Source/WebCore/platform/audio/PlatformMediaSessionManager.cpp
+++ b/Source/WebCore/platform/audio/PlatformMediaSessionManager.cpp
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2013-2021 Apple Inc. All rights reserved.
+ * Copyright (C) 2013-2022 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -47,6 +47,10 @@
 bool PlatformMediaSessionManager::m_opusDecoderEnabled;
 #endif
 
+#if ENABLE(ALTERNATE_WEBM_PLAYER)
+bool PlatformMediaSessionManager::m_alternateWebMPlayerEnabled;
+#endif
+
 #if ENABLE(VP9)
 bool PlatformMediaSessionManager::m_vp9DecoderEnabled;
 bool PlatformMediaSessionManager::m_vp8DecoderEnabled;
@@ -695,6 +699,24 @@
 #endif
 }
 
+void PlatformMediaSessionManager::setAlternateWebMPlayerEnabled(bool enabled)
+{
+#if ENABLE(ALTERNATE_WEBM_PLAYER)
+    m_alternateWebMPlayerEnabled = enabled;
+#else
+    UNUSED_PARAM(enabled);
+#endif
+}
+
+bool PlatformMediaSessionManager::alternateWebMPlayerEnabled()
+{
+#if ENABLE(ALTERNATE_WEBM_PLAYER)
+    return m_alternateWebMPlayerEnabled;
+#else
+    return false;
+#endif
+}
+
 #if ENABLE(VP9)
 void PlatformMediaSessionManager::setShouldEnableVP9Decoder(bool vp9DecoderEnabled)
 {
diff --git a/Source/WebCore/platform/audio/PlatformMediaSessionManager.h b/Source/WebCore/platform/audio/PlatformMediaSessionManager.h
index e3f034e..31011b8 100644
--- a/Source/WebCore/platform/audio/PlatformMediaSessionManager.h
+++ b/Source/WebCore/platform/audio/PlatformMediaSessionManager.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2013-2021 Apple Inc. All rights reserved.
+ * Copyright (C) 2013-2022 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -60,6 +60,8 @@
     WEBCORE_EXPORT static bool vorbisDecoderEnabled();
     WEBCORE_EXPORT static void setOpusDecoderEnabled(bool);
     WEBCORE_EXPORT static bool opusDecoderEnabled();
+    WEBCORE_EXPORT static void setAlternateWebMPlayerEnabled(bool);
+    WEBCORE_EXPORT static bool alternateWebMPlayerEnabled();
 
 #if ENABLE(VP9)
     WEBCORE_EXPORT static void setShouldEnableVP9Decoder(bool);
@@ -231,6 +233,9 @@
 #if ENABLE(OPUS)
     static bool m_opusDecoderEnabled;
 #endif
+#if ENABLE(ALTERNATE_WEBM_PLAYER)
+    static bool m_alternateWebMPlayerEnabled;
+#endif
 
 #if ENABLE(VP9)
     static bool m_vp9DecoderEnabled;
diff --git a/Source/WebCore/platform/graphics/MediaPlayer.cpp b/Source/WebCore/platform/graphics/MediaPlayer.cpp
index 03d9b7a..f6e2dbc 100644
--- a/Source/WebCore/platform/graphics/MediaPlayer.cpp
+++ b/Source/WebCore/platform/graphics/MediaPlayer.cpp
@@ -39,6 +39,7 @@
 #include "MIMETypeRegistry.h"
 #include "MediaPlayerPrivate.h"
 #include "PlatformMediaResourceLoader.h"
+#include "PlatformMediaSessionManager.h"
 #include "PlatformScreen.h"
 #include "PlatformTextTrack.h"
 #include "PlatformTimeRanges.h"
@@ -82,6 +83,10 @@
 #include "MediaPlayerPrivateMediaStreamAVFObjC.h"
 #endif
 
+#if ENABLE(ALTERNATE_WEBM_PLAYER)
+#include "MediaPlayerPrivateWebM.h"
+#endif
+
 #endif // PLATFORM(COCOA)
 
 #if PLATFORM(WIN) && USE(AVFOUNDATION) && !USE(GSTREAMER)
@@ -266,6 +271,15 @@
     if (DeprecatedGlobalSettings::isAVFoundationEnabled()) {
         auto& registerRemoteEngine = registerRemotePlayerCallback();
 
+#if ENABLE(ALTERNATE_WEBM_PLAYER)
+        if (PlatformMediaSessionManager::alternateWebMPlayerEnabled()) {
+            if (registerRemoteEngine)
+                registerRemoteEngine(addMediaEngine, MediaPlayerEnums::MediaEngineIdentifier::CocoaWebM);
+            else
+                MediaPlayerPrivateWebM::registerMediaEngine(addMediaEngine);
+        }
+#endif
+        
 #if PLATFORM(COCOA)
         if (registerRemoteEngine)
             registerRemoteEngine(addMediaEngine, MediaPlayerEnums::MediaEngineIdentifier::AVFoundation);
diff --git a/Source/WebCore/platform/graphics/MediaPlayerEnums.h b/Source/WebCore/platform/graphics/MediaPlayerEnums.h
index 408a01c..f312e4f 100644
--- a/Source/WebCore/platform/graphics/MediaPlayerEnums.h
+++ b/Source/WebCore/platform/graphics/MediaPlayerEnums.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2015-2020 Apple Inc. All rights reserved.
+ * Copyright (C) 2015-2022 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -98,6 +98,7 @@
         HolePunch,
         MediaFoundation,
         MockMSE,
+        CocoaWebM
     };
 
     enum class WirelessPlaybackTargetType : uint8_t {
@@ -232,7 +233,8 @@
         WebCore::MediaPlayerEnums::MediaEngineIdentifier::GStreamerMSE,
         WebCore::MediaPlayerEnums::MediaEngineIdentifier::HolePunch,
         WebCore::MediaPlayerEnums::MediaEngineIdentifier::MediaFoundation,
-        WebCore::MediaPlayerEnums::MediaEngineIdentifier::MockMSE
+        WebCore::MediaPlayerEnums::MediaEngineIdentifier::MockMSE,
+        WebCore::MediaPlayerEnums::MediaEngineIdentifier::CocoaWebM
     >;
 };
 
diff --git a/Source/WebCore/platform/graphics/cocoa/MediaPlayerPrivateWebM.h b/Source/WebCore/platform/graphics/cocoa/MediaPlayerPrivateWebM.h
new file mode 100644
index 0000000..27f5259
--- /dev/null
+++ b/Source/WebCore/platform/graphics/cocoa/MediaPlayerPrivateWebM.h
@@ -0,0 +1,119 @@
+/*
+ * Copyright (C) 2022 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#if ENABLE(ALTERNATE_WEBM_PLAYER)
+
+#include "MediaPlayerPrivate.h"
+#include "PlatformLayer.h"
+#include <wtf/LoggerHelper.h>
+#include <wtf/WeakPtr.h>
+
+namespace WebCore {
+
+class MediaPlayerPrivateWebM
+    : public MediaPlayerPrivateInterface
+    , private LoggerHelper {
+    WTF_MAKE_FAST_ALLOCATED;
+public:
+    MediaPlayerPrivateWebM(MediaPlayer*);
+    ~MediaPlayerPrivateWebM();
+    
+    static void registerMediaEngine(MediaEngineRegistrar);
+    
+    void load(const String&) final;
+    
+#if ENABLE(MEDIA_SOURCE)
+    void load(const URL&, const ContentType&, MediaSourcePrivateClient&) final;
+#endif
+#if ENABLE(MEDIA_STREAM)
+    void load(MediaStreamPrivate&) final;
+#endif
+    
+    void cancelLoad() final;
+    
+    PlatformLayer* platformLayer() const final;
+    
+    void play() final;
+    void pause() final;
+    
+    FloatSize naturalSize() const final { return m_naturalSize; };
+    
+    bool hasAudio() const final { return m_hasAudio; };
+    bool hasVideo() const final { return m_hasVideo; };
+    
+    void setPageIsVisible(bool) final;
+    
+    MediaTime currentMediaTime() const final;
+    MediaTime durationMediaTime() const final { return m_duration; };
+    
+    bool seeking() const final { return m_seeking; };
+    
+    bool paused() const final { return m_paused; };
+    
+    MediaPlayer::NetworkState networkState() const final { return m_networkState; };
+    MediaPlayer::ReadyState readyState() const final { return m_readyState; };
+    
+    std::unique_ptr<PlatformTimeRanges> buffered() const final;
+    
+    bool didLoadingProgress() const final;
+    
+    void paint(GraphicsContext&, const FloatRect&) final { };
+    
+    DestinationColorSpace colorSpace() final { return DestinationColorSpace::SRGB(); };
+    
+    bool supportsAcceleratedRendering() const final { return false; };
+    
+    const Logger& logger() const final { return m_logger.get(); }
+    const char* logClassName() const final { return "MediaPlayerPrivateWebM"; }
+    const void* logIdentifier() const final { return reinterpret_cast<const void*>(m_logIdentifier); }
+    WTFLogChannel& logChannel() const final;
+    
+private:
+    friend class MediaPlayerFactoryWebM;
+    static void getSupportedTypes(HashSet<String, ASCIICaseInsensitiveHash>&);
+    static MediaPlayer::SupportsType supportsType(const MediaEngineSupportParameters&);
+    
+    MediaPlayer* m_player;
+    
+    MediaPlayer::NetworkState m_networkState { MediaPlayer::NetworkState::Empty };
+    MediaPlayer::ReadyState m_readyState { MediaPlayer::ReadyState::HaveNothing };
+    
+    Ref<const Logger> m_logger;
+    const void* m_logIdentifier;
+    
+    FloatSize m_naturalSize;
+    bool m_hasAudio { false };
+    bool m_hasVideo { false };
+    MediaTime m_currentTime;
+    MediaTime m_duration;
+    bool m_seeking { false };
+    bool m_paused { false };
+};
+
+} // namespace WebCore
+
+#endif // ENABLE(ALTERNATE_WEBM_PLAYER)
diff --git a/Source/WebCore/platform/graphics/cocoa/MediaPlayerPrivateWebM.mm b/Source/WebCore/platform/graphics/cocoa/MediaPlayerPrivateWebM.mm
new file mode 100644
index 0000000..f4acb3f
--- /dev/null
+++ b/Source/WebCore/platform/graphics/cocoa/MediaPlayerPrivateWebM.mm
@@ -0,0 +1,165 @@
+/*
+ * Copyright (C) 2022 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import "config.h"
+#import "MediaPlayerPrivateWebM.h"
+
+#if ENABLE(ALTERNATE_WEBM_PLAYER)
+
+#import "Logging.h"
+#import "MediaPlayer.h"
+#import "NotImplemented.h"
+#import "SourceBufferParserWebM.h"
+
+namespace WebCore {
+
+MediaPlayerPrivateWebM::MediaPlayerPrivateWebM(MediaPlayer* player)
+    : m_player(player)
+    , m_logger(player->mediaPlayerLogger())
+    , m_logIdentifier(player->mediaPlayerLogIdentifier())
+{
+    ALWAYS_LOG(LOGIDENTIFIER);
+    UNUSED_VARIABLE(m_player);
+}
+
+MediaPlayerPrivateWebM::~MediaPlayerPrivateWebM()
+{
+    ALWAYS_LOG(LOGIDENTIFIER);
+}
+
+static HashSet<String, ASCIICaseInsensitiveHash>& mimeTypeCache()
+{
+    static NeverDestroyed cache = HashSet<String, ASCIICaseInsensitiveHash>();
+    if (cache->isEmpty()) {
+        auto types = SourceBufferParserWebM::supportedMIMETypes();
+        cache->add(types.begin(), types.end());
+    }
+    return cache;
+}
+
+void MediaPlayerPrivateWebM::getSupportedTypes(HashSet<String, ASCIICaseInsensitiveHash>& types)
+{
+    types = mimeTypeCache();
+}
+
+MediaPlayer::SupportsType MediaPlayerPrivateWebM::supportsType(const MediaEngineSupportParameters& parameters)
+{
+    if (parameters.isMediaSource || parameters.isMediaStream)
+        return MediaPlayer::SupportsType::IsNotSupported;
+    return SourceBufferParserWebM::isContentTypeSupported(parameters.type);
+}
+
+void MediaPlayerPrivateWebM::load(const String&)
+{
+    ALWAYS_LOG(LOGIDENTIFIER);
+}
+
+#if ENABLE(MEDIA_SOURCE)
+void MediaPlayerPrivateWebM::load(const URL&, const ContentType&, MediaSourcePrivateClient&)
+{
+    ERROR_LOG(LOGIDENTIFIER);
+}
+#endif
+
+#if ENABLE(MEDIA_STREAM)
+void MediaPlayerPrivateWebM::load(MediaStreamPrivate&)
+{
+    ERROR_LOG(LOGIDENTIFIER);
+}
+#endif
+
+void MediaPlayerPrivateWebM::cancelLoad()
+{
+    notImplemented();
+}
+
+PlatformLayer* MediaPlayerPrivateWebM::platformLayer() const
+{
+    return nullptr;
+}
+
+void MediaPlayerPrivateWebM::play()
+{
+    notImplemented();
+}
+
+void MediaPlayerPrivateWebM::pause()
+{
+    notImplemented();
+}
+
+void MediaPlayerPrivateWebM::setPageIsVisible(bool)
+{
+    notImplemented();
+}
+
+MediaTime MediaPlayerPrivateWebM::currentMediaTime() const
+{
+    return m_currentTime;
+}
+
+std::unique_ptr<PlatformTimeRanges> MediaPlayerPrivateWebM::buffered() const
+{
+    return makeUnique<PlatformTimeRanges>();
+}
+
+bool MediaPlayerPrivateWebM::didLoadingProgress() const
+{
+    return false;
+}
+
+WTFLogChannel& MediaPlayerPrivateWebM::logChannel() const
+{
+    return LogMedia;
+}
+
+class MediaPlayerFactoryWebM final : public MediaPlayerFactory {
+private:
+    MediaPlayerEnums::MediaEngineIdentifier identifier() const final { return MediaPlayerEnums::MediaEngineIdentifier::CocoaWebM; };
+
+    std::unique_ptr<MediaPlayerPrivateInterface> createMediaEnginePlayer(MediaPlayer* player) const final
+    {
+        return makeUnique<MediaPlayerPrivateWebM>(player);
+    }
+
+    void getSupportedTypes(HashSet<String, ASCIICaseInsensitiveHash>& types) const final
+    {
+        return MediaPlayerPrivateWebM::getSupportedTypes(types);
+    }
+
+    MediaPlayer::SupportsType supportsTypeAndCodecs(const MediaEngineSupportParameters& parameters) const final
+    {
+        return MediaPlayerPrivateWebM::supportsType(parameters);
+    }
+};
+
+void MediaPlayerPrivateWebM::registerMediaEngine(MediaEngineRegistrar registrar)
+{
+    registrar(makeUnique<MediaPlayerFactoryWebM>());
+}
+
+} // namespace WebCore
+
+#endif // ENABLE(ALTERNATE_WEBM_PLAYER)
diff --git a/Source/WebKit/GPUProcess/GPUProcess.cpp b/Source/WebKit/GPUProcess/GPUProcess.cpp
index 5059f01..f7083b4 100644
--- a/Source/WebKit/GPUProcess/GPUProcess.cpp
+++ b/Source/WebKit/GPUProcess/GPUProcess.cpp
@@ -316,6 +316,11 @@
     if (updatePreference(m_preferences.sampleBufferContentKeySessionSupportEnabled, preferences.sampleBufferContentKeySessionSupportEnabled))
         MediaSessionManagerCocoa::setSampleBufferContentKeySessionSupportEnabled(*m_preferences.sampleBufferContentKeySessionSupportEnabled);
 #endif
+    
+#if ENABLE(ALTERNATE_WEBM_PLAYER)
+    if (updatePreference(m_preferences.alternateWebMPlayerEnabled, preferences.alternateWebMPlayerEnabled))
+        PlatformMediaSessionManager::setAlternateWebMPlayerEnabled(*m_preferences.alternateWebMPlayerEnabled);
+#endif
 }
 
 bool GPUProcess::updatePreference(std::optional<bool>& oldPreference, std::optional<bool>& newPreference)
diff --git a/Source/WebKit/GPUProcess/GPUProcessPreferences.cpp b/Source/WebKit/GPUProcess/GPUProcessPreferences.cpp
index 4b9c298..40227ab 100644
--- a/Source/WebKit/GPUProcess/GPUProcessPreferences.cpp
+++ b/Source/WebKit/GPUProcess/GPUProcessPreferences.cpp
@@ -29,6 +29,7 @@
 #if ENABLE(GPU_PROCESS)
 
 #include "ArgumentCoders.h"
+#include "WebPreferences.h"
 
 #if PLATFORM(COCOA)
 #include "ArgumentCodersCF.h"
@@ -38,6 +39,49 @@
 
 GPUProcessPreferences::GPUProcessPreferences() = default;
 
+GPUProcessPreferences::GPUProcessPreferences(const WebPreferences& webPreferences)
+{
+    copyEnabledWebPreferences(webPreferences);
+}
+
+void GPUProcessPreferences::copyEnabledWebPreferences(const WebPreferences& webPreferences)
+{
+#if ENABLE(OPUS)
+    if (webPreferences.opusDecoderEnabled())
+        opusDecoderEnabled = true;
+#endif
+
+#if ENABLE(VORBIS)
+    if (webPreferences.vorbisDecoderEnabled())
+        vorbisDecoderEnabled = true;
+#endif
+
+#if ENABLE(WEBM_FORMAT_READER)
+    if (webPreferences.webMFormatReaderEnabled())
+        webMFormatReaderEnabled = true;
+#endif
+
+#if ENABLE(MEDIA_SOURCE) && ENABLE(VP9)
+    if (webPreferences.webMParserEnabled())
+        webMParserEnabled = true;
+#endif
+
+#if ENABLE(MEDIA_SOURCE) && HAVE(AVSAMPLEBUFFERVIDEOOUTPUT)
+    if (webPreferences.mediaSourceInlinePaintingEnabled())
+        mediaSourceInlinePaintingEnabled = true;
+#endif
+
+#if HAVE(AVCONTENTKEYSPECIFIER)
+    if (webPreferences.sampleBufferContentKeySessionSupportEnabled())
+        sampleBufferContentKeySessionSupportEnabled = true;
+#endif
+        
+#if ENABLE(ALTERNATE_WEBM_PLAYER)
+    if (webPreferences.alternateWebMPlayerEnabled())
+        alternateWebMPlayerEnabled = true;
+#endif
+}
+
 void GPUProcessPreferences::encode(IPC::Encoder& encoder) const
 {
 #if ENABLE(OPUS)
@@ -63,6 +107,10 @@
 #if HAVE(AVCONTENTKEYSPECIFIER)
     encoder << sampleBufferContentKeySessionSupportEnabled;
 #endif
+    
+#if ENABLE(ALTERNATE_WEBM_PLAYER)
+    encoder << alternateWebMPlayerEnabled;
+#endif
 }
 
 bool GPUProcessPreferences::decode(IPC::Decoder& decoder, GPUProcessPreferences& result)
@@ -96,6 +144,12 @@
     if (!decoder.decode(result.sampleBufferContentKeySessionSupportEnabled))
         return false;
 #endif
+    
+#if ENABLE(ALTERNATE_WEBM_PLAYER)
+    if (!decoder.decode(result.alternateWebMPlayerEnabled))
+        return false;
+#endif
+    
     return true;
 }
 
diff --git a/Source/WebKit/GPUProcess/GPUProcessPreferences.h b/Source/WebKit/GPUProcess/GPUProcessPreferences.h
index 17225cf..bbcb952 100644
--- a/Source/WebKit/GPUProcess/GPUProcessPreferences.h
+++ b/Source/WebKit/GPUProcess/GPUProcessPreferences.h
@@ -36,8 +36,12 @@
 
 namespace WebKit {
 
+class WebPreferences;
+
 struct GPUProcessPreferences {
     GPUProcessPreferences();
+    GPUProcessPreferences(const WebPreferences&);
+    void copyEnabledWebPreferences(const WebPreferences&);
     
 #if ENABLE(OPUS)
     std::optional<bool> opusDecoderEnabled;
@@ -62,6 +66,10 @@
 #if HAVE(AVCONTENTKEYSPECIFIER)
     std::optional<bool> sampleBufferContentKeySessionSupportEnabled;
 #endif
+    
+#if ENABLE(ALTERNATE_WEBM_PLAYER)
+    std::optional<bool> alternateWebMPlayerEnabled;
+#endif
 
     void encode(IPC::Encoder&) const;
     static WARN_UNUSED_RETURN bool decode(IPC::Decoder&, GPUProcessPreferences&);
diff --git a/Source/WebKit/UIProcess/GPU/GPUProcessProxy.cpp b/Source/WebKit/UIProcess/GPU/GPUProcessProxy.cpp
index 060aa44..4f92f55 100644
--- a/Source/WebKit/UIProcess/GPU/GPUProcessProxy.cpp
+++ b/Source/WebKit/UIProcess/GPU/GPUProcessProxy.cpp
@@ -634,39 +634,10 @@
     // In practice, all web pages' preferences should agree on these feature flag values.
     GPUProcessPreferences gpuPreferences;
     for (auto page : webProcess.pages()) {
-        auto& preferences = page->preferences();
-        if (!preferences.useGPUProcessForMediaEnabled())
+        auto& webPreferences = page->preferences();
+        if (!webPreferences.useGPUProcessForMediaEnabled())
             continue;
-
-#if ENABLE(OPUS)
-        if (preferences.opusDecoderEnabled())
-            gpuPreferences.opusDecoderEnabled = true;
-#endif
-
-#if ENABLE(VORBIS)
-        if (preferences.vorbisDecoderEnabled())
-            gpuPreferences.vorbisDecoderEnabled = true;
-#endif
-
-#if ENABLE(WEBM_FORMAT_READER)
-        if (preferences.webMFormatReaderEnabled())
-            gpuPreferences.webMFormatReaderEnabled = true;
-#endif
-
-#if ENABLE(MEDIA_SOURCE) && ENABLE(VP9)
-        if (preferences.webMParserEnabled())
-            gpuPreferences.webMParserEnabled = true;
-#endif
-
-#if ENABLE(MEDIA_SOURCE) && HAVE(AVSAMPLEBUFFERVIDEOOUTPUT)
-        if (preferences.mediaSourceInlinePaintingEnabled())
-            gpuPreferences.mediaSourceInlinePaintingEnabled = true;
-#endif
-
-#if HAVE(AVCONTENTKEYSPECIFIER)
-        if (preferences.sampleBufferContentKeySessionSupportEnabled())
-            gpuPreferences.sampleBufferContentKeySessionSupportEnabled = true;
-#endif
+        gpuPreferences.copyEnabledWebPreferences(webPreferences);
     }
     
     send(Messages::GPUProcess::UpdateGPUProcessPreferences(gpuPreferences), 0);
diff --git a/Source/WebKit/WebProcess/WebPage/WebPage.cpp b/Source/WebKit/WebProcess/WebPage/WebPage.cpp
index c97a724..964ec7d 100644
--- a/Source/WebKit/WebProcess/WebPage/WebPage.cpp
+++ b/Source/WebKit/WebProcess/WebPage/WebPage.cpp
@@ -4259,6 +4259,10 @@
     if (isParentProcessAWebBrowser())
         settings.setWebAuthenticationEnabled(true);
 #endif
+    
+#if ENABLE(ALTERNATE_WEBM_PLAYER)
+    PlatformMediaSessionManager::setAlternateWebMPlayerEnabled(settings.alternateWebMPlayerEnabled());
+#endif
 
 #if ENABLE(WEBM_FORMAT_READER)
     PlatformMediaSessionManager::setWebMFormatReaderEnabled(RuntimeEnabledFeatures::sharedFeatures().webMFormatReaderEnabled());