Commit bb7138d8 authored by mkwst@chromium.org's avatar mkwst@chromium.org

Credential manager: Introduce platform interface.

This patch adds a WebCredentialManager interface that the credential
manager module will (eventually) use to call up into its embedder in
response to JavaScript API calls.

These methods don't currently do anything, and aren't actually called;
until the Chromium-side work is done, there's no reason to wire them up
to the JavaScript bindings.

BUG=400674

Review URL: https://codereview.chromium.org/456293002

git-svn-id: svn://svn.chromium.org/blink/trunk@180040 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent a7d044d2
......@@ -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::ErrorTypeDisabled:
resolver->reject(DOMException::create(InvalidStateError, "The credential manager is disabled."));
break;
case WebCredentialManagerError::ErrorTypeUnknown:
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();
......
......@@ -66,6 +66,7 @@ class WebClipboard;
class WebCompositorSupport;
class WebConvertableToTraceFormat;
class WebCookieJar;
class WebCredentialManager;
class WebCrypto;
class WebDatabaseObserver;
class WebDiscardableMemory;
......@@ -170,6 +171,9 @@ public:
// Must return non-null.
virtual WebBlobRegistry* blobRegistry() { return 0; }
// Credential Management -----------------------------------------------
virtual WebCredentialManager* credentialManager() { return 0; }
// Database ------------------------------------------------------------
......
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef WebCredentialManager_h
#define WebCredentialManager_h
#include "public/platform/WebCallbacks.h"
#include "public/platform/WebCredentialManagerError.h"
#include "public/platform/WebString.h"
#include "public/platform/WebVector.h"
namespace blink {
// WebCredentialManager provides an interface for asking Blink's embedder to
// respond to `navigator.credentials.*` calls.
class WebCredentialManager {
public:
typedef WebCallbacks<WebCredential, WebCredentialManagerError> RequestCallbacks;
typedef WebCallbacks<void, WebCredentialManagerError> NotificationCallbacks;
WebCredentialManager();
virtual ~WebCredentialManager();
// Ownership of the callback is transferred to the callee for each of the following methods.
virtual void dispatchFailedSignIn(const WebCredential&, NotificationCallbacks*) { }
virtual void dispatchSignedIn(const WebCredential&, NotificationCallbacks*) { }
virtual void dispatchSignedOut(NotificationCallbacks*) { }
virtual void dispatchRequest(bool zeroClickOnly, const WebVector<WebString>& federations, RequestCallbacks*) { }
};
} // namespace blink
#endif // WebCredentialManager_h
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef WebCredentialManagerError_h
#define WebCredentialManagerError_h
#include "public/platform/WebString.h"
namespace blink {
struct WebCredentialManagerError {
// FIXME: This is a placeholder list of error conditions. We'll likely expand the
// list as the API evolves.
enum ErrorType {
ErrorTypeDisabled = 0,
ErrorTypeUnknown,
ErrorTypeLast = ErrorTypeUnknown
};
WebCredentialManagerError(ErrorType type, WebString message)
: errorType(type)
, errorMessage(message)
{
}
ErrorType errorType;
WebString errorMessage;
};
} // namespace blink
#endif
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment