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

Side by Side Diff: ui/views/controls/textfield/textfield.cc

Issue 2358463002: Views::Textfield: Prevent revealing password text. (Closed)
Patch Set: Address review comments. Created 4 years, 3 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
« no previous file with comments | « ui/views/controls/textfield/textfield.h ('k') | ui/views/controls/textfield/textfield_model.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "ui/views/controls/textfield/textfield.h" 5 #include "ui/views/controls/textfield/textfield.h"
6 6
7 #include <string> 7 #include <string>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/trace_event/trace_event.h" 10 #include "base/trace_event/trace_event.h"
(...skipping 1556 matching lines...) Expand 10 before | Expand all | Expand 10 after
1567 1567
1568 bool add_to_kill_buffer = false; 1568 bool add_to_kill_buffer = false;
1569 1569
1570 // Some codepaths may bypass GetCommandForKeyEvent, so any selection-dependent 1570 // Some codepaths may bypass GetCommandForKeyEvent, so any selection-dependent
1571 // modifications of the command should happen here. 1571 // modifications of the command should happen here.
1572 switch (command) { 1572 switch (command) {
1573 case ui::TextEditCommand::DELETE_TO_BEGINNING_OF_LINE: 1573 case ui::TextEditCommand::DELETE_TO_BEGINNING_OF_LINE:
1574 case ui::TextEditCommand::DELETE_TO_BEGINNING_OF_PARAGRAPH: 1574 case ui::TextEditCommand::DELETE_TO_BEGINNING_OF_PARAGRAPH:
1575 case ui::TextEditCommand::DELETE_TO_END_OF_LINE: 1575 case ui::TextEditCommand::DELETE_TO_END_OF_LINE:
1576 case ui::TextEditCommand::DELETE_TO_END_OF_PARAGRAPH: 1576 case ui::TextEditCommand::DELETE_TO_END_OF_PARAGRAPH:
1577 add_to_kill_buffer = true; 1577 add_to_kill_buffer = text_input_type_ != ui::TEXT_INPUT_TYPE_PASSWORD;
1578 // Fall through. 1578 // Fall through.
1579 case ui::TextEditCommand::DELETE_WORD_BACKWARD: 1579 case ui::TextEditCommand::DELETE_WORD_BACKWARD:
1580 case ui::TextEditCommand::DELETE_WORD_FORWARD: 1580 case ui::TextEditCommand::DELETE_WORD_FORWARD:
1581 if (HasSelection()) 1581 if (HasSelection())
1582 command = ui::TextEditCommand::DELETE_FORWARD; 1582 command = ui::TextEditCommand::DELETE_FORWARD;
1583 break; 1583 break;
1584 default: 1584 default:
1585 break; 1585 break;
1586 } 1586 }
1587 1587
(...skipping 412 matching lines...) Expand 10 before | Expand all | Expand 10 after
2000 if (!touch_selection_controller_) { 2000 if (!touch_selection_controller_) {
2001 touch_selection_controller_.reset( 2001 touch_selection_controller_.reset(
2002 ui::TouchEditingControllerDeprecated::Create(this)); 2002 ui::TouchEditingControllerDeprecated::Create(this));
2003 } 2003 }
2004 if (touch_selection_controller_) 2004 if (touch_selection_controller_)
2005 touch_selection_controller_->SelectionChanged(); 2005 touch_selection_controller_->SelectionChanged();
2006 } 2006 }
2007 2007
2008 void Textfield::UpdateSelectionClipboard() const { 2008 void Textfield::UpdateSelectionClipboard() const {
2009 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) 2009 #if defined(OS_LINUX) && !defined(OS_CHROMEOS)
2010 if (performing_user_action_ && HasSelection()) { 2010 if (performing_user_action_ && HasSelection() &&
2011 text_input_type_ != ui::TEXT_INPUT_TYPE_PASSWORD) {
2011 ui::ScopedClipboardWriter( 2012 ui::ScopedClipboardWriter(
2012 ui::CLIPBOARD_TYPE_SELECTION).WriteText(GetSelectedText()); 2013 ui::CLIPBOARD_TYPE_SELECTION).WriteText(GetSelectedText());
2013 if (controller_) 2014 if (controller_)
2014 controller_->OnAfterCutOrCopy(ui::CLIPBOARD_TYPE_SELECTION); 2015 controller_->OnAfterCutOrCopy(ui::CLIPBOARD_TYPE_SELECTION);
2015 } 2016 }
2016 #endif 2017 #endif
2017 } 2018 }
2018 2019
2019 void Textfield::PasteSelectionClipboard(const ui::MouseEvent& event) { 2020 void Textfield::PasteSelectionClipboard(const ui::MouseEvent& event) {
2020 DCHECK(event.IsOnlyMiddleMouseButton()); 2021 DCHECK(event.IsOnlyMiddleMouseButton());
2021 DCHECK(!read_only()); 2022 DCHECK(!read_only());
2022 base::string16 selection_clipboard_text = GetSelectionClipboardText(); 2023 base::string16 selection_clipboard_text = GetSelectionClipboardText();
2023 OnBeforeUserAction(); 2024 OnBeforeUserAction();
2024 const gfx::SelectionModel mouse = 2025 const gfx::SelectionModel mouse =
2025 GetRenderText()->FindCursorPosition(event.location()); 2026 GetRenderText()->FindCursorPosition(event.location());
2026 if (!HasFocus()) 2027 if (!HasFocus())
2027 RequestFocus(); 2028 RequestFocus();
2028 model_->MoveCursorTo(mouse); 2029 model_->MoveCursorTo(mouse);
2029 if (!selection_clipboard_text.empty()) { 2030 if (!selection_clipboard_text.empty()) {
2030 model_->InsertText(selection_clipboard_text); 2031 model_->InsertText(selection_clipboard_text);
2031 UpdateAfterChange(true, true); 2032 UpdateAfterChange(true, true);
2032 } 2033 }
2033 OnAfterUserAction(); 2034 OnAfterUserAction();
2034 } 2035 }
2035 2036
2036 } // namespace views 2037 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/controls/textfield/textfield.h ('k') | ui/views/controls/textfield/textfield_model.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698