| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 29 matching lines...) Expand all Loading... |
| 40 #include "modules/crypto/Key.h" | 40 #include "modules/crypto/Key.h" |
| 41 #include "modules/crypto/KeyPair.h" | 41 #include "modules/crypto/KeyPair.h" |
| 42 #include "modules/crypto/NormalizeAlgorithm.h" | 42 #include "modules/crypto/NormalizeAlgorithm.h" |
| 43 #include "public/platform/Platform.h" | 43 #include "public/platform/Platform.h" |
| 44 #include "public/platform/WebArrayBuffer.h" | 44 #include "public/platform/WebArrayBuffer.h" |
| 45 #include "public/platform/WebCryptoAlgorithm.h" | 45 #include "public/platform/WebCryptoAlgorithm.h" |
| 46 #include "wtf/ArrayBufferView.h" | 46 #include "wtf/ArrayBufferView.h" |
| 47 | 47 |
| 48 namespace WebCore { | 48 namespace WebCore { |
| 49 | 49 |
| 50 namespace { | 50 ExceptionCode webCryptoErrorToExceptionCode(blink::WebCryptoErrorType errorType) |
| 51 | |
| 52 ExceptionCode toExceptionCode(blink::WebCryptoErrorType errorType) | |
| 53 { | 51 { |
| 54 switch (errorType) { | 52 switch (errorType) { |
| 55 case blink::WebCryptoErrorTypeNotSupported: | 53 case blink::WebCryptoErrorTypeNotSupported: |
| 56 return NotSupportedError; | 54 return NotSupportedError; |
| 57 case blink::WebCryptoErrorTypeSyntax: | 55 case blink::WebCryptoErrorTypeSyntax: |
| 58 return SyntaxError; | 56 return SyntaxError; |
| 59 case blink::WebCryptoErrorTypeInvalidState: | 57 case blink::WebCryptoErrorTypeInvalidState: |
| 60 return InvalidStateError; | 58 return InvalidStateError; |
| 61 case blink::WebCryptoErrorTypeInvalidAccess: | 59 case blink::WebCryptoErrorTypeInvalidAccess: |
| 62 return InvalidAccessError; | 60 return InvalidAccessError; |
| 63 case blink::WebCryptoErrorTypeUnknown: | 61 case blink::WebCryptoErrorTypeUnknown: |
| 64 return UnknownError; | 62 return UnknownError; |
| 65 case blink::WebCryptoErrorTypeData: | 63 case blink::WebCryptoErrorTypeData: |
| 66 return DataError; | 64 return DataError; |
| 67 case blink::WebCryptoErrorTypeOperation: | 65 case blink::WebCryptoErrorTypeOperation: |
| 68 return OperationError; | 66 return OperationError; |
| 69 case blink::WebCryptoErrorTypeType: | 67 case blink::WebCryptoErrorTypeType: |
| 70 // FIXME: This should construct a TypeError instead. For now do | 68 // FIXME: This should construct a TypeError instead. For now do |
| 71 // something to facilitate refactor, but this will need to be | 69 // something to facilitate refactor, but this will need to be |
| 72 // revisited. | 70 // revisited. |
| 73 return DataError; | 71 return DataError; |
| 74 } | 72 } |
| 75 | 73 |
| 76 ASSERT_NOT_REACHED(); | 74 ASSERT_NOT_REACHED(); |
| 77 return 0; | 75 return 0; |
| 78 } | 76 } |
| 79 | 77 |
| 80 } // namespace | |
| 81 | |
| 82 // The PromiseState class contains all the state which is tied to an | 78 // The PromiseState class contains all the state which is tied to an |
| 83 // ExecutionContext. Whereas CryptoResultImpl can be deleted from any thread, | 79 // ExecutionContext. Whereas CryptoResultImpl can be deleted from any thread, |
| 84 // PromiseState is not thread safe and must only be accessed and deleted from | 80 // PromiseState is not thread safe and must only be accessed and deleted from |
| 85 // the blink thread. | 81 // the blink thread. |
| 86 // | 82 // |
| 87 // This is achieved by making CryptoResultImpl hold a WeakPtr to the PromiseStat
e. | 83 // This is achieved by making CryptoResultImpl hold a WeakPtr to the PromiseStat
e. |
| 88 // The PromiseState deletes itself after being notified of completion. | 84 // The PromiseState deletes itself after being notified of completion. |
| 89 // Additionally the PromiseState is deleted when the ExecutionContext is | 85 // Additionally the PromiseState is deleted when the ExecutionContext is |
| 90 // destroyed (necessary to avoid leaks when dealing with WebWorker threads, | 86 // destroyed (necessary to avoid leaks when dealing with WebWorker threads, |
| 91 // which may die before the operation is completed). | 87 // which may die before the operation is completed). |
| (...skipping 10 matching lines...) Expand all Loading... |
| 102 delete this; | 98 delete this; |
| 103 } | 99 } |
| 104 | 100 |
| 105 ScriptPromise promise() | 101 ScriptPromise promise() |
| 106 { | 102 { |
| 107 return m_promiseResolver->promise(); | 103 return m_promiseResolver->promise(); |
| 108 } | 104 } |
| 109 | 105 |
| 110 void completeWithError(blink::WebCryptoErrorType errorType, const blink::Web
String& errorDetails) | 106 void completeWithError(blink::WebCryptoErrorType errorType, const blink::Web
String& errorDetails) |
| 111 { | 107 { |
| 112 m_promiseResolver->reject(DOMException::create(toExceptionCode(errorType
), errorDetails)); | 108 m_promiseResolver->reject(DOMException::create(webCryptoErrorToException
Code(errorType), errorDetails)); |
| 113 delete this; | 109 delete this; |
| 114 } | 110 } |
| 115 | 111 |
| 116 void completeWithBuffer(const blink::WebArrayBuffer& buffer) | 112 void completeWithBuffer(const blink::WebArrayBuffer& buffer) |
| 117 { | 113 { |
| 118 m_promiseResolver->resolve(PassRefPtr<ArrayBuffer>(buffer)); | 114 m_promiseResolver->resolve(PassRefPtr<ArrayBuffer>(buffer)); |
| 119 delete this; | 115 delete this; |
| 120 } | 116 } |
| 121 | 117 |
| 122 void completeWithBoolean(bool b) | 118 void completeWithBoolean(bool b) |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 218 : m_promiseState(PromiseState::create(scriptState)) | 214 : m_promiseState(PromiseState::create(scriptState)) |
| 219 { | 215 { |
| 220 } | 216 } |
| 221 | 217 |
| 222 ScriptPromise CryptoResultImpl::promise() | 218 ScriptPromise CryptoResultImpl::promise() |
| 223 { | 219 { |
| 224 return m_promiseState->promise(); | 220 return m_promiseState->promise(); |
| 225 } | 221 } |
| 226 | 222 |
| 227 } // namespace WebCore | 223 } // namespace WebCore |
| OLD | NEW |