| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2013 Apple Inc. All rights reserved. | 2 * Copyright (C) 2013 Apple Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 #include "core/dom/ExecutionContext.h" | 32 #include "core/dom/ExecutionContext.h" |
| 33 #include "core/html/HTMLMediaElement.h" | 33 #include "core/html/HTMLMediaElement.h" |
| 34 #include "modules/encryptedmedia/EncryptedMediaUtils.h" | 34 #include "modules/encryptedmedia/EncryptedMediaUtils.h" |
| 35 #include "modules/encryptedmedia/MediaKeySession.h" | 35 #include "modules/encryptedmedia/MediaKeySession.h" |
| 36 #include "modules/encryptedmedia/SimpleContentDecryptionModuleResultPromise.h" | 36 #include "modules/encryptedmedia/SimpleContentDecryptionModuleResultPromise.h" |
| 37 #include "platform/Logging.h" | 37 #include "platform/Logging.h" |
| 38 #include "platform/Timer.h" | 38 #include "platform/Timer.h" |
| 39 #include "public/platform/WebContentDecryptionModule.h" | 39 #include "public/platform/WebContentDecryptionModule.h" |
| 40 #include "wtf/RefPtr.h" | 40 #include "wtf/RefPtr.h" |
| 41 | 41 |
| 42 #define MEDIA_KEYS_LOG_LEVEL 3 |
| 43 |
| 42 namespace blink { | 44 namespace blink { |
| 43 | 45 |
| 44 // A class holding a pending action. | 46 // A class holding a pending action. |
| 45 class MediaKeys::PendingAction final : public GarbageCollected<MediaKeys::Pendin
gAction> { | 47 class MediaKeys::PendingAction final : public GarbageCollected<MediaKeys::Pendin
gAction> { |
| 46 public: | 48 public: |
| 47 const Persistent<ContentDecryptionModuleResult> result() const | 49 const Persistent<ContentDecryptionModuleResult> result() const |
| 48 { | 50 { |
| 49 return m_result; | 51 return m_result; |
| 50 } | 52 } |
| 51 | 53 |
| 52 DOMArrayBuffer* data() const | 54 DOMArrayBuffer* data() const |
| 53 { | 55 { |
| 54 return m_data; | 56 return m_data; |
| 55 } | 57 } |
| 56 | 58 |
| 57 static PendingAction* CreatePendingSetServerCertificate(ContentDecryptionMod
uleResult* result, DOMArrayBuffer* serverCertificate) | 59 static PendingAction* CreatePendingSetServerCertificate(ContentDecryptionMod
uleResult* result, DOMArrayBuffer* serverCertificate) |
| 58 { | 60 { |
| 59 ASSERT(result); | 61 DCHECK(result); |
| 60 ASSERT(serverCertificate); | 62 DCHECK(serverCertificate); |
| 61 return new PendingAction(result, serverCertificate); | 63 return new PendingAction(result, serverCertificate); |
| 62 } | 64 } |
| 63 | 65 |
| 64 DEFINE_INLINE_TRACE() | 66 DEFINE_INLINE_TRACE() |
| 65 { | 67 { |
| 66 visitor->trace(m_result); | 68 visitor->trace(m_result); |
| 67 visitor->trace(m_data); | 69 visitor->trace(m_data); |
| 68 } | 70 } |
| 69 | 71 |
| 70 private: | 72 private: |
| (...skipping 16 matching lines...) Expand all Loading... |
| 87 | 89 |
| 88 MediaKeys::MediaKeys(ExecutionContext* context, const WebVector<WebEncryptedMedi
aSessionType>& supportedSessionTypes, PassOwnPtr<WebContentDecryptionModule> cdm
) | 90 MediaKeys::MediaKeys(ExecutionContext* context, const WebVector<WebEncryptedMedi
aSessionType>& supportedSessionTypes, PassOwnPtr<WebContentDecryptionModule> cdm
) |
| 89 : ActiveScriptWrappable(this) | 91 : ActiveScriptWrappable(this) |
| 90 , ActiveDOMObject(context) | 92 , ActiveDOMObject(context) |
| 91 , m_supportedSessionTypes(supportedSessionTypes) | 93 , m_supportedSessionTypes(supportedSessionTypes) |
| 92 , m_cdm(std::move(cdm)) | 94 , m_cdm(std::move(cdm)) |
| 93 , m_mediaElement(nullptr) | 95 , m_mediaElement(nullptr) |
| 94 , m_reservedForMediaElement(false) | 96 , m_reservedForMediaElement(false) |
| 95 , m_timer(this, &MediaKeys::timerFired) | 97 , m_timer(this, &MediaKeys::timerFired) |
| 96 { | 98 { |
| 97 WTF_LOG(Media, "MediaKeys(%p)::MediaKeys", this); | 99 DVLOG(MEDIA_KEYS_LOG_LEVEL) << __FUNCTION__ << "(" << this << ")"; |
| 98 } | 100 } |
| 99 | 101 |
| 100 MediaKeys::~MediaKeys() | 102 MediaKeys::~MediaKeys() |
| 101 { | 103 { |
| 102 WTF_LOG(Media, "MediaKeys(%p)::~MediaKeys", this); | 104 DVLOG(MEDIA_KEYS_LOG_LEVEL) << __FUNCTION__ << "(" << this << ")"; |
| 103 } | 105 } |
| 104 | 106 |
| 105 MediaKeySession* MediaKeys::createSession(ScriptState* scriptState, const String
& sessionTypeString, ExceptionState& exceptionState) | 107 MediaKeySession* MediaKeys::createSession(ScriptState* scriptState, const String
& sessionTypeString, ExceptionState& exceptionState) |
| 106 { | 108 { |
| 107 WTF_LOG(Media, "MediaKeys(%p)::createSession %s", this, sessionTypeString.ut
f8().data()); | 109 DVLOG(MEDIA_KEYS_LOG_LEVEL) << __FUNCTION__ << "(" << this << ") " << sessio
nTypeString; |
| 108 | 110 |
| 109 // From http://w3c.github.io/encrypted-media/#createSession | 111 // From http://w3c.github.io/encrypted-media/#createSession |
| 110 | 112 |
| 111 // When this method is invoked, the user agent must run the following steps: | 113 // When this method is invoked, the user agent must run the following steps: |
| 112 // 1. If this object's persistent state allowed value is false and | 114 // 1. If this object's persistent state allowed value is false and |
| 113 // sessionType is not "temporary", throw a new DOMException whose name is | 115 // sessionType is not "temporary", throw a new DOMException whose name is |
| 114 // NotSupportedError. | 116 // NotSupportedError. |
| 115 // (Chromium ensures that only session types supported by the | 117 // (Chromium ensures that only session types supported by the |
| 116 // configuration are listed in supportedSessionTypes.) | 118 // configuration are listed in supportedSessionTypes.) |
| 117 // 2. If the Key System implementation represented by this object's cdm | 119 // 2. If the Key System implementation represented by this object's cdm |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 } | 184 } |
| 183 | 185 |
| 184 void MediaKeys::cancelReservation() | 186 void MediaKeys::cancelReservation() |
| 185 { | 187 { |
| 186 m_reservedForMediaElement = false; | 188 m_reservedForMediaElement = false; |
| 187 m_mediaElement.clear(); | 189 m_mediaElement.clear(); |
| 188 } | 190 } |
| 189 | 191 |
| 190 void MediaKeys::clearMediaElement() | 192 void MediaKeys::clearMediaElement() |
| 191 { | 193 { |
| 192 ASSERT(m_mediaElement); | 194 DCHECK(m_mediaElement); |
| 193 m_mediaElement.clear(); | 195 m_mediaElement.clear(); |
| 194 } | 196 } |
| 195 | 197 |
| 196 bool MediaKeys::sessionTypeSupported(WebEncryptedMediaSessionType sessionType) | 198 bool MediaKeys::sessionTypeSupported(WebEncryptedMediaSessionType sessionType) |
| 197 { | 199 { |
| 198 for (size_t i = 0; i < m_supportedSessionTypes.size(); i++) { | 200 for (size_t i = 0; i < m_supportedSessionTypes.size(); i++) { |
| 199 if (m_supportedSessionTypes[i] == sessionType) | 201 if (m_supportedSessionTypes[i] == sessionType) |
| 200 return true; | 202 return true; |
| 201 } | 203 } |
| 202 | 204 |
| 203 return false; | 205 return false; |
| 204 } | 206 } |
| 205 | 207 |
| 206 void MediaKeys::timerFired(Timer<MediaKeys>*) | 208 void MediaKeys::timerFired(Timer<MediaKeys>*) |
| 207 { | 209 { |
| 208 ASSERT(m_pendingActions.size()); | 210 DCHECK(m_pendingActions.size()); |
| 209 | 211 |
| 210 // Swap the queue to a local copy to avoid problems if resolving promises | 212 // Swap the queue to a local copy to avoid problems if resolving promises |
| 211 // run synchronously. | 213 // run synchronously. |
| 212 HeapDeque<Member<PendingAction>> pendingActions; | 214 HeapDeque<Member<PendingAction>> pendingActions; |
| 213 pendingActions.swap(m_pendingActions); | 215 pendingActions.swap(m_pendingActions); |
| 214 | 216 |
| 215 while (!pendingActions.isEmpty()) { | 217 while (!pendingActions.isEmpty()) { |
| 216 PendingAction* action = pendingActions.takeFirst(); | 218 PendingAction* action = pendingActions.takeFirst(); |
| 217 WTF_LOG(Media, "MediaKeys(%p)::timerFired: Certificate", this); | 219 DVLOG(MEDIA_KEYS_LOG_LEVEL) << __FUNCTION__ << "(" << this << ") Certifi
cate"; |
| 218 | 220 |
| 219 // 5.1 Let cdm be the cdm during the initialization of this object. | 221 // 5.1 Let cdm be the cdm during the initialization of this object. |
| 220 WebContentDecryptionModule* cdm = contentDecryptionModule(); | 222 WebContentDecryptionModule* cdm = contentDecryptionModule(); |
| 221 | 223 |
| 222 // 5.2 Use the cdm to process certificate. | 224 // 5.2 Use the cdm to process certificate. |
| 223 cdm->setServerCertificate(static_cast<unsigned char*>(action->data()->da
ta()), action->data()->byteLength(), action->result()->result()); | 225 cdm->setServerCertificate(static_cast<unsigned char*>(action->data()->da
ta()), action->data()->byteLength(), action->result()->result()); |
| 224 // 5.3 If any of the preceding steps failed, reject promise with a | 226 // 5.3 If any of the preceding steps failed, reject promise with a |
| 225 // new DOMException whose name is the appropriate error name. | 227 // new DOMException whose name is the appropriate error name. |
| 226 // 5.4 Resolve promise. | 228 // 5.4 Resolve promise. |
| 227 // (These are handled by Chromium and the CDM.) | 229 // (These are handled by Chromium and the CDM.) |
| (...skipping 17 matching lines...) Expand all Loading... |
| 245 ActiveDOMObject::contextDestroyed(); | 247 ActiveDOMObject::contextDestroyed(); |
| 246 | 248 |
| 247 // We don't need the CDM anymore. Only destroyed after all related | 249 // We don't need the CDM anymore. Only destroyed after all related |
| 248 // ActiveDOMObjects have been stopped. | 250 // ActiveDOMObjects have been stopped. |
| 249 m_cdm.clear(); | 251 m_cdm.clear(); |
| 250 } | 252 } |
| 251 | 253 |
| 252 bool MediaKeys::hasPendingActivity() const | 254 bool MediaKeys::hasPendingActivity() const |
| 253 { | 255 { |
| 254 // Remain around if there are pending events. | 256 // Remain around if there are pending events. |
| 255 WTF_LOG(Media, "MediaKeys(%p)::hasPendingActivity %s%s", this, | 257 DVLOG(MEDIA_KEYS_LOG_LEVEL) << __FUNCTION__ << "(" << this << ")" |
| 256 !m_pendingActions.isEmpty() ? " !m_pendingActions.isEmpty()" : "", | 258 << (!m_pendingActions.isEmpty() ? " !m_pendingActions.isEmpty()" : "") |
| 257 m_reservedForMediaElement ? " m_reservedForMediaElement" : ""); | 259 << (m_reservedForMediaElement ? " m_reservedForMediaElement" : ""); |
| 258 | 260 |
| 259 return !m_pendingActions.isEmpty() || m_reservedForMediaElement; | 261 return !m_pendingActions.isEmpty() || m_reservedForMediaElement; |
| 260 } | 262 } |
| 261 | 263 |
| 262 void MediaKeys::stop() | 264 void MediaKeys::stop() |
| 263 { | 265 { |
| 264 ActiveDOMObject::stop(); | 266 ActiveDOMObject::stop(); |
| 265 | 267 |
| 266 if (m_timer.isActive()) | 268 if (m_timer.isActive()) |
| 267 m_timer.stop(); | 269 m_timer.stop(); |
| 268 m_pendingActions.clear(); | 270 m_pendingActions.clear(); |
| 269 } | 271 } |
| 270 | 272 |
| 271 } // namespace blink | 273 } // namespace blink |
| OLD | NEW |