summaryrefslogtreecommitdiffstats
path: root/chrome/browser/dom_ui/passwords_exceptions_handler.cc
diff options
context:
space:
mode:
Diffstat (limited to 'chrome/browser/dom_ui/passwords_exceptions_handler.cc')
-rw-r--r--chrome/browser/dom_ui/passwords_exceptions_handler.cc79
1 files changed, 69 insertions, 10 deletions
diff --git a/chrome/browser/dom_ui/passwords_exceptions_handler.cc b/chrome/browser/dom_ui/passwords_exceptions_handler.cc
index b69be9c..c41bf10 100644
--- a/chrome/browser/dom_ui/passwords_exceptions_handler.cc
+++ b/chrome/browser/dom_ui/passwords_exceptions_handler.cc
@@ -6,8 +6,9 @@
#include "app/l10n_util.h"
#include "base/callback.h"
-#include "base/values.h"
+#include "base/string_number_conversions.h"
#include "base/utf_string_conversions.h"
+#include "base/values.h"
#include "chrome/browser/pref_service.h"
#include "chrome/common/pref_names.h"
#include "chrome/common/url_constants.h"
@@ -30,7 +31,7 @@ void PasswordsExceptionsHandler::GetLocalizedValues(
l10n_util::GetStringUTF16(IDS_PASSWORDS_EXCEPTIONS_WINDOW_TITLE));
localized_strings->SetString("passwordsTabTitle",
l10n_util::GetStringUTF16(IDS_PASSWORDS_SHOW_PASSWORDS_TAB_TITLE));
- localized_strings->SetString("exceptionsTabTitle",
+ localized_strings->SetString("passwordsExceptionsTabTitle",
l10n_util::GetStringUTF16(IDS_PASSWORDS_EXCEPTIONS_TAB_TITLE));
localized_strings->SetString("passwordsSiteColumn",
l10n_util::GetStringUTF16(IDS_PASSWORDS_PAGE_VIEW_SITE_COLUMN));
@@ -54,28 +55,85 @@ void PasswordsExceptionsHandler::GetLocalizedValues(
void PasswordsExceptionsHandler::Initialize() {
profile_ = dom_ui_->GetProfile();
- populater_.Populate();
}
void PasswordsExceptionsHandler::RegisterMessages() {
+ DCHECK(dom_ui_);
+
+ dom_ui_->RegisterMessageCallback(
+ "loadSavedPasswords",
+ NewCallback(this, &PasswordsExceptionsHandler::LoadSavedPasswords));
+ dom_ui_->RegisterMessageCallback(
+ "removeAutofillable",
+ NewCallback(this, &PasswordsExceptionsHandler::RemoveEntry));
+ dom_ui_->RegisterMessageCallback(
+ "showSelectedPassword",
+ NewCallback(this, &PasswordsExceptionsHandler::ShowSelectedPassword));
}
PasswordStore* PasswordsExceptionsHandler::GetPasswordStore() {
return profile_->GetPasswordStore(Profile::EXPLICIT_ACCESS);
}
-void PasswordsExceptionsHandler::SetPasswordList(
- const std::vector<webkit_glue::PasswordForm*>& result) {
+void PasswordsExceptionsHandler::LoadSavedPasswords(const Value* value) {
+ populater_.Populate();
+}
+
+void PasswordsExceptionsHandler::RemoveEntry(const Value* value) {
+ if (!value || !value->IsType(Value::TYPE_LIST)) {
+ NOTREACHED();
+ return;
+ }
+
+ const ListValue* param_values = static_cast<const ListValue*>(value);
+ std::string string_value;
+ if (param_values->GetSize() != 1 ||
+ !param_values->GetString(0, &string_value)) {
+ NOTREACHED();
+ return;
+ }
+ int selected_index;
+ base::StringToInt(string_value, &selected_index);
+
+ GetPasswordStore()->RemoveLogin(*password_list_[selected_index]);
+ delete password_list_[selected_index];
+ password_list_.erase(password_list_.begin() + selected_index);
+ SetPasswordList();
+}
+
+void PasswordsExceptionsHandler::ShowSelectedPassword(const Value* value) {
+ if (!value || !value->IsType(Value::TYPE_LIST)) {
+ NOTREACHED();
+ return;
+ }
+
+ const ListValue* param_values = static_cast<const ListValue*>(value);
+ std::string string_value;
+ if (param_values->GetSize() != 1 ||
+ !param_values->GetString(0, &string_value)) {
+ NOTREACHED();
+ return;
+ }
+
+ int index;
+ base::StringToInt(string_value, &index);
+
+ std::string pass = UTF16ToUTF8(password_list_[index]->password_value);
+ scoped_ptr<Value> password_string(Value::CreateStringValue(pass));
+ dom_ui_->CallJavascriptFunction(
+ L"PasswordsExceptions.selectedPasswordCallback", *password_string.get());
+}
+
+void PasswordsExceptionsHandler::SetPasswordList() {
ListValue autofillableLogins;
std::wstring languages =
UTF8ToWide(profile_->GetPrefs()->GetString(prefs::kAcceptLanguages));
- password_list_ = result;
- for (size_t i = 0; i < result.size(); ++i) {
+ for (size_t i = 0; i < password_list_.size(); ++i) {
ListValue* entry = new ListValue();
entry->Append(new StringValue(
- WideToUTF8(net::FormatUrl(result[i]->origin, languages))));
+ WideToUTF8(net::FormatUrl(password_list_[i]->origin, languages))));
entry->Append(new StringValue(
- UTF16ToUTF8(result[i]->username_value)));
+ UTF16ToUTF8(password_list_[i]->username_value)));
autofillableLogins.Append(entry);
}
@@ -94,5 +152,6 @@ void PasswordsExceptionsHandler::PasswordListPopulater::
const std::vector<webkit_glue::PasswordForm*>& result) {
DCHECK_EQ(pending_login_query_, handle);
pending_login_query_ = 0;
- page_->SetPasswordList(result);
+ page_->password_list_ = result;
+ page_->SetPasswordList();
}