OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/webui/options/password_manager_handler.h" | 5 #include "chrome/browser/ui/webui/options/password_manager_handler.h" |
6 | 6 |
7 #include "base/callback.h" | 7 #include "base/callback.h" |
8 #include "base/string_number_conversions.h" | 8 #include "base/string_number_conversions.h" |
9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
10 #include "base/values.h" | 10 #include "base/values.h" |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 RegisterStrings(localized_strings, resources, arraysize(resources)); | 69 RegisterStrings(localized_strings, resources, arraysize(resources)); |
70 RegisterTitle(localized_strings, "passwordsPage", | 70 RegisterTitle(localized_strings, "passwordsPage", |
71 IDS_PASSWORDS_EXCEPTIONS_WINDOW_TITLE); | 71 IDS_PASSWORDS_EXCEPTIONS_WINDOW_TITLE); |
72 | 72 |
73 localized_strings->SetString("passwordManagerLearnMoreURL", | 73 localized_strings->SetString("passwordManagerLearnMoreURL", |
74 google_util::AppendGoogleLocaleParam( | 74 google_util::AppendGoogleLocaleParam( |
75 GURL(chrome::kPasswordManagerLearnMoreURL)).spec()); | 75 GURL(chrome::kPasswordManagerLearnMoreURL)).spec()); |
76 } | 76 } |
77 | 77 |
78 void PasswordManagerHandler::Initialize() { | 78 void PasswordManagerHandler::Initialize() { |
| 79 // Due to the way that handlers are (re)initialized under certain types of |
| 80 // navigation, we may already be initialized. (See bugs 88986 and 86448.) |
| 81 // If this is the case, return immediately. This is a hack. |
| 82 // TODO(mdm): remove this hack once it is no longer necessary. |
| 83 if (!show_passwords_.GetPrefName().empty()) |
| 84 return; |
| 85 |
79 show_passwords_.Init(prefs::kPasswordManagerAllowShowPasswords, | 86 show_passwords_.Init(prefs::kPasswordManagerAllowShowPasswords, |
80 web_ui_->GetProfile()->GetPrefs(), this); | 87 web_ui_->GetProfile()->GetPrefs(), this); |
81 // We should not cache web_ui_->GetProfile(). See crosbug.com/6304. | 88 // We should not cache web_ui_->GetProfile(). See crosbug.com/6304. |
82 PasswordStore* store = GetPasswordStore(); | 89 PasswordStore* store = GetPasswordStore(); |
83 if (store) | 90 if (store) |
84 store->AddObserver(this); | 91 store->AddObserver(this); |
85 } | 92 } |
86 | 93 |
87 void PasswordManagerHandler::RegisterMessages() { | 94 void PasswordManagerHandler::RegisterMessages() { |
88 DCHECK(web_ui_); | 95 DCHECK(web_ui_); |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 void PasswordManagerHandler::RemoveAllPasswordExceptions( | 175 void PasswordManagerHandler::RemoveAllPasswordExceptions( |
169 const ListValue* args) { | 176 const ListValue* args) { |
170 PasswordStore* store = GetPasswordStore(); | 177 PasswordStore* store = GetPasswordStore(); |
171 if (!store) | 178 if (!store) |
172 return; | 179 return; |
173 for (size_t i = 0; i < password_exception_list_.size(); ++i) | 180 for (size_t i = 0; i < password_exception_list_.size(); ++i) |
174 store->RemoveLogin(*password_exception_list_[i]); | 181 store->RemoveLogin(*password_exception_list_[i]); |
175 } | 182 } |
176 | 183 |
177 void PasswordManagerHandler::SetPasswordList() { | 184 void PasswordManagerHandler::SetPasswordList() { |
| 185 // Due to the way that handlers are (re)initialized under certain types of |
| 186 // navigation, we may not be initialized yet. (See bugs 88986 and 86448.) |
| 187 // If this is the case, initialize on demand. This is a hack. |
| 188 // TODO(mdm): remove this hack once it is no longer necessary. |
| 189 if (show_passwords_.GetPrefName().empty()) |
| 190 Initialize(); |
| 191 |
178 ListValue entries; | 192 ListValue entries; |
179 bool show_passwords = *show_passwords_; | 193 bool show_passwords = *show_passwords_; |
180 string16 empty; | 194 string16 empty; |
181 for (size_t i = 0; i < password_list_.size(); ++i) { | 195 for (size_t i = 0; i < password_list_.size(); ++i) { |
182 ListValue* entry = new ListValue(); | 196 ListValue* entry = new ListValue(); |
183 entry->Append(new StringValue(net::FormatUrl(password_list_[i]->origin, | 197 entry->Append(new StringValue(net::FormatUrl(password_list_[i]->origin, |
184 languages_))); | 198 languages_))); |
185 entry->Append(new StringValue(password_list_[i]->username_value)); | 199 entry->Append(new StringValue(password_list_[i]->username_value)); |
186 entry->Append(new StringValue( | 200 entry->Append(new StringValue( |
187 show_passwords ? password_list_[i]->password_value : empty)); | 201 show_passwords ? password_list_[i]->password_value : empty)); |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
261 OnPasswordStoreRequestDone( | 275 OnPasswordStoreRequestDone( |
262 CancelableRequestProvider::Handle handle, | 276 CancelableRequestProvider::Handle handle, |
263 const std::vector<webkit_glue::PasswordForm*>& result) { | 277 const std::vector<webkit_glue::PasswordForm*>& result) { |
264 DCHECK_EQ(pending_login_query_, handle); | 278 DCHECK_EQ(pending_login_query_, handle); |
265 pending_login_query_ = 0; | 279 pending_login_query_ = 0; |
266 page_->password_exception_list_.reset(); | 280 page_->password_exception_list_.reset(); |
267 page_->password_exception_list_.insert(page_->password_exception_list_.end(), | 281 page_->password_exception_list_.insert(page_->password_exception_list_.end(), |
268 result.begin(), result.end()); | 282 result.begin(), result.end()); |
269 page_->SetPasswordExceptionList(); | 283 page_->SetPasswordExceptionList(); |
270 } | 284 } |
OLD | NEW |