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 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 | 77 |
78 void PasswordManagerHandler::Initialize() { | 78 void PasswordManagerHandler::Initialize() { |
79 // Due to the way that handlers are (re)initialized under certain types of | 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.) | 80 // navigation, we may already be initialized. (See bugs 88986 and 86448.) |
81 // If this is the case, return immediately. This is a hack. | 81 // If this is the case, return immediately. This is a hack. |
82 // TODO(mdm): remove this hack once it is no longer necessary. | 82 // TODO(mdm): remove this hack once it is no longer necessary. |
83 if (!show_passwords_.GetPrefName().empty()) | 83 if (!show_passwords_.GetPrefName().empty()) |
84 return; | 84 return; |
85 | 85 |
86 show_passwords_.Init(prefs::kPasswordManagerAllowShowPasswords, | 86 show_passwords_.Init(prefs::kPasswordManagerAllowShowPasswords, |
87 web_ui_->GetProfile()->GetPrefs(), this); | 87 Profile::FromWebUI(web_ui_)->GetPrefs(), this); |
88 // We should not cache web_ui_->GetProfile(). See crosbug.com/6304. | 88 // We should not cache web_ui_->GetProfile(). See crosbug.com/6304. |
89 PasswordStore* store = GetPasswordStore(); | 89 PasswordStore* store = GetPasswordStore(); |
90 if (store) | 90 if (store) |
91 store->AddObserver(this); | 91 store->AddObserver(this); |
92 } | 92 } |
93 | 93 |
94 void PasswordManagerHandler::RegisterMessages() { | 94 void PasswordManagerHandler::RegisterMessages() { |
95 DCHECK(web_ui_); | 95 DCHECK(web_ui_); |
96 | 96 |
97 web_ui_->RegisterMessageCallback("updatePasswordLists", | 97 web_ui_->RegisterMessageCallback("updatePasswordLists", |
98 NewCallback(this, &PasswordManagerHandler::UpdatePasswordLists)); | 98 NewCallback(this, &PasswordManagerHandler::UpdatePasswordLists)); |
99 web_ui_->RegisterMessageCallback("removeSavedPassword", | 99 web_ui_->RegisterMessageCallback("removeSavedPassword", |
100 NewCallback(this, &PasswordManagerHandler::RemoveSavedPassword)); | 100 NewCallback(this, &PasswordManagerHandler::RemoveSavedPassword)); |
101 web_ui_->RegisterMessageCallback("removePasswordException", | 101 web_ui_->RegisterMessageCallback("removePasswordException", |
102 NewCallback(this, &PasswordManagerHandler::RemovePasswordException)); | 102 NewCallback(this, &PasswordManagerHandler::RemovePasswordException)); |
103 web_ui_->RegisterMessageCallback("removeAllSavedPasswords", | 103 web_ui_->RegisterMessageCallback("removeAllSavedPasswords", |
104 NewCallback(this, &PasswordManagerHandler::RemoveAllSavedPasswords)); | 104 NewCallback(this, &PasswordManagerHandler::RemoveAllSavedPasswords)); |
105 web_ui_->RegisterMessageCallback("removeAllPasswordExceptions", NewCallback( | 105 web_ui_->RegisterMessageCallback("removeAllPasswordExceptions", NewCallback( |
106 this, &PasswordManagerHandler::RemoveAllPasswordExceptions)); | 106 this, &PasswordManagerHandler::RemoveAllPasswordExceptions)); |
107 } | 107 } |
108 | 108 |
109 void PasswordManagerHandler::OnLoginsChanged() { | 109 void PasswordManagerHandler::OnLoginsChanged() { |
110 UpdatePasswordLists(NULL); | 110 UpdatePasswordLists(NULL); |
111 } | 111 } |
112 | 112 |
113 PasswordStore* PasswordManagerHandler::GetPasswordStore() { | 113 PasswordStore* PasswordManagerHandler::GetPasswordStore() { |
114 return web_ui_->GetProfile()->GetPasswordStore(Profile::EXPLICIT_ACCESS); | 114 return Profile::FromWebUI(web_ui_)-> |
| 115 GetPasswordStore(Profile::EXPLICIT_ACCESS); |
115 } | 116 } |
116 | 117 |
117 void PasswordManagerHandler::Observe(int type, | 118 void PasswordManagerHandler::Observe(int type, |
118 const NotificationSource& source, | 119 const NotificationSource& source, |
119 const NotificationDetails& details) { | 120 const NotificationDetails& details) { |
120 if (type == chrome::NOTIFICATION_PREF_CHANGED) { | 121 if (type == chrome::NOTIFICATION_PREF_CHANGED) { |
121 std::string* pref_name = Details<std::string>(details).ptr(); | 122 std::string* pref_name = Details<std::string>(details).ptr(); |
122 if (*pref_name == prefs::kPasswordManagerAllowShowPasswords) { | 123 if (*pref_name == prefs::kPasswordManagerAllowShowPasswords) { |
123 UpdatePasswordLists(NULL); | 124 UpdatePasswordLists(NULL); |
124 } | 125 } |
125 } | 126 } |
126 | 127 |
127 OptionsPageUIHandler::Observe(type, source, details); | 128 OptionsPageUIHandler::Observe(type, source, details); |
128 } | 129 } |
129 | 130 |
130 void PasswordManagerHandler::UpdatePasswordLists(const ListValue* args) { | 131 void PasswordManagerHandler::UpdatePasswordLists(const ListValue* args) { |
131 // Reset the current lists. | 132 // Reset the current lists. |
132 password_list_.reset(); | 133 password_list_.reset(); |
133 password_exception_list_.reset(); | 134 password_exception_list_.reset(); |
134 | 135 |
135 languages_ = | 136 languages_ = Profile::FromWebUI(web_ui_)->GetPrefs()-> |
136 web_ui_->GetProfile()->GetPrefs()->GetString(prefs::kAcceptLanguages); | 137 GetString(prefs::kAcceptLanguages); |
137 populater_.Populate(); | 138 populater_.Populate(); |
138 exception_populater_.Populate(); | 139 exception_populater_.Populate(); |
139 } | 140 } |
140 | 141 |
141 void PasswordManagerHandler::RemoveSavedPassword(const ListValue* args) { | 142 void PasswordManagerHandler::RemoveSavedPassword(const ListValue* args) { |
142 PasswordStore* store = GetPasswordStore(); | 143 PasswordStore* store = GetPasswordStore(); |
143 if (!store) | 144 if (!store) |
144 return; | 145 return; |
145 std::string string_value = UTF16ToUTF8(ExtractStringValue(args)); | 146 std::string string_value = UTF16ToUTF8(ExtractStringValue(args)); |
146 int index; | 147 int index; |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
275 OnPasswordStoreRequestDone( | 276 OnPasswordStoreRequestDone( |
276 CancelableRequestProvider::Handle handle, | 277 CancelableRequestProvider::Handle handle, |
277 const std::vector<webkit_glue::PasswordForm*>& result) { | 278 const std::vector<webkit_glue::PasswordForm*>& result) { |
278 DCHECK_EQ(pending_login_query_, handle); | 279 DCHECK_EQ(pending_login_query_, handle); |
279 pending_login_query_ = 0; | 280 pending_login_query_ = 0; |
280 page_->password_exception_list_.reset(); | 281 page_->password_exception_list_.reset(); |
281 page_->password_exception_list_.insert(page_->password_exception_list_.end(), | 282 page_->password_exception_list_.insert(page_->password_exception_list_.end(), |
282 result.begin(), result.end()); | 283 result.begin(), result.end()); |
283 page_->SetPasswordExceptionList(); | 284 page_->SetPasswordExceptionList(); |
284 } | 285 } |
OLD | NEW |