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

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

Issue 19776013: WebCrypto: Refactor the WebCryptoOperation interface to support errors. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Rebase onto master 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
« no previous file with comments | « Source/modules/crypto/CryptoOperation.h ('k') | Source/modules/crypto/SubtleCrypto.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/modules/crypto/CryptoOperation.cpp
diff --git a/Source/modules/crypto/CryptoOperation.cpp b/Source/modules/crypto/CryptoOperation.cpp
index fd2c1d18ef8bbf1e53eece95249a4e263eb56226..a6c974887d19090f1e2790a4be83139fa2ff5528 100644
--- a/Source/modules/crypto/CryptoOperation.cpp
+++ b/Source/modules/crypto/CryptoOperation.cpp
@@ -33,6 +33,7 @@
#include "bindings/v8/custom/V8ArrayBufferCustom.h" // MUST precede ScriptPromiseResolver for compilation to work.
#include "bindings/v8/ScriptPromiseResolver.h"
+#include "core/dom/ExceptionCode.h"
#include "modules/crypto/Algorithm.h"
#include "public/platform/WebArrayBuffer.h"
#include "public/platform/WebCrypto.h"
@@ -41,41 +42,24 @@
namespace WebCore {
-class CryptoOperation::Result : public WebKit::WebCryptoOperationResult {
-public:
- explicit Result(CryptoOperation* parent) : m_parent(parent) { }
-
- virtual void setArrayBuffer(const WebKit::WebArrayBuffer& buffer) OVERRIDE
- {
- ASSERT(m_parent->m_state == Finishing);
- m_parent->m_state = Done;
- m_parent->m_impl = 0;
-
- m_parent->promiseResolver()->fulfill(PassRefPtr<ArrayBuffer>(buffer));
- }
-
-private:
- CryptoOperation* m_parent;
-};
-
CryptoOperation::~CryptoOperation()
{
abortImpl();
ASSERT(!m_impl);
}
-PassRefPtr<CryptoOperation> CryptoOperation::create(const WebKit::WebCryptoAlgorithm& algorithm, WebKit::WebCryptoOperation* impl)
+PassRefPtr<CryptoOperation> CryptoOperation::create(const WebKit::WebCryptoAlgorithm& algorithm, ExceptionCode* ec)
{
- return adoptRef(new CryptoOperation(algorithm, impl));
+ return adoptRef(new CryptoOperation(algorithm, ec));
}
-CryptoOperation::CryptoOperation(const WebKit::WebCryptoAlgorithm& algorithm, WebKit::WebCryptoOperation* impl)
+CryptoOperation::CryptoOperation(const WebKit::WebCryptoAlgorithm& algorithm, ExceptionCode* ec)
: m_algorithm(algorithm)
- , m_impl(impl)
- , m_state(Processing)
- , m_result(adoptPtr(new Result(this)))
+ , m_impl(0)
+ , m_exceptionCode(ec)
+ , m_state(Initializing)
{
- ASSERT(impl);
+ ASSERT(ec);
ScriptWrappable::init(this);
}
@@ -94,10 +78,13 @@ CryptoOperation* CryptoOperation::process(ArrayBufferView* data)
ScriptObject CryptoOperation::finish()
{
switch (m_state) {
+ case Initializing:
+ ASSERT_NOT_REACHED();
+ return ScriptObject();
case Processing:
m_state = Finishing;
// NOTE: The following line can result in re-entrancy to |this|
- m_impl->finish(m_result.get());
+ m_impl->finish();
break;
case Finishing:
// Calling finish() twice is a no-op.
@@ -125,9 +112,52 @@ Algorithm* CryptoOperation::algorithm()
return m_algorithmNode.get();
}
+void CryptoOperation::initializationFailed()
+{
+ ASSERT(m_state == Initializing);
+
+ *m_exceptionCode = NotSupportedError;
+
+ m_exceptionCode = 0;
+ m_state = Done;
+}
+
+void CryptoOperation::initializationSucceded(WebKit::WebCryptoOperation* operationImpl)
+{
+ ASSERT(m_state == Initializing);
+ ASSERT(operationImpl);
+ ASSERT(!m_impl);
+
+ m_exceptionCode = 0;
+ m_impl = operationImpl;
+ m_state = Processing;
+}
+
+void CryptoOperation::completeWithError()
+{
+ ASSERT(m_state == Processing || m_state == Finishing);
+
+ m_impl = 0;
+ m_state = Done;
+
+ promiseResolver()->reject(ScriptValue::createNull());
+}
+
+void CryptoOperation::completeWithArrayBuffer(const WebKit::WebArrayBuffer& buffer)
+{
+ ASSERT(m_state == Processing || m_state == Finishing);
+
+ m_impl = 0;
+ m_state = Done;
+
+ promiseResolver()->fulfill(PassRefPtr<ArrayBuffer>(buffer));
+}
+
void CryptoOperation::process(const unsigned char* bytes, size_t size)
{
switch (m_state) {
+ case Initializing:
+ ASSERT_NOT_REACHED();
case Processing:
m_impl->process(bytes, size);
break;
@@ -140,11 +170,14 @@ void CryptoOperation::process(const unsigned char* bytes, size_t size)
bool CryptoOperation::abortImpl()
{
switch (m_state) {
+ case Initializing:
+ ASSERT_NOT_REACHED();
+ break;
case Processing:
case Finishing:
// This will cause m_impl to be deleted.
- m_impl->abort();
m_state = Done;
+ m_impl->abort();
m_impl = 0;
return true;
case Done:
« no previous file with comments | « Source/modules/crypto/CryptoOperation.h ('k') | Source/modules/crypto/SubtleCrypto.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698