OLD | NEW |
| (Empty) |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "config.h" | |
6 #include "bindings/modules/v8/V8CryptoKey.h" | |
7 | |
8 #include "bindings/core/v8/Dictionary.h" | |
9 #include "bindings/core/v8/V8Binding.h" | |
10 #include "bindings/core/v8/V8Uint8Array.h" | |
11 #include "public/platform/WebCryptoKeyAlgorithm.h" | |
12 | |
13 namespace blink { | |
14 | |
15 class DictionaryBuilder : public blink::WebCryptoKeyAlgorithmDictionary { | |
16 public: | |
17 DictionaryBuilder(v8::Local<v8::Object> holder, v8::Isolate* isolate) | |
18 : m_holder(holder) | |
19 , m_isolate(isolate) | |
20 , m_dictionary(Dictionary::createEmpty(isolate)) | |
21 { | |
22 } | |
23 | |
24 virtual void setString(const char* propertyName, const char* value) | |
25 { | |
26 m_dictionary.set(propertyName, value); | |
27 } | |
28 | |
29 virtual void setUint(const char* propertyName, unsigned value) | |
30 { | |
31 m_dictionary.set(propertyName, value); | |
32 } | |
33 | |
34 virtual void setAlgorithm(const char* propertyName, const blink::WebCryptoAl
gorithm& algorithm) | |
35 { | |
36 ASSERT(algorithm.paramsType() == blink::WebCryptoAlgorithmParamsTypeNone
); | |
37 | |
38 Dictionary algorithmValue = Dictionary::createEmpty(m_isolate); | |
39 algorithmValue.set("name", blink::WebCryptoAlgorithm::lookupAlgorithmInf
o(algorithm.id())->name); | |
40 m_dictionary.set(propertyName, algorithmValue); | |
41 } | |
42 | |
43 virtual void setUint8Array(const char* propertyName, const blink::WebVector<
unsigned char>& vector) | |
44 { | |
45 m_dictionary.set(propertyName, toV8(DOMUint8Array::create(vector.data(),
vector.size()), m_holder, m_isolate)); | |
46 } | |
47 | |
48 const Dictionary& dictionary() const { return m_dictionary; } | |
49 | |
50 private: | |
51 v8::Local<v8::Object> m_holder; | |
52 v8::Isolate* m_isolate; | |
53 Dictionary m_dictionary; | |
54 }; | |
55 | |
56 void V8CryptoKey::algorithmAttributeGetterCustom(const v8::PropertyCallbackInfo<
v8::Value>& info) | |
57 { | |
58 CryptoKey* impl = V8CryptoKey::toImpl(info.Holder()); | |
59 | |
60 DictionaryBuilder builder(info.Holder(), info.GetIsolate()); | |
61 impl->key().algorithm().writeToDictionary(&builder); | |
62 | |
63 v8SetReturnValue(info, builder.dictionary().v8Value()); | |
64 } | |
65 | |
66 } // namespace blink | |
OLD | NEW |