OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/extensions/api/passwords_private/passwords_private_dele
gate_impl.h" | 5 #include "chrome/browser/extensions/api/passwords_private/passwords_private_dele
gate_impl.h" |
6 | 6 |
7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
8 #include "build/build_config.h" | 8 #include "build/build_config.h" |
9 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
10 #include "chrome/browser/ui/passwords/manage_passwords_view_utils.h" | 10 #include "chrome/browser/ui/passwords/manage_passwords_view_utils.h" |
(...skipping 15 matching lines...) Expand all Loading... |
26 } | 26 } |
27 | 27 |
28 namespace extensions { | 28 namespace extensions { |
29 | 29 |
30 PasswordsPrivateDelegateImpl::PasswordsPrivateDelegateImpl(Profile* profile) | 30 PasswordsPrivateDelegateImpl::PasswordsPrivateDelegateImpl(Profile* profile) |
31 : profile_(profile), | 31 : profile_(profile), |
32 password_manager_presenter_(new PasswordManagerPresenter(this)), | 32 password_manager_presenter_(new PasswordManagerPresenter(this)), |
33 set_password_list_called_(false), | 33 set_password_list_called_(false), |
34 set_password_exception_list_called_(false), | 34 set_password_exception_list_called_(false), |
35 is_initialized_(false), | 35 is_initialized_(false), |
36 languages_(profile->GetPrefs()->GetString(prefs::kAcceptLanguages)), | |
37 web_contents_(nullptr) { | 36 web_contents_(nullptr) { |
38 password_manager_presenter_->Initialize(); | 37 password_manager_presenter_->Initialize(); |
39 password_manager_presenter_->UpdatePasswordLists(); | 38 password_manager_presenter_->UpdatePasswordLists(); |
40 } | 39 } |
41 | 40 |
42 PasswordsPrivateDelegateImpl::~PasswordsPrivateDelegateImpl() {} | 41 PasswordsPrivateDelegateImpl::~PasswordsPrivateDelegateImpl() {} |
43 | 42 |
44 void PasswordsPrivateDelegateImpl::AddObserver(Observer* observer) { | 43 void PasswordsPrivateDelegateImpl::AddObserver(Observer* observer) { |
45 observers_.AddObserver(observer); | 44 observers_.AddObserver(observer); |
46 | 45 |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 base::UTF16ToUTF8(password_value))); | 144 base::UTF16ToUTF8(password_value))); |
146 } | 145 } |
147 | 146 |
148 void PasswordsPrivateDelegateImpl::SetPasswordList( | 147 void PasswordsPrivateDelegateImpl::SetPasswordList( |
149 const std::vector<scoped_ptr<autofill::PasswordForm>>& password_list) { | 148 const std::vector<scoped_ptr<autofill::PasswordForm>>& password_list) { |
150 // Rebuild |login_pair_to_index_map_| so that it reflects the contents of the | 149 // Rebuild |login_pair_to_index_map_| so that it reflects the contents of the |
151 // new list. | 150 // new list. |
152 login_pair_to_index_map_.clear(); | 151 login_pair_to_index_map_.clear(); |
153 for (size_t i = 0; i < password_list.size(); i++) { | 152 for (size_t i = 0; i < password_list.size(); i++) { |
154 std::string key = LoginPairToMapKey( | 153 std::string key = LoginPairToMapKey( |
155 password_manager::GetHumanReadableOrigin(*password_list[i], languages_), | 154 password_manager::GetHumanReadableOrigin(*password_list[i]), |
156 base::UTF16ToUTF8(password_list[i]->username_value)); | 155 base::UTF16ToUTF8(password_list[i]->username_value)); |
157 login_pair_to_index_map_[key] = i; | 156 login_pair_to_index_map_[key] = i; |
158 } | 157 } |
159 | 158 |
160 // Now, create a list of PasswordUiEntry objects to send to observers. | 159 // Now, create a list of PasswordUiEntry objects to send to observers. |
161 current_entries_.clear(); | 160 current_entries_.clear(); |
162 for (const auto& form : password_list) { | 161 for (const auto& form : password_list) { |
163 api::passwords_private::PasswordUiEntry entry; | 162 api::passwords_private::PasswordUiEntry entry; |
164 entry.login_pair.origin_url = | 163 entry.login_pair.origin_url = |
165 password_manager::GetHumanReadableOrigin(*form, languages_); | 164 password_manager::GetHumanReadableOrigin(*form); |
166 entry.login_pair.username = base::UTF16ToUTF8(form->username_value); | 165 entry.login_pair.username = base::UTF16ToUTF8(form->username_value); |
167 entry.num_characters_in_password = form->password_value.length(); | 166 entry.num_characters_in_password = form->password_value.length(); |
168 | 167 |
169 if (!form->federation_origin.unique()) { | 168 if (!form->federation_origin.unique()) { |
170 entry.federation_text.reset(new std::string(l10n_util::GetStringFUTF8( | 169 entry.federation_text.reset(new std::string(l10n_util::GetStringFUTF8( |
171 IDS_PASSWORDS_VIA_FEDERATION, | 170 IDS_PASSWORDS_VIA_FEDERATION, |
172 base::UTF8ToUTF16(form->federation_origin.host())))); | 171 base::UTF8ToUTF16(form->federation_origin.host())))); |
173 } | 172 } |
174 | 173 |
175 current_entries_.push_back(std::move(entry)); | 174 current_entries_.push_back(std::move(entry)); |
(...skipping 11 matching lines...) Expand all Loading... |
187 } | 186 } |
188 | 187 |
189 void PasswordsPrivateDelegateImpl::SetPasswordExceptionList( | 188 void PasswordsPrivateDelegateImpl::SetPasswordExceptionList( |
190 const std::vector<scoped_ptr<autofill::PasswordForm>>& | 189 const std::vector<scoped_ptr<autofill::PasswordForm>>& |
191 password_exception_list) { | 190 password_exception_list) { |
192 // Rebuild |exception_url_to_index_map_| so that it reflects the contents of | 191 // Rebuild |exception_url_to_index_map_| so that it reflects the contents of |
193 // the new list. | 192 // the new list. |
194 exception_url_to_index_map_.clear(); | 193 exception_url_to_index_map_.clear(); |
195 for (size_t i = 0; i < password_exception_list.size(); i++) { | 194 for (size_t i = 0; i < password_exception_list.size(); i++) { |
196 std::string key = password_manager::GetHumanReadableOrigin( | 195 std::string key = password_manager::GetHumanReadableOrigin( |
197 *password_exception_list[i], languages_); | 196 *password_exception_list[i]); |
198 exception_url_to_index_map_[key] = i; | 197 exception_url_to_index_map_[key] = i; |
199 } | 198 } |
200 | 199 |
201 // Now, create a list of exceptions to send to observers. | 200 // Now, create a list of exceptions to send to observers. |
202 current_exceptions_.clear(); | 201 current_exceptions_.clear(); |
203 for (const auto& form : password_exception_list) { | 202 for (const auto& form : password_exception_list) { |
204 current_exceptions_.push_back( | 203 current_exceptions_.push_back( |
205 password_manager::GetHumanReadableOrigin(*form, languages_)); | 204 password_manager::GetHumanReadableOrigin(*form)); |
206 } | 205 } |
207 | 206 |
208 SendPasswordExceptionsList(); | 207 SendPasswordExceptionsList(); |
209 | 208 |
210 set_password_exception_list_called_ = true; | 209 set_password_exception_list_called_ = true; |
211 InitializeIfNecessary(); | 210 InitializeIfNecessary(); |
212 } | 211 } |
213 | 212 |
214 void PasswordsPrivateDelegateImpl::SendPasswordExceptionsList() { | 213 void PasswordsPrivateDelegateImpl::SendPasswordExceptionsList() { |
215 FOR_EACH_OBSERVER( | 214 FOR_EACH_OBSERVER( |
(...skipping 29 matching lines...) Expand all Loading... |
245 return; | 244 return; |
246 | 245 |
247 is_initialized_ = true; | 246 is_initialized_ = true; |
248 | 247 |
249 for (const base::Callback<void()>& callback : pre_initialization_callbacks_) { | 248 for (const base::Callback<void()>& callback : pre_initialization_callbacks_) { |
250 callback.Run(); | 249 callback.Run(); |
251 } | 250 } |
252 } | 251 } |
253 | 252 |
254 } // namespace extensions | 253 } // namespace extensions |
OLD | NEW |