Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "config.h" | 5 #include "config.h" |
| 6 #include "modules/encryptedmedia/HTMLMediaElementEncryptedMedia.h" | 6 #include "modules/encryptedmedia/HTMLMediaElementEncryptedMedia.h" |
| 7 | 7 |
| 8 #include "bindings/core/v8/ExceptionState.h" | 8 #include "bindings/core/v8/ExceptionState.h" |
| 9 #include "bindings/core/v8/ScriptPromise.h" | |
| 10 #include "bindings/core/v8/ScriptPromiseResolver.h" | |
| 11 #include "bindings/core/v8/ScriptState.h" | |
| 12 #include "core/dom/DOMException.h" | |
| 9 #include "core/dom/ExceptionCode.h" | 13 #include "core/dom/ExceptionCode.h" |
| 10 #include "core/html/HTMLMediaElement.h" | 14 #include "core/html/HTMLMediaElement.h" |
| 11 #include "core/html/MediaKeyError.h" | 15 #include "core/html/MediaKeyError.h" |
| 12 #include "core/html/MediaKeyEvent.h" | 16 #include "core/html/MediaKeyEvent.h" |
| 13 #include "modules/encryptedmedia/MediaKeyNeededEvent.h" | 17 #include "modules/encryptedmedia/MediaKeyNeededEvent.h" |
| 14 #include "modules/encryptedmedia/MediaKeys.h" | 18 #include "modules/encryptedmedia/MediaKeys.h" |
| 19 #include "modules/encryptedmedia/SimpleContentDecryptionModuleResult.h" | |
| 20 #include "platform/ContentDecryptionModuleResult.h" | |
| 15 #include "platform/Logging.h" | 21 #include "platform/Logging.h" |
| 16 #include "platform/RuntimeEnabledFeatures.h" | 22 #include "platform/RuntimeEnabledFeatures.h" |
| 23 #include "wtf/Functional.h" | |
| 17 #include "wtf/Uint8Array.h" | 24 #include "wtf/Uint8Array.h" |
| 18 | 25 |
| 19 namespace blink { | 26 namespace blink { |
| 20 | 27 |
| 21 static void throwExceptionIfMediaKeyExceptionOccurred(const String& keySystem, c onst String& sessionId, blink::WebMediaPlayer::MediaKeyException exception, Exce ptionState& exceptionState) | 28 static void throwExceptionIfMediaKeyExceptionOccurred(const String& keySystem, c onst String& sessionId, blink::WebMediaPlayer::MediaKeyException exception, Exce ptionState& exceptionState) |
| 22 { | 29 { |
| 23 switch (exception) { | 30 switch (exception) { |
| 24 case blink::WebMediaPlayer::MediaKeyExceptionNoError: | 31 case blink::WebMediaPlayer::MediaKeyExceptionNoError: |
| 25 return; | 32 return; |
| 26 case blink::WebMediaPlayer::MediaKeyExceptionInvalidPlayerState: | 33 case blink::WebMediaPlayer::MediaKeyExceptionInvalidPlayerState: |
| 27 exceptionState.throwDOMException(InvalidStateError, "The player is in an invalid state."); | 34 exceptionState.throwDOMException(InvalidStateError, "The player is in an invalid state."); |
| 28 return; | 35 return; |
| 29 case blink::WebMediaPlayer::MediaKeyExceptionKeySystemNotSupported: | 36 case blink::WebMediaPlayer::MediaKeyExceptionKeySystemNotSupported: |
| 30 exceptionState.throwDOMException(NotSupportedError, "The key system prov ided ('" + keySystem +"') is not supported."); | 37 exceptionState.throwDOMException(NotSupportedError, "The key system prov ided ('" + keySystem +"') is not supported."); |
| 31 return; | 38 return; |
| 32 case blink::WebMediaPlayer::MediaKeyExceptionInvalidAccess: | 39 case blink::WebMediaPlayer::MediaKeyExceptionInvalidAccess: |
| 33 exceptionState.throwDOMException(InvalidAccessError, "The session ID pro vided ('" + sessionId + "') is invalid."); | 40 exceptionState.throwDOMException(InvalidAccessError, "The session ID pro vided ('" + sessionId + "') is invalid."); |
| 34 return; | 41 return; |
| 35 } | 42 } |
| 36 | 43 |
| 37 ASSERT_NOT_REACHED(); | 44 ASSERT_NOT_REACHED(); |
| 38 return; | 45 return; |
| 39 } | 46 } |
| 40 | 47 |
| 48 // This class allows MediaKeys to be set asynchronously. | |
| 49 class SetMediaKeysHandler : public ScriptPromiseResolver { | |
| 50 WTF_MAKE_NONCOPYABLE(SetMediaKeysHandler); | |
| 51 | |
| 52 public: | |
| 53 static ScriptPromise create(ScriptState*, HTMLMediaElement&, MediaKeys*); | |
| 54 virtual ~SetMediaKeysHandler(); | |
| 55 | |
| 56 void timerFired(Timer<SetMediaKeysHandler>*); | |
| 57 | |
| 58 void ClearExistingMediaKeys(); | |
|
ddorwin
2014/08/11 21:42:55
Can the rest be private?
jrummell
2014/08/11 22:12:19
Yup.
| |
| 59 void SetNewMediaKeys(); | |
| 60 void Finish(); | |
| 61 | |
| 62 void ReportClearFailed(ExceptionCode, const String& errorMessage); | |
| 63 void ReportSetFailed(ExceptionCode, const String& errorMessage); | |
| 64 | |
| 65 private: | |
| 66 SetMediaKeysHandler(ScriptState*, HTMLMediaElement&, MediaKeys*); | |
| 67 | |
| 68 RawPtrWillBeMember<HTMLMediaElement> m_element; | |
| 69 Persistent<MediaKeys> m_newMediaKeys; | |
| 70 Timer<SetMediaKeysHandler> m_timer; | |
| 71 }; | |
| 72 | |
| 73 typedef Function<void()> SuccessCB; | |
| 74 typedef Function<void(ExceptionCode, const String&)> FailureCB; | |
| 75 | |
| 76 // Represents the result used when setContentDecryptionModule() is called. | |
| 77 // Calls |success| if result is resolved, |failure| is result is rejected. | |
| 78 class SetContentDecryptionModuleResult FINAL : public ContentDecryptionModuleRes ult { | |
| 79 public: | |
| 80 SetContentDecryptionModuleResult(SuccessCB success, FailureCB failure) | |
| 81 : m_successCallback(success) | |
| 82 , m_failureCallback(failure) | |
| 83 { | |
| 84 } | |
| 85 | |
| 86 // ContentDecryptionModuleResult implementation. | |
| 87 virtual void complete() OVERRIDE | |
| 88 { | |
| 89 m_successCallback(); | |
| 90 } | |
| 91 | |
| 92 virtual void completeWithSession(blink::WebContentDecryptionModuleResult::Se ssionStatus status) OVERRIDE | |
| 93 { | |
| 94 ASSERT_NOT_REACHED(); | |
| 95 m_failureCallback(InvalidStateError, "Unexpected completion."); | |
| 96 } | |
| 97 | |
| 98 virtual void completeWithError(blink::WebContentDecryptionModuleException co de, unsigned long systemCode, const blink::WebString& message) OVERRIDE | |
| 99 { | |
| 100 m_failureCallback(WebCdmExceptionToExceptionCode(code), message); | |
| 101 } | |
| 102 | |
| 103 private: | |
| 104 SuccessCB m_successCallback; | |
| 105 FailureCB m_failureCallback; | |
| 106 }; | |
| 107 | |
| 108 ScriptPromise SetMediaKeysHandler::create(ScriptState* scriptState, HTMLMediaEle ment& element, MediaKeys* mediaKeys) | |
| 109 { | |
| 110 RefPtr<SetMediaKeysHandler> handler = adoptRef(new SetMediaKeysHandler(scrip tState, element, mediaKeys)); | |
| 111 handler->suspendIfNeeded(); | |
| 112 handler->keepAliveWhilePending(); | |
| 113 return handler->promise(); | |
| 114 } | |
| 115 | |
| 116 SetMediaKeysHandler::SetMediaKeysHandler(ScriptState* scriptState, HTMLMediaElem ent& element, MediaKeys* mediaKeys) | |
| 117 : ScriptPromiseResolver(scriptState) | |
| 118 , m_element(element) | |
| 119 , m_newMediaKeys(mediaKeys) | |
| 120 , m_timer(this, &SetMediaKeysHandler::timerFired) | |
| 121 { | |
| 122 WTF_LOG(Media, "SetMediaKeysHandler::SetMediaKeysHandler"); | |
| 123 | |
| 124 // 3. Run the remaining steps asynchronously. | |
| 125 m_timer.startOneShot(0, FROM_HERE); | |
| 126 } | |
| 127 | |
| 128 SetMediaKeysHandler::~SetMediaKeysHandler() | |
| 129 { | |
| 130 } | |
| 131 | |
| 132 void SetMediaKeysHandler::timerFired(Timer<SetMediaKeysHandler>*) | |
| 133 { | |
| 134 ClearExistingMediaKeys(); | |
| 135 } | |
| 136 | |
| 137 void SetMediaKeysHandler::ClearExistingMediaKeys() | |
| 138 { | |
| 139 WTF_LOG(Media, "SetMediaKeysHandler::ClearExistingMediaKeys"); | |
| 140 HTMLMediaElementEncryptedMedia& thisElement = HTMLMediaElementEncryptedMedia ::from(*m_element); | |
| 141 | |
| 142 // 3.1 If mediaKeys is not null, it is already in use by another media | |
| 143 // element, and the user agent is unable to use it with this element, | |
| 144 // reject promise with a new DOMException whose name is | |
| 145 // "QuotaExceededError". | |
| 146 // FIXME: Need to check whether mediaKeys is already in use by another | |
| 147 // media element. | |
| 148 // 3.2 If the mediaKeys attribute is not null, run the following steps: | |
| 149 if (thisElement.m_mediaKeys) { | |
| 150 // 3.2.1 If the user agent or CDM do not support removing the | |
| 151 // association, return a promise rejected with a new DOMException | |
| 152 // whose name is "NotSupportedError". | |
| 153 // 3.2.2 If the association cannot currently be removed (i.e. during | |
| 154 // playback), return a promise rejected with a new DOMException | |
| 155 // whose name is "InvalidStateError". | |
| 156 if (m_element->webMediaPlayer()) { | |
| 157 reject(DOMException::create(InvalidStateError, "The existing MediaKe ys object cannot be removed.")); | |
|
ddorwin
2014/08/11 21:42:55
... while loaded?
jrummell
2014/08/11 22:12:19
Done.
| |
| 158 return; | |
| 159 } | |
| 160 | |
| 161 // 3.2.3 Stop using the CDM instance represented by the mediaKeys | |
| 162 // attribute to decrypt media data and remove the association | |
| 163 // with the media element. | |
| 164 // 3.2.4 If the preceding step failed, ... | |
| 165 // (done in ReportClearFailed()). | |
| 166 if (m_element->webMediaPlayer()) { | |
| 167 SuccessCB successCallback = bind(&SetMediaKeysHandler::SetNewMediaKe ys, this); | |
| 168 FailureCB failureCallback = bind<ExceptionCode, const String&>(&SetM ediaKeysHandler::ReportClearFailed, this); | |
| 169 ContentDecryptionModuleResult* result = new SetContentDecryptionModu leResult(successCallback, failureCallback); | |
| 170 m_element->webMediaPlayer()->setContentDecryptionModule(nullptr, res ult->result()); | |
| 171 | |
| 172 // Don't do anything more until |result| is resolved (or rejected). | |
| 173 return; | |
| 174 } | |
| 175 } | |
| 176 | |
| 177 // MediaKeys not currently set or no player connected, so continue on. | |
| 178 SetNewMediaKeys(); | |
| 179 } | |
| 180 | |
| 181 void SetMediaKeysHandler::SetNewMediaKeys() | |
| 182 { | |
| 183 WTF_LOG(Media, "SetMediaKeysHandler::SetNewMediaKeys"); | |
| 184 | |
| 185 // 3.3 If mediaKeys is not null, run the following steps: | |
| 186 if (m_newMediaKeys) { | |
| 187 // 3.3.1 Associate the CDM instance represented by mediaKeys with the | |
| 188 // media element for decrypting media data. | |
| 189 // 3.3.2 If the preceding step failed, run the following steps: | |
| 190 // (done in ReportSetFailed()). | |
| 191 // 3.3.3 Run the Attempt to Resume Playback If Necessary algorithm on | |
| 192 // the media element. The user agent may choose to skip this | |
| 193 // step if it knows resuming will fail (i.e. mediaKeys has no | |
| 194 // sessions). | |
| 195 // (Handled in Chromium). | |
| 196 if (m_element->webMediaPlayer()) { | |
| 197 SuccessCB successCallback = bind(&SetMediaKeysHandler::Finish, this) ; | |
| 198 FailureCB failureCallback = bind<ExceptionCode, const String&>(&SetM ediaKeysHandler::ReportSetFailed, this); | |
| 199 ContentDecryptionModuleResult* result = new SetContentDecryptionModu leResult(successCallback, failureCallback); | |
| 200 m_element->webMediaPlayer()->setContentDecryptionModule(m_newMediaKe ys->contentDecryptionModule(), result->result()); | |
| 201 | |
| 202 // Don't do anything more until |result| is resolved (or rejected). | |
| 203 return; | |
| 204 } | |
| 205 } | |
| 206 | |
| 207 // MediaKeys doesn't need to be set on the player, so continue on. | |
| 208 Finish(); | |
| 209 } | |
| 210 | |
| 211 void SetMediaKeysHandler::Finish() | |
| 212 { | |
| 213 WTF_LOG(Media, "SetMediaKeysHandler::Finish"); | |
| 214 HTMLMediaElementEncryptedMedia& thisElement = HTMLMediaElementEncryptedMedia ::from(*m_element); | |
| 215 | |
| 216 // 3.4 Set the mediaKeys attribute to mediaKeys. | |
| 217 thisElement.m_mediaKeys = m_newMediaKeys; | |
| 218 | |
| 219 // 3.5 Resolve promise with undefined. | |
| 220 resolve(); | |
| 221 } | |
| 222 | |
| 223 void SetMediaKeysHandler::ReportClearFailed(ExceptionCode code, const String& er rorMessage) | |
| 224 { | |
| 225 WTF_LOG(Media, "SetMediaKeysHandler::ReportClearFailed"); | |
| 226 | |
| 227 // 3.2.4 If the preceding step failed, reject promise with a new | |
| 228 // DOMException whose name is the appropriate error name and | |
| 229 // that has an appropriate message. | |
| 230 reject(DOMException::create(code, errorMessage)); | |
| 231 } | |
| 232 | |
| 233 void SetMediaKeysHandler::ReportSetFailed(ExceptionCode code, const String& erro rMessage) | |
| 234 { | |
| 235 WTF_LOG(Media, "SetMediaKeysHandler::ReportSetFailed"); | |
| 236 HTMLMediaElementEncryptedMedia& thisElement = HTMLMediaElementEncryptedMedia ::from(*m_element); | |
| 237 | |
| 238 // 3.3.2 If the preceding step failed, run the following steps: | |
| 239 // 3.3.2.1 Set the mediaKeys attribute to null. | |
| 240 thisElement.m_mediaKeys.clear(); | |
| 241 | |
| 242 // 3.3.2.2 Reject promise with a new DOMException whose name is the | |
| 243 // appropriate error name and that has an appropriate message. | |
| 244 reject(DOMException::create(code, errorMessage)); | |
| 245 } | |
| 246 | |
| 41 HTMLMediaElementEncryptedMedia::HTMLMediaElementEncryptedMedia() | 247 HTMLMediaElementEncryptedMedia::HTMLMediaElementEncryptedMedia() |
| 42 : m_emeMode(EmeModeNotSelected) | 248 : m_emeMode(EmeModeNotSelected) |
| 43 { | 249 { |
| 44 } | 250 } |
| 45 | 251 |
| 46 DEFINE_EMPTY_DESTRUCTOR_WILL_BE_REMOVED(HTMLMediaElementEncryptedMedia) | 252 DEFINE_EMPTY_DESTRUCTOR_WILL_BE_REMOVED(HTMLMediaElementEncryptedMedia) |
| 47 | 253 |
| 48 const char* HTMLMediaElementEncryptedMedia::supplementName() | 254 const char* HTMLMediaElementEncryptedMedia::supplementName() |
| 49 { | 255 { |
| 50 return "HTMLMediaElementEncryptedMedia"; | 256 return "HTMLMediaElementEncryptedMedia"; |
| 51 } | 257 } |
| 52 | 258 |
| 53 HTMLMediaElementEncryptedMedia& HTMLMediaElementEncryptedMedia::from(HTMLMediaEl ement& element) | 259 HTMLMediaElementEncryptedMedia& HTMLMediaElementEncryptedMedia::from(HTMLMediaEl ement& element) |
| 54 { | 260 { |
| 55 HTMLMediaElementEncryptedMedia* supplement = static_cast<HTMLMediaElementEnc ryptedMedia*>(WillBeHeapSupplement<HTMLMediaElement>::from(element, supplementNa me())); | 261 HTMLMediaElementEncryptedMedia* supplement = static_cast<HTMLMediaElementEnc ryptedMedia*>(WillBeHeapSupplement<HTMLMediaElement>::from(element, supplementNa me())); |
| 56 if (!supplement) { | 262 if (!supplement) { |
| 57 supplement = new HTMLMediaElementEncryptedMedia(); | 263 supplement = new HTMLMediaElementEncryptedMedia(); |
| 58 provideTo(element, supplementName(), adoptPtrWillBeNoop(supplement)); | 264 provideTo(element, supplementName(), adoptPtrWillBeNoop(supplement)); |
| 59 } | 265 } |
| 60 return *supplement; | 266 return *supplement; |
| 61 } | 267 } |
| 62 | 268 |
| 63 bool HTMLMediaElementEncryptedMedia::setEmeMode(EmeMode emeMode, ExceptionState& exceptionState) | 269 bool HTMLMediaElementEncryptedMedia::setEmeMode(EmeMode emeMode) |
| 64 { | 270 { |
| 65 if (m_emeMode != EmeModeNotSelected && m_emeMode != emeMode) { | 271 if (m_emeMode != EmeModeNotSelected && m_emeMode != emeMode) |
| 66 exceptionState.throwDOMException(InvalidStateError, "Mixed use of EME pr efixed and unprefixed API not allowed."); | |
| 67 return false; | 272 return false; |
| 68 } | 273 |
| 69 m_emeMode = emeMode; | 274 m_emeMode = emeMode; |
| 70 return true; | 275 return true; |
| 71 } | 276 } |
| 72 | 277 |
| 73 blink::WebContentDecryptionModule* HTMLMediaElementEncryptedMedia::contentDecryp tionModule() | 278 blink::WebContentDecryptionModule* HTMLMediaElementEncryptedMedia::contentDecryp tionModule() |
| 74 { | 279 { |
| 75 return m_mediaKeys ? m_mediaKeys->contentDecryptionModule() : 0; | 280 return m_mediaKeys ? m_mediaKeys->contentDecryptionModule() : 0; |
| 76 } | 281 } |
| 77 | 282 |
| 78 MediaKeys* HTMLMediaElementEncryptedMedia::mediaKeys(HTMLMediaElement& element) | 283 MediaKeys* HTMLMediaElementEncryptedMedia::mediaKeys(HTMLMediaElement& element) |
| 79 { | 284 { |
| 80 HTMLMediaElementEncryptedMedia& thisElement = HTMLMediaElementEncryptedMedia ::from(element); | 285 HTMLMediaElementEncryptedMedia& thisElement = HTMLMediaElementEncryptedMedia ::from(element); |
| 81 return thisElement.m_mediaKeys.get(); | 286 return thisElement.m_mediaKeys.get(); |
| 82 } | 287 } |
| 83 | 288 |
| 84 void HTMLMediaElementEncryptedMedia::setMediaKeysInternal(HTMLMediaElement& elem ent, MediaKeys* mediaKeys) | 289 ScriptPromise HTMLMediaElementEncryptedMedia::setMediaKeys(ScriptState* scriptSt ate, HTMLMediaElement& element, MediaKeys* mediaKeys) |
| 85 { | 290 { |
| 86 if (m_mediaKeys == mediaKeys) | 291 HTMLMediaElementEncryptedMedia& thisElement = HTMLMediaElementEncryptedMedia ::from(element); |
| 87 return; | 292 WTF_LOG(Media, "HTMLMediaElementEncryptedMedia::setMediaKeys current(%p), ne w(%p)", thisElement.m_mediaKeys.get(), mediaKeys); |
| 88 | 293 |
| 89 ASSERT(m_emeMode == EmeModeUnprefixed); | 294 if (!thisElement.setEmeMode(EmeModeUnprefixed)) |
| 90 m_mediaKeys = mediaKeys; | 295 return ScriptPromise::rejectWithDOMException(scriptState, DOMException:: create(InvalidStateError, "Mixed use of EME prefixed and unprefixed API not allo wed.")); |
| 91 | 296 |
| 92 // If a player is connected, tell it that the CDM has changed. | 297 // 1. If mediaKeys and the mediaKeys attribute are the same object, return |
| 93 if (element.webMediaPlayer()) | 298 // a promise resolved with undefined. |
| 94 element.webMediaPlayer()->setContentDecryptionModule(contentDecryptionMo dule()); | 299 if (thisElement.m_mediaKeys == mediaKeys) |
| 95 } | 300 return ScriptPromise::cast(scriptState, V8ValueTraits<V8UndefinedType>:: toV8Value(V8UndefinedType(), scriptState->context()->Global(), scriptState->isol ate())); |
| 96 | 301 |
| 97 void HTMLMediaElementEncryptedMedia::setMediaKeys(HTMLMediaElement& element, Med iaKeys* mediaKeys, ExceptionState& exceptionState) | 302 // 2. Let promise be a new promise. Remaining steps done in handler. |
| 98 { | 303 return SetMediaKeysHandler::create(scriptState, element, mediaKeys); |
| 99 WTF_LOG(Media, "HTMLMediaElementEncryptedMedia::setMediaKeys"); | |
| 100 HTMLMediaElementEncryptedMedia& thisElement = HTMLMediaElementEncryptedMedia ::from(element); | |
| 101 | |
| 102 if (!thisElement.setEmeMode(EmeModeUnprefixed, exceptionState)) | |
| 103 return; | |
| 104 | |
| 105 thisElement.setMediaKeysInternal(element, mediaKeys); | |
| 106 } | 304 } |
| 107 | 305 |
| 108 // Create a MediaKeyNeededEvent for WD EME. | 306 // Create a MediaKeyNeededEvent for WD EME. |
| 109 static PassRefPtrWillBeRawPtr<Event> createNeedKeyEvent(const String& contentTyp e, const unsigned char* initData, unsigned initDataLength) | 307 static PassRefPtrWillBeRawPtr<Event> createNeedKeyEvent(const String& contentTyp e, const unsigned char* initData, unsigned initDataLength) |
| 110 { | 308 { |
| 111 MediaKeyNeededEventInit initializer; | 309 MediaKeyNeededEventInit initializer; |
| 112 initializer.contentType = contentType; | 310 initializer.contentType = contentType; |
| 113 initializer.initData = Uint8Array::create(initData, initDataLength); | 311 initializer.initData = Uint8Array::create(initData, initDataLength); |
| 114 initializer.bubbles = false; | 312 initializer.bubbles = false; |
| 115 initializer.cancelable = false; | 313 initializer.cancelable = false; |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 132 | 330 |
| 133 void HTMLMediaElementEncryptedMedia::webkitGenerateKeyRequest(HTMLMediaElement& element, const String& keySystem, PassRefPtr<Uint8Array> initData, ExceptionStat e& exceptionState) | 331 void HTMLMediaElementEncryptedMedia::webkitGenerateKeyRequest(HTMLMediaElement& element, const String& keySystem, PassRefPtr<Uint8Array> initData, ExceptionStat e& exceptionState) |
| 134 { | 332 { |
| 135 HTMLMediaElementEncryptedMedia::from(element).generateKeyRequest(element.web MediaPlayer(), keySystem, initData, exceptionState); | 333 HTMLMediaElementEncryptedMedia::from(element).generateKeyRequest(element.web MediaPlayer(), keySystem, initData, exceptionState); |
| 136 } | 334 } |
| 137 | 335 |
| 138 void HTMLMediaElementEncryptedMedia::generateKeyRequest(blink::WebMediaPlayer* w ebMediaPlayer, const String& keySystem, PassRefPtr<Uint8Array> initData, Excepti onState& exceptionState) | 336 void HTMLMediaElementEncryptedMedia::generateKeyRequest(blink::WebMediaPlayer* w ebMediaPlayer, const String& keySystem, PassRefPtr<Uint8Array> initData, Excepti onState& exceptionState) |
| 139 { | 337 { |
| 140 WTF_LOG(Media, "HTMLMediaElementEncryptedMedia::webkitGenerateKeyRequest"); | 338 WTF_LOG(Media, "HTMLMediaElementEncryptedMedia::webkitGenerateKeyRequest"); |
| 141 | 339 |
| 142 if (!setEmeMode(EmeModePrefixed, exceptionState)) | 340 if (!setEmeMode(EmeModePrefixed)) { |
| 341 exceptionState.throwDOMException(InvalidStateError, "Mixed use of EME pr efixed and unprefixed API not allowed."); | |
| 143 return; | 342 return; |
| 343 } | |
| 144 | 344 |
| 145 if (keySystem.isEmpty()) { | 345 if (keySystem.isEmpty()) { |
| 146 exceptionState.throwDOMException(SyntaxError, "The key system provided i s empty."); | 346 exceptionState.throwDOMException(SyntaxError, "The key system provided i s empty."); |
| 147 return; | 347 return; |
| 148 } | 348 } |
| 149 | 349 |
| 150 if (!webMediaPlayer) { | 350 if (!webMediaPlayer) { |
| 151 exceptionState.throwDOMException(InvalidStateError, "No media has been l oaded."); | 351 exceptionState.throwDOMException(InvalidStateError, "No media has been l oaded."); |
| 152 return; | 352 return; |
| 153 } | 353 } |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 170 | 370 |
| 171 void HTMLMediaElementEncryptedMedia::webkitAddKey(HTMLMediaElement& element, con st String& keySystem, PassRefPtr<Uint8Array> key, PassRefPtr<Uint8Array> initDat a, const String& sessionId, ExceptionState& exceptionState) | 371 void HTMLMediaElementEncryptedMedia::webkitAddKey(HTMLMediaElement& element, con st String& keySystem, PassRefPtr<Uint8Array> key, PassRefPtr<Uint8Array> initDat a, const String& sessionId, ExceptionState& exceptionState) |
| 172 { | 372 { |
| 173 HTMLMediaElementEncryptedMedia::from(element).addKey(element.webMediaPlayer( ), keySystem, key, initData, sessionId, exceptionState); | 373 HTMLMediaElementEncryptedMedia::from(element).addKey(element.webMediaPlayer( ), keySystem, key, initData, sessionId, exceptionState); |
| 174 } | 374 } |
| 175 | 375 |
| 176 void HTMLMediaElementEncryptedMedia::addKey(blink::WebMediaPlayer* webMediaPlaye r, const String& keySystem, PassRefPtr<Uint8Array> key, PassRefPtr<Uint8Array> i nitData, const String& sessionId, ExceptionState& exceptionState) | 376 void HTMLMediaElementEncryptedMedia::addKey(blink::WebMediaPlayer* webMediaPlaye r, const String& keySystem, PassRefPtr<Uint8Array> key, PassRefPtr<Uint8Array> i nitData, const String& sessionId, ExceptionState& exceptionState) |
| 177 { | 377 { |
| 178 WTF_LOG(Media, "HTMLMediaElementEncryptedMedia::webkitAddKey"); | 378 WTF_LOG(Media, "HTMLMediaElementEncryptedMedia::webkitAddKey"); |
| 179 | 379 |
| 180 if (!setEmeMode(EmeModePrefixed, exceptionState)) | 380 if (!setEmeMode(EmeModePrefixed)) { |
| 381 exceptionState.throwDOMException(InvalidStateError, "Mixed use of EME pr efixed and unprefixed API not allowed."); | |
| 181 return; | 382 return; |
| 383 } | |
| 182 | 384 |
| 183 if (keySystem.isEmpty()) { | 385 if (keySystem.isEmpty()) { |
| 184 exceptionState.throwDOMException(SyntaxError, "The key system provided i s empty."); | 386 exceptionState.throwDOMException(SyntaxError, "The key system provided i s empty."); |
| 185 return; | 387 return; |
| 186 } | 388 } |
| 187 | 389 |
| 188 if (!key) { | 390 if (!key) { |
| 189 exceptionState.throwDOMException(SyntaxError, "The key provided is inval id."); | 391 exceptionState.throwDOMException(SyntaxError, "The key provided is inval id."); |
| 190 return; | 392 return; |
| 191 } | 393 } |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 218 | 420 |
| 219 void HTMLMediaElementEncryptedMedia::webkitCancelKeyRequest(HTMLMediaElement& el ement, const String& keySystem, const String& sessionId, ExceptionState& excepti onState) | 421 void HTMLMediaElementEncryptedMedia::webkitCancelKeyRequest(HTMLMediaElement& el ement, const String& keySystem, const String& sessionId, ExceptionState& excepti onState) |
| 220 { | 422 { |
| 221 HTMLMediaElementEncryptedMedia::from(element).cancelKeyRequest(element.webMe diaPlayer(), keySystem, sessionId, exceptionState); | 423 HTMLMediaElementEncryptedMedia::from(element).cancelKeyRequest(element.webMe diaPlayer(), keySystem, sessionId, exceptionState); |
| 222 } | 424 } |
| 223 | 425 |
| 224 void HTMLMediaElementEncryptedMedia::cancelKeyRequest(blink::WebMediaPlayer* web MediaPlayer, const String& keySystem, const String& sessionId, ExceptionState& e xceptionState) | 426 void HTMLMediaElementEncryptedMedia::cancelKeyRequest(blink::WebMediaPlayer* web MediaPlayer, const String& keySystem, const String& sessionId, ExceptionState& e xceptionState) |
| 225 { | 427 { |
| 226 WTF_LOG(Media, "HTMLMediaElementEncryptedMedia::webkitCancelKeyRequest"); | 428 WTF_LOG(Media, "HTMLMediaElementEncryptedMedia::webkitCancelKeyRequest"); |
| 227 | 429 |
| 228 if (!setEmeMode(EmeModePrefixed, exceptionState)) | 430 if (!setEmeMode(EmeModePrefixed)) { |
| 431 exceptionState.throwDOMException(InvalidStateError, "Mixed use of EME pr efixed and unprefixed API not allowed."); | |
| 229 return; | 432 return; |
| 433 } | |
| 230 | 434 |
| 231 if (keySystem.isEmpty()) { | 435 if (keySystem.isEmpty()) { |
| 232 exceptionState.throwDOMException(SyntaxError, "The key system provided i s empty."); | 436 exceptionState.throwDOMException(SyntaxError, "The key system provided i s empty."); |
| 233 return; | 437 return; |
| 234 } | 438 } |
| 235 | 439 |
| 236 if (!webMediaPlayer) { | 440 if (!webMediaPlayer) { |
| 237 exceptionState.throwDOMException(InvalidStateError, "No media has been l oaded."); | 441 exceptionState.throwDOMException(InvalidStateError, "No media has been l oaded."); |
| 238 return; | 442 return; |
| 239 } | 443 } |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 334 | 538 |
| 335 void HTMLMediaElementEncryptedMedia::playerDestroyed(HTMLMediaElement& element) | 539 void HTMLMediaElementEncryptedMedia::playerDestroyed(HTMLMediaElement& element) |
| 336 { | 540 { |
| 337 #if ENABLE(OILPAN) | 541 #if ENABLE(OILPAN) |
| 338 // FIXME: Oilpan: remove this once the media player is on the heap. crbug.co m/378229 | 542 // FIXME: Oilpan: remove this once the media player is on the heap. crbug.co m/378229 |
| 339 if (element.isFinalizing()) | 543 if (element.isFinalizing()) |
| 340 return; | 544 return; |
| 341 #endif | 545 #endif |
| 342 | 546 |
| 343 HTMLMediaElementEncryptedMedia& thisElement = HTMLMediaElementEncryptedMedia ::from(element); | 547 HTMLMediaElementEncryptedMedia& thisElement = HTMLMediaElementEncryptedMedia ::from(element); |
| 344 thisElement.setMediaKeysInternal(element, 0); | 548 if (!thisElement.m_mediaKeys) |
| 549 return; | |
| 550 | |
| 551 ASSERT(thisElement.m_emeMode == EmeModeUnprefixed); | |
| 552 thisElement.m_mediaKeys.clear(); | |
| 345 } | 553 } |
| 346 | 554 |
| 347 blink::WebContentDecryptionModule* HTMLMediaElementEncryptedMedia::contentDecryp tionModule(HTMLMediaElement& element) | 555 blink::WebContentDecryptionModule* HTMLMediaElementEncryptedMedia::contentDecryp tionModule(HTMLMediaElement& element) |
| 348 { | 556 { |
| 349 HTMLMediaElementEncryptedMedia& thisElement = HTMLMediaElementEncryptedMedia ::from(element); | 557 HTMLMediaElementEncryptedMedia& thisElement = HTMLMediaElementEncryptedMedia ::from(element); |
| 350 return thisElement.contentDecryptionModule(); | 558 return thisElement.contentDecryptionModule(); |
| 351 } | 559 } |
| 352 | 560 |
| 353 void HTMLMediaElementEncryptedMedia::trace(Visitor* visitor) | 561 void HTMLMediaElementEncryptedMedia::trace(Visitor* visitor) |
| 354 { | 562 { |
| 355 visitor->trace(m_mediaKeys); | 563 visitor->trace(m_mediaKeys); |
| 356 WillBeHeapSupplement<HTMLMediaElement>::trace(visitor); | 564 WillBeHeapSupplement<HTMLMediaElement>::trace(visitor); |
| 357 } | 565 } |
| 358 | 566 |
| 359 } // namespace blink | 567 } // namespace blink |
| OLD | NEW |