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

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 Ilya's further comments after rebasing. 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),
232 weak_ptr_factory_(this) { 234 weak_ptr_factory_(this) {
233 } 235 }
234 236
235 PasswordAutofillAgent::~PasswordAutofillAgent() { 237 PasswordAutofillAgent::~PasswordAutofillAgent() {
236 } 238 }
237 239
238 PasswordAutofillAgent::PasswordValueGatekeeper::PasswordValueGatekeeper() 240 PasswordAutofillAgent::PasswordValueGatekeeper::PasswordValueGatekeeper()
239 : was_user_gesture_seen_(false) { 241 : was_user_gesture_seen_(false) {
240 } 242 }
241 243
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
360 LoginToPasswordInfoMap::iterator iter = login_to_password_info_.find(element); 362 LoginToPasswordInfoMap::iterator iter = login_to_password_info_.find(element);
361 if (iter == login_to_password_info_.end()) 363 if (iter == login_to_password_info_.end())
362 return false; 364 return false;
363 365
364 int win_key_code = event.windowsKeyCode; 366 int win_key_code = event.windowsKeyCode;
365 iter->second.backspace_pressed_last = 367 iter->second.backspace_pressed_last =
366 (win_key_code == ui::VKEY_BACK || win_key_code == ui::VKEY_DELETE); 368 (win_key_code == ui::VKEY_BACK || win_key_code == ui::VKEY_DELETE);
367 return true; 369 return true;
368 } 370 }
369 371
370 bool PasswordAutofillAgent::AcceptSuggestion( 372 bool PasswordAutofillAgent::FillSuggestion(
371 const blink::WebNode& node, 373 const blink::WebNode& node,
372 const blink::WebString& username, 374 const blink::WebString& username,
373 const blink::WebString& password) { 375 const blink::WebString& password) {
374 blink::WebInputElement username_element; 376 blink::WebInputElement username_element;
375 PasswordInfo password_info; 377 PasswordInfo password_info;
376 378
377 if (!FindLoginInfo(node, &username_element, &password_info) || 379 if (!FindLoginInfo(node, &username_element, &password_info) ||
378 !IsElementAutocompletable(username_element) || 380 !IsElementAutocompletable(username_element) ||
379 !IsElementAutocompletable(password_info.password_field)) { 381 !IsElementAutocompletable(password_info.password_field)) {
380 return false; 382 return false;
381 } 383 }
382 384
383 base::string16 current_username = username_element.value(); 385 base::string16 current_username = username_element.value();
384 username_element.setValue(username, true); 386 username_element.setValue(username, true);
385 username_element.setAutofilled(true); 387 username_element.setAutofilled(true);
386 username_element.setSelectionRange(username.length(), username.length()); 388 username_element.setSelectionRange(username.length(), username.length());
387 389
388 password_info.password_field.setValue(password, true); 390 password_info.password_field.setValue(password, true);
389 password_info.password_field.setAutofilled(true); 391 password_info.password_field.setAutofilled(true);
390 392
391 return true; 393 return true;
392 } 394 }
393 395
396 bool PasswordAutofillAgent::PreviewSuggestion(
397 const blink::WebNode& node,
398 const blink::WebString& username,
399 const blink::WebString& password) {
400 blink::WebInputElement username_element;
401 PasswordInfo password_info;
402
403 if (!FindLoginInfo(node, &username_element, &password_info) ||
404 !IsElementAutocompletable(username_element) ||
405 !IsElementAutocompletable(password_info.password_field)) {
406 return false;
407 }
408
409 was_username_autofilled_ = username_element.isAutofilled();
410 username_element.setSuggestedValue(username);
411 username_element.setAutofilled(true);
412 // Selection range starts from the end of matching characters between the
413 // value and sugggestedValue of the username field.
414 std::string value_string = username_element.value().utf8();
415 std::string suggested_string = username_element.suggestedValue().utf8();
416 size_t selection_start = 0;
417 bool done_compare = false;
418 while (done_compare == false) {
419 if (selection_start == value_string.length() ||
420 selection_start == suggested_string.length())
421 done_compare = true;
422
423 if (value_string[selection_start] == suggested_string[selection_start])
424 selection_start++;
425 else
426 done_compare = true;
427 }
428 username_element.setSelectionRange(
429 selection_start,
430 username_element.suggestedValue().length());
431
432 was_password_autofilled_ = password_info.password_field.isAutofilled();
433 password_info.password_field.setSuggestedValue(password);
434 password_info.password_field.setAutofilled(true);
435
436 return true;
437 }
438
394 bool PasswordAutofillAgent::DidClearAutofillSelection( 439 bool PasswordAutofillAgent::DidClearAutofillSelection(
395 const blink::WebNode& node) { 440 const blink::WebNode& node) {
396 blink::WebInputElement input; 441 blink::WebInputElement username_element;
397 PasswordInfo password; 442 PasswordInfo password_info;
398 return FindLoginInfo(node, &input, &password); 443 if (!FindLoginInfo(node, &username_element, &password_info))
444 return false;
445
446 ClearPreview(&username_element, &password_info.password_field);
447
Ilya Sherman 2014/05/15 21:36:09 nit: I'd omit this blank line.
ziran.sun 2014/05/16 09:18:13 Done.
448 return true;
399 } 449 }
400 450
401 bool PasswordAutofillAgent::ShowSuggestions( 451 bool PasswordAutofillAgent::ShowSuggestions(
402 const blink::WebInputElement& element) { 452 const blink::WebInputElement& element) {
403 LoginToPasswordInfoMap::const_iterator iter = 453 LoginToPasswordInfoMap::const_iterator iter =
404 login_to_password_info_.find(element); 454 login_to_password_info_.find(element);
405 if (iter == login_to_password_info_.end()) 455 if (iter == login_to_password_info_.end())
406 return false; 456 return false;
407 457
408 // If autocomplete='off' is set on the form elements, no suggestion dialog 458 // 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>(); 1069 blink::WebInputElement input = element.to<blink::WebInputElement>();
1020 LoginToPasswordInfoMap::iterator iter = login_to_password_info_.find(input); 1070 LoginToPasswordInfoMap::iterator iter = login_to_password_info_.find(input);
1021 if (iter == login_to_password_info_.end()) 1071 if (iter == login_to_password_info_.end())
1022 return false; 1072 return false;
1023 1073
1024 *found_input = input; 1074 *found_input = input;
1025 *found_password = iter->second; 1075 *found_password = iter->second;
1026 return true; 1076 return true;
1027 } 1077 }
1028 1078
1079 void PasswordAutofillAgent::ClearPreview(
1080 blink::WebInputElement* username,
1081 blink::WebInputElement* password) {
1082 if (!username->suggestedValue().isEmpty()) {
1083 username->setSuggestedValue(blink::WebString());
1084 username->setAutofilled(was_username_autofilled_);
1085 username->setSelectionRange(username->value().length(),
1086 username->value().length());
1087 }
1088 if (!password->suggestedValue().isEmpty()) {
1089 password->setSuggestedValue(blink::WebString());
1090 password->setAutofilled(was_password_autofilled_);
1091 }
1092 }
1093
1029 } // namespace autofill 1094 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698