Chromium Code Reviews

Side by Side Diff: chrome/browser/dom_ui/options/password_manager_handler.cc

Issue 5935003: DOMUI: Implement new-style password manager. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Selection transitions. Created 10 years ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/dom_ui/options/password_manager_handler.h" 5 #include "chrome/browser/dom_ui/options/password_manager_handler.h"
6 6
7 #include "app/l10n_util.h" 7 #include "app/l10n_util.h"
8 #include "base/callback.h" 8 #include "base/callback.h"
9 #include "base/stl_util-inl.h" 9 #include "base/stl_util-inl.h"
10 #include "base/string_number_conversions.h" 10 #include "base/string_number_conversions.h"
(...skipping 12 matching lines...)
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 } 27 }
28 28
29 void PasswordManagerHandler::GetLocalizedValues( 29 void PasswordManagerHandler::GetLocalizedValues(
30 DictionaryValue* localized_strings) { 30 DictionaryValue* localized_strings) {
31 DCHECK(localized_strings); 31 DCHECK(localized_strings);
32 32
33 localized_strings->SetString("passwordsTitle",
34 l10n_util::GetStringUTF16(IDS_PASSWORDS_EXCEPTIONS_WINDOW_TITLE));
33 localized_strings->SetString("savedPasswordsTitle", 35 localized_strings->SetString("savedPasswordsTitle",
34 l10n_util::GetStringUTF16(IDS_PASSWORDS_EXCEPTIONS_WINDOW_TITLE));
35 localized_strings->SetString("passwordsTabTitle",
36 l10n_util::GetStringUTF16(IDS_PASSWORDS_SHOW_PASSWORDS_TAB_TITLE)); 36 l10n_util::GetStringUTF16(IDS_PASSWORDS_SHOW_PASSWORDS_TAB_TITLE));
37 localized_strings->SetString("passwordExceptionsTabTitle", 37 localized_strings->SetString("passwordExceptionsTitle",
38 l10n_util::GetStringUTF16(IDS_PASSWORDS_EXCEPTIONS_TAB_TITLE)); 38 l10n_util::GetStringUTF16(IDS_PASSWORDS_EXCEPTIONS_TAB_TITLE));
39 localized_strings->SetString("passwordsSiteColumn", 39 localized_strings->SetString("passwordsSiteColumn",
40 l10n_util::GetStringUTF16(IDS_PASSWORDS_PAGE_VIEW_SITE_COLUMN)); 40 l10n_util::GetStringUTF16(IDS_PASSWORDS_PAGE_VIEW_SITE_COLUMN));
41 localized_strings->SetString("passwordsUsernameColumn", 41 localized_strings->SetString("passwordsUsernameColumn",
42 l10n_util::GetStringUTF16(IDS_PASSWORDS_PAGE_VIEW_USERNAME_COLUMN)); 42 l10n_util::GetStringUTF16(IDS_PASSWORDS_PAGE_VIEW_USERNAME_COLUMN));
43 localized_strings->SetString("passwordsRemoveButton", 43 localized_strings->SetString("passwordsRemoveButton",
44 l10n_util::GetStringUTF16(IDS_PASSWORDS_PAGE_VIEW_REMOVE_BUTTON)); 44 l10n_util::GetStringUTF16(IDS_PASSWORDS_PAGE_VIEW_REMOVE_BUTTON));
45 localized_strings->SetString("passwordsRemoveAllButton", 45 localized_strings->SetString("passwordsRemoveAllButton",
46 l10n_util::GetStringUTF16(IDS_PASSWORDS_PAGE_VIEW_REMOVE_ALL_BUTTON)); 46 l10n_util::GetStringUTF16(IDS_PASSWORDS_PAGE_VIEW_REMOVE_ALL_BUTTON));
47 localized_strings->SetString("passwordsShowButton", 47 localized_strings->SetString("passwordsShowButton",
48 l10n_util::GetStringUTF16(IDS_PASSWORDS_PAGE_VIEW_SHOW_BUTTON)); 48 l10n_util::GetStringUTF16(IDS_PASSWORDS_PAGE_VIEW_SHOW_BUTTON));
49 localized_strings->SetString("passwordsHideButton", 49 localized_strings->SetString("passwordsHideButton",
50 l10n_util::GetStringUTF16(IDS_PASSWORDS_PAGE_VIEW_HIDE_BUTTON)); 50 l10n_util::GetStringUTF16(IDS_PASSWORDS_PAGE_VIEW_HIDE_BUTTON));
51 localized_strings->SetString("passwordsRemoveAllTitle", 51 localized_strings->SetString("passwordsRemoveAllTitle",
52 l10n_util::GetStringUTF16( 52 l10n_util::GetStringUTF16(
53 IDS_PASSWORDS_PAGE_VIEW_CAPTION_DELETE_ALL_PASSWORDS)); 53 IDS_PASSWORDS_PAGE_VIEW_CAPTION_DELETE_ALL_PASSWORDS));
54 localized_strings->SetString("passwordsRemoveAllWarning", 54 localized_strings->SetString("passwordsRemoveAllWarning",
55 l10n_util::GetStringUTF16( 55 l10n_util::GetStringUTF16(
56 IDS_PASSWORDS_PAGE_VIEW_TEXT_DELETE_ALL_PASSWORDS)); 56 IDS_PASSWORDS_PAGE_VIEW_TEXT_DELETE_ALL_PASSWORDS));
57 } 57 }
58 58
59 void PasswordManagerHandler::Initialize() { 59 void PasswordManagerHandler::Initialize() {
60 // We should not cache dom_ui_->GetProfile(). See crosbug.com/6304. 60 // We should not cache dom_ui_->GetProfile(). See crosbug.com/6304.
61 } 61 }
62 62
63 void PasswordManagerHandler::RegisterMessages() { 63 void PasswordManagerHandler::RegisterMessages() {
64 DCHECK(dom_ui_); 64 DCHECK(dom_ui_);
65 65
66 dom_ui_->RegisterMessageCallback("loadLists", 66 dom_ui_->RegisterMessageCallback("updatePasswordLists",
67 NewCallback(this, &PasswordManagerHandler::LoadLists)); 67 NewCallback(this, &PasswordManagerHandler::UpdatePasswordLists));
68 dom_ui_->RegisterMessageCallback("removeSavedPassword", 68 dom_ui_->RegisterMessageCallback("removeSavedPassword",
69 NewCallback(this, &PasswordManagerHandler::RemoveSavedPassword)); 69 NewCallback(this, &PasswordManagerHandler::RemoveSavedPassword));
70 dom_ui_->RegisterMessageCallback("removePasswordException", 70 dom_ui_->RegisterMessageCallback("removePasswordException",
71 NewCallback(this, &PasswordManagerHandler::RemovePasswordException)); 71 NewCallback(this, &PasswordManagerHandler::RemovePasswordException));
72 dom_ui_->RegisterMessageCallback("removeAllSavedPasswords", 72 dom_ui_->RegisterMessageCallback("removeAllSavedPasswords",
73 NewCallback(this, &PasswordManagerHandler::RemoveAllSavedPasswords)); 73 NewCallback(this, &PasswordManagerHandler::RemoveAllSavedPasswords));
74 dom_ui_->RegisterMessageCallback("removeAllPasswordExceptions", NewCallback( 74 dom_ui_->RegisterMessageCallback("removeAllPasswordExceptions", NewCallback(
75 this, &PasswordManagerHandler::RemoveAllPasswordExceptions)); 75 this, &PasswordManagerHandler::RemoveAllPasswordExceptions));
76 dom_ui_->RegisterMessageCallback("showSelectedPassword",
77 NewCallback(this, &PasswordManagerHandler::ShowSelectedPassword));
78 } 76 }
79 77
80 PasswordStore* PasswordManagerHandler::GetPasswordStore() { 78 PasswordStore* PasswordManagerHandler::GetPasswordStore() {
81 return dom_ui_->GetProfile()->GetPasswordStore(Profile::EXPLICIT_ACCESS); 79 return dom_ui_->GetProfile()->GetPasswordStore(Profile::EXPLICIT_ACCESS);
82 } 80 }
83 81
84 void PasswordManagerHandler::LoadLists(const ListValue* args) { 82 void PasswordManagerHandler::UpdatePasswordLists(const ListValue* args) {
85 languages_ = 83 languages_ =
86 dom_ui_->GetProfile()->GetPrefs()->GetString(prefs::kAcceptLanguages); 84 dom_ui_->GetProfile()->GetPrefs()->GetString(prefs::kAcceptLanguages);
87 populater_.Populate(); 85 populater_.Populate();
88 exception_populater_.Populate(); 86 exception_populater_.Populate();
89 } 87 }
90 88
91 void PasswordManagerHandler::RemoveSavedPassword(const ListValue* args) { 89 void PasswordManagerHandler::RemoveSavedPassword(const ListValue* args) {
92 std::string string_value = WideToUTF8(ExtractStringValue(args)); 90 std::string string_value = WideToUTF8(ExtractStringValue(args));
93 int index; 91 int index;
94 base::StringToInt(string_value, &index); 92 base::StringToInt(string_value, &index);
(...skipping 27 matching lines...)
122 120
123 void PasswordManagerHandler::RemoveAllPasswordExceptions( 121 void PasswordManagerHandler::RemoveAllPasswordExceptions(
124 const ListValue* args) { 122 const ListValue* args) {
125 PasswordStore* store = GetPasswordStore(); 123 PasswordStore* store = GetPasswordStore();
126 for (size_t i = 0; i < password_exception_list_.size(); ++i) 124 for (size_t i = 0; i < password_exception_list_.size(); ++i)
127 store->RemoveLogin(*password_exception_list_[i]); 125 store->RemoveLogin(*password_exception_list_[i]);
128 STLDeleteElements(&password_exception_list_); 126 STLDeleteElements(&password_exception_list_);
129 SetPasswordExceptionList(); 127 SetPasswordExceptionList();
130 } 128 }
131 129
132 void PasswordManagerHandler::ShowSelectedPassword(const ListValue* args) {
133 std::string string_value = WideToUTF8(ExtractStringValue(args));
134 int index;
135 base::StringToInt(string_value, &index);
136
137 std::string pass = UTF16ToUTF8(password_list_[index]->password_value);
138 scoped_ptr<Value> password_string(Value::CreateStringValue(pass));
139 dom_ui_->CallJavascriptFunction(
140 L"PasswordManager.selectedPasswordCallback", *password_string.get());
141 }
142
143 void PasswordManagerHandler::SetPasswordList() { 130 void PasswordManagerHandler::SetPasswordList() {
144 ListValue entries; 131 ListValue entries;
145 for (size_t i = 0; i < password_list_.size(); ++i) { 132 for (size_t i = 0; i < password_list_.size(); ++i) {
146 ListValue* entry = new ListValue(); 133 ListValue* entry = new ListValue();
147 entry->Append(new StringValue(net::FormatUrl(password_list_[i]->origin, 134 entry->Append(new StringValue(net::FormatUrl(password_list_[i]->origin,
148 languages_))); 135 languages_)));
149 entry->Append(new StringValue(password_list_[i]->username_value)); 136 entry->Append(new StringValue(password_list_[i]->username_value));
137 entry->Append(new StringValue(password_list_[i]->password_value));
150 entries.Append(entry); 138 entries.Append(entry);
151 } 139 }
152 140
153 dom_ui_->CallJavascriptFunction( 141 dom_ui_->CallJavascriptFunction(
154 L"PasswordManager.setSavedPasswordsList", entries); 142 L"PasswordManager.setSavedPasswordsList", entries);
155 } 143 }
156 144
157 void PasswordManagerHandler::SetPasswordExceptionList() { 145 void PasswordManagerHandler::SetPasswordExceptionList() {
158 ListValue entries; 146 ListValue entries;
159 for (size_t i = 0; i < password_exception_list_.size(); ++i) { 147 for (size_t i = 0; i < password_exception_list_.size(); ++i) {
(...skipping 33 matching lines...)
193 } 181 }
194 182
195 void PasswordManagerHandler::PasswordExceptionListPopulater:: 183 void PasswordManagerHandler::PasswordExceptionListPopulater::
196 OnPasswordStoreRequestDone(int handle, 184 OnPasswordStoreRequestDone(int handle,
197 const std::vector<webkit_glue::PasswordForm*>& result) { 185 const std::vector<webkit_glue::PasswordForm*>& result) {
198 DCHECK_EQ(pending_login_query_, handle); 186 DCHECK_EQ(pending_login_query_, handle);
199 pending_login_query_ = 0; 187 pending_login_query_ = 0;
200 page_->password_exception_list_ = result; 188 page_->password_exception_list_ = result;
201 page_->SetPasswordExceptionList(); 189 page_->SetPasswordExceptionList();
202 } 190 }
OLDNEW
« no previous file with comments | « chrome/browser/dom_ui/options/password_manager_handler.h ('k') | chrome/browser/resources/options/deletable_item_list.js » ('j') | no next file with comments »

Powered by Google App Engine