| OLD | NEW |
| 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 "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/metrics/user_metrics_action.h" | 9 #include "base/metrics/user_metrics_action.h" |
| 10 #include "base/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
| 11 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
| 12 #include "base/time/time.h" | 12 #include "base/time/time.h" |
| 13 #include "base/values.h" | 13 #include "base/values.h" |
| 14 #include "chrome/browser/password_manager/password_store_factory.h" | 14 #include "chrome/browser/password_manager/password_store_factory.h" |
| 15 #include "chrome/browser/password_manager/sync_metrics.h" | 15 #include "chrome/browser/password_manager/sync_metrics.h" |
| 16 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
| 17 #include "chrome/browser/ui/passwords/manage_passwords_view_utils.h" |
| 17 #include "chrome/browser/ui/passwords/password_ui_view.h" | 18 #include "chrome/browser/ui/passwords/password_ui_view.h" |
| 18 #include "chrome/common/chrome_switches.h" | 19 #include "chrome/common/chrome_switches.h" |
| 20 #include "chrome/common/pref_names.h" |
| 19 #include "chrome/common/url_constants.h" | 21 #include "chrome/common/url_constants.h" |
| 20 #include "components/autofill/core/common/password_form.h" | 22 #include "components/autofill/core/common/password_form.h" |
| 21 #include "components/password_manager/core/browser/password_manager_util.h" | 23 #include "components/password_manager/core/browser/password_manager_util.h" |
| 22 #include "components/password_manager/core/common/password_manager_pref_names.h" | 24 #include "components/password_manager/core/common/password_manager_pref_names.h" |
| 23 #include "content/public/browser/user_metrics.h" | 25 #include "content/public/browser/user_metrics.h" |
| 24 #include "content/public/browser/web_contents.h" | 26 #include "content/public/browser/web_contents.h" |
| 25 | 27 |
| 26 using password_manager::PasswordStore; | 28 using password_manager::PasswordStore; |
| 27 | 29 |
| 28 PasswordManagerPresenter::PasswordManagerPresenter( | 30 PasswordManagerPresenter::PasswordManagerPresenter( |
| (...skipping 24 matching lines...) Expand all Loading... |
| 53 show_passwords_.Init( | 55 show_passwords_.Init( |
| 54 password_manager::prefs::kPasswordManagerAllowShowPasswords, | 56 password_manager::prefs::kPasswordManagerAllowShowPasswords, |
| 55 password_view_->GetProfile()->GetPrefs(), | 57 password_view_->GetProfile()->GetPrefs(), |
| 56 base::Bind(&PasswordManagerPresenter::UpdatePasswordLists, | 58 base::Bind(&PasswordManagerPresenter::UpdatePasswordLists, |
| 57 base::Unretained(this))); | 59 base::Unretained(this))); |
| 58 // TODO(jhawkins) We should not cache web_ui()->GetProfile().See | 60 // TODO(jhawkins) We should not cache web_ui()->GetProfile().See |
| 59 // crosbug.com/6304. | 61 // crosbug.com/6304. |
| 60 PasswordStore* store = GetPasswordStore(); | 62 PasswordStore* store = GetPasswordStore(); |
| 61 if (store) | 63 if (store) |
| 62 store->AddObserver(this); | 64 store->AddObserver(this); |
| 65 |
| 66 languages_ = password_view_->GetProfile()->GetPrefs()-> |
| 67 GetString(prefs::kAcceptLanguages); |
| 63 } | 68 } |
| 64 | 69 |
| 65 void PasswordManagerPresenter::OnLoginsChanged( | 70 void PasswordManagerPresenter::OnLoginsChanged( |
| 66 const password_manager::PasswordStoreChangeList& changes) { | 71 const password_manager::PasswordStoreChangeList& changes) { |
| 67 // Entire list is updated for convenience. | 72 // Entire list is updated for convenience. |
| 68 UpdatePasswordLists(); | 73 UpdatePasswordLists(); |
| 69 } | 74 } |
| 70 | 75 |
| 71 PasswordStore* PasswordManagerPresenter::GetPasswordStore() { | 76 PasswordStore* PasswordManagerPresenter::GetPasswordStore() { |
| 72 return PasswordStoreFactory::GetForProfile(password_view_->GetProfile(), | 77 return PasswordStoreFactory::GetForProfile(password_view_->GetProfile(), |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 | 139 |
| 135 if (password_manager_sync_metrics::IsSyncAccountCredential( | 140 if (password_manager_sync_metrics::IsSyncAccountCredential( |
| 136 password_view_->GetProfile(), | 141 password_view_->GetProfile(), |
| 137 base::UTF16ToUTF8(password_list_[index]->username_value), | 142 base::UTF16ToUTF8(password_list_[index]->username_value), |
| 138 password_list_[index]->signon_realm)) { | 143 password_list_[index]->signon_realm)) { |
| 139 content::RecordAction( | 144 content::RecordAction( |
| 140 base::UserMetricsAction("PasswordManager_SyncCredentialShown")); | 145 base::UserMetricsAction("PasswordManager_SyncCredentialShown")); |
| 141 } | 146 } |
| 142 | 147 |
| 143 // Call back the front end to reveal the password. | 148 // Call back the front end to reveal the password. |
| 144 password_view_->ShowPassword(index, password_list_[index]->password_value); | 149 std::string origin_url = |
| 150 GetHumanReadableOrigin(*password_list_[index], languages_); |
| 151 password_view_->ShowPassword( |
| 152 index, |
| 153 origin_url, |
| 154 base::UTF16ToUTF8(password_list_[index]->username_value), |
| 155 password_list_[index]->password_value); |
| 145 #endif | 156 #endif |
| 146 } | 157 } |
| 147 | 158 |
| 148 const autofill::PasswordForm* PasswordManagerPresenter::GetPassword( | 159 const autofill::PasswordForm* PasswordManagerPresenter::GetPassword( |
| 149 size_t index) { | 160 size_t index) { |
| 150 if (index >= password_list_.size()) { | 161 if (index >= password_list_.size()) { |
| 151 // |index| out of bounds might come from a compromised renderer, don't let | 162 // |index| out of bounds might come from a compromised renderer, don't let |
| 152 // it crash the browser. http://crbug.com/362054 | 163 // it crash the browser. http://crbug.com/362054 |
| 153 NOTREACHED(); | 164 NOTREACHED(); |
| 154 return NULL; | 165 return NULL; |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 230 } else { | 241 } else { |
| 231 LOG(ERROR) << "No password store! Cannot display exceptions."; | 242 LOG(ERROR) << "No password store! Cannot display exceptions."; |
| 232 } | 243 } |
| 233 } | 244 } |
| 234 | 245 |
| 235 void PasswordManagerPresenter::PasswordExceptionListPopulater:: | 246 void PasswordManagerPresenter::PasswordExceptionListPopulater:: |
| 236 OnGetPasswordStoreResults(ScopedVector<autofill::PasswordForm> results) { | 247 OnGetPasswordStoreResults(ScopedVector<autofill::PasswordForm> results) { |
| 237 page_->password_exception_list_.swap(results); | 248 page_->password_exception_list_.swap(results); |
| 238 page_->SetPasswordExceptionList(); | 249 page_->SetPasswordExceptionList(); |
| 239 } | 250 } |
| OLD | NEW |