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

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

Issue 19082002: WebCrypto: Add SHA-1 support to crypto.subtle.digest(). (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: don't hold a ScriptObject Created 7 years, 5 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
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/CryptoOperation.h" 32 #include "modules/crypto/CryptoOperation.h"
33 33
34 #include "bindings/v8/custom/V8ArrayBufferCustom.h" // MUST precede ScriptPromis eResolver for compilation to work.
35 #include "bindings/v8/ScriptPromiseResolver.h"
34 #include "modules/crypto/Algorithm.h" 36 #include "modules/crypto/Algorithm.h"
37 #include "public/platform/WebCrypto.h"
38 #include "public/web/WebArrayBuffer.h"
abarth-chromium 2013/07/12 16:58:31 This is a backwards dependency. You can fix this
eroman 2013/07/12 20:38:19 Done. I also added a temporary forwarding header f
39 #include "wtf/ArrayBuffer.h"
40 #include "wtf/ArrayBufferView.h"
35 41
36 namespace WebCore { 42 namespace WebCore {
37 43
38 CryptoOperation::CryptoOperation(const WebKit::WebCryptoAlgorithm& algorithm) 44 class CryptoOperation::Result : public WebKit::WebCryptoOperationResult {
45 public:
46 explicit Result(CryptoOperation* parent) : m_parent(parent) { }
47
48 virtual void setArrayBuffer(const WebKit::WebArrayBuffer& buffer) OVERRIDE
49 {
50 ASSERT(m_parent->m_state == Finishing);
51 m_parent->m_state = Done;
52 m_parent->m_impl = 0;
53
54 m_parent->m_promiseResolver->fulfill(PassRefPtr<ArrayBuffer>(buffer));
55 }
abarth-chromium 2013/07/12 16:58:31 Should this clear m_result when done too?
eroman 2013/07/12 20:38:19 I would prefer not to clear m_result, for debuggin
56
57 private:
58 CryptoOperation* m_parent;
59 };
60
61 CryptoOperation::~CryptoOperation()
62 {
63 abort();
64 ASSERT(!m_impl);
65 }
66
67 PassRefPtr<CryptoOperation> CryptoOperation::create(const WebKit::WebCryptoAlgor ithm& algorithm, WebKit::WebCryptoOperation* impl)
68 {
69 return adoptRef(new CryptoOperation(algorithm, impl));
70 }
71
72 CryptoOperation::CryptoOperation(const WebKit::WebCryptoAlgorithm& algorithm, We bKit::WebCryptoOperation* impl)
39 : m_algorithm(algorithm) 73 : m_algorithm(algorithm)
74 , m_impl(impl)
75 , m_state(Processing)
76 , m_result(adoptPtr(new Result(this)))
40 { 77 {
78 ASSERT(impl);
41 ScriptWrappable::init(this); 79 ScriptWrappable::init(this);
80
81 m_promiseResolver = ScriptPromiseResolver::create();
82 }
83
84 CryptoOperation* CryptoOperation::process(ArrayBuffer* data)
85 {
86 process(static_cast<unsigned char*>(data->data()), data->byteLength());
87 return this;
88 }
89
90 CryptoOperation* CryptoOperation::process(ArrayBufferView* data)
91 {
92 process(static_cast<unsigned char*>(data->baseAddress()), data->byteLength() );
93 return this;
94 }
95
96 CryptoOperation* CryptoOperation::finish()
97 {
98 switch (m_state) {
99 case Processing:
100 m_state = Finishing;
101 // NOTE: The following line can result in re-entrancy to |this|
102 m_impl->finish(m_result.get());
103 break;
104 case Finishing:
105 // Calling finish() twice is a no-op.
106 break;
107 case Done:
108 // Calling finish() after already complete is a no-op.
109 ASSERT(!m_impl);
110 break;
111 }
112
113 return this;
114 }
115
116 CryptoOperation* CryptoOperation::abort()
117 {
118 switch (m_state) {
119 case Processing:
120 case Finishing:
121 // This will cause m_impl to be deleted.
122 m_impl->abort();
123 m_state = Done;
124 m_impl = 0;
125 m_promiseResolver->reject(ScriptValue(v8::Null()));
abarth-chromium 2013/07/12 16:58:31 We should give ScriptValue a factor method for mak
eroman 2013/07/12 20:38:19 Done.
126 break;
127 case Done:
128 ASSERT(!m_impl);
129 break;
130 }
131
132 return this;
42 } 133 }
43 134
44 Algorithm* CryptoOperation::algorithm() 135 Algorithm* CryptoOperation::algorithm()
45 { 136 {
46 if (!m_algorithmNode) 137 if (!m_algorithmNode)
47 m_algorithmNode = Algorithm::create(m_algorithm); 138 m_algorithmNode = Algorithm::create(m_algorithm);
48 return m_algorithmNode.get(); 139 return m_algorithmNode.get();
49 } 140 }
50 141
142 ScriptObject CryptoOperation::promise()
143 {
144 return m_promiseResolver->promise();
145 }
146
147 void CryptoOperation::process(const unsigned char* bytes, size_t size)
148 {
149 switch (m_state) {
150 case Processing:
151 m_impl->process(bytes, size);
152 break;
153 case Finishing:
154 case Done:
155 return;
156 }
157 }
158
51 } // namespace WebCore 159 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698