Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(461)

Side by Side Diff: components/autofill/content/renderer/password_autofill_agent.cc

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

Powered by Google App Engine
This is Rietveld 408576698