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

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

Issue 340353006: [webcrypto] Replace KeyAlgorithm interfaces with an Object. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Remove const reference and make v8value a value Created 6 years, 5 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 | « Source/bindings/core/v8/Dictionary.cpp ('k') | Source/bindings/modules/v8/custom/custom.gypi » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
« no previous file with comments | « Source/bindings/core/v8/Dictionary.cpp ('k') | Source/bindings/modules/v8/custom/custom.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698