 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 // Call UpdatePasswordLists() to update the password data model too. | |
| 
stuartmorgan
2011/04/01 22:22:16
Not sure why this comment is here; the call seems
 
Joao da Silva
2011/04/02 14:08:40
Done.
 | |
| 110 UpdatePasswordLists(NULL); | |
| 111 } | |
| 112 } | |
| 113 | |
| 114 OptionsPageUIHandler::Observe(type, source, details); | |
| 115 } | |
| 116 | |
| 99 void PasswordManagerHandler::UpdatePasswordLists(const ListValue* args) { | 117 void PasswordManagerHandler::UpdatePasswordLists(const ListValue* args) { | 
| 100 // Reset the current lists. | 118 // Reset the current lists. | 
| 101 password_list_.reset(); | 119 password_list_.reset(); | 
| 102 password_exception_list_.reset(); | 120 password_exception_list_.reset(); | 
| 103 | 121 | 
| 104 languages_ = | 122 languages_ = | 
| 105 web_ui_->GetProfile()->GetPrefs()->GetString(prefs::kAcceptLanguages); | 123 web_ui_->GetProfile()->GetPrefs()->GetString(prefs::kAcceptLanguages); | 
| 106 populater_.Populate(); | 124 populater_.Populate(); | 
| 107 exception_populater_.Populate(); | 125 exception_populater_.Populate(); | 
| 108 } | 126 } | 
| (...skipping 25 matching lines...) Expand all Loading... | |
| 134 | 152 | 
| 135 void PasswordManagerHandler::RemoveAllPasswordExceptions( | 153 void PasswordManagerHandler::RemoveAllPasswordExceptions( | 
| 136 const ListValue* args) { | 154 const ListValue* args) { | 
| 137 PasswordStore* store = GetPasswordStore(); | 155 PasswordStore* store = GetPasswordStore(); | 
| 138 for (size_t i = 0; i < password_exception_list_.size(); ++i) | 156 for (size_t i = 0; i < password_exception_list_.size(); ++i) | 
| 139 store->RemoveLogin(*password_exception_list_[i]); | 157 store->RemoveLogin(*password_exception_list_[i]); | 
| 140 } | 158 } | 
| 141 | 159 | 
| 142 void PasswordManagerHandler::SetPasswordList() { | 160 void PasswordManagerHandler::SetPasswordList() { | 
| 143 ListValue entries; | 161 ListValue entries; | 
| 162 bool show_passwords = *show_passwords_; | |
| 163 string16 hidden_password(ASCIIToUTF16("********")); | |
| 
stuartmorgan
2011/04/01 22:22:16
Why send this to JS at all, vs an empty string? JS
 
Joao da Silva
2011/04/02 14:08:40
Done.
 | |
| 144 for (size_t i = 0; i < password_list_.size(); ++i) { | 164 for (size_t i = 0; i < password_list_.size(); ++i) { | 
| 145 ListValue* entry = new ListValue(); | 165 ListValue* entry = new ListValue(); | 
| 146 entry->Append(new StringValue(net::FormatUrl(password_list_[i]->origin, | 166 entry->Append(new StringValue(net::FormatUrl(password_list_[i]->origin, | 
| 147 languages_))); | 167 languages_))); | 
| 148 entry->Append(new StringValue(password_list_[i]->username_value)); | 168 entry->Append(new StringValue(password_list_[i]->username_value)); | 
| 149 entry->Append(new StringValue(password_list_[i]->password_value)); | 169 entry->Append(new StringValue( | 
| 170 show_passwords ? password_list_[i]->password_value : hidden_password)); | |
| 150 entries.Append(entry); | 171 entries.Append(entry); | 
| 151 } | 172 } | 
| 152 | 173 | 
| 174 scoped_ptr<Value> show_value(Value::CreateBooleanValue(*show_passwords_)); | |
| 175 | |
| 153 web_ui_->CallJavascriptFunction("PasswordManager.setSavedPasswordsList", | 176 web_ui_->CallJavascriptFunction("PasswordManager.setSavedPasswordsList", | 
| 154 entries); | 177 entries, *show_value); | 
| 155 } | 178 } | 
| 156 | 179 | 
| 157 void PasswordManagerHandler::SetPasswordExceptionList() { | 180 void PasswordManagerHandler::SetPasswordExceptionList() { | 
| 158 ListValue entries; | 181 ListValue entries; | 
| 159 for (size_t i = 0; i < password_exception_list_.size(); ++i) { | 182 for (size_t i = 0; i < password_exception_list_.size(); ++i) { | 
| 160 entries.Append(new StringValue( | 183 entries.Append(new StringValue( | 
| 161 net::FormatUrl(password_exception_list_[i]->origin, languages_))); | 184 net::FormatUrl(password_exception_list_[i]->origin, languages_))); | 
| 162 } | 185 } | 
| 163 | 186 | 
| 164 web_ui_->CallJavascriptFunction("PasswordManager.setPasswordExceptionsList", | 187 web_ui_->CallJavascriptFunction("PasswordManager.setPasswordExceptionsList", | 
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 223 OnPasswordStoreRequestDone( | 246 OnPasswordStoreRequestDone( | 
| 224 CancelableRequestProvider::Handle handle, | 247 CancelableRequestProvider::Handle handle, | 
| 225 const std::vector<webkit_glue::PasswordForm*>& result) { | 248 const std::vector<webkit_glue::PasswordForm*>& result) { | 
| 226 DCHECK_EQ(pending_login_query_, handle); | 249 DCHECK_EQ(pending_login_query_, handle); | 
| 227 pending_login_query_ = 0; | 250 pending_login_query_ = 0; | 
| 228 page_->password_exception_list_.reset(); | 251 page_->password_exception_list_.reset(); | 
| 229 page_->password_exception_list_.insert(page_->password_exception_list_.end(), | 252 page_->password_exception_list_.insert(page_->password_exception_list_.end(), | 
| 230 result.begin(), result.end()); | 253 result.begin(), result.end()); | 
| 231 page_->SetPasswordExceptionList(); | 254 page_->SetPasswordExceptionList(); | 
| 232 } | 255 } | 
| OLD | NEW |