Index: Source/bindings/modules/v8/custom/V8CryptoKeyCustom.cpp |
diff --git a/Source/bindings/modules/v8/custom/V8CryptoKeyCustom.cpp b/Source/bindings/modules/v8/custom/V8CryptoKeyCustom.cpp |
new file mode 100644 |
index 0000000000000000000000000000000000000000..d479e5d4545da310ff1bc396edfd05d1948a9721 |
--- /dev/null |
+++ b/Source/bindings/modules/v8/custom/V8CryptoKeyCustom.cpp |
@@ -0,0 +1,73 @@ |
+// 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/core/v8/Dictionary.h" |
+#include "bindings/core/v8/V8Binding.h" |
+#include "bindings/core/v8/custom/V8Uint8ArrayCustom.h" |
+#include "public/platform/WebCryptoKeyAlgorithm.h" |
+#include "wtf/Uint8Array.h" |
+ |
+namespace WebCore { |
+ |
+class DictionaryBuilder : public blink::WebCryptoKeyAlgorithmDictionary { |
+public: |
+ DictionaryBuilder(v8::Handle<v8::Object> holder, v8::Isolate* isolate) |
+ : m_holder(holder) |
+ , m_isolate(isolate) |
+ , m_dictionary(isolate) |
+ { |
+ } |
+ |
+ virtual void setString(const char* propertyName, const char* value) |
+ { |
+ m_dictionary.set(propertyName, value); |
+ } |
+ |
+ virtual void setUint(const char* propertyName, unsigned value) |
+ { |
+ m_dictionary.set(propertyName, value); |
+ } |
+ |
+ virtual void setAlgorithm(const char* propertyName, const blink::WebCryptoAlgorithm& algorithm) |
+ { |
+ ASSERT(algorithm.paramsType() == blink::WebCryptoAlgorithmParamsTypeNone); |
+ |
+ Dictionary algorithmValue(m_isolate); |
+ algorithmValue.set("name", blink::WebCryptoAlgorithm::lookupAlgorithmInfo(algorithm.id())->name); |
+ m_dictionary.set(propertyName, algorithmValue); |
+ } |
+ |
+ virtual void setUint8Array(const char* propertyName, const blink::WebVector<unsigned char>& vector) |
+ { |
+ RefPtr<Uint8Array> uint8Array = Uint8Array::create(vector.data(), vector.size()); |
+ m_dictionary.set(propertyName, toV8(uint8Array.get(), m_holder, m_isolate)); |
+ } |
+ |
+ const Dictionary& dictionary() const { return m_dictionary; } |
+ |
+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; |
+ Dictionary m_dictionary; |
+}; |
+ |
+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.dictionary().v8Value()); |
+} |
+ |
+} // namespace WebCore |