| 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/stl_util-inl.h" |  | 
|    9 #include "base/string_number_conversions.h" |    8 #include "base/string_number_conversions.h" | 
|   10 #include "base/utf_string_conversions.h" |    9 #include "base/utf_string_conversions.h" | 
|   11 #include "base/values.h" |   10 #include "base/values.h" | 
|   12 #include "chrome/browser/prefs/pref_service.h" |   11 #include "chrome/browser/prefs/pref_service.h" | 
|   13 #include "chrome/browser/profiles/profile.h" |   12 #include "chrome/browser/profiles/profile.h" | 
|   14 #include "chrome/common/pref_names.h" |   13 #include "chrome/common/pref_names.h" | 
|   15 #include "chrome/common/url_constants.h" |   14 #include "chrome/common/url_constants.h" | 
|   16 #include "grit/chromium_strings.h" |   15 #include "grit/chromium_strings.h" | 
|   17 #include "grit/generated_resources.h" |   16 #include "grit/generated_resources.h" | 
|   18 #include "net/base/net_util.h" |   17 #include "net/base/net_util.h" | 
|   19 #include "ui/base/l10n/l10n_util.h" |   18 #include "ui/base/l10n/l10n_util.h" | 
 |   19 #include "webkit/glue/password_form.h" | 
|   20  |   20  | 
|   21 PasswordManagerHandler::PasswordManagerHandler() |   21 PasswordManagerHandler::PasswordManagerHandler() | 
|   22     : ALLOW_THIS_IN_INITIALIZER_LIST(populater_(this)), |   22     : ALLOW_THIS_IN_INITIALIZER_LIST(populater_(this)), | 
|   23       ALLOW_THIS_IN_INITIALIZER_LIST(exception_populater_(this)) { |   23       ALLOW_THIS_IN_INITIALIZER_LIST(exception_populater_(this)) { | 
|   24 } |   24 } | 
|   25  |   25  | 
|   26 PasswordManagerHandler::~PasswordManagerHandler() { |   26 PasswordManagerHandler::~PasswordManagerHandler() { | 
|   27   // TODO(scr): ScopedVector. |  | 
|   28   STLDeleteElements(&password_list_); |  | 
|   29   STLDeleteElements(&password_exception_list_); |  | 
|   30   GetPasswordStore()->RemoveObserver(this); |   27   GetPasswordStore()->RemoveObserver(this); | 
|   31 } |   28 } | 
|   32  |   29  | 
|   33 void PasswordManagerHandler::GetLocalizedValues( |   30 void PasswordManagerHandler::GetLocalizedValues( | 
|   34     DictionaryValue* localized_strings) { |   31     DictionaryValue* localized_strings) { | 
|   35   DCHECK(localized_strings); |   32   DCHECK(localized_strings); | 
|   36  |   33  | 
|   37   RegisterTitle(localized_strings, "passwordsPage", |   34   RegisterTitle(localized_strings, "passwordsPage", | 
|   38                 IDS_PASSWORDS_EXCEPTIONS_WINDOW_TITLE); |   35                 IDS_PASSWORDS_EXCEPTIONS_WINDOW_TITLE); | 
|   39   localized_strings->SetString("savedPasswordsTitle", |   36   localized_strings->SetString("savedPasswordsTitle", | 
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   83 void PasswordManagerHandler::OnLoginsChanged() { |   80 void PasswordManagerHandler::OnLoginsChanged() { | 
|   84   UpdatePasswordLists(NULL); |   81   UpdatePasswordLists(NULL); | 
|   85 } |   82 } | 
|   86  |   83  | 
|   87 PasswordStore* PasswordManagerHandler::GetPasswordStore() { |   84 PasswordStore* PasswordManagerHandler::GetPasswordStore() { | 
|   88   return web_ui_->GetProfile()->GetPasswordStore(Profile::EXPLICIT_ACCESS); |   85   return web_ui_->GetProfile()->GetPasswordStore(Profile::EXPLICIT_ACCESS); | 
|   89 } |   86 } | 
|   90  |   87  | 
|   91 void PasswordManagerHandler::UpdatePasswordLists(const ListValue* args) { |   88 void PasswordManagerHandler::UpdatePasswordLists(const ListValue* args) { | 
|   92   // Reset the current lists. |   89   // Reset the current lists. | 
|   93   STLDeleteElements(&password_list_); |   90   password_list_.reset(); | 
|   94   STLDeleteElements(&password_exception_list_); |   91   password_exception_list_.reset(); | 
|   95  |   92  | 
|   96   languages_ = |   93   languages_ = | 
|   97       web_ui_->GetProfile()->GetPrefs()->GetString(prefs::kAcceptLanguages); |   94       web_ui_->GetProfile()->GetPrefs()->GetString(prefs::kAcceptLanguages); | 
|   98   populater_.Populate(); |   95   populater_.Populate(); | 
|   99   exception_populater_.Populate(); |   96   exception_populater_.Populate(); | 
|  100 } |   97 } | 
|  101  |   98  | 
|  102 void PasswordManagerHandler::RemoveSavedPassword(const ListValue* args) { |   99 void PasswordManagerHandler::RemoveSavedPassword(const ListValue* args) { | 
|  103   std::string string_value = UTF16ToUTF8(ExtractStringValue(args)); |  100   std::string string_value = UTF16ToUTF8(ExtractStringValue(args)); | 
|  104   int index; |  101   int index; | 
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  151   for (size_t i = 0; i < password_exception_list_.size(); ++i) { |  148   for (size_t i = 0; i < password_exception_list_.size(); ++i) { | 
|  152     entries.Append(new StringValue( |  149     entries.Append(new StringValue( | 
|  153         net::FormatUrl(password_exception_list_[i]->origin, languages_))); |  150         net::FormatUrl(password_exception_list_[i]->origin, languages_))); | 
|  154   } |  151   } | 
|  155  |  152  | 
|  156   web_ui_->CallJavascriptFunction("PasswordManager.setPasswordExceptionsList", |  153   web_ui_->CallJavascriptFunction("PasswordManager.setPasswordExceptionsList", | 
|  157                                   entries); |  154                                   entries); | 
|  158 } |  155 } | 
|  159  |  156  | 
|  160 PasswordManagerHandler::ListPopulater::ListPopulater( |  157 PasswordManagerHandler::ListPopulater::ListPopulater( | 
|  161     PasswordManagerHandler* page) : page_(page), |  158     PasswordManagerHandler* page) | 
|  162                                     pending_login_query_(0) { |  159     : page_(page), | 
 |  160       pending_login_query_(CancelableRequestProvider::InvalidHandle()) { | 
|  163 } |  161 } | 
|  164  |  162  | 
|  165 PasswordManagerHandler::ListPopulater::~ListPopulater() { |  163 PasswordManagerHandler::ListPopulater::~ListPopulater() { | 
|  166   PasswordStore* store = page_->GetPasswordStore(); |  | 
|  167   if (store) |  | 
|  168     store->CancelLoginsQuery(pending_login_query_); |  | 
|  169 } |  164 } | 
|  170  |  165  | 
|  171 PasswordManagerHandler::PasswordListPopulater::PasswordListPopulater( |  166 PasswordManagerHandler::PasswordListPopulater::PasswordListPopulater( | 
|  172     PasswordManagerHandler* page) : ListPopulater(page) { |  167     PasswordManagerHandler* page) : ListPopulater(page) { | 
|  173 } |  168 } | 
|  174  |  169  | 
|  175 void PasswordManagerHandler::PasswordListPopulater::Populate() { |  170 void PasswordManagerHandler::PasswordListPopulater::Populate() { | 
|  176   DCHECK(!pending_login_query_); |  | 
|  177   PasswordStore* store = page_->GetPasswordStore(); |  171   PasswordStore* store = page_->GetPasswordStore(); | 
|  178   if (store != NULL) |  172   if (store != NULL) { | 
 |  173     if (CancelableRequestProvider::HandleIsValid(pending_login_query_)) | 
 |  174       store->CancelRequest(pending_login_query_); | 
 |  175  | 
|  179     pending_login_query_ = store->GetAutofillableLogins(this); |  176     pending_login_query_ = store->GetAutofillableLogins(this); | 
|  180   else |  177   } else { | 
|  181     LOG(ERROR) << "No password store! Cannot display passwords."; |  178     LOG(ERROR) << "No password store! Cannot display passwords."; | 
 |  179   } | 
|  182 } |  180 } | 
|  183  |  181  | 
|  184 void PasswordManagerHandler::PasswordListPopulater:: |  182 void PasswordManagerHandler::PasswordListPopulater:: | 
|  185     OnPasswordStoreRequestDone(int handle, |  183     OnPasswordStoreRequestDone( | 
|  186     const std::vector<webkit_glue::PasswordForm*>& result) { |  184         CancelableRequestProvider::Handle handle, | 
 |  185         const std::vector<webkit_glue::PasswordForm*>& result) { | 
|  187   DCHECK_EQ(pending_login_query_, handle); |  186   DCHECK_EQ(pending_login_query_, handle); | 
|  188   pending_login_query_ = 0; |  187   pending_login_query_ = CancelableRequestProvider::InvalidHandle(); | 
|  189   page_->password_list_ = result; |  188   page_->password_list_.reset(); | 
 |  189   page_->password_list_.insert(page_->password_list_.end(), | 
 |  190                                result.begin(), result.end()); | 
|  190   page_->SetPasswordList(); |  191   page_->SetPasswordList(); | 
|  191 } |  192 } | 
|  192  |  193  | 
|  193 PasswordManagerHandler::PasswordExceptionListPopulater:: |  194 PasswordManagerHandler::PasswordExceptionListPopulater:: | 
|  194     PasswordExceptionListPopulater(PasswordManagerHandler* page) |  195     PasswordExceptionListPopulater(PasswordManagerHandler* page) | 
|  195         : ListPopulater(page) { |  196         : ListPopulater(page) { | 
|  196 } |  197 } | 
|  197  |  198  | 
|  198 void PasswordManagerHandler::PasswordExceptionListPopulater::Populate() { |  199 void PasswordManagerHandler::PasswordExceptionListPopulater::Populate() { | 
|  199   DCHECK(!pending_login_query_); |  | 
|  200   PasswordStore* store = page_->GetPasswordStore(); |  200   PasswordStore* store = page_->GetPasswordStore(); | 
|  201   if (store != NULL) |  201   if (store != NULL) { | 
 |  202     if (CancelableRequestProvider::HandleIsValid(pending_login_query_)) | 
 |  203       store->CancelRequest(pending_login_query_); | 
 |  204  | 
|  202     pending_login_query_ = store->GetBlacklistLogins(this); |  205     pending_login_query_ = store->GetBlacklistLogins(this); | 
|  203   else |  206   } else { | 
|  204     LOG(ERROR) << "No password store! Cannot display exceptions."; |  207     LOG(ERROR) << "No password store! Cannot display exceptions."; | 
 |  208   } | 
|  205 } |  209 } | 
|  206  |  210  | 
|  207 void PasswordManagerHandler::PasswordExceptionListPopulater:: |  211 void PasswordManagerHandler::PasswordExceptionListPopulater:: | 
|  208     OnPasswordStoreRequestDone(int handle, |  212     OnPasswordStoreRequestDone( | 
|  209     const std::vector<webkit_glue::PasswordForm*>& result) { |  213         CancelableRequestProvider::Handle handle, | 
 |  214         const std::vector<webkit_glue::PasswordForm*>& result) { | 
|  210   DCHECK_EQ(pending_login_query_, handle); |  215   DCHECK_EQ(pending_login_query_, handle); | 
|  211   pending_login_query_ = 0; |  216   pending_login_query_ = CancelableRequestProvider::InvalidHandle(); | 
|  212   page_->password_exception_list_ = result; |  217   page_->password_exception_list_.reset(); | 
 |  218   page_->password_exception_list_.insert(page_->password_exception_list_.end(), | 
 |  219                                          result.begin(), result.end()); | 
|  213   page_->SetPasswordExceptionList(); |  220   page_->SetPasswordExceptionList(); | 
|  214 } |  221 } | 
| OLD | NEW |