| 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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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_scriptState(scriptState) |
| 104 , m_dictionary(Dictionary::createEmpty(scriptState->isolate())) | 105 , m_builder(scriptState->isolate()) |
| 105 { | 106 { |
| 106 } | 107 } |
| 107 | 108 |
| 108 virtual void setString(const char* propertyName, const char* value) | 109 virtual void setString(const char* propertyName, const char* value) |
| 109 { | 110 { |
| 110 m_dictionary.set(propertyName, value); | 111 m_builder.addString(propertyName, value); |
| 111 } | 112 } |
| 112 | 113 |
| 113 virtual void setUint(const char* propertyName, unsigned value) | 114 virtual void setUint(const char* propertyName, unsigned value) |
| 114 { | 115 { |
| 115 m_dictionary.set(propertyName, value); | 116 m_builder.addNumber(propertyName, value); |
| 116 } | 117 } |
| 117 | 118 |
| 118 virtual void setAlgorithm(const char* propertyName, const blink::WebCryptoAl
gorithm& algorithm) | 119 virtual void setAlgorithm(const char* propertyName, const blink::WebCryptoAl
gorithm& algorithm) |
| 119 { | 120 { |
| 120 ASSERT(algorithm.paramsType() == blink::WebCryptoAlgorithmParamsTypeNone
); | 121 ASSERT(algorithm.paramsType() == blink::WebCryptoAlgorithmParamsTypeNone
); |
| 121 | 122 |
| 122 Dictionary algorithmValue = Dictionary::createEmpty(m_scriptState->isola
te()); | 123 V8ObjectBuilder algorithmValue(m_scriptState->isolate()); |
| 123 algorithmValue.set("name", blink::WebCryptoAlgorithm::lookupAlgorithmInf
o(algorithm.id())->name); | 124 algorithmValue.addString("name", blink::WebCryptoAlgorithm::lookupAlgori
thmInfo(algorithm.id())->name); |
| 124 m_dictionary.set(propertyName, algorithmValue); | 125 m_builder.add(propertyName, algorithmValue); |
| 125 } | 126 } |
| 126 | 127 |
| 127 virtual void setUint8Array(const char* propertyName, const blink::WebVector<
unsigned char>& vector) | 128 virtual void setUint8Array(const char* propertyName, const blink::WebVector<
unsigned char>& vector) |
| 128 { | 129 { |
| 129 m_dictionary.set(propertyName, toV8(DOMUint8Array::create(vector.data(),
vector.size()), m_scriptState->context()->Global(), m_scriptState->isolate())); | 130 m_builder.add(propertyName, ScriptValue::from(m_scriptState.get(), DOMUi
nt8Array::create(vector.data(), vector.size()))); |
| 130 } | 131 } |
| 131 | 132 |
| 132 const Dictionary& dictionary() const { return m_dictionary; } | 133 ScriptValue value() const { return m_builder.scriptValue(); } |
| 133 | 134 |
| 134 private: | 135 private: |
| 135 RefPtr<ScriptState> m_scriptState; | 136 RefPtr<ScriptState> m_scriptState; |
| 136 Dictionary m_dictionary; | 137 V8ObjectBuilder m_builder; |
| 137 }; | 138 }; |
| 138 | 139 |
| 139 } // namespace | 140 } // namespace |
| 140 | 141 |
| 141 CryptoKey::~CryptoKey() | 142 CryptoKey::~CryptoKey() |
| 142 { | 143 { |
| 143 } | 144 } |
| 144 | 145 |
| 145 CryptoKey::CryptoKey(const WebCryptoKey& key) | 146 CryptoKey::CryptoKey(const WebCryptoKey& key) |
| 146 : m_key(key) | 147 : m_key(key) |
| 147 { | 148 { |
| 148 } | 149 } |
| 149 | 150 |
| 150 String CryptoKey::type() const | 151 String CryptoKey::type() const |
| 151 { | 152 { |
| 152 return keyTypeToString(m_key.type()); | 153 return keyTypeToString(m_key.type()); |
| 153 } | 154 } |
| 154 | 155 |
| 155 bool CryptoKey::extractable() const | 156 bool CryptoKey::extractable() const |
| 156 { | 157 { |
| 157 return m_key.extractable(); | 158 return m_key.extractable(); |
| 158 } | 159 } |
| 159 | 160 |
| 160 ScriptValue CryptoKey::algorithm(ScriptState* scriptState) | 161 ScriptValue CryptoKey::algorithm(ScriptState* scriptState) |
| 161 { | 162 { |
| 162 DictionaryBuilder builder(scriptState); | 163 DictionaryBuilder builder(scriptState); |
| 163 m_key.algorithm().writeToDictionary(&builder); | 164 m_key.algorithm().writeToDictionary(&builder); |
| 164 return ScriptValue(scriptState, builder.dictionary().v8Value()); | 165 return builder.value(); |
| 165 } | 166 } |
| 166 | 167 |
| 167 // FIXME: This creates a new javascript array each time. What should happen | 168 // FIXME: This creates a new javascript array each time. What should happen |
| 168 // instead is return the same (immutable) array. (Javascript callers can | 169 // instead is return the same (immutable) array. (Javascript callers can |
| 169 // distinguish this by doing an == test on the arrays and seeing they are | 170 // distinguish this by doing an == test on the arrays and seeing they are |
| 170 // different). | 171 // different). |
| 171 Vector<String> CryptoKey::usages() const | 172 Vector<String> CryptoKey::usages() const |
| 172 { | 173 { |
| 173 Vector<String> result; | 174 Vector<String> result; |
| 174 for (size_t i = 0; i < WTF_ARRAY_LENGTH(keyUsageMappings); ++i) { | 175 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) { | 227 if (!usage) { |
| 227 result->completeWithError(WebCryptoErrorTypeType, "Invalid keyUsages
argument"); | 228 result->completeWithError(WebCryptoErrorTypeType, "Invalid keyUsages
argument"); |
| 228 return false; | 229 return false; |
| 229 } | 230 } |
| 230 mask |= usage; | 231 mask |= usage; |
| 231 } | 232 } |
| 232 return true; | 233 return true; |
| 233 } | 234 } |
| 234 | 235 |
| 235 } // namespace blink | 236 } // namespace blink |
| OLD | NEW |