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); |
78 } | 82 } |
79 | 83 |
80 void PasswordManagerHandler::RegisterMessages() { | 84 void PasswordManagerHandler::RegisterMessages() { |
81 DCHECK(web_ui_); | 85 DCHECK(web_ui_); |
82 | 86 |
83 web_ui_->RegisterMessageCallback("updatePasswordLists", | 87 web_ui_->RegisterMessageCallback("updatePasswordLists", |
84 NewCallback(this, &PasswordManagerHandler::UpdatePasswordLists)); | 88 NewCallback(this, &PasswordManagerHandler::UpdatePasswordLists)); |
85 web_ui_->RegisterMessageCallback("removeSavedPassword", | 89 web_ui_->RegisterMessageCallback("removeSavedPassword", |
86 NewCallback(this, &PasswordManagerHandler::RemoveSavedPassword)); | 90 NewCallback(this, &PasswordManagerHandler::RemoveSavedPassword)); |
87 web_ui_->RegisterMessageCallback("removePasswordException", | 91 web_ui_->RegisterMessageCallback("removePasswordException", |
(...skipping 30 matching lines...) Expand all Loading... |
118 password_list_.reset(); | 122 password_list_.reset(); |
119 password_exception_list_.reset(); | 123 password_exception_list_.reset(); |
120 | 124 |
121 languages_ = | 125 languages_ = |
122 web_ui_->GetProfile()->GetPrefs()->GetString(prefs::kAcceptLanguages); | 126 web_ui_->GetProfile()->GetPrefs()->GetString(prefs::kAcceptLanguages); |
123 populater_.Populate(); | 127 populater_.Populate(); |
124 exception_populater_.Populate(); | 128 exception_populater_.Populate(); |
125 } | 129 } |
126 | 130 |
127 void PasswordManagerHandler::RemoveSavedPassword(const ListValue* args) { | 131 void PasswordManagerHandler::RemoveSavedPassword(const ListValue* args) { |
| 132 PasswordStore* store = GetPasswordStore(); |
| 133 if (!store) |
| 134 return; |
128 std::string string_value = UTF16ToUTF8(ExtractStringValue(args)); | 135 std::string string_value = UTF16ToUTF8(ExtractStringValue(args)); |
129 int index; | 136 int index; |
130 base::StringToInt(string_value, &index); | 137 base::StringToInt(string_value, &index); |
131 GetPasswordStore()->RemoveLogin(*password_list_[index]); | 138 store->RemoveLogin(*password_list_[index]); |
132 } | 139 } |
133 | 140 |
134 void PasswordManagerHandler::RemovePasswordException( | 141 void PasswordManagerHandler::RemovePasswordException( |
135 const ListValue* args) { | 142 const ListValue* args) { |
| 143 PasswordStore* store = GetPasswordStore(); |
| 144 if (!store) |
| 145 return; |
136 std::string string_value = UTF16ToUTF8(ExtractStringValue(args)); | 146 std::string string_value = UTF16ToUTF8(ExtractStringValue(args)); |
137 int index; | 147 int index; |
138 base::StringToInt(string_value, &index); | 148 base::StringToInt(string_value, &index); |
139 | 149 |
140 GetPasswordStore()->RemoveLogin(*password_exception_list_[index]); | 150 store->RemoveLogin(*password_exception_list_[index]); |
141 } | 151 } |
142 | 152 |
143 void PasswordManagerHandler::RemoveAllSavedPasswords( | 153 void PasswordManagerHandler::RemoveAllSavedPasswords( |
144 const ListValue* args) { | 154 const ListValue* args) { |
145 // TODO(jhawkins): This will cause a list refresh for every password in the | 155 // TODO(jhawkins): This will cause a list refresh for every password in the |
146 // list. Add PasswordStore::RemoveAllLogins(). | 156 // list. Add PasswordStore::RemoveAllLogins(). |
147 PasswordStore* store = GetPasswordStore(); | 157 PasswordStore* store = GetPasswordStore(); |
| 158 if (!store) |
| 159 return; |
148 for (size_t i = 0; i < password_list_.size(); ++i) | 160 for (size_t i = 0; i < password_list_.size(); ++i) |
149 store->RemoveLogin(*password_list_[i]); | 161 store->RemoveLogin(*password_list_[i]); |
150 } | 162 } |
151 | 163 |
152 void PasswordManagerHandler::RemoveAllPasswordExceptions( | 164 void PasswordManagerHandler::RemoveAllPasswordExceptions( |
153 const ListValue* args) { | 165 const ListValue* args) { |
154 PasswordStore* store = GetPasswordStore(); | 166 PasswordStore* store = GetPasswordStore(); |
| 167 if (!store) |
| 168 return; |
155 for (size_t i = 0; i < password_exception_list_.size(); ++i) | 169 for (size_t i = 0; i < password_exception_list_.size(); ++i) |
156 store->RemoveLogin(*password_exception_list_[i]); | 170 store->RemoveLogin(*password_exception_list_[i]); |
157 } | 171 } |
158 | 172 |
159 void PasswordManagerHandler::SetPasswordList() { | 173 void PasswordManagerHandler::SetPasswordList() { |
160 ListValue entries; | 174 ListValue entries; |
161 bool show_passwords = *show_passwords_; | 175 bool show_passwords = *show_passwords_; |
162 string16 empty; | 176 string16 empty; |
163 for (size_t i = 0; i < password_list_.size(); ++i) { | 177 for (size_t i = 0; i < password_list_.size(); ++i) { |
164 ListValue* entry = new ListValue(); | 178 ListValue* entry = new ListValue(); |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
243 OnPasswordStoreRequestDone( | 257 OnPasswordStoreRequestDone( |
244 CancelableRequestProvider::Handle handle, | 258 CancelableRequestProvider::Handle handle, |
245 const std::vector<webkit_glue::PasswordForm*>& result) { | 259 const std::vector<webkit_glue::PasswordForm*>& result) { |
246 DCHECK_EQ(pending_login_query_, handle); | 260 DCHECK_EQ(pending_login_query_, handle); |
247 pending_login_query_ = 0; | 261 pending_login_query_ = 0; |
248 page_->password_exception_list_.reset(); | 262 page_->password_exception_list_.reset(); |
249 page_->password_exception_list_.insert(page_->password_exception_list_.end(), | 263 page_->password_exception_list_.insert(page_->password_exception_list_.end(), |
250 result.begin(), result.end()); | 264 result.begin(), result.end()); |
251 page_->SetPasswordExceptionList(); | 265 page_->SetPasswordExceptionList(); |
252 } | 266 } |
OLD | NEW |