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

Side by Side Diff: chrome/browser/ui/passwords/password_manager_presenter.cc

Issue 1193143003: Enable import/export of passwords into/from Password Manager (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 8 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "chrome/browser/ui/passwords/password_manager_presenter.h" 5 #include "chrome/browser/ui/passwords/password_manager_presenter.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 10 matching lines...) Expand all
21 #include "chrome/browser/signin/signin_manager_factory.h" 21 #include "chrome/browser/signin/signin_manager_factory.h"
22 #include "chrome/browser/sync/profile_sync_service_factory.h" 22 #include "chrome/browser/sync/profile_sync_service_factory.h"
23 #include "chrome/browser/ui/passwords/manage_passwords_view_utils.h" 23 #include "chrome/browser/ui/passwords/manage_passwords_view_utils.h"
24 #include "chrome/browser/ui/passwords/password_ui_view.h" 24 #include "chrome/browser/ui/passwords/password_ui_view.h"
25 #include "chrome/common/chrome_switches.h" 25 #include "chrome/common/chrome_switches.h"
26 #include "chrome/common/pref_names.h" 26 #include "chrome/common/pref_names.h"
27 #include "chrome/common/url_constants.h" 27 #include "chrome/common/url_constants.h"
28 #include "components/autofill/core/common/password_form.h" 28 #include "components/autofill/core/common/password_form.h"
29 #include "components/browser_sync/browser/profile_sync_service.h" 29 #include "components/browser_sync/browser/profile_sync_service.h"
30 #include "components/password_manager/core/browser/affiliation_utils.h" 30 #include "components/password_manager/core/browser/affiliation_utils.h"
31 #include "components/password_manager/core/browser/import/password_importer.h"
31 #include "components/password_manager/core/browser/password_manager_util.h" 32 #include "components/password_manager/core/browser/password_manager_util.h"
32 #include "components/password_manager/core/browser/password_ui_utils.h" 33 #include "components/password_manager/core/browser/password_ui_utils.h"
33 #include "components/password_manager/core/common/password_manager_pref_names.h" 34 #include "components/password_manager/core/common/password_manager_pref_names.h"
34 #include "components/password_manager/sync/browser/password_sync_util.h" 35 #include "components/password_manager/sync/browser/password_sync_util.h"
35 #include "components/prefs/pref_service.h" 36 #include "components/prefs/pref_service.h"
37 #include "content/public/browser/browser_thread.h"
36 #include "content/public/browser/user_metrics.h" 38 #include "content/public/browser/user_metrics.h"
37 #include "content/public/browser/web_contents.h" 39 #include "content/public/browser/web_contents.h"
38 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" 40 #include "net/base/registry_controlled_domains/registry_controlled_domain.h"
39 41
40 #if defined(OS_WIN) 42 #if defined(OS_WIN)
41 #include "chrome/browser/password_manager/password_manager_util_win.h" 43 #include "chrome/browser/password_manager/password_manager_util_win.h"
42 #elif defined(OS_MACOSX) 44 #elif defined(OS_MACOSX)
43 #include "chrome/browser/password_manager/password_manager_util_mac.h" 45 #include "chrome/browser/password_manager/password_manager_util_mac.h"
44 #endif 46 #endif
45 47
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 216
215 void PasswordManagerPresenter::RequestShowPassword(size_t index) { 217 void PasswordManagerPresenter::RequestShowPassword(size_t index) {
216 #if !defined(OS_ANDROID) // This is never called on Android. 218 #if !defined(OS_ANDROID) // This is never called on Android.
217 if (index >= password_list_.size()) { 219 if (index >= password_list_.size()) {
218 // |index| out of bounds might come from a compromised renderer 220 // |index| out of bounds might come from a compromised renderer
219 // (http://crbug.com/362054), or the user requested to show a password while 221 // (http://crbug.com/362054), or the user requested to show a password while
220 // a request to the store is in progress (i.e. |password_list_| 222 // a request to the store is in progress (i.e. |password_list_|
221 // is empty). Don't let it crash the browser. 223 // is empty). Don't let it crash the browser.
222 return; 224 return;
223 } 225 }
224 if ((base::TimeTicks::Now() - last_authentication_time_) > 226
225 base::TimeDelta::FromSeconds(60)) { 227 if (!IsUserAuthenticated()) {
226 bool authenticated = true; 228 return;
227 #if defined(OS_WIN)
228 authenticated = password_manager_util_win::AuthenticateUser(
229 password_view_->GetNativeWindow());
230 #elif defined(OS_MACOSX)
231 authenticated = password_manager_util_mac::AuthenticateUser();
232 #endif
233 if (authenticated)
234 last_authentication_time_ = base::TimeTicks::Now();
235 else
236 return;
237 } 229 }
238 230
239 sync_driver::SyncService* sync_service = nullptr; 231 sync_driver::SyncService* sync_service = nullptr;
240 if (ProfileSyncServiceFactory::HasProfileSyncService( 232 if (ProfileSyncServiceFactory::HasProfileSyncService(
241 password_view_->GetProfile())) { 233 password_view_->GetProfile())) {
242 sync_service = 234 sync_service =
243 ProfileSyncServiceFactory::GetForProfile(password_view_->GetProfile()); 235 ProfileSyncServiceFactory::GetForProfile(password_view_->GetProfile());
244 } 236 }
245 if (password_manager::sync_util::IsSyncAccountCredential( 237 if (password_manager::sync_util::IsSyncAccountCredential(
246 *password_list_[index], sync_service, 238 *password_list_[index], sync_service,
247 SigninManagerFactory::GetForProfile(password_view_->GetProfile()))) { 239 SigninManagerFactory::GetForProfile(password_view_->GetProfile()))) {
248 content::RecordAction( 240 content::RecordAction(
249 base::UserMetricsAction("PasswordManager_SyncCredentialShown")); 241 base::UserMetricsAction("PasswordManager_SyncCredentialShown"));
250 } 242 }
251 243
252 // Call back the front end to reveal the password. 244 // Call back the front end to reveal the password.
253 std::string origin_url = password_manager::GetHumanReadableOrigin( 245 std::string origin_url = password_manager::GetHumanReadableOrigin(
254 *password_list_[index]); 246 *password_list_[index]);
255 password_view_->ShowPassword( 247 password_view_->ShowPassword(
256 index, 248 index,
257 origin_url, 249 origin_url,
258 base::UTF16ToUTF8(password_list_[index]->username_value), 250 base::UTF16ToUTF8(password_list_[index]->username_value),
259 password_list_[index]->password_value); 251 password_list_[index]->password_value);
260 #endif 252 #endif
261 } 253 }
262 254
255 std::vector<scoped_ptr<autofill::PasswordForm>>
256 PasswordManagerPresenter::GetAllPasswords() {
257 std::vector<scoped_ptr<autofill::PasswordForm>> ret_val;
258
259 for (const auto& form : password_list_) {
260 ret_val.push_back(make_scoped_ptr(new autofill::PasswordForm(*form)));
261 }
262
263 return ret_val;
264 }
265
263 const autofill::PasswordForm* PasswordManagerPresenter::GetPassword( 266 const autofill::PasswordForm* PasswordManagerPresenter::GetPassword(
264 size_t index) { 267 size_t index) {
265 if (index >= password_list_.size()) { 268 if (index >= password_list_.size()) {
266 // |index| out of bounds might come from a compromised renderer 269 // |index| out of bounds might come from a compromised renderer
267 // (http://crbug.com/362054), or the user requested to get a password while 270 // (http://crbug.com/362054), or the user requested to get a password while
268 // a request to the store is in progress (i.e. |password_list_| 271 // a request to the store is in progress (i.e. |password_list_|
269 // is empty). Don't let it crash the browser. 272 // is empty). Don't let it crash the browser.
270 return NULL; 273 return NULL;
271 } 274 }
272 return password_list_[index].get(); 275 return password_list_[index].get();
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
315 for (auto& pair : pairs) { 318 for (auto& pair : pairs) {
316 if (pair.first != previous_key) { 319 if (pair.first != previous_key) {
317 list->push_back(std::move(pair.second)); 320 list->push_back(std::move(pair.second));
318 previous_key = pair.first; 321 previous_key = pair.first;
319 } else { 322 } else {
320 duplicates->insert(std::make_pair(previous_key, std::move(pair.second))); 323 duplicates->insert(std::make_pair(previous_key, std::move(pair.second)));
321 } 324 }
322 } 325 }
323 } 326 }
324 327
328 bool PasswordManagerPresenter::IsUserAuthenticated() {
329 #if defined(OS_ANDROID)
330 NOTREACHED();
331 #endif
332 if (base::TimeTicks::Now() - last_authentication_time_ >
333 base::TimeDelta::FromSeconds(60)) {
334 bool authenticated = true;
335 #if defined(OS_WIN)
336 authenticated = password_manager_util_win::AuthenticateUser(
337 password_view_->GetNativeWindow());
338 #elif defined(OS_MACOSX)
339 authenticated = password_manager_util_mac::AuthenticateUser();
340 #endif
341 if (authenticated)
342 last_authentication_time_ = base::TimeTicks::Now();
343 return authenticated;
344 }
345 return true;
346 }
347
325 PasswordManagerPresenter::ListPopulater::ListPopulater( 348 PasswordManagerPresenter::ListPopulater::ListPopulater(
326 PasswordManagerPresenter* page) : page_(page) { 349 PasswordManagerPresenter* page) : page_(page) {
327 } 350 }
328 351
329 PasswordManagerPresenter::ListPopulater::~ListPopulater() { 352 PasswordManagerPresenter::ListPopulater::~ListPopulater() {
330 } 353 }
331 354
332 PasswordManagerPresenter::PasswordListPopulater::PasswordListPopulater( 355 PasswordManagerPresenter::PasswordListPopulater::PasswordListPopulater(
333 PasswordManagerPresenter* page) : ListPopulater(page) { 356 PasswordManagerPresenter* page) : ListPopulater(page) {
334 } 357 }
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
370 393
371 void PasswordManagerPresenter::PasswordExceptionListPopulater:: 394 void PasswordManagerPresenter::PasswordExceptionListPopulater::
372 OnGetPasswordStoreResults(ScopedVector<autofill::PasswordForm> results) { 395 OnGetPasswordStoreResults(ScopedVector<autofill::PasswordForm> results) {
373 page_->password_exception_list_ = 396 page_->password_exception_list_ =
374 password_manager_util::ConvertScopedVector(std::move(results)); 397 password_manager_util::ConvertScopedVector(std::move(results));
375 page_->SortEntriesAndHideDuplicates(&page_->password_exception_list_, 398 page_->SortEntriesAndHideDuplicates(&page_->password_exception_list_,
376 &page_->password_exception_duplicates_, 399 &page_->password_exception_duplicates_,
377 false /* don't use username and password*/); 400 false /* don't use username and password*/);
378 page_->SetPasswordExceptionList(); 401 page_->SetPasswordExceptionList();
379 } 402 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698