| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <string> | 10 #include <string> |
| 11 #include <utility> | 11 #include <utility> |
| 12 | 12 |
| 13 #include "base/bind.h" | 13 #include "base/bind.h" |
| 14 #include "base/i18n/case_conversion.h" | 14 #include "base/i18n/case_conversion.h" |
| 15 #include "base/memory/linked_ptr.h" | 15 #include "base/memory/linked_ptr.h" |
| 16 #include "base/memory/ptr_util.h" | 16 #include "base/memory/ptr_util.h" |
| 17 #include "base/memory/scoped_vector.h" | |
| 18 #include "base/message_loop/message_loop.h" | 17 #include "base/message_loop/message_loop.h" |
| 19 #include "base/metrics/histogram_macros.h" | 18 #include "base/metrics/histogram_macros.h" |
| 20 #include "base/strings/string_util.h" | |
| 21 #include "base/strings/utf_string_conversions.h" | 19 #include "base/strings/utf_string_conversions.h" |
| 22 #include "build/build_config.h" | 20 #include "build/build_config.h" |
| 21 #include "components/autofill/content/common/autofill_messages.h" |
| 23 #include "components/autofill/content/renderer/form_autofill_util.h" | 22 #include "components/autofill/content/renderer/form_autofill_util.h" |
| 24 #include "components/autofill/content/renderer/password_form_conversion_utils.h" | 23 #include "components/autofill/content/renderer/password_form_conversion_utils.h" |
| 25 #include "components/autofill/content/renderer/renderer_save_password_progress_l
ogger.h" | 24 #include "components/autofill/content/renderer/renderer_save_password_progress_l
ogger.h" |
| 26 #include "components/autofill/core/common/autofill_constants.h" | 25 #include "components/autofill/core/common/autofill_constants.h" |
| 27 #include "components/autofill/core/common/autofill_util.h" | 26 #include "components/autofill/core/common/autofill_util.h" |
| 28 #include "components/autofill/core/common/form_field_data.h" | 27 #include "components/autofill/core/common/form_field_data.h" |
| 29 #include "components/autofill/core/common/password_form_fill_data.h" | 28 #include "components/autofill/core/common/password_form_fill_data.h" |
| 30 #include "content/public/renderer/document_state.h" | 29 #include "content/public/renderer/document_state.h" |
| 31 #include "content/public/renderer/navigation_state.h" | 30 #include "content/public/renderer/navigation_state.h" |
| 32 #include "content/public/renderer/render_frame.h" | 31 #include "content/public/renderer/render_frame.h" |
| 33 #include "content/public/renderer/render_view.h" | 32 #include "content/public/renderer/render_view.h" |
| 34 #include "services/shell/public/cpp/interface_provider.h" | |
| 35 #include "services/shell/public/cpp/interface_registry.h" | |
| 36 #include "third_party/WebKit/public/platform/WebSecurityOrigin.h" | 33 #include "third_party/WebKit/public/platform/WebSecurityOrigin.h" |
| 37 #include "third_party/WebKit/public/platform/WebVector.h" | 34 #include "third_party/WebKit/public/platform/WebVector.h" |
| 38 #include "third_party/WebKit/public/web/WebAutofillClient.h" | 35 #include "third_party/WebKit/public/web/WebAutofillClient.h" |
| 39 #include "third_party/WebKit/public/web/WebDocument.h" | 36 #include "third_party/WebKit/public/web/WebDocument.h" |
| 40 #include "third_party/WebKit/public/web/WebElement.h" | 37 #include "third_party/WebKit/public/web/WebElement.h" |
| 41 #include "third_party/WebKit/public/web/WebFormElement.h" | 38 #include "third_party/WebKit/public/web/WebFormElement.h" |
| 42 #include "third_party/WebKit/public/web/WebInputEvent.h" | 39 #include "third_party/WebKit/public/web/WebInputEvent.h" |
| 43 #include "third_party/WebKit/public/web/WebLocalFrame.h" | 40 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
| 44 #include "third_party/WebKit/public/web/WebNode.h" | 41 #include "third_party/WebKit/public/web/WebNode.h" |
| 45 #include "third_party/WebKit/public/web/WebUserGestureIndicator.h" | 42 #include "third_party/WebKit/public/web/WebUserGestureIndicator.h" |
| (...skipping 528 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 574 | 571 |
| 575 } // namespace | 572 } // namespace |
| 576 | 573 |
| 577 //////////////////////////////////////////////////////////////////////////////// | 574 //////////////////////////////////////////////////////////////////////////////// |
| 578 // PasswordAutofillAgent, public: | 575 // PasswordAutofillAgent, public: |
| 579 | 576 |
| 580 PasswordAutofillAgent::PasswordAutofillAgent(content::RenderFrame* render_frame) | 577 PasswordAutofillAgent::PasswordAutofillAgent(content::RenderFrame* render_frame) |
| 581 : content::RenderFrameObserver(render_frame), | 578 : content::RenderFrameObserver(render_frame), |
| 582 logging_state_active_(false), | 579 logging_state_active_(false), |
| 583 was_username_autofilled_(false), | 580 was_username_autofilled_(false), |
| 584 was_password_autofilled_(false), | 581 was_password_autofilled_(false) { |
| 585 binding_(this) { | 582 Send(new AutofillHostMsg_PasswordAutofillAgentConstructed(routing_id())); |
| 586 // PasswordAutofillAgent is guaranteed to outlive |render_frame|. | |
| 587 render_frame->GetInterfaceRegistry()->AddInterface( | |
| 588 base::Bind(&PasswordAutofillAgent::BindRequest, base::Unretained(this))); | |
| 589 GetPasswordManagerDriver()->PasswordAutofillAgentConstructed(); | |
| 590 } | 583 } |
| 591 | 584 |
| 592 PasswordAutofillAgent::~PasswordAutofillAgent() { | 585 PasswordAutofillAgent::~PasswordAutofillAgent() { |
| 593 } | 586 } |
| 594 | 587 |
| 595 void PasswordAutofillAgent::BindRequest( | |
| 596 mojom::PasswordAutofillAgentRequest request) { | |
| 597 binding_.Bind(std::move(request)); | |
| 598 } | |
| 599 | |
| 600 void PasswordAutofillAgent::SetAutofillAgent(AutofillAgent* autofill_agent) { | 588 void PasswordAutofillAgent::SetAutofillAgent(AutofillAgent* autofill_agent) { |
| 601 autofill_agent_ = autofill_agent; | 589 autofill_agent_ = autofill_agent; |
| 602 } | 590 } |
| 603 | 591 |
| 604 PasswordAutofillAgent::PasswordValueGatekeeper::PasswordValueGatekeeper() | 592 PasswordAutofillAgent::PasswordValueGatekeeper::PasswordValueGatekeeper() |
| 605 : was_user_gesture_seen_(false) { | 593 : was_user_gesture_seen_(false) { |
| 606 } | 594 } |
| 607 | 595 |
| 608 PasswordAutofillAgent::PasswordValueGatekeeper::~PasswordValueGatekeeper() { | 596 PasswordAutofillAgent::PasswordValueGatekeeper::~PasswordValueGatekeeper() { |
| 609 } | 597 } |
| (...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 961 if (form_util::IsFormVisible(frame, provisionally_saved_form_->action, | 949 if (form_util::IsFormVisible(frame, provisionally_saved_form_->action, |
| 962 provisionally_saved_form_->origin, | 950 provisionally_saved_form_->origin, |
| 963 provisionally_saved_form_->form_data) || | 951 provisionally_saved_form_->form_data) || |
| 964 IsUnownedPasswordFormVisible(frame, provisionally_saved_form_->action, | 952 IsUnownedPasswordFormVisible(frame, provisionally_saved_form_->action, |
| 965 provisionally_saved_form_->origin, | 953 provisionally_saved_form_->origin, |
| 966 provisionally_saved_form_->form_data, | 954 provisionally_saved_form_->form_data, |
| 967 form_predictions_)) { | 955 form_predictions_)) { |
| 968 return; | 956 return; |
| 969 } | 957 } |
| 970 | 958 |
| 971 GetPasswordManagerDriver()->InPageNavigation(*provisionally_saved_form_); | 959 Send(new AutofillHostMsg_InPageNavigation(routing_id(), |
| 960 *provisionally_saved_form_)); |
| 972 provisionally_saved_form_.reset(); | 961 provisionally_saved_form_.reset(); |
| 973 } | 962 } |
| 974 | 963 |
| 975 void PasswordAutofillAgent::FirstUserGestureObserved() { | 964 void PasswordAutofillAgent::FirstUserGestureObserved() { |
| 976 gatekeeper_.OnUserGesture(); | 965 gatekeeper_.OnUserGesture(); |
| 977 } | 966 } |
| 978 | 967 |
| 979 void PasswordAutofillAgent::SendPasswordForms(bool only_visible) { | 968 void PasswordAutofillAgent::SendPasswordForms(bool only_visible) { |
| 980 std::unique_ptr<RendererSavePasswordProgressLogger> logger; | 969 std::unique_ptr<RendererSavePasswordProgressLogger> logger; |
| 981 if (logging_state_active_) { | 970 if (logging_state_active_) { |
| 982 logger.reset(new RendererSavePasswordProgressLogger( | 971 logger.reset(new RendererSavePasswordProgressLogger(this, routing_id())); |
| 983 GetPasswordManagerDriver().get())); | |
| 984 logger->LogMessage(Logger::STRING_SEND_PASSWORD_FORMS_METHOD); | 972 logger->LogMessage(Logger::STRING_SEND_PASSWORD_FORMS_METHOD); |
| 985 logger->LogBoolean(Logger::STRING_ONLY_VISIBLE, only_visible); | 973 logger->LogBoolean(Logger::STRING_ONLY_VISIBLE, only_visible); |
| 986 } | 974 } |
| 987 | 975 |
| 988 blink::WebFrame* frame = render_frame()->GetWebFrame(); | 976 blink::WebFrame* frame = render_frame()->GetWebFrame(); |
| 989 // Make sure that this security origin is allowed to use password manager. | 977 // Make sure that this security origin is allowed to use password manager. |
| 990 blink::WebSecurityOrigin origin = frame->document().getSecurityOrigin(); | 978 blink::WebSecurityOrigin origin = frame->document().getSecurityOrigin(); |
| 991 if (logger) { | 979 if (logger) { |
| 992 logger->LogURL(Logger::STRING_SECURITY_ORIGIN, | 980 logger->LogURL(Logger::STRING_SECURITY_ORIGIN, |
| 993 GURL(origin.toString().utf8())); | 981 GURL(origin.toString().utf8())); |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1068 if (password_forms.empty() && !only_visible) { | 1056 if (password_forms.empty() && !only_visible) { |
| 1069 // We need to send the PasswordFormsRendered message regardless of whether | 1057 // We need to send the PasswordFormsRendered message regardless of whether |
| 1070 // there are any forms visible, as this is also the code path that triggers | 1058 // there are any forms visible, as this is also the code path that triggers |
| 1071 // showing the infobar. | 1059 // showing the infobar. |
| 1072 return; | 1060 return; |
| 1073 } | 1061 } |
| 1074 | 1062 |
| 1075 if (only_visible) { | 1063 if (only_visible) { |
| 1076 blink::WebFrame* main_frame = render_frame()->GetWebFrame()->top(); | 1064 blink::WebFrame* main_frame = render_frame()->GetWebFrame()->top(); |
| 1077 bool did_stop_loading = !main_frame || !main_frame->isLoading(); | 1065 bool did_stop_loading = !main_frame || !main_frame->isLoading(); |
| 1078 GetPasswordManagerDriver()->PasswordFormsRendered(password_forms, | 1066 Send(new AutofillHostMsg_PasswordFormsRendered(routing_id(), password_forms, |
| 1079 did_stop_loading); | 1067 did_stop_loading)); |
| 1080 } else { | 1068 } else { |
| 1081 GetPasswordManagerDriver()->PasswordFormsParsed(password_forms); | 1069 Send(new AutofillHostMsg_PasswordFormsParsed(routing_id(), password_forms)); |
| 1082 } | 1070 } |
| 1083 } | 1071 } |
| 1084 | 1072 |
| 1073 bool PasswordAutofillAgent::OnMessageReceived(const IPC::Message& message) { |
| 1074 bool handled = true; |
| 1075 IPC_BEGIN_MESSAGE_MAP(PasswordAutofillAgent, message) |
| 1076 IPC_MESSAGE_HANDLER(AutofillMsg_FillPasswordForm, OnFillPasswordForm) |
| 1077 IPC_MESSAGE_HANDLER(AutofillMsg_SetLoggingState, OnSetLoggingState) |
| 1078 IPC_MESSAGE_HANDLER(AutofillMsg_AutofillUsernameAndPasswordDataReceived, |
| 1079 OnAutofillUsernameAndPasswordDataReceived) |
| 1080 IPC_MESSAGE_HANDLER(AutofillMsg_FindFocusedPasswordForm, |
| 1081 OnFindFocusedPasswordForm) |
| 1082 IPC_MESSAGE_UNHANDLED(handled = false) |
| 1083 IPC_END_MESSAGE_MAP() |
| 1084 return handled; |
| 1085 } |
| 1086 |
| 1085 void PasswordAutofillAgent::DidFinishDocumentLoad() { | 1087 void PasswordAutofillAgent::DidFinishDocumentLoad() { |
| 1086 // The |frame| contents have been parsed, but not yet rendered. Let the | 1088 // The |frame| contents have been parsed, but not yet rendered. Let the |
| 1087 // PasswordManager know that forms are loaded, even though we can't yet tell | 1089 // PasswordManager know that forms are loaded, even though we can't yet tell |
| 1088 // whether they're visible. | 1090 // whether they're visible. |
| 1089 form_util::ScopedLayoutPreventer layout_preventer; | 1091 form_util::ScopedLayoutPreventer layout_preventer; |
| 1090 SendPasswordForms(false); | 1092 SendPasswordForms(false); |
| 1091 } | 1093 } |
| 1092 | 1094 |
| 1093 void PasswordAutofillAgent::DidFinishLoad() { | 1095 void PasswordAutofillAgent::DidFinishLoad() { |
| 1094 // The |frame| contents have been rendered. Let the PasswordManager know | 1096 // The |frame| contents have been rendered. Let the PasswordManager know |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1108 OnSamePageNavigationCompleted(); | 1110 OnSamePageNavigationCompleted(); |
| 1109 } | 1111 } |
| 1110 } | 1112 } |
| 1111 | 1113 |
| 1112 void PasswordAutofillAgent::FrameDetached() { | 1114 void PasswordAutofillAgent::FrameDetached() { |
| 1113 // If a sub frame has been destroyed while the user was entering information | 1115 // If a sub frame has been destroyed while the user was entering information |
| 1114 // into a password form, try to save the data. See https://crbug.com/450806 | 1116 // into a password form, try to save the data. See https://crbug.com/450806 |
| 1115 // for examples of sites that perform login using this technique. | 1117 // for examples of sites that perform login using this technique. |
| 1116 if (render_frame()->GetWebFrame()->parent() && | 1118 if (render_frame()->GetWebFrame()->parent() && |
| 1117 ProvisionallySavedPasswordIsValid()) { | 1119 ProvisionallySavedPasswordIsValid()) { |
| 1118 GetPasswordManagerDriver()->InPageNavigation(*provisionally_saved_form_); | 1120 Send(new AutofillHostMsg_InPageNavigation(routing_id(), |
| 1121 *provisionally_saved_form_)); |
| 1119 } | 1122 } |
| 1120 FrameClosing(); | 1123 FrameClosing(); |
| 1121 } | 1124 } |
| 1122 | 1125 |
| 1123 void PasswordAutofillAgent::WillSendSubmitEvent( | 1126 void PasswordAutofillAgent::WillSendSubmitEvent( |
| 1124 const blink::WebFormElement& form) { | 1127 const blink::WebFormElement& form) { |
| 1125 // Forms submitted via XHR are not seen by WillSubmitForm if the default | 1128 // Forms submitted via XHR are not seen by WillSubmitForm if the default |
| 1126 // onsubmit handler is overridden. Such submission first gets detected in | 1129 // onsubmit handler is overridden. Such submission first gets detected in |
| 1127 // DidStartProvisionalLoad, which no longer knows about the particular form, | 1130 // DidStartProvisionalLoad, which no longer knows about the particular form, |
| 1128 // and uses the candidate stored in |provisionally_saved_form_|. | 1131 // and uses the candidate stored in |provisionally_saved_form_|. |
| 1129 // | 1132 // |
| 1130 // User-typed password will get stored to |provisionally_saved_form_| in | 1133 // User-typed password will get stored to |provisionally_saved_form_| in |
| 1131 // TextDidChangeInTextField. Autofilled or JavaScript-copied passwords need to | 1134 // TextDidChangeInTextField. Autofilled or JavaScript-copied passwords need to |
| 1132 // be saved here. | 1135 // be saved here. |
| 1133 // | 1136 // |
| 1134 // Only non-empty passwords are saved here. Empty passwords were likely | 1137 // Only non-empty passwords are saved here. Empty passwords were likely |
| 1135 // cleared by some scripts (http://crbug.com/28910, http://crbug.com/391693). | 1138 // cleared by some scripts (http://crbug.com/28910, http://crbug.com/391693). |
| 1136 // Had the user cleared the password, |provisionally_saved_form_| would | 1139 // Had the user cleared the password, |provisionally_saved_form_| would |
| 1137 // already have been updated in TextDidChangeInTextField. | 1140 // already have been updated in TextDidChangeInTextField. |
| 1138 std::unique_ptr<PasswordForm> password_form = CreatePasswordFormFromWebForm( | 1141 std::unique_ptr<PasswordForm> password_form = CreatePasswordFormFromWebForm( |
| 1139 form, &field_value_and_properties_map_, &form_predictions_); | 1142 form, &field_value_and_properties_map_, &form_predictions_); |
| 1140 ProvisionallySavePassword(std::move(password_form), | 1143 ProvisionallySavePassword(std::move(password_form), |
| 1141 RESTRICTION_NON_EMPTY_PASSWORD); | 1144 RESTRICTION_NON_EMPTY_PASSWORD); |
| 1142 } | 1145 } |
| 1143 | 1146 |
| 1144 void PasswordAutofillAgent::WillSubmitForm(const blink::WebFormElement& form) { | 1147 void PasswordAutofillAgent::WillSubmitForm(const blink::WebFormElement& form) { |
| 1145 std::unique_ptr<RendererSavePasswordProgressLogger> logger; | 1148 std::unique_ptr<RendererSavePasswordProgressLogger> logger; |
| 1146 if (logging_state_active_) { | 1149 if (logging_state_active_) { |
| 1147 logger.reset(new RendererSavePasswordProgressLogger( | 1150 logger.reset(new RendererSavePasswordProgressLogger(this, routing_id())); |
| 1148 GetPasswordManagerDriver().get())); | |
| 1149 logger->LogMessage(Logger::STRING_WILL_SUBMIT_FORM_METHOD); | 1151 logger->LogMessage(Logger::STRING_WILL_SUBMIT_FORM_METHOD); |
| 1150 LogHTMLForm(logger.get(), Logger::STRING_HTML_FORM_FOR_SUBMIT, form); | 1152 LogHTMLForm(logger.get(), Logger::STRING_HTML_FORM_FOR_SUBMIT, form); |
| 1151 } | 1153 } |
| 1152 | 1154 |
| 1153 std::unique_ptr<PasswordForm> submitted_form = CreatePasswordFormFromWebForm( | 1155 std::unique_ptr<PasswordForm> submitted_form = CreatePasswordFormFromWebForm( |
| 1154 form, &field_value_and_properties_map_, &form_predictions_); | 1156 form, &field_value_and_properties_map_, &form_predictions_); |
| 1155 | 1157 |
| 1156 // If there is a provisionally saved password, copy over the previous | 1158 // If there is a provisionally saved password, copy over the previous |
| 1157 // password value so we get the user's typed password, not the value that | 1159 // password value so we get the user's typed password, not the value that |
| 1158 // may have been transformed for submit. | 1160 // may have been transformed for submit. |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1172 submitted_form->new_password_value = | 1174 submitted_form->new_password_value = |
| 1173 provisionally_saved_form_->new_password_value; | 1175 provisionally_saved_form_->new_password_value; |
| 1174 submitted_form->username_value = | 1176 submitted_form->username_value = |
| 1175 provisionally_saved_form_->username_value; | 1177 provisionally_saved_form_->username_value; |
| 1176 } | 1178 } |
| 1177 | 1179 |
| 1178 // Some observers depend on sending this information now instead of when | 1180 // Some observers depend on sending this information now instead of when |
| 1179 // the frame starts loading. If there are redirects that cause a new | 1181 // the frame starts loading. If there are redirects that cause a new |
| 1180 // RenderView to be instantiated (such as redirects to the WebStore) | 1182 // RenderView to be instantiated (such as redirects to the WebStore) |
| 1181 // we will never get to finish the load. | 1183 // we will never get to finish the load. |
| 1182 GetPasswordManagerDriver()->PasswordFormSubmitted(*submitted_form); | 1184 Send(new AutofillHostMsg_PasswordFormSubmitted(routing_id(), |
| 1185 *submitted_form)); |
| 1183 provisionally_saved_form_.reset(); | 1186 provisionally_saved_form_.reset(); |
| 1184 } else if (logger) { | 1187 } else if (logger) { |
| 1185 logger->LogMessage(Logger::STRING_FORM_IS_NOT_PASSWORD); | 1188 logger->LogMessage(Logger::STRING_FORM_IS_NOT_PASSWORD); |
| 1186 } | 1189 } |
| 1187 } | 1190 } |
| 1188 | 1191 |
| 1189 void PasswordAutofillAgent::OnDestruct() { | 1192 void PasswordAutofillAgent::OnDestruct() { |
| 1190 base::ThreadTaskRunnerHandle::Get()->DeleteSoon(FROM_HERE, this); | 1193 base::ThreadTaskRunnerHandle::Get()->DeleteSoon(FROM_HERE, this); |
| 1191 } | 1194 } |
| 1192 | 1195 |
| 1193 void PasswordAutofillAgent::DidStartProvisionalLoad() { | 1196 void PasswordAutofillAgent::DidStartProvisionalLoad() { |
| 1194 std::unique_ptr<RendererSavePasswordProgressLogger> logger; | 1197 std::unique_ptr<RendererSavePasswordProgressLogger> logger; |
| 1195 if (logging_state_active_) { | 1198 if (logging_state_active_) { |
| 1196 logger.reset(new RendererSavePasswordProgressLogger( | 1199 logger.reset(new RendererSavePasswordProgressLogger(this, routing_id())); |
| 1197 GetPasswordManagerDriver().get())); | |
| 1198 logger->LogMessage(Logger::STRING_DID_START_PROVISIONAL_LOAD_METHOD); | 1200 logger->LogMessage(Logger::STRING_DID_START_PROVISIONAL_LOAD_METHOD); |
| 1199 } | 1201 } |
| 1200 | 1202 |
| 1201 const blink::WebLocalFrame* navigated_frame = render_frame()->GetWebFrame(); | 1203 const blink::WebLocalFrame* navigated_frame = render_frame()->GetWebFrame(); |
| 1202 if (navigated_frame->parent()) { | 1204 if (navigated_frame->parent()) { |
| 1203 if (logger) | 1205 if (logger) |
| 1204 logger->LogMessage(Logger::STRING_FRAME_NOT_MAIN_FRAME); | 1206 logger->LogMessage(Logger::STRING_FRAME_NOT_MAIN_FRAME); |
| 1205 return; | 1207 return; |
| 1206 } | 1208 } |
| 1207 | 1209 |
| 1208 // Bug fix for crbug.com/368690. isProcessingUserGesture() is false when | 1210 // Bug fix for crbug.com/368690. isProcessingUserGesture() is false when |
| 1209 // the user is performing actions outside the page (e.g. typed url, | 1211 // the user is performing actions outside the page (e.g. typed url, |
| 1210 // history navigation). We don't want to trigger saving in these cases. | 1212 // history navigation). We don't want to trigger saving in these cases. |
| 1211 content::DocumentState* document_state = | 1213 content::DocumentState* document_state = |
| 1212 content::DocumentState::FromDataSource( | 1214 content::DocumentState::FromDataSource( |
| 1213 navigated_frame->provisionalDataSource()); | 1215 navigated_frame->provisionalDataSource()); |
| 1214 content::NavigationState* navigation_state = | 1216 content::NavigationState* navigation_state = |
| 1215 document_state->navigation_state(); | 1217 document_state->navigation_state(); |
| 1216 ui::PageTransition type = navigation_state->GetTransitionType(); | 1218 ui::PageTransition type = navigation_state->GetTransitionType(); |
| 1217 if (ui::PageTransitionIsWebTriggerable(type) && | 1219 if (ui::PageTransitionIsWebTriggerable(type) && |
| 1218 ui::PageTransitionIsNewNavigation(type) && | 1220 ui::PageTransitionIsNewNavigation(type) && |
| 1219 !blink::WebUserGestureIndicator::isProcessingUserGesture()) { | 1221 !blink::WebUserGestureIndicator::isProcessingUserGesture()) { |
| 1220 // If onsubmit has been called, try and save that form. | 1222 // If onsubmit has been called, try and save that form. |
| 1221 if (provisionally_saved_form_) { | 1223 if (provisionally_saved_form_) { |
| 1222 if (logger) { | 1224 if (logger) { |
| 1223 logger->LogPasswordForm( | 1225 logger->LogPasswordForm( |
| 1224 Logger::STRING_PROVISIONALLY_SAVED_FORM_FOR_FRAME, | 1226 Logger::STRING_PROVISIONALLY_SAVED_FORM_FOR_FRAME, |
| 1225 *provisionally_saved_form_); | 1227 *provisionally_saved_form_); |
| 1226 } | 1228 } |
| 1227 GetPasswordManagerDriver()->PasswordFormSubmitted( | 1229 Send(new AutofillHostMsg_PasswordFormSubmitted( |
| 1228 *provisionally_saved_form_); | 1230 routing_id(), *provisionally_saved_form_)); |
| 1229 provisionally_saved_form_.reset(); | 1231 provisionally_saved_form_.reset(); |
| 1230 } else { | 1232 } else { |
| 1231 ScopedVector<PasswordForm> possible_submitted_forms; | 1233 ScopedVector<PasswordForm> possible_submitted_forms; |
| 1232 // Loop through the forms on the page looking for one that has been | 1234 // Loop through the forms on the page looking for one that has been |
| 1233 // filled out. If one exists, try and save the credentials. | 1235 // filled out. If one exists, try and save the credentials. |
| 1234 blink::WebVector<blink::WebFormElement> forms; | 1236 blink::WebVector<blink::WebFormElement> forms; |
| 1235 render_frame()->GetWebFrame()->document().forms(forms); | 1237 render_frame()->GetWebFrame()->document().forms(forms); |
| 1236 | 1238 |
| 1237 bool password_forms_found = false; | 1239 bool password_forms_found = false; |
| 1238 for (size_t i = 0; i < forms.size(); ++i) { | 1240 for (size_t i = 0; i < forms.size(); ++i) { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1252 &form_predictions_)); | 1254 &form_predictions_)); |
| 1253 | 1255 |
| 1254 for (const PasswordForm* password_form : possible_submitted_forms) { | 1256 for (const PasswordForm* password_form : possible_submitted_forms) { |
| 1255 if (password_form && !password_form->username_value.empty() && | 1257 if (password_form && !password_form->username_value.empty() && |
| 1256 FormContainsNonDefaultPasswordValue(*password_form)) { | 1258 FormContainsNonDefaultPasswordValue(*password_form)) { |
| 1257 password_forms_found = true; | 1259 password_forms_found = true; |
| 1258 if (logger) { | 1260 if (logger) { |
| 1259 logger->LogPasswordForm(Logger::STRING_PASSWORD_FORM_FOUND_ON_PAGE, | 1261 logger->LogPasswordForm(Logger::STRING_PASSWORD_FORM_FOUND_ON_PAGE, |
| 1260 *password_form); | 1262 *password_form); |
| 1261 } | 1263 } |
| 1262 GetPasswordManagerDriver()->PasswordFormSubmitted(*password_form); | 1264 Send(new AutofillHostMsg_PasswordFormSubmitted(routing_id(), |
| 1265 *password_form)); |
| 1263 break; | 1266 break; |
| 1264 } | 1267 } |
| 1265 } | 1268 } |
| 1266 | 1269 |
| 1267 if (!password_forms_found && logger) | 1270 if (!password_forms_found && logger) |
| 1268 logger->LogMessage(Logger::STRING_PASSWORD_FORM_NOT_FOUND_ON_PAGE); | 1271 logger->LogMessage(Logger::STRING_PASSWORD_FORM_NOT_FOUND_ON_PAGE); |
| 1269 } | 1272 } |
| 1270 } | 1273 } |
| 1271 | 1274 |
| 1272 // This is a new navigation, so require a new user gesture before filling in | 1275 // This is a new navigation, so require a new user gesture before filling in |
| 1273 // passwords. | 1276 // passwords. |
| 1274 gatekeeper_.Reset(); | 1277 gatekeeper_.Reset(); |
| 1275 } | 1278 } |
| 1276 | 1279 |
| 1277 // mojom::PasswordAutofillAgent: | 1280 void PasswordAutofillAgent::OnFillPasswordForm( |
| 1278 void PasswordAutofillAgent::FillPasswordForm( | |
| 1279 int key, | 1281 int key, |
| 1280 const PasswordFormFillData& form_data) { | 1282 const PasswordFormFillData& form_data) { |
| 1281 std::vector<blink::WebInputElement> elements; | 1283 std::vector<blink::WebInputElement> elements; |
| 1282 std::unique_ptr<RendererSavePasswordProgressLogger> logger; | 1284 std::unique_ptr<RendererSavePasswordProgressLogger> logger; |
| 1283 if (logging_state_active_) { | 1285 if (logging_state_active_) { |
| 1284 logger.reset(new RendererSavePasswordProgressLogger( | 1286 logger.reset(new RendererSavePasswordProgressLogger(this, routing_id())); |
| 1285 GetPasswordManagerDriver().get())); | |
| 1286 logger->LogMessage(Logger::STRING_ON_FILL_PASSWORD_FORM_METHOD); | 1287 logger->LogMessage(Logger::STRING_ON_FILL_PASSWORD_FORM_METHOD); |
| 1287 } | 1288 } |
| 1288 GetFillableElementFromFormData(key, form_data, logger.get(), &elements); | 1289 GetFillableElementFromFormData(key, form_data, logger.get(), &elements); |
| 1289 | 1290 |
| 1290 // If wait_for_username is true, we don't want to initially fill the form | 1291 // If wait_for_username is true, we don't want to initially fill the form |
| 1291 // until the user types in a valid username. | 1292 // until the user types in a valid username. |
| 1292 if (form_data.wait_for_username) | 1293 if (form_data.wait_for_username) |
| 1293 return; | 1294 return; |
| 1294 | 1295 |
| 1295 for (auto element : elements) { | 1296 for (auto element : elements) { |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1395 const blink::WebElement web_element = node.toConst<blink::WebElement>(); | 1396 const blink::WebElement web_element = node.toConst<blink::WebElement>(); |
| 1396 if (!web_element.isFormControlElement()) | 1397 if (!web_element.isFormControlElement()) |
| 1397 return; | 1398 return; |
| 1398 const blink::WebFormControlElement control_element = | 1399 const blink::WebFormControlElement control_element = |
| 1399 web_element.toConst<blink::WebFormControlElement>(); | 1400 web_element.toConst<blink::WebFormControlElement>(); |
| 1400 UpdateFieldValueAndPropertiesMaskMap(control_element, nullptr, | 1401 UpdateFieldValueAndPropertiesMaskMap(control_element, nullptr, |
| 1401 FieldPropertiesFlags::HAD_FOCUS, | 1402 FieldPropertiesFlags::HAD_FOCUS, |
| 1402 &field_value_and_properties_map_); | 1403 &field_value_and_properties_map_); |
| 1403 } | 1404 } |
| 1404 | 1405 |
| 1405 // mojom::PasswordAutofillAgent: | 1406 void PasswordAutofillAgent::OnSetLoggingState(bool active) { |
| 1406 void PasswordAutofillAgent::SetLoggingState(bool active) { | |
| 1407 logging_state_active_ = active; | 1407 logging_state_active_ = active; |
| 1408 } | 1408 } |
| 1409 | 1409 |
| 1410 void PasswordAutofillAgent::AutofillUsernameAndPasswordDataReceived( | 1410 void PasswordAutofillAgent::OnAutofillUsernameAndPasswordDataReceived( |
| 1411 const FormsPredictionsMap& predictions) { | 1411 const FormsPredictionsMap& predictions) { |
| 1412 form_predictions_.insert(predictions.begin(), predictions.end()); | 1412 form_predictions_.insert(predictions.begin(), predictions.end()); |
| 1413 } | 1413 } |
| 1414 | 1414 |
| 1415 void PasswordAutofillAgent::FindFocusedPasswordForm( | 1415 void PasswordAutofillAgent::OnFindFocusedPasswordForm() { |
| 1416 const FindFocusedPasswordFormCallback& callback) { | |
| 1417 std::unique_ptr<PasswordForm> password_form; | 1416 std::unique_ptr<PasswordForm> password_form; |
| 1418 | 1417 |
| 1419 blink::WebElement element = | 1418 blink::WebElement element = |
| 1420 render_frame()->GetWebFrame()->document().focusedElement(); | 1419 render_frame()->GetWebFrame()->document().focusedElement(); |
| 1421 if (!element.isNull() && element.hasHTMLTagName("input")) { | 1420 if (!element.isNull() && element.hasHTMLTagName("input")) { |
| 1422 blink::WebInputElement input = element.to<blink::WebInputElement>(); | 1421 blink::WebInputElement input = element.to<blink::WebInputElement>(); |
| 1423 if (input.isPasswordField() && !input.form().isNull()) { | 1422 if (input.isPasswordField() && !input.form().isNull()) { |
| 1424 if (!input.form().isNull()) { | 1423 if (!input.form().isNull()) { |
| 1425 password_form = CreatePasswordFormFromWebForm( | 1424 password_form = CreatePasswordFormFromWebForm( |
| 1426 input.form(), &field_value_and_properties_map_, &form_predictions_); | 1425 input.form(), &field_value_and_properties_map_, &form_predictions_); |
| 1427 } else { | 1426 } else { |
| 1428 password_form = CreatePasswordFormFromUnownedInputElements( | 1427 password_form = CreatePasswordFormFromUnownedInputElements( |
| 1429 *render_frame()->GetWebFrame(), &field_value_and_properties_map_, | 1428 *render_frame()->GetWebFrame(), &field_value_and_properties_map_, |
| 1430 &form_predictions_); | 1429 &form_predictions_); |
| 1431 // Only try to use this form if |input| is one of the password elements | 1430 // Only try to use this form if |input| is one of the password elements |
| 1432 // for |password_form|. | 1431 // for |password_form|. |
| 1433 if (password_form->password_element != input.nameForAutofill() && | 1432 if (password_form->password_element != input.nameForAutofill() && |
| 1434 password_form->new_password_element != input.nameForAutofill()) | 1433 password_form->new_password_element != input.nameForAutofill()) |
| 1435 password_form.reset(); | 1434 password_form.reset(); |
| 1436 } | 1435 } |
| 1437 } | 1436 } |
| 1438 } | 1437 } |
| 1439 | 1438 |
| 1440 if (!password_form) | 1439 if (!password_form) |
| 1441 password_form.reset(new PasswordForm()); | 1440 password_form.reset(new PasswordForm()); |
| 1442 | 1441 |
| 1443 callback.Run(*password_form); | 1442 Send(new AutofillHostMsg_FocusedPasswordFormFound( |
| 1443 routing_id(), *password_form)); |
| 1444 } | 1444 } |
| 1445 | 1445 |
| 1446 //////////////////////////////////////////////////////////////////////////////// | 1446 //////////////////////////////////////////////////////////////////////////////// |
| 1447 // PasswordAutofillAgent, private: | 1447 // PasswordAutofillAgent, private: |
| 1448 | 1448 |
| 1449 bool PasswordAutofillAgent::ShowSuggestionPopup( | 1449 bool PasswordAutofillAgent::ShowSuggestionPopup( |
| 1450 const PasswordInfo& password_info, | 1450 const PasswordInfo& password_info, |
| 1451 const blink::WebInputElement& user_input, | 1451 const blink::WebInputElement& user_input, |
| 1452 bool show_all, | 1452 bool show_all, |
| 1453 bool show_on_password_field) { | 1453 bool show_on_password_field) { |
| (...skipping 20 matching lines...) Expand all Loading... |
| 1474 if (show_all) | 1474 if (show_all) |
| 1475 options |= SHOW_ALL; | 1475 options |= SHOW_ALL; |
| 1476 if (show_on_password_field) | 1476 if (show_on_password_field) |
| 1477 options |= IS_PASSWORD_FIELD; | 1477 options |= IS_PASSWORD_FIELD; |
| 1478 | 1478 |
| 1479 base::string16 username_string( | 1479 base::string16 username_string( |
| 1480 user_input.isPasswordField() | 1480 user_input.isPasswordField() |
| 1481 ? base::string16() | 1481 ? base::string16() |
| 1482 : static_cast<base::string16>(user_input.value())); | 1482 : static_cast<base::string16>(user_input.value())); |
| 1483 | 1483 |
| 1484 GetPasswordManagerDriver()->ShowPasswordSuggestions( | 1484 Send(new AutofillHostMsg_ShowPasswordSuggestions( |
| 1485 password_info.key, field.text_direction, username_string, options, | 1485 routing_id(), password_info.key, field.text_direction, username_string, |
| 1486 render_frame()->GetRenderView()->ElementBoundsInWindow(user_input)); | 1486 options, |
| 1487 render_frame()->GetRenderView()->ElementBoundsInWindow(user_input))); |
| 1487 username_query_prefix_ = username_string; | 1488 username_query_prefix_ = username_string; |
| 1488 return CanShowSuggestion(password_info.fill_data, username_string, show_all); | 1489 return CanShowSuggestion(password_info.fill_data, username_string, show_all); |
| 1489 } | 1490 } |
| 1490 | 1491 |
| 1491 void PasswordAutofillAgent::FrameClosing() { | 1492 void PasswordAutofillAgent::FrameClosing() { |
| 1492 for (auto const& iter : web_input_to_password_info_) { | 1493 for (auto const& iter : web_input_to_password_info_) { |
| 1493 password_to_username_.erase(iter.second.password_field); | 1494 password_to_username_.erase(iter.second.password_field); |
| 1494 } | 1495 } |
| 1495 web_input_to_password_info_.clear(); | 1496 web_input_to_password_info_.clear(); |
| 1496 provisionally_saved_form_.reset(); | 1497 provisionally_saved_form_.reset(); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1528 !provisionally_saved_form_->username_value.empty() && | 1529 !provisionally_saved_form_->username_value.empty() && |
| 1529 !(provisionally_saved_form_->password_value.empty() && | 1530 !(provisionally_saved_form_->password_value.empty() && |
| 1530 provisionally_saved_form_->new_password_value.empty()); | 1531 provisionally_saved_form_->new_password_value.empty()); |
| 1531 } | 1532 } |
| 1532 | 1533 |
| 1533 const mojom::AutofillDriverPtr& PasswordAutofillAgent::GetAutofillDriver() { | 1534 const mojom::AutofillDriverPtr& PasswordAutofillAgent::GetAutofillDriver() { |
| 1534 DCHECK(autofill_agent_); | 1535 DCHECK(autofill_agent_); |
| 1535 return autofill_agent_->GetAutofillDriver(); | 1536 return autofill_agent_->GetAutofillDriver(); |
| 1536 } | 1537 } |
| 1537 | 1538 |
| 1538 const mojom::PasswordManagerDriverPtr& | |
| 1539 PasswordAutofillAgent::GetPasswordManagerDriver() { | |
| 1540 if (!password_manager_driver_) { | |
| 1541 render_frame()->GetRemoteInterfaces()->GetInterface( | |
| 1542 mojo::GetProxy(&password_manager_driver_)); | |
| 1543 } | |
| 1544 | |
| 1545 return password_manager_driver_; | |
| 1546 } | |
| 1547 | |
| 1548 } // namespace autofill | 1539 } // namespace autofill |
| OLD | NEW |