Chromium Code Reviews| 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" |
| 11 #include "chrome/browser/google/google_util.h" | 11 #include "chrome/browser/google/google_util.h" |
| 12 #include "chrome/browser/prefs/pref_service.h" | 12 #include "chrome/browser/prefs/pref_service.h" |
| 13 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
| 14 #include "chrome/common/pref_names.h" | 14 #include "chrome/common/pref_names.h" |
| 15 #include "chrome/common/url_constants.h" | 15 #include "chrome/common/url_constants.h" |
| 16 #include "content/common/notification_details.h" | 16 #include "content/common/notification_details.h" |
| 17 #include "content/common/notification_source.h" | 17 #include "content/common/notification_source.h" |
| 18 #include "grit/chromium_strings.h" | 18 #include "grit/chromium_strings.h" |
| 19 #include "grit/generated_resources.h" | 19 #include "grit/generated_resources.h" |
| 20 #include "net/base/net_util.h" | 20 #include "net/base/net_util.h" |
| 21 #include "ui/base/l10n/l10n_util.h" | 21 #include "ui/base/l10n/l10n_util.h" |
| 22 #include "webkit/glue/password_form.h" | 22 #include "webkit/glue/password_form.h" |
| 23 | 23 |
| 24 PasswordManagerHandler::PasswordManagerHandler() | 24 PasswordManagerHandler::PasswordManagerHandler() |
| 25 : ALLOW_THIS_IN_INITIALIZER_LIST(populater_(this)), | 25 : ALLOW_THIS_IN_INITIALIZER_LIST(populater_(this)), |
| 26 ALLOW_THIS_IN_INITIALIZER_LIST(exception_populater_(this)) { | 26 ALLOW_THIS_IN_INITIALIZER_LIST(exception_populater_(this)) { |
| 27 } | 27 } |
| 28 | 28 |
| 29 PasswordManagerHandler::~PasswordManagerHandler() { | 29 PasswordManagerHandler::~PasswordManagerHandler() { |
| 30 GetPasswordStore()->RemoveObserver(this); | 30 PasswordStore* store = GetPasswordStore(); |
| 31 if (store) | |
| 32 store->RemoveObserver(this); | |
| 31 } | 33 } |
| 32 | 34 |
| 33 void PasswordManagerHandler::GetLocalizedValues( | 35 void PasswordManagerHandler::GetLocalizedValues( |
| 34 DictionaryValue* localized_strings) { | 36 DictionaryValue* localized_strings) { |
| 35 DCHECK(localized_strings); | 37 DCHECK(localized_strings); |
| 36 | 38 |
| 37 static const OptionsStringResource resources[] = { | 39 static const OptionsStringResource resources[] = { |
| 38 { "savedPasswordsTitle", | 40 { "savedPasswordsTitle", |
| 39 IDS_PASSWORDS_SHOW_PASSWORDS_TAB_TITLE }, | 41 IDS_PASSWORDS_SHOW_PASSWORDS_TAB_TITLE }, |
| 40 { "passwordExceptionsTitle", | 42 { "passwordExceptionsTitle", |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 67 | 69 |
| 68 localized_strings->SetString("passwordManagerLearnMoreURL", | 70 localized_strings->SetString("passwordManagerLearnMoreURL", |
| 69 google_util::AppendGoogleLocaleParam( | 71 google_util::AppendGoogleLocaleParam( |
| 70 GURL(chrome::kPasswordManagerLearnMoreURL)).spec()); | 72 GURL(chrome::kPasswordManagerLearnMoreURL)).spec()); |
| 71 } | 73 } |
| 72 | 74 |
| 73 void PasswordManagerHandler::Initialize() { | 75 void PasswordManagerHandler::Initialize() { |
| 74 show_passwords_.Init(prefs::kPasswordManagerAllowShowPasswords, | 76 show_passwords_.Init(prefs::kPasswordManagerAllowShowPasswords, |
| 75 web_ui_->GetProfile()->GetPrefs(), this); | 77 web_ui_->GetProfile()->GetPrefs(), this); |
| 76 // We should not cache web_ui_->GetProfile(). See crosbug.com/6304. | 78 // We should not cache web_ui_->GetProfile(). See crosbug.com/6304. |
| 77 GetPasswordStore()->AddObserver(this); | 79 PasswordStore* store = GetPasswordStore(); |
| 80 if (store) | |
| 81 store->AddObserver(this); | |
| 82 else | |
| 83 NOTREACHED(); | |
|
James Hawkins
2011/05/18 17:52:27
I'm not a fan of the NOTREACHEDs. This will not hi
| |
| 78 } | 84 } |
| 79 | 85 |
| 80 void PasswordManagerHandler::RegisterMessages() { | 86 void PasswordManagerHandler::RegisterMessages() { |
| 81 DCHECK(web_ui_); | 87 DCHECK(web_ui_); |
| 82 | 88 |
| 83 web_ui_->RegisterMessageCallback("updatePasswordLists", | 89 web_ui_->RegisterMessageCallback("updatePasswordLists", |
| 84 NewCallback(this, &PasswordManagerHandler::UpdatePasswordLists)); | 90 NewCallback(this, &PasswordManagerHandler::UpdatePasswordLists)); |
| 85 web_ui_->RegisterMessageCallback("removeSavedPassword", | 91 web_ui_->RegisterMessageCallback("removeSavedPassword", |
| 86 NewCallback(this, &PasswordManagerHandler::RemoveSavedPassword)); | 92 NewCallback(this, &PasswordManagerHandler::RemoveSavedPassword)); |
| 87 web_ui_->RegisterMessageCallback("removePasswordException", | 93 web_ui_->RegisterMessageCallback("removePasswordException", |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 118 password_list_.reset(); | 124 password_list_.reset(); |
| 119 password_exception_list_.reset(); | 125 password_exception_list_.reset(); |
| 120 | 126 |
| 121 languages_ = | 127 languages_ = |
| 122 web_ui_->GetProfile()->GetPrefs()->GetString(prefs::kAcceptLanguages); | 128 web_ui_->GetProfile()->GetPrefs()->GetString(prefs::kAcceptLanguages); |
| 123 populater_.Populate(); | 129 populater_.Populate(); |
| 124 exception_populater_.Populate(); | 130 exception_populater_.Populate(); |
| 125 } | 131 } |
| 126 | 132 |
| 127 void PasswordManagerHandler::RemoveSavedPassword(const ListValue* args) { | 133 void PasswordManagerHandler::RemoveSavedPassword(const ListValue* args) { |
| 134 PasswordStore* store = GetPasswordStore(); | |
| 135 if (!store) { | |
| 136 NOTREACHED(); | |
| 137 return; | |
| 138 } | |
| 128 std::string string_value = UTF16ToUTF8(ExtractStringValue(args)); | 139 std::string string_value = UTF16ToUTF8(ExtractStringValue(args)); |
| 129 int index; | 140 int index; |
| 130 base::StringToInt(string_value, &index); | 141 base::StringToInt(string_value, &index); |
| 131 GetPasswordStore()->RemoveLogin(*password_list_[index]); | 142 store->RemoveLogin(*password_list_[index]); |
| 132 } | 143 } |
| 133 | 144 |
| 134 void PasswordManagerHandler::RemovePasswordException( | 145 void PasswordManagerHandler::RemovePasswordException( |
| 135 const ListValue* args) { | 146 const ListValue* args) { |
| 147 PasswordStore* store = GetPasswordStore(); | |
| 148 if (!store) { | |
| 149 NOTREACHED(); | |
| 150 return; | |
| 151 } | |
| 136 std::string string_value = UTF16ToUTF8(ExtractStringValue(args)); | 152 std::string string_value = UTF16ToUTF8(ExtractStringValue(args)); |
| 137 int index; | 153 int index; |
| 138 base::StringToInt(string_value, &index); | 154 base::StringToInt(string_value, &index); |
| 139 | 155 |
| 140 GetPasswordStore()->RemoveLogin(*password_exception_list_[index]); | 156 store->RemoveLogin(*password_exception_list_[index]); |
| 141 } | 157 } |
| 142 | 158 |
| 143 void PasswordManagerHandler::RemoveAllSavedPasswords( | 159 void PasswordManagerHandler::RemoveAllSavedPasswords( |
| 144 const ListValue* args) { | 160 const ListValue* args) { |
| 145 // TODO(jhawkins): This will cause a list refresh for every password in the | 161 // TODO(jhawkins): This will cause a list refresh for every password in the |
| 146 // list. Add PasswordStore::RemoveAllLogins(). | 162 // list. Add PasswordStore::RemoveAllLogins(). |
| 147 PasswordStore* store = GetPasswordStore(); | 163 PasswordStore* store = GetPasswordStore(); |
| 164 if (!store) { | |
| 165 NOTREACHED(); | |
| 166 return; | |
| 167 } | |
| 148 for (size_t i = 0; i < password_list_.size(); ++i) | 168 for (size_t i = 0; i < password_list_.size(); ++i) |
| 149 store->RemoveLogin(*password_list_[i]); | 169 store->RemoveLogin(*password_list_[i]); |
| 150 } | 170 } |
| 151 | 171 |
| 152 void PasswordManagerHandler::RemoveAllPasswordExceptions( | 172 void PasswordManagerHandler::RemoveAllPasswordExceptions( |
| 153 const ListValue* args) { | 173 const ListValue* args) { |
| 154 PasswordStore* store = GetPasswordStore(); | 174 PasswordStore* store = GetPasswordStore(); |
| 175 if (!store) { | |
| 176 NOTREACHED(); | |
| 177 return; | |
| 178 } | |
| 155 for (size_t i = 0; i < password_exception_list_.size(); ++i) | 179 for (size_t i = 0; i < password_exception_list_.size(); ++i) |
| 156 store->RemoveLogin(*password_exception_list_[i]); | 180 store->RemoveLogin(*password_exception_list_[i]); |
| 157 } | 181 } |
| 158 | 182 |
| 159 void PasswordManagerHandler::SetPasswordList() { | 183 void PasswordManagerHandler::SetPasswordList() { |
| 160 ListValue entries; | 184 ListValue entries; |
| 161 bool show_passwords = *show_passwords_; | 185 bool show_passwords = *show_passwords_; |
| 162 string16 empty; | 186 string16 empty; |
| 163 for (size_t i = 0; i < password_list_.size(); ++i) { | 187 for (size_t i = 0; i < password_list_.size(); ++i) { |
| 164 ListValue* entry = new ListValue(); | 188 ListValue* entry = new ListValue(); |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 243 OnPasswordStoreRequestDone( | 267 OnPasswordStoreRequestDone( |
| 244 CancelableRequestProvider::Handle handle, | 268 CancelableRequestProvider::Handle handle, |
| 245 const std::vector<webkit_glue::PasswordForm*>& result) { | 269 const std::vector<webkit_glue::PasswordForm*>& result) { |
| 246 DCHECK_EQ(pending_login_query_, handle); | 270 DCHECK_EQ(pending_login_query_, handle); |
| 247 pending_login_query_ = 0; | 271 pending_login_query_ = 0; |
| 248 page_->password_exception_list_.reset(); | 272 page_->password_exception_list_.reset(); |
| 249 page_->password_exception_list_.insert(page_->password_exception_list_.end(), | 273 page_->password_exception_list_.insert(page_->password_exception_list_.end(), |
| 250 result.begin(), result.end()); | 274 result.begin(), result.end()); |
| 251 page_->SetPasswordExceptionList(); | 275 page_->SetPasswordExceptionList(); |
| 252 } | 276 } |
| OLD | NEW |