Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(684)

Side by Side Diff: chrome/browser/dom_ui/passwords_exceptions_handler.cc

Issue 3177023: Implement Password Exceptions Tab (Closed) Base URL: http://src.chromium.org/git/chromium.git
Patch Set: sync Created 10 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
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/passwords_exceptions_handler.h" 5 #include "chrome/browser/dom_ui/passwords_exceptions_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/string_number_conversions.h" 10 #include "base/string_number_conversions.h"
10 #include "base/utf_string_conversions.h" 11 #include "base/utf_string_conversions.h"
11 #include "base/values.h" 12 #include "base/values.h"
12 #include "chrome/browser/pref_service.h" 13 #include "chrome/browser/pref_service.h"
13 #include "chrome/common/pref_names.h" 14 #include "chrome/common/pref_names.h"
14 #include "chrome/common/url_constants.h" 15 #include "chrome/common/url_constants.h"
15 #include "grit/chromium_strings.h" 16 #include "grit/chromium_strings.h"
16 #include "grit/generated_resources.h" 17 #include "grit/generated_resources.h"
17 #include "net/base/net_util.h" 18 #include "net/base/net_util.h"
18 19
19 PasswordsExceptionsHandler::PasswordsExceptionsHandler() 20 PasswordsExceptionsHandler::PasswordsExceptionsHandler()
20 : ALLOW_THIS_IN_INITIALIZER_LIST(populater_(this)) { 21 : ALLOW_THIS_IN_INITIALIZER_LIST(populater_(this)),
22 ALLOW_THIS_IN_INITIALIZER_LIST(exception_populater_(this)) {
21 } 23 }
22 24
23 PasswordsExceptionsHandler::~PasswordsExceptionsHandler() { 25 PasswordsExceptionsHandler::~PasswordsExceptionsHandler() {
24 } 26 }
25 27
26 void PasswordsExceptionsHandler::GetLocalizedValues( 28 void PasswordsExceptionsHandler::GetLocalizedValues(
27 DictionaryValue* localized_strings) { 29 DictionaryValue* localized_strings) {
28 DCHECK(localized_strings); 30 DCHECK(localized_strings);
29 31
30 localized_strings->SetString("savedPasswordsExceptionsTitle", 32 localized_strings->SetString("savedPasswordsExceptionsTitle",
31 l10n_util::GetStringUTF16(IDS_PASSWORDS_EXCEPTIONS_WINDOW_TITLE)); 33 l10n_util::GetStringUTF16(IDS_PASSWORDS_EXCEPTIONS_WINDOW_TITLE));
32 localized_strings->SetString("passwordsTabTitle", 34 localized_strings->SetString("passwordsTabTitle",
33 l10n_util::GetStringUTF16(IDS_PASSWORDS_SHOW_PASSWORDS_TAB_TITLE)); 35 l10n_util::GetStringUTF16(IDS_PASSWORDS_SHOW_PASSWORDS_TAB_TITLE));
34 localized_strings->SetString("passwordsExceptionsTabTitle", 36 localized_strings->SetString("passwordExceptionsTabTitle",
35 l10n_util::GetStringUTF16(IDS_PASSWORDS_EXCEPTIONS_TAB_TITLE)); 37 l10n_util::GetStringUTF16(IDS_PASSWORDS_EXCEPTIONS_TAB_TITLE));
36 localized_strings->SetString("passwordsSiteColumn", 38 localized_strings->SetString("passwordsSiteColumn",
37 l10n_util::GetStringUTF16(IDS_PASSWORDS_PAGE_VIEW_SITE_COLUMN)); 39 l10n_util::GetStringUTF16(IDS_PASSWORDS_PAGE_VIEW_SITE_COLUMN));
38 localized_strings->SetString("passwordsUsernameColumn", 40 localized_strings->SetString("passwordsUsernameColumn",
39 l10n_util::GetStringUTF16(IDS_PASSWORDS_PAGE_VIEW_USERNAME_COLUMN)); 41 l10n_util::GetStringUTF16(IDS_PASSWORDS_PAGE_VIEW_USERNAME_COLUMN));
40 localized_strings->SetString("passwordsRemoveButton", 42 localized_strings->SetString("passwordsRemoveButton",
41 l10n_util::GetStringUTF16(IDS_PASSWORDS_PAGE_VIEW_REMOVE_BUTTON)); 43 l10n_util::GetStringUTF16(IDS_PASSWORDS_PAGE_VIEW_REMOVE_BUTTON));
42 localized_strings->SetString("passwordsRemoveAllButton", 44 localized_strings->SetString("passwordsRemoveAllButton",
43 l10n_util::GetStringUTF16(IDS_PASSWORDS_PAGE_VIEW_REMOVE_ALL_BUTTON)); 45 l10n_util::GetStringUTF16(IDS_PASSWORDS_PAGE_VIEW_REMOVE_ALL_BUTTON));
44 localized_strings->SetString("passwordsShowButton", 46 localized_strings->SetString("passwordsShowButton",
45 l10n_util::GetStringUTF16(IDS_PASSWORDS_PAGE_VIEW_SHOW_BUTTON)); 47 l10n_util::GetStringUTF16(IDS_PASSWORDS_PAGE_VIEW_SHOW_BUTTON));
46 localized_strings->SetString("passwordsHideButton", 48 localized_strings->SetString("passwordsHideButton",
47 l10n_util::GetStringUTF16(IDS_PASSWORDS_PAGE_VIEW_HIDE_BUTTON)); 49 l10n_util::GetStringUTF16(IDS_PASSWORDS_PAGE_VIEW_HIDE_BUTTON));
48 localized_strings->SetString("passwordsRemoveAllTitle", 50 localized_strings->SetString("passwordsRemoveAllTitle",
49 l10n_util::GetStringUTF16( 51 l10n_util::GetStringUTF16(
50 IDS_PASSWORDS_PAGE_VIEW_CAPTION_DELETE_ALL_PASSWORDS)); 52 IDS_PASSWORDS_PAGE_VIEW_CAPTION_DELETE_ALL_PASSWORDS));
51 localized_strings->SetString("passwordsRemoveAllWarning", 53 localized_strings->SetString("passwordsRemoveAllWarning",
52 l10n_util::GetStringUTF16( 54 l10n_util::GetStringUTF16(
53 IDS_PASSWORDS_PAGE_VIEW_TEXT_DELETE_ALL_PASSWORDS)); 55 IDS_PASSWORDS_PAGE_VIEW_TEXT_DELETE_ALL_PASSWORDS));
54 } 56 }
55 57
56 void PasswordsExceptionsHandler::Initialize() { 58 void PasswordsExceptionsHandler::Initialize() {
57 profile_ = dom_ui_->GetProfile(); 59 profile_ = dom_ui_->GetProfile();
58 } 60 }
59 61
60 void PasswordsExceptionsHandler::RegisterMessages() { 62 void PasswordsExceptionsHandler::RegisterMessages() {
61 DCHECK(dom_ui_); 63 DCHECK(dom_ui_);
62 64
63 dom_ui_->RegisterMessageCallback( 65 dom_ui_->RegisterMessageCallback("loadLists",
64 "loadSavedPasswords", 66 NewCallback(this, &PasswordsExceptionsHandler::LoadLists));
65 NewCallback(this, &PasswordsExceptionsHandler::LoadSavedPasswords)); 67 dom_ui_->RegisterMessageCallback("removeSavedPassword",
66 dom_ui_->RegisterMessageCallback( 68 NewCallback(this, &PasswordsExceptionsHandler::RemoveSavedPassword));
67 "removeAutofillable", 69 dom_ui_->RegisterMessageCallback("removePasswordException",
68 NewCallback(this, &PasswordsExceptionsHandler::RemoveEntry)); 70 NewCallback(this, &PasswordsExceptionsHandler::RemovePasswordException));
69 dom_ui_->RegisterMessageCallback( 71 dom_ui_->RegisterMessageCallback("removeAllSavedPasswords",
70 "showSelectedPassword", 72 NewCallback(this, &PasswordsExceptionsHandler::RemoveAllSavedPasswords));
73 dom_ui_->RegisterMessageCallback("removeAllPasswordExceptions", NewCallback(
74 this, &PasswordsExceptionsHandler::RemoveAllPasswordExceptions));
75 dom_ui_->RegisterMessageCallback("showSelectedPassword",
71 NewCallback(this, &PasswordsExceptionsHandler::ShowSelectedPassword)); 76 NewCallback(this, &PasswordsExceptionsHandler::ShowSelectedPassword));
72 } 77 }
73 78
74 PasswordStore* PasswordsExceptionsHandler::GetPasswordStore() { 79 PasswordStore* PasswordsExceptionsHandler::GetPasswordStore() {
75 return profile_->GetPasswordStore(Profile::EXPLICIT_ACCESS); 80 return profile_->GetPasswordStore(Profile::EXPLICIT_ACCESS);
76 } 81 }
77 82
78 void PasswordsExceptionsHandler::LoadSavedPasswords(const ListValue* args) { 83 void PasswordsExceptionsHandler::LoadLists(const ListValue* args) {
84 languages_ = UTF8ToWide(
85 profile_->GetPrefs()->GetString(prefs::kAcceptLanguages));
79 populater_.Populate(); 86 populater_.Populate();
87 exception_populater_.Populate();
80 } 88 }
81 89
82 void PasswordsExceptionsHandler::RemoveEntry(const ListValue* args) { 90 void PasswordsExceptionsHandler::RemoveSavedPassword(const ListValue* args) {
91 std::string string_value = WideToUTF8(ExtractStringValue(args));;
83 int index; 92 int index;
84 CHECK(ExtractIntegerValue(args, &index)); 93 base::StringToInt(string_value, &index);
85 94
86 GetPasswordStore()->RemoveLogin(*password_list_[index]); 95 GetPasswordStore()->RemoveLogin(*password_list_[index]);
87 delete password_list_[index]; 96 delete password_list_[index];
88 password_list_.erase(password_list_.begin() + index); 97 password_list_.erase(password_list_.begin() + index);
89 SetPasswordList(); 98 SetPasswordList();
90 } 99 }
91 100
101 void PasswordsExceptionsHandler::RemovePasswordException(const ListValue* args) {
102 std::string string_value = WideToUTF8(ExtractStringValue(args));;
103 int index;
104 base::StringToInt(string_value, &index);
105
106 GetPasswordStore()->RemoveLogin(*password_exception_list_[index]);
107 delete password_exception_list_[index];
108 password_exception_list_.erase(password_exception_list_.begin() + index);
109 SetPasswordExceptionList();
110 }
111
112 void PasswordsExceptionsHandler::RemoveAllSavedPasswords(
113 const ListValue* args) {
114 PasswordStore* store = GetPasswordStore();
115 for (size_t i = 0; i < password_list_.size(); ++i)
116 store->RemoveLogin(*password_list_[i]);
117 STLDeleteElements(&password_list_);
118 SetPasswordList();
119 }
120
121 void PasswordsExceptionsHandler::RemoveAllPasswordExceptions(
122 const ListValue* args) {
123 PasswordStore* store = GetPasswordStore();
124 for (size_t i = 0; i < password_exception_list_.size(); ++i)
125 store->RemoveLogin(*password_exception_list_[i]);
126 STLDeleteElements(&password_exception_list_);
127 SetPasswordExceptionList();
128 }
129
92 void PasswordsExceptionsHandler::ShowSelectedPassword(const ListValue* args) { 130 void PasswordsExceptionsHandler::ShowSelectedPassword(const ListValue* args) {
131 std::string string_value = WideToUTF8(ExtractStringValue(args));;
93 int index; 132 int index;
94 CHECK(ExtractIntegerValue(args, &index)); 133 base::StringToInt(string_value, &index);
95 134
96 std::string pass = UTF16ToUTF8(password_list_[index]->password_value); 135 std::string pass = UTF16ToUTF8(password_list_[index]->password_value);
97 scoped_ptr<Value> password_string(Value::CreateStringValue(pass)); 136 scoped_ptr<Value> password_string(Value::CreateStringValue(pass));
98 dom_ui_->CallJavascriptFunction( 137 dom_ui_->CallJavascriptFunction(
99 L"PasswordsExceptions.selectedPasswordCallback", *password_string.get()); 138 L"PasswordsExceptions.selectedPasswordCallback", *password_string.get());
100 } 139 }
101 140
102 void PasswordsExceptionsHandler::SetPasswordList() { 141 void PasswordsExceptionsHandler::SetPasswordList() {
103 ListValue autofillableLogins; 142 ListValue entries;
104 std::wstring languages =
105 UTF8ToWide(profile_->GetPrefs()->GetString(prefs::kAcceptLanguages));
106 for (size_t i = 0; i < password_list_.size(); ++i) { 143 for (size_t i = 0; i < password_list_.size(); ++i) {
107 ListValue* entry = new ListValue(); 144 ListValue* entry = new ListValue();
108 entry->Append(new StringValue( 145 entry->Append(new StringValue(
109 WideToUTF8(net::FormatUrl(password_list_[i]->origin, languages)))); 146 WideToUTF8(net::FormatUrl(password_list_[i]->origin, languages_))));
110 entry->Append(new StringValue( 147 entry->Append(new StringValue(
111 UTF16ToUTF8(password_list_[i]->username_value))); 148 UTF16ToUTF8(password_list_[i]->username_value)));
112 autofillableLogins.Append(entry); 149 entries.Append(entry);
113 } 150 }
114 151
115 dom_ui_->CallJavascriptFunction( 152 dom_ui_->CallJavascriptFunction(
116 L"PasswordsExceptions.setAutofillableLogins", autofillableLogins); 153 L"PasswordsExceptions.setSavedPasswordsList", entries);
154 }
155
156 void PasswordsExceptionsHandler::SetPasswordExceptionList() {
157 ListValue entries;
158 for (size_t i = 0; i < password_exception_list_.size(); ++i) {
159 entries.Append(new StringValue(
160 WideToUTF8(net::FormatUrl(
161 password_exception_list_[i]->origin, languages_))));
162 }
163
164 dom_ui_->CallJavascriptFunction(
165 L"PasswordsExceptions.setPasswordExceptionsList", entries);
117 } 166 }
118 167
119 void PasswordsExceptionsHandler::PasswordListPopulater::Populate() { 168 void PasswordsExceptionsHandler::PasswordListPopulater::Populate() {
120 DCHECK(!pending_login_query_); 169 DCHECK(!pending_login_query_);
121 PasswordStore* store = page_->GetPasswordStore(); 170 PasswordStore* store = page_->GetPasswordStore();
122 pending_login_query_ = store->GetAutofillableLogins(this); 171 pending_login_query_ = store->GetAutofillableLogins(this);
123 } 172 }
124 173
125 void PasswordsExceptionsHandler::PasswordListPopulater:: 174 void PasswordsExceptionsHandler::PasswordListPopulater::
126 OnPasswordStoreRequestDone(int handle, 175 OnPasswordStoreRequestDone(int handle,
127 const std::vector<webkit_glue::PasswordForm*>& result) { 176 const std::vector<webkit_glue::PasswordForm*>& result) {
128 DCHECK_EQ(pending_login_query_, handle); 177 DCHECK_EQ(pending_login_query_, handle);
129 pending_login_query_ = 0; 178 pending_login_query_ = 0;
130 page_->password_list_ = result; 179 page_->password_list_ = result;
131 page_->SetPasswordList(); 180 page_->SetPasswordList();
132 } 181 }
182
183 void PasswordsExceptionsHandler::PasswordExceptionListPopulater::Populate() {
184 DCHECK(!pending_login_query_);
185 PasswordStore* store = page_->GetPasswordStore();
186 pending_login_query_ = store->GetBlacklistLogins(this);
187 }
188
189 void PasswordsExceptionsHandler::PasswordExceptionListPopulater::
190 OnPasswordStoreRequestDone(int handle,
191 const std::vector<webkit_glue::PasswordForm*>& result) {
192 DCHECK_EQ(pending_login_query_, handle);
193 pending_login_query_ = 0;
194 page_->password_exception_list_ = result;
195 page_->SetPasswordExceptionList();
196 }
OLDNEW
« no previous file with comments | « chrome/browser/dom_ui/passwords_exceptions_handler.h ('k') | chrome/browser/dom_ui/passwords_remove_all_handler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698