summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorchocobo@chromium.org <chocobo@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-02-16 19:21:16 +0000
committerchocobo@chromium.org <chocobo@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-02-16 19:21:16 +0000
commitd76bbe9ad18f01d5731d17ec73336709a224fdf1 (patch)
tree37f7128f819c64e3c388d0142aa40f2267d059f3
parent2027bd2c2668f5e3524270ad0aa9ccc9bb4d2e1e (diff)
downloadchromium_src-d76bbe9ad18f01d5731d17ec73336709a224fdf1.zip
chromium_src-d76bbe9ad18f01d5731d17ec73336709a224fdf1.tar.gz
chromium_src-d76bbe9ad18f01d5731d17ec73336709a224fdf1.tar.bz2
For VPN passwords that are not passed back to the UI from flimflam, we show a fake password ******** in the UI. When user focuses on the textfield, we clear it out and replace it when the textfield loses focus and the user has not changed the password.
BUG=chromium-os:24685 TEST=manual Review URL: https://chromiumcodereview.appspot.com/9406003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@122331 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/chromeos/cros/network_library.cc37
-rw-r--r--chrome/browser/chromeos/options/passphrase_textfield.cc45
-rw-r--r--chrome/browser/chromeos/options/passphrase_textfield.h34
-rw-r--r--chrome/browser/chromeos/options/vpn_config_view.cc21
-rw-r--r--chrome/browser/chromeos/options/vpn_config_view.h11
-rw-r--r--chrome/chrome_browser.gypi2
6 files changed, 126 insertions, 24 deletions
diff --git a/chrome/browser/chromeos/cros/network_library.cc b/chrome/browser/chromeos/cros/network_library.cc
index e770515..068b596 100644
--- a/chrome/browser/chromeos/cros/network_library.cc
+++ b/chrome/browser/chromeos/cros/network_library.cc
@@ -826,11 +826,15 @@ void VirtualNetwork::SetL2TPIPsecPSKCredentials(
const std::string& username,
const std::string& user_passphrase,
const std::string& group_name) {
- SetStringProperty(flimflam::kL2tpIpsecPskProperty,
- psk_passphrase, &psk_passphrase_);
+ if (!psk_passphrase.empty()) {
+ SetStringProperty(flimflam::kL2tpIpsecPskProperty,
+ psk_passphrase, &psk_passphrase_);
+ }
SetStringProperty(flimflam::kL2tpIpsecUserProperty, username, &username_);
- SetStringProperty(flimflam::kL2tpIpsecPasswordProperty,
- user_passphrase, &user_passphrase_);
+ if (!user_passphrase.empty()) {
+ SetStringProperty(flimflam::kL2tpIpsecPasswordProperty,
+ user_passphrase, &user_passphrase_);
+ }
SetStringProperty(flimflam::kL2tpIpsecGroupNameProperty,
group_name, &group_name_);
}
@@ -843,8 +847,10 @@ void VirtualNetwork::SetL2TPIPsecCertCredentials(
SetStringProperty(flimflam::kL2tpIpsecClientCertIdProperty,
client_cert_id, &client_cert_id_);
SetStringProperty(flimflam::kL2tpIpsecUserProperty, username, &username_);
- SetStringProperty(flimflam::kL2tpIpsecPasswordProperty,
- user_passphrase, &user_passphrase_);
+ if (!user_passphrase.empty()) {
+ SetStringProperty(flimflam::kL2tpIpsecPasswordProperty,
+ user_passphrase, &user_passphrase_);
+ }
SetStringProperty(flimflam::kL2tpIpsecGroupNameProperty,
group_name, &group_name_);
}
@@ -5283,16 +5289,25 @@ void NetworkLibraryImplStub::Init() {
" \"NetworkConfigurations\": ["
" {"
" \"GUID\": \"guid\","
- " \"Type\": \"WiFi\","
- " \"WiFi\": {"
- " \"Security\": \"WEP\","
- " \"SSID\": \"MySSID\","
+ " \"Type\": \"VPN\","
+ " \"Name\": \"VPNtest\","
+ " \"VPN\": {"
+ " \"Host\": \"172.22.12.98\","
+ " \"Type\": \"L2TP-IPsec\","
+ " \"IPsec\": {"
+ " \"AuthenticationType\": \"PSK\","
+ " \"IKEVersion\": 2,"
+ " \"PSK\": \"chromeos\","
+ " },"
+ " \"L2TP\": {"
+ " \"Username\": \"vpntest\","
+ " }"
" }"
" }"
" ],"
" \"Certificates\": []"
"}");
- LoadOncNetworks(test_blob, "", NetworkUIData::ONC_SOURCE_USER_IMPORT, NULL);
+// LoadOncNetworks(test_blob, "", NetworkUIData::ONC_SOURCE_USER_IMPORT, NULL);
}
////////////////////////////////////////////////////////////////////////////
diff --git a/chrome/browser/chromeos/options/passphrase_textfield.cc b/chrome/browser/chromeos/options/passphrase_textfield.cc
new file mode 100644
index 0000000..e7b3614
--- /dev/null
+++ b/chrome/browser/chromeos/options/passphrase_textfield.cc
@@ -0,0 +1,45 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/chromeos/options/passphrase_textfield.h"
+
+#include "base/utf_string_conversions.h"
+
+namespace chromeos {
+
+// String to use as password if the password is set but not available in the UI.
+// User will see this as ********
+const string16 kFakePassphrase = ASCIIToUTF16("********");
+
+PassphraseTextfield::PassphraseTextfield(bool show_fake)
+ : Textfield(views::Textfield::STYLE_OBSCURED),
+ show_fake_(show_fake),
+ changed_(true) {
+ if (show_fake_) {
+ SetText(kFakePassphrase);
+ changed_ = false;
+ }
+}
+
+void PassphraseTextfield::OnFocus() {
+ // If showing the fake password, then clear it when focused.
+ if (show_fake_ && !changed_) {
+ SetText(string16());
+ changed_ = true;
+ }
+}
+
+void PassphraseTextfield::OnBlur() {
+ // If passowrd is not changed, then show the fake password when blurred.
+ if (show_fake_ && text().empty()) {
+ SetText(kFakePassphrase);
+ changed_ = false;
+ }
+}
+
+std::string PassphraseTextfield::GetPassphrase() {
+ return changed_ ? UTF16ToUTF8(text()) : std::string();
+}
+
+} // namespace chromeos
diff --git a/chrome/browser/chromeos/options/passphrase_textfield.h b/chrome/browser/chromeos/options/passphrase_textfield.h
new file mode 100644
index 0000000..9eb46e8
--- /dev/null
+++ b/chrome/browser/chromeos/options/passphrase_textfield.h
@@ -0,0 +1,34 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_CHROMEOS_OPTIONS_PASSPHRASE_TEXTFIELD_H_
+#define CHROME_BROWSER_CHROMEOS_OPTIONS_PASSPHRASE_TEXTFIELD_H_
+#pragma once
+
+#include "ui/views/controls/textfield/textfield.h"
+
+namespace chromeos {
+
+class PassphraseTextfield : public views::Textfield {
+ public:
+ // If show_already_set is true, then the text field will show a fake password.
+ explicit PassphraseTextfield(bool show_fake);
+
+ // Override views::Textfield so that when focus is gained, then clear out the
+ // fake password if appropriate. Replace it when focus is lost if the user has
+ // not typed in a new password.
+ virtual void OnFocus();
+ virtual void OnBlur();
+
+ // Returns the passphrase. If it's unchanged, then returns an empty string.
+ std::string GetPassphrase();
+
+ private:
+ bool show_fake_;
+ bool changed_;
+};
+
+} // namespace chromeos
+
+#endif // CHROME_BROWSER_CHROMEOS_OPTIONS_PASSPHRASE_TEXTFIELD_H_
diff --git a/chrome/browser/chromeos/options/vpn_config_view.cc b/chrome/browser/chromeos/options/vpn_config_view.cc
index efa457b..f9654d1 100644
--- a/chrome/browser/chromeos/options/vpn_config_view.cc
+++ b/chrome/browser/chromeos/options/vpn_config_view.cc
@@ -325,7 +325,7 @@ const std::string VPNConfigView::GetPSKPassphrase() const {
if (psk_passphrase_textfield_ &&
enable_psk_passphrase_ &&
psk_passphrase_textfield_->visible())
- return GetTextFromField(psk_passphrase_textfield_, false);
+ return GetPassphraseFromField(psk_passphrase_textfield_);
return std::string();
}
@@ -334,7 +334,7 @@ const std::string VPNConfigView::GetUsername() const {
}
const std::string VPNConfigView::GetUserPassphrase() const {
- return GetTextFromField(user_passphrase_textfield_, false);
+ return GetPassphraseFromField(user_passphrase_textfield_);
}
const std::string VPNConfigView::GetGroupName() const {
@@ -481,11 +481,8 @@ void VPNConfigView::Init(VirtualNetwork* vpn) {
psk_passphrase_label_ = new views::Label(l10n_util::GetStringUTF16(
IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_VPN_PSK_PASSPHRASE));
layout->AddView(psk_passphrase_label_);
- psk_passphrase_textfield_ = new views::Textfield(
- views::Textfield::STYLE_OBSCURED);
+ psk_passphrase_textfield_ = new PassphraseTextfield(vpn);
psk_passphrase_textfield_->SetController(this);
- if (vpn && !vpn->psk_passphrase().empty())
- psk_passphrase_textfield_->SetText(UTF8ToUTF16(vpn->psk_passphrase()));
layout->AddView(psk_passphrase_textfield_);
layout->AddView(
new ControlledSettingIndicatorView(psk_passphrase_ui_data_));
@@ -549,12 +546,9 @@ void VPNConfigView::Init(VirtualNetwork* vpn) {
layout->StartRow(0, column_view_set_id);
layout->AddView(new views::Label(l10n_util::GetStringUTF16(
IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_VPN_USER_PASSPHRASE)));
- user_passphrase_textfield_ = new views::Textfield(
- views::Textfield::STYLE_OBSCURED);
+ user_passphrase_textfield_ = new PassphraseTextfield(vpn);
user_passphrase_textfield_->SetController(this);
user_passphrase_textfield_->SetEnabled(user_passphrase_ui_data_.editable());
- if (vpn && !vpn->user_passphrase().empty())
- user_passphrase_textfield_->SetText(UTF8ToUTF16(vpn->user_passphrase()));
layout->AddView(user_passphrase_textfield_);
layout->AddView(new ControlledSettingIndicatorView(user_passphrase_ui_data_));
layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing);
@@ -785,6 +779,13 @@ const std::string VPNConfigView::GetTextFromField(
return result;
}
+const std::string VPNConfigView::GetPassphraseFromField(
+ PassphraseTextfield* textfield) const {
+ if (!textfield)
+ return std::string();
+ return textfield->GetPassphrase();
+}
+
void VPNConfigView::ParseVPNUIProperty(NetworkPropertyUIData* property_ui_data,
Network* network,
const std::string& key) {
diff --git a/chrome/browser/chromeos/options/vpn_config_view.h b/chrome/browser/chromeos/options/vpn_config_view.h
index 152b140..defb407 100644
--- a/chrome/browser/chromeos/options/vpn_config_view.h
+++ b/chrome/browser/chromeos/options/vpn_config_view.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -11,6 +11,7 @@
#include "base/string16.h"
#include "chrome/browser/chromeos/cros/cert_library.h"
#include "chrome/browser/chromeos/options/network_config_view.h"
+#include "chrome/browser/chromeos/options/passphrase_textfield.h"
#include "chrome/browser/ui/select_file_dialog.h"
#include "ui/views/controls/button/button.h"
#include "ui/views/controls/combobox/combobox_listener.h"
@@ -87,6 +88,10 @@ class VPNConfigView : public ChildNetworkConfigView,
const std::string GetTextFromField(views::Textfield* textfield,
bool trim_whitespace) const;
+ // Get passphrase from input field.
+ const std::string GetPassphraseFromField(
+ PassphraseTextfield* textfield) const;
+
// Convenience methods to get text from input field or cached VirtualNetwork.
const std::string GetService() const;
const std::string GetServer() const;
@@ -133,13 +138,13 @@ class VPNConfigView : public ChildNetworkConfigView,
views::Combobox* provider_type_combobox_;
views::Label* provider_type_text_label_;
views::Label* psk_passphrase_label_;
- views::Textfield* psk_passphrase_textfield_;
+ PassphraseTextfield* psk_passphrase_textfield_;
views::Label* user_cert_label_;
views::Combobox* user_cert_combobox_;
views::Label* server_ca_cert_label_;
views::Combobox* server_ca_cert_combobox_;
views::Textfield* username_textfield_;
- views::Textfield* user_passphrase_textfield_;
+ PassphraseTextfield* user_passphrase_textfield_;
views::Label* otp_label_;
views::Textfield* otp_textfield_;
views::Label* group_name_label_;
diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi
index 432b6a8..4eccbef 100644
--- a/chrome/chrome_browser.gypi
+++ b/chrome/chrome_browser.gypi
@@ -726,6 +726,8 @@
'browser/chromeos/offline/offline_load_page.h',
'browser/chromeos/options/network_config_view.cc',
'browser/chromeos/options/network_config_view.h',
+ 'browser/chromeos/options/passphrase_textfield.cc',
+ 'browser/chromeos/options/passphrase_textfield.h',
'browser/chromeos/options/take_photo_dialog.cc',
'browser/chromeos/options/take_photo_dialog.h',
'browser/chromeos/options/vpn_config_view.cc',