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

Unified Diff: components/autofill/content/renderer/password_form_conversion_utils.cc

Issue 1153023004: Prepare the infrastructure for password overrides. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed the test. Created 5 years, 7 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 side-by-side diff with in-line comments
Download patch
Index: components/autofill/content/renderer/password_form_conversion_utils.cc
diff --git a/components/autofill/content/renderer/password_form_conversion_utils.cc b/components/autofill/content/renderer/password_form_conversion_utils.cc
index 3726fa221f2fbee4a6999a70d4eb6e6b52b45909..e27e482ac4b46aad2da8990eb99fa7e163402eda 100644
--- a/components/autofill/content/renderer/password_form_conversion_utils.cc
+++ b/components/autofill/content/renderer/password_form_conversion_utils.cc
@@ -11,8 +11,8 @@
#include "base/metrics/histogram_macros.h"
#include "base/strings/string_util.h"
#include "components/autofill/content/renderer/form_autofill_util.h"
-#include "components/autofill/core/common/form_data_predictions.h"
#include "components/autofill/core/common/password_form.h"
+#include "components/autofill/core/common/password_form_field_prediction_map.h"
#include "third_party/WebKit/public/platform/WebString.h"
#include "third_party/WebKit/public/web/WebDocument.h"
#include "third_party/WebKit/public/web/WebFormControlElement.h"
@@ -181,12 +181,13 @@ bool LocateSpecificPasswords(std::vector<WebInputElement> passwords,
return true;
}
-void FindPredictedUsernameElement(
+void FindPredictedElements(
const WebFormElement& form,
- const std::map<autofill::FormData, autofill::FormFieldData>&
- form_predictions,
+ const std::map<autofill::FormData,
+ autofill::PasswordFormFieldPredictionMap>& form_predictions,
WebVector<WebFormControlElement>* control_elements,
- WebInputElement* predicted_username_element) {
+ std::map<autofill::PasswordFormFieldPredictionType, WebInputElement>*
+ predicted_elements) {
FormData form_data;
if (!WebFormElementToFormData(form, WebFormControlElement(), EXTRACT_NONE,
&form_data, nullptr)) {
@@ -211,15 +212,23 @@ void FindPredictedUsernameElement(
std::vector<blink::WebFormControlElement> autofillable_elements =
ExtractAutofillableElementsFromSet(*control_elements);
- const autofill::FormFieldData& username_field = predictions_iterator->second;
- for (size_t i = 0; i < autofillable_elements.size(); ++i) {
- if (autofillable_elements[i].nameForAutofill() == username_field.name) {
- WebInputElement* input_element =
- toWebInputElement(&autofillable_elements[i]);
- if (input_element) {
- *predicted_username_element = *input_element;
+ const autofill::PasswordFormFieldPredictionMap& field_predictions =
+ predictions_iterator->second;
+ for (autofill::PasswordFormFieldPredictionMap::const_iterator prediction =
+ field_predictions.begin();
+ prediction != field_predictions.end(); ++prediction) {
+ const autofill::PasswordFormFieldPredictionType& type = prediction->first;
+ const autofill::FormFieldData& target_field = prediction->second;
+
+ for (size_t i = 0; i < autofillable_elements.size(); ++i) {
+ if (autofillable_elements[i].nameForAutofill() == target_field.name) {
+ WebInputElement* input_element =
+ toWebInputElement(&autofillable_elements[i]);
+ if (input_element) {
+ (*predicted_elements)[type] = *input_element;
+ }
+ break;
}
- break;
}
}
}
@@ -233,7 +242,8 @@ void GetPasswordForm(
PasswordForm* password_form,
const std::map<const blink::WebInputElement, blink::WebString>*
nonscript_modified_values,
- const std::map<autofill::FormData, autofill::FormFieldData>*
+ const std::map<autofill::FormData,
+ autofill::PasswordFormFieldPredictionMap>*
form_predictions) {
WebInputElement latest_input_element;
WebInputElement username_element;
@@ -336,24 +346,25 @@ void GetPasswordForm(
}
password_form->layout = SequenceToLayout(layout_sequence);
- WebInputElement predicted_username_element;
+ std::map<autofill::PasswordFormFieldPredictionType, WebInputElement>
+ predicted_elements;
if (form_predictions) {
- FindPredictedUsernameElement(form, *form_predictions, &control_elements,
- &predicted_username_element);
+ FindPredictedElements(form, *form_predictions, &control_elements,
+ &predicted_elements);
}
// Let server predictions override the selection of the username field. This
// allows instant adjusting without changing Chromium code.
- if (!predicted_username_element.isNull() &&
- username_element != predicted_username_element) {
+ if (!predicted_elements[autofill::PREDICTION_USERNAME].isNull() &&
+ username_element != predicted_elements[autofill::PREDICTION_USERNAME]) {
auto it =
find(other_possible_usernames.begin(), other_possible_usernames.end(),
- predicted_username_element.value());
+ predicted_elements[autofill::PREDICTION_USERNAME].value());
if (it != other_possible_usernames.end())
other_possible_usernames.erase(it);
if (!username_element.isNull()) {
other_possible_usernames.push_back(username_element.value());
}
- username_element = predicted_username_element;
+ username_element = predicted_elements[autofill::PREDICTION_USERNAME];
password_form->was_parsed_using_autofill_predictions = true;
}
@@ -455,7 +466,8 @@ scoped_ptr<PasswordForm> CreatePasswordForm(
const WebFormElement& web_form,
const std::map<const blink::WebInputElement, blink::WebString>*
nonscript_modified_values,
- const std::map<autofill::FormData, autofill::FormFieldData>*
+ const std::map<autofill::FormData,
+ autofill::PasswordFormFieldPredictionMap>*
form_predictions) {
if (web_form.isNull())
return scoped_ptr<PasswordForm>();

Powered by Google App Engine
This is Rietveld 408576698