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

Unified Diff: Source/modules/credentialmanager/CredentialsContainer.cpp

Issue 456293002: Credential manager: Introduce platform interface. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: feedback. Created 6 years, 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | public/platform/Platform.h » ('j') | public/platform/WebCredentialManagerError.h » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/modules/credentialmanager/CredentialsContainer.cpp
diff --git a/Source/modules/credentialmanager/CredentialsContainer.cpp b/Source/modules/credentialmanager/CredentialsContainer.cpp
index 2d99b217bd655653874452fc07320a4fd7e2c457..da5045a348d71029f6a1107bc1e5de14c90d486a 100644
--- a/Source/modules/credentialmanager/CredentialsContainer.cpp
+++ b/Source/modules/credentialmanager/CredentialsContainer.cpp
@@ -14,9 +14,67 @@
#include "modules/credentialmanager/Credential.h"
#include "platform/weborigin/SecurityOrigin.h"
#include "public/platform/Platform.h"
+#include "public/platform/WebCredential.h"
+#include "public/platform/WebCredentialManager.h"
+#include "public/platform/WebCredentialManagerError.h"
namespace blink {
+static void rejectDueToCredentialManagerError(PassRefPtr<ScriptPromiseResolver> resolver, WebCredentialManagerError* reason)
+{
+
+ switch (reason->errorType) {
+ case WebCredentialManagerError::DisabledErrorType:
+ resolver->reject(DOMException::create(InvalidStateError, "The credential manager is disabled."));
+ break;
+ case WebCredentialManagerError::UnknownErrorType:
+ default:
+ resolver->reject(DOMException::create(NotReadableError, "An unknown error occured while talking to the credential manager."));
+ break;
+ }
+}
+
+class NotificationCallbacks : public WebCredentialManager::NotificationCallbacks {
+ WTF_MAKE_NONCOPYABLE(NotificationCallbacks);
+public:
+ explicit NotificationCallbacks(PassRefPtr<ScriptPromiseResolver> resolver) : m_resolver(resolver) { }
+ virtual ~NotificationCallbacks() { }
+
+ virtual void onSuccess() OVERRIDE
+ {
+ m_resolver->resolve();
+ }
+
+ virtual void onError(WebCredentialManagerError* reason) OVERRIDE
+ {
+ rejectDueToCredentialManagerError(m_resolver, reason);
+ }
+
+private:
+ const RefPtr<ScriptPromiseResolver> m_resolver;
+};
+
+class RequestCallbacks : public WebCredentialManager::RequestCallbacks {
+ WTF_MAKE_NONCOPYABLE(RequestCallbacks);
+public:
+ explicit RequestCallbacks(PassRefPtr<ScriptPromiseResolver> resolver) : m_resolver(resolver) { }
+ virtual ~RequestCallbacks() { }
+
+ virtual void onSuccess(WebCredential* credential) OVERRIDE
+ {
+ m_resolver->resolve(Credential::create(credential->id(), credential->name(), credential->avatarURL()));
+ }
+
+ virtual void onError(WebCredentialManagerError* reason) OVERRIDE
+ {
+ rejectDueToCredentialManagerError(m_resolver, reason);
+ }
+
+private:
+ const RefPtr<ScriptPromiseResolver> m_resolver;
+};
+
+
CredentialsContainer* CredentialsContainer::create()
{
return new CredentialsContainer();
« no previous file with comments | « no previous file | public/platform/Platform.h » ('j') | public/platform/WebCredentialManagerError.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698