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

Side by Side Diff: components/autofill/content/renderer/password_autofill_agent.cc

Issue 208453002: Add "previewing on hover" support for password field. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Update code as per further review comments. Created 6 years, 7 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "components/autofill/content/renderer/password_autofill_agent.h" 5 #include "components/autofill/content/renderer/password_autofill_agent.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "base/metrics/histogram.h" 10 #include "base/metrics/histogram.h"
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 } // namespace 222 } // namespace
223 223
224 //////////////////////////////////////////////////////////////////////////////// 224 ////////////////////////////////////////////////////////////////////////////////
225 // PasswordAutofillAgent, public: 225 // PasswordAutofillAgent, public:
226 226
227 PasswordAutofillAgent::PasswordAutofillAgent(content::RenderView* render_view) 227 PasswordAutofillAgent::PasswordAutofillAgent(content::RenderView* render_view)
228 : content::RenderViewObserver(render_view), 228 : content::RenderViewObserver(render_view),
229 usernames_usage_(NOTHING_TO_AUTOFILL), 229 usernames_usage_(NOTHING_TO_AUTOFILL),
230 web_view_(render_view->GetWebView()), 230 web_view_(render_view->GetWebView()),
231 logging_state_active_(false), 231 logging_state_active_(false),
232 was_username_autofilled_(false),
233 was_password_autofilled_(false),
234 username_selection_start_(0),
232 weak_ptr_factory_(this) { 235 weak_ptr_factory_(this) {
233 } 236 }
234 237
235 PasswordAutofillAgent::~PasswordAutofillAgent() { 238 PasswordAutofillAgent::~PasswordAutofillAgent() {
236 } 239 }
237 240
238 PasswordAutofillAgent::PasswordValueGatekeeper::PasswordValueGatekeeper() 241 PasswordAutofillAgent::PasswordValueGatekeeper::PasswordValueGatekeeper()
239 : was_user_gesture_seen_(false) { 242 : was_user_gesture_seen_(false) {
240 } 243 }
241 244
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
360 LoginToPasswordInfoMap::iterator iter = login_to_password_info_.find(element); 363 LoginToPasswordInfoMap::iterator iter = login_to_password_info_.find(element);
361 if (iter == login_to_password_info_.end()) 364 if (iter == login_to_password_info_.end())
362 return false; 365 return false;
363 366
364 int win_key_code = event.windowsKeyCode; 367 int win_key_code = event.windowsKeyCode;
365 iter->second.backspace_pressed_last = 368 iter->second.backspace_pressed_last =
366 (win_key_code == ui::VKEY_BACK || win_key_code == ui::VKEY_DELETE); 369 (win_key_code == ui::VKEY_BACK || win_key_code == ui::VKEY_DELETE);
367 return true; 370 return true;
368 } 371 }
369 372
370 bool PasswordAutofillAgent::AcceptSuggestion( 373 bool PasswordAutofillAgent::FillSuggestion(
371 const blink::WebNode& node, 374 const blink::WebNode& node,
372 const blink::WebString& username, 375 const blink::WebString& username,
373 const blink::WebString& password) { 376 const blink::WebString& password) {
374 blink::WebInputElement username_element; 377 blink::WebInputElement username_element;
375 PasswordInfo password_info; 378 PasswordInfo password_info;
376 379
377 if (!FindLoginInfo(node, &username_element, &password_info) || 380 if (!FindLoginInfo(node, &username_element, &password_info) ||
378 !IsElementAutocompletable(username_element) || 381 !IsElementAutocompletable(username_element) ||
379 !IsElementAutocompletable(password_info.password_field)) { 382 !IsElementAutocompletable(password_info.password_field)) {
380 return false; 383 return false;
381 } 384 }
382 385
383 base::string16 current_username = username_element.value(); 386 base::string16 current_username = username_element.value();
384 username_element.setValue(username, true); 387 username_element.setValue(username, true);
385 username_element.setAutofilled(true); 388 username_element.setAutofilled(true);
386 username_element.setSelectionRange(username.length(), username.length()); 389 username_element.setSelectionRange(username.length(), username.length());
387 390
388 password_info.password_field.setValue(password, true); 391 password_info.password_field.setValue(password, true);
389 password_info.password_field.setAutofilled(true); 392 password_info.password_field.setAutofilled(true);
390 393
391 return true; 394 return true;
392 } 395 }
393 396
397 bool PasswordAutofillAgent::PreviewSuggestion(
398 const blink::WebNode& node,
399 const blink::WebString& username,
400 const blink::WebString& password) {
401 blink::WebInputElement username_element;
402 PasswordInfo password_info;
403
404 if (!FindLoginInfo(node, &username_element, &password_info) ||
405 !IsElementAutocompletable(username_element) ||
406 !IsElementAutocompletable(password_info.password_field)) {
407 return false;
408 }
409
410 was_username_autofilled_ = username_element.isAutofilled();
411 username_selection_start_ = username_element.selectionStart();
412 username_element.setSuggestedValue(username);
413 username_element.setAutofilled(true);
414 username_element.setSelectionRange(
415 username_selection_start_,
416 username_element.suggestedValue().length());
417
418 was_password_autofilled_ = password_info.password_field.isAutofilled();
419 password_info.password_field.setSuggestedValue(password);
420 password_info.password_field.setAutofilled(true);
421
422 return true;
423 }
424
394 bool PasswordAutofillAgent::DidClearAutofillSelection( 425 bool PasswordAutofillAgent::DidClearAutofillSelection(
395 const blink::WebNode& node) { 426 const blink::WebNode& node) {
396 blink::WebInputElement input; 427 blink::WebInputElement username_element;
397 PasswordInfo password; 428 PasswordInfo password_info;
398 return FindLoginInfo(node, &input, &password); 429 if (!FindLoginInfo(node, &username_element, &password_info))
430 return false;
431
432 ClearPreview(&username_element, &password_info.password_field);
433 return true;
399 } 434 }
400 435
401 bool PasswordAutofillAgent::ShowSuggestions( 436 bool PasswordAutofillAgent::ShowSuggestions(
402 const blink::WebInputElement& element) { 437 const blink::WebInputElement& element) {
403 LoginToPasswordInfoMap::const_iterator iter = 438 LoginToPasswordInfoMap::const_iterator iter =
404 login_to_password_info_.find(element); 439 login_to_password_info_.find(element);
405 if (iter == login_to_password_info_.end()) 440 if (iter == login_to_password_info_.end())
406 return false; 441 return false;
407 442
408 // If autocomplete='off' is set on the form elements, no suggestion dialog 443 // If autocomplete='off' is set on the form elements, no suggestion dialog
(...skipping 610 matching lines...) Expand 10 before | Expand all | Expand 10 after
1019 blink::WebInputElement input = element.to<blink::WebInputElement>(); 1054 blink::WebInputElement input = element.to<blink::WebInputElement>();
1020 LoginToPasswordInfoMap::iterator iter = login_to_password_info_.find(input); 1055 LoginToPasswordInfoMap::iterator iter = login_to_password_info_.find(input);
1021 if (iter == login_to_password_info_.end()) 1056 if (iter == login_to_password_info_.end())
1022 return false; 1057 return false;
1023 1058
1024 *found_input = input; 1059 *found_input = input;
1025 *found_password = iter->second; 1060 *found_password = iter->second;
1026 return true; 1061 return true;
1027 } 1062 }
1028 1063
1064 void PasswordAutofillAgent::ClearPreview(
1065 blink::WebInputElement* username,
1066 blink::WebInputElement* password) {
1067 if (!username->suggestedValue().isEmpty()) {
1068 username->setSuggestedValue(blink::WebString());
1069 username->setAutofilled(was_username_autofilled_);
1070 username->setSelectionRange(username_selection_start_,
1071 username->value().length());
1072 }
1073 if (!password->suggestedValue().isEmpty()) {
1074 password->setSuggestedValue(blink::WebString());
1075 password->setAutofilled(was_password_autofilled_);
1076 }
1077 }
1078
1029 } // namespace autofill 1079 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698