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 ClearExistingMediaKeys(Timer<SetMediaKeysHandler>*); | |
| 57 void SetNewMediaKeys(); | |
| 58 void Finish(); | |
| 59 | |
| 60 void ClearFailed(ExceptionCode, const String& errorMessage); | |
|
ddorwin
2014/08/09 00:36:53
Unless this is a callback (On...), it should be an
jrummell
2014/08/11 21:24:48
Done.
| |
| 61 void SetFailed(ExceptionCode, const String& errorMessage); | |
| 62 | |
| 63 private: | |
| 64 SetMediaKeysHandler(ScriptState*, HTMLMediaElement&, MediaKeys*); | |
| 65 | |
| 66 RawPtrWillBeMember<HTMLMediaElement> m_element; | |
| 67 Persistent<MediaKeys> m_newMediaKeys; | |
| 68 Timer<SetMediaKeysHandler> m_timer; | |
| 69 }; | |
| 70 | |
| 71 typedef Function<void()> SuccessCB; | |
| 72 typedef Function<void(ExceptionCode, const String&)> FailureCB; | |
| 73 | |
| 74 // Represents the result used when setContentDecryptionModule() is called. | |
| 75 // Calls |success| if result is resolved, |failure| is result is rejected. | |
| 76 class SetContentDecryptionModuleResult FINAL : public ContentDecryptionModuleRes ult { | |
| 77 public: | |
| 78 SetContentDecryptionModuleResult(SuccessCB success, FailureCB failure) | |
| 79 : m_successCallback(success) | |
| 80 , m_failureCallback(failure) | |
| 81 { | |
| 82 } | |
| 83 | |
| 84 // ContentDecryptionModuleResult implementation. | |
| 85 virtual void complete() OVERRIDE | |
| 86 { | |
| 87 m_successCallback(); | |
| 88 } | |
| 89 | |
| 90 virtual void completeWithSession(blink::WebContentDecryptionModuleResult::Se ssionStatus status) OVERRIDE | |
| 91 { | |
| 92 ASSERT_NOT_REACHED(); | |
| 93 m_failureCallback(InvalidStateError, "Unexpected completion."); | |
| 94 } | |
| 95 | |
| 96 virtual void completeWithError(blink::WebContentDecryptionModuleException co de, unsigned long systemCode, const blink::WebString& message) OVERRIDE | |
| 97 { | |
| 98 m_failureCallback(WebCdmExceptionToExceptionCode(code), message); | |
| 99 } | |
| 100 | |
| 101 private: | |
| 102 SuccessCB m_successCallback; | |
| 103 FailureCB m_failureCallback; | |
| 104 }; | |
| 105 | |
| 106 ScriptPromise SetMediaKeysHandler::create(ScriptState* scriptState, HTMLMediaEle ment& element, MediaKeys* mediaKeys) | |
| 107 { | |
| 108 RefPtr<SetMediaKeysHandler> handler = adoptRef(new SetMediaKeysHandler(scrip tState, element, mediaKeys)); | |
| 109 handler->suspendIfNeeded(); | |
| 110 handler->keepAliveWhilePending(); | |
| 111 return handler->promise(); | |
| 112 } | |
| 113 | |
| 114 SetMediaKeysHandler::SetMediaKeysHandler(ScriptState* scriptState, HTMLMediaElem ent& element, MediaKeys* mediaKeys) | |
| 115 : ScriptPromiseResolver(scriptState) | |
| 116 , m_element(element) | |
| 117 , m_newMediaKeys(mediaKeys) | |
| 118 , m_timer(this, &SetMediaKeysHandler::ClearExistingMediaKeys) | |
| 119 { | |
| 120 WTF_LOG(Media, "SetMediaKeysHandler::SetMediaKeysHandler"); | |
| 121 | |
| 122 // 3. Run the remaining steps asynchronously. | |
| 123 m_timer.startOneShot(0, FROM_HERE); | |
| 124 } | |
| 125 | |
| 126 SetMediaKeysHandler::~SetMediaKeysHandler() | |
| 127 { | |
| 128 } | |
| 129 | |
| 130 void SetMediaKeysHandler::ClearExistingMediaKeys(Timer<SetMediaKeysHandler>*) | |
|
ddorwin
2014/08/09 00:36:53
It's a bit weird that this action is tied to a Tim
jrummell
2014/08/11 21:24:48
Done.
| |
| 131 { | |
| 132 WTF_LOG(Media, "SetMediaKeysHandler::ClearExistingMediaKeys"); | |
| 133 HTMLMediaElementEncryptedMedia& thisElement = HTMLMediaElementEncryptedMedia ::from(*m_element); | |
| 134 | |
| 135 // 3.1 If mediaKeys is not null, it is already in use by another media | |
| 136 // element, and the user agent is unable to use it with this element, | |
| 137 // reject promise with a new DOMException whose name is | |
| 138 // "QuotaExceededError". | |
| 139 // (Currently no restrictions on using the same MediaKeys with multiple | |
|
ddorwin
2014/08/09 00:36:52
Chrome doesn't have any such limitations? I think
jrummell
2014/08/11 21:24:48
Done.
| |
| 140 // media elements.) | |
| 141 // 3.2 If the mediaKeys attribute is not null, run the following steps: | |
| 142 if (thisElement.m_mediaKeys) { | |
| 143 // 3.2.1 If the user agent or CDM do not support removing the | |
| 144 // association, return a promise rejected with a new DOMException | |
| 145 // whose name is "NotSupportedError". | |
| 146 // 3.2.2 If the association cannot currently be removed (i.e. during | |
| 147 // playback), return a promise rejected with a new DOMException | |
| 148 // whose name is "InvalidStateError". | |
| 149 if (m_element->isPlaying()) { | |
|
ddorwin
2014/08/09 00:36:52
m_element->webMediaPlayer() == is loaded?
It's at
jrummell
2014/08/11 21:24:48
Done.
| |
| 150 ClearFailed(InvalidStateError, "The existing MediaKeys object cannot be removed while playing."); | |
|
ddorwin
2014/08/09 00:36:53
Because this function includes a step that doesn't
jrummell
2014/08/11 21:24:48
Done.
| |
| 151 return; | |
| 152 } | |
| 153 | |
| 154 // 3.2.3 Stop using the CDM instance represented by the mediaKeys | |
| 155 // attribute to decrypt media data and remove the association | |
| 156 // with the media element. | |
| 157 // 3.2.4 If the preceding step failed, ... | |
| 158 // (done in ClearFailed()). | |
| 159 if (m_element->webMediaPlayer()) { | |
| 160 SuccessCB successCallback = bind(&SetMediaKeysHandler::SetNewMediaKe ys, this); | |
| 161 FailureCB failureCallback = bind<ExceptionCode, const String&>(&SetM ediaKeysHandler::ClearFailed, this); | |
| 162 ContentDecryptionModuleResult* result = new SetContentDecryptionModu leResult(successCallback, failureCallback); | |
| 163 m_element->webMediaPlayer()->setContentDecryptionModule(nullptr, res ult->result()); | |
| 164 | |
| 165 // Don't do anything more until |result| is resolved (or rejected). | |
| 166 return; | |
| 167 } | |
| 168 } | |
| 169 | |
| 170 // MediaKeys not currently set or no player connected, so continue on. | |
| 171 SetNewMediaKeys(); | |
| 172 } | |
| 173 | |
| 174 void SetMediaKeysHandler::SetNewMediaKeys() | |
| 175 { | |
| 176 WTF_LOG(Media, "SetMediaKeysHandler::SetNewMediaKeys"); | |
| 177 | |
| 178 // 3.3 If mediaKeys is not null, run the following steps: | |
| 179 if (m_newMediaKeys) { | |
| 180 // 3.3.1 Associate the CDM instance represented by mediaKeys with the | |
| 181 // media element for decrypting media data. | |
| 182 // 3.3.2 If the preceding step failed, run the following steps: | |
| 183 // (done in SetFailed()). | |
| 184 // 3.3.3 Run the Attempt to Resume Playback If Necessary algorithm on | |
| 185 // the media element. The user agent may choose to skip this | |
| 186 // step if it knows resuming will fail (i.e. mediaKeys has no | |
| 187 // sessions). | |
|
ddorwin
2014/08/09 00:36:52
Handled by Chromium?
jrummell
2014/08/11 21:24:48
Done.
| |
| 188 if (m_element->webMediaPlayer()) { | |
| 189 SuccessCB successCallback = bind(&SetMediaKeysHandler::Finish, this) ; | |
| 190 FailureCB failureCallback = bind<ExceptionCode, const String&>(&SetM ediaKeysHandler::SetFailed, this); | |
| 191 ContentDecryptionModuleResult* result = new SetContentDecryptionModu leResult(successCallback, failureCallback); | |
| 192 m_element->webMediaPlayer()->setContentDecryptionModule(m_newMediaKe ys->contentDecryptionModule(), result->result()); | |
| 193 | |
| 194 // Don't do anything more until |result| is resolved (or rejected). | |
| 195 return; | |
| 196 } | |
| 197 } | |
| 198 | |
| 199 // MediaKeys doesn't need to be set on the player, so continue on. | |
| 200 Finish(); | |
| 201 } | |
| 202 | |
| 203 void SetMediaKeysHandler::Finish() | |
| 204 { | |
| 205 WTF_LOG(Media, "SetMediaKeysHandler::Finish"); | |
| 206 HTMLMediaElementEncryptedMedia& thisElement = HTMLMediaElementEncryptedMedia ::from(*m_element); | |
| 207 | |
| 208 // 3.4 Set the mediaKeys attribute to mediaKeys. | |
| 209 thisElement.m_mediaKeys = m_newMediaKeys; | |
| 210 | |
| 211 // 3.5 Resolve promise with undefined. | |
| 212 resolve(); | |
| 213 } | |
| 214 | |
| 215 void SetMediaKeysHandler::ClearFailed(ExceptionCode code, const String& errorMes sage) | |
| 216 { | |
| 217 WTF_LOG(Media, "SetMediaKeysHandler::ClearFailed"); | |
| 218 | |
| 219 // 3.2.4 If the preceding step failed, reject promise with a new | |
| 220 // DOMException whose name is the appropriate error name and | |
| 221 // that has an appropriate message. | |
| 222 reject(DOMException::create(code, errorMessage)); | |
| 223 } | |
| 224 | |
| 225 void SetMediaKeysHandler::SetFailed(ExceptionCode code, const String& errorMessa ge) | |
| 226 { | |
| 227 WTF_LOG(Media, "SetMediaKeysHandler::SetFailed"); | |
| 228 HTMLMediaElementEncryptedMedia& thisElement = HTMLMediaElementEncryptedMedia ::from(*m_element); | |
| 229 | |
| 230 // 3.3.2 If the preceding step failed, run the following steps: | |
| 231 // 3.3.2.1 Set the mediaKeys attribute to null. | |
| 232 thisElement.m_mediaKeys.clear(); | |
| 233 | |
| 234 // 3.3.2.2 Reject promise with a new DOMException whose name is the | |
| 235 // appropriate error name and that has an appropriate message. | |
| 236 reject(DOMException::create(code, errorMessage)); | |
| 237 } | |
| 238 | |
| 41 HTMLMediaElementEncryptedMedia::HTMLMediaElementEncryptedMedia() | 239 HTMLMediaElementEncryptedMedia::HTMLMediaElementEncryptedMedia() |
| 42 : m_emeMode(EmeModeNotSelected) | 240 : m_emeMode(EmeModeNotSelected) |
| 43 { | 241 { |
| 44 } | 242 } |
| 45 | 243 |
| 46 DEFINE_EMPTY_DESTRUCTOR_WILL_BE_REMOVED(HTMLMediaElementEncryptedMedia) | 244 DEFINE_EMPTY_DESTRUCTOR_WILL_BE_REMOVED(HTMLMediaElementEncryptedMedia) |
| 47 | 245 |
| 48 const char* HTMLMediaElementEncryptedMedia::supplementName() | 246 const char* HTMLMediaElementEncryptedMedia::supplementName() |
| 49 { | 247 { |
| 50 return "HTMLMediaElementEncryptedMedia"; | 248 return "HTMLMediaElementEncryptedMedia"; |
| 51 } | 249 } |
| 52 | 250 |
| 53 HTMLMediaElementEncryptedMedia& HTMLMediaElementEncryptedMedia::from(HTMLMediaEl ement& element) | 251 HTMLMediaElementEncryptedMedia& HTMLMediaElementEncryptedMedia::from(HTMLMediaEl ement& element) |
| 54 { | 252 { |
| 55 HTMLMediaElementEncryptedMedia* supplement = static_cast<HTMLMediaElementEnc ryptedMedia*>(WillBeHeapSupplement<HTMLMediaElement>::from(element, supplementNa me())); | 253 HTMLMediaElementEncryptedMedia* supplement = static_cast<HTMLMediaElementEnc ryptedMedia*>(WillBeHeapSupplement<HTMLMediaElement>::from(element, supplementNa me())); |
| 56 if (!supplement) { | 254 if (!supplement) { |
| 57 supplement = new HTMLMediaElementEncryptedMedia(); | 255 supplement = new HTMLMediaElementEncryptedMedia(); |
| 58 provideTo(element, supplementName(), adoptPtrWillBeNoop(supplement)); | 256 provideTo(element, supplementName(), adoptPtrWillBeNoop(supplement)); |
| 59 } | 257 } |
| 60 return *supplement; | 258 return *supplement; |
| 61 } | 259 } |
| 62 | 260 |
| 63 bool HTMLMediaElementEncryptedMedia::setEmeMode(EmeMode emeMode, ExceptionState& exceptionState) | 261 bool HTMLMediaElementEncryptedMedia::setEmeMode(EmeMode emeMode) |
| 64 { | 262 { |
| 65 if (m_emeMode != EmeModeNotSelected && m_emeMode != emeMode) { | 263 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; | 264 return false; |
| 68 } | 265 |
| 69 m_emeMode = emeMode; | 266 m_emeMode = emeMode; |
| 70 return true; | 267 return true; |
| 71 } | 268 } |
| 72 | 269 |
| 73 blink::WebContentDecryptionModule* HTMLMediaElementEncryptedMedia::contentDecryp tionModule() | 270 blink::WebContentDecryptionModule* HTMLMediaElementEncryptedMedia::contentDecryp tionModule() |
| 74 { | 271 { |
| 75 return m_mediaKeys ? m_mediaKeys->contentDecryptionModule() : 0; | 272 return m_mediaKeys ? m_mediaKeys->contentDecryptionModule() : 0; |
| 76 } | 273 } |
| 77 | 274 |
| 78 MediaKeys* HTMLMediaElementEncryptedMedia::mediaKeys(HTMLMediaElement& element) | 275 MediaKeys* HTMLMediaElementEncryptedMedia::mediaKeys(HTMLMediaElement& element) |
| 79 { | 276 { |
| 80 HTMLMediaElementEncryptedMedia& thisElement = HTMLMediaElementEncryptedMedia ::from(element); | 277 HTMLMediaElementEncryptedMedia& thisElement = HTMLMediaElementEncryptedMedia ::from(element); |
| 81 return thisElement.m_mediaKeys.get(); | 278 return thisElement.m_mediaKeys.get(); |
| 82 } | 279 } |
| 83 | 280 |
| 84 void HTMLMediaElementEncryptedMedia::setMediaKeysInternal(HTMLMediaElement& elem ent, MediaKeys* mediaKeys) | 281 ScriptPromise HTMLMediaElementEncryptedMedia::setMediaKeys(ScriptState* scriptSt ate, HTMLMediaElement& element, MediaKeys* mediaKeys) |
| 85 { | 282 { |
| 86 if (m_mediaKeys == mediaKeys) | 283 HTMLMediaElementEncryptedMedia& thisElement = HTMLMediaElementEncryptedMedia ::from(element); |
| 87 return; | 284 WTF_LOG(Media, "HTMLMediaElementEncryptedMedia::setMediaKeys current(%p), ne w(%p)", thisElement.m_mediaKeys.get(), mediaKeys); |
| 88 | 285 |
| 89 ASSERT(m_emeMode == EmeModeUnprefixed); | 286 if (!thisElement.setEmeMode(EmeModeUnprefixed)) |
| 90 m_mediaKeys = mediaKeys; | 287 return ScriptPromise::rejectWithDOMException(scriptState, DOMException:: create(InvalidStateError, "Mixed use of EME prefixed and unprefixed API not allo wed.")); |
| 91 | 288 |
| 92 // If a player is connected, tell it that the CDM has changed. | 289 // 1. If mediaKeys and the mediaKeys attribute are the same object, return |
| 93 if (element.webMediaPlayer()) | 290 // a promise resolved with undefined. |
| 94 element.webMediaPlayer()->setContentDecryptionModule(contentDecryptionMo dule()); | 291 if (thisElement.m_mediaKeys == mediaKeys) |
| 95 } | 292 return ScriptPromise::cast(scriptState, V8ValueTraits<V8UndefinedType>:: toV8Value(V8UndefinedType(), scriptState->context()->Global(), scriptState->isol ate())); |
| 96 | 293 |
| 97 void HTMLMediaElementEncryptedMedia::setMediaKeys(HTMLMediaElement& element, Med iaKeys* mediaKeys, ExceptionState& exceptionState) | 294 // 2. Let promise be a new promise. Remaining steps done in handler. |
| 98 { | 295 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 } | 296 } |
| 107 | 297 |
| 108 // Create a MediaKeyNeededEvent for WD EME. | 298 // Create a MediaKeyNeededEvent for WD EME. |
| 109 static PassRefPtrWillBeRawPtr<Event> createNeedKeyEvent(const String& contentTyp e, const unsigned char* initData, unsigned initDataLength) | 299 static PassRefPtrWillBeRawPtr<Event> createNeedKeyEvent(const String& contentTyp e, const unsigned char* initData, unsigned initDataLength) |
| 110 { | 300 { |
| 111 MediaKeyNeededEventInit initializer; | 301 MediaKeyNeededEventInit initializer; |
| 112 initializer.contentType = contentType; | 302 initializer.contentType = contentType; |
| 113 initializer.initData = Uint8Array::create(initData, initDataLength); | 303 initializer.initData = Uint8Array::create(initData, initDataLength); |
| 114 initializer.bubbles = false; | 304 initializer.bubbles = false; |
| 115 initializer.cancelable = false; | 305 initializer.cancelable = false; |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 132 | 322 |
| 133 void HTMLMediaElementEncryptedMedia::webkitGenerateKeyRequest(HTMLMediaElement& element, const String& keySystem, PassRefPtr<Uint8Array> initData, ExceptionStat e& exceptionState) | 323 void HTMLMediaElementEncryptedMedia::webkitGenerateKeyRequest(HTMLMediaElement& element, const String& keySystem, PassRefPtr<Uint8Array> initData, ExceptionStat e& exceptionState) |
| 134 { | 324 { |
| 135 HTMLMediaElementEncryptedMedia::from(element).generateKeyRequest(element.web MediaPlayer(), keySystem, initData, exceptionState); | 325 HTMLMediaElementEncryptedMedia::from(element).generateKeyRequest(element.web MediaPlayer(), keySystem, initData, exceptionState); |
| 136 } | 326 } |
| 137 | 327 |
| 138 void HTMLMediaElementEncryptedMedia::generateKeyRequest(blink::WebMediaPlayer* w ebMediaPlayer, const String& keySystem, PassRefPtr<Uint8Array> initData, Excepti onState& exceptionState) | 328 void HTMLMediaElementEncryptedMedia::generateKeyRequest(blink::WebMediaPlayer* w ebMediaPlayer, const String& keySystem, PassRefPtr<Uint8Array> initData, Excepti onState& exceptionState) |
| 139 { | 329 { |
| 140 WTF_LOG(Media, "HTMLMediaElementEncryptedMedia::webkitGenerateKeyRequest"); | 330 WTF_LOG(Media, "HTMLMediaElementEncryptedMedia::webkitGenerateKeyRequest"); |
| 141 | 331 |
| 142 if (!setEmeMode(EmeModePrefixed, exceptionState)) | 332 if (!setEmeMode(EmeModePrefixed)) { |
| 333 exceptionState.throwDOMException(InvalidStateError, "Mixed use of EME pr efixed and unprefixed API not allowed."); | |
| 143 return; | 334 return; |
| 335 } | |
| 144 | 336 |
| 145 if (keySystem.isEmpty()) { | 337 if (keySystem.isEmpty()) { |
| 146 exceptionState.throwDOMException(SyntaxError, "The key system provided i s empty."); | 338 exceptionState.throwDOMException(SyntaxError, "The key system provided i s empty."); |
| 147 return; | 339 return; |
| 148 } | 340 } |
| 149 | 341 |
| 150 if (!webMediaPlayer) { | 342 if (!webMediaPlayer) { |
| 151 exceptionState.throwDOMException(InvalidStateError, "No media has been l oaded."); | 343 exceptionState.throwDOMException(InvalidStateError, "No media has been l oaded."); |
| 152 return; | 344 return; |
| 153 } | 345 } |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 170 | 362 |
| 171 void HTMLMediaElementEncryptedMedia::webkitAddKey(HTMLMediaElement& element, con st String& keySystem, PassRefPtr<Uint8Array> key, PassRefPtr<Uint8Array> initDat a, const String& sessionId, ExceptionState& exceptionState) | 363 void HTMLMediaElementEncryptedMedia::webkitAddKey(HTMLMediaElement& element, con st String& keySystem, PassRefPtr<Uint8Array> key, PassRefPtr<Uint8Array> initDat a, const String& sessionId, ExceptionState& exceptionState) |
| 172 { | 364 { |
| 173 HTMLMediaElementEncryptedMedia::from(element).addKey(element.webMediaPlayer( ), keySystem, key, initData, sessionId, exceptionState); | 365 HTMLMediaElementEncryptedMedia::from(element).addKey(element.webMediaPlayer( ), keySystem, key, initData, sessionId, exceptionState); |
| 174 } | 366 } |
| 175 | 367 |
| 176 void HTMLMediaElementEncryptedMedia::addKey(blink::WebMediaPlayer* webMediaPlaye r, const String& keySystem, PassRefPtr<Uint8Array> key, PassRefPtr<Uint8Array> i nitData, const String& sessionId, ExceptionState& exceptionState) | 368 void HTMLMediaElementEncryptedMedia::addKey(blink::WebMediaPlayer* webMediaPlaye r, const String& keySystem, PassRefPtr<Uint8Array> key, PassRefPtr<Uint8Array> i nitData, const String& sessionId, ExceptionState& exceptionState) |
| 177 { | 369 { |
| 178 WTF_LOG(Media, "HTMLMediaElementEncryptedMedia::webkitAddKey"); | 370 WTF_LOG(Media, "HTMLMediaElementEncryptedMedia::webkitAddKey"); |
| 179 | 371 |
| 180 if (!setEmeMode(EmeModePrefixed, exceptionState)) | 372 if (!setEmeMode(EmeModePrefixed)) { |
| 373 exceptionState.throwDOMException(InvalidStateError, "Mixed use of EME pr efixed and unprefixed API not allowed."); | |
| 181 return; | 374 return; |
| 375 } | |
| 182 | 376 |
| 183 if (keySystem.isEmpty()) { | 377 if (keySystem.isEmpty()) { |
| 184 exceptionState.throwDOMException(SyntaxError, "The key system provided i s empty."); | 378 exceptionState.throwDOMException(SyntaxError, "The key system provided i s empty."); |
| 185 return; | 379 return; |
| 186 } | 380 } |
| 187 | 381 |
| 188 if (!key) { | 382 if (!key) { |
| 189 exceptionState.throwDOMException(SyntaxError, "The key provided is inval id."); | 383 exceptionState.throwDOMException(SyntaxError, "The key provided is inval id."); |
| 190 return; | 384 return; |
| 191 } | 385 } |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 218 | 412 |
| 219 void HTMLMediaElementEncryptedMedia::webkitCancelKeyRequest(HTMLMediaElement& el ement, const String& keySystem, const String& sessionId, ExceptionState& excepti onState) | 413 void HTMLMediaElementEncryptedMedia::webkitCancelKeyRequest(HTMLMediaElement& el ement, const String& keySystem, const String& sessionId, ExceptionState& excepti onState) |
| 220 { | 414 { |
| 221 HTMLMediaElementEncryptedMedia::from(element).cancelKeyRequest(element.webMe diaPlayer(), keySystem, sessionId, exceptionState); | 415 HTMLMediaElementEncryptedMedia::from(element).cancelKeyRequest(element.webMe diaPlayer(), keySystem, sessionId, exceptionState); |
| 222 } | 416 } |
| 223 | 417 |
| 224 void HTMLMediaElementEncryptedMedia::cancelKeyRequest(blink::WebMediaPlayer* web MediaPlayer, const String& keySystem, const String& sessionId, ExceptionState& e xceptionState) | 418 void HTMLMediaElementEncryptedMedia::cancelKeyRequest(blink::WebMediaPlayer* web MediaPlayer, const String& keySystem, const String& sessionId, ExceptionState& e xceptionState) |
| 225 { | 419 { |
| 226 WTF_LOG(Media, "HTMLMediaElementEncryptedMedia::webkitCancelKeyRequest"); | 420 WTF_LOG(Media, "HTMLMediaElementEncryptedMedia::webkitCancelKeyRequest"); |
| 227 | 421 |
| 228 if (!setEmeMode(EmeModePrefixed, exceptionState)) | 422 if (!setEmeMode(EmeModePrefixed)) { |
| 423 exceptionState.throwDOMException(InvalidStateError, "Mixed use of EME pr efixed and unprefixed API not allowed."); | |
| 229 return; | 424 return; |
| 425 } | |
| 230 | 426 |
| 231 if (keySystem.isEmpty()) { | 427 if (keySystem.isEmpty()) { |
| 232 exceptionState.throwDOMException(SyntaxError, "The key system provided i s empty."); | 428 exceptionState.throwDOMException(SyntaxError, "The key system provided i s empty."); |
| 233 return; | 429 return; |
| 234 } | 430 } |
| 235 | 431 |
| 236 if (!webMediaPlayer) { | 432 if (!webMediaPlayer) { |
| 237 exceptionState.throwDOMException(InvalidStateError, "No media has been l oaded."); | 433 exceptionState.throwDOMException(InvalidStateError, "No media has been l oaded."); |
| 238 return; | 434 return; |
| 239 } | 435 } |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 334 | 530 |
| 335 void HTMLMediaElementEncryptedMedia::playerDestroyed(HTMLMediaElement& element) | 531 void HTMLMediaElementEncryptedMedia::playerDestroyed(HTMLMediaElement& element) |
| 336 { | 532 { |
| 337 #if ENABLE(OILPAN) | 533 #if ENABLE(OILPAN) |
| 338 // FIXME: Oilpan: remove this once the media player is on the heap. crbug.co m/378229 | 534 // FIXME: Oilpan: remove this once the media player is on the heap. crbug.co m/378229 |
| 339 if (element.isFinalizing()) | 535 if (element.isFinalizing()) |
| 340 return; | 536 return; |
| 341 #endif | 537 #endif |
| 342 | 538 |
| 343 HTMLMediaElementEncryptedMedia& thisElement = HTMLMediaElementEncryptedMedia ::from(element); | 539 HTMLMediaElementEncryptedMedia& thisElement = HTMLMediaElementEncryptedMedia ::from(element); |
| 344 thisElement.setMediaKeysInternal(element, 0); | 540 if (!thisElement.m_mediaKeys) |
| 541 return; | |
| 542 | |
| 543 ASSERT(thisElement.m_emeMode == EmeModeUnprefixed); | |
| 544 thisElement.m_mediaKeys.clear(); | |
| 545 | |
| 546 // If a player is connected, tell it that the CDM has changed. | |
|
ddorwin
2014/08/09 00:36:52
// There is no player to inform.
jrummell
2014/08/11 21:24:48
Removed since this is called right after m_webMedi
| |
| 547 ASSERT(!element.webMediaPlayer()); | |
| 345 } | 548 } |
| 346 | 549 |
| 347 blink::WebContentDecryptionModule* HTMLMediaElementEncryptedMedia::contentDecryp tionModule(HTMLMediaElement& element) | 550 blink::WebContentDecryptionModule* HTMLMediaElementEncryptedMedia::contentDecryp tionModule(HTMLMediaElement& element) |
| 348 { | 551 { |
| 349 HTMLMediaElementEncryptedMedia& thisElement = HTMLMediaElementEncryptedMedia ::from(element); | 552 HTMLMediaElementEncryptedMedia& thisElement = HTMLMediaElementEncryptedMedia ::from(element); |
| 350 return thisElement.contentDecryptionModule(); | 553 return thisElement.contentDecryptionModule(); |
| 351 } | 554 } |
| 352 | 555 |
| 353 void HTMLMediaElementEncryptedMedia::trace(Visitor* visitor) | 556 void HTMLMediaElementEncryptedMedia::trace(Visitor* visitor) |
| 354 { | 557 { |
| 355 visitor->trace(m_mediaKeys); | 558 visitor->trace(m_mediaKeys); |
| 356 WillBeHeapSupplement<HTMLMediaElement>::trace(visitor); | 559 WillBeHeapSupplement<HTMLMediaElement>::trace(visitor); |
| 357 } | 560 } |
| 358 | 561 |
| 359 } // namespace blink | 562 } // namespace blink |
| OLD | NEW |