Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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. | |
| 4 | |
| 5 #ifndef COMPONENTS_PASSWORD_MANAGER_CONTENT_RENDERER_CREDENTIAL_MANAGER_CLIENT_H _ | |
| 6 #define COMPONENTS_PASSWORD_MANAGER_CONTENT_RENDERER_CREDENTIAL_MANAGER_CLIENT_H _ | |
| 7 | |
| 8 #include "base/basictypes.h" | |
| 9 #include "base/compiler_specific.h" | |
| 10 #include "base/id_map.h" | |
| 11 #include "content/public/renderer/render_process_observer.h" | |
| 12 #include "ipc/ipc_listener.h" | |
| 13 #include "third_party/WebKit/public/platform/WebCredentialManagerClient.h" | |
| 14 #include "third_party/WebKit/public/platform/WebVector.h" | |
| 15 | |
| 16 namespace blink { | |
| 17 class WebCredential; | |
| 18 class WebURL; | |
| 19 } | |
| 20 | |
| 21 namespace content { | |
| 22 class RenderThread; | |
| 23 class RenderView; | |
| 24 } | |
| 25 | |
| 26 namespace password_manager { | |
| 27 | |
| 28 struct CredentialInfo; | |
| 29 | |
| 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. | |
| 34 // | |
| 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. | |
| 39 // | |
| 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 | |
| 42 // rejected. | |
| 43 // | |
| 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::RenderProcessObserver, | |
| 49 public IPC::Listener { | |
| 50 public: | |
| 51 CredentialManagerClient(); | |
| 52 virtual ~CredentialManagerClient(); | |
| 53 | |
| 54 // When a RenderView is created, we need to set this object as its client. | |
| 55 void OnRenderViewCreated(content::RenderView*); | |
| 56 | |
| 57 // content::RenderProcessObserver: | |
| 58 virtual void OnRenderProcessShutdown() OVERRIDE; | |
| 59 | |
| 60 // IPC::Listener: | |
| 61 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; | |
| 62 | |
| 63 // Message handlers for messages from the browser process: | |
| 64 virtual void OnAcknowledgeFailedSignIn(int request_id); | |
| 65 virtual void OnAcknowledgeSignedIn(int request_id); | |
| 66 virtual void OnAcknowledgeSignedOut(int request_id); | |
| 67 virtual void OnSendCredential(int request_id, | |
| 68 const CredentialInfo& credential_info); | |
| 69 | |
| 70 // blink::WebCredentialManager: | |
| 71 virtual void dispatchFailedSignIn( | |
| 72 const blink::WebCredential& credential, | |
| 73 WebCredentialManagerClient::NotificationCallbacks* callbacks) OVERRIDE; | |
| 74 virtual void dispatchSignedIn( | |
| 75 const blink::WebCredential& credential, | |
| 76 WebCredentialManagerClient::NotificationCallbacks* callbacks) OVERRIDE; | |
| 77 virtual void dispatchSignedOut(NotificationCallbacks* callbacks) OVERRIDE; | |
| 78 virtual void dispatchRequest( | |
| 79 bool zero_click_only, | |
| 80 const blink::WebVector<blink::WebURL>& federations, | |
| 81 RequestCallbacks* callbacks) OVERRIDE; | |
| 82 | |
| 83 protected: | |
| 84 virtual int GetRoutingID(); | |
| 85 | |
| 86 // Protected, as these are only meant to be used in tests. | |
| 87 bool FailedSignInCallbacksWaiting() { | |
|
Ilya Sherman
2014/08/21 00:11:21
Optional nit: Perhaps preppend "Has" to all of the
| |
| 88 return !failed_sign_in_callbacks_.IsEmpty(); | |
| 89 } | |
| 90 bool SignedInCallbacksWaiting() { return !signed_in_callbacks_.IsEmpty(); } | |
| 91 bool SignedOutCallbacksWaiting() { return !signed_out_callbacks_.IsEmpty(); } | |
| 92 bool RequestCallbacksWaiting() { return !request_callbacks_.IsEmpty(); } | |
| 93 | |
| 94 private: | |
| 95 typedef IDMap<blink::WebCredentialManagerClient::RequestCallbacks, | |
| 96 IDMapOwnPointer> RequestCallbacksMap; | |
| 97 typedef IDMap<blink::WebCredentialManagerClient::NotificationCallbacks, | |
| 98 IDMapOwnPointer> NotificationCallbacksMap; | |
| 99 | |
| 100 void RespondToNotificationCallback(int request_id, | |
| 101 NotificationCallbacksMap* map); | |
| 102 | |
| 103 // Nulls out the raw pointer to |render_thread_| after ensuring that any | |
| 104 // message routing is removed. | |
| 105 void DisconnectFromRenderThread(); | |
| 106 | |
| 107 int routing_id_; | |
| 108 content::RenderThread* render_thread_; | |
| 109 | |
| 110 // Track the various blink::WebCredentialManagerClient::*Callbacks objects | |
| 111 // generated from Blink. This class takes ownership of these objects. | |
| 112 NotificationCallbacksMap failed_sign_in_callbacks_; | |
| 113 NotificationCallbacksMap signed_in_callbacks_; | |
| 114 NotificationCallbacksMap signed_out_callbacks_; | |
| 115 RequestCallbacksMap request_callbacks_; | |
| 116 | |
| 117 DISALLOW_COPY_AND_ASSIGN(CredentialManagerClient); | |
| 118 }; | |
| 119 | |
| 120 } // namespace password_manager | |
| 121 | |
| 122 #endif // COMPONENTS_PASSWORD_MANAGER_CONTENT_RENDERER_CREDENTIAL_MANAGER_CLIEN T_H_ | |
| OLD | NEW |