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

Side by Side Diff: Source/modules/crypto/SubtleCrypto.cpp

Issue 23338006: Cleanup: remove WebCryptoResultPrivate from blink API. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Remove extra newline Created 7 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 | Annotate | Revision Log
« no previous file with comments | « Source/modules/crypto/CryptoResult.cpp ('k') | Source/modules/modules.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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/SubtleCrypto.h" 32 #include "modules/crypto/SubtleCrypto.h"
33 33
34 #include "V8Key.h" // Must precede ScriptPromiseResolver.h
35 #include "bindings/v8/ExceptionState.h" 34 #include "bindings/v8/ExceptionState.h"
36 #include "bindings/v8/custom/V8ArrayBufferCustom.h" // Must precede ScriptPromis eResolver.h
37 #include "bindings/v8/ScriptPromiseResolver.h"
38 #include "core/dom/ExceptionCode.h" 35 #include "core/dom/ExceptionCode.h"
36 #include "modules/crypto/CryptoResult.h"
39 #include "modules/crypto/Key.h" 37 #include "modules/crypto/Key.h"
40 #include "modules/crypto/NormalizeAlgorithm.h" 38 #include "modules/crypto/NormalizeAlgorithm.h"
41 #include "public/platform/Platform.h" 39 #include "public/platform/Platform.h"
42 #include "public/platform/WebArrayBuffer.h"
43 #include "public/platform/WebCrypto.h" 40 #include "public/platform/WebCrypto.h"
44 #include "public/platform/WebCryptoAlgorithm.h" 41 #include "public/platform/WebCryptoAlgorithm.h"
45 #include "wtf/ArrayBufferView.h" 42 #include "wtf/ArrayBufferView.h"
46 43
47 namespace WebCore { 44 namespace WebCore {
48 45
49 // FIXME: asynchronous completion of CryptoResult. Need to re-enter the 46 // FIXME: asynchronous completion of CryptoResult. Need to re-enter the
50 // v8::Context before trying to fulfill the promise, and enable test. 47 // v8::Context before trying to fulfill the promise, and enable test.
51 48
52 namespace { 49 namespace {
53 50
54 class CryptoResult : public WebKit::WebCryptoResultPrivate, public ThreadSafeRef Counted<CryptoResult> {
55 public:
56 static PassRefPtr<CryptoResult> create()
57 {
58 return adoptRef(new CryptoResult);
59 }
60
61 virtual void ref() OVERRIDE
62 {
63 ThreadSafeRefCounted<CryptoResult>::ref();
64 }
65
66 virtual void deref() OVERRIDE
67 {
68 ThreadSafeRefCounted<CryptoResult>::deref();
69 }
70
71 virtual void completeWithError() OVERRIDE
72 {
73 m_promiseResolver->reject(ScriptValue::createNull());
74 finish();
75 }
76
77 virtual void completeWithBuffer(const WebKit::WebArrayBuffer& buffer) OVERRI DE
78 {
79 m_promiseResolver->fulfill(PassRefPtr<ArrayBuffer>(buffer));
80 finish();
81 }
82
83 virtual void completeWithBoolean(bool b) OVERRIDE
84 {
85 m_promiseResolver->fulfill(ScriptValue::createBoolean(b));
86 finish();
87 }
88
89 virtual void completeWithKey(const WebKit::WebCryptoKey& key) OVERRIDE
90 {
91 m_promiseResolver->fulfill(Key::create(key));
92 finish();
93 }
94
95 WebKit::WebCryptoResult result()
96 {
97 return WebKit::WebCryptoResult(this);
98 }
99
100 ScriptObject promise()
101 {
102 return m_promiseResolver->promise();
103 }
104
105 private:
106 CryptoResult()
107 : m_promiseResolver(ScriptPromiseResolver::create())
108 , m_finished(false) { }
109
110 void finish()
111 {
112 ASSERT(!m_finished);
113 m_finished = true;
114 }
115
116 RefPtr<ScriptPromiseResolver> m_promiseResolver;
117 bool m_finished;
118 };
119
120 ScriptObject startCryptoOperation(const Dictionary& rawAlgorithm, Key* key, Algo rithmOperation operationType, ArrayBufferView* signature, ArrayBufferView* dataB uffer, ExceptionState& es) 51 ScriptObject startCryptoOperation(const Dictionary& rawAlgorithm, Key* key, Algo rithmOperation operationType, ArrayBufferView* signature, ArrayBufferView* dataB uffer, ExceptionState& es)
121 { 52 {
122 WebKit::WebCrypto* platformCrypto = WebKit::Platform::current()->crypto(); 53 WebKit::WebCrypto* platformCrypto = WebKit::Platform::current()->crypto();
123 if (!platformCrypto) { 54 if (!platformCrypto) {
124 es.throwDOMException(NotSupportedError); 55 es.throwDOMException(NotSupportedError);
125 return ScriptObject(); 56 return ScriptObject();
126 } 57 }
127 58
128 bool requiresKey = operationType != Digest; 59 bool requiresKey = operationType != Digest;
129 60
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 return ScriptObject(); 188 return ScriptObject();
258 189
259 const unsigned char* keyDataBytes = static_cast<unsigned char*>(keyData->bas eAddress()); 190 const unsigned char* keyDataBytes = static_cast<unsigned char*>(keyData->bas eAddress());
260 191
261 RefPtr<CryptoResult> result = CryptoResult::create(); 192 RefPtr<CryptoResult> result = CryptoResult::create();
262 platformCrypto->importKey(format, keyDataBytes, keyData->byteLength(), algor ithm, extractable, keyUsages, result->result()); 193 platformCrypto->importKey(format, keyDataBytes, keyData->byteLength(), algor ithm, extractable, keyUsages, result->result());
263 return result->promise(); 194 return result->promise();
264 } 195 }
265 196
266 } // namespace WebCore 197 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/modules/crypto/CryptoResult.cpp ('k') | Source/modules/modules.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698