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