OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "config.h" | 5 #include "config.h" |
6 #include "modules/credentialmanager/CredentialsContainer.h" | 6 #include "modules/credentialmanager/CredentialsContainer.h" |
7 | 7 |
8 #include "bindings/core/v8/Dictionary.h" | 8 #include "bindings/core/v8/Dictionary.h" |
9 #include "bindings/core/v8/ScriptPromise.h" | 9 #include "bindings/core/v8/ScriptPromise.h" |
10 #include "bindings/core/v8/ScriptPromiseResolver.h" | 10 #include "bindings/core/v8/ScriptPromiseResolver.h" |
11 #include "core/dom/DOMException.h" | 11 #include "core/dom/DOMException.h" |
12 #include "core/dom/ExceptionCode.h" | 12 #include "core/dom/ExceptionCode.h" |
13 #include "core/dom/ExecutionContext.h" | 13 #include "core/dom/ExecutionContext.h" |
14 #include "modules/credentialmanager/Credential.h" | 14 #include "modules/credentialmanager/Credential.h" |
15 #include "platform/weborigin/SecurityOrigin.h" | 15 #include "platform/weborigin/SecurityOrigin.h" |
16 #include "public/platform/Platform.h" | 16 #include "public/platform/Platform.h" |
17 #include "public/platform/WebCredential.h" | |
18 #include "public/platform/WebCredentialManager.h" | |
19 #include "public/platform/WebCredentialManagerError.h" | |
17 | 20 |
18 namespace blink { | 21 namespace blink { |
19 | 22 |
23 static void rejectDueToCredentialManagerError(PassRefPtr<ScriptPromiseResolver> resolver, WebCredentialManagerError* reason) | |
24 { | |
25 | |
26 switch (reason->errorType) { | |
27 case WebCredentialManagerError::DisabledErrorType: | |
28 resolver->reject(DOMException::create(InvalidStateError, "The credential manager is disabled.")); | |
29 break; | |
30 case WebCredentialManagerError::UnknownErrorType: | |
31 resolver->reject(DOMException::create(NotReadableError, "An unknown erro r occured while talking to the credential manager.")); | |
32 break; | |
tkent
2014/08/11 08:43:50
Will the break-then-ASSERT_NO_REACHED work well?
Mike West
2014/08/11 09:13:40
You're right, this is still prototypey-enough that
| |
33 }; | |
tkent
2014/08/11 08:43:50
; is unnecessary.
Mike West
2014/08/11 09:13:40
Done.
| |
34 ASSERT_NOT_REACHED(); | |
35 resolver->reject(DOMException::create(InvalidStateError)); | |
36 } | |
37 | |
38 class NotificationCallbacks : public WebCredentialManager::NotificationCallbacks { | |
yhirano
2014/08/11 08:58:48
How about enclosing this class with an unnamed nam
| |
39 WTF_MAKE_NONCOPYABLE(NotificationCallbacks); | |
40 public: | |
41 explicit NotificationCallbacks(PassRefPtr<ScriptPromiseResolver> resolver) : m_resolver(resolver) { } | |
42 virtual ~NotificationCallbacks() { } | |
43 | |
44 virtual void onSuccess() OVERRIDE | |
45 { | |
46 m_resolver->resolve(); | |
47 } | |
48 | |
49 virtual void onError(WebCredentialManagerError* reason) OVERRIDE | |
yhirano
2014/08/11 08:58:48
IIRC WebCallbacks handler parameter ownership is t
Mike West
2014/08/11 09:13:40
Hrm. My impression was that CallbackPromiseAdaptor
yhirano
2014/08/12 06:55:28
OK, I see.
| |
50 { | |
51 rejectDueToCredentialManagerError(m_resolver, reason); | |
52 } | |
53 | |
54 private: | |
55 const RefPtr<ScriptPromiseResolver> m_resolver; | |
56 }; | |
57 | |
58 class RequestCallbacks : public WebCredentialManager::RequestCallbacks { | |
yhirano
2014/08/11 08:58:48
ditto
| |
59 WTF_MAKE_NONCOPYABLE(RequestCallbacks); | |
60 public: | |
61 explicit RequestCallbacks(PassRefPtr<ScriptPromiseResolver> resolver) : m_re solver(resolver) { } | |
62 virtual ~RequestCallbacks() { } | |
63 | |
64 virtual void onSuccess(WebCredential* credential) OVERRIDE | |
yhirano
2014/08/11 08:58:48
ditto
| |
65 { | |
66 m_resolver->resolve(Credential::create(credential->id(), credential->nam e(), credential->avatarURL())); | |
67 } | |
68 | |
69 virtual void onError(WebCredentialManagerError* reason) OVERRIDE | |
yhirano
2014/08/11 08:58:48
ditto
| |
70 { | |
71 rejectDueToCredentialManagerError(m_resolver, reason); | |
72 } | |
73 | |
74 private: | |
75 const RefPtr<ScriptPromiseResolver> m_resolver; | |
76 }; | |
77 | |
78 | |
20 CredentialsContainer* CredentialsContainer::create() | 79 CredentialsContainer* CredentialsContainer::create() |
21 { | 80 { |
22 return new CredentialsContainer(); | 81 return new CredentialsContainer(); |
23 } | 82 } |
24 | 83 |
25 CredentialsContainer::CredentialsContainer() | 84 CredentialsContainer::CredentialsContainer() |
26 { | 85 { |
27 ScriptWrappable::init(this); | 86 ScriptWrappable::init(this); |
28 } | 87 } |
29 | 88 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
64 { | 123 { |
65 return stubImplementation(scriptState); | 124 return stubImplementation(scriptState); |
66 } | 125 } |
67 | 126 |
68 ScriptPromise CredentialsContainer::notifySignedOut(ScriptState* scriptState) | 127 ScriptPromise CredentialsContainer::notifySignedOut(ScriptState* scriptState) |
69 { | 128 { |
70 return stubImplementation(scriptState); | 129 return stubImplementation(scriptState); |
71 } | 130 } |
72 | 131 |
73 } // namespace blink | 132 } // namespace blink |
OLD | NEW |