Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(454)

Side by Side Diff: chrome/browser/ui/webui/options/password_manager_handler.cc

Issue 6770012: Handle the PasswordManagerAllowShowPasswords preference in the options webui. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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,
stuartmorgan 2011/03/29 15:24:58 Alignment is wrong on the continuation lines.
Joao da Silva 2011/03/31 10:03:22 Done.
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.
110 UpdatePasswordLists(NULL);
111 return;
stuartmorgan 2011/03/29 15:24:58 Why the early return?
Joao da Silva 2011/03/31 10:03:22 No reason for it, removed.
112 }
113 }
114
115 OptionsPageUIHandler::Observe(type, source, details);
116 }
117
99 void PasswordManagerHandler::UpdatePasswordLists(const ListValue* args) { 118 void PasswordManagerHandler::UpdatePasswordLists(const ListValue* args) {
100 // Reset the current lists. 119 // Reset the current lists.
101 password_list_.reset(); 120 password_list_.reset();
102 password_exception_list_.reset(); 121 password_exception_list_.reset();
103 122
104 languages_ = 123 languages_ =
105 web_ui_->GetProfile()->GetPrefs()->GetString(prefs::kAcceptLanguages); 124 web_ui_->GetProfile()->GetPrefs()->GetString(prefs::kAcceptLanguages);
106 populater_.Populate(); 125 populater_.Populate();
107 exception_populater_.Populate(); 126 exception_populater_.Populate();
108 } 127 }
(...skipping 25 matching lines...) Expand all
134 153
135 void PasswordManagerHandler::RemoveAllPasswordExceptions( 154 void PasswordManagerHandler::RemoveAllPasswordExceptions(
136 const ListValue* args) { 155 const ListValue* args) {
137 PasswordStore* store = GetPasswordStore(); 156 PasswordStore* store = GetPasswordStore();
138 for (size_t i = 0; i < password_exception_list_.size(); ++i) 157 for (size_t i = 0; i < password_exception_list_.size(); ++i)
139 store->RemoveLogin(*password_exception_list_[i]); 158 store->RemoveLogin(*password_exception_list_[i]);
140 } 159 }
141 160
142 void PasswordManagerHandler::SetPasswordList() { 161 void PasswordManagerHandler::SetPasswordList() {
143 ListValue entries; 162 ListValue entries;
163 bool show_passwords = *show_passwords_;
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 : string16()));
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
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 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698