| 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" |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 // Calls |success| if result is resolved, |failure| if result is rejected. | 62 // Calls |success| if result is resolved, |failure| if result is rejected. |
| 63 class SetContentDecryptionModuleResult final | 63 class SetContentDecryptionModuleResult final |
| 64 : public ContentDecryptionModuleResult { | 64 : public ContentDecryptionModuleResult { |
| 65 public: | 65 public: |
| 66 SetContentDecryptionModuleResult(std::unique_ptr<SuccessCallback> success, | 66 SetContentDecryptionModuleResult(std::unique_ptr<SuccessCallback> success, |
| 67 std::unique_ptr<FailureCallback> failure) | 67 std::unique_ptr<FailureCallback> failure) |
| 68 : m_successCallback(std::move(success)), | 68 : m_successCallback(std::move(success)), |
| 69 m_failureCallback(std::move(failure)) {} | 69 m_failureCallback(std::move(failure)) {} |
| 70 | 70 |
| 71 // ContentDecryptionModuleResult implementation. | 71 // ContentDecryptionModuleResult implementation. |
| 72 void complete() override { (*m_successCallback)(); } | 72 void complete() override { |
| 73 DVLOG(EME_LOG_LEVEL) << __func__ << ": promise resolved."; |
| 74 (*m_successCallback)(); |
| 75 } |
| 73 | 76 |
| 74 void completeWithContentDecryptionModule( | 77 void completeWithContentDecryptionModule( |
| 75 WebContentDecryptionModule*) override { | 78 WebContentDecryptionModule*) override { |
| 76 NOTREACHED(); | 79 NOTREACHED(); |
| 77 (*m_failureCallback)(InvalidStateError, "Unexpected completion."); | 80 (*m_failureCallback)(InvalidStateError, "Unexpected completion."); |
| 78 } | 81 } |
| 79 | 82 |
| 80 void completeWithSession( | 83 void completeWithSession( |
| 81 WebContentDecryptionModuleResult::SessionStatus status) override { | 84 WebContentDecryptionModuleResult::SessionStatus status) override { |
| 82 NOTREACHED(); | 85 NOTREACHED(); |
| 83 (*m_failureCallback)(InvalidStateError, "Unexpected completion."); | 86 (*m_failureCallback)(InvalidStateError, "Unexpected completion."); |
| 84 } | 87 } |
| 85 | 88 |
| 86 void completeWithError(WebContentDecryptionModuleException code, | 89 void completeWithError(WebContentDecryptionModuleException code, |
| 87 unsigned long systemCode, | 90 unsigned long systemCode, |
| 88 const WebString& message) override { | 91 const WebString& message) override { |
| 89 // Non-zero |systemCode| is appended to the |message|. If the |message| | 92 // Non-zero |systemCode| is appended to the |message|. If the |message| |
| 90 // is empty, we'll report "Rejected with system code (systemCode)". | 93 // is empty, we'll report "Rejected with system code (systemCode)". |
| 91 StringBuilder result; | 94 StringBuilder result; |
| 92 result.append(message); | 95 result.append(message); |
| 93 if (systemCode != 0) { | 96 if (systemCode != 0) { |
| 94 if (result.isEmpty()) | 97 if (result.isEmpty()) |
| 95 result.append("Rejected with system code"); | 98 result.append("Rejected with system code"); |
| 96 result.append(" ("); | 99 result.append(" ("); |
| 97 result.appendNumber(systemCode); | 100 result.appendNumber(systemCode); |
| 98 result.append(')'); | 101 result.append(')'); |
| 99 } | 102 } |
| 100 | 103 |
| 104 DVLOG(EME_LOG_LEVEL) << __func__ << ": promise rejected with code " << code |
| 105 << " and message: " << result.toString(); |
| 106 |
| 101 (*m_failureCallback)(WebCdmExceptionToExceptionCode(code), | 107 (*m_failureCallback)(WebCdmExceptionToExceptionCode(code), |
| 102 result.toString()); | 108 result.toString()); |
| 103 } | 109 } |
| 104 | 110 |
| 105 private: | 111 private: |
| 106 std::unique_ptr<SuccessCallback> m_successCallback; | 112 std::unique_ptr<SuccessCallback> m_successCallback; |
| 107 std::unique_ptr<FailureCallback> m_failureCallback; | 113 std::unique_ptr<FailureCallback> m_failureCallback; |
| 108 }; | 114 }; |
| 109 | 115 |
| 110 ScriptPromise SetMediaKeysHandler::create(ScriptState* scriptState, | 116 ScriptPromise SetMediaKeysHandler::create(ScriptState* scriptState, |
| (...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 331 HTMLMediaElementEncryptedMedia::from(element); | 337 HTMLMediaElementEncryptedMedia::from(element); |
| 332 return thisElement.m_mediaKeys.get(); | 338 return thisElement.m_mediaKeys.get(); |
| 333 } | 339 } |
| 334 | 340 |
| 335 ScriptPromise HTMLMediaElementEncryptedMedia::setMediaKeys( | 341 ScriptPromise HTMLMediaElementEncryptedMedia::setMediaKeys( |
| 336 ScriptState* scriptState, | 342 ScriptState* scriptState, |
| 337 HTMLMediaElement& element, | 343 HTMLMediaElement& element, |
| 338 MediaKeys* mediaKeys) { | 344 MediaKeys* mediaKeys) { |
| 339 HTMLMediaElementEncryptedMedia& thisElement = | 345 HTMLMediaElementEncryptedMedia& thisElement = |
| 340 HTMLMediaElementEncryptedMedia::from(element); | 346 HTMLMediaElementEncryptedMedia::from(element); |
| 341 DVLOG(EME_LOG_LEVEL) << __func__ << " current(" | 347 DVLOG(EME_LOG_LEVEL) << __func__ << ": current(" |
| 342 << thisElement.m_mediaKeys.get() << "), new(" | 348 << thisElement.m_mediaKeys.get() << "), new(" |
| 343 << mediaKeys << ")"; | 349 << mediaKeys << ")"; |
| 344 | 350 |
| 345 // From http://w3c.github.io/encrypted-media/#setMediaKeys | 351 // From http://w3c.github.io/encrypted-media/#setMediaKeys |
| 346 | 352 |
| 347 // 1. If mediaKeys and the mediaKeys attribute are the same object, | 353 // 1. If mediaKeys and the mediaKeys attribute are the same object, |
| 348 // return a resolved promise. | 354 // return a resolved promise. |
| 349 if (thisElement.m_mediaKeys == mediaKeys) | 355 if (thisElement.m_mediaKeys == mediaKeys) |
| 350 return ScriptPromise::castUndefined(scriptState); | 356 return ScriptPromise::castUndefined(scriptState); |
| 351 | 357 |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 437 return m_mediaKeys ? m_mediaKeys->contentDecryptionModule() : 0; | 443 return m_mediaKeys ? m_mediaKeys->contentDecryptionModule() : 0; |
| 438 } | 444 } |
| 439 | 445 |
| 440 DEFINE_TRACE(HTMLMediaElementEncryptedMedia) { | 446 DEFINE_TRACE(HTMLMediaElementEncryptedMedia) { |
| 441 visitor->trace(m_mediaElement); | 447 visitor->trace(m_mediaElement); |
| 442 visitor->trace(m_mediaKeys); | 448 visitor->trace(m_mediaKeys); |
| 443 Supplement<HTMLMediaElement>::trace(visitor); | 449 Supplement<HTMLMediaElement>::trace(visitor); |
| 444 } | 450 } |
| 445 | 451 |
| 446 } // namespace blink | 452 } // namespace blink |
| OLD | NEW |