summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authorsargrass@google.com <sargrass@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2010-08-16 23:28:52 +0000
committersargrass@google.com <sargrass@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2010-08-16 23:28:52 +0000
commit096187877f7caa78f0557d92909a85c76266dcde (patch)
tree26f38d7c5a3fea0e5655e781215cbc03bfbf9f57 /chrome
parent69fe7af6d2ffcc52d4539d624eca48524e7ca2b3 (diff)
downloadchromium_src-096187877f7caa78f0557d92909a85c76266dcde.zip
chromium_src-096187877f7caa78f0557d92909a85c76266dcde.tar.gz
chromium_src-096187877f7caa78f0557d92909a85c76266dcde.tar.bz2
Get saved passwords when click the "show saved passwords" button on personal stuff page.
Remove the trigger for showing list. Make the remove button work. BUG=49093 TEST=None Review URL: http://codereview.chromium.org/3137011 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@56261 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/dom_ui/passwords_exceptions_handler.cc79
-rw-r--r--chrome/browser/dom_ui/passwords_exceptions_handler.h14
-rw-r--r--chrome/browser/resources/options/import_data_overlay.js6
-rw-r--r--chrome/browser/resources/options/passwords_exceptions.html1
-rw-r--r--chrome/browser/resources/options/passwords_exceptions.js20
-rw-r--r--chrome/browser/resources/options/passwords_exceptions_list.js39
-rw-r--r--chrome/browser/resources/options/personal_options.js4
7 files changed, 140 insertions, 23 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();
}
diff --git a/chrome/browser/dom_ui/passwords_exceptions_handler.h b/chrome/browser/dom_ui/passwords_exceptions_handler.h
index d211130..1738125 100644
--- a/chrome/browser/dom_ui/passwords_exceptions_handler.h
+++ b/chrome/browser/dom_ui/passwords_exceptions_handler.h
@@ -25,9 +25,20 @@ class PasswordsExceptionsHandler : public OptionsPageUIHandler {
// The password store associated with the currently active profile.
PasswordStore* GetPasswordStore();
+ // Fired when user clicks 'show saved passwords' button in personal page.
+ void LoadSavedPasswords(const Value* value);
+
+ // Remove an entry.
+ // @param value the entry index to be removed.
+ void RemoveEntry(const Value* value);
+
+ // Get password value for the selected entry.
+ // @param value the selected entry index.
+ void ShowSelectedPassword(const Value* value);
+
// Sets the password list contents to the given data. We take ownership of
// the PasswordForms in the vector.
- void SetPasswordList(const std::vector<webkit_glue::PasswordForm*>& result);
+ void SetPasswordList();
// A short class to mediate requests to the password store.
class PasswordListPopulater : public PasswordStoreConsumer {
@@ -52,6 +63,7 @@ class PasswordsExceptionsHandler : public OptionsPageUIHandler {
// Password store consumer for populating the password list.
PasswordListPopulater populater_;
+ // A weak reference to profile.
Profile* profile_;
std::vector<webkit_glue::PasswordForm*> password_list_;
diff --git a/chrome/browser/resources/options/import_data_overlay.js b/chrome/browser/resources/options/import_data_overlay.js
index 8bca170..3bec1c2 100644
--- a/chrome/browser/resources/options/import_data_overlay.js
+++ b/chrome/browser/resources/options/import_data_overlay.js
@@ -111,7 +111,7 @@ cr.define('options', function() {
ImportDataOverlay.updateSupportedBrowsers = function(browsers) {
ImportDataOverlay.getInstance().updateSupportedBrowsers_(browsers);
- }
+ };
ImportDataOverlay.setDisable = function(state) {
$('supported-browsers').disabled = state;
@@ -120,7 +120,7 @@ cr.define('options', function() {
$('import-passwords').disabled = state;
$('import-history').disabled = state;
$('import-data-commit').disabled = state;
- }
+ };
ImportDataOverlay.setImportingState = function(state) {
ImportDataOverlay.setDisable(state);
@@ -138,7 +138,7 @@ cr.define('options', function() {
} else {
clearInterval(ImportDataOverlay.throbIntervalId);
}
- }
+ };
ImportDataOverlay.dismiss = function() {
OptionsPage.clearOverlays();
diff --git a/chrome/browser/resources/options/passwords_exceptions.html b/chrome/browser/resources/options/passwords_exceptions.html
index 47a02f0..fe7b7bd 100644
--- a/chrome/browser/resources/options/passwords_exceptions.html
+++ b/chrome/browser/resources/options/passwords_exceptions.html
@@ -17,7 +17,6 @@
<!-- Passwords tab contents -->
<div id="passwordsTab" class="subpages-tab-contents">
<section>
- <button id="trigger" i18n-content="passwordsTabTitle"></button>
<div id="passwordsArea">
<list id="autofillableLoginsList"></list>
</div>
diff --git a/chrome/browser/resources/options/passwords_exceptions.js b/chrome/browser/resources/options/passwords_exceptions.js
index 14ec9c9..3a979be 100644
--- a/chrome/browser/resources/options/passwords_exceptions.js
+++ b/chrome/browser/resources/options/passwords_exceptions.js
@@ -31,10 +31,6 @@ cr.define('options', function() {
options.passwordsExceptions.ListArea.decorate($('passwordsArea'));
// TODO(sargrass): Passwords filter page --------------------------
- $('trigger').onclick = function(event) {
- autofillableLoginsList.redraw();
- // TODO(sargrass): Remove this element.
- };
// TODO(sargrass): Exceptions filter page -------------------------
@@ -48,10 +44,26 @@ cr.define('options', function() {
},
};
+ PasswordsExceptions.load = function() {
+ chrome.send('loadSavedPasswords');
+ };
+
+ PasswordsExceptions.removeAutofillable = function(index) {
+ chrome.send('removeAutofillable', [String(index)]);
+ };
+
+ PasswordsExceptions.showSelectedPassword = function(index) {
+ chrome.send('showSelectedPassword', [String(index)]);
+ };
+
PasswordsExceptions.setAutofillableLogins = function(entries) {
PasswordsExceptions.getInstance().setAutofillableLogins_(entries);
};
+ PasswordsExceptions.selectedPasswordCallback = function(password) {
+ passwordsArea.displayReturnedPassword(password);
+ };
+
// Export
return {
PasswordsExceptions: PasswordsExceptions
diff --git a/chrome/browser/resources/options/passwords_exceptions_list.js b/chrome/browser/resources/options/passwords_exceptions_list.js
index b9a826a..8bf232e 100644
--- a/chrome/browser/resources/options/passwords_exceptions_list.js
+++ b/chrome/browser/resources/options/passwords_exceptions_list.js
@@ -114,9 +114,15 @@ cr.define('options.passwordsExceptions', function() {
* Remove selected row from browser's model.
*/
removeSelectedRow: function() {
- var selectedItem = this.selectedItem;
- chrome.send('removeAutofillable', selectedItem[0]);
+ var selectedIndex = this.selectionModel.selectedIndex;
+ PasswordsExceptions.removeAutofillable(selectedIndex);
},
+
+ showSelectedPassword: function() {
+ var selectedIndex = this.selectionModel.selectedIndex;
+ PasswordsExceptions.showSelectedPassword(selectedIndex);
+ },
+
};
var ListArea = cr.ui.define('div');
@@ -137,11 +143,32 @@ cr.define('options.passwordsExceptions', function() {
this.appendChild(removeRow);
this.removeRow = removeRow;
+ var showHidePassword = cr.doc.createElement('button');
+ showHidePassword.textContent = templateData.passwordsShowButton;
+ this.appendChild(showHidePassword);
+ this.showHidePassword = showHidePassword;
+ this.showingPassword = false
+
+ var passwordLabel = cr.doc.createElement('span');
+ this.appendChild(passwordLabel);
+ this.passwordLabel = passwordLabel;
+
var self = this;
removeRow.onclick = function(event) {
self.passwordsList.removeSelectedRow();
};
+ showHidePassword.onclick = function(event) {
+ if(self.showingPassword) {
+ self.passwordLabel.textContent = "";
+ this.textContent = templateData.passwordsShowButton;
+ } else {
+ self.passwordsList.showSelectedPassword();
+ this.textContent = templateData.passwordsHideButton;
+ }
+ self.showingPassword = !self.showingPassword;
+ };
+
this.updateButtonSensitivity();
},
@@ -156,12 +183,17 @@ cr.define('options.passwordsExceptions', function() {
return this.getAttribute('contentType', type);
},
+ displayReturnedPassword: function(password) {
+ this.passwordLabel.textContent = password;
+ },
+
/**
* Update the button's states
*/
updateButtonSensitivity: function() {
var selectionSize = autofillableLoginsList.selectedItems.length;
this.removeRow.disabled = selectionSize == 0;
+ this.showHidePassword.disabled = selectionSize == 0;
},
/**
@@ -170,6 +202,9 @@ cr.define('options.passwordsExceptions', function() {
* @private
*/
handleOnSelectionChange_: function(ce) {
+ this.passwordLabel.textContent = "";
+ this.showHidePassword.textContent = templateData.passwordsShowButton;
+ this.showingPassword = false;
this.updateButtonSensitivity();
},
};
diff --git a/chrome/browser/resources/options/personal_options.js b/chrome/browser/resources/options/personal_options.js
index 58e2b9b..04c3b08 100644
--- a/chrome/browser/resources/options/personal_options.js
+++ b/chrome/browser/resources/options/personal_options.js
@@ -54,9 +54,9 @@ cr.define('options', function() {
$('showpasswords').onclick = function(event) {
//TODO(sargrass): Add the Mac implementation
}
- }
- else {
+ } else {
$('showpasswords').onclick = function(event) {
+ PasswordsExceptions.load();
OptionsPage.showPageByName('passwordsExceptions');
OptionsPage.showTab($('passwords-nav-tab'));
};