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

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

Issue 2342953002: Update EME errors to use TypeError (Closed)
Patch Set: rebase on promise 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/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( 18 ExceptionCode WebCdmExceptionToExceptionCode(
18 WebContentDecryptionModuleException cdmException) { 19 WebContentDecryptionModuleException cdmException) {
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( 37 ContentDecryptionModuleResultPromise::ContentDecryptionModuleResultPromise(
43 ScriptState* scriptState) 38 ScriptState* scriptState)
44 : m_resolver(ScriptPromiseResolver::create(scriptState)) {} 39 : m_resolver(ScriptPromiseResolver::create(scriptState)) {}
45 40
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 } 86 }
92 87
93 ScriptPromise ContentDecryptionModuleResultPromise::promise() { 88 ScriptPromise ContentDecryptionModuleResultPromise::promise() {
94 return m_resolver->promise(); 89 return m_resolver->promise();
95 } 90 }
96 91
97 void ContentDecryptionModuleResultPromise::reject(ExceptionCode code, 92 void ContentDecryptionModuleResultPromise::reject(ExceptionCode code,
98 const String& errorMessage) { 93 const String& errorMessage) {
99 DCHECK(isValidToFulfillPromise()); 94 DCHECK(isValidToFulfillPromise());
100 95
101 m_resolver->reject(DOMException::create(code, errorMessage)); 96 if (code == V8TypeError) {
haraken 2016/10/15 01:30:46 Can you just use V8ThrowException::createDOMExcept
jrummell 2016/10/17 18:57:24 Done.
97 ScriptState::Scope scope(m_resolver->getScriptState());
jrummell 2016/10/14 20:43:47 Without this line I get a crash in v8::internal::H
haraken 2016/10/15 01:30:46 Yes, this is needed.
98 v8::Isolate* isolate = m_resolver->getScriptState()->isolate();
99 m_resolver->reject(
100 V8ThrowException::createTypeError(isolate, errorMessage));
101 } else {
102 m_resolver->reject(DOMException::create(code, errorMessage));
103 }
104
102 m_resolver.clear(); 105 m_resolver.clear();
103 } 106 }
104 107
105 ExecutionContext* ContentDecryptionModuleResultPromise::getExecutionContext() 108 ExecutionContext* ContentDecryptionModuleResultPromise::getExecutionContext()
106 const { 109 const {
107 return m_resolver->getExecutionContext(); 110 return m_resolver->getExecutionContext();
108 } 111 }
109 112
110 bool ContentDecryptionModuleResultPromise::isValidToFulfillPromise() { 113 bool ContentDecryptionModuleResultPromise::isValidToFulfillPromise() {
111 // getExecutionContext() is no longer valid once the context is destroyed. 114 // getExecutionContext() is no longer valid once the context is destroyed.
112 // activeDOMObjectsAreStopped() is called to see if the context is in the 115 // activeDOMObjectsAreStopped() is called to see if the context is in the
113 // process of being destroyed. If it is, there is no need to fulfill this 116 // process of being destroyed. If it is, there is no need to fulfill this
114 // promise which is about to go away anyway. 117 // promise which is about to go away anyway.
115 return getExecutionContext() && 118 return getExecutionContext() &&
116 !getExecutionContext()->activeDOMObjectsAreStopped(); 119 !getExecutionContext()->activeDOMObjectsAreStopped();
117 } 120 }
118 121
119 DEFINE_TRACE(ContentDecryptionModuleResultPromise) { 122 DEFINE_TRACE(ContentDecryptionModuleResultPromise) {
120 visitor->trace(m_resolver); 123 visitor->trace(m_resolver);
121 ContentDecryptionModuleResult::trace(visitor); 124 ContentDecryptionModuleResult::trace(visitor);
122 } 125 }
123 126
124 } // namespace blink 127 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698