diff options
Diffstat (limited to 'Source/WebCore/page/Crypto.cpp')
-rw-r--r-- | Source/WebCore/page/Crypto.cpp | 56 |
1 files changed, 27 insertions, 29 deletions
diff --git a/Source/WebCore/page/Crypto.cpp b/Source/WebCore/page/Crypto.cpp index 335873051..5bb80925f 100644 --- a/Source/WebCore/page/Crypto.cpp +++ b/Source/WebCore/page/Crypto.cpp @@ -34,22 +34,17 @@ #include "Document.h" #include "ExceptionCode.h" #include "SubtleCrypto.h" +#include "WebKitSubtleCrypto.h" #include <runtime/ArrayBufferView.h> #include <wtf/CryptographicallyRandomNumber.h> namespace WebCore { -namespace { - -bool isIntegerArray(ArrayBufferView* array) -{ - return JSC::isInt(array->getType()); -} - -} - -Crypto::Crypto(Document& document) - : ContextDestructionObserver(&document) +Crypto::Crypto(ScriptExecutionContext& context) + : ContextDestructionObserver(&context) +#if ENABLE(SUBTLE_CRYPTO) + , m_subtle(SubtleCrypto::create(context)) +#endif { } @@ -57,33 +52,36 @@ Crypto::~Crypto() { } -Document* Crypto::document() const +ExceptionOr<void> Crypto::getRandomValues(ArrayBufferView& array) { - return toDocument(scriptExecutionContext()); + if (!isInt(array.getType())) + return Exception { TYPE_MISMATCH_ERR }; + if (array.byteLength() > 65536) + return Exception { QUOTA_EXCEEDED_ERR }; + cryptographicallyRandomValues(array.baseAddress(), array.byteLength()); + return { }; } -void Crypto::getRandomValues(ArrayBufferView* array, ExceptionCode& ec) +#if ENABLE(SUBTLE_CRYPTO) + +SubtleCrypto& Crypto::subtle() { - if (!array || !isIntegerArray(array)) { - ec = TYPE_MISMATCH_ERR; - return; - } - if (array->byteLength() > 65536) { - ec = QUOTA_EXCEEDED_ERR; - return; - } - cryptographicallyRandomValues(array->baseAddress(), array->byteLength()); + return m_subtle; } -#if ENABLE(SUBTLE_CRYPTO) -SubtleCrypto* Crypto::subtle() +ExceptionOr<WebKitSubtleCrypto&> Crypto::webkitSubtle() { - ASSERT(isMainThread()); - if (!m_subtle) - m_subtle = SubtleCrypto::create(*document()); + if (!isMainThread()) + return Exception { NOT_SUPPORTED_ERR }; + + if (!m_webkitSubtle) { + m_webkitSubtle = WebKitSubtleCrypto::create(*downcast<Document>(scriptExecutionContext())); + scriptExecutionContext()->addConsoleMessage(MessageSource::Other, MessageLevel::Warning, ASCIILiteral("WebKitSubtleCrypto is deprecated. Please use SubtleCrypto instead.")); + } - return m_subtle.get(); + return *m_webkitSubtle; } + #endif } |