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 13 matching lines...) Expand all Loading... | |
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 */ | 29 */ |
30 | 30 |
31 #include "config.h" | 31 #include "config.h" |
32 #include "modules/crypto/CryptoResultImpl.h" | 32 #include "modules/crypto/CryptoResultImpl.h" |
33 | 33 |
34 #include "bindings/v8/ScriptPromiseResolver.h" | 34 #include "bindings/v8/NewScriptState.h" |
35 #include "bindings/v8/ScriptPromiseResolverWithContext.h" | |
35 #include "core/dom/ExecutionContext.h" | 36 #include "core/dom/ExecutionContext.h" |
36 #include "modules/crypto/Key.h" | 37 #include "modules/crypto/Key.h" |
37 #include "modules/crypto/KeyPair.h" | 38 #include "modules/crypto/KeyPair.h" |
38 #include "modules/crypto/NormalizeAlgorithm.h" | 39 #include "modules/crypto/NormalizeAlgorithm.h" |
39 #include "public/platform/Platform.h" | 40 #include "public/platform/Platform.h" |
40 #include "public/platform/WebArrayBuffer.h" | 41 #include "public/platform/WebArrayBuffer.h" |
41 #include "public/platform/WebCryptoAlgorithm.h" | 42 #include "public/platform/WebCryptoAlgorithm.h" |
42 #include "wtf/ArrayBufferView.h" | 43 #include "wtf/ArrayBufferView.h" |
43 | 44 |
44 namespace WebCore { | 45 namespace WebCore { |
45 | 46 |
46 CryptoResultImpl::~CryptoResultImpl() | 47 CryptoResultImpl::~CryptoResultImpl() |
47 { | 48 { |
48 } | 49 } |
49 | 50 |
50 PassRefPtr<CryptoResultImpl> CryptoResultImpl::create() | 51 PassRefPtr<CryptoResultImpl> CryptoResultImpl::create() |
51 { | 52 { |
52 return adoptRef(new CryptoResultImpl(callingExecutionContext(v8::Isolate::Ge tCurrent()))); | 53 return adoptRef(new CryptoResultImpl(callingExecutionContext(v8::Isolate::Ge tCurrent()))); |
53 } | 54 } |
54 | 55 |
55 void CryptoResultImpl::completeWithError(const blink::WebString& errorDetails) | 56 void CryptoResultImpl::completeWithError(const blink::WebString& errorDetails) |
56 { | 57 { |
57 ASSERT(!m_finished); | 58 ASSERT(!m_finished); |
58 | 59 |
59 if (canCompletePromise()) { | 60 if (canCompletePromise()) { |
60 NewScriptState::Scope scope(m_scriptState.get()); | |
61 if (!errorDetails.isEmpty()) { | 61 if (!errorDetails.isEmpty()) { |
62 // FIXME: Include the line number which started the crypto operation . | 62 // FIXME: Include the line number which started the crypto operation . |
63 executionContext()->addConsoleMessage(JSMessageSource, ErrorMessageL evel, errorDetails); | 63 executionContext()->addConsoleMessage(JSMessageSource, ErrorMessageL evel, errorDetails); |
64 } | 64 } |
65 m_promiseResolver->reject(ScriptValue::createNull()); | 65 m_promiseResolver->reject(ScriptValue::createNull()); |
66 } | 66 } |
67 } | 67 } |
68 | 68 |
69 void CryptoResultImpl::completeWithError() | 69 void CryptoResultImpl::completeWithError() |
70 { | 70 { |
71 completeWithError(blink::WebString()); | 71 completeWithError(blink::WebString()); |
72 } | 72 } |
73 | 73 |
74 void CryptoResultImpl::completeWithBuffer(const blink::WebArrayBuffer& buffer) | 74 void CryptoResultImpl::completeWithBuffer(const blink::WebArrayBuffer& buffer) |
75 { | 75 { |
76 ASSERT(!m_finished); | 76 ASSERT(!m_finished); |
77 | 77 |
78 if (canCompletePromise()) { | 78 if (canCompletePromise()) { |
79 NewScriptState::Scope scope(m_scriptState.get()); | |
80 m_promiseResolver->resolve(PassRefPtr<ArrayBuffer>(buffer)); | 79 m_promiseResolver->resolve(PassRefPtr<ArrayBuffer>(buffer)); |
81 } | 80 } |
82 | 81 |
83 finish(); | 82 finish(); |
84 } | 83 } |
85 | 84 |
86 void CryptoResultImpl::completeWithBoolean(bool b) | 85 void CryptoResultImpl::completeWithBoolean(bool b) |
87 { | 86 { |
88 ASSERT(!m_finished); | 87 ASSERT(!m_finished); |
89 | 88 |
90 if (canCompletePromise()) { | 89 if (canCompletePromise()) { |
91 NewScriptState::Scope scope(m_scriptState.get()); | |
eroman
2014/04/16 02:30:01
Are you sure this is correct? Although m_promiseRe
yhirano
2014/04/16 11:56:16
I've moved the conversion part inside ScriptPromis
| |
92 m_promiseResolver->resolve(ScriptValue::createBoolean(b)); | 90 m_promiseResolver->resolve(ScriptValue::createBoolean(b)); |
93 } | 91 } |
94 | 92 |
95 finish(); | 93 finish(); |
96 } | 94 } |
97 | 95 |
98 void CryptoResultImpl::completeWithKey(const blink::WebCryptoKey& key) | 96 void CryptoResultImpl::completeWithKey(const blink::WebCryptoKey& key) |
99 { | 97 { |
100 ASSERT(!m_finished); | 98 ASSERT(!m_finished); |
101 | 99 |
102 if (canCompletePromise()) { | 100 if (canCompletePromise()) { |
103 NewScriptState::Scope scope(m_scriptState.get()); | |
104 m_promiseResolver->resolve(Key::create(key)); | 101 m_promiseResolver->resolve(Key::create(key)); |
105 } | 102 } |
106 | 103 |
107 finish(); | 104 finish(); |
108 } | 105 } |
109 | 106 |
110 void CryptoResultImpl::completeWithKeyPair(const blink::WebCryptoKey& publicKey, const blink::WebCryptoKey& privateKey) | 107 void CryptoResultImpl::completeWithKeyPair(const blink::WebCryptoKey& publicKey, const blink::WebCryptoKey& privateKey) |
111 { | 108 { |
112 ASSERT(!m_finished); | 109 ASSERT(!m_finished); |
113 | 110 |
114 if (canCompletePromise()) { | 111 if (canCompletePromise()) { |
115 NewScriptState::Scope scope(m_scriptState.get()); | |
116 m_promiseResolver->resolve(KeyPair::create(publicKey, privateKey)); | 112 m_promiseResolver->resolve(KeyPair::create(publicKey, privateKey)); |
117 } | 113 } |
118 | 114 |
119 finish(); | 115 finish(); |
120 } | 116 } |
121 | 117 |
122 CryptoResultImpl::CryptoResultImpl(ExecutionContext* context) | 118 CryptoResultImpl::CryptoResultImpl(ExecutionContext* context) |
123 : ContextLifecycleObserver(context) | 119 : ContextLifecycleObserver(context) |
124 , m_promiseResolver(ScriptPromiseResolver::create(context)) | 120 , m_promiseResolver(ScriptPromiseResolverWithContext::create(NewScriptState: :current(toIsolate(context)))) |
125 , m_scriptState(NewScriptState::current(toIsolate(context))) | |
126 #if !ASSERT_DISABLED | 121 #if !ASSERT_DISABLED |
127 , m_owningThread(currentThread()) | 122 , m_owningThread(currentThread()) |
128 , m_finished(false) | 123 , m_finished(false) |
129 #endif | 124 #endif |
130 { | 125 { |
131 } | 126 } |
132 | 127 |
133 void CryptoResultImpl::finish() | 128 void CryptoResultImpl::finish() |
134 { | 129 { |
135 #if !ASSERT_DISABLED | 130 #if !ASSERT_DISABLED |
136 m_finished = true; | 131 m_finished = true; |
137 #endif | 132 #endif |
138 clearPromiseResolver(); | 133 clearPromiseResolver(); |
139 } | 134 } |
140 | 135 |
141 void CryptoResultImpl::clearPromiseResolver() | 136 void CryptoResultImpl::clearPromiseResolver() |
142 { | 137 { |
143 m_promiseResolver.clear(); | 138 m_promiseResolver.clear(); |
144 m_scriptState.clear(); | |
145 } | 139 } |
146 | 140 |
147 void CryptoResultImpl::CheckValidThread() const | 141 void CryptoResultImpl::CheckValidThread() const |
148 { | 142 { |
149 ASSERT(m_owningThread == currentThread()); | 143 ASSERT(m_owningThread == currentThread()); |
150 } | 144 } |
151 | 145 |
152 void CryptoResultImpl::contextDestroyed() | 146 void CryptoResultImpl::contextDestroyed() |
153 { | 147 { |
154 ContextLifecycleObserver::contextDestroyed(); | 148 ContextLifecycleObserver::contextDestroyed(); |
155 | 149 |
156 // Abandon the promise without completing it when the context goes away. | 150 // Abandon the promise without completing it when the context goes away. |
157 clearPromiseResolver(); | 151 clearPromiseResolver(); |
158 ASSERT(!canCompletePromise()); | 152 ASSERT(!canCompletePromise()); |
159 } | 153 } |
160 | 154 |
161 bool CryptoResultImpl::canCompletePromise() const | 155 bool CryptoResultImpl::canCompletePromise() const |
162 { | 156 { |
163 CheckValidThread(); | 157 CheckValidThread(); |
164 ExecutionContext* context = executionContext(); | 158 ExecutionContext* context = executionContext(); |
165 return context && !context->activeDOMObjectsAreSuspended() && !context->acti veDOMObjectsAreStopped(); | 159 return context && !context->activeDOMObjectsAreSuspended() && !context->acti veDOMObjectsAreStopped(); |
166 } | 160 } |
167 | 161 |
168 } // namespace WebCore | 162 } // namespace WebCore |
OLD | NEW |