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 "modules/encryptedmedia/HTMLMediaElementEncryptedMedia.h" | 5 #include "modules/encryptedmedia/HTMLMediaElementEncryptedMedia.h" |
| 6 | 6 |
| 7 #include "bindings/core/v8/ExceptionState.h" | 7 #include "bindings/core/v8/ExceptionState.h" |
| 8 #include "bindings/core/v8/ScriptPromise.h" | 8 #include "bindings/core/v8/ScriptPromise.h" |
| 9 #include "bindings/core/v8/ScriptPromiseResolver.h" | 9 #include "bindings/core/v8/ScriptPromiseResolver.h" |
| 10 #include "bindings/core/v8/ScriptState.h" | 10 #include "bindings/core/v8/ScriptState.h" |
| 11 #include "bindings/core/v8/V8Binding.h" | 11 #include "bindings/core/v8/V8ThrowException.h" |
| 12 #include "core/dom/DOMException.h" | 12 #include "core/dom/DOMException.h" |
| 13 #include "core/dom/DOMTypedArray.h" | 13 #include "core/dom/DOMTypedArray.h" |
| 14 #include "core/dom/ExceptionCode.h" | 14 #include "core/dom/ExceptionCode.h" |
| 15 #include "core/html/HTMLMediaElement.h" | 15 #include "core/html/HTMLMediaElement.h" |
| 16 #include "modules/encryptedmedia/ContentDecryptionModuleResultPromise.h" | 16 #include "modules/encryptedmedia/ContentDecryptionModuleResultPromise.h" |
| 17 #include "modules/encryptedmedia/EncryptedMediaUtils.h" | 17 #include "modules/encryptedmedia/EncryptedMediaUtils.h" |
| 18 #include "modules/encryptedmedia/MediaEncryptedEvent.h" | 18 #include "modules/encryptedmedia/MediaEncryptedEvent.h" |
| 19 #include "modules/encryptedmedia/MediaKeys.h" | 19 #include "modules/encryptedmedia/MediaKeys.h" |
| 20 #include "platform/ContentDecryptionModuleResult.h" | 20 #include "platform/ContentDecryptionModuleResult.h" |
| 21 #include "wtf/Functional.h" | 21 #include "wtf/Functional.h" |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 50 Member<HTMLMediaElement> m_element; | 50 Member<HTMLMediaElement> m_element; |
| 51 Member<MediaKeys> m_newMediaKeys; | 51 Member<MediaKeys> m_newMediaKeys; |
| 52 bool m_madeReservation; | 52 bool m_madeReservation; |
| 53 Timer<SetMediaKeysHandler> m_timer; | 53 Timer<SetMediaKeysHandler> m_timer; |
| 54 }; | 54 }; |
| 55 | 55 |
| 56 typedef Function<void()> SuccessCallback; | 56 typedef Function<void()> SuccessCallback; |
| 57 typedef Function<void(ExceptionCode, const String&)> FailureCallback; | 57 typedef Function<void(ExceptionCode, const String&)> FailureCallback; |
| 58 | 58 |
| 59 // Represents the result used when setContentDecryptionModule() is called. | 59 // Represents the result used when setContentDecryptionModule() is called. |
| 60 // Calls |success| if result is resolved, |failure| is result is rejected. | 60 // Calls |success| if result is resolved, |failure| if result is rejected. |
| 61 class SetContentDecryptionModuleResult final : public ContentDecryptionModuleRes ult { | 61 class SetContentDecryptionModuleResult final : public ContentDecryptionModuleRes ult { |
| 62 public: | 62 public: |
| 63 SetContentDecryptionModuleResult(std::unique_ptr<SuccessCallback> success, s td::unique_ptr<FailureCallback> failure) | 63 SetContentDecryptionModuleResult(std::unique_ptr<SuccessCallback> success, s td::unique_ptr<FailureCallback> failure) |
| 64 : m_successCallback(std::move(success)) | 64 : m_successCallback(std::move(success)) |
| 65 , m_failureCallback(std::move(failure)) | 65 , m_failureCallback(std::move(failure)) |
| 66 { | 66 { |
| 67 } | 67 } |
| 68 | 68 |
| 69 // ContentDecryptionModuleResult implementation. | 69 // ContentDecryptionModuleResult implementation. |
| 70 void complete() override | 70 void complete() override |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 90 // is empty, we'll report "Rejected with system code (systemCode)". | 90 // is empty, we'll report "Rejected with system code (systemCode)". |
| 91 StringBuilder result; | 91 StringBuilder result; |
| 92 result.append(message); | 92 result.append(message); |
| 93 if (systemCode != 0) { | 93 if (systemCode != 0) { |
| 94 if (result.isEmpty()) | 94 if (result.isEmpty()) |
| 95 result.append("Rejected with system code"); | 95 result.append("Rejected with system code"); |
| 96 result.append(" ("); | 96 result.append(" ("); |
| 97 result.appendNumber(systemCode); | 97 result.appendNumber(systemCode); |
| 98 result.append(')'); | 98 result.append(')'); |
| 99 } | 99 } |
| 100 | |
| 100 (*m_failureCallback)(WebCdmExceptionToExceptionCode(code), result.toStri ng()); | 101 (*m_failureCallback)(WebCdmExceptionToExceptionCode(code), result.toStri ng()); |
| 101 } | 102 } |
| 102 | 103 |
| 103 private: | 104 private: |
| 104 std::unique_ptr<SuccessCallback> m_successCallback; | 105 std::unique_ptr<SuccessCallback> m_successCallback; |
| 105 std::unique_ptr<FailureCallback> m_failureCallback; | 106 std::unique_ptr<FailureCallback> m_failureCallback; |
| 106 }; | 107 }; |
| 107 | 108 |
| 108 ScriptPromise SetMediaKeysHandler::create(ScriptState* scriptState, HTMLMediaEle ment& element, MediaKeys* mediaKeys) | 109 ScriptPromise SetMediaKeysHandler::create(ScriptState* scriptState, HTMLMediaEle ment& element, MediaKeys* mediaKeys) |
| 109 { | 110 { |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 233 | 234 |
| 234 void SetMediaKeysHandler::fail(ExceptionCode code, const String& errorMessage) | 235 void SetMediaKeysHandler::fail(ExceptionCode code, const String& errorMessage) |
| 235 { | 236 { |
| 236 // Reset ownership of |m_newMediaKeys|. | 237 // Reset ownership of |m_newMediaKeys|. |
| 237 if (m_madeReservation) | 238 if (m_madeReservation) |
| 238 m_newMediaKeys->cancelReservation(); | 239 m_newMediaKeys->cancelReservation(); |
| 239 | 240 |
| 240 // Make sure attaching media keys value is false. | 241 // Make sure attaching media keys value is false. |
| 241 DCHECK(!HTMLMediaElementEncryptedMedia::from(*m_element).m_isAttachingMediaK eys); | 242 DCHECK(!HTMLMediaElementEncryptedMedia::from(*m_element).m_isAttachingMediaK eys); |
| 242 | 243 |
| 243 // Reject promise with an appropriate error. | 244 // Reject promise with an appropriate error. Since |code| may represent |
| 244 reject(DOMException::create(code, errorMessage)); | 245 // a TypeError, use V8ThrowException::createDOMException() to handle it. |
| 246 if (getScriptState()->contextIsValid()) { | |
| 247 ScriptState::Scope scope(getScriptState()); | |
|
haraken
2016/09/16 23:55:21
Ditto.
| |
| 248 v8::Isolate* isolate = getScriptState()->isolate(); | |
| 249 reject(V8ThrowException::createDOMException(isolate, code, errorMessage) ); | |
| 250 } | |
| 245 } | 251 } |
| 246 | 252 |
| 247 void SetMediaKeysHandler::clearFailed(ExceptionCode code, const String& errorMes sage) | 253 void SetMediaKeysHandler::clearFailed(ExceptionCode code, const String& errorMes sage) |
| 248 { | 254 { |
| 249 DVLOG(EME_LOG_LEVEL) << __func__ << "(" << code << ", " << errorMessage << " )"; | 255 DVLOG(EME_LOG_LEVEL) << __func__ << "(" << code << ", " << errorMessage << " )"; |
| 250 HTMLMediaElementEncryptedMedia& thisElement = HTMLMediaElementEncryptedMedia ::from(*m_element); | 256 HTMLMediaElementEncryptedMedia& thisElement = HTMLMediaElementEncryptedMedia ::from(*m_element); |
| 251 | 257 |
| 252 // 5.2.4 If the preceding step failed, let this object's attaching media | 258 // 5.2.4 If the preceding step failed, let this object's attaching media |
| 253 // keys value be false and reject promise with an appropriate | 259 // keys value be false and reject promise with an appropriate |
| 254 // error name. | 260 // error name. |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 410 } | 416 } |
| 411 | 417 |
| 412 DEFINE_TRACE(HTMLMediaElementEncryptedMedia) | 418 DEFINE_TRACE(HTMLMediaElementEncryptedMedia) |
| 413 { | 419 { |
| 414 visitor->trace(m_mediaElement); | 420 visitor->trace(m_mediaElement); |
| 415 visitor->trace(m_mediaKeys); | 421 visitor->trace(m_mediaKeys); |
| 416 Supplement<HTMLMediaElement>::trace(visitor); | 422 Supplement<HTMLMediaElement>::trace(visitor); |
| 417 } | 423 } |
| 418 | 424 |
| 419 } // namespace blink | 425 } // namespace blink |
| OLD | NEW |