Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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_password_autofilled_(false), | |
| 233 is_password_previewed_(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 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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(); | |
| 384 username_element.setValue(username, true); | 385 username_element.setValue(username, true); |
| 385 username_element.setAutofilled(true); | 386 username_element.setAutofilled(true); |
| 386 username_element.setSelectionRange(username.length(), username.length()); | 387 username_element.setSelectionRange(username.length(), username.length()); |
|
Ilya Sherman
2014/05/13 00:44:05
If you rebase, you'll see that the line you remove
ziran.sun
2014/05/14 15:35:12
I'm not able to see where this line is needed, eve
Ilya Sherman
2014/05/14 23:10:58
Oops, sorry, you're right -- I was thinking of a d
| |
| 387 | 388 |
| 388 password_info.password_field.setValue(password, true); | 389 password_info.password_field.setValue(password, true); |
| 389 password_info.password_field.setAutofilled(true); | 390 password_info.password_field.setAutofilled(true); |
| 390 | 391 |
| 391 return true; | 392 return true; |
| 392 } | 393 } |
| 393 | 394 |
| 395 bool PasswordAutofillAgent::SelectSuggestion( | |
| 396 const blink::WebNode& node, | |
| 397 const blink::WebString& username, | |
| 398 const blink::WebString& password) { | |
| 399 blink::WebInputElement username_element; | |
| 400 PasswordInfo password_info; | |
| 401 | |
| 402 if (!FindLoginInfo(node, &username_element, &password_info) || | |
| 403 !IsElementAutocompletable(username_element) || | |
| 404 !IsElementAutocompletable(password_info.password_field)) { | |
| 405 return false; | |
| 406 } | |
| 407 | |
| 408 username_element.setSuggestedValue(username); | |
| 409 username_element.setAutofilled(true); | |
| 410 // Password inline autocompletion auto-completes the username and password | |
| 411 // fields once user types part of the username string in. We compare the | |
| 412 // suggested value with the auto-completed value if there is any character | |
| 413 // by character here and set selection range starting from the end of matching | |
| 414 // characters. | |
|
Ilya Sherman
2014/05/13 00:44:05
Hmm, does inline autocompletion actually call this
ziran.sun
2014/05/14 15:35:12
I don't think inline autocompletion calls this. Th
Ilya Sherman
2014/05/14 23:10:58
I agree with you there. However, there's a simple
ziran.sun
2014/05/15 12:36:37
I'm not sure this works for the use case I describ
Ilya Sherman
2014/05/15 21:36:08
Hmm, that's a fair point. How about this, then?
ziran.sun
2014/05/16 09:18:13
This will have the beginning of the suggestedValue
Ilya Sherman
2014/05/16 22:24:06
So, after patching this in locally and testing, I
| |
| 415 std::string value_string = username_element.value().utf8(); | |
| 416 std::string suggested_string = username_element.suggestedValue().utf8(); | |
| 417 size_t selection_start = 0; | |
| 418 bool done_compare = false; | |
| 419 while (done_compare == false) { | |
| 420 if (selection_start == value_string.length() || | |
| 421 selection_start == suggested_string.length()) | |
| 422 done_compare = true; | |
| 423 | |
| 424 if (value_string[selection_start] == suggested_string[selection_start]) | |
| 425 selection_start++; | |
| 426 else | |
| 427 done_compare = true; | |
| 428 } | |
| 429 username_element.setSelectionRange( | |
| 430 selection_start, | |
| 431 username_element.suggestedValue().length()); | |
| 432 | |
| 433 was_password_autofilled_ = password_info.password_field.isAutofilled(); | |
| 434 password_info.password_field.setSuggestedValue(password); | |
| 435 password_info.password_field.setAutofilled(true); | |
| 436 | |
| 437 is_password_previewed_ = true; | |
| 438 | |
| 439 return true; | |
| 440 } | |
| 441 | |
| 394 bool PasswordAutofillAgent::DidClearAutofillSelection( | 442 bool PasswordAutofillAgent::DidClearAutofillSelection( |
| 395 const blink::WebNode& node) { | 443 const blink::WebNode& node) { |
| 396 blink::WebInputElement input; | 444 blink::WebInputElement input; |
|
Ilya Sherman
2014/05/13 00:44:05
nit: I'd rename this to |username|.
ziran.sun
2014/05/14 15:35:12
Done.
| |
| 397 PasswordInfo password; | 445 PasswordInfo password; |
| 398 return FindLoginInfo(node, &input, &password); | 446 if (is_password_previewed_ || !FindLoginInfo(node, &input, &password)) |
| 447 return false; | |
| 448 | |
| 449 return true; | |
|
Ilya Sherman
2014/05/13 00:44:05
This method should actually clear the form, not ju
ziran.sun
2014/05/14 15:35:12
Done.
| |
| 399 } | 450 } |
| 400 | 451 |
| 401 bool PasswordAutofillAgent::ShowSuggestions( | 452 bool PasswordAutofillAgent::ShowSuggestions( |
| 402 const blink::WebInputElement& element) { | 453 const blink::WebInputElement& element) { |
| 403 LoginToPasswordInfoMap::const_iterator iter = | 454 LoginToPasswordInfoMap::const_iterator iter = |
| 404 login_to_password_info_.find(element); | 455 login_to_password_info_.find(element); |
| 405 if (iter == login_to_password_info_.end()) | 456 if (iter == login_to_password_info_.end()) |
| 406 return false; | 457 return false; |
| 407 | 458 |
| 408 // If autocomplete='off' is set on the form elements, no suggestion dialog | 459 // If autocomplete='off' is set on the form elements, no suggestion dialog |
| 409 // should be shown. However, return |true| to indicate that this is a known | 460 // should be shown. However, return |true| to indicate that this is a known |
| 410 // password form and that the request to show suggestions has been handled (as | 461 // password form and that the request to show suggestions has been handled (as |
| 411 // a no-op). | 462 // a no-op). |
| 412 if (!IsElementAutocompletable(element) || | 463 if (!IsElementAutocompletable(element) || |
| 413 !IsElementAutocompletable(iter->second.password_field)) | 464 !IsElementAutocompletable(iter->second.password_field)) |
| 414 return true; | 465 return true; |
| 415 | 466 |
| 416 return ShowSuggestionPopup(iter->second.fill_data, element); | 467 return ShowSuggestionPopup(iter->second.fill_data, element); |
| 417 } | 468 } |
| 418 | 469 |
| 470 bool PasswordAutofillAgent::WasPasswordAutofilled() { | |
| 471 return was_password_autofilled_; | |
| 472 } | |
| 473 | |
| 419 bool PasswordAutofillAgent::OriginCanAccessPasswordManager( | 474 bool PasswordAutofillAgent::OriginCanAccessPasswordManager( |
| 420 const blink::WebSecurityOrigin& origin) { | 475 const blink::WebSecurityOrigin& origin) { |
| 421 return origin.canAccessPasswordManager(); | 476 return origin.canAccessPasswordManager(); |
| 422 } | 477 } |
| 423 | 478 |
| 424 void PasswordAutofillAgent::OnDynamicFormsSeen(blink::WebFrame* frame) { | 479 void PasswordAutofillAgent::OnDynamicFormsSeen(blink::WebFrame* frame) { |
| 425 SendPasswordForms(frame, false /* only_visible */); | 480 SendPasswordForms(frame, false /* only_visible */); |
| 426 } | 481 } |
| 427 | 482 |
| 428 void PasswordAutofillAgent::FirstUserGestureObserved() { | 483 void PasswordAutofillAgent::FirstUserGestureObserved() { |
| (...skipping 591 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1020 LoginToPasswordInfoMap::iterator iter = login_to_password_info_.find(input); | 1075 LoginToPasswordInfoMap::iterator iter = login_to_password_info_.find(input); |
| 1021 if (iter == login_to_password_info_.end()) | 1076 if (iter == login_to_password_info_.end()) |
| 1022 return false; | 1077 return false; |
| 1023 | 1078 |
| 1024 *found_input = input; | 1079 *found_input = input; |
| 1025 *found_password = iter->second; | 1080 *found_password = iter->second; |
| 1026 return true; | 1081 return true; |
| 1027 } | 1082 } |
| 1028 | 1083 |
| 1029 } // namespace autofill | 1084 } // namespace autofill |
| OLD | NEW |