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

Side by Side Diff: components/password_manager/content/renderer/credential_manager_client.cc

Issue 464883002: Credential Manager: Renderer-side implementation. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixing debug. 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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 #include "components/password_manager/content/renderer/credential_manager_client .h"
6
7 #include "components/password_manager/content/common/credential_manager_messages .h"
8 #include "components/password_manager/content/common/credential_manager_types.h"
9 #include "content/public/renderer/render_thread.h"
10 #include "content/public/renderer/render_view.h"
11 #include "third_party/WebKit/public/platform/WebCredential.h"
12 #include "third_party/WebKit/public/platform/WebCredentialManagerError.h"
13 #include "third_party/WebKit/public/web/WebView.h"
14
15 namespace password_manager {
16
17 namespace {
18
19 template <typename T>
20 void ClearCallbacksMapWithErrors(T* callbacks_map) {
21 typename T::iterator iter(callbacks_map);
22 while (!iter.IsAtEnd()) {
23 blink::WebCredentialManagerError reason(
24 blink::WebCredentialManagerError::ErrorTypeUnknown,
25 "An unknown error occurred.");
26 iter.GetCurrentValue()->onError(&reason);
27 callbacks_map->Remove(iter.GetCurrentKey());
28 iter.Advance();
29 }
30 }
31
32 } // namespace
33
34 CredentialManagerClient::CredentialManagerClient()
35 : routing_id_(MSG_ROUTING_NONE)
36 , render_thread_(content::RenderThread::Get()) {
Ilya Sherman 2014/08/21 17:58:15 nit: In Chromium style, the comma goes on the prev
Mike West 2014/08/22 09:03:15 Done.
37 DCHECK(render_thread_);
38 }
39
40 CredentialManagerClient::~CredentialManagerClient() {
41 DisconnectFromRenderThread();
42
43 ClearCallbacksMapWithErrors(&failed_sign_in_callbacks_);
44 ClearCallbacksMapWithErrors(&signed_in_callbacks_);
45 ClearCallbacksMapWithErrors(&signed_out_callbacks_);
46 ClearCallbacksMapWithErrors(&request_callbacks_);
47 }
48
49 void CredentialManagerClient::OnRenderViewCreated(
50 content::RenderView* render_view) {
51 render_view->GetWebView()->setCredentialManagerClient(this);
52 }
53
54 void CredentialManagerClient::OnRenderProcessShutdown() {
55 DisconnectFromRenderThread();
56 }
57
58 int CredentialManagerClient::GetRoutingID() {
59 if (render_thread_ && routing_id_ == MSG_ROUTING_NONE) {
60 routing_id_ = render_thread_->GenerateRoutingID();
61 render_thread_->AddRoute(routing_id_, this);
62 }
63 return routing_id_;
64 }
65
66 void CredentialManagerClient::DisconnectFromRenderThread() {
67 if (render_thread_ && routing_id_ != MSG_ROUTING_NONE)
68 render_thread_->RemoveRoute(routing_id_);
69 render_thread_ = NULL;
70 routing_id_ = MSG_ROUTING_NONE;
71 }
72
73 // -----------------------------------------------------------------------------
74 // Handle messages from the browser.
75
76 bool CredentialManagerClient::OnMessageReceived(
77 const IPC::Message& message) {
78 bool handled = true;
79 IPC_BEGIN_MESSAGE_MAP(CredentialManagerClient, message)
80 IPC_MESSAGE_HANDLER(CredentialManagerMsg_AcknowledgeFailedSignIn,
81 OnAcknowledgeFailedSignIn)
82 IPC_MESSAGE_HANDLER(CredentialManagerMsg_AcknowledgeSignedIn,
83 OnAcknowledgeSignedIn)
84 IPC_MESSAGE_HANDLER(CredentialManagerMsg_AcknowledgeSignedOut,
85 OnAcknowledgeSignedOut)
86 IPC_MESSAGE_HANDLER(CredentialManagerMsg_SendCredential, OnSendCredential)
87 IPC_MESSAGE_UNHANDLED(handled = false)
88 IPC_END_MESSAGE_MAP()
89 return handled;
90 }
91
92 void CredentialManagerClient::OnAcknowledgeFailedSignIn(int request_id) {
93 RespondToNotificationCallback(request_id, &failed_sign_in_callbacks_);
94 }
95
96 void CredentialManagerClient::OnAcknowledgeSignedIn(int request_id) {
97 RespondToNotificationCallback(request_id, &signed_in_callbacks_);
98 }
99
100 void CredentialManagerClient::OnAcknowledgeSignedOut(int request_id) {
101 RespondToNotificationCallback(request_id, &signed_out_callbacks_);
102 }
103
104 void CredentialManagerClient::OnSendCredential(
105 int request_id,
106 const CredentialInfo& info) {
107 RequestCallbacks* callbacks = request_callbacks_.Lookup(request_id);
108 DCHECK(callbacks);
109 // TODO(mkwst): Split into local/federated credentials.
110 blink::WebCredential credential(info.id, info.name, info.avatar);
111 callbacks->onSuccess(&credential);
112 request_callbacks_.Remove(request_id);
113 }
114
115 // -----------------------------------------------------------------------------
116 // Dispatch messages from the renderer to the browser.
117
118 void CredentialManagerClient::dispatchFailedSignIn(
119 const blink::WebCredential& credential,
120 blink::WebCredentialManagerClient::NotificationCallbacks* callbacks) {
121 int request_id = failed_sign_in_callbacks_.Add(callbacks);
122 CredentialInfo info(
123 credential.id(), credential.name(), credential.avatarURL());
124 if (render_thread_) {
125 render_thread_->Send(new CredentialManagerHostMsg_NotifyFailedSignIn(
126 GetRoutingID(), request_id, info));
127 }
128 }
129
130 void CredentialManagerClient::dispatchSignedIn(
131 const blink::WebCredential& credential,
132 blink::WebCredentialManagerClient::NotificationCallbacks* callbacks) {
133 int request_id = signed_in_callbacks_.Add(callbacks);
134 CredentialInfo info(
135 credential.id(), credential.name(), credential.avatarURL());
136 if (render_thread_) {
137 render_thread_->Send(new CredentialManagerHostMsg_NotifySignedIn(
138 GetRoutingID(), request_id, info));
139 }
140 }
141
142 void CredentialManagerClient::dispatchSignedOut(
143 NotificationCallbacks* callbacks) {
144 int request_id = signed_out_callbacks_.Add(callbacks);
145 if (render_thread_) {
146 render_thread_->Send(
147 new CredentialManagerHostMsg_NotifySignedOut(GetRoutingID(),
148 request_id));
149 }
150 }
151
152 void CredentialManagerClient::dispatchRequest(
153 bool zeroClickOnly,
154 const blink::WebVector<blink::WebURL>& federations,
155 RequestCallbacks* callbacks) {
156 int request_id = request_callbacks_.Add(callbacks);
157 std::vector<GURL> federation_vector;
158 for (size_t i = 0; i < std::min(federations.size(), kMaxFederations); ++i)
159 federation_vector.push_back(federations[i]);
160 if (render_thread_) {
161 render_thread_->Send(new CredentialManagerHostMsg_RequestCredential(
162 GetRoutingID(), request_id, zeroClickOnly, federation_vector));
163 }
164 }
165
166 void CredentialManagerClient::RespondToNotificationCallback(
167 int request_id,
168 CredentialManagerClient::NotificationCallbacksMap* map) {
169 blink::WebCredentialManagerClient::NotificationCallbacks* callbacks =
170 map->Lookup(request_id);
171 DCHECK(callbacks);
172 callbacks->onSuccess();
173 map->Remove(request_id);
174 }
175
176
177 } // namespace password_manager
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698