Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(432)

Side by Side Diff: third_party/WebKit/Source/modules/encryptedmedia/HTMLMediaElementEncryptedMedia.cpp

Issue 2342953002: Update EME errors to use TypeError (Closed)
Patch Set: changes Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 29 matching lines...) Expand all
51 Member<HTMLMediaElement> m_element; 51 Member<HTMLMediaElement> m_element;
52 Member<MediaKeys> m_newMediaKeys; 52 Member<MediaKeys> m_newMediaKeys;
53 bool m_madeReservation; 53 bool m_madeReservation;
54 Timer<SetMediaKeysHandler> m_timer; 54 Timer<SetMediaKeysHandler> m_timer;
55 }; 55 };
56 56
57 typedef Function<void()> SuccessCallback; 57 typedef Function<void()> SuccessCallback;
58 typedef Function<void(ExceptionCode, const String&)> FailureCallback; 58 typedef Function<void(ExceptionCode, const String&)> FailureCallback;
59 59
60 // Represents the result used when setContentDecryptionModule() is called. 60 // Represents the result used when setContentDecryptionModule() is called.
61 // Calls |success| if result is resolved, |failure| is result is rejected. 61 // Calls |success| if result is resolved, |failure| if result is rejected.
62 class SetContentDecryptionModuleResult final 62 class SetContentDecryptionModuleResult final
63 : public ContentDecryptionModuleResult { 63 : public ContentDecryptionModuleResult {
64 public: 64 public:
65 SetContentDecryptionModuleResult(std::unique_ptr<SuccessCallback> success, 65 SetContentDecryptionModuleResult(std::unique_ptr<SuccessCallback> success,
66 std::unique_ptr<FailureCallback> failure) 66 std::unique_ptr<FailureCallback> failure)
67 : m_successCallback(std::move(success)), 67 : m_successCallback(std::move(success)),
68 m_failureCallback(std::move(failure)) {} 68 m_failureCallback(std::move(failure)) {}
69 69
70 // ContentDecryptionModuleResult implementation. 70 // ContentDecryptionModuleResult implementation.
71 void complete() override { (*m_successCallback)(); } 71 void complete() override { (*m_successCallback)(); }
(...skipping 17 matching lines...) Expand all
89 // is empty, we'll report "Rejected with system code (systemCode)". 89 // is empty, we'll report "Rejected with system code (systemCode)".
90 StringBuilder result; 90 StringBuilder result;
91 result.append(message); 91 result.append(message);
92 if (systemCode != 0) { 92 if (systemCode != 0) {
93 if (result.isEmpty()) 93 if (result.isEmpty())
94 result.append("Rejected with system code"); 94 result.append("Rejected with system code");
95 result.append(" ("); 95 result.append(" (");
96 result.appendNumber(systemCode); 96 result.appendNumber(systemCode);
97 result.append(')'); 97 result.append(')');
98 } 98 }
99
99 (*m_failureCallback)(WebCdmExceptionToExceptionCode(code), 100 (*m_failureCallback)(WebCdmExceptionToExceptionCode(code),
100 result.toString()); 101 result.toString());
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, 109 ScriptPromise SetMediaKeysHandler::create(ScriptState* scriptState,
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 void SetMediaKeysHandler::fail(ExceptionCode code, const String& errorMessage) { 244 void SetMediaKeysHandler::fail(ExceptionCode code, const String& errorMessage) {
244 // Reset ownership of |m_newMediaKeys|. 245 // Reset ownership of |m_newMediaKeys|.
245 if (m_madeReservation) 246 if (m_madeReservation)
246 m_newMediaKeys->cancelReservation(); 247 m_newMediaKeys->cancelReservation();
247 248
248 // Make sure attaching media keys value is false. 249 // Make sure attaching media keys value is false.
249 DCHECK( 250 DCHECK(
250 !HTMLMediaElementEncryptedMedia::from(*m_element).m_isAttachingMediaKeys); 251 !HTMLMediaElementEncryptedMedia::from(*m_element).m_isAttachingMediaKeys);
251 252
252 // Reject promise with an appropriate error. 253 // Reject promise with an appropriate error.
253 reject(DOMException::create(code, errorMessage)); 254 ScriptState::Scope scope(getScriptState());
255 v8::Isolate* isolate = getScriptState()->isolate();
256 reject(V8ThrowException::createDOMException(isolate, code, errorMessage));
254 } 257 }
255 258
256 void SetMediaKeysHandler::clearFailed(ExceptionCode code, 259 void SetMediaKeysHandler::clearFailed(ExceptionCode code,
257 const String& errorMessage) { 260 const String& errorMessage) {
258 DVLOG(EME_LOG_LEVEL) << __func__ << "(" << code << ", " << errorMessage 261 DVLOG(EME_LOG_LEVEL) << __func__ << "(" << code << ", " << errorMessage
259 << ")"; 262 << ")";
260 HTMLMediaElementEncryptedMedia& thisElement = 263 HTMLMediaElementEncryptedMedia& thisElement =
261 HTMLMediaElementEncryptedMedia::from(*m_element); 264 HTMLMediaElementEncryptedMedia::from(*m_element);
262 265
263 // 5.2.4 If the preceding step failed, let this object's attaching media 266 // 5.2.4 If the preceding step failed, let this object's attaching media
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
431 return m_mediaKeys ? m_mediaKeys->contentDecryptionModule() : 0; 434 return m_mediaKeys ? m_mediaKeys->contentDecryptionModule() : 0;
432 } 435 }
433 436
434 DEFINE_TRACE(HTMLMediaElementEncryptedMedia) { 437 DEFINE_TRACE(HTMLMediaElementEncryptedMedia) {
435 visitor->trace(m_mediaElement); 438 visitor->trace(m_mediaElement);
436 visitor->trace(m_mediaKeys); 439 visitor->trace(m_mediaKeys);
437 Supplement<HTMLMediaElement>::trace(visitor); 440 Supplement<HTMLMediaElement>::trace(visitor);
438 } 441 }
439 442
440 } // namespace blink 443 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698