This source file includes following definitions.
- create
- completeWithError
- completeWithError
- completeWithBuffer
- completeWithBoolean
- completeWithKey
- completeWithKeyPair
- m_finished
- finish
- clearPromiseResolver
- CheckValidThread
- contextDestroyed
- canCompletePromise
#include "config.h"
#include "modules/crypto/CryptoResultImpl.h"
#include "bindings/v8/ScriptPromiseResolver.h"
#include "core/dom/ExecutionContext.h"
#include "modules/crypto/Key.h"
#include "modules/crypto/KeyPair.h"
#include "modules/crypto/NormalizeAlgorithm.h"
#include "public/platform/Platform.h"
#include "public/platform/WebArrayBuffer.h"
#include "public/platform/WebCryptoAlgorithm.h"
#include "wtf/ArrayBufferView.h"
namespace WebCore {
CryptoResultImpl::~CryptoResultImpl()
{
}
PassRefPtr<CryptoResultImpl> CryptoResultImpl::create()
{
return adoptRef(new CryptoResultImpl(callingExecutionContext(v8::Isolate::GetCurrent())));
}
void CryptoResultImpl::completeWithError(const blink::WebString& errorDetails)
{
ASSERT(!m_finished);
if (canCompletePromise()) {
DOMRequestState::Scope scope(m_requestState);
if (!errorDetails.isEmpty()) {
executionContext()->addConsoleMessage(JSMessageSource, ErrorMessageLevel, errorDetails);
}
m_promiseResolver->reject(ScriptValue::createNull());
}
}
void CryptoResultImpl::completeWithError()
{
completeWithError(blink::WebString());
}
void CryptoResultImpl::completeWithBuffer(const blink::WebArrayBuffer& buffer)
{
ASSERT(!m_finished);
if (canCompletePromise()) {
DOMRequestState::Scope scope(m_requestState);
m_promiseResolver->resolve(PassRefPtr<ArrayBuffer>(buffer));
}
finish();
}
void CryptoResultImpl::completeWithBoolean(bool b)
{
ASSERT(!m_finished);
if (canCompletePromise()) {
DOMRequestState::Scope scope(m_requestState);
m_promiseResolver->resolve(ScriptValue::createBoolean(b));
}
finish();
}
void CryptoResultImpl::completeWithKey(const blink::WebCryptoKey& key)
{
ASSERT(!m_finished);
if (canCompletePromise()) {
DOMRequestState::Scope scope(m_requestState);
m_promiseResolver->resolve(Key::create(key));
}
finish();
}
void CryptoResultImpl::completeWithKeyPair(const blink::WebCryptoKey& publicKey, const blink::WebCryptoKey& privateKey)
{
ASSERT(!m_finished);
if (canCompletePromise()) {
DOMRequestState::Scope scope(m_requestState);
m_promiseResolver->resolve(KeyPair::create(publicKey, privateKey));
}
finish();
}
CryptoResultImpl::CryptoResultImpl(ExecutionContext* context)
: ContextLifecycleObserver(context)
, m_promiseResolver(ScriptPromiseResolver::create(context))
, m_requestState(context)
#if !ASSERT_DISABLED
, m_owningThread(currentThread())
, m_finished(false)
#endif
{
}
void CryptoResultImpl::finish()
{
#if !ASSERT_DISABLED
m_finished = true;
#endif
clearPromiseResolver();
}
void CryptoResultImpl::clearPromiseResolver()
{
m_promiseResolver.clear();
m_requestState.clear();
}
void CryptoResultImpl::CheckValidThread() const
{
ASSERT(m_owningThread == currentThread());
}
void CryptoResultImpl::contextDestroyed()
{
ContextLifecycleObserver::contextDestroyed();
clearPromiseResolver();
ASSERT(!canCompletePromise());
}
bool CryptoResultImpl::canCompletePromise() const
{
CheckValidThread();
ExecutionContext* context = executionContext();
return context && !context->activeDOMObjectsAreSuspended() && !context->activeDOMObjectsAreStopped();
}
}