Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(268)

Unified Diff: Source/bindings/v8/custom/V8CryptoKeyCustom.cpp

Issue 340353006: [webcrypto] Replace KeyAlgorithm interfaces with an Object. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: rebase onto master Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | Source/bindings/v8/custom/custom.gypi » ('j') | Source/modules/crypto/CryptoKey.h » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
« no previous file with comments | « no previous file | Source/bindings/v8/custom/custom.gypi » ('j') | Source/modules/crypto/CryptoKey.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698