summaryrefslogtreecommitdiffstats
path: root/chrome/views/controls
diff options
context:
space:
mode:
authorjcampan@chromium.org <jcampan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-04-10 18:32:52 +0000
committerjcampan@chromium.org <jcampan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-04-10 18:32:52 +0000
commit13619fbbb3bef81f1373e92a45878cf776460b03 (patch)
treed543c6764103395b0cc3efa17c01a672ca40f15c /chrome/views/controls
parent863e1409a83ec7b3849754c1dbf365d44505a147 (diff)
downloadchromium_src-13619fbbb3bef81f1373e92a45878cf776460b03.zip
chromium_src-13619fbbb3bef81f1373e92a45878cf776460b03.tar.gz
chromium_src-13619fbbb3bef81f1373e92a45878cf776460b03.tar.bz2
Make sure one cannot cut or copy from a password
text-field. And assorted unit-tests. BUG=9425 TEST=Visit a page with basic auth (ex: http://prism.library.cornell.edu/control/authBasic/authTest/). Type some text in the password field. Select the text and try to cut/copy with CTRL-X, CTRL-V and right click menu. You should not be able to cut/copy the text. Review URL: http://codereview.chromium.org/63053 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@13520 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/views/controls')
-rw-r--r--chrome/views/controls/text_field.cc14
-rw-r--r--chrome/views/controls/text_field.h2
2 files changed, 13 insertions, 3 deletions
diff --git a/chrome/views/controls/text_field.cc b/chrome/views/controls/text_field.cc
index 5114d83c..1485427 100644
--- a/chrome/views/controls/text_field.cc
+++ b/chrome/views/controls/text_field.cc
@@ -375,8 +375,9 @@ void TextField::Edit::SetBackgroundColor(COLORREF bg_color) {
bool TextField::Edit::IsCommandEnabled(int id) const {
switch (id) {
case IDS_UNDO: return !parent_->IsReadOnly() && !!CanUndo();
- case IDS_CUT: return !parent_->IsReadOnly() && !!CanCut();
- case IDS_COPY: return !!CanCopy();
+ case IDS_CUT: return !parent_->IsReadOnly() &&
+ !parent_->IsPassword() && !!CanCut();
+ case IDS_COPY: return !!CanCopy() && !parent_->IsPassword();
case IDS_PASTE: return !parent_->IsReadOnly() && !!CanPaste();
case IDS_SELECT_ALL: return !!CanSelectAll();
default: NOTREACHED();
@@ -412,6 +413,9 @@ void TextField::Edit::OnContextMenu(HWND window, const CPoint& point) {
}
void TextField::Edit::OnCopy() {
+ if (parent_->IsPassword())
+ return;
+
const std::wstring text(GetSelectedText());
if (!text.empty()) {
@@ -427,7 +431,7 @@ LRESULT TextField::Edit::OnCreate(CREATESTRUCT* create_struct) {
}
void TextField::Edit::OnCut() {
- if (parent_->IsReadOnly())
+ if (parent_->IsReadOnly() || parent_->IsPassword())
return;
OnCopy();
@@ -1032,6 +1036,10 @@ bool TextField::IsReadOnly() const {
return edit_ ? ((edit_->GetStyle() & ES_READONLY) != 0) : read_only_;
}
+bool TextField::IsPassword() const {
+ return GetStyle() & TextField::STYLE_PASSWORD;
+}
+
bool TextField::IsMultiLine() const {
return (style_ & STYLE_MULTILINE) != 0;
}
diff --git a/chrome/views/controls/text_field.h b/chrome/views/controls/text_field.h
index 2447e92..ffa5469 100644
--- a/chrome/views/controls/text_field.h
+++ b/chrome/views/controls/text_field.h
@@ -84,6 +84,8 @@ class TextField : public View {
void SetReadOnly(bool read_only);
bool IsReadOnly() const;
+ bool IsPassword() const;
+
// Whether the text field is multi-line or not, must be set when the text
// field is created, using StyleFlags.
bool IsMultiLine() const;