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 default: |
| 32 resolver->reject(DOMException::create(NotReadableError, "An unknown erro
r occured while talking to the credential manager.")); |
| 33 break; |
| 34 } |
| 35 } |
| 36 |
| 37 class NotificationCallbacks : public WebCredentialManager::NotificationCallbacks
{ |
| 38 WTF_MAKE_NONCOPYABLE(NotificationCallbacks); |
| 39 public: |
| 40 explicit NotificationCallbacks(PassRefPtr<ScriptPromiseResolver> resolver) :
m_resolver(resolver) { } |
| 41 virtual ~NotificationCallbacks() { } |
| 42 |
| 43 virtual void onSuccess() OVERRIDE |
| 44 { |
| 45 m_resolver->resolve(); |
| 46 } |
| 47 |
| 48 virtual void onError(WebCredentialManagerError* reason) OVERRIDE |
| 49 { |
| 50 rejectDueToCredentialManagerError(m_resolver, reason); |
| 51 } |
| 52 |
| 53 private: |
| 54 const RefPtr<ScriptPromiseResolver> m_resolver; |
| 55 }; |
| 56 |
| 57 class RequestCallbacks : public WebCredentialManager::RequestCallbacks { |
| 58 WTF_MAKE_NONCOPYABLE(RequestCallbacks); |
| 59 public: |
| 60 explicit RequestCallbacks(PassRefPtr<ScriptPromiseResolver> resolver) : m_re
solver(resolver) { } |
| 61 virtual ~RequestCallbacks() { } |
| 62 |
| 63 virtual void onSuccess(WebCredential* credential) OVERRIDE |
| 64 { |
| 65 m_resolver->resolve(Credential::create(credential->id(), credential->nam
e(), credential->avatarURL())); |
| 66 } |
| 67 |
| 68 virtual void onError(WebCredentialManagerError* reason) OVERRIDE |
| 69 { |
| 70 rejectDueToCredentialManagerError(m_resolver, reason); |
| 71 } |
| 72 |
| 73 private: |
| 74 const RefPtr<ScriptPromiseResolver> m_resolver; |
| 75 }; |
| 76 |
| 77 |
20 CredentialsContainer* CredentialsContainer::create() | 78 CredentialsContainer* CredentialsContainer::create() |
21 { | 79 { |
22 return new CredentialsContainer(); | 80 return new CredentialsContainer(); |
23 } | 81 } |
24 | 82 |
25 CredentialsContainer::CredentialsContainer() | 83 CredentialsContainer::CredentialsContainer() |
26 { | 84 { |
27 ScriptWrappable::init(this); | 85 ScriptWrappable::init(this); |
28 } | 86 } |
29 | 87 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 { | 122 { |
65 return stubImplementation(scriptState); | 123 return stubImplementation(scriptState); |
66 } | 124 } |
67 | 125 |
68 ScriptPromise CredentialsContainer::notifySignedOut(ScriptState* scriptState) | 126 ScriptPromise CredentialsContainer::notifySignedOut(ScriptState* scriptState) |
69 { | 127 { |
70 return stubImplementation(scriptState); | 128 return stubImplementation(scriptState); |
71 } | 129 } |
72 | 130 |
73 } // namespace blink | 131 } // namespace blink |
OLD | NEW |