Commit 8d5d43ba authored by Vadym Doroshenko's avatar Vadym Doroshenko Committed by Commit Bot

Using blink::* in password manager renderer code.

Bug: None
Change-Id: I0680e554a50a299ae2f35cb95e44cdb0e3b4e38c
Reviewed-on: https://chromium-review.googlesource.com/1148450Reviewed-by: default avatarVasilii Sukhanov <vasilii@chromium.org>
Commit-Queue: Vadym Doroshenko <dvadym@chromium.org>
Cr-Commit-Position: refs/heads/master@{#577833}
parent 9acaaa43
...@@ -56,10 +56,19 @@ ...@@ -56,10 +56,19 @@
#include "ui/events/keycodes/keyboard_codes.h" #include "ui/events/keycodes/keyboard_codes.h"
#include "url/gurl.h" #include "url/gurl.h"
using blink::ToWebInputElement;
using blink::WebAutofillState; using blink::WebAutofillState;
using blink::WebDocument; using blink::WebDocument;
using blink::WebInputElement; using blink::WebElement;
using blink::WebElementCollection;
using blink::WebFormElement;
using blink::WebFormControlElement; using blink::WebFormControlElement;
using blink::WebFrame;
using blink::WebInputElement;
using blink::WebLocalFrame;
using blink::WebString;
using blink::WebVector;
using blink::WebView;
namespace autofill { namespace autofill {
namespace { namespace {
...@@ -71,7 +80,7 @@ const char kDummyUsernameField[] = "anonymous_username"; ...@@ -71,7 +80,7 @@ const char kDummyUsernameField[] = "anonymous_username";
const char kDummyPasswordField[] = "anonymous_password"; const char kDummyPasswordField[] = "anonymous_password";
// Maps element names to the actual elements to simplify form filling. // Maps element names to the actual elements to simplify form filling.
typedef std::map<base::string16, blink::WebInputElement> FormInputElementMap; typedef std::map<base::string16, WebInputElement> FormInputElementMap;
// Use the shorter name when referencing SavePasswordProgressLogger::StringID // Use the shorter name when referencing SavePasswordProgressLogger::StringID
// values to spare line breaks. The code provides enough context for that // values to spare line breaks. The code provides enough context for that
...@@ -166,13 +175,13 @@ bool IsFieldPasswordField(const FormFieldData& field) { ...@@ -166,13 +175,13 @@ bool IsFieldPasswordField(const FormFieldData& field) {
// either |autocomplete='current-password'| or |autocomplete='new-password'| // either |autocomplete='current-password'| or |autocomplete='new-password'|
// attribute. // attribute.
bool HasPasswordWithAutocompleteAttribute( bool HasPasswordWithAutocompleteAttribute(
const std::vector<blink::WebFormControlElement>& control_elements) { const std::vector<WebFormControlElement>& control_elements) {
for (const blink::WebFormControlElement& control_element : control_elements) { for (const WebFormControlElement& control_element : control_elements) {
if (!control_element.HasHTMLTagName("input")) if (!control_element.HasHTMLTagName("input"))
continue; continue;
const blink::WebInputElement input_element = const WebInputElement input_element =
control_element.ToConst<blink::WebInputElement>(); control_element.ToConst<WebInputElement>();
const AutocompleteFlag flag = AutocompleteFlagForElement(input_element); const AutocompleteFlag flag = AutocompleteFlagForElement(input_element);
if (input_element.IsPasswordFieldForAutofill() && if (input_element.IsPasswordFieldForAutofill() &&
(flag == AutocompleteFlag::CURRENT_PASSWORD || (flag == AutocompleteFlag::CURRENT_PASSWORD ||
...@@ -195,7 +204,7 @@ base::string16 FieldName(const FormFieldData& field, ...@@ -195,7 +204,7 @@ base::string16 FieldName(const FormFieldData& field,
: field.name; : field.name;
} }
bool IsUnownedPasswordFormVisible(const blink::WebInputElement& input_element) { bool IsUnownedPasswordFormVisible(const WebInputElement& input_element) {
return !input_element.IsNull() && return !input_element.IsNull() &&
form_util::IsWebElementVisible(input_element); form_util::IsWebElementVisible(input_element);
} }
...@@ -205,7 +214,7 @@ bool IsUnownedPasswordFormVisible(const blink::WebInputElement& input_element) { ...@@ -205,7 +214,7 @@ bool IsUnownedPasswordFormVisible(const blink::WebInputElement& input_element) {
// |true|. Otherwise clears the references from each |HTMLInputElement| from // |true|. Otherwise clears the references from each |HTMLInputElement| from
// |result| and returns |false|. // |result| and returns |false|.
bool FindFormInputElement( bool FindFormInputElement(
const std::vector<blink::WebFormControlElement>& control_elements, const std::vector<WebFormControlElement>& control_elements,
const FormFieldData& field, const FormFieldData& field,
bool ambiguous_or_empty_names, bool ambiguous_or_empty_names,
FormInputElementMap* result) { FormInputElementMap* result) {
...@@ -218,7 +227,7 @@ bool FindFormInputElement( ...@@ -218,7 +227,7 @@ bool FindFormInputElement(
does_password_field_has_ambigous_or_empty_name && does_password_field_has_ambigous_or_empty_name &&
HasPasswordWithAutocompleteAttribute(control_elements); HasPasswordWithAutocompleteAttribute(control_elements);
base::string16 field_name = FieldName(field, ambiguous_or_empty_names); base::string16 field_name = FieldName(field, ambiguous_or_empty_names);
for (const blink::WebFormControlElement& control_element : control_elements) { for (const WebFormControlElement& control_element : control_elements) {
if (!ambiguous_or_empty_names && if (!ambiguous_or_empty_names &&
control_element.NameForAutofill().Utf16() != field_name) { control_element.NameForAutofill().Utf16() != field_name) {
continue; continue;
...@@ -229,8 +238,8 @@ bool FindFormInputElement( ...@@ -229,8 +238,8 @@ bool FindFormInputElement(
// Only fill saved passwords into password fields and usernames into text // Only fill saved passwords into password fields and usernames into text
// fields. // fields.
const blink::WebInputElement input_element = const WebInputElement input_element =
control_element.ToConst<blink::WebInputElement>(); control_element.ToConst<WebInputElement>();
if (!input_element.IsTextField() || if (!input_element.IsTextField() ||
input_element.IsPasswordFieldForAutofill() != is_password_field) input_element.IsPasswordFieldForAutofill() != is_password_field)
continue; continue;
...@@ -280,7 +289,7 @@ bool FindFormInputElement( ...@@ -280,7 +289,7 @@ bool FindFormInputElement(
// Helper to search through |control_elements| for the specified input elements // Helper to search through |control_elements| for the specified input elements
// in |data|, and add results to |result|. // in |data|, and add results to |result|.
bool FindFormInputElements( bool FindFormInputElements(
const std::vector<blink::WebFormControlElement>& control_elements, const std::vector<WebFormControlElement>& control_elements,
const PasswordFormFillData& data, const PasswordFormFillData& data,
bool ambiguous_or_empty_names, bool ambiguous_or_empty_names,
FormInputElementMap* result) { FormInputElementMap* result) {
...@@ -298,23 +307,23 @@ void FindFormElements(content::RenderFrame* render_frame, ...@@ -298,23 +307,23 @@ void FindFormElements(content::RenderFrame* render_frame,
FormElementsList* results) { FormElementsList* results) {
DCHECK(results); DCHECK(results);
blink::WebDocument doc = render_frame->GetWebFrame()->GetDocument(); WebDocument doc = render_frame->GetWebFrame()->GetDocument();
if (GetSignOnRealm(data.origin) != if (GetSignOnRealm(data.origin) !=
GetSignOnRealm(form_util::GetCanonicalOriginForDocument(doc))) GetSignOnRealm(form_util::GetCanonicalOriginForDocument(doc)))
return; return;
blink::WebVector<blink::WebFormElement> forms; WebVector<WebFormElement> forms;
doc.Forms(forms); doc.Forms(forms);
for (size_t i = 0; i < forms.size(); ++i) { for (size_t i = 0; i < forms.size(); ++i) {
blink::WebFormElement fe = forms[i]; WebFormElement fe = forms[i];
// Action URL must match. // Action URL must match.
if (data.action != form_util::GetCanonicalActionForForm(fe)) if (data.action != form_util::GetCanonicalActionForForm(fe))
continue; continue;
std::vector<blink::WebFormControlElement> control_elements = std::vector<WebFormControlElement> control_elements =
form_util::ExtractAutofillableElementsInForm(fe); form_util::ExtractAutofillableElementsInForm(fe);
FormInputElementMap cur_map; FormInputElementMap cur_map;
if (FindFormInputElements(control_elements, data, ambiguous_or_empty_names, if (FindFormInputElements(control_elements, data, ambiguous_or_empty_names,
...@@ -326,7 +335,7 @@ void FindFormElements(content::RenderFrame* render_frame, ...@@ -326,7 +335,7 @@ void FindFormElements(content::RenderFrame* render_frame,
if (data.action != data.origin) if (data.action != data.origin)
return; return;
std::vector<blink::WebFormControlElement> control_elements = std::vector<WebFormControlElement> control_elements =
form_util::GetUnownedAutofillableFormFieldElements(doc.All(), nullptr); form_util::GetUnownedAutofillableFormFieldElements(doc.All(), nullptr);
FormInputElementMap unowned_elements_map; FormInputElementMap unowned_elements_map;
if (FindFormInputElements(control_elements, data, ambiguous_or_empty_names, if (FindFormInputElements(control_elements, data, ambiguous_or_empty_names,
...@@ -334,7 +343,7 @@ void FindFormElements(content::RenderFrame* render_frame, ...@@ -334,7 +343,7 @@ void FindFormElements(content::RenderFrame* render_frame,
results->push_back(unowned_elements_map); results->push_back(unowned_elements_map);
} }
bool IsElementEditable(const blink::WebInputElement& element) { bool IsElementEditable(const WebInputElement& element) {
return element.IsEnabled() && !element.IsReadOnly(); return element.IsEnabled() && !element.IsReadOnly();
} }
...@@ -348,7 +357,7 @@ bool DoUsernamesMatch(const base::string16& potential_suggestion, ...@@ -348,7 +357,7 @@ bool DoUsernamesMatch(const base::string16& potential_suggestion,
} }
// Returns whether the given |element| is editable. // Returns whether the given |element| is editable.
bool IsElementAutocompletable(const blink::WebInputElement& element) { bool IsElementAutocompletable(const WebInputElement& element) {
return IsElementEditable(element); return IsElementEditable(element);
} }
...@@ -358,7 +367,7 @@ bool IsElementAutocompletable(const blink::WebInputElement& element) { ...@@ -358,7 +367,7 @@ bool IsElementAutocompletable(const blink::WebInputElement& element) {
// |username_element| is user-defined (i.e., non-empty and non-autofilled), then // |username_element| is user-defined (i.e., non-empty and non-autofilled), then
// this function returns false. This is a precaution, to not override the field // this function returns false. This is a precaution, to not override the field
// if it has been classified as username by accident. // if it has been classified as username by accident.
bool IsUsernameAmendable(const blink::WebInputElement& username_element, bool IsUsernameAmendable(const WebInputElement& username_element,
bool is_password_field_selected) { bool is_password_field_selected) {
return !username_element.IsNull() && return !username_element.IsNull() &&
IsElementAutocompletable(username_element) && IsElementAutocompletable(username_element) &&
...@@ -369,7 +378,7 @@ bool IsUsernameAmendable(const blink::WebInputElement& username_element, ...@@ -369,7 +378,7 @@ bool IsUsernameAmendable(const blink::WebInputElement& username_element,
// Log a message including the name, method and action of |form|. // Log a message including the name, method and action of |form|.
void LogHTMLForm(SavePasswordProgressLogger* logger, void LogHTMLForm(SavePasswordProgressLogger* logger,
SavePasswordProgressLogger::StringID message_id, SavePasswordProgressLogger::StringID message_id,
const blink::WebFormElement& form) { const WebFormElement& form) {
logger->LogHTMLForm(message_id, form.GetName().Utf8(), logger->LogHTMLForm(message_id, form.GetName().Utf8(),
GURL(form.Action().Utf8())); GURL(form.Action().Utf8()));
} }
...@@ -407,7 +416,7 @@ bool CanShowSuggestion(const PasswordFormFillData& fill_data, ...@@ -407,7 +416,7 @@ bool CanShowSuggestion(const PasswordFormFillData& fill_data,
// If |value| is null, the value is neither updated nor added. // If |value| is null, the value is neither updated nor added.
// If |*value| is empty, USER_TYPED and AUTOFILLED should be cleared. // If |*value| is empty, USER_TYPED and AUTOFILLED should be cleared.
void UpdateFieldValueAndPropertiesMaskMap( void UpdateFieldValueAndPropertiesMaskMap(
const blink::WebFormControlElement& element, const WebFormControlElement& element,
const base::string16* value, const base::string16* value,
FieldPropertiesMask added_flags, FieldPropertiesMask added_flags,
FieldValueAndPropertiesMaskMap* field_value_and_properties_map) { FieldValueAndPropertiesMaskMap* field_value_and_properties_map) {
...@@ -509,73 +518,68 @@ bool IsPublicSuffixDomainMatch(const std::string& url1, ...@@ -509,73 +518,68 @@ bool IsPublicSuffixDomainMatch(const std::string& url1,
} }
// Helper function that calculates form signature for |password_form| and // Helper function that calculates form signature for |password_form| and
// returns it as blink::WebString. // returns it as WebString.
blink::WebString GetFormSignatureAsWebString( WebString GetFormSignatureAsWebString(const PasswordForm& password_form) {
const PasswordForm& password_form) { return WebString::FromUTF8(
return blink::WebString::FromUTF8(
base::NumberToString(CalculateFormSignature(password_form.form_data))); base::NumberToString(CalculateFormSignature(password_form.form_data)));
} }
// Annotate |fields| with field signatures and form signature as HTML // Annotate |fields| with field signatures and form signature as HTML
// attributes. // attributes.
void AnnotateFieldsWithSignatures( void AnnotateFieldsWithSignatures(std::vector<WebFormControlElement>* fields,
std::vector<blink::WebFormControlElement>* fields, const WebString& form_signature) {
const blink::WebString& form_signature) { for (WebFormControlElement& control_element : *fields) {
for (blink::WebFormControlElement& control_element : *fields) {
FieldSignature field_signature = CalculateFieldSignatureByNameAndType( FieldSignature field_signature = CalculateFieldSignatureByNameAndType(
control_element.NameForAutofill().Utf16(), control_element.NameForAutofill().Utf16(),
control_element.FormControlTypeForAutofill().Utf8()); control_element.FormControlTypeForAutofill().Utf8());
control_element.SetAttribute( control_element.SetAttribute(
blink::WebString::FromASCII(kDebugAttributeForFieldSignature), WebString::FromASCII(kDebugAttributeForFieldSignature),
blink::WebString::FromUTF8(base::NumberToString(field_signature))); WebString::FromUTF8(base::NumberToString(field_signature)));
control_element.SetAttribute( control_element.SetAttribute(
blink::WebString::FromASCII(kDebugAttributeForFormSignature), WebString::FromASCII(kDebugAttributeForFormSignature), form_signature);
form_signature);
} }
} }
// Annotate |forms| and all fields in the |frame| with form and field signatures // Annotate |forms| and all fields in the |frame| with form and field signatures
// as HTML attributes. // as HTML attributes.
void AnnotateFormsAndFieldsWithSignatures( void AnnotateFormsAndFieldsWithSignatures(WebLocalFrame* frame,
blink::WebLocalFrame* frame, WebVector<WebFormElement>* forms) {
blink::WebVector<blink::WebFormElement>* forms) { for (WebFormElement& form : *forms) {
for (blink::WebFormElement& form : *forms) {
std::unique_ptr<PasswordForm> password_form( std::unique_ptr<PasswordForm> password_form(
CreatePasswordFormFromWebForm(form, nullptr, nullptr, nullptr)); CreatePasswordFormFromWebForm(form, nullptr, nullptr, nullptr));
blink::WebString form_signature; WebString form_signature;
if (password_form) { if (password_form) {
form_signature = GetFormSignatureAsWebString(*password_form); form_signature = GetFormSignatureAsWebString(*password_form);
form.SetAttribute( form.SetAttribute(WebString::FromASCII(kDebugAttributeForFormSignature),
blink::WebString::FromASCII(kDebugAttributeForFormSignature), form_signature);
form_signature);
} }
std::vector<blink::WebFormControlElement> form_fields = std::vector<WebFormControlElement> form_fields =
form_util::ExtractAutofillableElementsInForm(form); form_util::ExtractAutofillableElementsInForm(form);
AnnotateFieldsWithSignatures(&form_fields, form_signature); AnnotateFieldsWithSignatures(&form_fields, form_signature);
} }
std::vector<blink::WebFormControlElement> unowned_elements = std::vector<WebFormControlElement> unowned_elements =
form_util::GetUnownedAutofillableFormFieldElements( form_util::GetUnownedAutofillableFormFieldElements(
frame->GetDocument().All(), nullptr); frame->GetDocument().All(), nullptr);
std::unique_ptr<PasswordForm> password_form( std::unique_ptr<PasswordForm> password_form(
CreatePasswordFormFromUnownedInputElements(*frame, nullptr, nullptr, CreatePasswordFormFromUnownedInputElements(*frame, nullptr, nullptr,
nullptr)); nullptr));
blink::WebString form_signature; WebString form_signature;
if (password_form) if (password_form)
form_signature = GetFormSignatureAsWebString(*password_form); form_signature = GetFormSignatureAsWebString(*password_form);
AnnotateFieldsWithSignatures(&unowned_elements, form_signature); AnnotateFieldsWithSignatures(&unowned_elements, form_signature);
} }
// Returns true iff there is a password field in |frame|. // Returns true iff there is a password field in |frame|.
bool HasPasswordField(const blink::WebLocalFrame& frame) { bool HasPasswordField(const WebLocalFrame& frame) {
CR_DEFINE_STATIC_LOCAL(blink::WebString, kPassword, ("password")); CR_DEFINE_STATIC_LOCAL(WebString, kPassword, ("password"));
const blink::WebElementCollection elements = frame.GetDocument().All(); const WebElementCollection elements = frame.GetDocument().All();
for (blink::WebElement element = elements.FirstItem(); !element.IsNull(); for (WebElement element = elements.FirstItem(); !element.IsNull();
element = elements.NextItem()) { element = elements.NextItem()) {
if (element.IsFormControlElement()) { if (element.IsFormControlElement()) {
const blink::WebFormControlElement& control = const WebFormControlElement& control =
element.To<blink::WebFormControlElement>(); element.To<WebFormControlElement>();
if (control.FormControlTypeForAutofill() == kPassword) if (control.FormControlTypeForAutofill() == kPassword)
return true; return true;
} }
...@@ -586,28 +590,28 @@ bool HasPasswordField(const blink::WebLocalFrame& frame) { ...@@ -586,28 +590,28 @@ bool HasPasswordField(const blink::WebLocalFrame& frame) {
// Returns the closest visible autocompletable non-password text element // Returns the closest visible autocompletable non-password text element
// preceding the |password_element| either in a form, if it belongs to one, or // preceding the |password_element| either in a form, if it belongs to one, or
// in the |frame|. // in the |frame|.
blink::WebInputElement FindUsernameElementPrecedingPasswordElement( WebInputElement FindUsernameElementPrecedingPasswordElement(
blink::WebLocalFrame* frame, WebLocalFrame* frame,
const blink::WebInputElement& password_element) { const WebInputElement& password_element) {
DCHECK(!password_element.IsNull()); DCHECK(!password_element.IsNull());
std::vector<blink::WebFormControlElement> elements; std::vector<WebFormControlElement> elements;
if (password_element.Form().IsNull()) { if (password_element.Form().IsNull()) {
elements = form_util::GetUnownedAutofillableFormFieldElements( elements = form_util::GetUnownedAutofillableFormFieldElements(
frame->GetDocument().All(), nullptr); frame->GetDocument().All(), nullptr);
} else { } else {
blink::WebVector<blink::WebFormControlElement> web_control_elements; WebVector<WebFormControlElement> web_control_elements;
password_element.Form().GetFormControlElements(web_control_elements); password_element.Form().GetFormControlElements(web_control_elements);
elements.assign(web_control_elements.begin(), web_control_elements.end()); elements.assign(web_control_elements.begin(), web_control_elements.end());
} }
auto iter = std::find(elements.begin(), elements.end(), password_element); auto iter = std::find(elements.begin(), elements.end(), password_element);
if (iter == elements.end()) if (iter == elements.end())
return blink::WebInputElement(); return WebInputElement();
for (auto begin = elements.begin(); iter != begin;) { for (auto begin = elements.begin(); iter != begin;) {
--iter; --iter;
const blink::WebInputElement* input = blink::ToWebInputElement(&*iter); const WebInputElement* input = ToWebInputElement(&*iter);
if (input && input->IsTextField() && !input->IsPasswordFieldForAutofill() && if (input && input->IsTextField() && !input->IsPasswordFieldForAutofill() &&
IsElementAutocompletable(*input) && IsElementAutocompletable(*input) &&
form_util::IsWebElementVisible(*input)) { form_util::IsWebElementVisible(*input)) {
...@@ -615,7 +619,7 @@ blink::WebInputElement FindUsernameElementPrecedingPasswordElement( ...@@ -615,7 +619,7 @@ blink::WebInputElement FindUsernameElementPrecedingPasswordElement(
} }
} }
return blink::WebInputElement(); return WebInputElement();
} }
PasswordForm::SubmissionIndicatorEvent ToSubmissionIndicatorEvent( PasswordForm::SubmissionIndicatorEvent ToSubmissionIndicatorEvent(
...@@ -637,7 +641,7 @@ PasswordForm::SubmissionIndicatorEvent ToSubmissionIndicatorEvent( ...@@ -637,7 +641,7 @@ PasswordForm::SubmissionIndicatorEvent ToSubmissionIndicatorEvent(
WebInputElement ConvertToWebInput(const WebFormControlElement& element) { WebInputElement ConvertToWebInput(const WebFormControlElement& element) {
if (element.IsNull()) if (element.IsNull())
return WebInputElement(); return WebInputElement();
const WebInputElement* input = blink::ToWebInputElement(&element); const WebInputElement* input = ToWebInputElement(&element);
return input ? *input : WebInputElement(); return input ? *input : WebInputElement();
} }
...@@ -696,7 +700,7 @@ PasswordAutofillAgent::PasswordValueGatekeeper::~PasswordValueGatekeeper() { ...@@ -696,7 +700,7 @@ PasswordAutofillAgent::PasswordValueGatekeeper::~PasswordValueGatekeeper() {
} }
void PasswordAutofillAgent::PasswordValueGatekeeper::RegisterElement( void PasswordAutofillAgent::PasswordValueGatekeeper::RegisterElement(
blink::WebInputElement* element) { WebInputElement* element) {
if (was_user_gesture_seen_) if (was_user_gesture_seen_)
ShowValue(element); ShowValue(element);
else else
...@@ -709,7 +713,7 @@ void PasswordAutofillAgent::PasswordValueGatekeeper::OnUserGesture() { ...@@ -709,7 +713,7 @@ void PasswordAutofillAgent::PasswordValueGatekeeper::OnUserGesture() {
was_user_gesture_seen_ = true; was_user_gesture_seen_ = true;
for (blink::WebInputElement& element : elements_) for (WebInputElement& element : elements_)
ShowValue(&element); ShowValue(&element);
elements_.clear(); elements_.clear();
...@@ -721,7 +725,7 @@ void PasswordAutofillAgent::PasswordValueGatekeeper::Reset() { ...@@ -721,7 +725,7 @@ void PasswordAutofillAgent::PasswordValueGatekeeper::Reset() {
} }
void PasswordAutofillAgent::PasswordValueGatekeeper::ShowValue( void PasswordAutofillAgent::PasswordValueGatekeeper::ShowValue(
blink::WebInputElement* element) { WebInputElement* element) {
if (!element->IsNull() && !element->SuggestedValue().IsEmpty()) { if (!element->IsNull() && !element->SuggestedValue().IsEmpty()) {
element->SetAutofillValue(element->SuggestedValue()); element->SetAutofillValue(element->SuggestedValue());
element->SetAutofillState(WebAutofillState::kAutofilled); element->SetAutofillState(WebAutofillState::kAutofilled);
...@@ -729,9 +733,9 @@ void PasswordAutofillAgent::PasswordValueGatekeeper::ShowValue( ...@@ -729,9 +733,9 @@ void PasswordAutofillAgent::PasswordValueGatekeeper::ShowValue(
} }
bool PasswordAutofillAgent::TextDidChangeInTextField( bool PasswordAutofillAgent::TextDidChangeInTextField(
const blink::WebInputElement& element) { const WebInputElement& element) {
// TODO(vabr): Get a mutable argument instead. http://crbug.com/397083 // TODO(vabr): Get a mutable argument instead. http://crbug.com/397083
blink::WebInputElement mutable_element = element; // We need a non-const. WebInputElement mutable_element = element; // We need a non-const.
mutable_element.SetAutofillState(WebAutofillState::kNotFilled); mutable_element.SetAutofillState(WebAutofillState::kNotFilled);
WebInputToPasswordInfoMap::iterator iter = WebInputToPasswordInfoMap::iterator iter =
...@@ -745,9 +749,9 @@ bool PasswordAutofillAgent::TextDidChangeInTextField( ...@@ -745,9 +749,9 @@ bool PasswordAutofillAgent::TextDidChangeInTextField(
} }
void PasswordAutofillAgent::UpdateStateForTextChange( void PasswordAutofillAgent::UpdateStateForTextChange(
const blink::WebInputElement& element) { const WebInputElement& element) {
// TODO(vabr): Get a mutable argument instead. http://crbug.com/397083 // TODO(vabr): Get a mutable argument instead. http://crbug.com/397083
blink::WebInputElement mutable_element = element; // We need a non-const. WebInputElement mutable_element = element; // We need a non-const.
if (element.IsTextField()) { if (element.IsTextField()) {
const base::string16 element_value = element.Value().Utf16(); const base::string16 element_value = element.Value().Utf16();
...@@ -773,16 +777,16 @@ void PasswordAutofillAgent::UpdateStateForTextChange( ...@@ -773,16 +777,16 @@ void PasswordAutofillAgent::UpdateStateForTextChange(
} }
bool PasswordAutofillAgent::FillSuggestion( bool PasswordAutofillAgent::FillSuggestion(
const blink::WebFormControlElement& control_element, const WebFormControlElement& control_element,
const base::string16& username, const base::string16& username,
const base::string16& password) { const base::string16& password) {
// The element in context of the suggestion popup. // The element in context of the suggestion popup.
const blink::WebInputElement* element = ToWebInputElement(&control_element); const WebInputElement* element = ToWebInputElement(&control_element);
if (!element) if (!element)
return false; return false;
blink::WebInputElement username_element; WebInputElement username_element;
blink::WebInputElement password_element; WebInputElement password_element;
PasswordInfo* password_info = nullptr; PasswordInfo* password_info = nullptr;
if (!FindPasswordInfoForElement(*element, &username_element, if (!FindPasswordInfoForElement(*element, &username_element,
...@@ -810,7 +814,7 @@ bool PasswordAutofillAgent::FillSuggestion( ...@@ -810,7 +814,7 @@ bool PasswordAutofillAgent::FillSuggestion(
FillPasswordFieldAndSave(&password_element, password); FillPasswordFieldAndSave(&password_element, password);
blink::WebInputElement mutable_filled_element = *element; WebInputElement mutable_filled_element = *element;
mutable_filled_element.SetSelectionRange(element->Value().length(), mutable_filled_element.SetSelectionRange(element->Value().length(),
element->Value().length()); element->Value().length());
...@@ -837,11 +841,11 @@ void PasswordAutofillAgent::FillIntoFocusedField( ...@@ -837,11 +841,11 @@ void PasswordAutofillAgent::FillIntoFocusedField(
std::move(callback).Run(autofill::FillingStatus::SUCCESS); std::move(callback).Run(autofill::FillingStatus::SUCCESS);
} }
void PasswordAutofillAgent::FillField(blink::WebInputElement* input, void PasswordAutofillAgent::FillField(WebInputElement* input,
const base::string16& credential) { const base::string16& credential) {
DCHECK(input); DCHECK(input);
DCHECK(!input->IsNull()); DCHECK(!input->IsNull());
input->SetAutofillValue(blink::WebString::FromUTF16(credential)); input->SetAutofillValue(WebString::FromUTF16(credential));
input->SetAutofillState(WebAutofillState::kAutofilled); input->SetAutofillState(WebAutofillState::kAutofilled);
UpdateFieldValueAndPropertiesMaskMap(*input, &credential, UpdateFieldValueAndPropertiesMaskMap(*input, &credential,
FieldPropertiesFlags::AUTOFILLED, FieldPropertiesFlags::AUTOFILLED,
...@@ -849,7 +853,7 @@ void PasswordAutofillAgent::FillField(blink::WebInputElement* input, ...@@ -849,7 +853,7 @@ void PasswordAutofillAgent::FillField(blink::WebInputElement* input,
} }
void PasswordAutofillAgent::FillPasswordFieldAndSave( void PasswordAutofillAgent::FillPasswordFieldAndSave(
blink::WebInputElement* password_input, WebInputElement* password_input,
const base::string16& credential) { const base::string16& credential) {
DCHECK(password_input); DCHECK(password_input);
DCHECK(password_input->IsPasswordFieldForAutofill()); DCHECK(password_input->IsPasswordFieldForAutofill());
...@@ -859,16 +863,16 @@ void PasswordAutofillAgent::FillPasswordFieldAndSave( ...@@ -859,16 +863,16 @@ void PasswordAutofillAgent::FillPasswordFieldAndSave(
} }
bool PasswordAutofillAgent::PreviewSuggestion( bool PasswordAutofillAgent::PreviewSuggestion(
const blink::WebFormControlElement& control_element, const WebFormControlElement& control_element,
const blink::WebString& username, const WebString& username,
const blink::WebString& password) { const WebString& password) {
// The element in context of the suggestion popup. // The element in context of the suggestion popup.
const blink::WebInputElement* element = ToWebInputElement(&control_element); const WebInputElement* element = ToWebInputElement(&control_element);
if (!element) if (!element)
return false; return false;
blink::WebInputElement username_element; WebInputElement username_element;
blink::WebInputElement password_element; WebInputElement password_element;
PasswordInfo* password_info; PasswordInfo* password_info;
if (!FindPasswordInfoForElement(*element, &username_element, if (!FindPasswordInfoForElement(*element, &username_element,
...@@ -896,13 +900,13 @@ bool PasswordAutofillAgent::PreviewSuggestion( ...@@ -896,13 +900,13 @@ bool PasswordAutofillAgent::PreviewSuggestion(
} }
bool PasswordAutofillAgent::DidClearAutofillSelection( bool PasswordAutofillAgent::DidClearAutofillSelection(
const blink::WebFormControlElement& control_element) { const WebFormControlElement& control_element) {
const blink::WebInputElement* element = ToWebInputElement(&control_element); const WebInputElement* element = ToWebInputElement(&control_element);
if (!element) if (!element)
return false; return false;
blink::WebInputElement username_element; WebInputElement username_element;
blink::WebInputElement password_element; WebInputElement password_element;
PasswordInfo* password_info; PasswordInfo* password_info;
if (!FindPasswordInfoForElement(*element, &username_element, if (!FindPasswordInfoForElement(*element, &username_element,
...@@ -915,9 +919,9 @@ bool PasswordAutofillAgent::DidClearAutofillSelection( ...@@ -915,9 +919,9 @@ bool PasswordAutofillAgent::DidClearAutofillSelection(
} }
bool PasswordAutofillAgent::FindPasswordInfoForElement( bool PasswordAutofillAgent::FindPasswordInfoForElement(
const blink::WebInputElement& element, const WebInputElement& element,
blink::WebInputElement* username_element, WebInputElement* username_element,
blink::WebInputElement* password_element, WebInputElement* password_element,
PasswordInfo** password_info) { PasswordInfo** password_info) {
DCHECK(username_element && password_element && password_info); DCHECK(username_element && password_element && password_info);
username_element->Reset(); username_element->Reset();
...@@ -972,7 +976,7 @@ bool PasswordAutofillAgent::FindPasswordInfoForElement( ...@@ -972,7 +976,7 @@ bool PasswordAutofillAgent::FindPasswordInfoForElement(
} }
bool PasswordAutofillAgent::IsUsernameOrPasswordField( bool PasswordAutofillAgent::IsUsernameOrPasswordField(
const blink::WebInputElement& element) { const WebInputElement& element) {
// Note: A site may use a Password field to collect a CVV or a Credit Card // Note: A site may use a Password field to collect a CVV or a Credit Card
// number, but showing a slightly misleading warning here is better than // number, but showing a slightly misleading warning here is better than
// showing no warning at all. // showing no warning at all.
...@@ -1000,18 +1004,17 @@ bool PasswordAutofillAgent::IsUsernameOrPasswordField( ...@@ -1000,18 +1004,17 @@ bool PasswordAutofillAgent::IsUsernameOrPasswordField(
return (password_form->username_element == element.NameForAutofill().Utf16()); return (password_form->username_element == element.NameForAutofill().Utf16());
} }
bool PasswordAutofillAgent::ShowSuggestions( bool PasswordAutofillAgent::ShowSuggestions(const WebInputElement& element,
const blink::WebInputElement& element, bool show_all,
bool show_all, bool generation_popup_showing) {
bool generation_popup_showing) { WebInputElement username_element;
blink::WebInputElement username_element; WebInputElement password_element;
blink::WebInputElement password_element;
PasswordInfo* password_info; PasswordInfo* password_info;
if (!FindPasswordInfoForElement(element, &username_element, &password_element, if (!FindPasswordInfoForElement(element, &username_element, &password_element,
&password_info)) { &password_info)) {
if (IsUsernameOrPasswordField(element)) { if (IsUsernameOrPasswordField(element)) {
blink::WebLocalFrame* frame = render_frame()->GetWebFrame(); WebLocalFrame* frame = render_frame()->GetWebFrame();
GURL frame_url = GURL(frame->GetDocument().Url()); GURL frame_url = GURL(frame->GetDocument().Url());
#if defined(SAFE_BROWSING_DB_LOCAL) #if defined(SAFE_BROWSING_DB_LOCAL)
if (!checked_safe_browsing_reputation_) { if (!checked_safe_browsing_reputation_) {
...@@ -1071,7 +1074,7 @@ bool PasswordAutofillAgent::ShowSuggestions( ...@@ -1071,7 +1074,7 @@ bool PasswordAutofillAgent::ShowSuggestions(
bool PasswordAutofillAgent::FrameCanAccessPasswordManager() { bool PasswordAutofillAgent::FrameCanAccessPasswordManager() {
// about:blank or about:srcdoc frames should not be allowed to use password // about:blank or about:srcdoc frames should not be allowed to use password
// manager. See https://crbug.com/756587. // manager. See https://crbug.com/756587.
blink::WebLocalFrame* frame = render_frame()->GetWebFrame(); WebLocalFrame* frame = render_frame()->GetWebFrame();
if (frame->GetDocument().Url().ProtocolIs(url::kAboutScheme)) if (frame->GetDocument().Url().ProtocolIs(url::kAboutScheme))
return false; return false;
return frame->GetSecurityOrigin().CanAccessPasswordManager(); return frame->GetSecurityOrigin().CanAccessPasswordManager();
...@@ -1090,7 +1093,7 @@ void PasswordAutofillAgent::FireSubmissionIfFormDisappear( ...@@ -1090,7 +1093,7 @@ void PasswordAutofillAgent::FireSubmissionIfFormDisappear(
// Prompt to save only if the form is now gone, either invisible or // Prompt to save only if the form is now gone, either invisible or
// removed from the DOM. // removed from the DOM.
blink::WebLocalFrame* frame = render_frame()->GetWebFrame(); WebLocalFrame* frame = render_frame()->GetWebFrame();
const auto& password_form = provisionally_saved_form_.password_form(); const auto& password_form = provisionally_saved_form_.password_form();
// TODO(crbug.com/720347): This method could be called often and checking form // TODO(crbug.com/720347): This method could be called often and checking form
// visibility could be expesive. Add performance metrics for this. // visibility could be expesive. Add performance metrics for this.
...@@ -1124,7 +1127,7 @@ void PasswordAutofillAgent::SendPasswordForms(bool only_visible) { ...@@ -1124,7 +1127,7 @@ void PasswordAutofillAgent::SendPasswordForms(bool only_visible) {
logger->LogBoolean(Logger::STRING_ONLY_VISIBLE, only_visible); logger->LogBoolean(Logger::STRING_ONLY_VISIBLE, only_visible);
} }
blink::WebLocalFrame* frame = render_frame()->GetWebFrame(); WebLocalFrame* frame = render_frame()->GetWebFrame();
// Make sure that this security origin is allowed to use password manager. // Make sure that this security origin is allowed to use password manager.
blink::WebSecurityOrigin origin = frame->GetDocument().GetSecurityOrigin(); blink::WebSecurityOrigin origin = frame->GetDocument().GetSecurityOrigin();
...@@ -1146,7 +1149,7 @@ void PasswordAutofillAgent::SendPasswordForms(bool only_visible) { ...@@ -1146,7 +1149,7 @@ void PasswordAutofillAgent::SendPasswordForms(bool only_visible) {
return; return;
} }
blink::WebVector<blink::WebFormElement> forms; WebVector<WebFormElement> forms;
frame->GetDocument().Forms(forms); frame->GetDocument().Forms(forms);
if (IsShowAutofillSignaturesEnabled()) if (IsShowAutofillSignaturesEnabled())
...@@ -1155,7 +1158,7 @@ void PasswordAutofillAgent::SendPasswordForms(bool only_visible) { ...@@ -1155,7 +1158,7 @@ void PasswordAutofillAgent::SendPasswordForms(bool only_visible) {
logger->LogNumber(Logger::STRING_NUMBER_OF_ALL_FORMS, forms.size()); logger->LogNumber(Logger::STRING_NUMBER_OF_ALL_FORMS, forms.size());
std::vector<PasswordForm> password_forms; std::vector<PasswordForm> password_forms;
for (const blink::WebFormElement& form : forms) { for (const WebFormElement& form : forms) {
if (only_visible) { if (only_visible) {
bool is_form_visible = form_util::AreFormContentsVisible(form); bool is_form_visible = form_util::AreFormContentsVisible(form);
if (logger) { if (logger) {
...@@ -1184,7 +1187,7 @@ void PasswordAutofillAgent::SendPasswordForms(bool only_visible) { ...@@ -1184,7 +1187,7 @@ void PasswordAutofillAgent::SendPasswordForms(bool only_visible) {
// password submission. // password submission.
bool add_unowned_inputs = true; bool add_unowned_inputs = true;
if (only_visible) { if (only_visible) {
std::vector<blink::WebFormControlElement> control_elements = std::vector<WebFormControlElement> control_elements =
form_util::GetUnownedAutofillableFormFieldElements( form_util::GetUnownedAutofillableFormFieldElements(
frame->GetDocument().All(), nullptr); frame->GetDocument().All(), nullptr);
add_unowned_inputs = add_unowned_inputs =
...@@ -1210,7 +1213,7 @@ void PasswordAutofillAgent::SendPasswordForms(bool only_visible) { ...@@ -1210,7 +1213,7 @@ void PasswordAutofillAgent::SendPasswordForms(bool only_visible) {
// Send the PasswordFormsRendered message regardless of whether // Send the PasswordFormsRendered message regardless of whether
// |password_forms| is empty. The empty |password_forms| are a possible // |password_forms| is empty. The empty |password_forms| are a possible
// signal to the browser that a pending login attempt succeeded. // signal to the browser that a pending login attempt succeeded.
blink::WebFrame* main_frame = render_frame()->GetWebFrame()->Top(); WebFrame* main_frame = render_frame()->GetWebFrame()->Top();
bool did_stop_loading = !main_frame || !main_frame->IsLoading(); bool did_stop_loading = !main_frame || !main_frame->IsLoading();
GetPasswordManagerDriver()->PasswordFormsRendered(password_forms, GetPasswordManagerDriver()->PasswordFormsRendered(password_forms,
did_stop_loading); did_stop_loading);
...@@ -1282,8 +1285,7 @@ void PasswordAutofillAgent::OnFrameDetached() { ...@@ -1282,8 +1285,7 @@ void PasswordAutofillAgent::OnFrameDetached() {
FrameClosing(); FrameClosing();
} }
void PasswordAutofillAgent::OnWillSubmitForm( void PasswordAutofillAgent::OnWillSubmitForm(const WebFormElement& form) {
const blink::WebFormElement& form) {
std::unique_ptr<RendererSavePasswordProgressLogger> logger; std::unique_ptr<RendererSavePasswordProgressLogger> logger;
if (logging_state_active_) { if (logging_state_active_) {
logger.reset(new RendererSavePasswordProgressLogger( logger.reset(new RendererSavePasswordProgressLogger(
...@@ -1346,13 +1348,13 @@ void PasswordAutofillAgent::FocusedNodeChanged(const blink::WebNode& node) { ...@@ -1346,13 +1348,13 @@ void PasswordAutofillAgent::FocusedNodeChanged(const blink::WebNode& node) {
focused_input_element_.Reset(); focused_input_element_.Reset();
if (node.IsNull() || // |node| is null <==> focus outside of frame. if (node.IsNull() || // |node| is null <==> focus outside of frame.
!node.IsElementNode()) { // Not a valid blink::WebElement. !node.IsElementNode()) { // Not a valid WebElement.
GetPasswordManagerDriver()->FocusedInputChanged( GetPasswordManagerDriver()->FocusedInputChanged(
/*is_fillable=*/false, /*is_password_field=*/false); /*is_fillable=*/false, /*is_password_field=*/false);
return; return;
} }
blink::WebElement web_element = node.ToConst<blink::WebElement>(); WebElement web_element = node.ToConst<WebElement>();
const WebInputElement* input = ToWebInputElement(&web_element); const WebInputElement* input = ToWebInputElement(&web_element);
if (!input) { if (!input) {
GetPasswordManagerDriver()->FocusedInputChanged( GetPasswordManagerDriver()->FocusedInputChanged(
...@@ -1382,7 +1384,7 @@ void PasswordAutofillAgent::DidStartProvisionalLoad( ...@@ -1382,7 +1384,7 @@ void PasswordAutofillAgent::DidStartProvisionalLoad(
logger->LogMessage(Logger::STRING_DID_START_PROVISIONAL_LOAD_METHOD); logger->LogMessage(Logger::STRING_DID_START_PROVISIONAL_LOAD_METHOD);
} }
blink::WebLocalFrame* navigated_frame = render_frame()->GetWebFrame(); WebLocalFrame* navigated_frame = render_frame()->GetWebFrame();
if (navigated_frame->Parent()) { if (navigated_frame->Parent()) {
if (logger) if (logger)
logger->LogMessage(Logger::STRING_FRAME_NOT_MAIN_FRAME); logger->LogMessage(Logger::STRING_FRAME_NOT_MAIN_FRAME);
...@@ -1455,7 +1457,7 @@ void PasswordAutofillAgent::FillPasswordForm( ...@@ -1455,7 +1457,7 @@ void PasswordAutofillAgent::FillPasswordForm(
return; return;
} }
std::vector<blink::WebInputElement> elements; std::vector<WebInputElement> elements;
std::unique_ptr<RendererSavePasswordProgressLogger> logger; std::unique_ptr<RendererSavePasswordProgressLogger> logger;
if (logging_state_active_) { if (logging_state_active_) {
logger.reset(new RendererSavePasswordProgressLogger( logger.reset(new RendererSavePasswordProgressLogger(
...@@ -1470,10 +1472,10 @@ void PasswordAutofillAgent::FillPasswordForm( ...@@ -1470,10 +1472,10 @@ void PasswordAutofillAgent::FillPasswordForm(
return; return;
for (auto element : elements) { for (auto element : elements) {
blink::WebInputElement username_element = WebInputElement username_element = !element.IsPasswordFieldForAutofill()
!element.IsPasswordFieldForAutofill() ? element ? element
: password_to_username_[element]; : password_to_username_[element];
blink::WebInputElement password_element = WebInputElement password_element =
element.IsPasswordFieldForAutofill() element.IsPasswordFieldForAutofill()
? element ? element
: web_input_to_password_info_[element].password_field; : web_input_to_password_info_[element].password_field;
...@@ -1488,7 +1490,7 @@ void PasswordAutofillAgent::GetFillableElementFromFormData( ...@@ -1488,7 +1490,7 @@ void PasswordAutofillAgent::GetFillableElementFromFormData(
int key, int key,
const PasswordFormFillData& form_data, const PasswordFormFillData& form_data,
RendererSavePasswordProgressLogger* logger, RendererSavePasswordProgressLogger* logger,
std::vector<blink::WebInputElement>* elements) { std::vector<WebInputElement>* elements) {
DCHECK(elements); DCHECK(elements);
bool ambiguous_or_empty_names = bool ambiguous_or_empty_names =
DoesFormContainAmbiguousOrEmptyNames(form_data); DoesFormContainAmbiguousOrEmptyNames(form_data);
...@@ -1522,8 +1524,8 @@ void PasswordAutofillAgent::GetFillableElementFromFormData( ...@@ -1522,8 +1524,8 @@ void PasswordAutofillAgent::GetFillableElementFromFormData(
} }
// Attach autocomplete listener to enable selecting alternate logins. // Attach autocomplete listener to enable selecting alternate logins.
blink::WebInputElement username_element; WebInputElement username_element;
blink::WebInputElement password_element; WebInputElement password_element;
// Check whether the password form has a username input field. // Check whether the password form has a username input field.
if (!username_field_name.empty()) { if (!username_field_name.empty()) {
...@@ -1544,7 +1546,7 @@ void PasswordAutofillAgent::GetFillableElementFromFormData( ...@@ -1544,7 +1546,7 @@ void PasswordAutofillAgent::GetFillableElementFromFormData(
password_element = it->second; password_element = it->second;
} }
blink::WebInputElement main_element = WebInputElement main_element =
username_element.IsNull() ? password_element : username_element; username_element.IsNull() ? password_element : username_element;
if (elements) if (elements)
elements->push_back(main_element); elements->push_back(main_element);
...@@ -1558,18 +1560,18 @@ void PasswordAutofillAgent::GetFillableElementFromFormData( ...@@ -1558,18 +1560,18 @@ void PasswordAutofillAgent::GetFillableElementFromFormData(
void PasswordAutofillAgent::FocusedNodeHasChanged(const blink::WebNode& node) { void PasswordAutofillAgent::FocusedNodeHasChanged(const blink::WebNode& node) {
if (node.IsNull() || !node.IsElementNode()) if (node.IsNull() || !node.IsElementNode())
return; return;
const blink::WebElement web_element = node.ToConst<blink::WebElement>(); const WebElement web_element = node.ToConst<WebElement>();
if (!web_element.IsFormControlElement()) if (!web_element.IsFormControlElement())
return; return;
const blink::WebFormControlElement control_element = const WebFormControlElement control_element =
web_element.ToConst<blink::WebFormControlElement>(); web_element.ToConst<WebFormControlElement>();
UpdateFieldValueAndPropertiesMaskMap(control_element, nullptr, UpdateFieldValueAndPropertiesMaskMap(control_element, nullptr,
FieldPropertiesFlags::HAD_FOCUS, FieldPropertiesFlags::HAD_FOCUS,
&field_value_and_properties_map_); &field_value_and_properties_map_);
} }
std::unique_ptr<PasswordForm> PasswordAutofillAgent::GetPasswordFormFromWebForm( std::unique_ptr<PasswordForm> PasswordAutofillAgent::GetPasswordFormFromWebForm(
const blink::WebFormElement& web_form) { const WebFormElement& web_form) {
return CreatePasswordFormFromWebForm( return CreatePasswordFormFromWebForm(
web_form, &field_value_and_properties_map_, &form_predictions_, web_form, &field_value_and_properties_map_, &form_predictions_,
&username_detector_cache_); &username_detector_cache_);
...@@ -1584,7 +1586,7 @@ PasswordAutofillAgent::GetPasswordFormFromUnownedInputElements() { ...@@ -1584,7 +1586,7 @@ PasswordAutofillAgent::GetPasswordFormFromUnownedInputElements() {
content::RenderFrame* frame = render_frame(); content::RenderFrame* frame = render_frame();
if (!frame) if (!frame)
return nullptr; return nullptr;
blink::WebLocalFrame* web_frame = frame->GetWebFrame(); WebLocalFrame* web_frame = frame->GetWebFrame();
if (!web_frame) if (!web_frame)
return nullptr; return nullptr;
return CreatePasswordFormFromUnownedInputElements( return CreatePasswordFormFromUnownedInputElements(
...@@ -1606,10 +1608,10 @@ void PasswordAutofillAgent::FindFocusedPasswordForm( ...@@ -1606,10 +1608,10 @@ void PasswordAutofillAgent::FindFocusedPasswordForm(
FindFocusedPasswordFormCallback callback) { FindFocusedPasswordFormCallback callback) {
std::unique_ptr<PasswordForm> password_form; std::unique_ptr<PasswordForm> password_form;
blink::WebElement element = WebElement element =
render_frame()->GetWebFrame()->GetDocument().FocusedElement(); render_frame()->GetWebFrame()->GetDocument().FocusedElement();
if (!element.IsNull() && element.HasHTMLTagName("input")) { if (!element.IsNull() && element.HasHTMLTagName("input")) {
blink::WebInputElement input = element.To<blink::WebInputElement>(); WebInputElement input = element.To<WebInputElement>();
if (input.IsPasswordFieldForAutofill()) { if (input.IsPasswordFieldForAutofill()) {
if (!input.Form().IsNull()) { if (!input.Form().IsNull()) {
password_form = GetPasswordFormFromWebForm(input.Form()); password_form = GetPasswordFormFromWebForm(input.Form());
...@@ -1639,15 +1641,15 @@ void PasswordAutofillAgent::FindFocusedPasswordForm( ...@@ -1639,15 +1641,15 @@ void PasswordAutofillAgent::FindFocusedPasswordForm(
bool PasswordAutofillAgent::ShowSuggestionPopup( bool PasswordAutofillAgent::ShowSuggestionPopup(
const PasswordInfo& password_info, const PasswordInfo& password_info,
const blink::WebInputElement& user_input, const WebInputElement& user_input,
bool show_all, bool show_all,
bool show_on_password_field) { bool show_on_password_field) {
DCHECK(!user_input.IsNull()); DCHECK(!user_input.IsNull());
blink::WebFrame* frame = user_input.GetDocument().GetFrame(); WebFrame* frame = user_input.GetDocument().GetFrame();
if (!frame) if (!frame)
return false; return false;
blink::WebView* webview = frame->View(); WebView* webview = frame->View();
if (!webview) if (!webview)
return false; return false;
...@@ -1696,23 +1698,22 @@ void PasswordAutofillAgent::FrameClosing() { ...@@ -1696,23 +1698,22 @@ void PasswordAutofillAgent::FrameClosing() {
#endif #endif
} }
void PasswordAutofillAgent::ClearPreview( void PasswordAutofillAgent::ClearPreview(WebInputElement* username,
blink::WebInputElement* username, WebInputElement* password) {
blink::WebInputElement* password) {
if (!username->IsNull() && !username->SuggestedValue().IsEmpty()) { if (!username->IsNull() && !username->SuggestedValue().IsEmpty()) {
username->SetSuggestedValue(blink::WebString()); username->SetSuggestedValue(WebString());
username->SetAutofillState(username_autofill_state_); username->SetAutofillState(username_autofill_state_);
username->SetSelectionRange(username_query_prefix_.length(), username->SetSelectionRange(username_query_prefix_.length(),
username->Value().length()); username->Value().length());
} }
if (!password->SuggestedValue().IsEmpty()) { if (!password->SuggestedValue().IsEmpty()) {
password->SetSuggestedValue(blink::WebString()); password->SetSuggestedValue(WebString());
password->SetAutofillState(password_autofill_state_); password->SetAutofillState(password_autofill_state_);
} }
} }
void PasswordAutofillAgent::ProvisionallySavePassword( void PasswordAutofillAgent::ProvisionallySavePassword(
const blink::WebFormElement& form, const WebFormElement& form,
const blink::WebInputElement& element, const WebInputElement& element,
ProvisionallySaveRestriction restriction) { ProvisionallySaveRestriction restriction) {
DCHECK(!form.IsNull() || !element.IsNull()); DCHECK(!form.IsNull() || !element.IsNull());
...@@ -1744,8 +1745,8 @@ void PasswordAutofillAgent::ProvisionallySavePassword( ...@@ -1744,8 +1745,8 @@ void PasswordAutofillAgent::ProvisionallySavePassword(
} }
bool PasswordAutofillAgent::FillUserNameAndPassword( bool PasswordAutofillAgent::FillUserNameAndPassword(
blink::WebInputElement* username_element, WebInputElement* username_element,
blink::WebInputElement* password_element, WebInputElement* password_element,
const PasswordFormFillData& fill_data, const PasswordFormFillData& fill_data,
bool exact_username_match, bool exact_username_match,
bool username_may_use_prefilled_placeholder, bool username_may_use_prefilled_placeholder,
...@@ -1816,8 +1817,7 @@ bool PasswordAutofillAgent::FillUserNameAndPassword( ...@@ -1816,8 +1817,7 @@ bool PasswordAutofillAgent::FillUserNameAndPassword(
IsElementAutocompletable(*username_element)) { IsElementAutocompletable(*username_element)) {
if (!username.empty() && (username_element->Value().IsEmpty() || if (!username.empty() && (username_element->Value().IsEmpty() ||
prefilled_placeholder_username)) { prefilled_placeholder_username)) {
username_element->SetSuggestedValue( username_element->SetSuggestedValue(WebString::FromUTF16(username));
blink::WebString::FromUTF16(username));
gatekeeper_.RegisterElement(username_element); gatekeeper_.RegisterElement(username_element);
if (prefilled_placeholder_username) { if (prefilled_placeholder_username) {
LogPrefilledUsernameFillOutcome( LogPrefilledUsernameFillOutcome(
...@@ -1838,7 +1838,7 @@ bool PasswordAutofillAgent::FillUserNameAndPassword( ...@@ -1838,7 +1838,7 @@ bool PasswordAutofillAgent::FillUserNameAndPassword(
// sure that we do not fill in the DOM with a password until we believe the // sure that we do not fill in the DOM with a password until we believe the
// user is intentionally interacting with the page. // user is intentionally interacting with the page.
if (password_element->Value().Utf16() != password) if (password_element->Value().Utf16() != password)
password_element->SetSuggestedValue(blink::WebString::FromUTF16(password)); password_element->SetSuggestedValue(WebString::FromUTF16(password));
UpdateFieldValueAndPropertiesMaskMap(*password_element, &password, UpdateFieldValueAndPropertiesMaskMap(*password_element, &password,
FieldPropertiesFlags::AUTOFILLED, FieldPropertiesFlags::AUTOFILLED,
field_value_and_properties_map); field_value_and_properties_map);
...@@ -1863,15 +1863,14 @@ void PasswordAutofillAgent::LogPrefilledUsernameFillOutcome( ...@@ -1863,15 +1863,14 @@ void PasswordAutofillAgent::LogPrefilledUsernameFillOutcome(
bool PasswordAutofillAgent::FillFormOnPasswordReceived( bool PasswordAutofillAgent::FillFormOnPasswordReceived(
const PasswordFormFillData& fill_data, const PasswordFormFillData& fill_data,
blink::WebInputElement username_element, WebInputElement username_element,
blink::WebInputElement password_element, WebInputElement password_element,
FieldValueAndPropertiesMaskMap* field_value_and_properties_map, FieldValueAndPropertiesMaskMap* field_value_and_properties_map,
RendererSavePasswordProgressLogger* logger) { RendererSavePasswordProgressLogger* logger) {
// Do not fill if the password field is in a chain of iframes not having // Do not fill if the password field is in a chain of iframes not having
// identical origin. // identical origin.
blink::WebFrame* cur_frame = password_element.GetDocument().GetFrame(); WebFrame* cur_frame = password_element.GetDocument().GetFrame();
blink::WebString bottom_frame_origin = WebString bottom_frame_origin = cur_frame->GetSecurityOrigin().ToString();
cur_frame->GetSecurityOrigin().ToString();
DCHECK(cur_frame); DCHECK(cur_frame);
...@@ -1898,14 +1897,14 @@ bool PasswordAutofillAgent::FillFormOnPasswordReceived( ...@@ -1898,14 +1897,14 @@ bool PasswordAutofillAgent::FillFormOnPasswordReceived(
} }
void PasswordAutofillAgent::OnProvisionallySaveForm( void PasswordAutofillAgent::OnProvisionallySaveForm(
const blink::WebFormElement& form, const WebFormElement& form,
const blink::WebFormControlElement& element, const WebFormControlElement& element,
ElementChangeSource source) { ElementChangeSource source) {
// PasswordAutofillAgent isn't interested in SELECT control change. // PasswordAutofillAgent isn't interested in SELECT control change.
if (source == ElementChangeSource::SELECT_CHANGED) if (source == ElementChangeSource::SELECT_CHANGED)
return; return;
blink::WebInputElement input_element; WebInputElement input_element;
if (!element.IsNull() && element.HasHTMLTagName("input")) if (!element.IsNull() && element.HasHTMLTagName("input"))
input_element = *ToWebInputElement(&element); input_element = *ToWebInputElement(&element);
...@@ -1934,7 +1933,7 @@ void PasswordAutofillAgent::OnProvisionallySaveForm( ...@@ -1934,7 +1933,7 @@ void PasswordAutofillAgent::OnProvisionallySaveForm(
RESTRICTION_NON_EMPTY_PASSWORD); RESTRICTION_NON_EMPTY_PASSWORD);
} }
void PasswordAutofillAgent::OnFormSubmitted(const blink::WebFormElement& form) { void PasswordAutofillAgent::OnFormSubmitted(const WebFormElement& form) {
OnWillSubmitForm(form); OnWillSubmitForm(form);
} }
......
...@@ -37,6 +37,10 @@ ...@@ -37,6 +37,10 @@
#include "ui/gfx/geometry/rect.h" #include "ui/gfx/geometry/rect.h"
using blink::WebAutofillState; using blink::WebAutofillState;
using blink::WebInputElement;
using blink::WebFormControlElement;
using blink::WebFormElement;
using blink::WebLocalFrame;
namespace autofill { namespace autofill {
...@@ -48,31 +52,30 @@ using Logger = autofill::SavePasswordProgressLogger; ...@@ -48,31 +52,30 @@ using Logger = autofill::SavePasswordProgressLogger;
// Returns pairs of |PasswordForm| and corresponding |WebFormElement| for all // Returns pairs of |PasswordForm| and corresponding |WebFormElement| for all
// <form>s in the frame and for unowned <input>s. The method doesn't filter out // <form>s in the frame and for unowned <input>s. The method doesn't filter out
// invalid |PasswordForm|s. // invalid |PasswordForm|s.
std::vector<std::pair<std::unique_ptr<PasswordForm>, blink::WebFormElement>> std::vector<std::pair<std::unique_ptr<PasswordForm>, WebFormElement>>
GetAllPasswordFormsInFrame(PasswordAutofillAgent* password_agent, GetAllPasswordFormsInFrame(PasswordAutofillAgent* password_agent,
blink::WebLocalFrame* web_frame) { WebLocalFrame* web_frame) {
blink::WebVector<blink::WebFormElement> web_forms; blink::WebVector<WebFormElement> web_forms;
web_frame->GetDocument().Forms(web_forms); web_frame->GetDocument().Forms(web_forms);
std::vector<std::pair<std::unique_ptr<PasswordForm>, blink::WebFormElement>> std::vector<std::pair<std::unique_ptr<PasswordForm>, WebFormElement>>
all_forms; all_forms;
for (const blink::WebFormElement& web_form : web_forms) { for (const WebFormElement& web_form : web_forms) {
all_forms.emplace_back(std::make_pair( all_forms.emplace_back(std::make_pair(
password_agent->GetPasswordFormFromWebForm(web_form), web_form)); password_agent->GetPasswordFormFromWebForm(web_form), web_form));
} }
all_forms.emplace_back( all_forms.emplace_back(
std::make_pair(password_agent->GetPasswordFormFromUnownedInputElements(), std::make_pair(password_agent->GetPasswordFormFromUnownedInputElements(),
blink::WebFormElement())); WebFormElement()));
return all_forms; return all_forms;
} }
// Returns true if we think that this form is for account creation. Password // Returns true if we think that this form is for account creation. Password
// field(s) of the form are pushed back to |passwords|. // field(s) of the form are pushed back to |passwords|.
bool GetAccountCreationPasswordFields( bool GetAccountCreationPasswordFields(
const std::vector<blink::WebFormControlElement>& control_elements, const std::vector<WebFormControlElement>& control_elements,
std::vector<blink::WebInputElement>* passwords) { std::vector<WebInputElement>* passwords) {
for (const auto& control_element : control_elements) { for (const auto& control_element : control_elements) {
const blink::WebInputElement* input_element = const WebInputElement* input_element = ToWebInputElement(&control_element);
ToWebInputElement(&control_element);
if (input_element && input_element->IsTextField() && if (input_element && input_element->IsTextField() &&
input_element->IsPasswordFieldForAutofill()) { input_element->IsPasswordFieldForAutofill()) {
passwords->push_back(*input_element); passwords->push_back(*input_element);
...@@ -99,11 +102,11 @@ const PasswordFormGenerationData* FindFormGenerationData( ...@@ -99,11 +102,11 @@ const PasswordFormGenerationData* FindFormGenerationData(
// Returns a vector of up to 2 password fields with autocomplete attribute set // Returns a vector of up to 2 password fields with autocomplete attribute set
// to "new-password". These will be filled with the generated password. // to "new-password". These will be filled with the generated password.
std::vector<blink::WebInputElement> FindNewPasswordElementsMarkedBySite( std::vector<WebInputElement> FindNewPasswordElementsMarkedBySite(
const std::vector<blink::WebInputElement>& all_password_elements) { const std::vector<WebInputElement>& all_password_elements) {
std::vector<blink::WebInputElement> passwords; std::vector<WebInputElement> passwords;
auto is_new_password_field = [](const blink::WebInputElement& element) { auto is_new_password_field = [](const WebInputElement& element) {
return AutocompleteFlagForElement(element) == return AutocompleteFlagForElement(element) ==
AutocompleteFlag::NEW_PASSWORD; AutocompleteFlag::NEW_PASSWORD;
}; };
...@@ -125,14 +128,14 @@ std::vector<blink::WebInputElement> FindNewPasswordElementsMarkedBySite( ...@@ -125,14 +128,14 @@ std::vector<blink::WebInputElement> FindNewPasswordElementsMarkedBySite(
// Returns a vector of up to 2 password fields into which Chrome should fill the // Returns a vector of up to 2 password fields into which Chrome should fill the
// generated password. It assumes that |field_signature| describes the field // generated password. It assumes that |field_signature| describes the field
// where Chrome shows the password generation prompt. // where Chrome shows the password generation prompt.
std::vector<blink::WebInputElement> FindPasswordElementsForGeneration( std::vector<WebInputElement> FindPasswordElementsForGeneration(
const std::vector<blink::WebInputElement>& all_password_elements, const std::vector<WebInputElement>& all_password_elements,
const PasswordFormGenerationData& generation_data) { const PasswordFormGenerationData& generation_data) {
auto generation_field_iter = all_password_elements.end(); auto generation_field_iter = all_password_elements.end();
auto confirmation_field_iter = all_password_elements.end(); auto confirmation_field_iter = all_password_elements.end();
for (auto iter = all_password_elements.begin(); for (auto iter = all_password_elements.begin();
iter != all_password_elements.end(); ++iter) { iter != all_password_elements.end(); ++iter) {
const blink::WebInputElement& input = *iter; const WebInputElement& input = *iter;
FieldSignature signature = CalculateFieldSignatureByNameAndType( FieldSignature signature = CalculateFieldSignatureByNameAndType(
input.NameForAutofill().Utf16(), input.NameForAutofill().Utf16(),
input.FormControlTypeForAutofill().Utf8()); input.FormControlTypeForAutofill().Utf8());
...@@ -144,7 +147,7 @@ std::vector<blink::WebInputElement> FindPasswordElementsForGeneration( ...@@ -144,7 +147,7 @@ std::vector<blink::WebInputElement> FindPasswordElementsForGeneration(
} }
} }
std::vector<blink::WebInputElement> passwords; std::vector<WebInputElement> passwords;
if (generation_field_iter != all_password_elements.end()) { if (generation_field_iter != all_password_elements.end()) {
passwords.push_back(*generation_field_iter); passwords.push_back(*generation_field_iter);
...@@ -157,9 +160,9 @@ std::vector<blink::WebInputElement> FindPasswordElementsForGeneration( ...@@ -157,9 +160,9 @@ std::vector<blink::WebInputElement> FindPasswordElementsForGeneration(
} }
void CopyElementValueToOtherInputElements( void CopyElementValueToOtherInputElements(
const blink::WebInputElement* element, const WebInputElement* element,
std::vector<blink::WebInputElement>* elements) { std::vector<WebInputElement>* elements) {
for (blink::WebInputElement& it : *elements) { for (WebInputElement& it : *elements) {
if (*element != it) { if (*element != it) {
it.SetAutofillValue(element->Value()); it.SetAutofillValue(element->Value());
} }
...@@ -187,7 +190,7 @@ size_t GetMaximumOfferSize() { ...@@ -187,7 +190,7 @@ size_t GetMaximumOfferSize() {
PasswordGenerationAgent::AccountCreationFormData::AccountCreationFormData( PasswordGenerationAgent::AccountCreationFormData::AccountCreationFormData(
linked_ptr<PasswordForm> password_form, linked_ptr<PasswordForm> password_form,
std::vector<blink::WebInputElement> passwords) std::vector<WebInputElement> passwords)
: form(password_form), password_elements(std::move(passwords)) {} : form(password_form), password_elements(std::move(passwords)) {}
PasswordGenerationAgent::AccountCreationFormData::AccountCreationFormData( PasswordGenerationAgent::AccountCreationFormData::AccountCreationFormData(
...@@ -300,7 +303,7 @@ void PasswordGenerationAgent::OnDynamicFormsSeen() { ...@@ -300,7 +303,7 @@ void PasswordGenerationAgent::OnDynamicFormsSeen() {
} }
void PasswordGenerationAgent::OnFieldAutofilled( void PasswordGenerationAgent::OnFieldAutofilled(
const blink::WebInputElement& password_element) { const WebInputElement& password_element) {
if (password_is_generated_ && generation_element_ == password_element) if (password_is_generated_ && generation_element_ == password_element)
PasswordNoLongerGenerated(); PasswordNoLongerGenerated();
} }
...@@ -310,7 +313,7 @@ void PasswordGenerationAgent::AllowToRunFormClassifier() { ...@@ -310,7 +313,7 @@ void PasswordGenerationAgent::AllowToRunFormClassifier() {
} }
void PasswordGenerationAgent::RunFormClassifierAndSaveVote( void PasswordGenerationAgent::RunFormClassifierAndSaveVote(
const blink::WebFormElement& web_form, const WebFormElement& web_form,
const PasswordForm& form) { const PasswordForm& form) {
DCHECK(form_classifier_enabled_); DCHECK(form_classifier_enabled_);
...@@ -333,8 +336,8 @@ void PasswordGenerationAgent::FindPossibleGenerationForm() { ...@@ -333,8 +336,8 @@ void PasswordGenerationAgent::FindPossibleGenerationForm() {
if (generation_form_data_) if (generation_form_data_)
return; return;
blink::WebLocalFrame* web_frame = render_frame()->GetWebFrame(); WebLocalFrame* web_frame = render_frame()->GetWebFrame();
std::vector<std::pair<std::unique_ptr<PasswordForm>, blink::WebFormElement>> std::vector<std::pair<std::unique_ptr<PasswordForm>, WebFormElement>>
all_password_forms = all_password_forms =
GetAllPasswordFormsInFrame(password_agent_, web_frame); GetAllPasswordFormsInFrame(password_agent_, web_frame);
for (auto& form : all_password_forms) { for (auto& form : all_password_forms) {
...@@ -352,8 +355,8 @@ void PasswordGenerationAgent::FindPossibleGenerationForm() { ...@@ -352,8 +355,8 @@ void PasswordGenerationAgent::FindPossibleGenerationForm() {
if (realm == GaiaUrls::GetInstance()->gaia_login_form_realm()) if (realm == GaiaUrls::GetInstance()->gaia_login_form_realm())
continue; continue;
std::vector<blink::WebInputElement> passwords; std::vector<WebInputElement> passwords;
const blink::WebFormElement& web_form = form.second; const WebFormElement& web_form = form.second;
if (GetAccountCreationPasswordFields( if (GetAccountCreationPasswordFields(
web_form.IsNull() web_form.IsNull()
? form_util::GetUnownedFormFieldElements( ? form_util::GetUnownedFormFieldElements(
...@@ -490,7 +493,7 @@ void PasswordGenerationAgent::DetermineGenerationElement() { ...@@ -490,7 +493,7 @@ void PasswordGenerationAgent::DetermineGenerationElement() {
PasswordForm* possible_password_form = possible_form_data.form.get(); PasswordForm* possible_password_form = possible_form_data.form.get();
const PasswordFormGenerationData* generation_data = nullptr; const PasswordFormGenerationData* generation_data = nullptr;
std::vector<blink::WebInputElement> password_elements; std::vector<WebInputElement> password_elements;
if (base::CommandLine::ForCurrentProcess()->HasSwitch( if (base::CommandLine::ForCurrentProcess()->HasSwitch(
switches::kLocalHeuristicsOnlyForPasswordGeneration)) { switches::kLocalHeuristicsOnlyForPasswordGeneration)) {
password_elements = possible_form_data.password_elements; password_elements = possible_form_data.password_elements;
...@@ -546,14 +549,14 @@ bool PasswordGenerationAgent::SetUpUserTriggeredGeneration() { ...@@ -546,14 +549,14 @@ bool PasswordGenerationAgent::SetUpUserTriggeredGeneration() {
if (last_focused_password_element_.IsNull() || !render_frame()) if (last_focused_password_element_.IsNull() || !render_frame())
return false; return false;
blink::WebFormElement form = last_focused_password_element_.Form(); WebFormElement form = last_focused_password_element_.Form();
std::unique_ptr<PasswordForm> password_form; std::unique_ptr<PasswordForm> password_form;
std::vector<blink::WebFormControlElement> control_elements; std::vector<WebFormControlElement> control_elements;
if (!form.IsNull()) { if (!form.IsNull()) {
password_form = password_agent_->GetPasswordFormFromWebForm(form); password_form = password_agent_->GetPasswordFormFromWebForm(form);
control_elements = form_util::ExtractAutofillableElementsInForm(form); control_elements = form_util::ExtractAutofillableElementsInForm(form);
} else { } else {
const blink::WebLocalFrame& frame = *render_frame()->GetWebFrame(); const WebLocalFrame& frame = *render_frame()->GetWebFrame();
blink::WebDocument doc = frame.GetDocument(); blink::WebDocument doc = frame.GetDocument();
if (doc.IsNull()) if (doc.IsNull())
return false; return false;
...@@ -566,7 +569,7 @@ bool PasswordGenerationAgent::SetUpUserTriggeredGeneration() { ...@@ -566,7 +569,7 @@ bool PasswordGenerationAgent::SetUpUserTriggeredGeneration() {
return false; return false;
generation_element_ = last_focused_password_element_; generation_element_ = last_focused_password_element_;
std::vector<blink::WebInputElement> password_elements; std::vector<WebInputElement> password_elements;
GetAccountCreationPasswordFields(control_elements, &password_elements); GetAccountCreationPasswordFields(control_elements, &password_elements);
password_elements = FindPasswordElementsForGeneration( password_elements = FindPasswordElementsForGeneration(
password_elements, password_elements,
...@@ -598,7 +601,7 @@ bool PasswordGenerationAgent::FocusedNodeHasChanged( ...@@ -598,7 +601,7 @@ bool PasswordGenerationAgent::FocusedNodeHasChanged(
return false; return false;
} }
const blink::WebInputElement* element = ToWebInputElement(&web_element); const WebInputElement* element = ToWebInputElement(&web_element);
if (element && element->IsPasswordFieldForAutofill()) if (element && element->IsPasswordFieldForAutofill())
last_focused_password_element_ = *element; last_focused_password_element_ = *element;
if (!element || *element != generation_element_) { if (!element || *element != generation_element_) {
...@@ -630,7 +633,7 @@ bool PasswordGenerationAgent::FocusedNodeHasChanged( ...@@ -630,7 +633,7 @@ bool PasswordGenerationAgent::FocusedNodeHasChanged(
} }
bool PasswordGenerationAgent::TextDidChangeInTextField( bool PasswordGenerationAgent::TextDidChangeInTextField(
const blink::WebInputElement& element) { const WebInputElement& element) {
if (element != generation_element_) { if (element != generation_element_) {
// Presave the username if it has been changed. // Presave the username if it has been changed.
if (password_is_generated_ && if (password_is_generated_ &&
...@@ -723,8 +726,7 @@ void PasswordGenerationAgent::PasswordNoLongerGenerated() { ...@@ -723,8 +726,7 @@ void PasswordGenerationAgent::PasswordNoLongerGenerated() {
password_is_generated_ = false; password_is_generated_ = false;
password_edited_ = false; password_edited_ = false;
generation_element_.SetShouldRevealPassword(false); generation_element_.SetShouldRevealPassword(false);
for (blink::WebInputElement& password : for (WebInputElement& password : generation_form_data_->password_elements)
generation_form_data_->password_elements)
password.SetAutofillState(WebAutofillState::kNotFilled); password.SetAutofillState(WebAutofillState::kNotFilled);
password_generation::LogPasswordGenerationEvent( password_generation::LogPasswordGenerationEvent(
password_generation::PASSWORD_DELETED); password_generation::PASSWORD_DELETED);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment