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

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

Issue 2270333002: Reland: [Autofill] Migrate ContentPasswordManagerDriver<-->Password{Autofill,Generation}Agent IPCs … (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase 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 314 matching lines...) Expand 10 before | Expand all | Expand 10 after
912 if (form_util::IsFormVisible(frame, provisionally_saved_form_->action, 924 if (form_util::IsFormVisible(frame, provisionally_saved_form_->action,
913 provisionally_saved_form_->origin, 925 provisionally_saved_form_->origin,
914 provisionally_saved_form_->form_data) || 926 provisionally_saved_form_->form_data) ||
915 IsUnownedPasswordFormVisible(frame, provisionally_saved_form_->action, 927 IsUnownedPasswordFormVisible(frame, provisionally_saved_form_->action,
916 provisionally_saved_form_->origin, 928 provisionally_saved_form_->origin,
917 provisionally_saved_form_->form_data, 929 provisionally_saved_form_->form_data,
918 form_predictions_)) { 930 form_predictions_)) {
919 return; 931 return;
920 } 932 }
921 933
922 Send(new AutofillHostMsg_InPageNavigation(routing_id(), 934 GetPasswordManagerDriver()->InPageNavigation(*provisionally_saved_form_);
923 *provisionally_saved_form_));
924 provisionally_saved_form_.reset(); 935 provisionally_saved_form_.reset();
925 } 936 }
926 937
927 void PasswordAutofillAgent::FirstUserGestureObserved() { 938 void PasswordAutofillAgent::FirstUserGestureObserved() {
928 gatekeeper_.OnUserGesture(); 939 gatekeeper_.OnUserGesture();
929 } 940 }
930 941
931 void PasswordAutofillAgent::SendPasswordForms(bool only_visible) { 942 void PasswordAutofillAgent::SendPasswordForms(bool only_visible) {
932 std::unique_ptr<RendererSavePasswordProgressLogger> logger; 943 std::unique_ptr<RendererSavePasswordProgressLogger> logger;
933 if (logging_state_active_) { 944 if (logging_state_active_) {
934 logger.reset(new RendererSavePasswordProgressLogger(this, routing_id())); 945 logger.reset(new RendererSavePasswordProgressLogger(
946 GetPasswordManagerDriver().get()));
935 logger->LogMessage(Logger::STRING_SEND_PASSWORD_FORMS_METHOD); 947 logger->LogMessage(Logger::STRING_SEND_PASSWORD_FORMS_METHOD);
936 logger->LogBoolean(Logger::STRING_ONLY_VISIBLE, only_visible); 948 logger->LogBoolean(Logger::STRING_ONLY_VISIBLE, only_visible);
937 } 949 }
938 950
939 blink::WebFrame* frame = render_frame()->GetWebFrame(); 951 blink::WebFrame* frame = render_frame()->GetWebFrame();
940 // Make sure that this security origin is allowed to use password manager. 952 // Make sure that this security origin is allowed to use password manager.
941 blink::WebSecurityOrigin origin = frame->document().getSecurityOrigin(); 953 blink::WebSecurityOrigin origin = frame->document().getSecurityOrigin();
942 if (logger) { 954 if (logger) {
943 logger->LogURL(Logger::STRING_SECURITY_ORIGIN, 955 logger->LogURL(Logger::STRING_SECURITY_ORIGIN,
944 GURL(origin.toString().utf8())); 956 GURL(origin.toString().utf8()));
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
1019 if (password_forms.empty() && !only_visible) { 1031 if (password_forms.empty() && !only_visible) {
1020 // We need to send the PasswordFormsRendered message regardless of whether 1032 // We need to send the PasswordFormsRendered message regardless of whether
1021 // there are any forms visible, as this is also the code path that triggers 1033 // there are any forms visible, as this is also the code path that triggers
1022 // showing the infobar. 1034 // showing the infobar.
1023 return; 1035 return;
1024 } 1036 }
1025 1037
1026 if (only_visible) { 1038 if (only_visible) {
1027 blink::WebFrame* main_frame = render_frame()->GetWebFrame()->top(); 1039 blink::WebFrame* main_frame = render_frame()->GetWebFrame()->top();
1028 bool did_stop_loading = !main_frame || !main_frame->isLoading(); 1040 bool did_stop_loading = !main_frame || !main_frame->isLoading();
1029 Send(new AutofillHostMsg_PasswordFormsRendered(routing_id(), password_forms, 1041 GetPasswordManagerDriver()->PasswordFormsRendered(password_forms,
1030 did_stop_loading)); 1042 did_stop_loading);
1031 } else { 1043 } else {
1032 Send(new AutofillHostMsg_PasswordFormsParsed(routing_id(), password_forms)); 1044 GetPasswordManagerDriver()->PasswordFormsParsed(password_forms);
1033 } 1045 }
1034 } 1046 }
1035 1047
1036 bool PasswordAutofillAgent::OnMessageReceived(const IPC::Message& message) {
1037 bool handled = true;
1038 IPC_BEGIN_MESSAGE_MAP(PasswordAutofillAgent, message)
1039 IPC_MESSAGE_HANDLER(AutofillMsg_FillPasswordForm, OnFillPasswordForm)
1040 IPC_MESSAGE_HANDLER(AutofillMsg_SetLoggingState, OnSetLoggingState)
1041 IPC_MESSAGE_HANDLER(AutofillMsg_AutofillUsernameAndPasswordDataReceived,
1042 OnAutofillUsernameAndPasswordDataReceived)
1043 IPC_MESSAGE_HANDLER(AutofillMsg_FindFocusedPasswordForm,
1044 OnFindFocusedPasswordForm)
1045 IPC_MESSAGE_UNHANDLED(handled = false)
1046 IPC_END_MESSAGE_MAP()
1047 return handled;
1048 }
1049
1050 void PasswordAutofillAgent::DidFinishDocumentLoad() { 1048 void PasswordAutofillAgent::DidFinishDocumentLoad() {
1051 // The |frame| contents have been parsed, but not yet rendered. Let the 1049 // The |frame| contents have been parsed, but not yet rendered. Let the
1052 // PasswordManager know that forms are loaded, even though we can't yet tell 1050 // PasswordManager know that forms are loaded, even though we can't yet tell
1053 // whether they're visible. 1051 // whether they're visible.
1054 form_util::ScopedLayoutPreventer layout_preventer; 1052 form_util::ScopedLayoutPreventer layout_preventer;
1055 SendPasswordForms(false); 1053 SendPasswordForms(false);
1056 } 1054 }
1057 1055
1058 void PasswordAutofillAgent::DidFinishLoad() { 1056 void PasswordAutofillAgent::DidFinishLoad() {
1059 // The |frame| contents have been rendered. Let the PasswordManager know 1057 // The |frame| contents have been rendered. Let the PasswordManager know
(...skipping 13 matching lines...) Expand all
1073 OnSamePageNavigationCompleted(); 1071 OnSamePageNavigationCompleted();
1074 } 1072 }
1075 } 1073 }
1076 1074
1077 void PasswordAutofillAgent::FrameDetached() { 1075 void PasswordAutofillAgent::FrameDetached() {
1078 // If a sub frame has been destroyed while the user was entering information 1076 // If a sub frame has been destroyed while the user was entering information
1079 // into a password form, try to save the data. See https://crbug.com/450806 1077 // into a password form, try to save the data. See https://crbug.com/450806
1080 // for examples of sites that perform login using this technique. 1078 // for examples of sites that perform login using this technique.
1081 if (render_frame()->GetWebFrame()->parent() && 1079 if (render_frame()->GetWebFrame()->parent() &&
1082 ProvisionallySavedPasswordIsValid()) { 1080 ProvisionallySavedPasswordIsValid()) {
1083 Send(new AutofillHostMsg_InPageNavigation(routing_id(), 1081 GetPasswordManagerDriver()->InPageNavigation(*provisionally_saved_form_);
1084 *provisionally_saved_form_));
1085 } 1082 }
1086 FrameClosing(); 1083 FrameClosing();
1087 } 1084 }
1088 1085
1089 void PasswordAutofillAgent::WillSendSubmitEvent( 1086 void PasswordAutofillAgent::WillSendSubmitEvent(
1090 const blink::WebFormElement& form) { 1087 const blink::WebFormElement& form) {
1091 // Forms submitted via XHR are not seen by WillSubmitForm if the default 1088 // Forms submitted via XHR are not seen by WillSubmitForm if the default
1092 // onsubmit handler is overridden. Such submission first gets detected in 1089 // onsubmit handler is overridden. Such submission first gets detected in
1093 // DidStartProvisionalLoad, which no longer knows about the particular form, 1090 // DidStartProvisionalLoad, which no longer knows about the particular form,
1094 // and uses the candidate stored in |provisionally_saved_form_|. 1091 // and uses the candidate stored in |provisionally_saved_form_|.
1095 // 1092 //
1096 // User-typed password will get stored to |provisionally_saved_form_| in 1093 // User-typed password will get stored to |provisionally_saved_form_| in
1097 // TextDidChangeInTextField. Autofilled or JavaScript-copied passwords need to 1094 // TextDidChangeInTextField. Autofilled or JavaScript-copied passwords need to
1098 // be saved here. 1095 // be saved here.
1099 // 1096 //
1100 // Only non-empty passwords are saved here. Empty passwords were likely 1097 // Only non-empty passwords are saved here. Empty passwords were likely
1101 // cleared by some scripts (http://crbug.com/28910, http://crbug.com/391693). 1098 // cleared by some scripts (http://crbug.com/28910, http://crbug.com/391693).
1102 // Had the user cleared the password, |provisionally_saved_form_| would 1099 // Had the user cleared the password, |provisionally_saved_form_| would
1103 // already have been updated in TextDidChangeInTextField. 1100 // already have been updated in TextDidChangeInTextField.
1104 std::unique_ptr<PasswordForm> password_form = CreatePasswordFormFromWebForm( 1101 std::unique_ptr<PasswordForm> password_form = CreatePasswordFormFromWebForm(
1105 form, &field_value_and_properties_map_, &form_predictions_); 1102 form, &field_value_and_properties_map_, &form_predictions_);
1106 ProvisionallySavePassword(std::move(password_form), 1103 ProvisionallySavePassword(std::move(password_form),
1107 RESTRICTION_NON_EMPTY_PASSWORD); 1104 RESTRICTION_NON_EMPTY_PASSWORD);
1108 } 1105 }
1109 1106
1110 void PasswordAutofillAgent::WillSubmitForm(const blink::WebFormElement& form) { 1107 void PasswordAutofillAgent::WillSubmitForm(const blink::WebFormElement& form) {
1111 std::unique_ptr<RendererSavePasswordProgressLogger> logger; 1108 std::unique_ptr<RendererSavePasswordProgressLogger> logger;
1112 if (logging_state_active_) { 1109 if (logging_state_active_) {
1113 logger.reset(new RendererSavePasswordProgressLogger(this, routing_id())); 1110 logger.reset(new RendererSavePasswordProgressLogger(
1111 GetPasswordManagerDriver().get()));
1114 logger->LogMessage(Logger::STRING_WILL_SUBMIT_FORM_METHOD); 1112 logger->LogMessage(Logger::STRING_WILL_SUBMIT_FORM_METHOD);
1115 LogHTMLForm(logger.get(), Logger::STRING_HTML_FORM_FOR_SUBMIT, form); 1113 LogHTMLForm(logger.get(), Logger::STRING_HTML_FORM_FOR_SUBMIT, form);
1116 } 1114 }
1117 1115
1118 std::unique_ptr<PasswordForm> submitted_form = CreatePasswordFormFromWebForm( 1116 std::unique_ptr<PasswordForm> submitted_form = CreatePasswordFormFromWebForm(
1119 form, &field_value_and_properties_map_, &form_predictions_); 1117 form, &field_value_and_properties_map_, &form_predictions_);
1120 1118
1121 // If there is a provisionally saved password, copy over the previous 1119 // If there is a provisionally saved password, copy over the previous
1122 // password value so we get the user's typed password, not the value that 1120 // password value so we get the user's typed password, not the value that
1123 // may have been transformed for submit. 1121 // may have been transformed for submit.
(...skipping 13 matching lines...) Expand all
1137 submitted_form->new_password_value = 1135 submitted_form->new_password_value =
1138 provisionally_saved_form_->new_password_value; 1136 provisionally_saved_form_->new_password_value;
1139 submitted_form->username_value = 1137 submitted_form->username_value =
1140 provisionally_saved_form_->username_value; 1138 provisionally_saved_form_->username_value;
1141 } 1139 }
1142 1140
1143 // Some observers depend on sending this information now instead of when 1141 // Some observers depend on sending this information now instead of when
1144 // the frame starts loading. If there are redirects that cause a new 1142 // the frame starts loading. If there are redirects that cause a new
1145 // RenderView to be instantiated (such as redirects to the WebStore) 1143 // RenderView to be instantiated (such as redirects to the WebStore)
1146 // we will never get to finish the load. 1144 // we will never get to finish the load.
1147 Send(new AutofillHostMsg_PasswordFormSubmitted(routing_id(), 1145 GetPasswordManagerDriver()->PasswordFormSubmitted(*submitted_form);
1148 *submitted_form));
1149 provisionally_saved_form_.reset(); 1146 provisionally_saved_form_.reset();
1150 } else if (logger) { 1147 } else if (logger) {
1151 logger->LogMessage(Logger::STRING_FORM_IS_NOT_PASSWORD); 1148 logger->LogMessage(Logger::STRING_FORM_IS_NOT_PASSWORD);
1152 } 1149 }
1153 } 1150 }
1154 1151
1155 void PasswordAutofillAgent::OnDestruct() { 1152 void PasswordAutofillAgent::OnDestruct() {
1156 base::ThreadTaskRunnerHandle::Get()->DeleteSoon(FROM_HERE, this); 1153 base::ThreadTaskRunnerHandle::Get()->DeleteSoon(FROM_HERE, this);
1157 } 1154 }
1158 1155
1159 void PasswordAutofillAgent::DidStartProvisionalLoad() { 1156 void PasswordAutofillAgent::DidStartProvisionalLoad() {
1160 std::unique_ptr<RendererSavePasswordProgressLogger> logger; 1157 std::unique_ptr<RendererSavePasswordProgressLogger> logger;
1161 if (logging_state_active_) { 1158 if (logging_state_active_) {
1162 logger.reset(new RendererSavePasswordProgressLogger(this, routing_id())); 1159 logger.reset(new RendererSavePasswordProgressLogger(
1160 GetPasswordManagerDriver().get()));
1163 logger->LogMessage(Logger::STRING_DID_START_PROVISIONAL_LOAD_METHOD); 1161 logger->LogMessage(Logger::STRING_DID_START_PROVISIONAL_LOAD_METHOD);
1164 } 1162 }
1165 1163
1166 const blink::WebLocalFrame* navigated_frame = render_frame()->GetWebFrame(); 1164 const blink::WebLocalFrame* navigated_frame = render_frame()->GetWebFrame();
1167 if (navigated_frame->parent()) { 1165 if (navigated_frame->parent()) {
1168 if (logger) 1166 if (logger)
1169 logger->LogMessage(Logger::STRING_FRAME_NOT_MAIN_FRAME); 1167 logger->LogMessage(Logger::STRING_FRAME_NOT_MAIN_FRAME);
1170 return; 1168 return;
1171 } 1169 }
1172 1170
1173 // Bug fix for crbug.com/368690. isProcessingUserGesture() is false when 1171 // Bug fix for crbug.com/368690. isProcessingUserGesture() is false when
1174 // the user is performing actions outside the page (e.g. typed url, 1172 // the user is performing actions outside the page (e.g. typed url,
1175 // history navigation). We don't want to trigger saving in these cases. 1173 // history navigation). We don't want to trigger saving in these cases.
1176 content::DocumentState* document_state = 1174 content::DocumentState* document_state =
1177 content::DocumentState::FromDataSource( 1175 content::DocumentState::FromDataSource(
1178 navigated_frame->provisionalDataSource()); 1176 navigated_frame->provisionalDataSource());
1179 content::NavigationState* navigation_state = 1177 content::NavigationState* navigation_state =
1180 document_state->navigation_state(); 1178 document_state->navigation_state();
1181 ui::PageTransition type = navigation_state->GetTransitionType(); 1179 ui::PageTransition type = navigation_state->GetTransitionType();
1182 if (ui::PageTransitionIsWebTriggerable(type) && 1180 if (ui::PageTransitionIsWebTriggerable(type) &&
1183 ui::PageTransitionIsNewNavigation(type) && 1181 ui::PageTransitionIsNewNavigation(type) &&
1184 !blink::WebUserGestureIndicator::isProcessingUserGesture()) { 1182 !blink::WebUserGestureIndicator::isProcessingUserGesture()) {
1185 // If onsubmit has been called, try and save that form. 1183 // If onsubmit has been called, try and save that form.
1186 if (provisionally_saved_form_) { 1184 if (provisionally_saved_form_) {
1187 if (logger) { 1185 if (logger) {
1188 logger->LogPasswordForm( 1186 logger->LogPasswordForm(
1189 Logger::STRING_PROVISIONALLY_SAVED_FORM_FOR_FRAME, 1187 Logger::STRING_PROVISIONALLY_SAVED_FORM_FOR_FRAME,
1190 *provisionally_saved_form_); 1188 *provisionally_saved_form_);
1191 } 1189 }
1192 Send(new AutofillHostMsg_PasswordFormSubmitted( 1190 GetPasswordManagerDriver()->PasswordFormSubmitted(
1193 routing_id(), *provisionally_saved_form_)); 1191 *provisionally_saved_form_);
1194 provisionally_saved_form_.reset(); 1192 provisionally_saved_form_.reset();
1195 } else { 1193 } else {
1196 ScopedVector<PasswordForm> possible_submitted_forms; 1194 ScopedVector<PasswordForm> possible_submitted_forms;
1197 // Loop through the forms on the page looking for one that has been 1195 // Loop through the forms on the page looking for one that has been
1198 // filled out. If one exists, try and save the credentials. 1196 // filled out. If one exists, try and save the credentials.
1199 blink::WebVector<blink::WebFormElement> forms; 1197 blink::WebVector<blink::WebFormElement> forms;
1200 render_frame()->GetWebFrame()->document().forms(forms); 1198 render_frame()->GetWebFrame()->document().forms(forms);
1201 1199
1202 bool password_forms_found = false; 1200 bool password_forms_found = false;
1203 for (size_t i = 0; i < forms.size(); ++i) { 1201 for (size_t i = 0; i < forms.size(); ++i) {
(...skipping 13 matching lines...) Expand all
1217 &form_predictions_)); 1215 &form_predictions_));
1218 1216
1219 for (const PasswordForm* password_form : possible_submitted_forms) { 1217 for (const PasswordForm* password_form : possible_submitted_forms) {
1220 if (password_form && !password_form->username_value.empty() && 1218 if (password_form && !password_form->username_value.empty() &&
1221 FormContainsNonDefaultPasswordValue(*password_form)) { 1219 FormContainsNonDefaultPasswordValue(*password_form)) {
1222 password_forms_found = true; 1220 password_forms_found = true;
1223 if (logger) { 1221 if (logger) {
1224 logger->LogPasswordForm(Logger::STRING_PASSWORD_FORM_FOUND_ON_PAGE, 1222 logger->LogPasswordForm(Logger::STRING_PASSWORD_FORM_FOUND_ON_PAGE,
1225 *password_form); 1223 *password_form);
1226 } 1224 }
1227 Send(new AutofillHostMsg_PasswordFormSubmitted(routing_id(), 1225 GetPasswordManagerDriver()->PasswordFormSubmitted(*password_form);
1228 *password_form));
1229 break; 1226 break;
1230 } 1227 }
1231 } 1228 }
1232 1229
1233 if (!password_forms_found && logger) 1230 if (!password_forms_found && logger)
1234 logger->LogMessage(Logger::STRING_PASSWORD_FORM_NOT_FOUND_ON_PAGE); 1231 logger->LogMessage(Logger::STRING_PASSWORD_FORM_NOT_FOUND_ON_PAGE);
1235 } 1232 }
1236 } 1233 }
1237 1234
1238 // This is a new navigation, so require a new user gesture before filling in 1235 // This is a new navigation, so require a new user gesture before filling in
1239 // passwords. 1236 // passwords.
1240 gatekeeper_.Reset(); 1237 gatekeeper_.Reset();
1241 } 1238 }
1242 1239
1243 void PasswordAutofillAgent::OnFillPasswordForm( 1240 // mojom::PasswordAutofillAgent:
1241 void PasswordAutofillAgent::FillPasswordForm(
1244 int key, 1242 int key,
1245 const PasswordFormFillData& form_data) { 1243 const PasswordFormFillData& form_data) {
1246 std::vector<blink::WebInputElement> elements; 1244 std::vector<blink::WebInputElement> elements;
1247 std::unique_ptr<RendererSavePasswordProgressLogger> logger; 1245 std::unique_ptr<RendererSavePasswordProgressLogger> logger;
1248 if (logging_state_active_) { 1246 if (logging_state_active_) {
1249 logger.reset(new RendererSavePasswordProgressLogger(this, routing_id())); 1247 logger.reset(new RendererSavePasswordProgressLogger(
1248 GetPasswordManagerDriver().get()));
1250 logger->LogMessage(Logger::STRING_ON_FILL_PASSWORD_FORM_METHOD); 1249 logger->LogMessage(Logger::STRING_ON_FILL_PASSWORD_FORM_METHOD);
1251 } 1250 }
1252 GetFillableElementFromFormData(key, form_data, logger.get(), &elements); 1251 GetFillableElementFromFormData(key, form_data, logger.get(), &elements);
1253 1252
1254 // If wait_for_username is true, we don't want to initially fill the form 1253 // If wait_for_username is true, we don't want to initially fill the form
1255 // until the user types in a valid username. 1254 // until the user types in a valid username.
1256 if (form_data.wait_for_username) 1255 if (form_data.wait_for_username)
1257 return; 1256 return;
1258 1257
1259 for (auto element : elements) { 1258 for (auto element : elements) {
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
1359 const blink::WebElement web_element = node.toConst<blink::WebElement>(); 1358 const blink::WebElement web_element = node.toConst<blink::WebElement>();
1360 if (!web_element.isFormControlElement()) 1359 if (!web_element.isFormControlElement())
1361 return; 1360 return;
1362 const blink::WebFormControlElement control_element = 1361 const blink::WebFormControlElement control_element =
1363 web_element.toConst<blink::WebFormControlElement>(); 1362 web_element.toConst<blink::WebFormControlElement>();
1364 UpdateFieldValueAndPropertiesMaskMap(control_element, nullptr, 1363 UpdateFieldValueAndPropertiesMaskMap(control_element, nullptr,
1365 FieldPropertiesFlags::HAD_FOCUS, 1364 FieldPropertiesFlags::HAD_FOCUS,
1366 &field_value_and_properties_map_); 1365 &field_value_and_properties_map_);
1367 } 1366 }
1368 1367
1369 void PasswordAutofillAgent::OnSetLoggingState(bool active) { 1368 // mojom::PasswordAutofillAgent:
1369 void PasswordAutofillAgent::SetLoggingState(bool active) {
1370 logging_state_active_ = active; 1370 logging_state_active_ = active;
1371 } 1371 }
1372 1372
1373 void PasswordAutofillAgent::OnAutofillUsernameAndPasswordDataReceived( 1373 void PasswordAutofillAgent::AutofillUsernameAndPasswordDataReceived(
1374 const FormsPredictionsMap& predictions) { 1374 const FormsPredictionsMap& predictions) {
1375 form_predictions_.insert(predictions.begin(), predictions.end()); 1375 form_predictions_.insert(predictions.begin(), predictions.end());
1376 } 1376 }
1377 1377
1378 void PasswordAutofillAgent::OnFindFocusedPasswordForm() { 1378 void PasswordAutofillAgent::FindFocusedPasswordForm(
1379 const FindFocusedPasswordFormCallback& callback) {
1379 std::unique_ptr<PasswordForm> password_form; 1380 std::unique_ptr<PasswordForm> password_form;
1380 1381
1381 blink::WebElement element = 1382 blink::WebElement element =
1382 render_frame()->GetWebFrame()->document().focusedElement(); 1383 render_frame()->GetWebFrame()->document().focusedElement();
1383 if (!element.isNull() && element.hasHTMLTagName("input")) { 1384 if (!element.isNull() && element.hasHTMLTagName("input")) {
1384 blink::WebInputElement input = element.to<blink::WebInputElement>(); 1385 blink::WebInputElement input = element.to<blink::WebInputElement>();
1385 if (input.isPasswordField() && !input.form().isNull()) { 1386 if (input.isPasswordField() && !input.form().isNull()) {
1386 if (!input.form().isNull()) { 1387 if (!input.form().isNull()) {
1387 password_form = CreatePasswordFormFromWebForm( 1388 password_form = CreatePasswordFormFromWebForm(
1388 input.form(), &field_value_and_properties_map_, &form_predictions_); 1389 input.form(), &field_value_and_properties_map_, &form_predictions_);
1389 } else { 1390 } else {
1390 password_form = CreatePasswordFormFromUnownedInputElements( 1391 password_form = CreatePasswordFormFromUnownedInputElements(
1391 *render_frame()->GetWebFrame(), &field_value_and_properties_map_, 1392 *render_frame()->GetWebFrame(), &field_value_and_properties_map_,
1392 &form_predictions_); 1393 &form_predictions_);
1393 // Only try to use this form if |input| is one of the password elements 1394 // Only try to use this form if |input| is one of the password elements
1394 // for |password_form|. 1395 // for |password_form|.
1395 if (password_form->password_element != input.nameForAutofill() && 1396 if (password_form->password_element != input.nameForAutofill() &&
1396 password_form->new_password_element != input.nameForAutofill()) 1397 password_form->new_password_element != input.nameForAutofill())
1397 password_form.reset(); 1398 password_form.reset();
1398 } 1399 }
1399 } 1400 }
1400 } 1401 }
1401 1402
1402 if (!password_form) 1403 if (!password_form)
1403 password_form.reset(new PasswordForm()); 1404 password_form.reset(new PasswordForm());
1404 1405
1405 Send(new AutofillHostMsg_FocusedPasswordFormFound( 1406 callback.Run(*password_form);
1406 routing_id(), *password_form));
1407 } 1407 }
1408 1408
1409 //////////////////////////////////////////////////////////////////////////////// 1409 ////////////////////////////////////////////////////////////////////////////////
1410 // PasswordAutofillAgent, private: 1410 // PasswordAutofillAgent, private:
1411 1411
1412 bool PasswordAutofillAgent::ShowSuggestionPopup( 1412 bool PasswordAutofillAgent::ShowSuggestionPopup(
1413 const PasswordInfo& password_info, 1413 const PasswordInfo& password_info,
1414 const blink::WebInputElement& user_input, 1414 const blink::WebInputElement& user_input,
1415 bool show_all, 1415 bool show_all,
1416 bool show_on_password_field) { 1416 bool show_on_password_field) {
(...skipping 20 matching lines...) Expand all
1437 if (show_all) 1437 if (show_all)
1438 options |= SHOW_ALL; 1438 options |= SHOW_ALL;
1439 if (show_on_password_field) 1439 if (show_on_password_field)
1440 options |= IS_PASSWORD_FIELD; 1440 options |= IS_PASSWORD_FIELD;
1441 1441
1442 base::string16 username_string( 1442 base::string16 username_string(
1443 user_input.isPasswordField() 1443 user_input.isPasswordField()
1444 ? base::string16() 1444 ? base::string16()
1445 : static_cast<base::string16>(user_input.value())); 1445 : static_cast<base::string16>(user_input.value()));
1446 1446
1447 Send(new AutofillHostMsg_ShowPasswordSuggestions( 1447 GetPasswordManagerDriver()->ShowPasswordSuggestions(
1448 routing_id(), password_info.key, field.text_direction, username_string, 1448 password_info.key, field.text_direction, username_string, options,
1449 options, 1449 render_frame()->GetRenderView()->ElementBoundsInWindow(user_input));
1450 render_frame()->GetRenderView()->ElementBoundsInWindow(user_input)));
1451 username_query_prefix_ = username_string; 1450 username_query_prefix_ = username_string;
1452 return CanShowSuggestion(password_info.fill_data, username_string, show_all); 1451 return CanShowSuggestion(password_info.fill_data, username_string, show_all);
1453 } 1452 }
1454 1453
1455 void PasswordAutofillAgent::FrameClosing() { 1454 void PasswordAutofillAgent::FrameClosing() {
1456 for (auto const& iter : web_input_to_password_info_) { 1455 for (auto const& iter : web_input_to_password_info_) {
1457 password_to_username_.erase(iter.second.password_field); 1456 password_to_username_.erase(iter.second.password_field);
1458 } 1457 }
1459 web_input_to_password_info_.clear(); 1458 web_input_to_password_info_.clear();
1460 provisionally_saved_form_.reset(); 1459 provisionally_saved_form_.reset();
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
1492 !provisionally_saved_form_->username_value.empty() && 1491 !provisionally_saved_form_->username_value.empty() &&
1493 !(provisionally_saved_form_->password_value.empty() && 1492 !(provisionally_saved_form_->password_value.empty() &&
1494 provisionally_saved_form_->new_password_value.empty()); 1493 provisionally_saved_form_->new_password_value.empty());
1495 } 1494 }
1496 1495
1497 const mojom::AutofillDriverPtr& PasswordAutofillAgent::GetAutofillDriver() { 1496 const mojom::AutofillDriverPtr& PasswordAutofillAgent::GetAutofillDriver() {
1498 DCHECK(autofill_agent_); 1497 DCHECK(autofill_agent_);
1499 return autofill_agent_->GetAutofillDriver(); 1498 return autofill_agent_->GetAutofillDriver();
1500 } 1499 }
1501 1500
1501 const mojom::PasswordManagerDriverPtr&
1502 PasswordAutofillAgent::GetPasswordManagerDriver() {
1503 if (!password_manager_driver_) {
1504 render_frame()->GetRemoteInterfaces()->GetInterface(
1505 mojo::GetProxy(&password_manager_driver_));
1506 }
1507
1508 return password_manager_driver_;
1509 }
1510
1502 } // namespace autofill 1511 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698