Chromium Code Reviews| Index: public/platform/WebCrypto.h |
| diff --git a/public/platform/WebCrypto.h b/public/platform/WebCrypto.h |
| index 4b091d16929eccbd290a3af61ec04e6ba0eb4b08..b1c88f51cd41ceced16b15a818e0ca40cd667781 100644 |
| --- a/public/platform/WebCrypto.h |
| +++ b/public/platform/WebCrypto.h |
| @@ -32,12 +32,19 @@ |
| #define WebCrypto_h |
| #include "WebCommon.h" |
| +#include "WebCryptoKey.h" |
| +#include "WebPrivatePtr.h" |
| + |
| +namespace WebCore { |
| +class CryptoOperation; |
| +class KeyOperation; |
| +} |
| namespace WebKit { |
| class WebArrayBuffer; |
| -class WebCryptoAlgorithm; |
| -class WebCryptoKey; |
| +class WebCryptoKeyOperation; |
| +class WebCryptoKeyOperationResult; |
| class WebCryptoOperation; |
| class WebCryptoOperationResult; |
| @@ -49,17 +56,17 @@ public: |
| // The following methods begin an asynchronous multi-part cryptographic |
| // operation. |
| // |
| - // Let the WebCryptoOperationResult* be called "result". |
| + // Let the WebCryptoOperationResult& be called "result". |
| // |
| - // Implementations can either: |
| + // Before returning, implementations can either: |
| // |
| // * Synchronously fail initialization by calling: |
| - // result->initializationFailed(errorDetails) |
| + // result.initializationFailed(errorDetails) |
| // |
| // OR |
| // |
| // * Create a new WebCryptoOperation* and return it by calling: |
| - // result->initializationSucceeded(cryptoOperation) |
| + // result.initializationSucceeded(cryptoOperation) |
| // |
| // If initialization succeeds, then Blink will subsequently call |
| // methods on cryptoOperation: |
| @@ -68,10 +75,11 @@ public: |
| // - cryptoOperation->finish() to indicate there is no more data |
| // - cryptoOperation->abort() to cancel. |
| // |
| - // The embedder may call result->completeWithXXX() at any time while the |
| - // cryptoOperation is "in progress". Typically completion is set once |
| - // cryptoOperation->finish() is called, however it can also be called |
| - // during cryptoOperation->process() (for instance to set an error). |
| + // The embedder may call result.completeWithXXX() at any time while the |
| + // cryptoOperation is "in progress" (can copy the initial "result" object). |
| + // Typically completion is set once cryptoOperation->finish() is called, |
| + // however it can also be called during cryptoOperation->process() (for |
| + // instance to set an error). |
| // |
| // The cryptoOperation pointer MUST remain valid while it is "in progress". |
| // The cryptoOperation is said to be "in progress" from the time after |
| @@ -79,12 +87,43 @@ public: |
| // |
| // - Blink calls cryptoOperation->abort() |
| // OR |
| - // - Embedder calls result->completeWithXXX() |
| + // - Embedder calls result.completeWithXXX() |
| + // |
| + // Once the cryptoOperation is no longer "in progress" the embedder is |
| + // responsible for freeing the cryptoOperation. |
| + virtual void digest(const WebCryptoAlgorithm&, WebCryptoOperationResult&) { } |
| + |
| + // The following methods begin an asynchronous single-part key operation. |
| + // |
| + // Let the WebCryptoKeyOperationResult& be called "result". |
| + // |
| + // Before returning, implementations can either: |
| + // |
| + // (a) Synchronously fail initialization by calling: |
| + // result.initializationFailed(errorDetails) |
| + // (this results in throwing a Javascript exception) |
| + // |
| + // (b) Synchronously complete the request (success or error) by calling: |
| + // result.completeWithXXX() |
| + // |
| + // (c) Defer completion by calling |
| + // result.initializationSucceeded(keyOperation) |
| + // |
| + // If asynchronous completion (c) was chosen, then the embedder can notify |
| + // completion after returning by calling result.completeWithXXX() (can make |
| + // a copy of "result"). |
| + // |
| + // The keyOperation pointer MUST remain valid while it is "in progress". |
| + // The keyOperation is said to be "in progress" from the time after |
| + // result->initializationSucceded() has been called, up until either: |
| + // |
| + // - Blink calls keyOperation->abort() |
| + // OR |
| + // - Embedder calls result.completeWithXXX() |
| // |
| - // Once the cryptoOperation is no longer "in progress" the "result" pointer |
| - // is no longer valid. At this time the embedder is responsible for freeing |
| - // the cryptoOperation. |
| - virtual void digest(const WebCryptoAlgorithm&, WebCryptoOperationResult*) { } |
| + // Once the keyOperation is no longer "in progress" the embedder is |
| + // responsible for freeing the cryptoOperation. |
| + virtual void importKey(WebCryptoKeyFormat, const unsigned char* keyData, size_t keyDataSize, const WebCryptoAlgorithm&, bool extractable, WebCryptoKeyUsageMask, WebCryptoKeyOperationResult&) { } |
| protected: |
| virtual ~WebCrypto() { } |
| @@ -112,16 +151,73 @@ protected: |
| // FIXME: Add error types. |
| class WebCryptoOperationResult { |
| public: |
| +#if WEBKIT_IMPLEMENTATION |
| + WebCryptoOperationResult(WebCore::CryptoOperation*); |
| +#endif |
| + |
| + WebCryptoOperationResult(const WebCryptoOperationResult& o) |
| + { |
| + m_impl = o.m_impl; |
| + } |
| + |
| + WebCryptoOperationResult& operator=(const WebCryptoOperationResult& o) |
| + { |
| + m_impl = o.m_impl; |
| + return *this; |
| + } |
| + |
| // Only one of these should be called. |
| - virtual void initializationFailed() = 0; |
| - virtual void initializationSucceded(WebCryptoOperation*) = 0; |
| + WEBKIT_EXPORT void initializationFailed(); |
| + WEBKIT_EXPORT void initializationSucceeded(WebCryptoOperation*); |
| // Only one of these should be called to set the result. |
| - virtual void completeWithError() = 0; |
| - virtual void completeWithArrayBuffer(const WebArrayBuffer&) = 0; |
| + WEBKIT_EXPORT void completeWithError(); |
| + WEBKIT_EXPORT void completeWithArrayBuffer(const WebArrayBuffer&); |
| + |
| +private: |
| + WebCore::CryptoOperation* m_impl; |
|
abarth-chromium
2013/07/23 21:45:49
Should this be a WebPrivatePtr<WebCore::CryptoOper
eroman
2013/07/23 23:29:02
Done.
(I was initially concerned about refcountin
|
| +}; |
| + |
| +class WebCryptoKeyOperation { |
| +public: |
| + // Cancels the in-progress operation. |
| + // * Implementations should delete |this| after aborting. |
| + virtual void abort() = 0; |
| protected: |
| - virtual ~WebCryptoOperationResult() { } |
| + virtual ~WebCryptoKeyOperation() { } |
| +}; |
| + |
| +class WebCryptoKeyOperationResult { |
| +public: |
| +#if WEBKIT_IMPLEMENTATION |
| + WebCryptoKeyOperationResult(WebCore::KeyOperation*); |
| +#endif |
| + |
| + ~WebCryptoKeyOperationResult() { reset(); } |
| + |
| + WebCryptoKeyOperationResult(const WebCryptoKeyOperationResult& o) |
| + { |
| + assign(o); |
| + } |
| + |
| + WebCryptoKeyOperationResult& operator=(const WebCryptoKeyOperationResult& o) |
| + { |
| + assign(o); |
| + return *this; |
| + } |
| + |
| + WEBKIT_EXPORT void initializationFailed(); |
| + WEBKIT_EXPORT void initializationSucceeded(WebCryptoKeyOperation*); |
| + |
| + WEBKIT_EXPORT void completeWithError(); |
| + WEBKIT_EXPORT void completeWithKey(const WebCryptoKey&); |
| + |
| +private: |
| + WEBKIT_EXPORT void reset(); |
| + WEBKIT_EXPORT void assign(const WebCryptoKeyOperationResult&); |
| + |
| + WebPrivatePtr<WebCore::KeyOperation> m_impl; |
| }; |
| } // namespace WebKit |