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 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 218 const blink::WebFormElement& form) { | 218 const blink::WebFormElement& form) { |
| 219 logger->LogHTMLForm(message_id, | 219 logger->LogHTMLForm(message_id, |
| 220 form.name().utf8(), | 220 form.name().utf8(), |
| 221 GURL(form.action().utf8())); | 221 GURL(form.action().utf8())); |
| 222 } | 222 } |
| 223 | 223 |
| 224 bool FillDataContainsUsername(const PasswordFormFillData& fill_data) { | 224 bool FillDataContainsUsername(const PasswordFormFillData& fill_data) { |
| 225 return !fill_data.basic_data.fields[0].name.empty(); | 225 return !fill_data.basic_data.fields[0].name.empty(); |
| 226 } | 226 } |
| 227 | 227 |
| 228 // This function attempts to fill |suggestions| and |realms| form |fill_data| | |
| 229 // based on |current_username|. Returns true when |suggestions| | |
|
vabr (Chromium)
2014/09/30 14:46:45
Please use all available space for the line.
Deepak
2014/09/30 15:01:36
Done.
| |
| 230 // gets filled from |fill_data.other_possible_usernames|, else returns false. | |
| 231 bool GetSuggestions(const PasswordFormFillData& fill_data, | |
| 232 const base::string16& current_username, | |
| 233 std::vector<base::string16>* suggestions, | |
| 234 std::vector<base::string16>* realms, | |
| 235 bool show_all) { | |
| 236 bool other_possible_username_shown = false; | |
| 237 if (show_all || | |
| 238 StartsWith( | |
| 239 fill_data.basic_data.fields[0].value, current_username, false)) { | |
| 240 suggestions->push_back(fill_data.basic_data.fields[0].value); | |
| 241 realms->push_back(base::UTF8ToUTF16(fill_data.preferred_realm)); | |
| 242 } | |
| 243 | |
| 244 for (PasswordFormFillData::LoginCollection::const_iterator iter = | |
| 245 fill_data.additional_logins.begin(); | |
| 246 iter != fill_data.additional_logins.end(); | |
| 247 ++iter) { | |
| 248 if (show_all || StartsWith(iter->first, current_username, false)) { | |
| 249 suggestions->push_back(iter->first); | |
| 250 realms->push_back(base::UTF8ToUTF16(iter->second.realm)); | |
| 251 } | |
| 252 } | |
| 253 | |
| 254 for (PasswordFormFillData::UsernamesCollection::const_iterator iter = | |
| 255 fill_data.other_possible_usernames.begin(); | |
| 256 iter != fill_data.other_possible_usernames.end(); | |
| 257 ++iter) { | |
| 258 for (size_t i = 0; i < iter->second.size(); ++i) { | |
| 259 if (show_all || StartsWith(iter->second[i], current_username, false)) { | |
| 260 other_possible_username_shown = true; | |
| 261 suggestions->push_back(iter->second[i]); | |
| 262 realms->push_back(base::UTF8ToUTF16(iter->first.realm)); | |
| 263 } | |
| 264 } | |
| 265 } | |
| 266 return other_possible_username_shown; | |
| 267 } | |
| 268 | |
| 269 // This function attempts to fill |username_element| and |password_element| | |
| 270 // with values from |fill_data|. The |password_element| will only have the | |
| 271 // |suggestedValue| set, and will be registered for copying that to the real | |
| 272 // value through |registration_callback|. The function returns true when | |
| 273 // selected username comes from |fill_data.other_possible_usernames|. | |
| 274 bool FillUserNameAndPassword( | |
| 275 blink::WebInputElement* username_element, | |
| 276 blink::WebInputElement* password_element, | |
| 277 const PasswordFormFillData& fill_data, | |
| 278 bool exact_username_match, | |
| 279 bool set_selection, | |
| 280 base::Callback<void(blink::WebInputElement*)> registration_callback) { | |
| 281 bool other_possible_username_selected = false; | |
| 282 // Don't fill username if password can't be set. | |
| 283 if (!IsElementAutocompletable(*password_element)) | |
| 284 return false; | |
| 285 | |
| 286 base::string16 current_username; | |
| 287 if (!username_element->isNull()) { | |
| 288 current_username = username_element->value(); | |
| 289 } | |
| 290 | |
| 291 // username and password will contain the match found if any. | |
| 292 base::string16 username; | |
| 293 base::string16 password; | |
| 294 | |
| 295 // Look for any suitable matches to current field text. | |
| 296 if (DoUsernamesMatch(fill_data.basic_data.fields[0].value, | |
| 297 current_username, | |
| 298 exact_username_match)) { | |
| 299 username = fill_data.basic_data.fields[0].value; | |
| 300 password = fill_data.basic_data.fields[1].value; | |
| 301 } else { | |
| 302 // Scan additional logins for a match. | |
| 303 PasswordFormFillData::LoginCollection::const_iterator iter; | |
| 304 for (iter = fill_data.additional_logins.begin(); | |
| 305 iter != fill_data.additional_logins.end(); | |
| 306 ++iter) { | |
| 307 if (DoUsernamesMatch( | |
| 308 iter->first, current_username, exact_username_match)) { | |
| 309 username = iter->first; | |
| 310 password = iter->second.password; | |
| 311 break; | |
| 312 } | |
| 313 } | |
| 314 | |
| 315 // Check possible usernames. | |
| 316 if (username.empty() && password.empty()) { | |
| 317 for (PasswordFormFillData::UsernamesCollection::const_iterator iter = | |
| 318 fill_data.other_possible_usernames.begin(); | |
| 319 iter != fill_data.other_possible_usernames.end(); | |
| 320 ++iter) { | |
| 321 for (size_t i = 0; i < iter->second.size(); ++i) { | |
| 322 if (DoUsernamesMatch( | |
| 323 iter->second[i], current_username, exact_username_match)) { | |
| 324 other_possible_username_selected = true; | |
| 325 username = iter->second[i]; | |
| 326 password = iter->first.password; | |
| 327 break; | |
| 328 } | |
| 329 } | |
| 330 if (!username.empty() && !password.empty()) | |
| 331 break; | |
| 332 } | |
| 333 } | |
| 334 } | |
| 335 if (password.empty()) | |
| 336 return other_possible_username_selected; // No match was found. | |
| 337 | |
| 338 // TODO(tkent): Check maxlength and pattern for both username and password | |
| 339 // fields. | |
| 340 | |
| 341 // Input matches the username, fill in required values. | |
| 342 if (!username_element->isNull() && | |
| 343 IsElementAutocompletable(*username_element)) { | |
| 344 username_element->setValue(username, true); | |
| 345 username_element->setAutofilled(true); | |
| 346 | |
| 347 if (set_selection) { | |
| 348 username_element->setSelectionRange(current_username.length(), | |
| 349 username.length()); | |
| 350 } | |
| 351 } else if (current_username != username) { | |
| 352 // If the username can't be filled and it doesn't match a saved password | |
| 353 // as is, don't autofill a password. | |
| 354 return other_possible_username_selected; | |
| 355 } | |
| 356 | |
| 357 // Wait to fill in the password until a user gesture occurs. This is to make | |
| 358 // sure that we do not fill in the DOM with a password until we believe the | |
| 359 // user is intentionally interacting with the page. | |
| 360 password_element->setSuggestedValue(password); | |
| 361 registration_callback.Run(password_element); | |
| 362 | |
| 363 password_element->setAutofilled(true); | |
| 364 return other_possible_username_selected; | |
| 365 } | |
| 366 | |
| 367 // Attempts to fill |username_element| and |password_element| with the | |
| 368 // |fill_data|. Will use the data corresponding to the preferred username, | |
| 369 // unless the |username_element| already has a value set. In that case, | |
| 370 // attempts to fill the password matching the already filled username, if | |
| 371 // such a password exists. The |password_element| will have the | |
| 372 // |suggestedValue| set, and |suggestedValue| will be registered for copying to | |
| 373 // the real value through |registration_callback|. Returns true when the | |
| 374 // username gets selected from |other_possible_usernames|, else returns false. | |
| 375 bool FillFormOnPasswordRecieved( | |
| 376 const PasswordFormFillData& fill_data, | |
| 377 blink::WebInputElement username_element, | |
| 378 blink::WebInputElement password_element, | |
| 379 base::Callback<void(blink::WebInputElement*)> registration_callback) { | |
| 380 // Do not fill if the password field is in an iframe. | |
| 381 DCHECK(password_element.document().frame()); | |
| 382 if (password_element.document().frame()->parent()) | |
| 383 return false; | |
| 384 | |
| 385 bool form_contains_username_field = FillDataContainsUsername(fill_data); | |
| 386 if (!ShouldIgnoreAutocompleteOffForPasswordFields() && | |
| 387 form_contains_username_field && !username_element.form().autoComplete()) | |
| 388 return false; | |
| 389 | |
| 390 // If we can't modify the password, don't try to set the username | |
| 391 if (!IsElementAutocompletable(password_element)) | |
| 392 return false; | |
| 393 | |
| 394 // Try to set the username to the preferred name, but only if the field | |
| 395 // can be set and isn't prefilled. | |
| 396 if (form_contains_username_field && | |
| 397 IsElementAutocompletable(username_element) && | |
| 398 username_element.value().isEmpty()) { | |
| 399 // TODO(tkent): Check maxlength and pattern. | |
| 400 username_element.setValue(fill_data.basic_data.fields[0].value, true); | |
| 401 } | |
| 402 | |
| 403 // Fill if we have an exact match for the username. Note that this sets | |
| 404 // username to autofilled. | |
| 405 return FillUserNameAndPassword(&username_element, | |
| 406 &password_element, | |
| 407 fill_data, | |
| 408 true /* exact_username_match */, | |
| 409 false /* set_selection */, | |
| 410 registration_callback); | |
| 411 } | |
| 412 | |
| 228 } // namespace | 413 } // namespace |
| 229 | 414 |
| 230 //////////////////////////////////////////////////////////////////////////////// | 415 //////////////////////////////////////////////////////////////////////////////// |
| 231 // PasswordAutofillAgent, public: | 416 // PasswordAutofillAgent, public: |
| 232 | 417 |
| 233 PasswordAutofillAgent::PasswordAutofillAgent(content::RenderView* render_view) | 418 PasswordAutofillAgent::PasswordAutofillAgent(content::RenderView* render_view) |
| 234 : content::RenderViewObserver(render_view), | 419 : content::RenderViewObserver(render_view), |
| 235 usernames_usage_(NOTHING_TO_AUTOFILL), | 420 usernames_usage_(NOTHING_TO_AUTOFILL), |
| 236 web_view_(render_view->GetWebView()), | 421 web_view_(render_view->GetWebView()), |
| 237 logging_state_active_(false), | 422 logging_state_active_(false), |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 303 return false; | 488 return false; |
| 304 | 489 |
| 305 blink::WebInputElement password = password_info.password_field; | 490 blink::WebInputElement password = password_info.password_field; |
| 306 if (!IsElementEditable(password)) | 491 if (!IsElementEditable(password)) |
| 307 return false; | 492 return false; |
| 308 | 493 |
| 309 blink::WebInputElement username = element; // We need a non-const. | 494 blink::WebInputElement username = element; // We need a non-const. |
| 310 | 495 |
| 311 // Do not set selection when ending an editing session, otherwise it can | 496 // Do not set selection when ending an editing session, otherwise it can |
| 312 // mess with focus. | 497 // mess with focus. |
| 313 FillUserNameAndPassword(&username, | 498 if (FillUserNameAndPassword( |
| 314 &password, | 499 &username, |
| 315 fill_data, | 500 &password, |
| 316 true /* exact_username_match */, | 501 fill_data, |
| 317 false /* set_selection */); | 502 true /* exact_username_match */, |
| 503 false /* set_selection */, | |
| 504 base::Bind(&PasswordValueGatekeeper::RegisterElement, | |
| 505 base::Unretained(&gatekeeper_)))) { | |
| 506 usernames_usage_ = OTHER_POSSIBLE_USERNAME_SELECTED; | |
| 507 } | |
| 318 return true; | 508 return true; |
| 319 } | 509 } |
| 320 | 510 |
| 321 bool PasswordAutofillAgent::TextDidChangeInTextField( | 511 bool PasswordAutofillAgent::TextDidChangeInTextField( |
| 322 const blink::WebInputElement& element) { | 512 const blink::WebInputElement& element) { |
| 323 // TODO(vabr): Get a mutable argument instead. http://crbug.com/397083 | 513 // TODO(vabr): Get a mutable argument instead. http://crbug.com/397083 |
| 324 blink::WebInputElement mutable_element = element; // We need a non-const. | 514 blink::WebInputElement mutable_element = element; // We need a non-const. |
| 325 | 515 |
| 326 if (element.isPasswordField()) { | 516 if (element.isPasswordField()) { |
| 327 // Some login forms have event handlers that put a hash of the password into | 517 // Some login forms have event handlers that put a hash of the password into |
| (...skipping 494 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 822 if (form_data.basic_data.fields[1].name.empty()) | 1012 if (form_data.basic_data.fields[1].name.empty()) |
| 823 break; | 1013 break; |
| 824 | 1014 |
| 825 // Get pointer to password element. (We currently only support single | 1015 // Get pointer to password element. (We currently only support single |
| 826 // password forms). | 1016 // password forms). |
| 827 password_element = | 1017 password_element = |
| 828 form_elements->input_elements[form_data.basic_data.fields[1].name]; | 1018 form_elements->input_elements[form_data.basic_data.fields[1].name]; |
| 829 | 1019 |
| 830 // If wait_for_username is true, we don't want to initially fill the form | 1020 // If wait_for_username is true, we don't want to initially fill the form |
| 831 // until the user types in a valid username. | 1021 // until the user types in a valid username. |
| 832 if (!form_data.wait_for_username) | 1022 if (!form_data.wait_for_username && |
| 833 FillFormOnPasswordRecieved(form_data, username_element, password_element); | 1023 FillFormOnPasswordRecieved( |
| 834 | 1024 form_data, |
| 1025 username_element, | |
| 1026 password_element, | |
| 1027 base::Bind(&PasswordValueGatekeeper::RegisterElement, | |
| 1028 base::Unretained(&gatekeeper_)))) { | |
| 1029 usernames_usage_ = OTHER_POSSIBLE_USERNAME_SELECTED; | |
| 1030 } | |
| 835 // We might have already filled this form if there are two <form> elements | 1031 // We might have already filled this form if there are two <form> elements |
| 836 // with identical markup. | 1032 // with identical markup. |
| 837 if (login_to_password_info_.find(username_element) != | 1033 if (login_to_password_info_.find(username_element) != |
| 838 login_to_password_info_.end()) | 1034 login_to_password_info_.end()) |
| 839 continue; | 1035 continue; |
| 840 | 1036 |
| 841 PasswordInfo password_info; | 1037 PasswordInfo password_info; |
| 842 password_info.fill_data = form_data; | 1038 password_info.fill_data = form_data; |
| 843 password_info.password_field = password_element; | 1039 password_info.password_field = password_element; |
| 844 login_to_password_info_[username_element] = password_info; | 1040 login_to_password_info_[username_element] = password_info; |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 860 logging_state_active_ = active; | 1056 logging_state_active_ = active; |
| 861 } | 1057 } |
| 862 | 1058 |
| 863 //////////////////////////////////////////////////////////////////////////////// | 1059 //////////////////////////////////////////////////////////////////////////////// |
| 864 // PasswordAutofillAgent, private: | 1060 // PasswordAutofillAgent, private: |
| 865 | 1061 |
| 866 PasswordAutofillAgent::PasswordInfo::PasswordInfo() | 1062 PasswordAutofillAgent::PasswordInfo::PasswordInfo() |
| 867 : backspace_pressed_last(false), password_was_edited_last(false) { | 1063 : backspace_pressed_last(false), password_was_edited_last(false) { |
| 868 } | 1064 } |
| 869 | 1065 |
| 870 void PasswordAutofillAgent::GetSuggestions( | |
| 871 const PasswordFormFillData& fill_data, | |
| 872 const base::string16& input, | |
| 873 std::vector<base::string16>* suggestions, | |
| 874 std::vector<base::string16>* realms, | |
| 875 bool show_all) { | |
| 876 if (show_all || | |
| 877 StartsWith(fill_data.basic_data.fields[0].value, input, false)) { | |
| 878 suggestions->push_back(fill_data.basic_data.fields[0].value); | |
| 879 realms->push_back(base::UTF8ToUTF16(fill_data.preferred_realm)); | |
| 880 } | |
| 881 | |
| 882 for (PasswordFormFillData::LoginCollection::const_iterator iter = | |
| 883 fill_data.additional_logins.begin(); | |
| 884 iter != fill_data.additional_logins.end(); | |
| 885 ++iter) { | |
| 886 if (show_all || StartsWith(iter->first, input, false)) { | |
| 887 suggestions->push_back(iter->first); | |
| 888 realms->push_back(base::UTF8ToUTF16(iter->second.realm)); | |
| 889 } | |
| 890 } | |
| 891 | |
| 892 for (PasswordFormFillData::UsernamesCollection::const_iterator iter = | |
| 893 fill_data.other_possible_usernames.begin(); | |
| 894 iter != fill_data.other_possible_usernames.end(); | |
| 895 ++iter) { | |
| 896 for (size_t i = 0; i < iter->second.size(); ++i) { | |
| 897 if (show_all || StartsWith(iter->second[i], input, false)) { | |
| 898 usernames_usage_ = OTHER_POSSIBLE_USERNAME_SHOWN; | |
| 899 suggestions->push_back(iter->second[i]); | |
| 900 realms->push_back(base::UTF8ToUTF16(iter->first.realm)); | |
| 901 } | |
| 902 } | |
| 903 } | |
| 904 } | |
| 905 | |
| 906 bool PasswordAutofillAgent::ShowSuggestionPopup( | 1066 bool PasswordAutofillAgent::ShowSuggestionPopup( |
| 907 const PasswordFormFillData& fill_data, | 1067 const PasswordFormFillData& fill_data, |
| 908 const blink::WebInputElement& user_input, | 1068 const blink::WebInputElement& user_input, |
| 909 bool show_all) { | 1069 bool show_all) { |
| 910 blink::WebFrame* frame = user_input.document().frame(); | 1070 blink::WebFrame* frame = user_input.document().frame(); |
| 911 if (!frame) | 1071 if (!frame) |
| 912 return false; | 1072 return false; |
| 913 | 1073 |
| 914 blink::WebView* webview = frame->view(); | 1074 blink::WebView* webview = frame->view(); |
| 915 if (!webview) | 1075 if (!webview) |
| 916 return false; | 1076 return false; |
| 917 | 1077 |
| 918 std::vector<base::string16> suggestions; | 1078 std::vector<base::string16> suggestions; |
| 919 std::vector<base::string16> realms; | 1079 std::vector<base::string16> realms; |
| 920 GetSuggestions( | 1080 if (GetSuggestions( |
| 921 fill_data, user_input.value(), &suggestions, &realms, show_all); | 1081 fill_data, user_input.value(), &suggestions, &realms, show_all)) { |
| 1082 usernames_usage_ = OTHER_POSSIBLE_USERNAME_SHOWN; | |
| 1083 } | |
| 1084 | |
| 922 DCHECK_EQ(suggestions.size(), realms.size()); | 1085 DCHECK_EQ(suggestions.size(), realms.size()); |
| 923 | 1086 |
| 924 FormData form; | 1087 FormData form; |
| 925 FormFieldData field; | 1088 FormFieldData field; |
| 926 FindFormAndFieldForFormControlElement( | 1089 FindFormAndFieldForFormControlElement( |
| 927 user_input, &form, &field, REQUIRE_NONE); | 1090 user_input, &form, &field, REQUIRE_NONE); |
| 928 | 1091 |
| 929 blink::WebInputElement selected_element = user_input; | 1092 blink::WebInputElement selected_element = user_input; |
| 930 gfx::Rect bounding_box(selected_element.boundsInViewportSpace()); | 1093 gfx::Rect bounding_box(selected_element.boundsInViewportSpace()); |
| 931 | 1094 |
| 932 float scale = web_view_->pageScaleFactor(); | 1095 float scale = web_view_->pageScaleFactor(); |
| 933 gfx::RectF bounding_box_scaled(bounding_box.x() * scale, | 1096 gfx::RectF bounding_box_scaled(bounding_box.x() * scale, |
| 934 bounding_box.y() * scale, | 1097 bounding_box.y() * scale, |
| 935 bounding_box.width() * scale, | 1098 bounding_box.width() * scale, |
| 936 bounding_box.height() * scale); | 1099 bounding_box.height() * scale); |
| 937 Send(new AutofillHostMsg_ShowPasswordSuggestions( | 1100 Send(new AutofillHostMsg_ShowPasswordSuggestions( |
| 938 routing_id(), field, bounding_box_scaled, suggestions, realms)); | 1101 routing_id(), field, bounding_box_scaled, suggestions, realms)); |
| 939 return !suggestions.empty(); | 1102 return !suggestions.empty(); |
| 940 } | 1103 } |
| 941 | 1104 |
| 942 void PasswordAutofillAgent::FillFormOnPasswordRecieved( | |
| 943 const PasswordFormFillData& fill_data, | |
| 944 blink::WebInputElement username_element, | |
| 945 blink::WebInputElement password_element) { | |
| 946 // Do not fill if the password field is in an iframe. | |
| 947 DCHECK(password_element.document().frame()); | |
| 948 if (password_element.document().frame()->parent()) | |
| 949 return; | |
| 950 | |
| 951 bool form_contains_username_field = FillDataContainsUsername(fill_data); | |
| 952 if (!ShouldIgnoreAutocompleteOffForPasswordFields() && | |
| 953 form_contains_username_field && !username_element.form().autoComplete()) | |
| 954 return; | |
| 955 | |
| 956 // If we can't modify the password, don't try to set the username | |
| 957 if (!IsElementAutocompletable(password_element)) | |
| 958 return; | |
| 959 | |
| 960 // Try to set the username to the preferred name, but only if the field | |
| 961 // can be set and isn't prefilled. | |
| 962 if (form_contains_username_field && | |
| 963 IsElementAutocompletable(username_element) && | |
| 964 username_element.value().isEmpty()) { | |
| 965 // TODO(tkent): Check maxlength and pattern. | |
| 966 username_element.setValue(fill_data.basic_data.fields[0].value, true); | |
| 967 } | |
| 968 | |
| 969 // Fill if we have an exact match for the username. Note that this sets | |
| 970 // username to autofilled. | |
| 971 FillUserNameAndPassword(&username_element, | |
| 972 &password_element, | |
| 973 fill_data, | |
| 974 true /* exact_username_match */, | |
| 975 false /* set_selection */); | |
| 976 } | |
| 977 | |
| 978 bool PasswordAutofillAgent::FillUserNameAndPassword( | |
| 979 blink::WebInputElement* username_element, | |
| 980 blink::WebInputElement* password_element, | |
| 981 const PasswordFormFillData& fill_data, | |
| 982 bool exact_username_match, | |
| 983 bool set_selection) { | |
| 984 // Don't fill username if password can't be set. | |
| 985 if (!IsElementAutocompletable(*password_element)) | |
| 986 return false; | |
| 987 | |
| 988 base::string16 current_username; | |
| 989 if (!username_element->isNull()) { | |
| 990 current_username = username_element->value(); | |
| 991 } | |
| 992 | |
| 993 // username and password will contain the match found if any. | |
| 994 base::string16 username; | |
| 995 base::string16 password; | |
| 996 | |
| 997 // Look for any suitable matches to current field text. | |
| 998 if (DoUsernamesMatch(fill_data.basic_data.fields[0].value, | |
| 999 current_username, | |
| 1000 exact_username_match)) { | |
| 1001 username = fill_data.basic_data.fields[0].value; | |
| 1002 password = fill_data.basic_data.fields[1].value; | |
| 1003 } else { | |
| 1004 // Scan additional logins for a match. | |
| 1005 PasswordFormFillData::LoginCollection::const_iterator iter; | |
| 1006 for (iter = fill_data.additional_logins.begin(); | |
| 1007 iter != fill_data.additional_logins.end(); | |
| 1008 ++iter) { | |
| 1009 if (DoUsernamesMatch( | |
| 1010 iter->first, current_username, exact_username_match)) { | |
| 1011 username = iter->first; | |
| 1012 password = iter->second.password; | |
| 1013 break; | |
| 1014 } | |
| 1015 } | |
| 1016 | |
| 1017 // Check possible usernames. | |
| 1018 if (username.empty() && password.empty()) { | |
| 1019 for (PasswordFormFillData::UsernamesCollection::const_iterator iter = | |
| 1020 fill_data.other_possible_usernames.begin(); | |
| 1021 iter != fill_data.other_possible_usernames.end(); | |
| 1022 ++iter) { | |
| 1023 for (size_t i = 0; i < iter->second.size(); ++i) { | |
| 1024 if (DoUsernamesMatch( | |
| 1025 iter->second[i], current_username, exact_username_match)) { | |
| 1026 usernames_usage_ = OTHER_POSSIBLE_USERNAME_SELECTED; | |
| 1027 username = iter->second[i]; | |
| 1028 password = iter->first.password; | |
| 1029 break; | |
| 1030 } | |
| 1031 } | |
| 1032 if (!username.empty() && !password.empty()) | |
| 1033 break; | |
| 1034 } | |
| 1035 } | |
| 1036 } | |
| 1037 if (password.empty()) | |
| 1038 return false; // No match was found. | |
| 1039 | |
| 1040 // TODO(tkent): Check maxlength and pattern for both username and password | |
| 1041 // fields. | |
| 1042 | |
| 1043 // Input matches the username, fill in required values. | |
| 1044 if (!username_element->isNull() && | |
| 1045 IsElementAutocompletable(*username_element)) { | |
| 1046 username_element->setValue(username, true); | |
| 1047 username_element->setAutofilled(true); | |
| 1048 | |
| 1049 if (set_selection) { | |
| 1050 username_element->setSelectionRange(current_username.length(), | |
| 1051 username.length()); | |
| 1052 } | |
| 1053 } else if (current_username != username) { | |
| 1054 // If the username can't be filled and it doesn't match a saved password | |
| 1055 // as is, don't autofill a password. | |
| 1056 return false; | |
| 1057 } | |
| 1058 | |
| 1059 // Wait to fill in the password until a user gesture occurs. This is to make | |
| 1060 // sure that we do not fill in the DOM with a password until we believe the | |
| 1061 // user is intentionally interacting with the page. | |
| 1062 password_element->setSuggestedValue(password); | |
| 1063 gatekeeper_.RegisterElement(password_element); | |
| 1064 | |
| 1065 password_element->setAutofilled(true); | |
| 1066 return true; | |
| 1067 } | |
| 1068 | |
| 1069 void PasswordAutofillAgent::PerformInlineAutocomplete( | 1105 void PasswordAutofillAgent::PerformInlineAutocomplete( |
| 1070 const blink::WebInputElement& username_input, | 1106 const blink::WebInputElement& username_input, |
| 1071 const blink::WebInputElement& password_input, | 1107 const blink::WebInputElement& password_input, |
| 1072 const PasswordFormFillData& fill_data) { | 1108 const PasswordFormFillData& fill_data) { |
| 1073 DCHECK(!fill_data.wait_for_username); | 1109 DCHECK(!fill_data.wait_for_username); |
| 1074 | 1110 |
| 1075 // We need non-const versions of the username and password inputs. | 1111 // We need non-const versions of the username and password inputs. |
| 1076 blink::WebInputElement username = username_input; | 1112 blink::WebInputElement username = username_input; |
| 1077 blink::WebInputElement password = password_input; | 1113 blink::WebInputElement password = password_input; |
| 1078 | 1114 |
| 1079 // Don't inline autocomplete if the caret is not at the end. | 1115 // Don't inline autocomplete if the caret is not at the end. |
| 1080 // TODO(jcivelli): is there a better way to test the caret location? | 1116 // TODO(jcivelli): is there a better way to test the caret location? |
| 1081 if (username.selectionStart() != username.selectionEnd() || | 1117 if (username.selectionStart() != username.selectionEnd() || |
| 1082 username.selectionEnd() != static_cast<int>(username.value().length())) { | 1118 username.selectionEnd() != static_cast<int>(username.value().length())) { |
| 1083 return; | 1119 return; |
| 1084 } | 1120 } |
| 1085 | 1121 |
| 1086 // Show the popup with the list of available usernames. | 1122 // Show the popup with the list of available usernames. |
| 1087 ShowSuggestionPopup(fill_data, username, false); | 1123 ShowSuggestionPopup(fill_data, username, false); |
| 1088 | 1124 |
| 1089 #if !defined(OS_ANDROID) | 1125 #if !defined(OS_ANDROID) |
| 1090 // Fill the user and password field with the most relevant match. Android | 1126 // Fill the user and password field with the most relevant match. Android |
| 1091 // only fills in the fields after the user clicks on the suggestion popup. | 1127 // only fills in the fields after the user clicks on the suggestion popup. |
| 1092 FillUserNameAndPassword(&username, | 1128 if (FillUserNameAndPassword( |
| 1093 &password, | 1129 &username, |
| 1094 fill_data, | 1130 &password, |
| 1095 false /* exact_username_match */, | 1131 fill_data, |
| 1096 true /* set_selection */); | 1132 false /* exact_username_match */, |
| 1133 true /* set_selection */, | |
| 1134 base::Bind(&PasswordValueGatekeeper::RegisterElement, | |
| 1135 base::Unretained(&gatekeeper_)))) { | |
| 1136 usernames_usage_ = OTHER_POSSIBLE_USERNAME_SELECTED; | |
| 1137 } | |
| 1097 #endif | 1138 #endif |
| 1098 } | 1139 } |
| 1099 | 1140 |
| 1100 void PasswordAutofillAgent::FrameClosing(const blink::WebFrame* frame) { | 1141 void PasswordAutofillAgent::FrameClosing(const blink::WebFrame* frame) { |
| 1101 for (LoginToPasswordInfoMap::iterator iter = login_to_password_info_.begin(); | 1142 for (LoginToPasswordInfoMap::iterator iter = login_to_password_info_.begin(); |
| 1102 iter != login_to_password_info_.end();) { | 1143 iter != login_to_password_info_.end();) { |
| 1103 // There may not be a username field, so get the frame from the password | 1144 // There may not be a username field, so get the frame from the password |
| 1104 // field. | 1145 // field. |
| 1105 if (iter->second.password_field.document().frame() == frame) { | 1146 if (iter->second.password_field.document().frame() == frame) { |
| 1106 password_to_username_.erase(iter->second.password_field); | 1147 password_to_username_.erase(iter->second.password_field); |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1162 scoped_ptr<PasswordForm> password_form(CreatePasswordForm(form)); | 1203 scoped_ptr<PasswordForm> password_form(CreatePasswordForm(form)); |
| 1163 if (!password_form || (restriction == RESTRICTION_NON_EMPTY_PASSWORD && | 1204 if (!password_form || (restriction == RESTRICTION_NON_EMPTY_PASSWORD && |
| 1164 password_form->password_value.empty() && | 1205 password_form->password_value.empty() && |
| 1165 password_form->new_password_value.empty())) { | 1206 password_form->new_password_value.empty())) { |
| 1166 return; | 1207 return; |
| 1167 } | 1208 } |
| 1168 provisionally_saved_forms_[frame].reset(password_form.release()); | 1209 provisionally_saved_forms_[frame].reset(password_form.release()); |
| 1169 } | 1210 } |
| 1170 | 1211 |
| 1171 } // namespace autofill | 1212 } // namespace autofill |
| OLD | NEW |