[EME] Push CDMFactory into the platform layer
authorzandobersek@gmail.com <zandobersek@gmail.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 4 Aug 2017 09:54:42 +0000 (09:54 +0000)
committerzandobersek@gmail.com <zandobersek@gmail.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 4 Aug 2017 09:54:42 +0000 (09:54 +0000)
https://bugs.webkit.org/show_bug.cgi?id=175129

Reviewed by Xabier Rodriguez-Calvar.

This is a follow-up to r219678 that moved the majority of CDM abstraction
classes into the platform layer, but missed the CDMFactory class.

The CDMFactory abstraction is now also placed in the platform layer. Only
change to the interface is that the createCDM() method can't accept a CDM
object reference anymore since that class is cemented into the WebCore
layer, and no current implementation used it anyway.

Additionally, the static Vector object of registered factories is moved
under the CDMFactory class, along with the register and unregister
functions. The platformRegisterFactories() function is added to allow for
platform-specific factory registrations to occur when the registered
factories are queried for the first time. Empty implementation for this
function is provided for non-GStreamer platforms, while for GStreamer
the implementation is kept in CDMFactoryGStreamer.cpp. It's still empty
for now, but it will register the ClearKey factory there in the near
future.

No new tests -- none affected, only refactoring.

* CMakeLists.txt:
* Modules/encryptedmedia/CDM.cpp:
(WebCore::createCDMPrivateForKeySystem):
(WebCore::CDM::supportsKeySystem):
(WebCore::CDM::CDM):
(): Deleted.
(WebCore::CDM::registerCDMFactory): Deleted.
(WebCore::CDM::unregisterCDMFactory): Deleted.
* Modules/encryptedmedia/CDM.h:
(WebCore::CDMFactory::~CDMFactory): Deleted.
* PlatformWPE.cmake:
* platform/GStreamer.cmake:
* platform/encryptedmedia/CDMFactory.cpp: Added.
(WebCore::CDMFactory::registerFactory):
(WebCore::CDMFactory::unregisterFactory):
(WebCore::CDMFactory::platformRegisterFactories):
* platform/encryptedmedia/CDMFactory.h: Added.
(WebCore::CDMFactory::~CDMFactory):
* platform/encryptedmedia/clearkey/CDMClearKey.cpp:
(WebCore::CDMFactoryClearKey::createCDM):
* platform/encryptedmedia/clearkey/CDMClearKey.h:
* platform/encryptedmedia/gstreamer/CDMFactoryGStreamer.cpp: Added.
(WebCore::CDMFactory::platformRegisterFactories):
* testing/MockCDMFactory.cpp:
(WebCore::m_weakPtrFactory):
(WebCore::MockCDMFactory::unregister):
(WebCore::MockCDMFactory::createCDM):
* testing/MockCDMFactory.h:

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

13 files changed:
Source/WebCore/CMakeLists.txt
Source/WebCore/ChangeLog
Source/WebCore/Modules/encryptedmedia/CDM.cpp
Source/WebCore/Modules/encryptedmedia/CDM.h
Source/WebCore/PlatformWPE.cmake
Source/WebCore/platform/GStreamer.cmake
Source/WebCore/platform/encryptedmedia/CDMFactory.cpp [new file with mode: 0644]
Source/WebCore/platform/encryptedmedia/CDMFactory.h [new file with mode: 0644]
Source/WebCore/platform/encryptedmedia/clearkey/CDMClearKey.cpp
Source/WebCore/platform/encryptedmedia/clearkey/CDMClearKey.h
Source/WebCore/platform/graphics/gstreamer/eme/CDMFactoryGStreamer.cpp [new file with mode: 0644]
Source/WebCore/testing/MockCDMFactory.cpp
Source/WebCore/testing/MockCDMFactory.h

index 3cc9688..d2ad9f3 100644 (file)
@@ -2303,6 +2303,8 @@ set(WebCore_SOURCES
     platform/audio/VectorMath.cpp
     platform/audio/ZeroPole.cpp
 
+    platform/encryptedmedia/CDMFactory.cpp
+
     platform/graphics/BitmapImage.cpp
     platform/graphics/Color.cpp
     platform/graphics/ComplexTextController.cpp
index 3386164..644749f 100644 (file)
@@ -1,3 +1,59 @@
+2017-08-04  Zan Dobersek  <zdobersek@igalia.com>
+
+        [EME] Push CDMFactory into the platform layer
+        https://bugs.webkit.org/show_bug.cgi?id=175129
+
+        Reviewed by Xabier Rodriguez-Calvar.
+
+        This is a follow-up to r219678 that moved the majority of CDM abstraction
+        classes into the platform layer, but missed the CDMFactory class.
+
+        The CDMFactory abstraction is now also placed in the platform layer. Only
+        change to the interface is that the createCDM() method can't accept a CDM
+        object reference anymore since that class is cemented into the WebCore
+        layer, and no current implementation used it anyway.
+
+        Additionally, the static Vector object of registered factories is moved
+        under the CDMFactory class, along with the register and unregister
+        functions. The platformRegisterFactories() function is added to allow for
+        platform-specific factory registrations to occur when the registered
+        factories are queried for the first time. Empty implementation for this
+        function is provided for non-GStreamer platforms, while for GStreamer
+        the implementation is kept in CDMFactoryGStreamer.cpp. It's still empty
+        for now, but it will register the ClearKey factory there in the near
+        future.
+
+        No new tests -- none affected, only refactoring.
+
+        * CMakeLists.txt:
+        * Modules/encryptedmedia/CDM.cpp:
+        (WebCore::createCDMPrivateForKeySystem):
+        (WebCore::CDM::supportsKeySystem):
+        (WebCore::CDM::CDM):
+        (): Deleted.
+        (WebCore::CDM::registerCDMFactory): Deleted.
+        (WebCore::CDM::unregisterCDMFactory): Deleted.
+        * Modules/encryptedmedia/CDM.h:
+        (WebCore::CDMFactory::~CDMFactory): Deleted.
+        * PlatformWPE.cmake:
+        * platform/GStreamer.cmake:
+        * platform/encryptedmedia/CDMFactory.cpp: Added.
+        (WebCore::CDMFactory::registerFactory):
+        (WebCore::CDMFactory::unregisterFactory):
+        (WebCore::CDMFactory::platformRegisterFactories):
+        * platform/encryptedmedia/CDMFactory.h: Added.
+        (WebCore::CDMFactory::~CDMFactory):
+        * platform/encryptedmedia/clearkey/CDMClearKey.cpp:
+        (WebCore::CDMFactoryClearKey::createCDM):
+        * platform/encryptedmedia/clearkey/CDMClearKey.h:
+        * platform/encryptedmedia/gstreamer/CDMFactoryGStreamer.cpp: Added.
+        (WebCore::CDMFactory::platformRegisterFactories):
+        * testing/MockCDMFactory.cpp:
+        (WebCore::m_weakPtrFactory):
+        (WebCore::MockCDMFactory::unregister):
+        (WebCore::MockCDMFactory::createCDM):
+        * testing/MockCDMFactory.h:
+
 2017-08-04  Frederic Wang  <fwang@igalia.com>
 
         ScrollingTreeOverflowScrollingNodeIOS uses the wrong fixed position rectangle
index 6cd7114..98a84ca 100644 (file)
@@ -28,6 +28,7 @@
 
 #if ENABLE(ENCRYPTED_MEDIA)
 
+#include "CDMFactory.h"
 #include "CDMPrivate.h"
 #include "Document.h"
 #include "InitDataRegistry.h"
 
 namespace WebCore {
 
-static Vector<CDMFactory*>& cdmFactories()
-{
-    static NeverDestroyed<Vector<CDMFactory*>> factories;
-    return factories;
-}
-
-void CDM::registerCDMFactory(CDMFactory& factory)
-{
-    ASSERT(!cdmFactories().contains(&factory));
-    cdmFactories().append(&factory);
-}
-
-void CDM::unregisterCDMFactory(CDMFactory& factory)
-{
-    ASSERT(cdmFactories().contains(&factory));
-    cdmFactories().removeAll(&factory);
-}
-
 bool CDM::supportsKeySystem(const String& keySystem)
 {
-    for (auto* factory : cdmFactories()) {
+    for (auto* factory : CDMFactory::registeredFactories()) {
         if (factory->supportsKeySystem(keySystem))
             return true;
     }
@@ -79,9 +62,9 @@ CDM::CDM(Document& document, const String& keySystem)
     , m_weakPtrFactory(this)
 {
     ASSERT(supportsKeySystem(keySystem));
-    for (auto* factory : cdmFactories()) {
+    for (auto* factory : CDMFactory::registeredFactories()) {
         if (factory->supportsKeySystem(keySystem)) {
-            m_private = factory->createCDM(*this);
+            m_private = factory->createCDM();
             break;
         }
     }
index b08baf1..46d53ad 100644 (file)
 
 namespace WebCore {
 
-class CDM;
+class CDMFactory;
 class CDMInstance;
 class CDMPrivate;
 class Document;
 class ScriptExecutionContext;
 class SharedBuffer;
 
-class CDMFactory {
-public:
-    virtual ~CDMFactory() { };
-    virtual std::unique_ptr<CDMPrivate> createCDM(CDM&) = 0;
-    virtual bool supportsKeySystem(const String&) = 0;
-};
-
 class CDM : public RefCounted<CDM>, private ContextDestructionObserver {
 public:
-    WEBCORE_EXPORT static void registerCDMFactory(CDMFactory&);
-    WEBCORE_EXPORT static void unregisterCDMFactory(CDMFactory&);
-
     static bool supportsKeySystem(const String&);
     static bool isPersistentType(MediaKeySessionType);
 
index 748771c..de4a63d 100644 (file)
@@ -150,15 +150,6 @@ list(APPEND WebCorePlatformWPE_SOURCES
     platform/wpe/WidgetWPE.cpp
 )
 
-if (ENABLE_ENCRYPTED_MEDIA)
-    list(APPEND WebCore_INCLUDE_DIRECTORIES
-        "${WEBCORE_DIR}/platform/encryptedmedia/clearkey"
-    )
-    list(APPEND WebCore_SOURCES
-        platform/encryptedmedia/clearkey/CDMClearKey.cpp
-    )
-endif ()
-
 list(APPEND WebCore_USER_AGENT_STYLE_SHEETS
     ${WEBCORE_DIR}/Modules/mediacontrols/mediaControlsBase.css
 )
index 201a843..f72fde9 100644 (file)
@@ -133,8 +133,14 @@ endif ()
 
 if (ENABLE_ENCRYPTED_MEDIA)
     list(APPEND WebCore_INCLUDE_DIRECTORIES
+        "${WEBCORE_DIR}/platform/encryptedmedia/clearkey"
         ${LIBGCRYPT_INCLUDE_DIRS}
     )
+    list(APPEND WebCore_SOURCES
+        platform/encryptedmedia/clearkey/CDMClearKey.cpp
+
+        platform/graphics/gstreamer/eme/CDMFactoryGStreamer.cpp
+    )
     list(APPEND WebCore_LIBRARIES
         ${LIBGCRYPT_LIBRARIES} -lgpg-error
     )
diff --git a/Source/WebCore/platform/encryptedmedia/CDMFactory.cpp b/Source/WebCore/platform/encryptedmedia/CDMFactory.cpp
new file mode 100644 (file)
index 0000000..b286a2e
--- /dev/null
@@ -0,0 +1,67 @@
+/*
+ * Copyright (C) 2016 Apple Inc. All rights reserved.
+ * Copyright (C) 2017 Metrological Group B.V.
+ * Copyright (C) 2017 Igalia S.L.
+ *
+ * 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.
+ */
+
+#include "config.h"
+#include "CDMFactory.h"
+
+#if ENABLE(ENCRYPTED_MEDIA)
+
+#include <mutex>
+#include <wtf/NeverDestroyed.h>
+
+namespace WebCore {
+
+Vector<CDMFactory*>& CDMFactory::registeredFactories()
+{
+    static NeverDestroyed<Vector<CDMFactory*>> factories;
+    static std::once_flag once;
+    std::call_once(once, [&] { platformRegisterFactories(factories); });
+
+    return factories;
+}
+
+void CDMFactory::registerFactory(CDMFactory& factory)
+{
+    ASSERT(!registeredFactories().contains(&factory));
+    registeredFactories().append(&factory);
+}
+
+void CDMFactory::unregisterFactory(CDMFactory& factory)
+{
+    ASSERT(registeredFactories().contains(&factory));
+    registeredFactories().removeAll(&factory);
+}
+
+#if !USE(GSTREAMER)
+void CDMFactory::platformRegisterFactories()
+{
+}
+#endif
+
+} // namespace WebCore
+
+#endif // ENABLE(ENCRYPTED_MEDIA)
diff --git a/Source/WebCore/platform/encryptedmedia/CDMFactory.h b/Source/WebCore/platform/encryptedmedia/CDMFactory.h
new file mode 100644 (file)
index 0000000..1b7e07b
--- /dev/null
@@ -0,0 +1,57 @@
+/*
+ * Copyright (C) 2016 Apple Inc. All rights reserved.
+ * Copyright (C) 2017 Metrological Group B.V.
+ * Copyright (C) 2017 Igalia S.L.
+ *
+ * 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(ENCRYPTED_MEDIA)
+
+#include <memory>
+#include <wtf/Forward.h>
+#include <wtf/Vector.h>
+
+namespace WebCore {
+
+class CDMPrivate;
+
+class CDMFactory {
+public:
+    virtual ~CDMFactory() { };
+    virtual std::unique_ptr<CDMPrivate> createCDM() = 0;
+    virtual bool supportsKeySystem(const String&) = 0;
+
+    static Vector<CDMFactory*>& registeredFactories();
+    WEBCORE_EXPORT static void registerFactory(CDMFactory&);
+    WEBCORE_EXPORT static void unregisterFactory(CDMFactory&);
+
+    // Platform-specific function that's called when the list of
+    // registered CDMFactory objects is queried for the first time.
+    static void platformRegisterFactories(Vector<CDMFactory*>&);
+};
+
+} // namespace WebCore
+
+#endif // ENABLE(ENCRYPTED_MEDIA)
index e62b7af..c87549a 100644 (file)
 
 #if ENABLE(ENCRYPTED_MEDIA)
 
+#include "SharedBuffer.h"
+
 namespace WebCore {
 
 CDMFactoryClearKey::CDMFactoryClearKey() = default;
 CDMFactoryClearKey::~CDMFactoryClearKey() = default;
 
-std::unique_ptr<CDMPrivate> CDMFactoryClearKey::createCDM(CDM&)
+std::unique_ptr<CDMPrivate> CDMFactoryClearKey::createCDM()
 {
     return std::unique_ptr<CDMPrivate>(new CDMPrivateClearKey);
 }
index 847f1e4..4fc10b5 100644 (file)
@@ -30,7 +30,7 @@
 
 #if ENABLE(ENCRYPTED_MEDIA)
 
-#include "CDM.h"
+#include "CDMFactory.h"
 #include "CDMInstance.h"
 #include "CDMPrivate.h"
 
@@ -41,7 +41,7 @@ public:
     CDMFactoryClearKey();
     virtual ~CDMFactoryClearKey();
 
-    std::unique_ptr<CDMPrivate> createCDM(CDM&) override;
+    std::unique_ptr<CDMPrivate> createCDM() override;
     bool supportsKeySystem(const String&) override;
 };
 
diff --git a/Source/WebCore/platform/graphics/gstreamer/eme/CDMFactoryGStreamer.cpp b/Source/WebCore/platform/graphics/gstreamer/eme/CDMFactoryGStreamer.cpp
new file mode 100644 (file)
index 0000000..5c58417
--- /dev/null
@@ -0,0 +1,42 @@
+/*
+ * Copyright (C) 2016 Metrological Group B.V.
+ * Copyright (C) 2016 Igalia S.L.
+ *
+ * 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 THE COPYRIGHT HOLDERS AND 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 THE COPYRIGHT
+ * HOLDER OR 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.
+ */
+
+#include "config.h"
+#include "CDMFactory.h"
+
+#if ENABLE(ENCRYPTED_MEDIA)
+
+namespace WebCore {
+
+void CDMFactory::platformRegisterFactories(Vector<CDMFactory*>& factories)
+{
+}
+
+} // namespace WebCore
+
+#endif // ENABLE(ENCRYPTED_MEDIA)
index 6890065..198c696 100644 (file)
@@ -40,7 +40,7 @@ MockCDMFactory::MockCDMFactory()
     : m_supportedSessionTypes({ MediaKeySessionType::Temporary, MediaKeySessionType::PersistentUsageRecord, MediaKeySessionType::PersistentLicense })
     , m_weakPtrFactory(this)
 {
-    CDM::registerCDMFactory(*this);
+    CDMFactory::registerFactory(*this);
 }
 
 MockCDMFactory::~MockCDMFactory()
@@ -51,7 +51,7 @@ MockCDMFactory::~MockCDMFactory()
 void MockCDMFactory::unregister()
 {
     if (m_registered) {
-        CDM::unregisterCDMFactory(*this);
+        CDMFactory::unregisterFactory(*this);
         m_registered = false;
     }
 }
@@ -96,7 +96,7 @@ void MockCDMFactory::setSupportedDataTypes(Vector<String>&& types)
         m_supportedDataTypes.append(type);
 }
 
-std::unique_ptr<CDMPrivate> MockCDMFactory::createCDM(CDM&)
+std::unique_ptr<CDMPrivate> MockCDMFactory::createCDM()
 {
     return std::make_unique<MockCDM>(m_weakPtrFactory.createWeakPtr());
 }
index cfee400..28ea58d 100644 (file)
@@ -28,6 +28,7 @@
 #if ENABLE(ENCRYPTED_MEDIA)
 
 #include "CDM.h"
+#include "CDMFactory.h"
 #include "CDMInstance.h"
 #include "CDMPrivate.h"
 #include "MediaKeysRequirement.h"
@@ -77,7 +78,7 @@ public:
 
 private:
     MockCDMFactory();
-    std::unique_ptr<CDMPrivate> createCDM(CDM&) final;
+    std::unique_ptr<CDMPrivate> createCDM() final;
     bool supportsKeySystem(const String&) final;
 
     MediaKeysRequirement m_distinctiveIdentifiersRequirement { MediaKeysRequirement::Optional };