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_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 18 matching lines...) Expand all Loading... | |
260 } | 262 } |
261 | 263 |
262 elements_.clear(); | 264 elements_.clear(); |
263 } | 265 } |
264 | 266 |
265 void PasswordAutofillAgent::PasswordValueGatekeeper::Reset() { | 267 void PasswordAutofillAgent::PasswordValueGatekeeper::Reset() { |
266 was_user_gesture_seen_ = false; | 268 was_user_gesture_seen_ = false; |
267 elements_.clear(); | 269 elements_.clear(); |
268 } | 270 } |
269 | 271 |
272 bool PasswordAutofillAgent::ClearPreviewForTest( | |
273 blink::WebInputElement* username, | |
274 blink::WebInputElement* password) { | |
275 return ClearPreview(username, password); | |
276 } | |
277 | |
270 void PasswordAutofillAgent::PasswordValueGatekeeper::ShowValue( | 278 void PasswordAutofillAgent::PasswordValueGatekeeper::ShowValue( |
271 blink::WebInputElement* element) { | 279 blink::WebInputElement* element) { |
272 if (!element->isNull() && !element->suggestedValue().isNull()) | 280 if (!element->isNull() && !element->suggestedValue().isNull()) |
273 element->setValue(element->suggestedValue(), true); | 281 element->setValue(element->suggestedValue(), true); |
274 } | 282 } |
275 | 283 |
276 bool PasswordAutofillAgent::TextFieldDidEndEditing( | 284 bool PasswordAutofillAgent::TextFieldDidEndEditing( |
277 const blink::WebInputElement& element) { | 285 const blink::WebInputElement& element) { |
278 LoginToPasswordInfoMap::const_iterator iter = | 286 LoginToPasswordInfoMap::const_iterator iter = |
279 login_to_password_info_.find(element); | 287 login_to_password_info_.find(element); |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
360 LoginToPasswordInfoMap::iterator iter = login_to_password_info_.find(element); | 368 LoginToPasswordInfoMap::iterator iter = login_to_password_info_.find(element); |
361 if (iter == login_to_password_info_.end()) | 369 if (iter == login_to_password_info_.end()) |
362 return false; | 370 return false; |
363 | 371 |
364 int win_key_code = event.windowsKeyCode; | 372 int win_key_code = event.windowsKeyCode; |
365 iter->second.backspace_pressed_last = | 373 iter->second.backspace_pressed_last = |
366 (win_key_code == ui::VKEY_BACK || win_key_code == ui::VKEY_DELETE); | 374 (win_key_code == ui::VKEY_BACK || win_key_code == ui::VKEY_DELETE); |
367 return true; | 375 return true; |
368 } | 376 } |
369 | 377 |
370 bool PasswordAutofillAgent::AcceptSuggestion( | 378 bool PasswordAutofillAgent::FillSuggestion( |
371 const blink::WebNode& node, | 379 const blink::WebNode& node, |
372 const blink::WebString& username, | 380 const blink::WebString& username, |
373 const blink::WebString& password) { | 381 const blink::WebString& password) { |
374 blink::WebInputElement username_element; | 382 blink::WebInputElement username_element; |
375 PasswordInfo password_info; | 383 PasswordInfo password_info; |
376 | 384 |
377 if (!FindLoginInfo(node, &username_element, &password_info) || | 385 if (!FindLoginInfo(node, &username_element, &password_info) || |
378 !IsElementAutocompletable(username_element) || | 386 !IsElementAutocompletable(username_element) || |
379 !IsElementAutocompletable(password_info.password_field)) { | 387 !IsElementAutocompletable(password_info.password_field)) { |
380 return false; | 388 return false; |
381 } | 389 } |
382 | 390 |
383 base::string16 current_username = username_element.value(); | 391 base::string16 current_username = username_element.value(); |
384 username_element.setValue(username, true); | 392 username_element.setValue(username, true); |
385 username_element.setAutofilled(true); | 393 username_element.setAutofilled(true); |
386 username_element.setSelectionRange(username.length(), username.length()); | 394 username_element.setSelectionRange(username.length(), username.length()); |
387 | 395 |
388 password_info.password_field.setValue(password, true); | 396 password_info.password_field.setValue(password, true); |
389 password_info.password_field.setAutofilled(true); | 397 password_info.password_field.setAutofilled(true); |
390 | 398 |
391 return true; | 399 return true; |
392 } | 400 } |
393 | 401 |
402 bool PasswordAutofillAgent::PreviewSuggestion( | |
403 const blink::WebNode& node, | |
404 const blink::WebString& username, | |
405 const blink::WebString& password) { | |
406 blink::WebInputElement username_element; | |
407 PasswordInfo password_info; | |
408 | |
409 if (!FindLoginInfo(node, &username_element, &password_info) || | |
410 !IsElementAutocompletable(username_element) || | |
411 !IsElementAutocompletable(password_info.password_field)) { | |
412 return false; | |
413 } | |
414 | |
415 was_username_autofilled_ = username_element.isAutofilled(); | |
416 username_element.setSuggestedValue(username); | |
417 username_element.setAutofilled(true); | |
418 // Selection range starts from the end of matching characters between the | |
419 // value and sugggestedValue of the username field. | |
420 std::string value_string = username_element.value().utf8(); | |
421 std::string suggested_string = username_element.suggestedValue().utf8(); | |
422 size_t selection_start = 0; | |
423 bool done_compare = false; | |
424 while (done_compare == false) { | |
425 if (selection_start == value_string.length() || | |
426 selection_start == suggested_string.length()) | |
427 done_compare = true; | |
428 | |
429 if (value_string[selection_start] == suggested_string[selection_start]) | |
430 selection_start++; | |
431 else | |
432 done_compare = true; | |
433 } | |
434 username_element.setSelectionRange( | |
435 selection_start, | |
436 username_element.suggestedValue().length()); | |
437 | |
438 was_password_autofilled_ = password_info.password_field.isAutofilled(); | |
439 password_info.password_field.setSuggestedValue(password); | |
440 password_info.password_field.setAutofilled(true); | |
441 | |
442 return true; | |
443 } | |
444 | |
394 bool PasswordAutofillAgent::DidClearAutofillSelection( | 445 bool PasswordAutofillAgent::DidClearAutofillSelection( |
395 const blink::WebNode& node) { | 446 const blink::WebNode& node) { |
396 blink::WebInputElement input; | 447 blink::WebInputElement username_element; |
397 PasswordInfo password; | 448 PasswordInfo password_info; |
398 return FindLoginInfo(node, &input, &password); | 449 if (!FindLoginInfo(node, &username_element, &password_info)) |
450 return false; | |
451 | |
452 return ClearPreview(&username_element, &password_info.password_field); | |
399 } | 453 } |
400 | 454 |
401 bool PasswordAutofillAgent::ShowSuggestions( | 455 bool PasswordAutofillAgent::ShowSuggestions( |
402 const blink::WebInputElement& element) { | 456 const blink::WebInputElement& element) { |
403 LoginToPasswordInfoMap::const_iterator iter = | 457 LoginToPasswordInfoMap::const_iterator iter = |
404 login_to_password_info_.find(element); | 458 login_to_password_info_.find(element); |
405 if (iter == login_to_password_info_.end()) | 459 if (iter == login_to_password_info_.end()) |
406 return false; | 460 return false; |
407 | 461 |
408 // If autocomplete='off' is set on the form elements, no suggestion dialog | 462 // If autocomplete='off' is set on the form elements, no suggestion dialog |
(...skipping 610 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1019 blink::WebInputElement input = element.to<blink::WebInputElement>(); | 1073 blink::WebInputElement input = element.to<blink::WebInputElement>(); |
1020 LoginToPasswordInfoMap::iterator iter = login_to_password_info_.find(input); | 1074 LoginToPasswordInfoMap::iterator iter = login_to_password_info_.find(input); |
1021 if (iter == login_to_password_info_.end()) | 1075 if (iter == login_to_password_info_.end()) |
1022 return false; | 1076 return false; |
1023 | 1077 |
1024 *found_input = input; | 1078 *found_input = input; |
1025 *found_password = iter->second; | 1079 *found_password = iter->second; |
1026 return true; | 1080 return true; |
1027 } | 1081 } |
1028 | 1082 |
1083 bool PasswordAutofillAgent::ClearPreview( | |
1084 blink::WebInputElement* username, | |
1085 blink::WebInputElement* password) { | |
1086 if (!username->suggestedValue().isEmpty()) { | |
1087 username->setSuggestedValue(blink::WebString()); | |
1088 username->setAutofilled(was_username_autofilled_); | |
1089 username->setSelectionRange(username->value().length(), | |
1090 username->value().length()); | |
1091 } | |
1092 if (!password->suggestedValue().isEmpty()) { | |
1093 password->setSuggestedValue(blink::WebString()); | |
1094 password->setAutofilled(was_password_autofilled_); | |
1095 } | |
1096 | |
1097 return true; | |
Ilya Sherman
2014/05/14 23:10:58
Hmm, it looks like this method can only ever retur
ziran.sun
2014/05/15 12:36:37
Done.
| |
1098 } | |
1099 | |
1029 } // namespace autofill | 1100 } // namespace autofill |
OLD | NEW |