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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 { | 93 { |
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(V8ObjectBuilder& builder) |
103 : m_scriptState(scriptState) | 104 : m_builder(builder) |
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, DOMUint8Array::create(vector.data(), vector.
size())); |
130 } | 130 } |
131 | 131 |
132 const Dictionary& dictionary() const { return m_dictionary; } | |
133 | |
134 private: | 132 private: |
135 RefPtr<ScriptState> m_scriptState; | 133 V8ObjectBuilder& m_builder; |
136 Dictionary m_dictionary; | |
137 }; | 134 }; |
138 | 135 |
139 } // namespace | 136 } // namespace |
140 | 137 |
141 CryptoKey::~CryptoKey() | 138 CryptoKey::~CryptoKey() |
142 { | 139 { |
143 } | 140 } |
144 | 141 |
145 CryptoKey::CryptoKey(const WebCryptoKey& key) | 142 CryptoKey::CryptoKey(const WebCryptoKey& key) |
146 : m_key(key) | 143 : m_key(key) |
147 { | 144 { |
148 } | 145 } |
149 | 146 |
150 String CryptoKey::type() const | 147 String CryptoKey::type() const |
151 { | 148 { |
152 return keyTypeToString(m_key.type()); | 149 return keyTypeToString(m_key.type()); |
153 } | 150 } |
154 | 151 |
155 bool CryptoKey::extractable() const | 152 bool CryptoKey::extractable() const |
156 { | 153 { |
157 return m_key.extractable(); | 154 return m_key.extractable(); |
158 } | 155 } |
159 | 156 |
160 ScriptValue CryptoKey::algorithm(ScriptState* scriptState) | 157 ScriptValue CryptoKey::algorithm(ScriptState* scriptState) |
161 { | 158 { |
162 DictionaryBuilder builder(scriptState); | 159 V8ObjectBuilder objectBuilder(scriptState); |
163 m_key.algorithm().writeToDictionary(&builder); | 160 DictionaryBuilder dictionaryBuilder(objectBuilder); |
164 return ScriptValue(scriptState, builder.dictionary().v8Value()); | 161 m_key.algorithm().writeToDictionary(&dictionaryBuilder); |
| 162 return objectBuilder.scriptValue(); |
165 } | 163 } |
166 | 164 |
167 // FIXME: This creates a new javascript array each time. What should happen | 165 // FIXME: This creates a new javascript array each time. What should happen |
168 // instead is return the same (immutable) array. (Javascript callers can | 166 // instead is return the same (immutable) array. (Javascript callers can |
169 // distinguish this by doing an == test on the arrays and seeing they are | 167 // distinguish this by doing an == test on the arrays and seeing they are |
170 // different). | 168 // different). |
171 Vector<String> CryptoKey::usages() const | 169 Vector<String> CryptoKey::usages() const |
172 { | 170 { |
173 Vector<String> result; | 171 Vector<String> result; |
174 for (size_t i = 0; i < WTF_ARRAY_LENGTH(keyUsageMappings); ++i) { | 172 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) { | 224 if (!usage) { |
227 result->completeWithError(WebCryptoErrorTypeType, "Invalid keyUsages
argument"); | 225 result->completeWithError(WebCryptoErrorTypeType, "Invalid keyUsages
argument"); |
228 return false; | 226 return false; |
229 } | 227 } |
230 mask |= usage; | 228 mask |= usage; |
231 } | 229 } |
232 return true; | 230 return true; |
233 } | 231 } |
234 | 232 |
235 } // namespace blink | 233 } // namespace blink |
OLD | NEW |