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 14 matching lines...) Expand all Loading... | |
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/CryptoKey.h" | 32 #include "modules/crypto/CryptoKey.h" |
33 | 33 |
34 #include "bindings/core/v8/ExceptionState.h" | 34 #include "bindings/core/v8/ExceptionState.h" |
35 #include "bindings/core/v8/V8ObjectBuilder.h" | |
35 #include "bindings/core/v8/V8Uint8Array.h" | 36 #include "bindings/core/v8/V8Uint8Array.h" |
36 #include "core/dom/ExceptionCode.h" | 37 #include "core/dom/ExceptionCode.h" |
37 #include "platform/CryptoResult.h" | 38 #include "platform/CryptoResult.h" |
38 #include "public/platform/WebCryptoAlgorithmParams.h" | 39 #include "public/platform/WebCryptoAlgorithmParams.h" |
39 #include "public/platform/WebCryptoKeyAlgorithm.h" | 40 #include "public/platform/WebCryptoKeyAlgorithm.h" |
40 #include "public/platform/WebString.h" | 41 #include "public/platform/WebString.h" |
41 | 42 |
42 namespace blink { | 43 namespace blink { |
43 | 44 |
44 namespace { | 45 namespace { |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
93 for (size_t i = 0; i < WTF_ARRAY_LENGTH(keyUsageMappings); ++i) { | 94 for (size_t i = 0; i < WTF_ARRAY_LENGTH(keyUsageMappings); ++i) { |
94 if (keyUsageMappings[i].name == usageString) | 95 if (keyUsageMappings[i].name == usageString) |
95 return keyUsageMappings[i].value; | 96 return keyUsageMappings[i].value; |
96 } | 97 } |
97 return 0; | 98 return 0; |
98 } | 99 } |
99 | 100 |
100 class DictionaryBuilder : public blink::WebCryptoKeyAlgorithmDictionary { | 101 class DictionaryBuilder : public blink::WebCryptoKeyAlgorithmDictionary { |
101 public: | 102 public: |
102 explicit DictionaryBuilder(ScriptState* scriptState) | 103 explicit DictionaryBuilder(ScriptState* scriptState) |
103 : m_scriptState(scriptState) | 104 : m_builder(scriptState) |
104 , m_dictionary(Dictionary::createEmpty(scriptState->isolate())) | |
105 { | 105 { |
106 } | 106 } |
107 | 107 |
108 virtual void setString(const char* propertyName, const char* value) | 108 virtual void setString(const char* propertyName, const char* value) |
109 { | 109 { |
110 m_dictionary.set(propertyName, value); | 110 m_builder.addString(propertyName, value); |
111 } | 111 } |
112 | 112 |
113 virtual void setUint(const char* propertyName, unsigned value) | 113 virtual void setUint(const char* propertyName, unsigned value) |
114 { | 114 { |
115 m_dictionary.set(propertyName, value); | 115 m_builder.addNumber(propertyName, value); |
116 } | 116 } |
117 | 117 |
118 virtual void setAlgorithm(const char* propertyName, const blink::WebCryptoAl gorithm& algorithm) | 118 virtual void setAlgorithm(const char* propertyName, const blink::WebCryptoAl gorithm& algorithm) |
119 { | 119 { |
120 ASSERT(algorithm.paramsType() == blink::WebCryptoAlgorithmParamsTypeNone ); | 120 ASSERT(algorithm.paramsType() == blink::WebCryptoAlgorithmParamsTypeNone ); |
121 | 121 |
122 Dictionary algorithmValue = Dictionary::createEmpty(m_scriptState->isola te()); | 122 V8ObjectBuilder algorithmValue(m_builder.scriptState()); |
123 algorithmValue.set("name", blink::WebCryptoAlgorithm::lookupAlgorithmInf o(algorithm.id())->name); | 123 algorithmValue.addString("name", blink::WebCryptoAlgorithm::lookupAlgori thmInfo(algorithm.id())->name); |
124 m_dictionary.set(propertyName, algorithmValue); | 124 m_builder.add(propertyName, algorithmValue); |
125 } | 125 } |
126 | 126 |
127 virtual void setUint8Array(const char* propertyName, const blink::WebVector< unsigned char>& vector) | 127 virtual void setUint8Array(const char* propertyName, const blink::WebVector< unsigned char>& vector) |
128 { | 128 { |
129 m_dictionary.set(propertyName, toV8(DOMUint8Array::create(vector.data(), vector.size()), m_scriptState->context()->Global(), m_scriptState->isolate())); | 129 m_builder.add(propertyName, ScriptValue::from(m_builder.scriptState(), D OMUint8Array::create(vector.data(), vector.size()))); |
bashi
2015/03/25 01:09:25
IMHO, having addUint8Array() in V8ObjectBuilder wo
Jens Widell
2015/03/25 11:16:04
I'm not sure. Supporting generic values (e.g. Scri
Jens Widell
2015/03/25 11:34:01
Generic add() added now, and the explicit ScriptVa
| |
130 } | 130 } |
131 | 131 |
132 const Dictionary& dictionary() const { return m_dictionary; } | 132 ScriptValue value() const { return m_builder.scriptValue(); } |
133 | 133 |
134 private: | 134 private: |
135 RefPtr<ScriptState> m_scriptState; | 135 V8ObjectBuilder m_builder; |
136 Dictionary m_dictionary; | |
137 }; | 136 }; |
138 | 137 |
139 } // namespace | 138 } // namespace |
140 | 139 |
141 CryptoKey::~CryptoKey() | 140 CryptoKey::~CryptoKey() |
142 { | 141 { |
143 } | 142 } |
144 | 143 |
145 CryptoKey::CryptoKey(const WebCryptoKey& key) | 144 CryptoKey::CryptoKey(const WebCryptoKey& key) |
146 : m_key(key) | 145 : m_key(key) |
147 { | 146 { |
148 } | 147 } |
149 | 148 |
150 String CryptoKey::type() const | 149 String CryptoKey::type() const |
151 { | 150 { |
152 return keyTypeToString(m_key.type()); | 151 return keyTypeToString(m_key.type()); |
153 } | 152 } |
154 | 153 |
155 bool CryptoKey::extractable() const | 154 bool CryptoKey::extractable() const |
156 { | 155 { |
157 return m_key.extractable(); | 156 return m_key.extractable(); |
158 } | 157 } |
159 | 158 |
160 ScriptValue CryptoKey::algorithm(ScriptState* scriptState) | 159 ScriptValue CryptoKey::algorithm(ScriptState* scriptState) |
161 { | 160 { |
162 DictionaryBuilder builder(scriptState); | 161 DictionaryBuilder builder(scriptState); |
163 m_key.algorithm().writeToDictionary(&builder); | 162 m_key.algorithm().writeToDictionary(&builder); |
164 return ScriptValue(scriptState, builder.dictionary().v8Value()); | 163 return builder.value(); |
165 } | 164 } |
166 | 165 |
167 // FIXME: This creates a new javascript array each time. What should happen | 166 // FIXME: This creates a new javascript array each time. What should happen |
168 // instead is return the same (immutable) array. (Javascript callers can | 167 // instead is return the same (immutable) array. (Javascript callers can |
169 // distinguish this by doing an == test on the arrays and seeing they are | 168 // distinguish this by doing an == test on the arrays and seeing they are |
170 // different). | 169 // different). |
171 Vector<String> CryptoKey::usages() const | 170 Vector<String> CryptoKey::usages() const |
172 { | 171 { |
173 Vector<String> result; | 172 Vector<String> result; |
174 for (size_t i = 0; i < WTF_ARRAY_LENGTH(keyUsageMappings); ++i) { | 173 for (size_t i = 0; i < WTF_ARRAY_LENGTH(keyUsageMappings); ++i) { |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
226 if (!usage) { | 225 if (!usage) { |
227 result->completeWithError(WebCryptoErrorTypeType, "Invalid keyUsages argument"); | 226 result->completeWithError(WebCryptoErrorTypeType, "Invalid keyUsages argument"); |
228 return false; | 227 return false; |
229 } | 228 } |
230 mask |= usage; | 229 mask |= usage; |
231 } | 230 } |
232 return true; | 231 return true; |
233 } | 232 } |
234 | 233 |
235 } // namespace blink | 234 } // namespace blink |
OLD | NEW |