Title: [206984] trunk/Source/WebCore
Revision
206984
Author
[email protected]
Date
2016-10-09 23:54:21 -0700 (Sun, 09 Oct 2016)

Log Message

Move encrypted media from legacy to new DOM exceptions
https://bugs.webkit.org/show_bug.cgi?id=163194

Reviewed by Youenn Fablet.

* Modules/encryptedmedia/CDM.cpp:
(WebCore::CDM::createSession): Take a reference instead of a pointer.
* Modules/encryptedmedia/CDM.h: Updated for above change.

* Modules/encryptedmedia/legacy/WebKitMediaKeySession.cpp:
(WebCore::WebKitMediaKeySession::create): Take a reference instead of a pointer.
(WebCore::WebKitMediaKeySession::MediaKeySession): Ditto.
(WebCore::WebKitMediaKeySession::~MediaKeySession): Removed unneeded code that
sets m_session to null.
(WebCore::WebKitMediaKeySession::keyRequestTimerFired): Use auto.
(WebCore::WebKitMediaKeySession::update): Use ExceptionOr.
(WebCore::WebKitMediaKeySession::addKeyTimerFired): Use m_keys directly instead
of calling the keys function.
(WebCore::WebKitMediaKeySession::sendError): Set m_error directly instead of
calling the setError function.
(WebCore::WebKitMediaKeySession::mediaKeysStorageDirectory): Use auto.
(WebCore::WebKitMediaKeySession::hasPendingActivity): Check m_session directly
instead of writing !isClosed.
(WebCore::WebKitMediaKeySession::setError): Deleted.

* Modules/encryptedmedia/legacy/WebKitMediaKeySession.h: Use pragma once. Removed
unneeded includes. Changed create to take a reference instead of a pointer.
Made most members and base classes private instead of public. Also removed
a few now-unneeded functions. Made everything that was formerly protected
private instead, since the two are the same in a final class.

* Modules/encryptedmedia/legacy/WebKitMediaKeySession.idl: Removed unneeded comments.
Moved from MayThrowLegacyException to MayThrowException.

* Modules/encryptedmedia/legacy/WebKitMediaKeys.cpp:
(WebCore::WebKitMediaKeys::create): Use ExceptionOr.
(WebCore::WebKitMediaKeys::MediaKeys): Made argument be an rvalue reference.
Also initialize m_mediaElement in the class definition.
(WebCore::WebKitMediaKeys::~MediaKeys): Call detachKeys instead of setKeys(nullptr).
(WebCore::WebKitMediaKeys::createSession): Use ExceptionOr. Also pass reference
insteead of pointer to create. Also removed unneeded separate checks for null
strings in code that already calls isEmpty.
(WebCore::WebKitMediaKeys::isTypeSupported): Removed unneeded checks for null strings
in code that already calls isEmpty.
(WebCore::WebKitMediaKeys::cdmMediaPlayer): Tweaked a bit.
(WebCore::WebKitMediaKeys::cachedKeyForKeyId): Use auto.

* Modules/encryptedmedia/legacy/WebKitMediaKeys.h: Use pragma once. Removed unneeded includes.
Changed cdm() function to return a reference. Initialize m_mediaElement.
Use private instead of protected.

* Modules/encryptedmedia/legacy/WebKitMediaKeys.idl: Use ConstructorMayThrowException
and MayThrowException instead of the legacy versions.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (206983 => 206984)


--- trunk/Source/WebCore/ChangeLog	2016-10-10 06:21:52 UTC (rev 206983)
+++ trunk/Source/WebCore/ChangeLog	2016-10-10 06:54:21 UTC (rev 206984)
@@ -1,3 +1,59 @@
+2016-10-09  Darin Adler  <[email protected]>
+
+        Move encrypted media from legacy to new DOM exceptions
+        https://bugs.webkit.org/show_bug.cgi?id=163194
+
+        Reviewed by Youenn Fablet.
+
+        * Modules/encryptedmedia/CDM.cpp:
+        (WebCore::CDM::createSession): Take a reference instead of a pointer.
+        * Modules/encryptedmedia/CDM.h: Updated for above change.
+
+        * Modules/encryptedmedia/legacy/WebKitMediaKeySession.cpp:
+        (WebCore::WebKitMediaKeySession::create): Take a reference instead of a pointer.
+        (WebCore::WebKitMediaKeySession::MediaKeySession): Ditto.
+        (WebCore::WebKitMediaKeySession::~MediaKeySession): Removed unneeded code that
+        sets m_session to null.
+        (WebCore::WebKitMediaKeySession::keyRequestTimerFired): Use auto.
+        (WebCore::WebKitMediaKeySession::update): Use ExceptionOr.
+        (WebCore::WebKitMediaKeySession::addKeyTimerFired): Use m_keys directly instead
+        of calling the keys function.
+        (WebCore::WebKitMediaKeySession::sendError): Set m_error directly instead of
+        calling the setError function.
+        (WebCore::WebKitMediaKeySession::mediaKeysStorageDirectory): Use auto.
+        (WebCore::WebKitMediaKeySession::hasPendingActivity): Check m_session directly
+        instead of writing !isClosed.
+        (WebCore::WebKitMediaKeySession::setError): Deleted.
+
+        * Modules/encryptedmedia/legacy/WebKitMediaKeySession.h: Use pragma once. Removed
+        unneeded includes. Changed create to take a reference instead of a pointer.
+        Made most members and base classes private instead of public. Also removed
+        a few now-unneeded functions. Made everything that was formerly protected
+        private instead, since the two are the same in a final class.
+
+        * Modules/encryptedmedia/legacy/WebKitMediaKeySession.idl: Removed unneeded comments.
+        Moved from MayThrowLegacyException to MayThrowException.
+
+        * Modules/encryptedmedia/legacy/WebKitMediaKeys.cpp:
+        (WebCore::WebKitMediaKeys::create): Use ExceptionOr.
+        (WebCore::WebKitMediaKeys::MediaKeys): Made argument be an rvalue reference.
+        Also initialize m_mediaElement in the class definition.
+        (WebCore::WebKitMediaKeys::~MediaKeys): Call detachKeys instead of setKeys(nullptr).
+        (WebCore::WebKitMediaKeys::createSession): Use ExceptionOr. Also pass reference
+        insteead of pointer to create. Also removed unneeded separate checks for null
+        strings in code that already calls isEmpty.
+        (WebCore::WebKitMediaKeys::isTypeSupported): Removed unneeded checks for null strings
+        in code that already calls isEmpty.
+        (WebCore::WebKitMediaKeys::cdmMediaPlayer): Tweaked a bit.
+        (WebCore::WebKitMediaKeys::cachedKeyForKeyId): Use auto.
+
+        * Modules/encryptedmedia/legacy/WebKitMediaKeys.h: Use pragma once. Removed unneeded includes.
+        Changed cdm() function to return a reference. Initialize m_mediaElement.
+        Use private instead of protected.
+
+        * Modules/encryptedmedia/legacy/WebKitMediaKeys.idl: Use ConstructorMayThrowException
+        and MayThrowException instead of the legacy versions.
+
 2016-10-09  Zan Dobersek  <[email protected]>
 
         ENABLE_LEGACY_ENCRYPTED_MEDIA interfaces should have a hard-coded WebKit prefix

Modified: trunk/Source/WebCore/Modules/encryptedmedia/CDM.cpp (206983 => 206984)


--- trunk/Source/WebCore/Modules/encryptedmedia/CDM.cpp	2016-10-10 06:21:52 UTC (rev 206983)
+++ trunk/Source/WebCore/Modules/encryptedmedia/CDM.cpp	2016-10-10 06:54:21 UTC (rev 206984)
@@ -131,9 +131,9 @@
     return m_private->supportsMIMEType(mimeType);
 }
 
-std::unique_ptr<CDMSession> CDM::createSession(CDMSessionClient* client)
+std::unique_ptr<CDMSession> CDM::createSession(CDMSessionClient& client)
 {
-    std::unique_ptr<CDMSession> session = m_private->createSession(client);
+    auto session = m_private->createSession(&client);
     if (mediaPlayer())
         mediaPlayer()->setCDMSession(session.get());
     return session;

Modified: trunk/Source/WebCore/Modules/encryptedmedia/CDM.h (206983 => 206984)


--- trunk/Source/WebCore/Modules/encryptedmedia/CDM.h	2016-10-10 06:21:52 UTC (rev 206983)
+++ trunk/Source/WebCore/Modules/encryptedmedia/CDM.h	2016-10-10 06:54:21 UTC (rev 206984)
@@ -23,8 +23,7 @@
  * THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#ifndef CDM_h
-#define CDM_h
+#pragma once
 
 #if ENABLE(LEGACY_ENCRYPTED_MEDIA)
 
@@ -62,7 +61,7 @@
     ~CDM();
 
     bool supportsMIMEType(const String&) const;
-    std::unique_ptr<CDMSession> createSession(CDMSessionClient*);
+    std::unique_ptr<CDMSession> createSession(CDMSessionClient&);
 
     const String& keySystem() const { return m_keySystem; }
 
@@ -80,5 +79,3 @@
 }
 
 #endif // ENABLE(LEGACY_ENCRYPTED_MEDIA)
-
-#endif // CDM_h

Modified: trunk/Source/WebCore/Modules/encryptedmedia/legacy/WebKitMediaKeySession.cpp (206983 => 206984)


--- trunk/Source/WebCore/Modules/encryptedmedia/legacy/WebKitMediaKeySession.cpp	2016-10-10 06:21:52 UTC (rev 206983)
+++ trunk/Source/WebCore/Modules/encryptedmedia/legacy/WebKitMediaKeySession.cpp	2016-10-10 06:54:21 UTC (rev 206984)
@@ -28,13 +28,10 @@
 
 #if ENABLE(LEGACY_ENCRYPTED_MEDIA)
 
-#include "CDM.h"
-#include "CDMSession.h"
 #include "Document.h"
-#include "Event.h"
 #include "EventNames.h"
+#include "ExceptionCode.h"
 #include "FileSystem.h"
-#include "GenericEventQueue.h"
 #include "Settings.h"
 #include "WebKitMediaKeyError.h"
 #include "WebKitMediaKeyMessageEvent.h"
@@ -42,7 +39,7 @@
 
 namespace WebCore {
 
-Ref<WebKitMediaKeySession> WebKitMediaKeySession::create(ScriptExecutionContext& context, WebKitMediaKeys* keys, const String& keySystem)
+Ref<WebKitMediaKeySession> WebKitMediaKeySession::create(ScriptExecutionContext& context, WebKitMediaKeys& keys, const String& keySystem)
 {
     auto session = adoptRef(*new WebKitMediaKeySession(context, keys, keySystem));
     session->suspendIfNeeded();
@@ -49,12 +46,12 @@
     return session;
 }
 
-WebKitMediaKeySession::WebKitMediaKeySession(ScriptExecutionContext& context, WebKitMediaKeys* keys, const String& keySystem)
+WebKitMediaKeySession::WebKitMediaKeySession(ScriptExecutionContext& context, WebKitMediaKeys& keys, const String& keySystem)
     : ActiveDOMObject(&context)
-    , m_keys(keys)
+    , m_keys(&keys)
     , m_keySystem(keySystem)
     , m_asyncEventQueue(*this)
-    , m_session(keys->cdm()->createSession(this))
+    , m_session(keys.cdm().createSession(*this))
     , m_keyRequestTimer(*this, &WebKitMediaKeySession::keyRequestTimerFired)
     , m_addKeyTimer(*this, &WebKitMediaKeySession::addKeyTimerFired)
 {
@@ -62,19 +59,12 @@
 
 WebKitMediaKeySession::~WebKitMediaKeySession()
 {
-    if (m_session) {
+    if (m_session)
         m_session->setClient(nullptr);
-        m_session = nullptr;
-    }
 
     m_asyncEventQueue.cancelAllEvents();
 }
 
-void WebKitMediaKeySession::setError(WebKitMediaKeyError* error)
-{
-    m_error = error;
-}
-
 void WebKitMediaKeySession::close()
 {
     if (m_session)
@@ -104,7 +94,7 @@
         return;
 
     while (!m_pendingKeyRequests.isEmpty()) {
-        PendingKeyRequest request = m_pendingKeyRequests.takeFirst();
+        auto request = m_pendingKeyRequests.takeFirst();
 
         // NOTE: Continued from step 5 in MediaKeys::createSession().
         // The user agent will asynchronously execute the following steps in the task:
@@ -117,7 +107,7 @@
 
         // 3. Use cdm to generate a key request and follow the steps for the first matching condition from the following list:
 
-        RefPtr<Uint8Array> keyRequest = m_session->generateKeyRequest(request.mimeType, request.initData.ptr(), destinationURL, errorCode, systemCode);
+        auto keyRequest = m_session->generateKeyRequest(request.mimeType, request.initData.ptr(), destinationURL, errorCode, systemCode);
 
         // Otherwise [if a request is not successfully generated]:
         if (errorCode) {
@@ -140,20 +130,20 @@
     }
 }
 
-void WebKitMediaKeySession::update(Ref<Uint8Array>&& key, ExceptionCode& ec)
+ExceptionOr<void> WebKitMediaKeySession::update(Ref<Uint8Array>&& key)
 {
     // From <http://dvcs.w3.org/hg/html-media/raw-file/tip/encrypted-media/encrypted-media.html#dom-addkey>:
     // The addKey(key) method must run the following steps:
     // 1. If the first or second argument [sic] is an empty array, throw an INVALID_ACCESS_ERR.
     // NOTE: the reference to a "second argument" is a spec bug.
-    if (!key->length()) {
-        ec = INVALID_ACCESS_ERR;
-        return;
-    }
+    if (!key->length())
+        return Exception { INVALID_ACCESS_ERR };
 
     // 2. Schedule a task to handle the call, providing key.
     m_pendingKeys.append(WTFMove(key));
     m_addKeyTimer.startOneShot(0);
+
+    return { };
 }
 
 void WebKitMediaKeySession::addKeyTimerFired()
@@ -192,7 +182,8 @@
             keyaddedEvent->setTarget(this);
             m_asyncEventQueue.enqueueEvent(WTFMove(keyaddedEvent));
 
-            keys()->keyAdded();
+            ASSERT(m_keys);
+            m_keys->keyAdded();
         }
 
         // 2.8. If any of the preceding steps in the task failed
@@ -216,10 +207,9 @@
     m_asyncEventQueue.enqueueEvent(WTFMove(event));
 }
 
-void WebKitMediaKeySession::sendError(CDMSessionClient::MediaKeyErrorCode errorCode, uint32_t systemCode)
+void WebKitMediaKeySession::sendError(MediaKeyErrorCode errorCode, uint32_t systemCode)
 {
-    Ref<WebKitMediaKeyError> error = WebKitMediaKeyError::create(errorCode, systemCode).get();
-    setError(error.ptr());
+    m_error = WebKitMediaKeyError::create(errorCode, systemCode);
 
     auto keyerrorEvent = Event::create(eventNames().webkitkeyerrorEvent, false, false);
     keyerrorEvent->setTarget(this);
@@ -228,19 +218,19 @@
 
 String WebKitMediaKeySession::mediaKeysStorageDirectory() const
 {
-    Document* document = downcast<Document>(scriptExecutionContext());
+    auto* document = downcast<Document>(scriptExecutionContext());
     if (!document)
         return emptyString();
 
-    Settings* settings = document->settings();
+    auto* settings = document->settings();
     if (!settings)
         return emptyString();
 
-    String storageDirectory = settings->mediaKeysStorageDirectory();
+    auto storageDirectory = settings->mediaKeysStorageDirectory();
     if (storageDirectory.isEmpty())
         return emptyString();
 
-    SecurityOrigin* origin = document->securityOrigin();
+    auto* origin = document->securityOrigin();
     if (!origin)
         return emptyString();
 
@@ -249,7 +239,7 @@
 
 bool WebKitMediaKeySession::hasPendingActivity() const
 {
-    return (m_keys && !isClosed()) || m_asyncEventQueue.hasPendingEvents();
+    return (m_keys && m_session) || m_asyncEventQueue.hasPendingEvents();
 }
 
 void WebKitMediaKeySession::stop()

Modified: trunk/Source/WebCore/Modules/encryptedmedia/legacy/WebKitMediaKeySession.h (206983 => 206984)


--- trunk/Source/WebCore/Modules/encryptedmedia/legacy/WebKitMediaKeySession.h	2016-10-10 06:21:52 UTC (rev 206983)
+++ trunk/Source/WebCore/Modules/encryptedmedia/legacy/WebKitMediaKeySession.h	2016-10-10 06:54:21 UTC (rev 206984)
@@ -23,8 +23,7 @@
  * THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#ifndef WebKitMediaKeySession_h
-#define WebKitMediaKeySession_h
+#pragma once
 
 #if ENABLE(LEGACY_ENCRYPTED_MEDIA)
 
@@ -31,13 +30,11 @@
 #include "ActiveDOMObject.h"
 #include "CDMSession.h"
 #include "EventTarget.h"
-#include "ExceptionCode.h"
+#include "ExceptionOr.h"
 #include "GenericEventQueue.h"
 #include "Timer.h"
 #include <runtime/Uint8Array.h>
 #include <wtf/Deque.h>
-#include <wtf/RefCounted.h>
-#include <wtf/text/WTFString.h>
 
 namespace WebCore {
 
@@ -44,50 +41,48 @@
 class WebKitMediaKeyError;
 class WebKitMediaKeys;
 
-class WebKitMediaKeySession final : public RefCounted<WebKitMediaKeySession>, public EventTargetWithInlineData, public ActiveDOMObject, public CDMSessionClient {
+class WebKitMediaKeySession final : public RefCounted<WebKitMediaKeySession>, public EventTargetWithInlineData, private ActiveDOMObject, private CDMSessionClient {
 public:
-    static Ref<WebKitMediaKeySession> create(ScriptExecutionContext&, WebKitMediaKeys*, const String& keySystem);
+    static Ref<WebKitMediaKeySession> create(ScriptExecutionContext&, WebKitMediaKeys&, const String& keySystem);
     ~WebKitMediaKeySession();
 
+    WebKitMediaKeyError* error() { return m_error.get(); }
     const String& keySystem() const { return m_keySystem; }
-    CDMSession* session() { return m_session.get(); }
     const String& sessionId() const;
+    ExceptionOr<void> update(Ref<Uint8Array>&& key);
+    void close();
 
-    void setError(WebKitMediaKeyError*);
-    WebKitMediaKeyError* error() { return m_error.get(); }
+    CDMSession* session() { return m_session.get(); }
 
-    void setKeys(WebKitMediaKeys* keys) { m_keys = keys; }
-    WebKitMediaKeys* keys() const { return m_keys; }
+    void detachKeys() { m_keys = nullptr; }
 
     void generateKeyRequest(const String& mimeType, Ref<Uint8Array>&& initData);
-    void update(Ref<Uint8Array>&& key, ExceptionCode&);
+    RefPtr<ArrayBuffer> cachedKeyForKeyId(const String& keyId) const;
 
-    bool isClosed() const { return !m_session; }
-    void close();
+    using RefCounted::ref;
+    using RefCounted::deref;
 
-    RefPtr<ArrayBuffer> cachedKeyForKeyId(const String& keyId) const;
+    bool hasPendingActivity() const final;
 
-    using RefCounted<WebKitMediaKeySession>::ref;
-    using RefCounted<WebKitMediaKeySession>::deref;
+private:
+    WebKitMediaKeySession(ScriptExecutionContext&, WebKitMediaKeys&, const String& keySystem);
+    void keyRequestTimerFired();
+    void addKeyTimerFired();
 
-    void enqueueEvent(RefPtr<Event>&&);
+    void sendMessage(Uint8Array*, String destinationURL) final;
+    void sendError(MediaKeyErrorCode, uint32_t systemCode) final;
+    String mediaKeysStorageDirectory() const final;
 
-    EventTargetInterface eventTargetInterface() const override { return WebKitMediaKeySessionEventTargetInterfaceType; }
-    ScriptExecutionContext* scriptExecutionContext() const override { return ActiveDOMObject::scriptExecutionContext(); }
+    void refEventTarget() final { ref(); }
+    void derefEventTarget() final { deref(); }
 
-    // ActiveDOMObject API.
-    bool hasPendingActivity() const override;
+    void stop() final;
+    bool canSuspendForDocumentSuspension() const final;
+    const char* activeDOMObjectName() const final;
 
-protected:
-    WebKitMediaKeySession(ScriptExecutionContext&, WebKitMediaKeys*, const String& keySystem);
-    void keyRequestTimerFired();
-    void addKeyTimerFired();
+    EventTargetInterface eventTargetInterface() const final { return WebKitMediaKeySessionEventTargetInterfaceType; }
+    ScriptExecutionContext* scriptExecutionContext() const final { return ActiveDOMObject::scriptExecutionContext(); }
 
-    // CDMSessionClient
-    void sendMessage(Uint8Array*, String destinationURL) override;
-    void sendError(MediaKeyErrorCode, uint32_t systemCode) override;
-    String mediaKeysStorageDirectory() const override;
-
     WebKitMediaKeys* m_keys;
     String m_keySystem;
     String m_sessionId;
@@ -104,19 +99,8 @@
 
     Deque<Ref<Uint8Array>> m_pendingKeys;
     Timer m_addKeyTimer;
-
-private:
-    void refEventTarget() override { ref(); }
-    void derefEventTarget() override { deref(); }
-
-    // ActiveDOMObject API.
-    void stop() override;
-    bool canSuspendForDocumentSuspension() const override;
-    const char* activeDOMObjectName() const override;
 };
 
 }
 
 #endif // ENABLE(LEGACY_ENCRYPTED_MEDIA)
-
-#endif // WebKitMediaKeySession_h

Modified: trunk/Source/WebCore/Modules/encryptedmedia/legacy/WebKitMediaKeySession.idl (206983 => 206984)


--- trunk/Source/WebCore/Modules/encryptedmedia/legacy/WebKitMediaKeySession.idl	2016-10-10 06:21:52 UTC (rev 206983)
+++ trunk/Source/WebCore/Modules/encryptedmedia/legacy/WebKitMediaKeySession.idl	2016-10-10 06:54:21 UTC (rev 206984)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2013 Apple Inc.  All rights reserved.
+ * Copyright (C) 2013 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -24,18 +24,15 @@
      */
 
 [
+    ActiveDOMObject,
     Conditional=LEGACY_ENCRYPTED_MEDIA,
-    ActiveDOMObject,
 ] interface WebKitMediaKeySession : EventTarget {
-    // error state
     readonly attribute WebKitMediaKeyError error;
 
-    // session properties
     readonly attribute DOMString keySystem;
     readonly attribute DOMString sessionId;
 
-    // session operations
-    [MayThrowLegacyException] void update(Uint8Array key);
+    [MayThrowException] void update(Uint8Array key);
     void close();
     
     attribute EventHandler onwebkitkeyadded;

Modified: trunk/Source/WebCore/Modules/encryptedmedia/legacy/WebKitMediaKeys.cpp (206983 => 206984)


--- trunk/Source/WebCore/Modules/encryptedmedia/legacy/WebKitMediaKeys.cpp	2016-10-10 06:21:52 UTC (rev 206983)
+++ trunk/Source/WebCore/Modules/encryptedmedia/legacy/WebKitMediaKeys.cpp	2016-10-10 06:54:21 UTC (rev 206984)
@@ -28,35 +28,28 @@
 
 #if ENABLE(LEGACY_ENCRYPTED_MEDIA)
 
-#include "CDM.h"
 #include "EventNames.h"
 #include "HTMLMediaElement.h"
-#include "UUID.h"
-#include "WebKitMediaKeyMessageEvent.h"
 #include "WebKitMediaKeySession.h"
 
 namespace WebCore {
 
-RefPtr<WebKitMediaKeys> WebKitMediaKeys::create(const String& keySystem, ExceptionCode& ec)
+ExceptionOr<Ref<WebKitMediaKeys>> WebKitMediaKeys::create(const String& keySystem)
 {
     // From <http://dvcs.w3.org/hg/html-media/raw-file/tip/encrypted-media/encrypted-media.html#dom-media-keys-constructor>:
     // The MediaKeys(keySystem) constructor must run the following steps:
 
     // 1. If keySystem is null or an empty string, throw an INVALID_ACCESS_ERR exception and abort these steps.
-    if (keySystem.isNull() || keySystem.isEmpty()) {
-        ec = INVALID_ACCESS_ERR;
-        return nullptr;
-    }
+    if (keySystem.isEmpty())
+        return Exception { INVALID_ACCESS_ERR };
 
     // 2. If keySystem is not one of the user agent's supported Key Systems, throw a NOT_SUPPORTED_ERR and abort these steps.
-    if (!CDM::supportsKeySystem(keySystem)) {
-        ec = NOT_SUPPORTED_ERR;
-        return nullptr;
-    }
+    if (!CDM::supportsKeySystem(keySystem))
+        return Exception { NOT_SUPPORTED_ERR };
 
     // 3. Let cdm be the content decryption module corresponding to keySystem.
     // 4. Load cdm if necessary.
-    std::unique_ptr<CDM> cdm = CDM::create(keySystem);
+    auto cdm = CDM::create(keySystem);
 
     // 5. Create a new MediaKeys object.
     // 5.1 Let the keySystem attribute be keySystem.
@@ -64,9 +57,8 @@
     return adoptRef(*new WebKitMediaKeys(keySystem, WTFMove(cdm)));
 }
 
-WebKitMediaKeys::WebKitMediaKeys(const String& keySystem, std::unique_ptr<CDM> cdm)
-    : m_mediaElement(nullptr)
-    , m_keySystem(keySystem)
+WebKitMediaKeys::WebKitMediaKeys(const String& keySystem, std::unique_ptr<CDM>&& cdm)
+    : m_keySystem(keySystem)
     , m_cdm(WTFMove(cdm))
 {
     m_cdm->setClient(this);
@@ -78,11 +70,11 @@
     // When destroying a MediaKeys object, follow the steps in close().
     for (auto& session : m_sessions) {
         session->close();
-        session->setKeys(nullptr);
+        session->detachKeys();
     }
 }
 
-RefPtr<WebKitMediaKeySession> WebKitMediaKeys::createSession(ScriptExecutionContext& context, const String& type, Ref<Uint8Array>&& initData, ExceptionCode& ec)
+ExceptionOr<Ref<WebKitMediaKeySession>> WebKitMediaKeys::createSession(ScriptExecutionContext& context, const String& type, Ref<Uint8Array>&& initData)
 {
     // From <http://www.w3.org/TR/2014/WD-encrypted-media-20140218/#dom-createsession>:
     // The createSession(type, initData) method must run the following steps:
@@ -89,28 +81,22 @@
     // Note: The contents of initData are container-specific Initialization Data.
 
     // 1. If contentType is null or an empty string, throw an INVALID_ACCESS_ERR exception and abort these steps.
-    if (type.isEmpty()) {
-        ec = INVALID_ACCESS_ERR;
-        return nullptr;
-    }
+    if (type.isEmpty())
+        return Exception { INVALID_ACCESS_ERR };
 
     // 2. If initData is an empty array, throw an INVALID_ACCESS_ERR exception and abort these steps.
-    if (!initData->length()) {
-        ec = INVALID_ACCESS_ERR;
-        return nullptr;
-    }
+    if (!initData->length())
+        return Exception { INVALID_ACCESS_ERR };
 
     // 3. If type contains a MIME type that is not supported or is not supported by the keySystem, throw
     // a NOT_SUPPORTED_ERR exception and abort these steps.
-    if (!type.isNull() && !type.isEmpty() && !m_cdm->supportsMIMEType(type)) {
-        ec = NOT_SUPPORTED_ERR;
-        return nullptr;
-    }
+    if (!m_cdm->supportsMIMEType(type))
+        return Exception { NOT_SUPPORTED_ERR };
 
     // 4. Create a new MediaKeySession object.
     // 4.1 Let the keySystem attribute be keySystem.
     // 4.2 Let the sessionId attribute be a unique Session ID string. It may be generated by cdm.
-    auto session = WebKitMediaKeySession::create(context, this, keySystem());
+    auto session = WebKitMediaKeySession::create(context, *this, m_keySystem);
 
     m_sessions.append(session.copyRef());
 
@@ -125,11 +111,11 @@
 {
     // 1. If keySystem contains an unrecognized or unsupported Key System, return false and abort these steps.
     // Key system string comparison is case-sensitive.
-    if (keySystem.isNull() || keySystem.isEmpty() || !CDM::supportsKeySystem(keySystem))
+    if (keySystem.isEmpty() || !CDM::supportsKeySystem(keySystem))
         return false;
 
     // 2. If type is null or an empty string, return true and abort these steps.
-    if (mimeType.isNull() || mimeType.isEmpty())
+    if (mimeType.isEmpty())
         return true;
 
     // 3. If the Key System specified by keySystem does not support decrypting the container and/or codec
@@ -154,9 +140,9 @@
 
 MediaPlayer* WebKitMediaKeys::cdmMediaPlayer(const CDM*) const
 {
-    if (m_mediaElement)
-        return m_mediaElement->player();
-    return 0;
+    if (!m_mediaElement)
+        return nullptr;
+    return m_mediaElement->player();
 }
 
 void WebKitMediaKeys::keyAdded()
@@ -163,13 +149,12 @@
 {
     if (m_mediaElement)
         m_mediaElement->keyAdded();
-
 }
 
 RefPtr<ArrayBuffer> WebKitMediaKeys::cachedKeyForKeyId(const String& keyId) const
 {
     for (auto& session : m_sessions) {
-        if (RefPtr<ArrayBuffer> key = session->cachedKeyForKeyId(keyId))
+        if (auto key = session->cachedKeyForKeyId(keyId))
             return key;
     }
     return nullptr;

Modified: trunk/Source/WebCore/Modules/encryptedmedia/legacy/WebKitMediaKeys.h (206983 => 206984)


--- trunk/Source/WebCore/Modules/encryptedmedia/legacy/WebKitMediaKeys.h	2016-10-10 06:21:52 UTC (rev 206983)
+++ trunk/Source/WebCore/Modules/encryptedmedia/legacy/WebKitMediaKeys.h	2016-10-10 06:54:21 UTC (rev 206984)
@@ -23,51 +23,44 @@
  * THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#ifndef WebKitMediaKeys_h
-#define WebKitMediaKeys_h
+#pragma once
 
 #if ENABLE(LEGACY_ENCRYPTED_MEDIA)
 
 #include "CDM.h"
-#include "EventTarget.h"
-#include "ExceptionCode.h"
+#include "ExceptionOr.h"
 #include <runtime/Uint8Array.h>
-#include <wtf/RefCounted.h>
 #include <wtf/Vector.h>
-#include <wtf/text/WTFString.h>
 
 namespace WebCore {
 
 class HTMLMediaElement;
+class ScriptExecutionContext;
 class WebKitMediaKeySession;
 
-class WebKitMediaKeys : public RefCounted<WebKitMediaKeys>, public CDMClient {
+class WebKitMediaKeys final : public RefCounted<WebKitMediaKeys>, private CDMClient {
 public:
-    static RefPtr<WebKitMediaKeys> create(const String& keySystem, ExceptionCode&);
+    static ExceptionOr<Ref<WebKitMediaKeys>> create(const String& keySystem);
     virtual ~WebKitMediaKeys();
 
-    RefPtr<WebKitMediaKeySession> createSession(ScriptExecutionContext&, const String& mimeType, Ref<Uint8Array>&& initData, ExceptionCode&);
-
+    ExceptionOr<Ref<WebKitMediaKeySession>> createSession(ScriptExecutionContext&, const String& mimeType, Ref<Uint8Array>&& initData);
     static bool isTypeSupported(const String& keySystem, const String& mimeType);
-
     const String& keySystem() const { return m_keySystem; }
-    CDM* cdm() { return m_cdm.get(); }
 
-    HTMLMediaElement* mediaElement() const { return m_mediaElement; }
+    CDM& cdm() { ASSERT(m_cdm); return *m_cdm; }
+
     void setMediaElement(HTMLMediaElement*);
 
     void keyAdded();
     RefPtr<ArrayBuffer> cachedKeyForKeyId(const String& keyId) const;
 
-protected:
-    // CDMClient:
-    MediaPlayer* cdmMediaPlayer(const CDM*) const override;
+private:
+    MediaPlayer* cdmMediaPlayer(const CDM*) const final;
 
-    WebKitMediaKeys(const String& keySystem, std::unique_ptr<CDM>);
+    WebKitMediaKeys(const String& keySystem, std::unique_ptr<CDM>&&);
 
     Vector<Ref<WebKitMediaKeySession>> m_sessions;
-
-    HTMLMediaElement* m_mediaElement;
+    HTMLMediaElement* m_mediaElement { nullptr };
     String m_keySystem;
     std::unique_ptr<CDM> m_cdm;
 };
@@ -75,5 +68,3 @@
 }
 
 #endif // ENABLE(LEGACY_ENCRYPTED_MEDIA)
-
-#endif // WebKitMediaKeys_h

Modified: trunk/Source/WebCore/Modules/encryptedmedia/legacy/WebKitMediaKeys.idl (206983 => 206984)


--- trunk/Source/WebCore/Modules/encryptedmedia/legacy/WebKitMediaKeys.idl	2016-10-10 06:21:52 UTC (rev 206983)
+++ trunk/Source/WebCore/Modules/encryptedmedia/legacy/WebKitMediaKeys.idl	2016-10-10 06:54:21 UTC (rev 206984)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2013 Apple Inc.  All rights reserved.
+ * Copyright (C) 2013 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -26,9 +26,9 @@
 [
     Conditional=LEGACY_ENCRYPTED_MEDIA,
     Constructor(DOMString keySystem),
-    ConstructorMayThrowLegacyException,
+    ConstructorMayThrowException,
 ] interface WebKitMediaKeys {
-    [CallWith=ScriptExecutionContext, MayThrowLegacyException] WebKitMediaKeySession createSession(DOMString type, Uint8Array initData);
+    [CallWith=ScriptExecutionContext, MayThrowException] WebKitMediaKeySession createSession(DOMString type, Uint8Array initData);
     static boolean isTypeSupported(DOMString keySystem, optional DOMString type);
     readonly attribute DOMString keySystem;
 };
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to