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

Side by Side Diff: components/password_manager/content/browser/credential_manager_dispatcher.cc

Issue 879913004: Credential Management: Support zeroclick credential in 'request()'. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Test. Created 5 years, 10 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "components/password_manager/content/browser/credential_manager_dispatc her.h" 5 #include "components/password_manager/content/browser/credential_manager_dispatc her.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/memory/scoped_vector.h" 8 #include "base/memory/scoped_vector.h"
9 #include "base/strings/string16.h" 9 #include "base/strings/string16.h"
10 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 new CredentialManagerMsg_SendCredential( 130 new CredentialManagerMsg_SendCredential(
131 web_contents()->GetRenderViewHost()->GetRoutingID(), request_id, 131 web_contents()->GetRenderViewHost()->GetRoutingID(), request_id,
132 CredentialInfo())); 132 CredentialInfo()));
133 return; 133 return;
134 } 134 }
135 135
136 pending_request_.reset(new PendingRequestParameters( 136 pending_request_.reset(new PendingRequestParameters(
137 request_id, zero_click_only, 137 request_id, zero_click_only,
138 web_contents()->GetLastCommittedURL().GetOrigin(), federations)); 138 web_contents()->GetLastCommittedURL().GetOrigin(), federations));
139 139
140 // This will result in a callback to ::OnGetPasswordStoreResults().
140 store->GetAutofillableLogins(this); 141 store->GetAutofillableLogins(this);
141 } 142 }
142 143
143 void CredentialManagerDispatcher::OnGetPasswordStoreResults( 144 void CredentialManagerDispatcher::OnGetPasswordStoreResults(
144 const std::vector<autofill::PasswordForm*>& results) { 145 const std::vector<autofill::PasswordForm*>& results) {
145 DCHECK(pending_request_); 146 DCHECK(pending_request_);
146 147
147 std::set<std::string> federations; 148 std::set<std::string> federations;
148 for (const GURL& origin : pending_request_->federations) 149 for (const GURL& origin : pending_request_->federations)
149 federations.insert(origin.spec()); 150 federations.insert(origin.spec());
150 151
151 // We own the PasswordForm instances, so we're responsible for cleaning 152 // We own the PasswordForm instances, so we're responsible for cleaning
152 // up the instances we don't add to |local_results| or |federated_results|. 153 // up the instances we don't add to |local_results| or |federated_results|.
153 // We'll dump them into a ScopedVector and allow it to delete the 154 // We'll dump them into a ScopedVector and allow it to delete the
154 // PasswordForms upon destruction. 155 // PasswordForms upon destruction.
156 autofill::PasswordForm* to_send_as_zero_click = nullptr;
157 bool multiple_zero_click = false;
155 std::vector<autofill::PasswordForm*> local_results; 158 std::vector<autofill::PasswordForm*> local_results;
156 std::vector<autofill::PasswordForm*> federated_results; 159 std::vector<autofill::PasswordForm*> federated_results;
157 ScopedVector<autofill::PasswordForm> discarded_results; 160 ScopedVector<autofill::PasswordForm> discarded_results;
158 for (autofill::PasswordForm* form : results) { 161 for (autofill::PasswordForm* form : results) {
159 // TODO(mkwst): Extend this filter to include federations. 162 if (form->origin == pending_request_->origin) {
160 if (form->origin == pending_request_->origin)
161 local_results.push_back(form); 163 local_results.push_back(form);
162 else if (federations.count(form->origin.spec()) != 0) 164
165 // If more than one local credential is_zero_click, then we punt on
166 // auto signin.
167 //
168 // TODO(mkwst): We should have a global on-off switch here alongside the
169 // credential-level toggle.
170 if (form->is_zero_click && !multiple_zero_click) {
vasilii 2015/01/28 13:25:30 AS we discussed, I'll rename form->is_zero_click t
Mike West 2015/01/28 14:42:14 Perfect, thanks.
171 if (to_send_as_zero_click)
172 multiple_zero_click = true;
173 to_send_as_zero_click = multiple_zero_click ? nullptr : form;
174 }
175 } else if (federations.count(form->origin.spec()) != 0) {
163 federated_results.push_back(form); 176 federated_results.push_back(form);
164 else 177 } else {
165 discarded_results.push_back(form); 178 discarded_results.push_back(form);
vabr (Chromium) 2015/01/28 13:37:52 Why not just delete form; ?
Mike West 2015/01/28 14:42:14 That would be too easy!
179 }
166 } 180 }
167 181
168 if ((local_results.empty() && federated_results.empty()) || 182 if ((local_results.empty() && federated_results.empty()) ||
169 web_contents()->GetLastCommittedURL().GetOrigin() != 183 web_contents()->GetLastCommittedURL().GetOrigin() !=
170 pending_request_->origin) { 184 pending_request_->origin) {
171 SendCredential(pending_request_->id, CredentialInfo()); 185 SendCredential(pending_request_->id, CredentialInfo());
172 return; 186 return;
173 } 187 }
174 188
175 if (!client_->PromptUserToChooseCredentials( 189 if (to_send_as_zero_click) {
176 local_results, 190 discarded_results.assign(local_results.begin(), local_results.end());
vabr (Chromium) 2015/01/28 13:37:52 Why not use STLDeleteElements? This is a bit crypt
Mike West 2015/01/28 14:42:14 Sure. I can do that.
177 federated_results, 191 discarded_results.assign(federated_results.begin(),
192 federated_results.end());
193 CredentialInfo info(*to_send_as_zero_click,
194 to_send_as_zero_click->federation_url.is_empty()
195 ? CredentialType::CREDENTIAL_TYPE_LOCAL
196 : CredentialType::CREDENTIAL_TYPE_FEDERATED);
197 SendCredential(pending_request_->id, info);
198 return;
199 }
200
201 if (pending_request_->zero_click_only ||
202 !client_->PromptUserToChooseCredentials(
203 local_results, federated_results,
178 base::Bind(&CredentialManagerDispatcher::SendCredential, 204 base::Bind(&CredentialManagerDispatcher::SendCredential,
179 base::Unretained(this), pending_request_->id))) { 205 base::Unretained(this), pending_request_->id))) {
180 SendCredential(pending_request_->id, CredentialInfo()); 206 SendCredential(pending_request_->id, CredentialInfo());
181 } 207 }
182 } 208 }
183 209
184 PasswordStore* CredentialManagerDispatcher::GetPasswordStore() { 210 PasswordStore* CredentialManagerDispatcher::GetPasswordStore() {
185 return client_ ? client_->GetPasswordStore() : nullptr; 211 return client_ ? client_->GetPasswordStore() : nullptr;
186 } 212 }
187 213
(...skipping 20 matching lines...) Expand all
208 DCHECK(pending_request_); 234 DCHECK(pending_request_);
209 DCHECK_EQ(pending_request_->id, request_id); 235 DCHECK_EQ(pending_request_->id, request_id);
210 web_contents()->GetRenderViewHost()->Send( 236 web_contents()->GetRenderViewHost()->Send(
211 new CredentialManagerMsg_SendCredential( 237 new CredentialManagerMsg_SendCredential(
212 web_contents()->GetRenderViewHost()->GetRoutingID(), 238 web_contents()->GetRenderViewHost()->GetRoutingID(),
213 pending_request_->id, info)); 239 pending_request_->id, info));
214 pending_request_.reset(); 240 pending_request_.reset();
215 } 241 }
216 242
217 } // namespace password_manager 243 } // namespace password_manager
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698