| OLD | NEW |
| 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 Loading... |
| 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 // PasswordForms upon destruction. | |
| 155 std::vector<autofill::PasswordForm*> local_results; | 154 std::vector<autofill::PasswordForm*> local_results; |
| 156 std::vector<autofill::PasswordForm*> federated_results; | 155 std::vector<autofill::PasswordForm*> federated_results; |
| 157 ScopedVector<autofill::PasswordForm> discarded_results; | |
| 158 for (autofill::PasswordForm* form : results) { | 156 for (autofill::PasswordForm* form : results) { |
| 159 // TODO(mkwst): Extend this filter to include federations. | |
| 160 if (form->origin == pending_request_->origin) | 157 if (form->origin == pending_request_->origin) |
| 161 local_results.push_back(form); | 158 local_results.push_back(form); |
| 162 else if (federations.count(form->origin.spec()) != 0) | 159 else if (federations.count(form->origin.spec()) != 0) |
| 163 federated_results.push_back(form); | 160 federated_results.push_back(form); |
| 164 else | 161 else |
| 165 discarded_results.push_back(form); | 162 delete form; |
| 166 } | 163 } |
| 167 | 164 |
| 168 if ((local_results.empty() && federated_results.empty()) || | 165 if ((local_results.empty() && federated_results.empty()) || |
| 169 web_contents()->GetLastCommittedURL().GetOrigin() != | 166 web_contents()->GetLastCommittedURL().GetOrigin() != |
| 170 pending_request_->origin) { | 167 pending_request_->origin) { |
| 171 SendCredential(pending_request_->id, CredentialInfo()); | 168 SendCredential(pending_request_->id, CredentialInfo()); |
| 172 return; | 169 return; |
| 173 } | 170 } |
| 174 | 171 |
| 175 if (!client_->PromptUserToChooseCredentials( | 172 if (local_results.size() == 1 && IsZeroClickAllowed()) { |
| 176 local_results, | 173 // TODO(mkwst): Use the `one_time_disable_zero_click` flag on the result |
| 177 federated_results, | 174 // to prevent auto-sign-in, once that flag is implemented. |
| 175 CredentialInfo info(*local_results[0], |
| 176 local_results[0]->federation_url.is_empty() |
| 177 ? CredentialType::CREDENTIAL_TYPE_LOCAL |
| 178 : CredentialType::CREDENTIAL_TYPE_FEDERATED); |
| 179 STLDeleteElements(&local_results); |
| 180 STLDeleteElements(&federated_results); |
| 181 SendCredential(pending_request_->id, info); |
| 182 return; |
| 183 } |
| 184 |
| 185 if (pending_request_->zero_click_only || |
| 186 !client_->PromptUserToChooseCredentials( |
| 187 local_results, federated_results, |
| 178 base::Bind(&CredentialManagerDispatcher::SendCredential, | 188 base::Bind(&CredentialManagerDispatcher::SendCredential, |
| 179 base::Unretained(this), pending_request_->id))) { | 189 base::Unretained(this), pending_request_->id))) { |
| 190 STLDeleteElements(&local_results); |
| 191 STLDeleteElements(&federated_results); |
| 180 SendCredential(pending_request_->id, CredentialInfo()); | 192 SendCredential(pending_request_->id, CredentialInfo()); |
| 181 } | 193 } |
| 182 } | 194 } |
| 183 | 195 |
| 184 PasswordStore* CredentialManagerDispatcher::GetPasswordStore() { | 196 PasswordStore* CredentialManagerDispatcher::GetPasswordStore() { |
| 185 return client_ ? client_->GetPasswordStore() : nullptr; | 197 return client_ ? client_->GetPasswordStore() : nullptr; |
| 186 } | 198 } |
| 187 | 199 |
| 188 bool CredentialManagerDispatcher::IsSavingEnabledForCurrentPage() const { | 200 bool CredentialManagerDispatcher::IsSavingEnabledForCurrentPage() const { |
| 189 // TODO(vasilii): add more, see http://crbug.com/450583. | 201 // TODO(vasilii): add more, see http://crbug.com/450583. |
| 190 return !client_->IsOffTheRecord(); | 202 return !client_->IsOffTheRecord(); |
| 191 } | 203 } |
| 192 | 204 |
| 193 bool CredentialManagerDispatcher::IsZeroClickAllowed() const { | 205 bool CredentialManagerDispatcher::IsZeroClickAllowed() const { |
| 194 return !client_->IsOffTheRecord(); | 206 return !client_->IsOffTheRecord() && client_->IsZeroClickEnabled(); |
| 195 } | 207 } |
| 196 | 208 |
| 197 base::WeakPtr<PasswordManagerDriver> CredentialManagerDispatcher::GetDriver() { | 209 base::WeakPtr<PasswordManagerDriver> CredentialManagerDispatcher::GetDriver() { |
| 198 ContentPasswordManagerDriverFactory* driver_factory = | 210 ContentPasswordManagerDriverFactory* driver_factory = |
| 199 ContentPasswordManagerDriverFactory::FromWebContents(web_contents()); | 211 ContentPasswordManagerDriverFactory::FromWebContents(web_contents()); |
| 200 DCHECK(driver_factory); | 212 DCHECK(driver_factory); |
| 201 PasswordManagerDriver* driver = | 213 PasswordManagerDriver* driver = |
| 202 driver_factory->GetDriverForFrame(web_contents()->GetMainFrame()); | 214 driver_factory->GetDriverForFrame(web_contents()->GetMainFrame()); |
| 203 return driver->AsWeakPtr(); | 215 return driver->AsWeakPtr(); |
| 204 } | 216 } |
| 205 | 217 |
| 206 void CredentialManagerDispatcher::SendCredential(int request_id, | 218 void CredentialManagerDispatcher::SendCredential(int request_id, |
| 207 const CredentialInfo& info) { | 219 const CredentialInfo& info) { |
| 208 DCHECK(pending_request_); | 220 DCHECK(pending_request_); |
| 209 DCHECK_EQ(pending_request_->id, request_id); | 221 DCHECK_EQ(pending_request_->id, request_id); |
| 210 web_contents()->GetRenderViewHost()->Send( | 222 web_contents()->GetRenderViewHost()->Send( |
| 211 new CredentialManagerMsg_SendCredential( | 223 new CredentialManagerMsg_SendCredential( |
| 212 web_contents()->GetRenderViewHost()->GetRoutingID(), | 224 web_contents()->GetRenderViewHost()->GetRoutingID(), |
| 213 pending_request_->id, info)); | 225 pending_request_->id, info)); |
| 214 pending_request_.reset(); | 226 pending_request_.reset(); |
| 215 } | 227 } |
| 216 | 228 |
| 217 } // namespace password_manager | 229 } // namespace password_manager |
| OLD | NEW |