Title: [221816] trunk/Source/WebCore
Revision
221816
Author
[email protected]
Date
2017-09-09 05:42:05 -0700 (Sat, 09 Sep 2017)

Log Message

[EME] MediaKeySession: handle MediaKeys association through a WeakPtr
https://bugs.webkit.org/show_bug.cgi?id=176584

Reviewed by Xabier Rodriguez-Calvar.

Don't keep a raw pointer to the originating MediaKeys object in
MediaKeySession that gets nulled out once MediaKeys is destroyed.
Instead, make MediaKeys a WeakPtrFactory and use a WeakPtr<MediaKeys>
object to maintain the association between MediaKeySession and
MediaKeys.

* Modules/encryptedmedia/MediaKeySession.cpp:
(WebCore::MediaKeySession::create):
(WebCore::MediaKeySession::MediaKeySession):
(WebCore::MediaKeySession::detachKeys): Deleted.
* Modules/encryptedmedia/MediaKeySession.h:
* Modules/encryptedmedia/MediaKeys.cpp:
(WebCore::MediaKeys::MediaKeys):
(WebCore::MediaKeys::createSession):
(WebCore::MediaKeys::~MediaKeys): Deleted.
* Modules/encryptedmedia/MediaKeys.h:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (221815 => 221816)


--- trunk/Source/WebCore/ChangeLog	2017-09-09 12:38:48 UTC (rev 221815)
+++ trunk/Source/WebCore/ChangeLog	2017-09-09 12:42:05 UTC (rev 221816)
@@ -1,5 +1,29 @@
 2017-09-09  Zan Dobersek  <[email protected]>
 
+        [EME] MediaKeySession: handle MediaKeys association through a WeakPtr
+        https://bugs.webkit.org/show_bug.cgi?id=176584
+
+        Reviewed by Xabier Rodriguez-Calvar.
+
+        Don't keep a raw pointer to the originating MediaKeys object in
+        MediaKeySession that gets nulled out once MediaKeys is destroyed.
+        Instead, make MediaKeys a WeakPtrFactory and use a WeakPtr<MediaKeys>
+        object to maintain the association between MediaKeySession and
+        MediaKeys.
+
+        * Modules/encryptedmedia/MediaKeySession.cpp:
+        (WebCore::MediaKeySession::create):
+        (WebCore::MediaKeySession::MediaKeySession):
+        (WebCore::MediaKeySession::detachKeys): Deleted.
+        * Modules/encryptedmedia/MediaKeySession.h:
+        * Modules/encryptedmedia/MediaKeys.cpp:
+        (WebCore::MediaKeys::MediaKeys):
+        (WebCore::MediaKeys::createSession):
+        (WebCore::MediaKeys::~MediaKeys): Deleted.
+        * Modules/encryptedmedia/MediaKeys.h:
+
+2017-09-09  Zan Dobersek  <[email protected]>
+
         [GStreamer] Missing GRefPtr adoptions in MediaPlayerPrivateGStreamerBase, PlaybackPipeline
         https://bugs.webkit.org/show_bug.cgi?id=176646
 

Modified: trunk/Source/WebCore/Modules/encryptedmedia/MediaKeySession.cpp (221815 => 221816)


--- trunk/Source/WebCore/Modules/encryptedmedia/MediaKeySession.cpp	2017-09-09 12:38:48 UTC (rev 221815)
+++ trunk/Source/WebCore/Modules/encryptedmedia/MediaKeySession.cpp	2017-09-09 12:42:05 UTC (rev 221816)
@@ -45,16 +45,16 @@
 
 namespace WebCore {
 
-Ref<MediaKeySession> MediaKeySession::create(ScriptExecutionContext& context, MediaKeys& keys, MediaKeySessionType sessionType, bool useDistinctiveIdentifier, Ref<CDM>&& implementation, Ref<CDMInstance>&& instance)
+Ref<MediaKeySession> MediaKeySession::create(ScriptExecutionContext& context, WeakPtr<MediaKeys>&& keys, MediaKeySessionType sessionType, bool useDistinctiveIdentifier, Ref<CDM>&& implementation, Ref<CDMInstance>&& instance)
 {
-    auto session = adoptRef(*new MediaKeySession(context, keys, sessionType, useDistinctiveIdentifier, WTFMove(implementation), WTFMove(instance)));
+    auto session = adoptRef(*new MediaKeySession(context, WTFMove(keys), sessionType, useDistinctiveIdentifier, WTFMove(implementation), WTFMove(instance)));
     session->suspendIfNeeded();
     return session;
 }
 
-MediaKeySession::MediaKeySession(ScriptExecutionContext& context, MediaKeys& keys, MediaKeySessionType sessionType, bool useDistinctiveIdentifier, Ref<CDM>&& implementation, Ref<CDMInstance>&& instance)
+MediaKeySession::MediaKeySession(ScriptExecutionContext& context, WeakPtr<MediaKeys>&& keys, MediaKeySessionType sessionType, bool useDistinctiveIdentifier, Ref<CDM>&& implementation, Ref<CDMInstance>&& instance)
     : ActiveDOMObject(&context)
-    , m_keys(&keys)
+    , m_keys(WTFMove(keys))
     , m_expiration(std::numeric_limits<double>::quiet_NaN())
     , m_keyStatuses(MediaKeyStatusMap::create(*this))
     , m_useDistinctiveIdentifier(useDistinctiveIdentifier)
@@ -92,11 +92,6 @@
     m_keyStatuses->detachSession();
 }
 
-void MediaKeySession::detachKeys()
-{
-    m_keys = nullptr;
-}
-
 const String& MediaKeySession::sessionId() const
 {
     return m_sessionId;

Modified: trunk/Source/WebCore/Modules/encryptedmedia/MediaKeySession.h (221815 => 221816)


--- trunk/Source/WebCore/Modules/encryptedmedia/MediaKeySession.h	2017-09-09 12:38:48 UTC (rev 221815)
+++ trunk/Source/WebCore/Modules/encryptedmedia/MediaKeySession.h	2017-09-09 12:42:05 UTC (rev 221816)
@@ -54,7 +54,7 @@
 
 class MediaKeySession final : public RefCounted<MediaKeySession>, public EventTargetWithInlineData, public ActiveDOMObject {
 public:
-    static Ref<MediaKeySession> create(ScriptExecutionContext&, MediaKeys&, MediaKeySessionType, bool useDistinctiveIdentifier, Ref<CDM>&&, Ref<CDMInstance>&&);
+    static Ref<MediaKeySession> create(ScriptExecutionContext&, WeakPtr<MediaKeys>&&, MediaKeySessionType, bool useDistinctiveIdentifier, Ref<CDM>&&, Ref<CDMInstance>&&);
     virtual ~MediaKeySession();
 
     using RefCounted<MediaKeySession>::ref;
@@ -61,7 +61,6 @@
     using RefCounted<MediaKeySession>::deref;
 
     bool isClosed() const { return m_closed; }
-    void detachKeys();
 
     const String& sessionId() const;
     double expiration() const;
@@ -79,7 +78,7 @@
     const Vector<std::pair<Ref<SharedBuffer>, MediaKeyStatus>>& statuses() const { return m_statuses; }
 
 private:
-    MediaKeySession(ScriptExecutionContext&, MediaKeys&, MediaKeySessionType, bool useDistinctiveIdentifier, Ref<CDM>&&, Ref<CDMInstance>&&);
+    MediaKeySession(ScriptExecutionContext&, WeakPtr<MediaKeys>&&, MediaKeySessionType, bool useDistinctiveIdentifier, Ref<CDM>&&, Ref<CDMInstance>&&);
     void enqueueMessage(MediaKeyMessageType, const SharedBuffer&);
     void updateKeyStatuses(CDMInstance::KeyStatusVector&&);
     void updateExpiration(double);
@@ -97,7 +96,7 @@
     bool canSuspendForDocumentSuspension() const override;
     void stop() override;
 
-    MediaKeys* m_keys;
+    WeakPtr<MediaKeys> m_keys;
     String m_sessionId;
     double m_expiration;
     ClosedPromise m_closedPromise;

Modified: trunk/Source/WebCore/Modules/encryptedmedia/MediaKeys.cpp (221815 => 221816)


--- trunk/Source/WebCore/Modules/encryptedmedia/MediaKeys.cpp	2017-09-09 12:38:48 UTC (rev 221815)
+++ trunk/Source/WebCore/Modules/encryptedmedia/MediaKeys.cpp	2017-09-09 12:42:05 UTC (rev 221816)
@@ -45,14 +45,11 @@
     , m_supportedSessionTypes(supportedSessionTypes)
     , m_implementation(WTFMove(implementation))
     , m_instance(WTFMove(instance))
+    , m_weakPtrFactory(this)
 {
 }
 
-MediaKeys::~MediaKeys()
-{
-    for (auto& session : m_sessions)
-        session->detachKeys();
-}
+MediaKeys::~MediaKeys() = default;
 
 ExceptionOr<Ref<MediaKeySession>> MediaKeys::createSession(ScriptExecutionContext& context, MediaKeySessionType sessionType)
 {
@@ -71,7 +68,7 @@
     // 3. Let session be a new MediaKeySession object, and initialize it as follows:
     // NOTE: Continued in MediaKeySession.
     // 4. Return session.
-    auto session = MediaKeySession::create(context, *this, sessionType, m_useDistinctiveIdentifier, m_implementation.copyRef(), m_instance.copyRef());
+    auto session = MediaKeySession::create(context, m_weakPtrFactory.createWeakPtr(), sessionType, m_useDistinctiveIdentifier, m_implementation.copyRef(), m_instance.copyRef());
     m_sessions.append(session.copyRef());
     return WTFMove(session);
 }

Modified: trunk/Source/WebCore/Modules/encryptedmedia/MediaKeys.h (221815 => 221816)


--- trunk/Source/WebCore/Modules/encryptedmedia/MediaKeys.h	2017-09-09 12:38:48 UTC (rev 221815)
+++ trunk/Source/WebCore/Modules/encryptedmedia/MediaKeys.h	2017-09-09 12:42:05 UTC (rev 221816)
@@ -36,6 +36,7 @@
 #include "MediaKeySessionType.h"
 #include <wtf/Ref.h>
 #include <wtf/RefCounted.h>
+#include <wtf/WeakPtr.h>
 
 namespace WebCore {
 
@@ -75,6 +76,7 @@
     Ref<CDM> m_implementation;
     Ref<CDMInstance> m_instance;
 
+    WeakPtrFactory<MediaKeys> m_weakPtrFactory;
     Vector<Ref<MediaKeySession>> m_sessions;
     Vector<CDMClient*> m_cdmClients;
     GenericTaskQueue<Timer> m_taskQueue;
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to