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

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

Issue 1859453002: components/autofill: scoped_ptr -> unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase on password_manager changes Created 4 years, 8 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
9 #include <memory>
Mathieu 2016/04/04 13:36:16 it's also been included in the .h for this file. I
vabr (Chromium) 2016/04/04 14:29:04 My reason to keep this here: There are 2 kinds of
8 #include <utility> 10 #include <utility>
9 11
10 #include "base/bind.h" 12 #include "base/bind.h"
11 #include "base/command_line.h" 13 #include "base/command_line.h"
12 #include "base/i18n/case_conversion.h" 14 #include "base/i18n/case_conversion.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "base/message_loop/message_loop.h" 15 #include "base/message_loop/message_loop.h"
15 #include "base/metrics/field_trial.h" 16 #include "base/metrics/field_trial.h"
16 #include "base/metrics/histogram_macros.h" 17 #include "base/metrics/histogram_macros.h"
17 #include "base/strings/utf_string_conversions.h" 18 #include "base/strings/utf_string_conversions.h"
18 #include "build/build_config.h" 19 #include "build/build_config.h"
19 #include "components/autofill/content/common/autofill_messages.h" 20 #include "components/autofill/content/common/autofill_messages.h"
20 #include "components/autofill/content/renderer/form_autofill_util.h" 21 #include "components/autofill/content/renderer/form_autofill_util.h"
21 #include "components/autofill/content/renderer/password_form_conversion_utils.h" 22 #include "components/autofill/content/renderer/password_form_conversion_utils.h"
22 #include "components/autofill/content/renderer/renderer_save_password_progress_l ogger.h" 23 #include "components/autofill/content/renderer/renderer_save_password_progress_l ogger.h"
23 #include "components/autofill/core/common/autofill_constants.h" 24 #include "components/autofill/core/common/autofill_constants.h"
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 ? IsPasswordField(field) ? base::ASCIIToUTF16(kDummyPasswordField) 121 ? IsPasswordField(field) ? base::ASCIIToUTF16(kDummyPasswordField)
121 : base::ASCIIToUTF16(kDummyUsernameField) 122 : base::ASCIIToUTF16(kDummyUsernameField)
122 : field.name; 123 : field.name;
123 } 124 }
124 125
125 bool IsUnownedPasswordFormVisible(blink::WebFrame* frame, 126 bool IsUnownedPasswordFormVisible(blink::WebFrame* frame,
126 const GURL& action, 127 const GURL& action,
127 const GURL& origin, 128 const GURL& origin,
128 const FormData& form_data, 129 const FormData& form_data,
129 const FormsPredictionsMap& form_predictions) { 130 const FormsPredictionsMap& form_predictions) {
130 scoped_ptr<PasswordForm> unowned_password_form( 131 std::unique_ptr<PasswordForm> unowned_password_form(
131 CreatePasswordFormFromUnownedInputElements(*frame, nullptr, 132 CreatePasswordFormFromUnownedInputElements(*frame, nullptr,
132 &form_predictions)); 133 &form_predictions));
133 if (!unowned_password_form) 134 if (!unowned_password_form)
134 return false; 135 return false;
135 std::vector<blink::WebFormControlElement> control_elements = 136 std::vector<blink::WebFormControlElement> control_elements =
136 form_util::GetUnownedAutofillableFormFieldElements( 137 form_util::GetUnownedAutofillableFormFieldElements(
137 frame->document().all(), nullptr); 138 frame->document().all(), nullptr);
138 if (!form_util::IsSomeControlElementVisible(control_elements)) 139 if (!form_util::IsSomeControlElementVisible(control_elements))
139 return false; 140 return false;
140 141
(...skipping 600 matching lines...) Expand 10 before | Expand all | Expand 10 after
741 if (!element_frame) 742 if (!element_frame)
742 return; 743 return;
743 DCHECK_EQ(element_frame, render_frame()->GetWebFrame()); 744 DCHECK_EQ(element_frame, render_frame()->GetWebFrame());
744 745
745 // Some login forms have event handlers that put a hash of the password into 746 // Some login forms have event handlers that put a hash of the password into
746 // a hidden field and then clear the password (http://crbug.com/28910, 747 // a hidden field and then clear the password (http://crbug.com/28910,
747 // http://crbug.com/391693). This method gets called before any of those 748 // http://crbug.com/391693). This method gets called before any of those
748 // handlers run, so save away a copy of the password in case it gets lost. 749 // handlers run, so save away a copy of the password in case it gets lost.
749 // To honor the user having explicitly cleared the password, even an empty 750 // To honor the user having explicitly cleared the password, even an empty
750 // password will be saved here. 751 // password will be saved here.
751 scoped_ptr<PasswordForm> password_form; 752 std::unique_ptr<PasswordForm> password_form;
752 if (element.form().isNull()) { 753 if (element.form().isNull()) {
753 password_form = CreatePasswordFormFromUnownedInputElements( 754 password_form = CreatePasswordFormFromUnownedInputElements(
754 *element_frame, &nonscript_modified_values_, &form_predictions_); 755 *element_frame, &nonscript_modified_values_, &form_predictions_);
755 } else { 756 } else {
756 password_form = CreatePasswordFormFromWebForm( 757 password_form = CreatePasswordFormFromWebForm(
757 element.form(), &nonscript_modified_values_, &form_predictions_); 758 element.form(), &nonscript_modified_values_, &form_predictions_);
758 } 759 }
759 ProvisionallySavePassword(std::move(password_form), RESTRICTION_NONE); 760 ProvisionallySavePassword(std::move(password_form), RESTRICTION_NONE);
760 761
761 if (element.isPasswordField()) { 762 if (element.isPasswordField()) {
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
961 Send(new AutofillHostMsg_InPageNavigation(routing_id(), 962 Send(new AutofillHostMsg_InPageNavigation(routing_id(),
962 *provisionally_saved_form_)); 963 *provisionally_saved_form_));
963 provisionally_saved_form_.reset(); 964 provisionally_saved_form_.reset();
964 } 965 }
965 966
966 void PasswordAutofillAgent::FirstUserGestureObserved() { 967 void PasswordAutofillAgent::FirstUserGestureObserved() {
967 gatekeeper_.OnUserGesture(); 968 gatekeeper_.OnUserGesture();
968 } 969 }
969 970
970 void PasswordAutofillAgent::SendPasswordForms(bool only_visible) { 971 void PasswordAutofillAgent::SendPasswordForms(bool only_visible) {
971 scoped_ptr<RendererSavePasswordProgressLogger> logger; 972 std::unique_ptr<RendererSavePasswordProgressLogger> logger;
972 if (logging_state_active_) { 973 if (logging_state_active_) {
973 logger.reset(new RendererSavePasswordProgressLogger(this, routing_id())); 974 logger.reset(new RendererSavePasswordProgressLogger(this, routing_id()));
974 logger->LogMessage(Logger::STRING_SEND_PASSWORD_FORMS_METHOD); 975 logger->LogMessage(Logger::STRING_SEND_PASSWORD_FORMS_METHOD);
975 logger->LogBoolean(Logger::STRING_ONLY_VISIBLE, only_visible); 976 logger->LogBoolean(Logger::STRING_ONLY_VISIBLE, only_visible);
976 } 977 }
977 978
978 blink::WebFrame* frame = render_frame()->GetWebFrame(); 979 blink::WebFrame* frame = render_frame()->GetWebFrame();
979 // Make sure that this security origin is allowed to use password manager. 980 // Make sure that this security origin is allowed to use password manager.
980 blink::WebSecurityOrigin origin = frame->document().getSecurityOrigin(); 981 blink::WebSecurityOrigin origin = frame->document().getSecurityOrigin();
981 if (logger) { 982 if (logger) {
(...skipping 28 matching lines...) Expand all
1010 LogHTMLForm(logger.get(), Logger::STRING_FORM_FOUND_ON_PAGE, form); 1011 LogHTMLForm(logger.get(), Logger::STRING_FORM_FOUND_ON_PAGE, form);
1011 logger->LogBoolean(Logger::STRING_FORM_IS_VISIBLE, is_form_visible); 1012 logger->LogBoolean(Logger::STRING_FORM_IS_VISIBLE, is_form_visible);
1012 } 1013 }
1013 1014
1014 // If requested, ignore non-rendered forms, e.g., those styled with 1015 // If requested, ignore non-rendered forms, e.g., those styled with
1015 // display:none. 1016 // display:none.
1016 if (!is_form_visible) 1017 if (!is_form_visible)
1017 continue; 1018 continue;
1018 } 1019 }
1019 1020
1020 scoped_ptr<PasswordForm> password_form( 1021 std::unique_ptr<PasswordForm> password_form(
1021 CreatePasswordFormFromWebForm(form, nullptr, &form_predictions_)); 1022 CreatePasswordFormFromWebForm(form, nullptr, &form_predictions_));
1022 if (password_form) { 1023 if (password_form) {
1023 if (logger) { 1024 if (logger) {
1024 logger->LogPasswordForm(Logger::STRING_FORM_IS_PASSWORD, 1025 logger->LogPasswordForm(Logger::STRING_FORM_IS_PASSWORD,
1025 *password_form); 1026 *password_form);
1026 } 1027 }
1027 password_forms.push_back(*password_form); 1028 password_forms.push_back(*password_form);
1028 } 1029 }
1029 } 1030 }
1030 1031
1031 // See if there are any unattached input elements that could be used for 1032 // See if there are any unattached input elements that could be used for
1032 // password submission. 1033 // password submission.
1033 bool add_unowned_inputs = true; 1034 bool add_unowned_inputs = true;
1034 if (only_visible) { 1035 if (only_visible) {
1035 std::vector<blink::WebFormControlElement> control_elements = 1036 std::vector<blink::WebFormControlElement> control_elements =
1036 form_util::GetUnownedAutofillableFormFieldElements( 1037 form_util::GetUnownedAutofillableFormFieldElements(
1037 frame->document().all(), nullptr); 1038 frame->document().all(), nullptr);
1038 add_unowned_inputs = 1039 add_unowned_inputs =
1039 form_util::IsSomeControlElementVisible(control_elements); 1040 form_util::IsSomeControlElementVisible(control_elements);
1040 if (logger) { 1041 if (logger) {
1041 logger->LogBoolean(Logger::STRING_UNOWNED_INPUTS_VISIBLE, 1042 logger->LogBoolean(Logger::STRING_UNOWNED_INPUTS_VISIBLE,
1042 add_unowned_inputs); 1043 add_unowned_inputs);
1043 } 1044 }
1044 } 1045 }
1045 if (add_unowned_inputs) { 1046 if (add_unowned_inputs) {
1046 scoped_ptr<PasswordForm> password_form( 1047 std::unique_ptr<PasswordForm> password_form(
1047 CreatePasswordFormFromUnownedInputElements(*frame, nullptr, 1048 CreatePasswordFormFromUnownedInputElements(*frame, nullptr,
1048 &form_predictions_)); 1049 &form_predictions_));
1049 if (password_form) { 1050 if (password_form) {
1050 if (logger) { 1051 if (logger) {
1051 logger->LogPasswordForm(Logger::STRING_FORM_IS_PASSWORD, 1052 logger->LogPasswordForm(Logger::STRING_FORM_IS_PASSWORD,
1052 *password_form); 1053 *password_form);
1053 } 1054 }
1054 password_forms.push_back(*password_form); 1055 password_forms.push_back(*password_form);
1055 } 1056 }
1056 } 1057 }
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
1132 // and uses the candidate stored in |provisionally_saved_form_|. 1133 // and uses the candidate stored in |provisionally_saved_form_|.
1133 // 1134 //
1134 // User-typed password will get stored to |provisionally_saved_form_| in 1135 // User-typed password will get stored to |provisionally_saved_form_| in
1135 // TextDidChangeInTextField. Autofilled or JavaScript-copied passwords need to 1136 // TextDidChangeInTextField. Autofilled or JavaScript-copied passwords need to
1136 // be saved here. 1137 // be saved here.
1137 // 1138 //
1138 // Only non-empty passwords are saved here. Empty passwords were likely 1139 // Only non-empty passwords are saved here. Empty passwords were likely
1139 // cleared by some scripts (http://crbug.com/28910, http://crbug.com/391693). 1140 // cleared by some scripts (http://crbug.com/28910, http://crbug.com/391693).
1140 // Had the user cleared the password, |provisionally_saved_form_| would 1141 // Had the user cleared the password, |provisionally_saved_form_| would
1141 // already have been updated in TextDidChangeInTextField. 1142 // already have been updated in TextDidChangeInTextField.
1142 scoped_ptr<PasswordForm> password_form = CreatePasswordFormFromWebForm( 1143 std::unique_ptr<PasswordForm> password_form = CreatePasswordFormFromWebForm(
1143 form, &nonscript_modified_values_, &form_predictions_); 1144 form, &nonscript_modified_values_, &form_predictions_);
1144 ProvisionallySavePassword(std::move(password_form), 1145 ProvisionallySavePassword(std::move(password_form),
1145 RESTRICTION_NON_EMPTY_PASSWORD); 1146 RESTRICTION_NON_EMPTY_PASSWORD);
1146 } 1147 }
1147 1148
1148 void PasswordAutofillAgent::WillSubmitForm(const blink::WebFormElement& form) { 1149 void PasswordAutofillAgent::WillSubmitForm(const blink::WebFormElement& form) {
1149 scoped_ptr<RendererSavePasswordProgressLogger> logger; 1150 std::unique_ptr<RendererSavePasswordProgressLogger> logger;
1150 if (logging_state_active_) { 1151 if (logging_state_active_) {
1151 logger.reset(new RendererSavePasswordProgressLogger(this, routing_id())); 1152 logger.reset(new RendererSavePasswordProgressLogger(this, routing_id()));
1152 logger->LogMessage(Logger::STRING_WILL_SUBMIT_FORM_METHOD); 1153 logger->LogMessage(Logger::STRING_WILL_SUBMIT_FORM_METHOD);
1153 LogHTMLForm(logger.get(), Logger::STRING_HTML_FORM_FOR_SUBMIT, form); 1154 LogHTMLForm(logger.get(), Logger::STRING_HTML_FORM_FOR_SUBMIT, form);
1154 } 1155 }
1155 1156
1156 scoped_ptr<PasswordForm> submitted_form = 1157 std::unique_ptr<PasswordForm> submitted_form = CreatePasswordFormFromWebForm(
1157 CreatePasswordFormFromWebForm(form, &nonscript_modified_values_, 1158 form, &nonscript_modified_values_, &form_predictions_);
1158 &form_predictions_);
1159 1159
1160 // If there is a provisionally saved password, copy over the previous 1160 // If there is a provisionally saved password, copy over the previous
1161 // password value so we get the user's typed password, not the value that 1161 // password value so we get the user's typed password, not the value that
1162 // may have been transformed for submit. 1162 // may have been transformed for submit.
1163 // TODO(gcasto): Do we need to have this action equality check? Is it trying 1163 // TODO(gcasto): Do we need to have this action equality check? Is it trying
1164 // to prevent accidentally copying over passwords from a different form? 1164 // to prevent accidentally copying over passwords from a different form?
1165 if (submitted_form) { 1165 if (submitted_form) {
1166 if (logger) { 1166 if (logger) {
1167 logger->LogPasswordForm(Logger::STRING_CREATED_PASSWORD_FORM, 1167 logger->LogPasswordForm(Logger::STRING_CREATED_PASSWORD_FORM,
1168 *submitted_form); 1168 *submitted_form);
(...skipping 16 matching lines...) Expand all
1185 // we will never get to finish the load. 1185 // we will never get to finish the load.
1186 Send(new AutofillHostMsg_PasswordFormSubmitted(routing_id(), 1186 Send(new AutofillHostMsg_PasswordFormSubmitted(routing_id(),
1187 *submitted_form)); 1187 *submitted_form));
1188 provisionally_saved_form_.reset(); 1188 provisionally_saved_form_.reset();
1189 } else if (logger) { 1189 } else if (logger) {
1190 logger->LogMessage(Logger::STRING_FORM_IS_NOT_PASSWORD); 1190 logger->LogMessage(Logger::STRING_FORM_IS_NOT_PASSWORD);
1191 } 1191 }
1192 } 1192 }
1193 1193
1194 void PasswordAutofillAgent::DidStartProvisionalLoad() { 1194 void PasswordAutofillAgent::DidStartProvisionalLoad() {
1195 scoped_ptr<RendererSavePasswordProgressLogger> logger; 1195 std::unique_ptr<RendererSavePasswordProgressLogger> logger;
1196 if (logging_state_active_) { 1196 if (logging_state_active_) {
1197 logger.reset(new RendererSavePasswordProgressLogger(this, routing_id())); 1197 logger.reset(new RendererSavePasswordProgressLogger(this, routing_id()));
1198 logger->LogMessage(Logger::STRING_DID_START_PROVISIONAL_LOAD_METHOD); 1198 logger->LogMessage(Logger::STRING_DID_START_PROVISIONAL_LOAD_METHOD);
1199 } 1199 }
1200 1200
1201 const blink::WebLocalFrame* navigated_frame = render_frame()->GetWebFrame(); 1201 const blink::WebLocalFrame* navigated_frame = render_frame()->GetWebFrame();
1202 if (navigated_frame->parent()) { 1202 if (navigated_frame->parent()) {
1203 if (logger) 1203 if (logger)
1204 logger->LogMessage(Logger::STRING_FRAME_NOT_MAIN_FRAME); 1204 logger->LogMessage(Logger::STRING_FRAME_NOT_MAIN_FRAME);
1205 return; 1205 return;
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
1349 void PasswordAutofillAgent::OnSetLoggingState(bool active) { 1349 void PasswordAutofillAgent::OnSetLoggingState(bool active) {
1350 logging_state_active_ = active; 1350 logging_state_active_ = active;
1351 } 1351 }
1352 1352
1353 void PasswordAutofillAgent::OnAutofillUsernameAndPasswordDataReceived( 1353 void PasswordAutofillAgent::OnAutofillUsernameAndPasswordDataReceived(
1354 const FormsPredictionsMap& predictions) { 1354 const FormsPredictionsMap& predictions) {
1355 form_predictions_.insert(predictions.begin(), predictions.end()); 1355 form_predictions_.insert(predictions.begin(), predictions.end());
1356 } 1356 }
1357 1357
1358 void PasswordAutofillAgent::OnFindFocusedPasswordForm() { 1358 void PasswordAutofillAgent::OnFindFocusedPasswordForm() {
1359 scoped_ptr<PasswordForm> password_form; 1359 std::unique_ptr<PasswordForm> password_form;
1360 1360
1361 blink::WebElement element = render_frame()->GetFocusedElement(); 1361 blink::WebElement element = render_frame()->GetFocusedElement();
1362 if (!element.isNull() && element.hasHTMLTagName("input")) { 1362 if (!element.isNull() && element.hasHTMLTagName("input")) {
1363 blink::WebInputElement input = element.to<blink::WebInputElement>(); 1363 blink::WebInputElement input = element.to<blink::WebInputElement>();
1364 if (input.isPasswordField() && !input.form().isNull()) { 1364 if (input.isPasswordField() && !input.form().isNull()) {
1365 if (!input.form().isNull()) { 1365 if (!input.form().isNull()) {
1366 password_form = CreatePasswordFormFromWebForm( 1366 password_form = CreatePasswordFormFromWebForm(
1367 input.form(), &nonscript_modified_values_, &form_predictions_); 1367 input.form(), &nonscript_modified_values_, &form_predictions_);
1368 } else { 1368 } else {
1369 password_form = CreatePasswordFormFromUnownedInputElements( 1369 password_form = CreatePasswordFormFromUnownedInputElements(
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
1489 username->setSelectionRange(username_query_prefix_.length(), 1489 username->setSelectionRange(username_query_prefix_.length(),
1490 username->value().length()); 1490 username->value().length());
1491 } 1491 }
1492 if (!password->suggestedValue().isEmpty()) { 1492 if (!password->suggestedValue().isEmpty()) {
1493 password->setSuggestedValue(blink::WebString()); 1493 password->setSuggestedValue(blink::WebString());
1494 password->setAutofilled(was_password_autofilled_); 1494 password->setAutofilled(was_password_autofilled_);
1495 } 1495 }
1496 } 1496 }
1497 1497
1498 void PasswordAutofillAgent::ProvisionallySavePassword( 1498 void PasswordAutofillAgent::ProvisionallySavePassword(
1499 scoped_ptr<PasswordForm> password_form, 1499 std::unique_ptr<PasswordForm> password_form,
1500 ProvisionallySaveRestriction restriction) { 1500 ProvisionallySaveRestriction restriction) {
1501 if (!password_form || (restriction == RESTRICTION_NON_EMPTY_PASSWORD && 1501 if (!password_form || (restriction == RESTRICTION_NON_EMPTY_PASSWORD &&
1502 password_form->password_value.empty() && 1502 password_form->password_value.empty() &&
1503 password_form->new_password_value.empty())) { 1503 password_form->new_password_value.empty())) {
1504 return; 1504 return;
1505 } 1505 }
1506 provisionally_saved_form_ = std::move(password_form); 1506 provisionally_saved_form_ = std::move(password_form);
1507 } 1507 }
1508 1508
1509 bool PasswordAutofillAgent::ProvisionallySavedPasswordIsValid() { 1509 bool PasswordAutofillAgent::ProvisionallySavedPasswordIsValid() {
1510 return provisionally_saved_form_ && 1510 return provisionally_saved_form_ &&
1511 !provisionally_saved_form_->username_value.empty() && 1511 !provisionally_saved_form_->username_value.empty() &&
1512 !(provisionally_saved_form_->password_value.empty() && 1512 !(provisionally_saved_form_->password_value.empty() &&
1513 provisionally_saved_form_->new_password_value.empty()); 1513 provisionally_saved_form_->new_password_value.empty());
1514 } 1514 }
1515 1515
1516 } // namespace autofill 1516 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698