Diff
Modified: trunk/LayoutTests/ChangeLog (211856 => 211857)
--- trunk/LayoutTests/ChangeLog 2017-02-08 10:25:23 UTC (rev 211856)
+++ trunk/LayoutTests/ChangeLog 2017-02-08 10:39:49 UTC (rev 211857)
@@ -1,5 +1,26 @@
2017-02-08 Zan Dobersek <[email protected]>
+ [EME] Implement MediaKeySession::remove()
+ https://bugs.webkit.org/show_bug.cgi?id=167870
+
+ Reviewed by Xabier Rodriguez-Calvar.
+
+ Add the mock-MediaKeySession-remove.html test that tests the functionality
+ of the MediaKeySession::remove() implementation. The test checks that the
+ calls to that method properly resolve or reject the returned promise,
+ depending on the object state. Another test checks the message that's
+ queued upon a successful removal.
+
+ Additional tests will be added later once MediaKeySession properly
+ implements the close() method and key status updates.
+
+ * media/encrypted-media/mock-MediaKeySession-remove-expected.txt: Added.
+ * media/encrypted-media/mock-MediaKeySession-remove.html: Added.
+ * platform/efl/TestExpectations:
+ * platform/mac/TestExpectations:
+
+2017-02-08 Zan Dobersek <[email protected]>
+
[EME] Implement MediaKeySession::close()
https://bugs.webkit.org/show_bug.cgi?id=167869
Added: trunk/LayoutTests/media/encrypted-media/mock-MediaKeySession-remove-expected.txt (0 => 211857)
--- trunk/LayoutTests/media/encrypted-media/mock-MediaKeySession-remove-expected.txt (rev 0)
+++ trunk/LayoutTests/media/encrypted-media/mock-MediaKeySession-remove-expected.txt 2017-02-08 10:39:49 UTC (rev 211857)
@@ -0,0 +1,58 @@
+RUN(internals.initializeMockMediaSource())
+RUN(mock = internals.registerMockCDM())
+RUN(mock.supportedDataTypes = ["keyids"])
+RUN(capabilities.initDataTypes = ["keyids"])
+RUN(capabilities.videoCapabilities = [{ contentType: 'video/mock; codecs="mock"' }] )
+RUN(promise = navigator.requestMediaKeySystemAccess("org.webkit.mock", [capabilities]))
+Promise resolved OK
+
+RUN(promise = mediaKeySystemAccess.createMediaKeys())
+Promise resolved OK
+
+Removing from a non-callable MediaKeySession should reject.
+RUN(mediaKeySession = mediaKeys.createSession("temporary"))
+EXPECTED (typeof mediaKeySession == 'object') OK
+RUN(promise = mediaKeySession.remove())
+Promise rejected correctly OK
+
+Removing from a failed MediaKeySession should reject.
+RUN(kids = JSON.stringify({ invalid: "invalid" }))
+RUN(mediaKeySession = mediaKeys.createSession("temporary"))
+RUN(promise = mediaKeySession.generateRequest("keyids", encoder.encode(kids)))
+Promise rejected correctly OK
+RUN(promise = mediaKeySession.remove())
+Promise rejected correctly OK
+
+Removing from a valid MediaKeySession should resolve.
+RUN(kids = JSON.stringify({ kids: [ "MTIzNDU=" ] }))
+RUN(mediaKeySession = mediaKeys.createSession("temporary"))
+RUN(promise = mediaKeySession.generateRequest("keyids", encoder.encode(kids)))
+Promise resolved OK
+RUN(promise = mediaKeySession.remove())
+Promise resolved OK
+
+Removing from a valid MediaKeySession should dispatch a license-release message.
+RUN(kids = JSON.stringify({ kids: [ "MTIzNDU=" ] }))
+RUN(mediaKeySession = mediaKeys.createSession("temporary"))
+RUN(promise = mediaKeySession.generateRequest("keyids", encoder.encode(kids)))
+Promise resolved OK
+RUN(promise = mediaKeySession.remove())
+EXPECTED (event.messageType == 'license-release') OK
+EXPECTED (new Uint8Array(event.message).length == '14') OK
+EXPECTED (new Uint8Array(event.message)[0] == '114') OK
+EXPECTED (new Uint8Array(event.message)[1] == '101') OK
+EXPECTED (new Uint8Array(event.message)[2] == '109') OK
+EXPECTED (new Uint8Array(event.message)[3] == '111') OK
+EXPECTED (new Uint8Array(event.message)[4] == '118') OK
+EXPECTED (new Uint8Array(event.message)[5] == '101') OK
+EXPECTED (new Uint8Array(event.message)[6] == '45') OK
+EXPECTED (new Uint8Array(event.message)[7] == '109') OK
+EXPECTED (new Uint8Array(event.message)[8] == '101') OK
+EXPECTED (new Uint8Array(event.message)[9] == '115') OK
+EXPECTED (new Uint8Array(event.message)[10] == '115') OK
+EXPECTED (new Uint8Array(event.message)[11] == '97') OK
+EXPECTED (new Uint8Array(event.message)[12] == '103') OK
+EXPECTED (new Uint8Array(event.message)[13] == '101') OK
+Promise resolved OK
+END OF TEST
+
Added: trunk/LayoutTests/media/encrypted-media/mock-MediaKeySession-remove.html (0 => 211857)
--- trunk/LayoutTests/media/encrypted-media/mock-MediaKeySession-remove.html (rev 0)
+++ trunk/LayoutTests/media/encrypted-media/mock-MediaKeySession-remove.html 2017-02-08 10:39:49 UTC (rev 211857)
@@ -0,0 +1,109 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <script src=""
+ <script type="text/_javascript_">
+ var mock;
+ var promise;
+ var mediaKeySystemAccess;
+ var mediaKeys;
+ var mediaKeySession;
+ var capabilities = {};
+ var kids;
+ var encoder = new TextEncoder();
+
+ function doTest()
+ {
+ if (!window.internals) {
+ failTest("Internals is required for this test.")
+ return;
+ }
+
+ run('internals.initializeMockMediaSource()');
+ run('mock = internals.registerMockCDM()');
+ run('mock.supportedDataTypes = ["keyids"]');
+ run('capabilities.initDataTypes = ["keyids"]');
+ run(`capabilities.videoCapabilities = [{ contentType: 'video/mock; codecs="mock"' }] `);
+ run('promise = navigator.requestMediaKeySystemAccess("org.webkit.mock", [capabilities])');
+ shouldResolve(promise).then(gotMediaKeySystemAccess, failTest);
+ }
+
+ function next() {
+ if (!tests.length) {
+ mock.unregister();
+ endTest()
+ return;
+ }
+
+ var nextTest = tests.shift();
+ consoleWrite('');
+ nextTest();
+ }
+
+ function gotMediaKeySystemAccess(result) {
+ mediaKeySystemAccess = result;
+ next();
+ }
+
+ function gotMediaKeys(result) {
+ mediaKeys = result;
+ next();
+ }
+
+ tests = [
+ function() {
+ run('promise = mediaKeySystemAccess.createMediaKeys()');
+ shouldResolve(promise).then(gotMediaKeys, failTest);
+ },
+
+ function() {
+ consoleWrite('Removing from a non-callable MediaKeySession should reject.');
+ run('mediaKeySession = mediaKeys.createSession("temporary")');
+ testExpected('typeof mediaKeySession', 'object');
+ run('promise = mediaKeySession.remove()');
+ shouldReject(promise).then(next, next);
+ },
+
+ function() {
+ consoleWrite('Removing from a failed MediaKeySession should reject.');
+ run('kids = JSON.stringify({ invalid: "invalid" })');
+ run('mediaKeySession = mediaKeys.createSession("temporary")');
+ run('promise = mediaKeySession.generateRequest("keyids", encoder.encode(kids))');
+ shouldReject(promise).then(function() {
+ run('promise = mediaKeySession.remove()');
+ shouldReject(promise).then(next, next);
+ }, next);
+ },
+
+ function() {
+ consoleWrite('Removing from a valid MediaKeySession should resolve.');
+ run('kids = JSON.stringify({ kids: [ "MTIzNDU=" ] })');
+ run('mediaKeySession = mediaKeys.createSession("temporary")');
+ run('promise = mediaKeySession.generateRequest("keyids", encoder.encode(kids))');
+ shouldResolve(promise).then(function() {
+ run('promise = mediaKeySession.remove()');
+ shouldResolve(promise).then(next, next);
+ }, next);
+ },
+
+ function() {
+ consoleWrite('Removing from a valid MediaKeySession should dispatch a license-release message.');
+ run('kids = JSON.stringify({ kids: [ "MTIzNDU=" ] })');
+ run('mediaKeySession = mediaKeys.createSession("temporary")');
+ run('promise = mediaKeySession.generateRequest("keyids", encoder.encode(kids))');
+ shouldResolve(promise).then(function() {
+ run('promise = mediaKeySession.remove()');
+ mediaKeySession.addEventListener('message', function(event) {
+ testExpected('event.messageType', 'license-release');
+ testArraysEqual('new Uint8Array(event.message)', encoder.encode("remove-message"));
+
+ shouldResolve(promise).then(next, next);
+ }, true);
+ }, next);
+ },
+ ];
+ </script>
+</head>
+<body _onload_="doTest()">
+</body>
+</html>
Modified: trunk/LayoutTests/platform/efl/TestExpectations (211856 => 211857)
--- trunk/LayoutTests/platform/efl/TestExpectations 2017-02-08 10:25:23 UTC (rev 211856)
+++ trunk/LayoutTests/platform/efl/TestExpectations 2017-02-08 10:39:49 UTC (rev 211857)
@@ -2983,6 +2983,7 @@
Bug(EFL) media/encrypted-media/encrypted-media-syntax.html [ Failure ]
Bug(EFL) media/encrypted-media/mock-MediaKeySession-close.html [ Failure ]
Bug(EFL) media/encrypted-media/mock-MediaKeySession-generateRequest.html [ Failure ]
+Bug(EFL) media/encrypted-media/mock-MediaKeySession-remove.html [ Failure ]
Bug(EFL) media/encrypted-media/mock-MediaKeySession-update.html [ Failure ]
Bug(EFL) media/encrypted-media/mock-MediaKeySystemAccess.html [ Failure ]
Bug(EFL) media/encrypted-media/mock-MediaKeys-createSession.html [ Failure ]
Modified: trunk/LayoutTests/platform/mac/TestExpectations (211856 => 211857)
--- trunk/LayoutTests/platform/mac/TestExpectations 2017-02-08 10:25:23 UTC (rev 211856)
+++ trunk/LayoutTests/platform/mac/TestExpectations 2017-02-08 10:39:49 UTC (rev 211857)
@@ -1494,6 +1494,7 @@
media/encrypted-media/mock-MediaKeys-createSession.html [ Skip ]
media/encrypted-media/mock-MediaKeySession-close.html [ Skip ]
media/encrypted-media/mock-MediaKeySession-generateRequest.html [ Skip ]
+media/encrypted-media/mock-MediaKeySession-remove.html [ Skip ]
media/encrypted-media/mock-MediaKeySession-update.html [ Skip ]
webkit.org/b/166025 http/tests/fetch/fetching-same-resource-with-diffferent-options.html [ Pass Failure ]
Modified: trunk/Source/WebCore/ChangeLog (211856 => 211857)
--- trunk/Source/WebCore/ChangeLog 2017-02-08 10:25:23 UTC (rev 211856)
+++ trunk/Source/WebCore/ChangeLog 2017-02-08 10:39:49 UTC (rev 211857)
@@ -1,5 +1,42 @@
2017-02-08 Zan Dobersek <[email protected]>
+ [EME] Implement MediaKeySession::remove()
+ https://bugs.webkit.org/show_bug.cgi?id=167870
+
+ Reviewed by Xabier Rodriguez-Calvar.
+
+ Implement MediaKeySession::remove() as outlined in the specification.
+
+ The CDMInstance::removeSessionData() virtual method is added. CDMInstance
+ implementors should remove any session data stored for the session that's
+ represented by the passed-in session ID and session type.
+
+ Once the session data is removed, the passed-in callback should be invoked
+ by the CDMInstance object so that MediaKeySession can immediately queue a
+ task in which it updates key statuses and expiration, reject the promise if
+ the data removal failed, or enqueue any license-release message and finally
+ successfully resolve the promise.
+
+ MockCDMFactory gains the removeKeysFromSessionWithID() method that purges
+ the keys for a given session ID. The method is called from
+ MockCDMInstance::removeSessionData() implementation, which passes the
+ removed keys to the RemoveSessionDataCallback, along with a license-release
+ message that is checked in the tests. The key removal itself isn't tested
+ yet because the MediaKeySession's `update key statuses` algorithm isn't
+ implemented yet.
+
+ Test: media/encrypted-media/mock-MediaKeySession-remove.html
+
+ * Modules/encryptedmedia/CDMInstance.h:
+ * Modules/encryptedmedia/MediaKeySession.cpp:
+ (WebCore::MediaKeySession::remove):
+ * testing/MockCDMFactory.cpp:
+ (WebCore::MockCDMFactory::removeKeysFromSessionWithID):
+ (WebCore::MockCDMInstance::removeSessionData):
+ * testing/MockCDMFactory.h:
+
+2017-02-08 Zan Dobersek <[email protected]>
+
[EME] Implement MediaKeySession::close()
https://bugs.webkit.org/show_bug.cgi?id=167869
Modified: trunk/Source/WebCore/Modules/encryptedmedia/CDMInstance.h (211856 => 211857)
--- trunk/Source/WebCore/Modules/encryptedmedia/CDMInstance.h 2017-02-08 10:25:23 UTC (rev 211856)
+++ trunk/Source/WebCore/Modules/encryptedmedia/CDMInstance.h 2017-02-08 10:39:49 UTC (rev 211857)
@@ -69,6 +69,9 @@
using CloseSessionCallback = Function<void()>;
virtual void closeSession(const String& sessionId, CloseSessionCallback) = 0;
+
+ using RemoveSessionDataCallback = Function<void(KeyStatusVector&&, std::optional<Ref<SharedBuffer>>&&, SuccessValue)>;
+ virtual void removeSessionData(const String& sessionId, LicenseType, RemoveSessionDataCallback) = 0;
};
}
Modified: trunk/Source/WebCore/Modules/encryptedmedia/MediaKeySession.cpp (211856 => 211857)
--- trunk/Source/WebCore/Modules/encryptedmedia/MediaKeySession.cpp 2017-02-08 10:25:23 UTC (rev 211856)
+++ trunk/Source/WebCore/Modules/encryptedmedia/MediaKeySession.cpp 2017-02-08 10:39:49 UTC (rev 211857)
@@ -400,9 +400,70 @@
// 6. Return promise.
}
-void MediaKeySession::remove(Ref<DeferredPromise>&&)
+void MediaKeySession::remove(Ref<DeferredPromise>&& promise)
{
- notImplemented();
+ // https://w3c.github.io/encrypted-media/#dom-mediakeysession-remove
+ // W3C Editor's Draft 09 November 2016
+
+ // 1. If this object is closed, return a promise rejected with an InvalidStateError.
+ // 2. If this object's callable value is false, return a promise rejected with an InvalidStateError.
+ if (m_closed || !m_callable) {
+ promise->reject(INVALID_STATE_ERR);
+ return;
+ }
+
+ // 3. Let promise be a new promise.
+ // 4. Run the following steps in parallel:
+ m_taskQueue.enqueueTask([this, promise = WTFMove(promise)] () mutable {
+ // 4.1. Let cdm be the CDM instance represented by this object's cdm instance value.
+ // 4.2. Let message be null.
+ // 4.3. Let message type be null.
+
+ // 4.4. Use the cdm to execute the following steps:
+ m_instance->removeSessionData(m_sessionId, m_sessionType, [this, weakThis = m_weakPtrFactory.createWeakPtr(), promise = WTFMove(promise)] (CDMInstance::KeyStatusVector&& keys, std::optional<Ref<SharedBuffer>>&& message, CDMInstance::SuccessValue succeeded) mutable {
+ if (!weakThis)
+ return;
+
+ // 4.4.1. If any license(s) and/or key(s) are associated with the session:
+ // 4.4.1.1. Destroy the license(s) and/or key(s) associated with the session.
+ // 4.4.1.2. Follow the steps for the value of this object's session type from the following list:
+ // ↳ "temporary"
+ // 4.4.1.2.1.1 Continue with the following steps.
+ // ↳ "persistent-license"
+ // 4.4.1.2.2.1. Let record of license destruction be a record of license destruction for the license represented by this object.
+ // 4.4.1.2.2.2. Store the record of license destruction.
+ // 4.4.1.2.2.3. Let message be a message containing or reflecting the record of license destruction.
+ // ↳ "persistent-usage-record"
+ // 4.4.1.2.3.1. Store this object's record of key usage.
+ // 4.4.1.2.3.2. Let message be a message containing or reflecting this object's record of key usage.
+ // NOTE: Step 4.4.1. should be implemented in CDMInstance.
+
+ // 4.5. Queue a task to run the following steps:
+ m_taskQueue.enqueueTask([this, keys = WTFMove(keys), message = WTFMove(message), succeeded, promise = WTFMove(promise)] () mutable {
+ // 4.5.1. Run the Update Key Statuses algorithm on the session, providing all key ID(s) in the session along with the "released" MediaKeyStatus value for each.
+ updateKeyStatuses(WTFMove(keys));
+
+ // 4.5.2. Run the Update Expiration algorithm on the session, providing NaN.
+ updateExpiration(std::numeric_limits<double>::quiet_NaN());
+
+ // 4.5.3. If any of the preceding steps failed, reject promise with a new DOMException whose name is the appropriate error name.
+ if (succeeded == CDMInstance::SuccessValue::Failed) {
+ promise->reject(NOT_SUPPORTED_ERR);
+ return;
+ }
+
+ // 4.5.4. Let message type be "license-release".
+ // 4.5.5. If message is not null, run the Queue a "message" Event algorithm on the session, providing message type and message.
+ if (message)
+ enqueueMessage(MediaKeyMessageType::LicenseRelease, *message);
+
+ // 4.5.6. Resolve promise.
+ promise->resolve();
+ });
+ });
+ });
+
+ // 5. Return promise.
}
void MediaKeySession::enqueueMessage(MediaKeyMessageType messageType, const SharedBuffer& message)
Modified: trunk/Source/WebCore/testing/MockCDMFactory.cpp (211856 => 211857)
--- trunk/Source/WebCore/testing/MockCDMFactory.cpp 2017-02-08 10:25:23 UTC (rev 211856)
+++ trunk/Source/WebCore/testing/MockCDMFactory.cpp 2017-02-08 10:39:49 UTC (rev 211857)
@@ -72,6 +72,15 @@
value.append(WTFMove(key));
}
+Vector<Ref<SharedBuffer>> MockCDMFactory::removeKeysFromSessionWithID(const String& id)
+{
+ auto it = m_sessions.find(id);
+ if (it == m_sessions.end())
+ return { };
+
+ return WTFMove(it->value);
+}
+
void MockCDMFactory::setSupportedDataTypes(Vector<String>&& types)
{
m_supportedDataTypes.clear();
@@ -301,6 +310,24 @@
callback();
}
+void MockCDMInstance::removeSessionData(const String& id, LicenseType, RemoveSessionDataCallback callback)
+{
+ MockCDMFactory* factory = m_cdm ? m_cdm->factory() : nullptr;
+ if (!factory) {
+ callback({ }, std::nullopt, SuccessValue::Failed);
+ return;
+ }
+
+ auto keys = factory->removeKeysFromSessionWithID(id);
+ KeyStatusVector keyStatusVector;
+ keyStatusVector.reserveInitialCapacity(keys.size());
+ for (auto& key : keys)
+ keyStatusVector.uncheckedAppend({ WTFMove(key), KeyStatus::Released });
+
+ CString message { "remove-message" };
+ callback(WTFMove(keyStatusVector), SharedBuffer::create(message.data(), message.length()), SuccessValue::Succeeded);
}
+}
+
#endif
Modified: trunk/Source/WebCore/testing/MockCDMFactory.h (211856 => 211857)
--- trunk/Source/WebCore/testing/MockCDMFactory.h 2017-02-08 10:25:23 UTC (rev 211856)
+++ trunk/Source/WebCore/testing/MockCDMFactory.h 2017-02-08 10:39:49 UTC (rev 211857)
@@ -72,6 +72,7 @@
bool hasSessionWithID(const String& id) { return m_sessions.contains(id); }
void removeSessionWithID(const String& id) { m_sessions.remove(id); }
void addKeysToSessionWithID(const String& id, Vector<Ref<SharedBuffer>>&&);
+ Vector<Ref<SharedBuffer>> removeKeysFromSessionWithID(const String& id);
private:
MockCDMFactory();
@@ -131,6 +132,7 @@
void requestLicense(LicenseType, const AtomicString& initDataType, Ref<SharedBuffer>&& initData, LicenseCallback) final;
void updateLicense(LicenseType, const SharedBuffer&, LicenseUpdateCallback) final;
void closeSession(const String&, CloseSessionCallback) final;
+ void removeSessionData(const String&, LicenseType, RemoveSessionDataCallback) final;
WeakPtr<MockCDM> m_cdm;
bool m_distinctiveIdentifiersAllowed { true };