This source file includes following definitions.
- isKeySystemSupportedWithContentType
- create
- m_weakFactory
- createSession
- isTypeSupported
- setMediaElement
- contentDecryptionModule
- initializeNewSessionTimerFired
- trace
- trace
- contextDestroyed
#include "config.h"
#include "modules/encryptedmedia/MediaKeys.h"
#include "bindings/v8/ExceptionState.h"
#include "core/dom/ContextLifecycleObserver.h"
#include "core/dom/Document.h"
#include "core/dom/ExecutionContext.h"
#include "core/html/HTMLMediaElement.h"
#include "modules/encryptedmedia/MediaKeyMessageEvent.h"
#include "modules/encryptedmedia/MediaKeysClient.h"
#include "modules/encryptedmedia/MediaKeysController.h"
#include "platform/ContentType.h"
#include "platform/Logging.h"
#include "platform/MIMETypeRegistry.h"
#include "platform/UUID.h"
#include "public/platform/Platform.h"
#include "public/platform/WebContentDecryptionModule.h"
#include "wtf/HashSet.h"
namespace WebCore {
static bool isKeySystemSupportedWithContentType(const String& keySystem, const String& contentType)
{
ASSERT(!keySystem.isEmpty());
ContentType type(contentType);
String codecs = type.parameter("codecs");
return MIMETypeRegistry::isSupportedEncryptedMediaMIMEType(keySystem, type.type(), codecs);
}
PassRefPtrWillBeRawPtr<MediaKeys> MediaKeys::create(ExecutionContext* context, const String& keySystem, ExceptionState& exceptionState)
{
if (keySystem.isEmpty()) {
exceptionState.throwDOMException(InvalidAccessError, "The key system provided is invalid.");
return nullptr;
}
if (!isKeySystemSupportedWithContentType(keySystem, "")) {
exceptionState.throwDOMException(NotSupportedError, "The '" + keySystem + "' key system is not supported.");
return nullptr;
}
Document* document = toDocument(context);
MediaKeysController* controller = MediaKeysController::from(document->page());
OwnPtr<blink::WebContentDecryptionModule> cdm = controller->createContentDecryptionModule(context, keySystem);
if (!cdm) {
exceptionState.throwDOMException(NotSupportedError, "A content decryption module could not be loaded for the '" + keySystem + "' key system.");
return nullptr;
}
return adoptRefWillBeNoop(new MediaKeys(context, keySystem, cdm.release()));
}
MediaKeys::MediaKeys(ExecutionContext* context, const String& keySystem, PassOwnPtr<blink::WebContentDecryptionModule> cdm)
: ContextLifecycleObserver(context)
, m_mediaElement(0)
, m_keySystem(keySystem)
, m_cdm(cdm)
, m_initializeNewSessionTimer(this, &MediaKeys::initializeNewSessionTimerFired)
, m_weakFactory(this)
{
WTF_LOG(Media, "MediaKeys::MediaKeys");
ScriptWrappable::init(this);
}
MediaKeys::~MediaKeys()
{
}
PassRefPtrWillBeRawPtr<MediaKeySession> MediaKeys::createSession(ExecutionContext* context, const String& contentType, Uint8Array* initData, ExceptionState& exceptionState)
{
WTF_LOG(Media, "MediaKeys::createSession");
if (contentType.isEmpty()) {
exceptionState.throwDOMException(InvalidAccessError, "The contentType provided ('" + contentType + "') is empty.");
return nullptr;
}
if (!initData || !initData->length()) {
exceptionState.throwDOMException(InvalidAccessError, "The initData provided is null or empty.");
return nullptr;
}
if (!isKeySystemSupportedWithContentType(m_keySystem, contentType)) {
exceptionState.throwDOMException(NotSupportedError, "The type provided ('" + contentType + "') is unsupported.");
return nullptr;
}
RefPtrWillBeRawPtr<MediaKeySession> session = MediaKeySession::create(context, m_cdm.get(), m_weakFactory.createWeakPtr());
ASSERT(!session->keySystem().isEmpty());
m_pendingInitializeNewSessionData.append(InitializeNewSessionData(session, contentType, initData));
if (!m_initializeNewSessionTimer.isActive())
m_initializeNewSessionTimer.startOneShot(0, FROM_HERE);
return session;
}
bool MediaKeys::isTypeSupported(const String& keySystem, const String& contentType)
{
WTF_LOG(Media, "MediaKeys::isTypeSupported(%s, %s)", keySystem.ascii().data(), contentType.ascii().data());
if (keySystem.isEmpty())
return false;
if (!isKeySystemSupportedWithContentType(keySystem, ""))
return false;
if (contentType.isEmpty())
return true;
return isKeySystemSupportedWithContentType(keySystem, contentType);
}
void MediaKeys::setMediaElement(HTMLMediaElement* element)
{
ASSERT(!m_mediaElement != !element);
m_mediaElement = element;
}
blink::WebContentDecryptionModule* MediaKeys::contentDecryptionModule()
{
return m_cdm.get();
}
void MediaKeys::initializeNewSessionTimerFired(Timer<MediaKeys>*)
{
ASSERT(m_pendingInitializeNewSessionData.size());
while (!m_pendingInitializeNewSessionData.isEmpty()) {
InitializeNewSessionData data = m_pendingInitializeNewSessionData.takeFirst();
data.session->initializeNewSession(data.contentType, *data.initData);
}
}
void MediaKeys::trace(Visitor* visitor)
{
visitor->trace(m_pendingInitializeNewSessionData);
}
void MediaKeys::InitializeNewSessionData::trace(Visitor* visitor)
{
visitor->trace(session);
}
void MediaKeys::contextDestroyed()
{
ContextLifecycleObserver::contextDestroyed();
m_cdm.clear();
}
}