| 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 27 matching lines...) Expand all Loading... |
| 38 #include "modules/crypto/NormalizeAlgorithm.h" | 38 #include "modules/crypto/NormalizeAlgorithm.h" |
| 39 #include "public/platform/Platform.h" | 39 #include "public/platform/Platform.h" |
| 40 #include "public/platform/WebArrayBuffer.h" | 40 #include "public/platform/WebArrayBuffer.h" |
| 41 #include "public/platform/WebCryptoAlgorithm.h" | 41 #include "public/platform/WebCryptoAlgorithm.h" |
| 42 #include "wtf/ArrayBufferView.h" | 42 #include "wtf/ArrayBufferView.h" |
| 43 | 43 |
| 44 namespace WebCore { | 44 namespace WebCore { |
| 45 | 45 |
| 46 CryptoResultImpl::~CryptoResultImpl() | 46 CryptoResultImpl::~CryptoResultImpl() |
| 47 { | 47 { |
| 48 ASSERT(m_finished); | |
| 49 ASSERT(!m_promiseResolver.get()); | |
| 50 ASSERT(!m_requestState.isValid()); | |
| 51 } | 48 } |
| 52 | 49 |
| 53 PassRefPtr<CryptoResultImpl> CryptoResultImpl::create(ScriptPromise promise) | 50 PassRefPtr<CryptoResultImpl> CryptoResultImpl::create(ScriptPromise promise) |
| 54 { | 51 { |
| 55 return adoptRef(new CryptoResultImpl(activeExecutionContext(), promise)); | 52 return adoptRef(new CryptoResultImpl(activeExecutionContext(), promise)); |
| 56 } | 53 } |
| 57 | 54 |
| 58 void CryptoResultImpl::completeWithError() | 55 void CryptoResultImpl::completeWithError(const blink::WebString& errorDetails) |
| 59 { | 56 { |
| 60 ASSERT(!m_finished); | 57 ASSERT(!m_finished); |
| 61 | 58 |
| 62 if (canCompletePromise()) { | 59 if (canCompletePromise()) { |
| 63 DOMRequestState::Scope scope(m_requestState); | 60 DOMRequestState::Scope scope(m_requestState); |
| 61 if (!errorDetails.isEmpty()) { |
| 62 // FIXME: Include the line number which started the crypto operation
. |
| 63 executionContext()->addConsoleMessage(JSMessageSource, ErrorMessageL
evel, errorDetails); |
| 64 } |
| 64 m_promiseResolver->reject(ScriptValue::createNull()); | 65 m_promiseResolver->reject(ScriptValue::createNull()); |
| 65 } | 66 } |
| 67 } |
| 66 | 68 |
| 67 finish(); | 69 void CryptoResultImpl::completeWithError() |
| 70 { |
| 71 completeWithError(blink::WebString()); |
| 68 } | 72 } |
| 69 | 73 |
| 70 void CryptoResultImpl::completeWithBuffer(const blink::WebArrayBuffer& buffer) | 74 void CryptoResultImpl::completeWithBuffer(const blink::WebArrayBuffer& buffer) |
| 71 { | 75 { |
| 72 ASSERT(!m_finished); | 76 ASSERT(!m_finished); |
| 73 | 77 |
| 74 if (canCompletePromise()) { | 78 if (canCompletePromise()) { |
| 75 DOMRequestState::Scope scope(m_requestState); | 79 DOMRequestState::Scope scope(m_requestState); |
| 76 m_promiseResolver->resolve(PassRefPtr<ArrayBuffer>(buffer)); | 80 m_promiseResolver->resolve(PassRefPtr<ArrayBuffer>(buffer)); |
| 77 } | 81 } |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 } | 160 } |
| 157 | 161 |
| 158 bool CryptoResultImpl::canCompletePromise() const | 162 bool CryptoResultImpl::canCompletePromise() const |
| 159 { | 163 { |
| 160 CheckValidThread(); | 164 CheckValidThread(); |
| 161 ExecutionContext* context = executionContext(); | 165 ExecutionContext* context = executionContext(); |
| 162 return context && !context->activeDOMObjectsAreSuspended() && !context->acti
veDOMObjectsAreStopped(); | 166 return context && !context->activeDOMObjectsAreSuspended() && !context->acti
veDOMObjectsAreStopped(); |
| 163 } | 167 } |
| 164 | 168 |
| 165 } // namespace WebCore | 169 } // namespace WebCore |
| OLD | NEW |