Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(653)

Side by Side Diff: Source/modules/crypto/KeyOperation.cpp

Issue 19885002: WebCrypto: Add interfaces for importKey(). (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Add testing interface Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 11 matching lines...) Expand all
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 30
31 #include "config.h" 31 #include "config.h"
32 #include "modules/crypto/KeyOperation.h"
33
32 #include "bindings/v8/ExceptionState.h" 34 #include "bindings/v8/ExceptionState.h"
33 35 #include "V8Key.h" // NOTE: This must appear before ScriptPromiseResolver to def ine toV8()
34 #include "bindings/v8/V8ThrowException.h" 36 #include "bindings/v8/ScriptPromiseResolver.h"
35 #include "core/dom/ExceptionCode.h" 37 #include "core/dom/ExceptionCode.h"
38 #include "modules/crypto/Key.h"
39 #include "public/platform/WebCrypto.h"
36 40
37 namespace WebCore { 41 namespace WebCore {
38 42
39 void ExceptionState::clearException() 43 PassRefPtr<KeyOperation> KeyOperation::create()
40 { 44 {
41 m_code = 0; 45 return adoptRef(new KeyOperation);
42 m_exception.clear();
43 } 46 }
44 47
45 void ExceptionState::throwDOMException(const ExceptionCode& ec, const String& me ssage) 48 KeyOperation::KeyOperation()
49 : m_state(Initializing)
50 , m_impl(0)
51 , m_exceptionCode(0)
46 { 52 {
47 ASSERT(ec);
48 m_code = ec;
49 setException(V8ThrowException::createDOMException(ec, message, m_isolate));
50 } 53 }
51 54
52 void ExceptionState::setException(v8::Handle<v8::Value> exception) 55 KeyOperation::~KeyOperation()
53 { 56 {
54 if (exception.IsEmpty()) { 57 ASSERT(!m_impl);
55 clearException(); 58 }
56 return; 59
60 void KeyOperation::initializationFailed()
61 {
62 ASSERT(m_state == Initializing);
63 ASSERT(!m_impl);
64
65 m_exceptionCode = NotSupportedError;
66 m_state = Done;
67 }
68
69 void KeyOperation::initializationSucceeded(WebKit::WebCryptoKeyOperation* operat ionImpl)
70 {
71 ASSERT(m_state == Initializing);
72 ASSERT(operationImpl);
73 ASSERT(!m_impl);
74
75 m_impl = operationImpl;
76 m_state = InProgress;
77 }
78
79 void KeyOperation::completeWithError()
80 {
81 ASSERT(m_state == Initializing || m_state == InProgress);
82
83 m_impl = 0;
84 m_state = Done;
85
86 promiseResolver()->reject(ScriptValue::createNull());
87 }
88
89 void KeyOperation::completeWithKey(const WebKit::WebCryptoKey& key)
90 {
91 ASSERT(m_state == Initializing || m_state == InProgress);
92
93 m_impl = 0;
94 m_state = Done;
95
96 promiseResolver()->fulfill(Key::create(key));
97 }
98
99 ScriptObject KeyOperation::returnValue(ExceptionState& es)
100 {
101 ASSERT(m_state != Initializing);
102
103 if (m_exceptionCode) {
104 es.throwDOMException(m_exceptionCode);
105 return ScriptObject();
57 } 106 }
58 107
59 m_exception.set(m_isolate, exception); 108 return promiseResolver()->promise();
60 } 109 }
61 110
62 void ExceptionState::throwTypeError(const String& message) 111 ScriptPromiseResolver* KeyOperation::promiseResolver()
63 { 112 {
64 m_code = TypeError; 113 if (!m_promiseResolver)
65 setException(V8ThrowException::createTypeError(message, m_isolate)); 114 m_promiseResolver = ScriptPromiseResolver::create();
66 } 115 return m_promiseResolver.get();
67
68 NonThrowExceptionState::NonThrowExceptionState()
69 : ExceptionState(0) { }
70
71 void NonThrowExceptionState::throwDOMException(const ExceptionCode& ec, const St ring&)
72 {
73 m_code = ec;
74 }
75
76 void NonThrowExceptionState::throwTypeError(const String&)
77 {
78 m_code = TypeError;
79 } 116 }
80 117
81 } // namespace WebCore 118 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698