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

Unified Diff: Source/modules/crypto/CryptoKey.cpp

Issue 984053003: [bindings] Remove custom binding usage from CryptoKey.idl (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Patch for landing! Created 5 years, 9 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/modules/crypto/CryptoKey.h ('k') | Source/modules/crypto/CryptoKey.idl » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/modules/crypto/CryptoKey.cpp
diff --git a/Source/modules/crypto/CryptoKey.cpp b/Source/modules/crypto/CryptoKey.cpp
index 4c2babef72784848851178bb1502133caf4cfe29..01510cc809d667ccbe89817210063771780339a9 100644
--- a/Source/modules/crypto/CryptoKey.cpp
+++ b/Source/modules/crypto/CryptoKey.cpp
@@ -32,6 +32,7 @@
#include "modules/crypto/CryptoKey.h"
#include "bindings/core/v8/ExceptionState.h"
+#include "bindings/core/v8/V8Uint8Array.h"
#include "core/dom/ExceptionCode.h"
#include "platform/CryptoResult.h"
#include "public/platform/WebCryptoAlgorithmParams.h"
@@ -96,6 +97,45 @@ WebCryptoKeyUsageMask keyUsageStringToMask(const String& usageString)
return 0;
}
+class DictionaryBuilder : public blink::WebCryptoKeyAlgorithmDictionary {
+public:
+ explicit DictionaryBuilder(ScriptState* scriptState)
+ : m_scriptState(scriptState)
+ , m_dictionary(Dictionary::createEmpty(scriptState->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 = Dictionary::createEmpty(m_scriptState->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)
+ {
+ m_dictionary.set(propertyName, toV8(DOMUint8Array::create(vector.data(), vector.size()), m_scriptState->context()->Global(), m_scriptState->isolate()));
+ }
+
+ const Dictionary& dictionary() const { return m_dictionary; }
+
+private:
+ RefPtr<ScriptState> m_scriptState;
+ Dictionary m_dictionary;
+};
+
} // namespace
CryptoKey::~CryptoKey()
@@ -117,6 +157,13 @@ bool CryptoKey::extractable() const
return m_key.extractable();
}
+ScriptValue CryptoKey::algorithm(ScriptState* scriptState)
+{
+ DictionaryBuilder builder(scriptState);
+ m_key.algorithm().writeToDictionary(&builder);
+ return ScriptValue(scriptState, builder.dictionary().v8Value());
+}
+
// FIXME: This creates a new javascript array each time. What should happen
// instead is return the same (immutable) array. (Javascript callers can
// distinguish this by doing an == test on the arrays and seeing they are
« no previous file with comments | « Source/modules/crypto/CryptoKey.h ('k') | Source/modules/crypto/CryptoKey.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698