OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 if (!resolver->executionContext() || resolver->executionContext()->activeDOM
ObjectsAreStopped()) | 56 if (!resolver->executionContext() || resolver->executionContext()->activeDOM
ObjectsAreStopped()) |
57 return; | 57 return; |
58 | 58 |
59 ScriptState::Scope scope(resolver->scriptState()); | 59 ScriptState::Scope scope(resolver->scriptState()); |
60 v8::Isolate* isolate = resolver->scriptState()->isolate(); | 60 v8::Isolate* isolate = resolver->scriptState()->isolate(); |
61 resolver->reject(v8::Exception::TypeError(v8String(isolate, errorDetails))); | 61 resolver->reject(v8::Exception::TypeError(v8String(isolate, errorDetails))); |
62 } | 62 } |
63 | 63 |
64 class CryptoResultImpl::Resolver final : public ScriptPromiseResolver { | 64 class CryptoResultImpl::Resolver final : public ScriptPromiseResolver { |
65 public: | 65 public: |
66 static PassRefPtrWillBeRawPtr<ScriptPromiseResolver> create(ScriptState* scr
iptState, CryptoResultImpl* result) | 66 static Resolver* create(ScriptState* scriptState, CryptoResultImpl* result) |
67 { | 67 { |
68 RefPtrWillBeRawPtr<Resolver> resolver = adoptRefWillBeNoop(new Resolver(
scriptState, result)); | 68 ASSERT(scriptState->contextIsValid()); |
| 69 Resolver* resolver = new Resolver(scriptState, result); |
69 resolver->suspendIfNeeded(); | 70 resolver->suspendIfNeeded(); |
70 resolver->keepAliveWhilePending(); | 71 resolver->keepAliveWhilePending(); |
71 return resolver.release(); | 72 return resolver; |
72 } | 73 } |
73 | 74 |
74 void stop() override | 75 void stop() override |
75 { | 76 { |
76 m_result->cancel(); | 77 m_result->cancel(); |
77 m_result->clearResolver(); | 78 m_result->clearResolver(); |
78 m_result = nullptr; | 79 m_result = nullptr; |
79 ScriptPromiseResolver::stop(); | 80 ScriptPromiseResolver::stop(); |
80 } | 81 } |
81 | 82 |
| 83 DEFINE_INLINE_VIRTUAL_TRACE() |
| 84 { |
| 85 visitor->trace(m_result); |
| 86 ScriptPromiseResolver::trace(visitor); |
| 87 } |
| 88 |
82 private: | 89 private: |
83 Resolver(ScriptState* scriptState, CryptoResultImpl* result) | 90 Resolver(ScriptState* scriptState, CryptoResultImpl* result) |
84 : ScriptPromiseResolver(scriptState) | 91 : ScriptPromiseResolver(scriptState) |
85 , m_result(result) { } | 92 , m_result(result) { } |
86 RefPtr<CryptoResultImpl> m_result; | 93 |
| 94 Member<CryptoResultImpl> m_result; |
87 }; | 95 }; |
88 | 96 |
89 ExceptionCode webCryptoErrorToExceptionCode(WebCryptoErrorType errorType) | 97 ExceptionCode webCryptoErrorToExceptionCode(WebCryptoErrorType errorType) |
90 { | 98 { |
91 switch (errorType) { | 99 switch (errorType) { |
92 case WebCryptoErrorTypeNotSupported: | 100 case WebCryptoErrorTypeNotSupported: |
93 return NotSupportedError; | 101 return NotSupportedError; |
94 case WebCryptoErrorTypeSyntax: | 102 case WebCryptoErrorTypeSyntax: |
95 return SyntaxError; | 103 return SyntaxError; |
96 case WebCryptoErrorTypeInvalidAccess: | 104 case WebCryptoErrorTypeInvalidAccess: |
97 return InvalidAccessError; | 105 return InvalidAccessError; |
98 case WebCryptoErrorTypeData: | 106 case WebCryptoErrorTypeData: |
99 return DataError; | 107 return DataError; |
100 case WebCryptoErrorTypeOperation: | 108 case WebCryptoErrorTypeOperation: |
101 return OperationError; | 109 return OperationError; |
102 case WebCryptoErrorTypeType: | 110 case WebCryptoErrorTypeType: |
103 return V8TypeError; | 111 return V8TypeError; |
104 } | 112 } |
105 | 113 |
106 ASSERT_NOT_REACHED(); | 114 ASSERT_NOT_REACHED(); |
107 return 0; | 115 return 0; |
108 } | 116 } |
109 | 117 |
| 118 CryptoResultImpl::CryptoResultImpl(ScriptState* scriptState) |
| 119 : m_cancelled(0) |
| 120 { |
| 121 m_resolver = Resolver::create(scriptState, this); |
| 122 } |
| 123 |
110 CryptoResultImpl::~CryptoResultImpl() | 124 CryptoResultImpl::~CryptoResultImpl() |
111 { | 125 { |
112 ASSERT(!m_resolver); | 126 ASSERT(!m_resolver); |
113 } | 127 } |
114 | 128 |
| 129 DEFINE_TRACE(CryptoResultImpl) |
| 130 { |
| 131 visitor->trace(m_resolver); |
| 132 CryptoResult::trace(visitor); |
| 133 } |
| 134 |
115 void CryptoResultImpl::clearResolver() | 135 void CryptoResultImpl::clearResolver() |
116 { | 136 { |
117 m_resolver = nullptr; | 137 m_resolver = nullptr; |
118 } | 138 } |
119 | 139 |
120 PassRefPtrWillBeRawPtr<CryptoResultImpl> CryptoResultImpl::create(ScriptState* s
criptState) | 140 CryptoResultImpl* CryptoResultImpl::create(ScriptState* scriptState) |
121 { | 141 { |
122 return adoptRefWillBeNoop(new CryptoResultImpl(scriptState)); | 142 return new CryptoResultImpl(scriptState); |
123 } | 143 } |
124 | 144 |
125 void CryptoResultImpl::completeWithError(WebCryptoErrorType errorType, const Web
String& errorDetails) | 145 void CryptoResultImpl::completeWithError(WebCryptoErrorType errorType, const Web
String& errorDetails) |
126 { | 146 { |
127 if (m_resolver) { | 147 if (m_resolver) { |
128 ExceptionCode ec = webCryptoErrorToExceptionCode(errorType); | 148 ExceptionCode ec = webCryptoErrorToExceptionCode(errorType); |
129 | 149 |
130 // Handle TypeError separately, as it cannot be created using | 150 // Handle TypeError separately, as it cannot be created using |
131 // DOMException. | 151 // DOMException. |
132 if (ec == V8TypeError) | 152 if (ec == V8TypeError) |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
196 bool CryptoResultImpl::cancelled() const | 216 bool CryptoResultImpl::cancelled() const |
197 { | 217 { |
198 return acquireLoad(&m_cancelled); | 218 return acquireLoad(&m_cancelled); |
199 } | 219 } |
200 | 220 |
201 void CryptoResultImpl::cancel() | 221 void CryptoResultImpl::cancel() |
202 { | 222 { |
203 releaseStore(&m_cancelled, 1); | 223 releaseStore(&m_cancelled, 1); |
204 } | 224 } |
205 | 225 |
206 CryptoResultImpl::CryptoResultImpl(ScriptState* scriptState) | |
207 : m_cancelled(0) | |
208 { | |
209 ASSERT(scriptState->contextIsValid()); | |
210 if (scriptState->executionContext()->activeDOMObjectsAreStopped()) { | |
211 // If active dom objects have been stopped, avoid creating | |
212 // CryptoResultResolver. | |
213 m_resolver = nullptr; | |
214 } else { | |
215 m_resolver = Resolver::create(scriptState, this).get(); | |
216 } | |
217 } | |
218 | |
219 ScriptPromise CryptoResultImpl::promise() | 226 ScriptPromise CryptoResultImpl::promise() |
220 { | 227 { |
221 return m_resolver ? m_resolver->promise() : ScriptPromise(); | 228 return m_resolver ? m_resolver->promise() : ScriptPromise(); |
222 } | 229 } |
223 | 230 |
224 } // namespace blink | 231 } // namespace blink |
OLD | NEW |