 Chromium Code Reviews
 Chromium Code Reviews Issue 6770012:
  Handle the PasswordManagerAllowShowPasswords preference in the options webui.  (Closed) 
  Base URL: svn://svn.chromium.org/chrome/trunk/src
    
  
    Issue 6770012:
  Handle the PasswordManagerAllowShowPasswords preference in the options webui.  (Closed) 
  Base URL: svn://svn.chromium.org/chrome/trunk/src| 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" | |
| 17 #include "content/common/notification_source.h" | |
| 16 #include "grit/chromium_strings.h" | 18 #include "grit/chromium_strings.h" | 
| 17 #include "grit/generated_resources.h" | 19 #include "grit/generated_resources.h" | 
| 18 #include "net/base/net_util.h" | 20 #include "net/base/net_util.h" | 
| 19 #include "ui/base/l10n/l10n_util.h" | 21 #include "ui/base/l10n/l10n_util.h" | 
| 20 #include "webkit/glue/password_form.h" | 22 #include "webkit/glue/password_form.h" | 
| 21 | 23 | 
| 22 PasswordManagerHandler::PasswordManagerHandler() | 24 PasswordManagerHandler::PasswordManagerHandler() | 
| 23 : ALLOW_THIS_IN_INITIALIZER_LIST(populater_(this)), | 25 : ALLOW_THIS_IN_INITIALIZER_LIST(populater_(this)), | 
| 24 ALLOW_THIS_IN_INITIALIZER_LIST(exception_populater_(this)) { | 26 ALLOW_THIS_IN_INITIALIZER_LIST(exception_populater_(this)) { | 
| 25 } | 27 } | 
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 62 RegisterStrings(localized_strings, resources, arraysize(resources)); | 64 RegisterStrings(localized_strings, resources, arraysize(resources)); | 
| 63 RegisterTitle(localized_strings, "passwordsPage", | 65 RegisterTitle(localized_strings, "passwordsPage", | 
| 64 IDS_PASSWORDS_EXCEPTIONS_WINDOW_TITLE); | 66 IDS_PASSWORDS_EXCEPTIONS_WINDOW_TITLE); | 
| 65 | 67 | 
| 66 localized_strings->SetString("passwordManagerLearnMoreURL", | 68 localized_strings->SetString("passwordManagerLearnMoreURL", | 
| 67 google_util::AppendGoogleLocaleParam( | 69 google_util::AppendGoogleLocaleParam( | 
| 68 GURL(chrome::kPasswordManagerLearnMoreURL)).spec()); | 70 GURL(chrome::kPasswordManagerLearnMoreURL)).spec()); | 
| 69 } | 71 } | 
| 70 | 72 | 
| 71 void PasswordManagerHandler::Initialize() { | 73 void PasswordManagerHandler::Initialize() { | 
| 74 show_passwords_.Init(prefs::kPasswordManagerAllowShowPasswords, | |
| 75 web_ui_->GetProfile()->GetPrefs(), this); | |
| 72 // We should not cache web_ui_->GetProfile(). See crosbug.com/6304. | 76 // We should not cache web_ui_->GetProfile(). See crosbug.com/6304. | 
| 73 GetPasswordStore()->AddObserver(this); | 77 GetPasswordStore()->AddObserver(this); | 
| 74 } | 78 } | 
| 75 | 79 | 
| 76 void PasswordManagerHandler::RegisterMessages() { | 80 void PasswordManagerHandler::RegisterMessages() { | 
| 77 DCHECK(web_ui_); | 81 DCHECK(web_ui_); | 
| 78 | 82 | 
| 79 web_ui_->RegisterMessageCallback("updatePasswordLists", | 83 web_ui_->RegisterMessageCallback("updatePasswordLists", | 
| 80 NewCallback(this, &PasswordManagerHandler::UpdatePasswordLists)); | 84 NewCallback(this, &PasswordManagerHandler::UpdatePasswordLists)); | 
| 81 web_ui_->RegisterMessageCallback("removeSavedPassword", | 85 web_ui_->RegisterMessageCallback("removeSavedPassword", | 
| 82 NewCallback(this, &PasswordManagerHandler::RemoveSavedPassword)); | 86 NewCallback(this, &PasswordManagerHandler::RemoveSavedPassword)); | 
| 83 web_ui_->RegisterMessageCallback("removePasswordException", | 87 web_ui_->RegisterMessageCallback("removePasswordException", | 
| 84 NewCallback(this, &PasswordManagerHandler::RemovePasswordException)); | 88 NewCallback(this, &PasswordManagerHandler::RemovePasswordException)); | 
| 85 web_ui_->RegisterMessageCallback("removeAllSavedPasswords", | 89 web_ui_->RegisterMessageCallback("removeAllSavedPasswords", | 
| 86 NewCallback(this, &PasswordManagerHandler::RemoveAllSavedPasswords)); | 90 NewCallback(this, &PasswordManagerHandler::RemoveAllSavedPasswords)); | 
| 87 web_ui_->RegisterMessageCallback("removeAllPasswordExceptions", NewCallback( | 91 web_ui_->RegisterMessageCallback("removeAllPasswordExceptions", NewCallback( | 
| 88 this, &PasswordManagerHandler::RemoveAllPasswordExceptions)); | 92 this, &PasswordManagerHandler::RemoveAllPasswordExceptions)); | 
| 89 } | 93 } | 
| 90 | 94 | 
| 91 void PasswordManagerHandler::OnLoginsChanged() { | 95 void PasswordManagerHandler::OnLoginsChanged() { | 
| 92 UpdatePasswordLists(NULL); | 96 UpdatePasswordLists(NULL); | 
| 93 } | 97 } | 
| 94 | 98 | 
| 95 PasswordStore* PasswordManagerHandler::GetPasswordStore() { | 99 PasswordStore* PasswordManagerHandler::GetPasswordStore() { | 
| 96 return web_ui_->GetProfile()->GetPasswordStore(Profile::EXPLICIT_ACCESS); | 100 return web_ui_->GetProfile()->GetPasswordStore(Profile::EXPLICIT_ACCESS); | 
| 97 } | 101 } | 
| 98 | 102 | 
| 103 void PasswordManagerHandler::Observe(NotificationType type, | |
| 104 const NotificationSource& source, | |
| 105 const NotificationDetails& details) { | |
| 106 if (type.value == NotificationType::PREF_CHANGED) { | |
| 107 std::string* pref_name = Details<std::string>(details).ptr(); | |
| 108 if (*pref_name == prefs::kPasswordManagerAllowShowPasswords) { | |
| 109 UpdatePasswordLists(NULL); | |
| 110 } | |
| 111 } | |
| 112 | |
| 113 OptionsPageUIHandler::Observe(type, source, details); | |
| 114 } | |
| 115 | |
| 99 void PasswordManagerHandler::UpdatePasswordLists(const ListValue* args) { | 116 void PasswordManagerHandler::UpdatePasswordLists(const ListValue* args) { | 
| 100 // Reset the current lists. | 117 // Reset the current lists. | 
| 101 password_list_.reset(); | 118 password_list_.reset(); | 
| 102 password_exception_list_.reset(); | 119 password_exception_list_.reset(); | 
| 103 | 120 | 
| 104 languages_ = | 121 languages_ = | 
| 105 web_ui_->GetProfile()->GetPrefs()->GetString(prefs::kAcceptLanguages); | 122 web_ui_->GetProfile()->GetPrefs()->GetString(prefs::kAcceptLanguages); | 
| 106 populater_.Populate(); | 123 populater_.Populate(); | 
| 107 exception_populater_.Populate(); | 124 exception_populater_.Populate(); | 
| 108 } | 125 } | 
| (...skipping 25 matching lines...) Expand all Loading... | |
| 134 | 151 | 
| 135 void PasswordManagerHandler::RemoveAllPasswordExceptions( | 152 void PasswordManagerHandler::RemoveAllPasswordExceptions( | 
| 136 const ListValue* args) { | 153 const ListValue* args) { | 
| 137 PasswordStore* store = GetPasswordStore(); | 154 PasswordStore* store = GetPasswordStore(); | 
| 138 for (size_t i = 0; i < password_exception_list_.size(); ++i) | 155 for (size_t i = 0; i < password_exception_list_.size(); ++i) | 
| 139 store->RemoveLogin(*password_exception_list_[i]); | 156 store->RemoveLogin(*password_exception_list_[i]); | 
| 140 } | 157 } | 
| 141 | 158 | 
| 142 void PasswordManagerHandler::SetPasswordList() { | 159 void PasswordManagerHandler::SetPasswordList() { | 
| 143 ListValue entries; | 160 ListValue entries; | 
| 161 bool show_passwords = *show_passwords_; | |
| 162 string16 stars(ASCIIToUTF16("***")); | |
| 
stuartmorgan
2011/04/05 15:58:29
Why just three stars?
 
Joao da Silva
2011/04/05 16:15:59
No particular reason. This has been moved to js an
 | |
| 144 for (size_t i = 0; i < password_list_.size(); ++i) { | 163 for (size_t i = 0; i < password_list_.size(); ++i) { | 
| 145 ListValue* entry = new ListValue(); | 164 ListValue* entry = new ListValue(); | 
| 146 entry->Append(new StringValue(net::FormatUrl(password_list_[i]->origin, | 165 entry->Append(new StringValue(net::FormatUrl(password_list_[i]->origin, | 
| 147 languages_))); | 166 languages_))); | 
| 148 entry->Append(new StringValue(password_list_[i]->username_value)); | 167 entry->Append(new StringValue(password_list_[i]->username_value)); | 
| 149 entry->Append(new StringValue(password_list_[i]->password_value)); | 168 entry->Append(new StringValue( | 
| 169 show_passwords ? password_list_[i]->password_value : stars)); | |
| 150 entries.Append(entry); | 170 entries.Append(entry); | 
| 151 } | 171 } | 
| 152 | 172 | 
| 153 web_ui_->CallJavascriptFunction("PasswordManager.setSavedPasswordsList", | 173 web_ui_->CallJavascriptFunction("PasswordManager.setSavedPasswordsList", | 
| 154 entries); | 174 entries); | 
| 155 } | 175 } | 
| 156 | 176 | 
| 157 void PasswordManagerHandler::SetPasswordExceptionList() { | 177 void PasswordManagerHandler::SetPasswordExceptionList() { | 
| 158 ListValue entries; | 178 ListValue entries; | 
| 159 for (size_t i = 0; i < password_exception_list_.size(); ++i) { | 179 for (size_t i = 0; i < password_exception_list_.size(); ++i) { | 
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 223 OnPasswordStoreRequestDone( | 243 OnPasswordStoreRequestDone( | 
| 224 CancelableRequestProvider::Handle handle, | 244 CancelableRequestProvider::Handle handle, | 
| 225 const std::vector<webkit_glue::PasswordForm*>& result) { | 245 const std::vector<webkit_glue::PasswordForm*>& result) { | 
| 226 DCHECK_EQ(pending_login_query_, handle); | 246 DCHECK_EQ(pending_login_query_, handle); | 
| 227 pending_login_query_ = 0; | 247 pending_login_query_ = 0; | 
| 228 page_->password_exception_list_.reset(); | 248 page_->password_exception_list_.reset(); | 
| 229 page_->password_exception_list_.insert(page_->password_exception_list_.end(), | 249 page_->password_exception_list_.insert(page_->password_exception_list_.end(), | 
| 230 result.begin(), result.end()); | 250 result.begin(), result.end()); | 
| 231 page_->SetPasswordExceptionList(); | 251 page_->SetPasswordExceptionList(); | 
| 232 } | 252 } | 
| OLD | NEW |