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/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
(...skipping 857 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
868 blink::WebFrame* frame = render_frame()->GetWebFrame(); | 868 blink::WebFrame* frame = render_frame()->GetWebFrame(); |
869 blink::WebVector<blink::WebFormElement> forms; | 869 blink::WebVector<blink::WebFormElement> forms; |
870 frame->document().forms(forms); | 870 frame->document().forms(forms); |
871 | 871 |
872 for (size_t i = 0; i < forms.size(); ++i) { | 872 for (size_t i = 0; i < forms.size(); ++i) { |
873 const blink::WebFormElement& form = forms[i]; | 873 const blink::WebFormElement& form = forms[i]; |
874 if (!IsWebNodeVisible(form)) { | 874 if (!IsWebNodeVisible(form)) { |
875 continue; | 875 continue; |
876 } | 876 } |
877 | 877 |
878 scoped_ptr<PasswordForm> password_form( | 878 scoped_ptr<PasswordForm> password_form(CreatePasswordForm( |
879 CreatePasswordForm(form, &nonscript_modified_values_)); | 879 form, &nonscript_modified_values_, &form_predictions_)); |
880 if (password_form.get()) { | 880 if (password_form.get()) { |
881 if (provisionally_saved_form_->action == password_form->action) { | 881 if (provisionally_saved_form_->action == password_form->action) { |
882 // Form still exists, no save required. | 882 // Form still exists, no save required. |
883 return; | 883 return; |
884 } | 884 } |
885 } | 885 } |
886 } | 886 } |
887 Send(new AutofillHostMsg_InPageNavigation(routing_id(), | 887 Send(new AutofillHostMsg_InPageNavigation(routing_id(), |
888 *provisionally_saved_form_)); | 888 *provisionally_saved_form_)); |
889 provisionally_saved_form_.reset(); | 889 provisionally_saved_form_.reset(); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
937 LogHTMLForm(logger.get(), Logger::STRING_FORM_FOUND_ON_PAGE, form); | 937 LogHTMLForm(logger.get(), Logger::STRING_FORM_FOUND_ON_PAGE, form); |
938 logger->LogBoolean(Logger::STRING_FORM_IS_VISIBLE, is_form_visible); | 938 logger->LogBoolean(Logger::STRING_FORM_IS_VISIBLE, is_form_visible); |
939 } | 939 } |
940 | 940 |
941 // If requested, ignore non-rendered forms, e.g., those styled with | 941 // If requested, ignore non-rendered forms, e.g., those styled with |
942 // display:none. | 942 // display:none. |
943 if (!is_form_visible) | 943 if (!is_form_visible) |
944 continue; | 944 continue; |
945 } | 945 } |
946 | 946 |
947 scoped_ptr<PasswordForm> password_form(CreatePasswordForm(form, nullptr)); | 947 scoped_ptr<PasswordForm> password_form( |
| 948 CreatePasswordForm(form, nullptr, &form_predictions_)); |
948 if (password_form.get()) { | 949 if (password_form.get()) { |
949 if (logger) { | 950 if (logger) { |
950 logger->LogPasswordForm(Logger::STRING_FORM_IS_PASSWORD, | 951 logger->LogPasswordForm(Logger::STRING_FORM_IS_PASSWORD, |
951 *password_form); | 952 *password_form); |
952 } | 953 } |
953 password_forms.push_back(*password_form); | 954 password_forms.push_back(*password_form); |
954 } | 955 } |
955 } | 956 } |
956 | 957 |
957 if (password_forms.empty() && !only_visible) { | 958 if (password_forms.empty() && !only_visible) { |
(...skipping 10 matching lines...) Expand all Loading... |
968 } else { | 969 } else { |
969 Send(new AutofillHostMsg_PasswordFormsParsed(routing_id(), password_forms)); | 970 Send(new AutofillHostMsg_PasswordFormsParsed(routing_id(), password_forms)); |
970 } | 971 } |
971 } | 972 } |
972 | 973 |
973 bool PasswordAutofillAgent::OnMessageReceived(const IPC::Message& message) { | 974 bool PasswordAutofillAgent::OnMessageReceived(const IPC::Message& message) { |
974 bool handled = true; | 975 bool handled = true; |
975 IPC_BEGIN_MESSAGE_MAP(PasswordAutofillAgent, message) | 976 IPC_BEGIN_MESSAGE_MAP(PasswordAutofillAgent, message) |
976 IPC_MESSAGE_HANDLER(AutofillMsg_FillPasswordForm, OnFillPasswordForm) | 977 IPC_MESSAGE_HANDLER(AutofillMsg_FillPasswordForm, OnFillPasswordForm) |
977 IPC_MESSAGE_HANDLER(AutofillMsg_SetLoggingState, OnSetLoggingState) | 978 IPC_MESSAGE_HANDLER(AutofillMsg_SetLoggingState, OnSetLoggingState) |
| 979 IPC_MESSAGE_HANDLER(AutofillMsg_AutofillUsernameDataReceived, |
| 980 OnAutofillUsernameDataReceived) |
978 IPC_MESSAGE_UNHANDLED(handled = false) | 981 IPC_MESSAGE_UNHANDLED(handled = false) |
979 IPC_END_MESSAGE_MAP() | 982 IPC_END_MESSAGE_MAP() |
980 return handled; | 983 return handled; |
981 } | 984 } |
982 | 985 |
983 void PasswordAutofillAgent::DidFinishDocumentLoad() { | 986 void PasswordAutofillAgent::DidFinishDocumentLoad() { |
984 // The |frame| contents have been parsed, but not yet rendered. Let the | 987 // The |frame| contents have been parsed, but not yet rendered. Let the |
985 // PasswordManager know that forms are loaded, even though we can't yet tell | 988 // PasswordManager know that forms are loaded, even though we can't yet tell |
986 // whether they're visible. | 989 // whether they're visible. |
987 SendPasswordForms(false); | 990 SendPasswordForms(false); |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1060 } | 1063 } |
1061 | 1064 |
1062 void PasswordAutofillAgent::WillSubmitForm(const blink::WebFormElement& form) { | 1065 void PasswordAutofillAgent::WillSubmitForm(const blink::WebFormElement& form) { |
1063 scoped_ptr<RendererSavePasswordProgressLogger> logger; | 1066 scoped_ptr<RendererSavePasswordProgressLogger> logger; |
1064 if (logging_state_active_) { | 1067 if (logging_state_active_) { |
1065 logger.reset(new RendererSavePasswordProgressLogger(this, routing_id())); | 1068 logger.reset(new RendererSavePasswordProgressLogger(this, routing_id())); |
1066 logger->LogMessage(Logger::STRING_WILL_SUBMIT_FORM_METHOD); | 1069 logger->LogMessage(Logger::STRING_WILL_SUBMIT_FORM_METHOD); |
1067 LogHTMLForm(logger.get(), Logger::STRING_HTML_FORM_FOR_SUBMIT, form); | 1070 LogHTMLForm(logger.get(), Logger::STRING_HTML_FORM_FOR_SUBMIT, form); |
1068 } | 1071 } |
1069 | 1072 |
1070 scoped_ptr<PasswordForm> submitted_form = CreatePasswordForm(form, nullptr); | 1073 scoped_ptr<PasswordForm> submitted_form = |
| 1074 CreatePasswordForm(form, nullptr, &form_predictions_); |
1071 | 1075 |
1072 // If there is a provisionally saved password, copy over the previous | 1076 // If there is a provisionally saved password, copy over the previous |
1073 // password value so we get the user's typed password, not the value that | 1077 // password value so we get the user's typed password, not the value that |
1074 // may have been transformed for submit. | 1078 // may have been transformed for submit. |
1075 // TODO(gcasto): Do we need to have this action equality check? Is it trying | 1079 // TODO(gcasto): Do we need to have this action equality check? Is it trying |
1076 // to prevent accidentally copying over passwords from a different form? | 1080 // to prevent accidentally copying over passwords from a different form? |
1077 if (submitted_form) { | 1081 if (submitted_form) { |
1078 if (logger) { | 1082 if (logger) { |
1079 logger->LogPasswordForm(Logger::STRING_CREATED_PASSWORD_FORM, | 1083 logger->LogPasswordForm(Logger::STRING_CREATED_PASSWORD_FORM, |
1080 *submitted_form); | 1084 *submitted_form); |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1145 blink::WebVector<blink::WebFormElement> forms; | 1149 blink::WebVector<blink::WebFormElement> forms; |
1146 render_frame()->GetWebFrame()->document().forms(forms); | 1150 render_frame()->GetWebFrame()->document().forms(forms); |
1147 | 1151 |
1148 bool password_forms_found = false; | 1152 bool password_forms_found = false; |
1149 for (size_t i = 0; i < forms.size(); ++i) { | 1153 for (size_t i = 0; i < forms.size(); ++i) { |
1150 blink::WebFormElement form_element = forms[i]; | 1154 blink::WebFormElement form_element = forms[i]; |
1151 if (logger) { | 1155 if (logger) { |
1152 LogHTMLForm(logger.get(), Logger::STRING_FORM_FOUND_ON_PAGE, | 1156 LogHTMLForm(logger.get(), Logger::STRING_FORM_FOUND_ON_PAGE, |
1153 form_element); | 1157 form_element); |
1154 } | 1158 } |
1155 scoped_ptr<PasswordForm> password_form( | 1159 scoped_ptr<PasswordForm> password_form(CreatePasswordForm( |
1156 CreatePasswordForm(form_element, &nonscript_modified_values_)); | 1160 form_element, &nonscript_modified_values_, &form_predictions_)); |
1157 if (password_form.get() && !password_form->username_value.empty() && | 1161 if (password_form.get() && !password_form->username_value.empty() && |
1158 FormContainsNonDefaultPasswordValue(*password_form, form_element)) { | 1162 FormContainsNonDefaultPasswordValue(*password_form, form_element)) { |
1159 password_forms_found = true; | 1163 password_forms_found = true; |
1160 if (logger) { | 1164 if (logger) { |
1161 logger->LogPasswordForm(Logger::STRING_PASSWORD_FORM_FOUND_ON_PAGE, | 1165 logger->LogPasswordForm(Logger::STRING_PASSWORD_FORM_FOUND_ON_PAGE, |
1162 *password_form); | 1166 *password_form); |
1163 } | 1167 } |
1164 Send(new AutofillHostMsg_PasswordFormSubmitted(routing_id(), | 1168 Send(new AutofillHostMsg_PasswordFormSubmitted(routing_id(), |
1165 *password_form)); | 1169 *password_form)); |
1166 } | 1170 } |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1236 login_to_password_info_[username_element] = password_info; | 1240 login_to_password_info_[username_element] = password_info; |
1237 password_to_username_[password_element] = username_element; | 1241 password_to_username_[password_element] = username_element; |
1238 login_to_password_info_key_[username_element] = key; | 1242 login_to_password_info_key_[username_element] = key; |
1239 } | 1243 } |
1240 } | 1244 } |
1241 | 1245 |
1242 void PasswordAutofillAgent::OnSetLoggingState(bool active) { | 1246 void PasswordAutofillAgent::OnSetLoggingState(bool active) { |
1243 logging_state_active_ = active; | 1247 logging_state_active_ = active; |
1244 } | 1248 } |
1245 | 1249 |
| 1250 void PasswordAutofillAgent::OnAutofillUsernameDataReceived( |
| 1251 const std::map<autofill::FormData, autofill::FormFieldData>& predictions) { |
| 1252 form_predictions_ = predictions; |
| 1253 } |
| 1254 |
1246 //////////////////////////////////////////////////////////////////////////////// | 1255 //////////////////////////////////////////////////////////////////////////////// |
1247 // PasswordAutofillAgent, private: | 1256 // PasswordAutofillAgent, private: |
1248 | 1257 |
1249 PasswordAutofillAgent::PasswordInfo::PasswordInfo() | 1258 PasswordAutofillAgent::PasswordInfo::PasswordInfo() |
1250 : backspace_pressed_last(false), password_was_edited_last(false) { | 1259 : backspace_pressed_last(false), password_was_edited_last(false) { |
1251 } | 1260 } |
1252 | 1261 |
1253 bool PasswordAutofillAgent::ShowSuggestionPopup( | 1262 bool PasswordAutofillAgent::ShowSuggestionPopup( |
1254 const PasswordFormFillData& fill_data, | 1263 const PasswordFormFillData& fill_data, |
1255 const blink::WebInputElement& user_input, | 1264 const blink::WebInputElement& user_input, |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1386 } | 1395 } |
1387 if (!password->suggestedValue().isEmpty()) { | 1396 if (!password->suggestedValue().isEmpty()) { |
1388 password->setSuggestedValue(blink::WebString()); | 1397 password->setSuggestedValue(blink::WebString()); |
1389 password->setAutofilled(was_password_autofilled_); | 1398 password->setAutofilled(was_password_autofilled_); |
1390 } | 1399 } |
1391 } | 1400 } |
1392 | 1401 |
1393 void PasswordAutofillAgent::ProvisionallySavePassword( | 1402 void PasswordAutofillAgent::ProvisionallySavePassword( |
1394 const blink::WebFormElement& form, | 1403 const blink::WebFormElement& form, |
1395 ProvisionallySaveRestriction restriction) { | 1404 ProvisionallySaveRestriction restriction) { |
1396 scoped_ptr<PasswordForm> password_form( | 1405 scoped_ptr<PasswordForm> password_form(CreatePasswordForm( |
1397 CreatePasswordForm(form, &nonscript_modified_values_)); | 1406 form, &nonscript_modified_values_, &form_predictions_)); |
1398 if (!password_form || (restriction == RESTRICTION_NON_EMPTY_PASSWORD && | 1407 if (!password_form || (restriction == RESTRICTION_NON_EMPTY_PASSWORD && |
1399 password_form->password_value.empty() && | 1408 password_form->password_value.empty() && |
1400 password_form->new_password_value.empty())) { | 1409 password_form->new_password_value.empty())) { |
1401 return; | 1410 return; |
1402 } | 1411 } |
1403 provisionally_saved_form_ = password_form.Pass(); | 1412 provisionally_saved_form_ = password_form.Pass(); |
1404 } | 1413 } |
1405 | 1414 |
1406 bool PasswordAutofillAgent::ProvisionallySavedPasswordIsValid() { | 1415 bool PasswordAutofillAgent::ProvisionallySavedPasswordIsValid() { |
1407 return provisionally_saved_form_ && | 1416 return provisionally_saved_form_ && |
(...skipping 25 matching lines...) Expand all Loading... |
1433 void PasswordAutofillAgent::LegacyPasswordAutofillAgent::DidStopLoading() { | 1442 void PasswordAutofillAgent::LegacyPasswordAutofillAgent::DidStopLoading() { |
1434 agent_->DidStopLoading(); | 1443 agent_->DidStopLoading(); |
1435 } | 1444 } |
1436 | 1445 |
1437 void PasswordAutofillAgent::LegacyPasswordAutofillAgent:: | 1446 void PasswordAutofillAgent::LegacyPasswordAutofillAgent:: |
1438 DidStartProvisionalLoad(blink::WebLocalFrame* navigated_frame) { | 1447 DidStartProvisionalLoad(blink::WebLocalFrame* navigated_frame) { |
1439 agent_->LegacyDidStartProvisionalLoad(navigated_frame); | 1448 agent_->LegacyDidStartProvisionalLoad(navigated_frame); |
1440 } | 1449 } |
1441 | 1450 |
1442 } // namespace autofill | 1451 } // namespace autofill |
OLD | NEW |