| 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 13 matching lines...) Expand all Loading... |
| 24 */ | 24 */ |
| 25 | 25 |
| 26 #include "modules/encryptedmedia/MediaKeys.h" | 26 #include "modules/encryptedmedia/MediaKeys.h" |
| 27 | 27 |
| 28 #include "bindings/core/v8/ScriptState.h" | 28 #include "bindings/core/v8/ScriptState.h" |
| 29 #include "core/dom/DOMArrayBuffer.h" | 29 #include "core/dom/DOMArrayBuffer.h" |
| 30 #include "core/dom/DOMException.h" | 30 #include "core/dom/DOMException.h" |
| 31 #include "core/dom/ExceptionCode.h" | 31 #include "core/dom/ExceptionCode.h" |
| 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/ContentDecryptionModuleResultPromise.h" |
| 34 #include "modules/encryptedmedia/EncryptedMediaUtils.h" | 35 #include "modules/encryptedmedia/EncryptedMediaUtils.h" |
| 35 #include "modules/encryptedmedia/MediaKeySession.h" | 36 #include "modules/encryptedmedia/MediaKeySession.h" |
| 36 #include "modules/encryptedmedia/SimpleContentDecryptionModuleResultPromise.h" | |
| 37 #include "platform/Timer.h" | 37 #include "platform/Timer.h" |
| 38 #include "public/platform/WebContentDecryptionModule.h" | 38 #include "public/platform/WebContentDecryptionModule.h" |
| 39 #include "wtf/RefPtr.h" | 39 #include "wtf/RefPtr.h" |
| 40 #include <memory> | 40 #include <memory> |
| 41 | 41 |
| 42 #define MEDIA_KEYS_LOG_LEVEL 3 | 42 #define MEDIA_KEYS_LOG_LEVEL 3 |
| 43 | 43 |
| 44 namespace blink { | 44 namespace blink { |
| 45 | 45 |
| 46 // A class holding a pending action. | 46 // A class holding a pending action. |
| (...skipping 28 matching lines...) Expand all Loading... |
| 75 }; | 75 }; |
| 76 | 76 |
| 77 // This class wraps the promise resolver used when setting the certificate | 77 // This class wraps the promise resolver used when setting the certificate |
| 78 // and is passed to Chromium to fullfill the promise. This implementation of | 78 // and is passed to Chromium to fullfill the promise. This implementation of |
| 79 // complete() will resolve the promise with true, while completeWithError() | 79 // complete() will resolve the promise with true, while completeWithError() |
| 80 // will reject the promise with an exception. completeWithSession() | 80 // will reject the promise with an exception. completeWithSession() |
| 81 // is not expected to be called, and will reject the promise. | 81 // is not expected to be called, and will reject the promise. |
| 82 class SetCertificateResultPromise | 82 class SetCertificateResultPromise |
| 83 : public ContentDecryptionModuleResultPromise { | 83 : public ContentDecryptionModuleResultPromise { |
| 84 public: | 84 public: |
| 85 SetCertificateResultPromise(ScriptState* scriptState) | 85 SetCertificateResultPromise(ScriptState* scriptState, MediaKeys* mediaKeys) |
| 86 : ContentDecryptionModuleResultPromise(scriptState) {} | 86 : ContentDecryptionModuleResultPromise(scriptState), |
| 87 m_mediaKeys(mediaKeys) {} |
| 87 | 88 |
| 88 ~SetCertificateResultPromise() override {} | 89 ~SetCertificateResultPromise() override {} |
| 89 | 90 |
| 90 // ContentDecryptionModuleResult implementation. | 91 // ContentDecryptionModuleResult implementation. |
| 91 void complete() override { resolve(true); } | 92 void complete() override { resolve(true); } |
| 92 | 93 |
| 93 void completeWithError(WebContentDecryptionModuleException exceptionCode, | 94 void completeWithError(WebContentDecryptionModuleException exceptionCode, |
| 94 unsigned long systemCode, | 95 unsigned long systemCode, |
| 95 const WebString& errorMessage) override { | 96 const WebString& errorMessage) override { |
| 96 // The EME spec specifies that "If the Key System implementation does | 97 // The EME spec specifies that "If the Key System implementation does |
| 97 // not support server certificates, return a promise resolved with | 98 // not support server certificates, return a promise resolved with |
| 98 // false." So convert any NOTSUPPORTEDERROR into resolving with false. | 99 // false." So convert any NOTSUPPORTEDERROR into resolving with false. |
| 99 if (exceptionCode == WebContentDecryptionModuleExceptionNotSupportedError) { | 100 if (exceptionCode == WebContentDecryptionModuleExceptionNotSupportedError) { |
| 100 resolve(false); | 101 resolve(false); |
| 101 return; | 102 return; |
| 102 } | 103 } |
| 103 | 104 |
| 104 ContentDecryptionModuleResultPromise::completeWithError( | 105 ContentDecryptionModuleResultPromise::completeWithError( |
| 105 exceptionCode, systemCode, errorMessage); | 106 exceptionCode, systemCode, errorMessage); |
| 106 } | 107 } |
| 108 |
| 109 DEFINE_INLINE_TRACE() { |
| 110 visitor->trace(m_mediaKeys); |
| 111 ContentDecryptionModuleResultPromise::trace(visitor); |
| 112 } |
| 113 |
| 114 private: |
| 115 Member<MediaKeys> m_mediaKeys; |
| 107 }; | 116 }; |
| 108 | 117 |
| 109 MediaKeys* MediaKeys::create( | 118 MediaKeys* MediaKeys::create( |
| 110 ExecutionContext* context, | 119 ExecutionContext* context, |
| 111 const WebVector<WebEncryptedMediaSessionType>& supportedSessionTypes, | 120 const WebVector<WebEncryptedMediaSessionType>& supportedSessionTypes, |
| 112 std::unique_ptr<WebContentDecryptionModule> cdm) { | 121 std::unique_ptr<WebContentDecryptionModule> cdm) { |
| 113 MediaKeys* mediaKeys = | 122 MediaKeys* mediaKeys = |
| 114 new MediaKeys(context, supportedSessionTypes, std::move(cdm)); | 123 new MediaKeys(context, supportedSessionTypes, std::move(cdm)); |
| 115 mediaKeys->suspendIfNeeded(); | 124 mediaKeys->suspendIfNeeded(); |
| 116 return mediaKeys; | 125 return mediaKeys; |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 // "NotSupportedError". | 196 // "NotSupportedError". |
| 188 // (Let the CDM decide whether to support this or not.) | 197 // (Let the CDM decide whether to support this or not.) |
| 189 | 198 |
| 190 // 3. Let certificate be a copy of the contents of the serverCertificate | 199 // 3. Let certificate be a copy of the contents of the serverCertificate |
| 191 // parameter. | 200 // parameter. |
| 192 DOMArrayBuffer* serverCertificateBuffer = DOMArrayBuffer::create( | 201 DOMArrayBuffer* serverCertificateBuffer = DOMArrayBuffer::create( |
| 193 serverCertificate.data(), serverCertificate.byteLength()); | 202 serverCertificate.data(), serverCertificate.byteLength()); |
| 194 | 203 |
| 195 // 4. Let promise be a new promise. | 204 // 4. Let promise be a new promise. |
| 196 SetCertificateResultPromise* result = | 205 SetCertificateResultPromise* result = |
| 197 new SetCertificateResultPromise(scriptState); | 206 new SetCertificateResultPromise(scriptState, this); |
| 198 ScriptPromise promise = result->promise(); | 207 ScriptPromise promise = result->promise(); |
| 199 | 208 |
| 200 // 5. Run the following steps asynchronously (documented in timerFired()). | 209 // 5. Run the following steps asynchronously (documented in timerFired()). |
| 201 m_pendingActions.append(PendingAction::CreatePendingSetServerCertificate( | 210 m_pendingActions.append(PendingAction::CreatePendingSetServerCertificate( |
| 202 result, serverCertificateBuffer)); | 211 result, serverCertificateBuffer)); |
| 203 if (!m_timer.isActive()) | 212 if (!m_timer.isActive()) |
| 204 m_timer.startOneShot(0, BLINK_FROM_HERE); | 213 m_timer.startOneShot(0, BLINK_FROM_HERE); |
| 205 | 214 |
| 206 // 6. Return promise. | 215 // 6. Return promise. |
| 207 return promise; | 216 return promise; |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 290 // Remain around if there are pending events. | 299 // Remain around if there are pending events. |
| 291 DVLOG(MEDIA_KEYS_LOG_LEVEL) | 300 DVLOG(MEDIA_KEYS_LOG_LEVEL) |
| 292 << __func__ << "(" << this << ")" | 301 << __func__ << "(" << this << ")" |
| 293 << (!m_pendingActions.isEmpty() ? " !m_pendingActions.isEmpty()" : "") | 302 << (!m_pendingActions.isEmpty() ? " !m_pendingActions.isEmpty()" : "") |
| 294 << (m_reservedForMediaElement ? " m_reservedForMediaElement" : ""); | 303 << (m_reservedForMediaElement ? " m_reservedForMediaElement" : ""); |
| 295 | 304 |
| 296 return !m_pendingActions.isEmpty() || m_reservedForMediaElement; | 305 return !m_pendingActions.isEmpty() || m_reservedForMediaElement; |
| 297 } | 306 } |
| 298 | 307 |
| 299 } // namespace blink | 308 } // namespace blink |
| OLD | NEW |