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