Diff
Modified: trunk/LayoutTests/ChangeLog (262780 => 262781)
--- trunk/LayoutTests/ChangeLog 2020-06-09 07:11:12 UTC (rev 262780)
+++ trunk/LayoutTests/ChangeLog 2020-06-09 08:23:28 UTC (rev 262781)
@@ -1,3 +1,13 @@
+2020-06-09 Xabier Rodriguez Calvar <[email protected]>
+
+ [EME] CDMProxyInstance should not keep CDMInstanceSessions hard referenced
+ https://bugs.webkit.org/show_bug.cgi?id=212689
+
+ Reviewed by Youenn Fablet.
+
+ * media/encrypted-media/clearKey/clearKey-session-life-cycle-expected.txt: Added.
+ * media/encrypted-media/clearKey/clearKey-session-life-cycle.html: Added.
+
2020-06-08 Diego Pino Garcia <[email protected]>
[WPE] Gardening, update test expectations after r262763
Added: trunk/LayoutTests/media/encrypted-media/clearKey/clearKey-session-life-cycle-expected.txt (0 => 262781)
--- trunk/LayoutTests/media/encrypted-media/clearKey/clearKey-session-life-cycle-expected.txt (rev 0)
+++ trunk/LayoutTests/media/encrypted-media/clearKey/clearKey-session-life-cycle-expected.txt 2020-06-09 08:23:28 UTC (rev 262781)
@@ -0,0 +1,10 @@
+
+EME API is supported OK
+EXPECTED (_mediaKeysSystemAccess.keySystem == 'org.w3.clearkey') OK
+EXPECTED (_mediaKeys != 'null') OK
+EXPECTED (typeof _mediaKeys.createSession == 'function') OK
+EXPECTED (_mediaKeySession.constructor.name == 'MediaKeySession') OK
+EXPECTED (internals.mediaKeysInternalInstanceObjectRefCount(_mediaKeys) == '1') OK
+EXPECTED (internals.mediaKeySessionInternalInstanceSessionObjectRefCount(_mediaKeySession) == '1') OK
+END OF TEST
+
Added: trunk/LayoutTests/media/encrypted-media/clearKey/clearKey-session-life-cycle.html (0 => 262781)
--- trunk/LayoutTests/media/encrypted-media/clearKey/clearKey-session-life-cycle.html (rev 0)
+++ trunk/LayoutTests/media/encrypted-media/clearKey/clearKey-session-life-cycle.html 2020-06-09 08:23:28 UTC (rev 262781)
@@ -0,0 +1,47 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <title>Encrypted ClearKey Session life cycles</title>
+ <script src=""
+ <script src=""
+ <script>
+ var _mediaKeysSystemAccess;
+ var _mediaKeys;
+ var _mediaKeySession;
+
+ function runTest() {
+ if (!navigator.requestMediaKeySystemAccess) {
+ logResult(false, "EME API is not supported");
+ return;
+ } else {
+ logResult(true, "EME API is supported");
+ }
+
+ const options = [
+ { initDataTypes: ["cenc"],
+ videoCapabilities: [{contentType : 'video/mp4; codecs="avc1.64001F"'}] }
+ ];
+
+ navigator.requestMediaKeySystemAccess('org.w3.clearkey', options).then(function(access) {
+ _mediaKeysSystemAccess = access;
+ testExpected("_mediaKeysSystemAccess.keySystem", 'org.w3.clearkey');
+ return access.createMediaKeys();
+ }).then(function(result) {
+ _mediaKeys = result;
+ testExpected("_mediaKeys", null, "!=");
+ testExpected("typeof _mediaKeys.createSession", 'function');
+ _mediaKeySession = _mediaKeys.createSession();
+ testExpected("_mediaKeySession.constructor.name", 'MediaKeySession');
+ testExpected("internals.mediaKeysInternalInstanceObjectRefCount(_mediaKeys)", 1);
+ testExpected("internals.mediaKeySessionInternalInstanceSessionObjectRefCount(_mediaKeySession)", 1);
+ endTest();
+ }).catch(function(failure) {
+ failTest(failure);
+ });
+ }
+ </script>
+</head>
+<body _onload_="runTest()">
+ <video></video>
+</body>
+</html>
Modified: trunk/Source/WebCore/ChangeLog (262780 => 262781)
--- trunk/Source/WebCore/ChangeLog 2020-06-09 07:11:12 UTC (rev 262780)
+++ trunk/Source/WebCore/ChangeLog 2020-06-09 08:23:28 UTC (rev 262781)
@@ -1,3 +1,34 @@
+2020-06-09 Xabier Rodriguez Calvar <[email protected]>
+
+ [EME] CDMProxyInstance should not keep CDMInstanceSessions hard referenced
+ https://bugs.webkit.org/show_bug.cgi?id=212689
+
+ Reviewed by Youenn Fablet.
+
+ Sessions are now tracked as WeakPtr inside the CDMInstanceProxy
+ instead of RefPtr because this creates referencing issues as the
+ internal objects should be released when the backing JS object is
+ garbage collected.
+
+ Test: media/encrypted-media/clearKey/clearKey-session-life-cycle.html
+
+ * Modules/encryptedmedia/MediaKeySession.h:
+ * Modules/encryptedmedia/MediaKeySession.idl:
+ * Modules/encryptedmedia/MediaKeys.h:
+ * Modules/encryptedmedia/MediaKeys.idl:
+ * platform/encryptedmedia/CDMProxy.cpp:
+ (WebCore::CDMInstanceProxy::trackSession):
+ * platform/encryptedmedia/CDMProxy.h:
+ (WebCore::CDMInstanceProxy::trackSession):
+ * platform/encryptedmedia/clearkey/CDMClearKey.cpp:
+ (WebCore::CDMInstanceClearKey::createSession):
+ * platform/encryptedmedia/clearkey/CDMClearKey.h:
+ * testing/Internals.cpp:
+ (WebCore::Internals::mediaKeysInternalInstanceObjectRefCount const):
+ (WebCore::Internals::mediaKeySessionInternalInstanceSessionObjectRefCount const):
+ * testing/Internals.h:
+ * testing/Internals.idl:
+
2020-06-09 Sihui Liu <[email protected]>
TextManipulationController range of paragraph may be wrong after r262601
Modified: trunk/Source/WebCore/Modules/encryptedmedia/MediaKeySession.h (262780 => 262781)
--- trunk/Source/WebCore/Modules/encryptedmedia/MediaKeySession.h 2020-06-09 07:11:12 UTC (rev 262780)
+++ trunk/Source/WebCore/Modules/encryptedmedia/MediaKeySession.h 2020-06-09 08:23:28 UTC (rev 262781)
@@ -86,6 +86,8 @@
const Vector<std::pair<Ref<SharedBuffer>, MediaKeyStatus>>& statuses() const { return m_statuses; }
+ unsigned internalInstanceSessionObjectRefCount() const { return m_instanceSession->refCount(); }
+
private:
MediaKeySession(Document&, WeakPtr<MediaKeys>&&, MediaKeySessionType, bool useDistinctiveIdentifier, Ref<CDM>&&, Ref<CDMInstanceSession>&&);
void enqueueMessage(MediaKeyMessageType, const SharedBuffer&);
Modified: trunk/Source/WebCore/Modules/encryptedmedia/MediaKeySession.idl (262780 => 262781)
--- trunk/Source/WebCore/Modules/encryptedmedia/MediaKeySession.idl 2020-06-09 07:11:12 UTC (rev 262780)
+++ trunk/Source/WebCore/Modules/encryptedmedia/MediaKeySession.idl 2020-06-09 08:23:28 UTC (rev 262781)
@@ -30,6 +30,7 @@
ActiveDOMObject,
Conditional=ENCRYPTED_MEDIA,
EnabledAtRuntime=EncryptedMediaAPI,
+ ExportToWrappedFunction,
DisabledByQuirk=hasBrokenEncryptedMediaAPISupport,
] interface MediaKeySession : EventTarget {
readonly attribute DOMString sessionId;
Modified: trunk/Source/WebCore/Modules/encryptedmedia/MediaKeys.h (262780 => 262781)
--- trunk/Source/WebCore/Modules/encryptedmedia/MediaKeys.h 2020-06-09 07:11:12 UTC (rev 262780)
+++ trunk/Source/WebCore/Modules/encryptedmedia/MediaKeys.h 2020-06-09 08:23:28 UTC (rev 262781)
@@ -80,6 +80,8 @@
const void* nextChildIdentifier() const;
#endif
+ unsigned internalInstanceObjectRefCount() const { return m_instance->refCount(); }
+
protected:
MediaKeys(Document&, bool useDistinctiveIdentifier, bool persistentStateAllowed, const Vector<MediaKeySessionType>&, Ref<CDM>&&, Ref<CDMInstance>&&);
Modified: trunk/Source/WebCore/Modules/encryptedmedia/MediaKeys.idl (262780 => 262781)
--- trunk/Source/WebCore/Modules/encryptedmedia/MediaKeys.idl 2020-06-09 07:11:12 UTC (rev 262780)
+++ trunk/Source/WebCore/Modules/encryptedmedia/MediaKeys.idl 2020-06-09 08:23:28 UTC (rev 262781)
@@ -29,6 +29,7 @@
[
Conditional=ENCRYPTED_MEDIA,
EnabledAtRuntime=EncryptedMediaAPI,
+ ExportToWrappedFunction,
DisabledByQuirk=hasBrokenEncryptedMediaAPISupport,
] interface MediaKeys {
[CallWith=Document, MayThrowException] MediaKeySession createSession(optional MediaKeySessionType sessionType = "temporary");
Modified: trunk/Source/WebCore/platform/encryptedmedia/CDMProxy.cpp (262780 => 262781)
--- trunk/Source/WebCore/platform/encryptedmedia/CDMProxy.cpp 2020-06-09 07:11:12 UTC (rev 262780)
+++ trunk/Source/WebCore/platform/encryptedmedia/CDMProxy.cpp 2020-06-09 08:23:28 UTC (rev 262781)
@@ -313,6 +313,12 @@
m_keyStore.removeAllKeysFrom(keyStore);
}
+void CDMInstanceProxy::trackSession(const CDMInstanceSessionProxy& session)
+{
+ ASSERT(!m_sessions.contains(session));
+ m_sessions.add(session);
+}
+
} // namespace WebCore
#endif // ENABLE(ENCRYPTED_MEDIA)
Modified: trunk/Source/WebCore/platform/encryptedmedia/CDMProxy.h (262780 => 262781)
--- trunk/Source/WebCore/platform/encryptedmedia/CDMProxy.h 2020-06-09 07:11:12 UTC (rev 262780)
+++ trunk/Source/WebCore/platform/encryptedmedia/CDMProxy.h 2020-06-09 08:23:28 UTC (rev 262781)
@@ -36,6 +36,7 @@
#include "SharedBuffer.h"
#include <wtf/Condition.h>
#include <wtf/VectorHash.h>
+#include <wtf/WeakHashSet.h>
namespace WebCore {
@@ -155,6 +156,9 @@
KeyStore m_keyStore;
};
+class CDMInstanceSessionProxy : public CDMInstanceSession, public CanMakeWeakPtr<CDMInstanceSessionProxy, WeakPtrFactoryInitialization::Eager> {
+};
+
// Base class for common session management code and for communicating messages
// from "real CDM" state changes to JS.
class CDMInstanceProxy : public CDMInstance {
@@ -185,7 +189,7 @@
void stoppedWaitingForKey();
protected:
- void trackSession(const RefPtr<CDMInstanceSession> session) { m_sessions.append(session); }
+ void trackSession(const CDMInstanceSessionProxy&);
private:
RefPtr<CDMProxy> m_cdmProxy;
@@ -195,7 +199,7 @@
MediaPlayer* m_player { nullptr }; // FIXME: MainThread<T>?
std::atomic<int> m_numDecryptorsWaitingForKey { 0 };
- Vector<RefPtr<CDMInstanceSession>> m_sessions;
+ WeakHashSet<CDMInstanceSessionProxy> m_sessions;
KeyStore m_keyStore;
};
Modified: trunk/Source/WebCore/platform/encryptedmedia/clearkey/CDMClearKey.cpp (262780 => 262781)
--- trunk/Source/WebCore/platform/encryptedmedia/clearkey/CDMClearKey.cpp 2020-06-09 07:11:12 UTC (rev 262780)
+++ trunk/Source/WebCore/platform/encryptedmedia/clearkey/CDMClearKey.cpp 2020-06-09 08:23:28 UTC (rev 262781)
@@ -461,8 +461,8 @@
RefPtr<CDMInstanceSession> CDMInstanceClearKey::createSession()
{
- RefPtr<CDMInstanceSession> newSession = adoptRef(new CDMInstanceSessionClearKey(*this));
- trackSession(newSession);
+ auto newSession = adoptRef(new CDMInstanceSessionClearKey(*this));
+ trackSession(*newSession);
return newSession;
}
Modified: trunk/Source/WebCore/platform/encryptedmedia/clearkey/CDMClearKey.h (262780 => 262781)
--- trunk/Source/WebCore/platform/encryptedmedia/clearkey/CDMClearKey.h 2020-06-09 07:11:12 UTC (rev 262780)
+++ trunk/Source/WebCore/platform/encryptedmedia/clearkey/CDMClearKey.h 2020-06-09 08:23:28 UTC (rev 262781)
@@ -104,7 +104,7 @@
RefPtr<CDMInstanceSession> createSession() final;
};
-class CDMInstanceSessionClearKey final : public CDMInstanceSession, public CanMakeWeakPtr<CDMInstanceSessionClearKey> {
+class CDMInstanceSessionClearKey final : public CDMInstanceSessionProxy {
public:
CDMInstanceSessionClearKey(CDMInstanceClearKey& parent)
: m_parentInstance(parent) { }
Modified: trunk/Source/WebCore/testing/Internals.cpp (262780 => 262781)
--- trunk/Source/WebCore/testing/Internals.cpp 2020-06-09 07:11:12 UTC (rev 262780)
+++ trunk/Source/WebCore/testing/Internals.cpp 2020-06-09 08:23:28 UTC (rev 262781)
@@ -5765,5 +5765,16 @@
#endif
+#if ENABLE(ENCRYPTED_MEDIA)
+unsigned Internals::mediaKeysInternalInstanceObjectRefCount(const MediaKeys& mediaKeys) const
+{
+ return mediaKeys.internalInstanceObjectRefCount();
+}
+unsigned Internals::mediaKeySessionInternalInstanceSessionObjectRefCount(const MediaKeySession& mediaKeySession) const
+{
+ return mediaKeySession.internalInstanceSessionObjectRefCount();
+}
+#endif
+
} // namespace WebCore
Modified: trunk/Source/WebCore/testing/Internals.h (262780 => 262781)
--- trunk/Source/WebCore/testing/Internals.h 2020-06-09 07:11:12 UTC (rev 262780)
+++ trunk/Source/WebCore/testing/Internals.h 2020-06-09 08:23:28 UTC (rev 262781)
@@ -48,6 +48,11 @@
#include "MediaElementSession.h"
#endif
+#if ENABLE(ENCRYPTED_MEDIA)
+#include "MediaKeySession.h"
+#include "MediaKeys.h"
+#endif
+
namespace WebCore {
class AnimationTimeline;
@@ -1019,6 +1024,11 @@
ExceptionOr<RefPtr<WebXRTest>> xrTest();
#endif
+#if ENABLE(ENCRYPTED_MEDIA)
+ unsigned mediaKeysInternalInstanceObjectRefCount(const MediaKeys&) const;
+ unsigned mediaKeySessionInternalInstanceSessionObjectRefCount(const MediaKeySession&) const;
+#endif
+
private:
explicit Internals(Document&);
Document* contextDocument() const;
Modified: trunk/Source/WebCore/testing/Internals.idl (262780 => 262781)
--- trunk/Source/WebCore/testing/Internals.idl 2020-06-09 07:11:12 UTC (rev 262780)
+++ trunk/Source/WebCore/testing/Internals.idl 2020-06-09 08:23:28 UTC (rev 262781)
@@ -913,4 +913,7 @@
boolean destroySleepDisabler(unsigned long identifier);
[Conditional=WEBXR, MayThrowException] readonly attribute WebXRTest xrTest;
+
+ [Conditional=ENCRYPTED_MEDIA] unsigned long mediaKeysInternalInstanceObjectRefCount(MediaKeys mediaKeys);
+ [Conditional=ENCRYPTED_MEDIA] unsigned long mediaKeySessionInternalInstanceSessionObjectRefCount(MediaKeySession session);
};