summaryrefslogtreecommitdiff
path: root/Source/WebCore/page/Crypto.cpp
diff options
context:
space:
mode:
authorLorry Tar Creator <lorry-tar-importer@lorry>2017-06-27 06:07:23 +0000
committerLorry Tar Creator <lorry-tar-importer@lorry>2017-06-27 06:07:23 +0000
commit1bf1084f2b10c3b47fd1a588d85d21ed0eb41d0c (patch)
tree46dcd36c86e7fbc6e5df36deb463b33e9967a6f7 /Source/WebCore/page/Crypto.cpp
parent32761a6cee1d0dee366b885b7b9c777e67885688 (diff)
downloadWebKitGtk-tarball-master.tar.gz
Diffstat (limited to 'Source/WebCore/page/Crypto.cpp')
-rw-r--r--Source/WebCore/page/Crypto.cpp56
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
}