| 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 896 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 907 LogHTMLForm(logger.get(), Logger::STRING_FORM_FOUND_ON_PAGE, form); | 907 LogHTMLForm(logger.get(), Logger::STRING_FORM_FOUND_ON_PAGE, form); |
| 908 logger->LogBoolean(Logger::STRING_FORM_IS_VISIBLE, is_form_visible); | 908 logger->LogBoolean(Logger::STRING_FORM_IS_VISIBLE, is_form_visible); |
| 909 } | 909 } |
| 910 | 910 |
| 911 // If requested, ignore non-rendered forms, e.g., those styled with | 911 // If requested, ignore non-rendered forms, e.g., those styled with |
| 912 // display:none. | 912 // display:none. |
| 913 if (!is_form_visible) | 913 if (!is_form_visible) |
| 914 continue; | 914 continue; |
| 915 } | 915 } |
| 916 | 916 |
| 917 scoped_ptr<PasswordForm> password_form(CreatePasswordForm(form, nullptr)); | 917 scoped_ptr<PasswordForm> password_form( |
| 918 CreatePasswordForm(form, nullptr, &form_predictions_)); |
| 918 if (password_form.get()) { | 919 if (password_form.get()) { |
| 919 if (logger) { | 920 if (logger) { |
| 920 logger->LogPasswordForm(Logger::STRING_FORM_IS_PASSWORD, | 921 logger->LogPasswordForm(Logger::STRING_FORM_IS_PASSWORD, |
| 921 *password_form); | 922 *password_form); |
| 922 } | 923 } |
| 923 password_forms.push_back(*password_form); | 924 password_forms.push_back(*password_form); |
| 924 } | 925 } |
| 925 } | 926 } |
| 926 | 927 |
| 927 if (password_forms.empty() && !only_visible) { | 928 if (password_forms.empty() && !only_visible) { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 938 } else { | 939 } else { |
| 939 Send(new AutofillHostMsg_PasswordFormsParsed(routing_id(), password_forms)); | 940 Send(new AutofillHostMsg_PasswordFormsParsed(routing_id(), password_forms)); |
| 940 } | 941 } |
| 941 } | 942 } |
| 942 | 943 |
| 943 bool PasswordAutofillAgent::OnMessageReceived(const IPC::Message& message) { | 944 bool PasswordAutofillAgent::OnMessageReceived(const IPC::Message& message) { |
| 944 bool handled = true; | 945 bool handled = true; |
| 945 IPC_BEGIN_MESSAGE_MAP(PasswordAutofillAgent, message) | 946 IPC_BEGIN_MESSAGE_MAP(PasswordAutofillAgent, message) |
| 946 IPC_MESSAGE_HANDLER(AutofillMsg_FillPasswordForm, OnFillPasswordForm) | 947 IPC_MESSAGE_HANDLER(AutofillMsg_FillPasswordForm, OnFillPasswordForm) |
| 947 IPC_MESSAGE_HANDLER(AutofillMsg_SetLoggingState, OnSetLoggingState) | 948 IPC_MESSAGE_HANDLER(AutofillMsg_SetLoggingState, OnSetLoggingState) |
| 949 IPC_MESSAGE_HANDLER(AutofillMsg_AutofillPasswordDataReceived, |
| 950 OnAutofillDataReceived) |
| 948 IPC_MESSAGE_UNHANDLED(handled = false) | 951 IPC_MESSAGE_UNHANDLED(handled = false) |
| 949 IPC_END_MESSAGE_MAP() | 952 IPC_END_MESSAGE_MAP() |
| 950 return handled; | 953 return handled; |
| 951 } | 954 } |
| 952 | 955 |
| 953 void PasswordAutofillAgent::DidFinishDocumentLoad() { | 956 void PasswordAutofillAgent::DidFinishDocumentLoad() { |
| 954 // The |frame| contents have been parsed, but not yet rendered. Let the | 957 // The |frame| contents have been parsed, but not yet rendered. Let the |
| 955 // PasswordManager know that forms are loaded, even though we can't yet tell | 958 // PasswordManager know that forms are loaded, even though we can't yet tell |
| 956 // whether they're visible. | 959 // whether they're visible. |
| 957 SendPasswordForms(false); | 960 SendPasswordForms(false); |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1022 } | 1025 } |
| 1023 | 1026 |
| 1024 void PasswordAutofillAgent::WillSubmitForm(const blink::WebFormElement& form) { | 1027 void PasswordAutofillAgent::WillSubmitForm(const blink::WebFormElement& form) { |
| 1025 scoped_ptr<RendererSavePasswordProgressLogger> logger; | 1028 scoped_ptr<RendererSavePasswordProgressLogger> logger; |
| 1026 if (logging_state_active_) { | 1029 if (logging_state_active_) { |
| 1027 logger.reset(new RendererSavePasswordProgressLogger(this, routing_id())); | 1030 logger.reset(new RendererSavePasswordProgressLogger(this, routing_id())); |
| 1028 logger->LogMessage(Logger::STRING_WILL_SUBMIT_FORM_METHOD); | 1031 logger->LogMessage(Logger::STRING_WILL_SUBMIT_FORM_METHOD); |
| 1029 LogHTMLForm(logger.get(), Logger::STRING_HTML_FORM_FOR_SUBMIT, form); | 1032 LogHTMLForm(logger.get(), Logger::STRING_HTML_FORM_FOR_SUBMIT, form); |
| 1030 } | 1033 } |
| 1031 | 1034 |
| 1032 scoped_ptr<PasswordForm> submitted_form = CreatePasswordForm(form, nullptr); | 1035 scoped_ptr<PasswordForm> submitted_form = |
| 1036 CreatePasswordForm(form, nullptr, &form_predictions_); |
| 1033 | 1037 |
| 1034 // If there is a provisionally saved password, copy over the previous | 1038 // If there is a provisionally saved password, copy over the previous |
| 1035 // password value so we get the user's typed password, not the value that | 1039 // password value so we get the user's typed password, not the value that |
| 1036 // may have been transformed for submit. | 1040 // may have been transformed for submit. |
| 1037 // TODO(gcasto): Do we need to have this action equality check? Is it trying | 1041 // TODO(gcasto): Do we need to have this action equality check? Is it trying |
| 1038 // to prevent accidentally copying over passwords from a different form? | 1042 // to prevent accidentally copying over passwords from a different form? |
| 1039 if (submitted_form) { | 1043 if (submitted_form) { |
| 1040 if (logger) { | 1044 if (logger) { |
| 1041 logger->LogPasswordForm(Logger::STRING_CREATED_PASSWORD_FORM, | 1045 logger->LogPasswordForm(Logger::STRING_CREATED_PASSWORD_FORM, |
| 1042 *submitted_form); | 1046 *submitted_form); |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1107 blink::WebVector<blink::WebFormElement> forms; | 1111 blink::WebVector<blink::WebFormElement> forms; |
| 1108 render_frame()->GetWebFrame()->document().forms(forms); | 1112 render_frame()->GetWebFrame()->document().forms(forms); |
| 1109 | 1113 |
| 1110 bool password_forms_found = false; | 1114 bool password_forms_found = false; |
| 1111 for (size_t i = 0; i < forms.size(); ++i) { | 1115 for (size_t i = 0; i < forms.size(); ++i) { |
| 1112 blink::WebFormElement form_element = forms[i]; | 1116 blink::WebFormElement form_element = forms[i]; |
| 1113 if (logger) { | 1117 if (logger) { |
| 1114 LogHTMLForm(logger.get(), Logger::STRING_FORM_FOUND_ON_PAGE, | 1118 LogHTMLForm(logger.get(), Logger::STRING_FORM_FOUND_ON_PAGE, |
| 1115 form_element); | 1119 form_element); |
| 1116 } | 1120 } |
| 1117 scoped_ptr<PasswordForm> password_form( | 1121 scoped_ptr<PasswordForm> password_form(CreatePasswordForm( |
| 1118 CreatePasswordForm(form_element, &nonscript_modified_values_)); | 1122 form_element, &nonscript_modified_values_, &form_predictions_)); |
| 1119 if (password_form.get() && !password_form->username_value.empty() && | 1123 if (password_form.get() && !password_form->username_value.empty() && |
| 1120 FormContainsNonDefaultPasswordValue(*password_form, form_element)) { | 1124 FormContainsNonDefaultPasswordValue(*password_form, form_element)) { |
| 1121 password_forms_found = true; | 1125 password_forms_found = true; |
| 1122 if (logger) { | 1126 if (logger) { |
| 1123 logger->LogPasswordForm(Logger::STRING_PASSWORD_FORM_FOUND_ON_PAGE, | 1127 logger->LogPasswordForm(Logger::STRING_PASSWORD_FORM_FOUND_ON_PAGE, |
| 1124 *password_form); | 1128 *password_form); |
| 1125 } | 1129 } |
| 1126 Send(new AutofillHostMsg_PasswordFormSubmitted(routing_id(), | 1130 Send(new AutofillHostMsg_PasswordFormSubmitted(routing_id(), |
| 1127 *password_form)); | 1131 *password_form)); |
| 1128 } | 1132 } |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1198 login_to_password_info_[username_element] = password_info; | 1202 login_to_password_info_[username_element] = password_info; |
| 1199 password_to_username_[password_element] = username_element; | 1203 password_to_username_[password_element] = username_element; |
| 1200 login_to_password_info_key_[username_element] = key; | 1204 login_to_password_info_key_[username_element] = key; |
| 1201 } | 1205 } |
| 1202 } | 1206 } |
| 1203 | 1207 |
| 1204 void PasswordAutofillAgent::OnSetLoggingState(bool active) { | 1208 void PasswordAutofillAgent::OnSetLoggingState(bool active) { |
| 1205 logging_state_active_ = active; | 1209 logging_state_active_ = active; |
| 1206 } | 1210 } |
| 1207 | 1211 |
| 1212 void PasswordAutofillAgent::OnAutofillDataReceived( |
| 1213 const std::vector<autofill::FormDataPredictions>& forms) { |
| 1214 form_predictions_ = forms; |
| 1215 } |
| 1216 |
| 1208 //////////////////////////////////////////////////////////////////////////////// | 1217 //////////////////////////////////////////////////////////////////////////////// |
| 1209 // PasswordAutofillAgent, private: | 1218 // PasswordAutofillAgent, private: |
| 1210 | 1219 |
| 1211 PasswordAutofillAgent::PasswordInfo::PasswordInfo() | 1220 PasswordAutofillAgent::PasswordInfo::PasswordInfo() |
| 1212 : backspace_pressed_last(false), password_was_edited_last(false) { | 1221 : backspace_pressed_last(false), password_was_edited_last(false) { |
| 1213 } | 1222 } |
| 1214 | 1223 |
| 1215 bool PasswordAutofillAgent::ShowSuggestionPopup( | 1224 bool PasswordAutofillAgent::ShowSuggestionPopup( |
| 1216 const PasswordFormFillData& fill_data, | 1225 const PasswordFormFillData& fill_data, |
| 1217 const blink::WebInputElement& user_input, | 1226 const blink::WebInputElement& user_input, |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1348 } | 1357 } |
| 1349 if (!password->suggestedValue().isEmpty()) { | 1358 if (!password->suggestedValue().isEmpty()) { |
| 1350 password->setSuggestedValue(blink::WebString()); | 1359 password->setSuggestedValue(blink::WebString()); |
| 1351 password->setAutofilled(was_password_autofilled_); | 1360 password->setAutofilled(was_password_autofilled_); |
| 1352 } | 1361 } |
| 1353 } | 1362 } |
| 1354 | 1363 |
| 1355 void PasswordAutofillAgent::ProvisionallySavePassword( | 1364 void PasswordAutofillAgent::ProvisionallySavePassword( |
| 1356 const blink::WebFormElement& form, | 1365 const blink::WebFormElement& form, |
| 1357 ProvisionallySaveRestriction restriction) { | 1366 ProvisionallySaveRestriction restriction) { |
| 1358 scoped_ptr<PasswordForm> password_form( | 1367 scoped_ptr<PasswordForm> password_form(CreatePasswordForm( |
| 1359 CreatePasswordForm(form, &nonscript_modified_values_)); | 1368 form, &nonscript_modified_values_, &form_predictions_)); |
| 1360 if (!password_form || (restriction == RESTRICTION_NON_EMPTY_PASSWORD && | 1369 if (!password_form || (restriction == RESTRICTION_NON_EMPTY_PASSWORD && |
| 1361 password_form->password_value.empty() && | 1370 password_form->password_value.empty() && |
| 1362 password_form->new_password_value.empty())) { | 1371 password_form->new_password_value.empty())) { |
| 1363 return; | 1372 return; |
| 1364 } | 1373 } |
| 1365 provisionally_saved_form_ = password_form.Pass(); | 1374 provisionally_saved_form_ = password_form.Pass(); |
| 1366 } | 1375 } |
| 1367 | 1376 |
| 1368 // LegacyPasswordAutofillAgent ------------------------------------------------- | 1377 // LegacyPasswordAutofillAgent ------------------------------------------------- |
| 1369 | 1378 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 1388 void PasswordAutofillAgent::LegacyPasswordAutofillAgent::DidStopLoading() { | 1397 void PasswordAutofillAgent::LegacyPasswordAutofillAgent::DidStopLoading() { |
| 1389 agent_->DidStopLoading(); | 1398 agent_->DidStopLoading(); |
| 1390 } | 1399 } |
| 1391 | 1400 |
| 1392 void PasswordAutofillAgent::LegacyPasswordAutofillAgent:: | 1401 void PasswordAutofillAgent::LegacyPasswordAutofillAgent:: |
| 1393 DidStartProvisionalLoad(blink::WebLocalFrame* navigated_frame) { | 1402 DidStartProvisionalLoad(blink::WebLocalFrame* navigated_frame) { |
| 1394 agent_->LegacyDidStartProvisionalLoad(navigated_frame); | 1403 agent_->LegacyDidStartProvisionalLoad(navigated_frame); |
| 1395 } | 1404 } |
| 1396 | 1405 |
| 1397 } // namespace autofill | 1406 } // namespace autofill |
| OLD | NEW |