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

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

Issue 2342953002: Update EME errors to use TypeError (Closed)
Patch Set: comments only Created 4 years, 3 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/ContentDecryptionModuleResultPromise.h" 5 #include "modules/encryptedmedia/ContentDecryptionModuleResultPromise.h"
6 6
7 #include "bindings/core/v8/ScriptPromise.h" 7 #include "bindings/core/v8/ScriptPromise.h"
8 #include "bindings/core/v8/ScriptState.h" 8 #include "bindings/core/v8/ScriptState.h"
9 #include "bindings/core/v8/V8ThrowException.h"
9 #include "core/dom/DOMException.h" 10 #include "core/dom/DOMException.h"
10 #include "core/dom/ExecutionContext.h" 11 #include "core/dom/ExecutionContext.h"
11 #include "core/dom/ExecutionContextTask.h" 12 #include "core/dom/ExecutionContextTask.h"
12 #include "public/platform/WebString.h" 13 #include "public/platform/WebString.h"
13 #include "wtf/Assertions.h" 14 #include "wtf/Assertions.h"
14 15
15 namespace blink { 16 namespace blink {
16 17
17 ExceptionCode WebCdmExceptionToExceptionCode(WebContentDecryptionModuleException cdmException) 18 ExceptionCode WebCdmExceptionToExceptionCode(WebContentDecryptionModuleException cdmException)
18 { 19 {
19 switch (cdmException) { 20 switch (cdmException) {
21 case WebContentDecryptionModuleExceptionTypeError:
22 return V8TypeError;
20 case WebContentDecryptionModuleExceptionNotSupportedError: 23 case WebContentDecryptionModuleExceptionNotSupportedError:
21 return NotSupportedError; 24 return NotSupportedError;
22 case WebContentDecryptionModuleExceptionInvalidStateError: 25 case WebContentDecryptionModuleExceptionInvalidStateError:
23 return InvalidStateError; 26 return InvalidStateError;
24 case WebContentDecryptionModuleExceptionInvalidAccessError:
25 return InvalidAccessError;
26 case WebContentDecryptionModuleExceptionQuotaExceededError: 27 case WebContentDecryptionModuleExceptionQuotaExceededError:
27 return QuotaExceededError; 28 return QuotaExceededError;
28 case WebContentDecryptionModuleExceptionUnknownError: 29 case WebContentDecryptionModuleExceptionUnknownError:
29 return UnknownError; 30 return UnknownError;
30 case WebContentDecryptionModuleExceptionClientError:
31 case WebContentDecryptionModuleExceptionOutputError:
32 // Currently no matching DOMException for these 2 errors.
33 // FIXME: Update DOMException to handle these if actually added to
34 // the EME spec.
35 return UnknownError;
36 } 31 }
37 32
38 NOTREACHED(); 33 NOTREACHED();
39 return UnknownError; 34 return UnknownError;
40 } 35 }
41 36
42 ContentDecryptionModuleResultPromise::ContentDecryptionModuleResultPromise(Scrip tState* scriptState) 37 ContentDecryptionModuleResultPromise::ContentDecryptionModuleResultPromise(Scrip tState* scriptState)
43 : m_resolver(ScriptPromiseResolver::create(scriptState)) 38 : m_resolver(ScriptPromiseResolver::create(scriptState))
44 { 39 {
45 } 40 }
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 85
91 void ContentDecryptionModuleResultPromise::reject(ExceptionCode code, const Stri ng& errorMessage) 86 void ContentDecryptionModuleResultPromise::reject(ExceptionCode code, const Stri ng& errorMessage)
92 { 87 {
93 // Reject the promise asynchronously. This avoids problems when gc is 88 // Reject the promise asynchronously. This avoids problems when gc is
94 // destroying objects that result in unfulfilled promises being rejected. 89 // destroying objects that result in unfulfilled promises being rejected.
95 // (Resolving promises is still done synchronously as there may be events 90 // (Resolving promises is still done synchronously as there may be events
96 // already posted that need to happen only after the promise is resolved.) 91 // already posted that need to happen only after the promise is resolved.)
97 // TODO(jrummell): Make resolving a promise asynchronous as well (including 92 // TODO(jrummell): Make resolving a promise asynchronous as well (including
98 // making sure events still happen after the promise is resolved). 93 // making sure events still happen after the promise is resolved).
99 if (getExecutionContext()) { 94 if (getExecutionContext()) {
100 getExecutionContext()->postTask(BLINK_FROM_HERE, createSameThreadTask(&C ontentDecryptionModuleResultPromise::rejectInternal, wrapPersistent(this), code, errorMessage)); 95 getExecutionContext()->postTask(BLINK_FROM_HERE, createSameThreadTask(&C ontentDecryptionModuleResultPromise::rejectInternal, wrapPersistent(this), code, errorMessage));
haraken 2016/09/20 05:22:32 I begin to think that this postTask is the culprit
101 } 96 }
102 } 97 }
103 98
104 void ContentDecryptionModuleResultPromise::rejectInternal(ExceptionCode code, co nst String& errorMessage) 99 void ContentDecryptionModuleResultPromise::rejectInternal(ExceptionCode code, co nst String& errorMessage)
105 { 100 {
106 m_resolver->reject(DOMException::create(code, errorMessage)); 101 // Reject promise with an appropriate error. Since |code| may represent
102 // a TypeError, use V8ThrowException::createDOMException() to handle it.
103 if (m_resolver->getScriptState()->contextIsValid()) {
104 ScriptState::Scope scope(m_resolver->getScriptState());
105 v8::Isolate* isolate = m_resolver->getScriptState()->isolate();
106 m_resolver->reject(V8ThrowException::createDOMException(isolate, code, e rrorMessage));
107 }
108
107 m_resolver.clear(); 109 m_resolver.clear();
108 } 110 }
109 111
110 ExecutionContext* ContentDecryptionModuleResultPromise::getExecutionContext() co nst 112 ExecutionContext* ContentDecryptionModuleResultPromise::getExecutionContext() co nst
111 { 113 {
112 return m_resolver->getExecutionContext(); 114 return m_resolver->getExecutionContext();
113 } 115 }
114 116
115 DEFINE_TRACE(ContentDecryptionModuleResultPromise) 117 DEFINE_TRACE(ContentDecryptionModuleResultPromise)
116 { 118 {
117 visitor->trace(m_resolver); 119 visitor->trace(m_resolver);
118 ContentDecryptionModuleResult::trace(visitor); 120 ContentDecryptionModuleResult::trace(visitor);
119 } 121 }
120 122
121 } // namespace blink 123 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698