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
3 // found in the LICENSE file.
5 #ifndef COMPONENTS_PASSWORD_MANAGER_CONTENT_RENDERER_CREDENTIAL_MANAGER_CLIENT_H_
6 #define COMPONENTS_PASSWORD_MANAGER_CONTENT_RENDERER_CREDENTIAL_MANAGER_CLIENT_H_
8 #include "base/basictypes.h"
9 #include "base/compiler_specific.h"
10 #include "base/id_map.h"
11 #include "content/public/renderer/render_view_observer.h"
12 #include "ipc/ipc_listener.h"
13 #include "third_party/WebKit/public/platform/WebCredentialManagerClient.h"
14 #include "third_party/WebKit/public/platform/WebCredentialManagerError.h"
15 #include "third_party/WebKit/public/platform/WebVector.h"
26 namespace password_manager
{
28 struct CredentialInfo
;
30 // The CredentialManagerClient implements the Blink platform interface
31 // WebCredentialManagerClient, and acts as an intermediary between Blink-side
32 // calls to 'navigator.credential.*' and the password manager internals which
33 // live in the browser process.
35 // One instance of CredentialManagerClient is created per RenderThread,
36 // held in a scoped_ptr on ChromeContentRendererClient. The client holds
37 // a raw pointer to the RenderThread on which it lives, and uses that pointer
38 // to send messages to the browser process, and to route responses to itself.
40 // When the render thread is shut down (or the client is destructed), the
41 // routing is removed, the pointer is cleared, and any pending responses are
44 // Note that each RenderView's WebView holds a pointer to the
45 // CredentialManagerClient (set in 'OnRenderViewCreated()'). The client is
46 // guaranteed to outlive the views that point to it.
47 class CredentialManagerClient
: public blink::WebCredentialManagerClient
,
48 public content::RenderViewObserver
{
50 explicit CredentialManagerClient(content::RenderView
* render_view
);
51 ~CredentialManagerClient() override
;
53 // RenderViewObserver:
54 bool OnMessageReceived(const IPC::Message
& message
) override
;
56 // Message handlers for messages from the browser process:
57 virtual void OnAcknowledgeFailedSignIn(int request_id
);
58 virtual void OnAcknowledgeSignedIn(int request_id
);
59 virtual void OnAcknowledgeSignedOut(int request_id
);
60 virtual void OnSendCredential(int request_id
,
61 const CredentialInfo
& credential_info
);
62 virtual void OnRejectCredentialRequest(
64 blink::WebCredentialManagerError::ErrorType error_type
);
66 // blink::WebCredentialManager:
67 virtual void dispatchFailedSignIn(
68 const blink::WebCredential
& credential
,
69 WebCredentialManagerClient::NotificationCallbacks
* callbacks
);
70 virtual void dispatchSignedIn(
71 const blink::WebCredential
& credential
,
72 WebCredentialManagerClient::NotificationCallbacks
* callbacks
);
73 virtual void dispatchSignedOut(NotificationCallbacks
* callbacks
);
74 virtual void dispatchRequest(
76 const blink::WebVector
<blink::WebURL
>& federations
,
77 RequestCallbacks
* callbacks
);
80 typedef IDMap
<blink::WebCredentialManagerClient::RequestCallbacks
,
81 IDMapOwnPointer
> RequestCallbacksMap
;
82 typedef IDMap
<blink::WebCredentialManagerClient::NotificationCallbacks
,
83 IDMapOwnPointer
> NotificationCallbacksMap
;
85 void RespondToNotificationCallback(int request_id
,
86 NotificationCallbacksMap
* map
);
88 // Track the various blink::WebCredentialManagerClient::*Callbacks objects
89 // generated from Blink. This class takes ownership of these objects.
90 NotificationCallbacksMap failed_sign_in_callbacks_
;
91 NotificationCallbacksMap signed_in_callbacks_
;
92 NotificationCallbacksMap signed_out_callbacks_
;
93 RequestCallbacksMap request_callbacks_
;
95 DISALLOW_COPY_AND_ASSIGN(CredentialManagerClient
);
98 } // namespace password_manager
100 #endif // COMPONENTS_PASSWORD_MANAGER_CONTENT_RENDERER_CREDENTIAL_MANAGER_CLIENT_H_