Chromium Code Reviews| 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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 43 #include "core/dom/ExecutionContext.h" | 43 #include "core/dom/ExecutionContext.h" |
| 44 #include "modules/crypto/CryptoKey.h" | 44 #include "modules/crypto/CryptoKey.h" |
| 45 #include "modules/crypto/NormalizeAlgorithm.h" | 45 #include "modules/crypto/NormalizeAlgorithm.h" |
| 46 #include "public/platform/Platform.h" | 46 #include "public/platform/Platform.h" |
| 47 #include "public/platform/WebCryptoAlgorithm.h" | 47 #include "public/platform/WebCryptoAlgorithm.h" |
| 48 | 48 |
| 49 namespace blink { | 49 namespace blink { |
| 50 | 50 |
| 51 class CryptoResultImpl::WeakResolver : public ScriptPromiseResolver { | 51 class CryptoResultImpl::WeakResolver : public ScriptPromiseResolver { |
| 52 public: | 52 public: |
| 53 static WeakPtr<ScriptPromiseResolver> create(ScriptState* scriptState, Crypt oResultImpl* result) | 53 static PassRefPtr<ScriptPromiseResolver> create(ScriptState* scriptState, Cr yptoResultImpl* result) |
| 54 { | 54 { |
| 55 RefPtr<WeakResolver> p = adoptRef(new WeakResolver(scriptState, result)) ; | 55 RefPtr<WeakResolver> p = adoptRef(new WeakResolver(scriptState, result)) ; |
| 56 p->suspendIfNeeded(); | 56 p->suspendIfNeeded(); |
| 57 p->keepAliveWhilePending(); | 57 p->keepAliveWhilePending(); |
| 58 return p->m_weakPtrFactory.createWeakPtr(); | 58 return p.release(); |
| 59 } | 59 } |
| 60 | 60 |
| 61 virtual ~WeakResolver() | 61 virtual void stop() override |
| 62 { | 62 { |
| 63 m_result->cancel(); | 63 m_result->cancel(); |
| 64 m_result->clearResolver(); | |
| 65 ScriptPromiseResolver::stop(); | |
| 64 } | 66 } |
| 65 | 67 |
| 66 private: | 68 private: |
| 67 WeakResolver(ScriptState* scriptState, CryptoResultImpl* result) | 69 WeakResolver(ScriptState* scriptState, CryptoResultImpl* result) |
| 68 : ScriptPromiseResolver(scriptState) | 70 : ScriptPromiseResolver(scriptState) |
| 69 , m_weakPtrFactory(this) | |
| 70 , m_result(result) { } | 71 , m_result(result) { } |
| 71 WeakPtrFactory<ScriptPromiseResolver> m_weakPtrFactory; | 72 CryptoResultImpl* m_result; |
|
yhirano
2014/12/11 02:27:59
I'm not sure this change is correct, because I thi
tasak
2014/12/11 09:44:39
I see.
Now CryptoResultImpl::clearResolver() invok
| |
| 72 RefPtr<CryptoResultImpl> m_result; | |
| 73 }; | 73 }; |
| 74 | 74 |
| 75 ExceptionCode webCryptoErrorToExceptionCode(WebCryptoErrorType errorType) | 75 ExceptionCode webCryptoErrorToExceptionCode(WebCryptoErrorType errorType) |
| 76 { | 76 { |
| 77 switch (errorType) { | 77 switch (errorType) { |
| 78 case WebCryptoErrorTypeNotSupported: | 78 case WebCryptoErrorTypeNotSupported: |
| 79 return NotSupportedError; | 79 return NotSupportedError; |
| 80 case WebCryptoErrorTypeSyntax: | 80 case WebCryptoErrorTypeSyntax: |
| 81 return SyntaxError; | 81 return SyntaxError; |
| 82 case WebCryptoErrorTypeInvalidState: | 82 case WebCryptoErrorTypeInvalidState: |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 97 } | 97 } |
| 98 | 98 |
| 99 ASSERT_NOT_REACHED(); | 99 ASSERT_NOT_REACHED(); |
| 100 return 0; | 100 return 0; |
| 101 } | 101 } |
| 102 | 102 |
| 103 CryptoResultImpl::~CryptoResultImpl() | 103 CryptoResultImpl::~CryptoResultImpl() |
| 104 { | 104 { |
| 105 } | 105 } |
| 106 | 106 |
| 107 void CryptoResultImpl::clearResolver() | |
| 108 { | |
| 109 m_resolver = nullptr; | |
| 110 } | |
| 111 | |
| 107 PassRefPtr<CryptoResultImpl> CryptoResultImpl::create(ScriptState* scriptState) | 112 PassRefPtr<CryptoResultImpl> CryptoResultImpl::create(ScriptState* scriptState) |
| 108 { | 113 { |
| 109 return adoptRef(new CryptoResultImpl(scriptState)); | 114 return adoptRef(new CryptoResultImpl(scriptState)); |
| 110 } | 115 } |
| 111 | 116 |
| 112 void CryptoResultImpl::completeWithError(WebCryptoErrorType errorType, const Web String& errorDetails) | 117 void CryptoResultImpl::completeWithError(WebCryptoErrorType errorType, const Web String& errorDetails) |
| 113 { | 118 { |
| 114 if (m_resolver) | 119 if (m_resolver) |
| 115 m_resolver->reject(DOMException::create(webCryptoErrorToExceptionCode(er rorType), errorDetails)); | 120 m_resolver->reject(DOMException::create(webCryptoErrorToExceptionCode(er rorType), errorDetails)); |
| 121 m_resolver = nullptr; | |
| 116 } | 122 } |
| 117 | 123 |
| 118 void CryptoResultImpl::completeWithBuffer(const void* bytes, unsigned bytesSize) | 124 void CryptoResultImpl::completeWithBuffer(const void* bytes, unsigned bytesSize) |
| 119 { | 125 { |
| 120 if (m_resolver) | 126 if (m_resolver) |
| 121 m_resolver->resolve(DOMArrayBuffer::create(bytes, bytesSize)); | 127 m_resolver->resolve(DOMArrayBuffer::create(bytes, bytesSize)); |
| 128 m_resolver = nullptr; | |
| 122 } | 129 } |
| 123 | 130 |
| 124 void CryptoResultImpl::completeWithJson(const char* utf8Data, unsigned length) | 131 void CryptoResultImpl::completeWithJson(const char* utf8Data, unsigned length) |
| 125 { | 132 { |
| 126 if (m_resolver) { | 133 if (m_resolver) { |
| 127 ScriptPromiseResolver* resolver = m_resolver.get(); | 134 ScriptPromiseResolver* resolver = m_resolver.get(); |
| 128 ScriptState* scriptState = resolver->scriptState(); | 135 ScriptState* scriptState = resolver->scriptState(); |
| 129 ScriptState::Scope scope(scriptState); | 136 ScriptState::Scope scope(scriptState); |
| 130 | 137 |
| 131 v8::Handle<v8::String> jsonString = v8::String::NewFromUtf8(scriptState- >isolate(), utf8Data, v8::String::kInternalizedString, length); | 138 v8::Handle<v8::String> jsonString = v8::String::NewFromUtf8(scriptState- >isolate(), utf8Data, v8::String::kInternalizedString, length); |
| 132 | 139 |
| 133 v8::TryCatch exceptionCatcher; | 140 v8::TryCatch exceptionCatcher; |
| 134 v8::Handle<v8::Value> jsonDictionary = v8::JSON::Parse(jsonString); | 141 v8::Handle<v8::Value> jsonDictionary = v8::JSON::Parse(jsonString); |
| 135 if (exceptionCatcher.HasCaught() || jsonDictionary.IsEmpty()) { | 142 if (exceptionCatcher.HasCaught() || jsonDictionary.IsEmpty()) { |
| 136 ASSERT_NOT_REACHED(); | 143 ASSERT_NOT_REACHED(); |
| 137 resolver->reject(DOMException::create(OperationError, "Failed inflat ing JWK JSON to object")); | 144 resolver->reject(DOMException::create(OperationError, "Failed inflat ing JWK JSON to object")); |
| 138 } else { | 145 } else { |
| 139 resolver->resolve(jsonDictionary); | 146 resolver->resolve(jsonDictionary); |
| 140 } | 147 } |
| 141 } | 148 } |
| 149 m_resolver = nullptr; | |
| 142 } | 150 } |
| 143 | 151 |
| 144 void CryptoResultImpl::completeWithBoolean(bool b) | 152 void CryptoResultImpl::completeWithBoolean(bool b) |
| 145 { | 153 { |
| 146 if (m_resolver) | 154 if (m_resolver) |
| 147 m_resolver->resolve(b); | 155 m_resolver->resolve(b); |
| 156 m_resolver = nullptr; | |
| 148 } | 157 } |
| 149 | 158 |
| 150 void CryptoResultImpl::completeWithKey(const WebCryptoKey& key) | 159 void CryptoResultImpl::completeWithKey(const WebCryptoKey& key) |
| 151 { | 160 { |
| 152 if (m_resolver) | 161 if (m_resolver) |
| 153 m_resolver->resolve(CryptoKey::create(key)); | 162 m_resolver->resolve(CryptoKey::create(key)); |
| 163 m_resolver = nullptr; | |
| 154 } | 164 } |
| 155 | 165 |
| 156 void CryptoResultImpl::completeWithKeyPair(const WebCryptoKey& publicKey, const WebCryptoKey& privateKey) | 166 void CryptoResultImpl::completeWithKeyPair(const WebCryptoKey& publicKey, const WebCryptoKey& privateKey) |
| 157 { | 167 { |
| 158 if (m_resolver) { | 168 if (m_resolver) { |
| 159 ScriptState* scriptState = m_resolver->scriptState(); | 169 ScriptState* scriptState = m_resolver->scriptState(); |
| 160 ScriptState::Scope scope(scriptState); | 170 ScriptState::Scope scope(scriptState); |
| 161 | 171 |
| 162 Dictionary keyPair = Dictionary::createEmpty(scriptState->isolate()); | 172 Dictionary keyPair = Dictionary::createEmpty(scriptState->isolate()); |
| 163 | 173 |
| 164 v8::Handle<v8::Value> publicKeyValue = toV8(CryptoKey::create(publicKey) , scriptState->context()->Global(), scriptState->isolate()); | 174 v8::Handle<v8::Value> publicKeyValue = toV8(CryptoKey::create(publicKey) , scriptState->context()->Global(), scriptState->isolate()); |
| 165 v8::Handle<v8::Value> privateKeyValue = toV8(CryptoKey::create(privateKe y), scriptState->context()->Global(), scriptState->isolate()); | 175 v8::Handle<v8::Value> privateKeyValue = toV8(CryptoKey::create(privateKe y), scriptState->context()->Global(), scriptState->isolate()); |
| 166 | 176 |
| 167 keyPair.set("publicKey", publicKeyValue); | 177 keyPair.set("publicKey", publicKeyValue); |
| 168 keyPair.set("privateKey", privateKeyValue); | 178 keyPair.set("privateKey", privateKeyValue); |
| 169 | 179 |
| 170 m_resolver->resolve(keyPair.v8Value()); | 180 m_resolver->resolve(keyPair.v8Value()); |
| 171 } | 181 } |
| 182 m_resolver = nullptr; | |
| 172 } | 183 } |
| 173 | 184 |
| 174 bool CryptoResultImpl::cancelled() const | 185 bool CryptoResultImpl::cancelled() const |
| 175 { | 186 { |
| 176 return acquireLoad(&m_cancelled); | 187 return acquireLoad(&m_cancelled); |
| 177 } | 188 } |
| 178 | 189 |
| 179 void CryptoResultImpl::cancel() | 190 void CryptoResultImpl::cancel() |
| 180 { | 191 { |
| 181 releaseStore(&m_cancelled, 1); | 192 releaseStore(&m_cancelled, 1); |
| 182 } | 193 } |
| 183 | 194 |
| 184 CryptoResultImpl::CryptoResultImpl(ScriptState* scriptState) | 195 CryptoResultImpl::CryptoResultImpl(ScriptState* scriptState) |
| 185 : m_cancelled(0) | 196 : m_cancelled(0) |
| 186 { | 197 { |
| 187 // Creating the WeakResolver may return nullptr if active dom objects have | 198 // Creating the WeakResolver may return nullptr if active dom objects have |
|
eroman
2014/12/09 19:15:29
This comment is no longer correct, and I believe t
tasak
2014/12/11 09:44:39
I see.
I checked whether ActiveDOMObjectStopped he
| |
| 188 // been stopped. And in the process set m_cancelled to 1. | 199 // been stopped. And in the process set m_cancelled to 1. |
| 189 m_resolver = WeakResolver::create(scriptState, this); | 200 m_resolver = WeakResolver::create(scriptState, this).get(); |
| 190 } | 201 } |
| 191 | 202 |
| 192 ScriptPromise CryptoResultImpl::promise() | 203 ScriptPromise CryptoResultImpl::promise() |
| 193 { | 204 { |
| 194 return m_resolver ? m_resolver->promise() : ScriptPromise(); | 205 return m_resolver ? m_resolver->promise() : ScriptPromise(); |
| 195 } | 206 } |
| 196 | 207 |
| 197 } // namespace blink | 208 } // namespace blink |
| OLD | NEW |