Chromium Code Reviews| Index: Source/bindings/v8/custom/V8CryptoKeyCustom.cpp |
| diff --git a/Source/bindings/v8/custom/V8CryptoKeyCustom.cpp b/Source/bindings/v8/custom/V8CryptoKeyCustom.cpp |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..c273124230210f57f5b0fd378fd71e45b1383bc9 |
| --- /dev/null |
| +++ b/Source/bindings/v8/custom/V8CryptoKeyCustom.cpp |
| @@ -0,0 +1,75 @@ |
| +// Copyright 2014 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "config.h" |
| +#include "bindings/modules/v8/V8CryptoKey.h" |
| + |
| +#include "bindings/v8/V8Binding.h" |
| +#include "bindings/v8/custom/V8Uint8ArrayCustom.h" |
| +#include "public/platform/WebCryptoKeyAlgorithm.h" |
| +#include "wtf/Uint8Array.h" |
| + |
| +namespace WebCore { |
| + |
| +class DictionaryBuilder : public blink::WebCryptoKeyAlgorithmDictionary { |
|
abarth-chromium
2014/06/26 19:56:17
Can we move this class into the bindings directory
|
| +public: |
| + DictionaryBuilder(v8::Handle<v8::Object> holder, v8::Isolate* isolate) |
| + : m_holder(holder) |
| + , m_isolate(isolate) |
| + , m_object(v8::Object::New(isolate)) |
| + { |
| + } |
| + |
| + virtual void setString(const char* propertyName, const char* value) |
| + { |
| + m_object->Set(createString(propertyName), createString(value)); |
| + } |
| + |
| + virtual void setUint(const char* propertyName, unsigned value) |
| + { |
| + m_object->Set(createString(propertyName), v8::Integer::NewFromUnsigned(m_isolate, value)); |
| + } |
| + |
| + virtual void setAlgorithm(const char* propertyName, const blink::WebCryptoAlgorithm& algorithm) |
| + { |
| + ASSERT(algorithm.paramsType() == blink::WebCryptoAlgorithmParamsTypeNone); |
| + |
| + DictionaryBuilder builder(m_holder, m_isolate); |
| + builder.setString("name", blink::WebCryptoAlgorithm::lookupAlgorithmInfo(algorithm.id())->name); |
| + m_object->Set(createString(propertyName), builder.v8Object()); |
| + } |
| + |
| + virtual void setUint8Array(const char* propertyName, const blink::WebVector<unsigned char>& vector) |
| + { |
| + RefPtr<Uint8Array> uint8Array = Uint8Array::create(vector.data(), vector.size()); |
| + m_object->Set(createString(propertyName), toV8(uint8Array.get(), m_holder, m_isolate)); |
| + } |
| + |
| + v8::Handle<v8::Object> v8Object() const |
| + { |
| + return m_object; |
| + } |
| + |
| +private: |
| + v8::Local<v8::String> createString(const char* utf8CString) |
| + { |
| + return v8::String::NewFromUtf8(m_isolate, utf8CString); |
| + } |
| + |
| + v8::Handle<v8::Object> m_holder; |
| + v8::Isolate* m_isolate; |
| + v8::Handle<v8::Object> m_object; |
| +}; |
| + |
| +void V8CryptoKey::algorithmAttributeGetterCustom(const v8::PropertyCallbackInfo<v8::Value>& info) |
| +{ |
| + CryptoKey* impl = V8CryptoKey::toNative(info.Holder()); |
| + |
| + DictionaryBuilder builder(info.Holder(), info.GetIsolate()); |
| + impl->key().algorithm().writeToDictionary(&builder); |
| + |
| + v8SetReturnValue(info, builder.v8Object()); |
| +} |
| + |
| +} // namespace WebCore |