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

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

Issue 19885002: WebCrypto: Add interfaces for importKey(). (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Add testing interface Created 7 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
Index: Source/modules/crypto/KeyOperation.cpp
diff --git a/Source/bindings/v8/ExceptionState.cpp b/Source/modules/crypto/KeyOperation.cpp
similarity index 50%
copy from Source/bindings/v8/ExceptionState.cpp
copy to Source/modules/crypto/KeyOperation.cpp
index 26ea567f9cab9fc1a6f509cbe621d65e70544171..3c98d881cf78c15c5c8a6efca6967f576afba72b 100644
--- a/Source/bindings/v8/ExceptionState.cpp
+++ b/Source/modules/crypto/KeyOperation.cpp
@@ -29,53 +29,90 @@
*/
#include "config.h"
-#include "bindings/v8/ExceptionState.h"
+#include "modules/crypto/KeyOperation.h"
-#include "bindings/v8/V8ThrowException.h"
+#include "bindings/v8/ExceptionState.h"
+#include "V8Key.h" // NOTE: This must appear before ScriptPromiseResolver to define toV8()
+#include "bindings/v8/ScriptPromiseResolver.h"
#include "core/dom/ExceptionCode.h"
+#include "modules/crypto/Key.h"
+#include "public/platform/WebCrypto.h"
namespace WebCore {
-void ExceptionState::clearException()
+PassRefPtr<KeyOperation> KeyOperation::create()
{
- m_code = 0;
- m_exception.clear();
+ return adoptRef(new KeyOperation);
}
-void ExceptionState::throwDOMException(const ExceptionCode& ec, const String& message)
+KeyOperation::KeyOperation()
+ : m_state(Initializing)
+ , m_impl(0)
+ , m_exceptionCode(0)
{
- ASSERT(ec);
- m_code = ec;
- setException(V8ThrowException::createDOMException(ec, message, m_isolate));
}
-void ExceptionState::setException(v8::Handle<v8::Value> exception)
+KeyOperation::~KeyOperation()
{
- if (exception.IsEmpty()) {
- clearException();
- return;
- }
+ ASSERT(!m_impl);
+}
+
+void KeyOperation::initializationFailed()
+{
+ ASSERT(m_state == Initializing);
+ ASSERT(!m_impl);
- m_exception.set(m_isolate, exception);
+ m_exceptionCode = NotSupportedError;
+ m_state = Done;
}
-void ExceptionState::throwTypeError(const String& message)
+void KeyOperation::initializationSucceeded(WebKit::WebCryptoKeyOperation* operationImpl)
{
- m_code = TypeError;
- setException(V8ThrowException::createTypeError(message, m_isolate));
+ ASSERT(m_state == Initializing);
+ ASSERT(operationImpl);
+ ASSERT(!m_impl);
+
+ m_impl = operationImpl;
+ m_state = InProgress;
}
-NonThrowExceptionState::NonThrowExceptionState()
- : ExceptionState(0) { }
+void KeyOperation::completeWithError()
+{
+ ASSERT(m_state == Initializing || m_state == InProgress);
-void NonThrowExceptionState::throwDOMException(const ExceptionCode& ec, const String&)
+ m_impl = 0;
+ m_state = Done;
+
+ promiseResolver()->reject(ScriptValue::createNull());
+}
+
+void KeyOperation::completeWithKey(const WebKit::WebCryptoKey& key)
{
- m_code = ec;
+ ASSERT(m_state == Initializing || m_state == InProgress);
+
+ m_impl = 0;
+ m_state = Done;
+
+ promiseResolver()->fulfill(Key::create(key));
+}
+
+ScriptObject KeyOperation::returnValue(ExceptionState& es)
+{
+ ASSERT(m_state != Initializing);
+
+ if (m_exceptionCode) {
+ es.throwDOMException(m_exceptionCode);
+ return ScriptObject();
+ }
+
+ return promiseResolver()->promise();
}
-void NonThrowExceptionState::throwTypeError(const String&)
+ScriptPromiseResolver* KeyOperation::promiseResolver()
{
- m_code = TypeError;
+ if (!m_promiseResolver)
+ m_promiseResolver = ScriptPromiseResolver::create();
+ return m_promiseResolver.get();
}
} // namespace WebCore

Powered by Google App Engine
This is Rietveld 408576698