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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | Source/bindings/v8/custom/custom.gypi » ('j') | Source/modules/crypto/CryptoKey.h » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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/v8/V8Binding.h"
9 #include "bindings/v8/custom/V8Uint8ArrayCustom.h"
10 #include "public/platform/WebCryptoKeyAlgorithm.h"
11 #include "wtf/Uint8Array.h"
12
13 namespace WebCore {
14
15 class DictionaryBuilder : public blink::WebCryptoKeyAlgorithmDictionary {
abarth-chromium 2014/06/26 19:56:17 Can we move this class into the bindings directory
16 public:
17 DictionaryBuilder(v8::Handle<v8::Object> holder, v8::Isolate* isolate)
18 : m_holder(holder)
19 , m_isolate(isolate)
20 , m_object(v8::Object::New(isolate))
21 {
22 }
23
24 virtual void setString(const char* propertyName, const char* value)
25 {
26 m_object->Set(createString(propertyName), createString(value));
27 }
28
29 virtual void setUint(const char* propertyName, unsigned value)
30 {
31 m_object->Set(createString(propertyName), v8::Integer::NewFromUnsigned(m _isolate, value));
32 }
33
34 virtual void setAlgorithm(const char* propertyName, const blink::WebCryptoAl gorithm& algorithm)
35 {
36 ASSERT(algorithm.paramsType() == blink::WebCryptoAlgorithmParamsTypeNone );
37
38 DictionaryBuilder builder(m_holder, m_isolate);
39 builder.setString("name", blink::WebCryptoAlgorithm::lookupAlgorithmInfo (algorithm.id())->name);
40 m_object->Set(createString(propertyName), builder.v8Object());
41 }
42
43 virtual void setUint8Array(const char* propertyName, const blink::WebVector< unsigned char>& vector)
44 {
45 RefPtr<Uint8Array> uint8Array = Uint8Array::create(vector.data(), vector .size());
46 m_object->Set(createString(propertyName), toV8(uint8Array.get(), m_holde r, m_isolate));
47 }
48
49 v8::Handle<v8::Object> v8Object() const
50 {
51 return m_object;
52 }
53
54 private:
55 v8::Local<v8::String> createString(const char* utf8CString)
56 {
57 return v8::String::NewFromUtf8(m_isolate, utf8CString);
58 }
59
60 v8::Handle<v8::Object> m_holder;
61 v8::Isolate* m_isolate;
62 v8::Handle<v8::Object> m_object;
63 };
64
65 void V8CryptoKey::algorithmAttributeGetterCustom(const v8::PropertyCallbackInfo< v8::Value>& info)
66 {
67 CryptoKey* impl = V8CryptoKey::toNative(info.Holder());
68
69 DictionaryBuilder builder(info.Holder(), info.GetIsolate());
70 impl->key().algorithm().writeToDictionary(&builder);
71
72 v8SetReturnValue(info, builder.v8Object());
73 }
74
75 } // namespace WebCore
OLDNEW
« 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