Commit a9585522 authored by Mason Freed's avatar Mason Freed Committed by Chromium LUCI CQ

Pass through blink::Element::GetIdAttribute to WebElement

Rather than manually retrieve the "id" attribute, it is cleaner
and faster to use the existing blink::Element method, which is
optimized [1].

This should have no behavior changes.

[1] https://source.chromium.org/chromium/chromium/src/+/master:third_party/blink/renderer/core/dom/element.h;l=1326;drc=9f3ae654ee080ec3ccb5c3f85a51f5e880f5f18e

Change-Id: Ic7634eaa8e8057315d83317862ae16428ee15078
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2628029Reviewed-by: default avatarDominic Battré <battre@chromium.org>
Reviewed-by: default avatarPhilip Rogers <pdr@chromium.org>
Commit-Queue: Mason Freed <masonfreed@chromium.org>
Cr-Commit-Position: refs/heads/master@{#843783}
parent d7899881
......@@ -1654,10 +1654,8 @@ bool IsWebElementVisible(const blink::WebElement& element) {
base::string16 GetFormIdentifier(const WebFormElement& form) {
base::string16 identifier = form.GetName().Utf16();
static base::NoDestructor<WebString> kId("id");
if (identifier.empty())
identifier = form.GetAttribute(*kId).Utf16();
identifier = form.GetIdAttribute().Utf16();
return identifier;
}
......@@ -1707,7 +1705,6 @@ void WebFormControlElementToFormField(
DCHECK(field);
DCHECK(!element.IsNull());
static base::NoDestructor<WebString> kAutocomplete("autocomplete");
static base::NoDestructor<WebString> kId("id");
static base::NoDestructor<WebString> kName("name");
static base::NoDestructor<WebString> kRole("role");
static base::NoDestructor<WebString> kPlaceholder("placeholder");
......@@ -1716,7 +1713,7 @@ void WebFormControlElementToFormField(
// Save both id and name attributes, if present. If there is only one of them,
// it will be saved to |name|. See HTMLFormControlElement::nameForAutofill.
field->name = element.NameForAutofill().Utf16();
field->id_attribute = element.GetAttribute(*kId).Utf16();
field->id_attribute = element.GetIdAttribute().Utf16();
field->name_attribute = element.GetAttribute(*kName).Utf16();
field->unique_renderer_id =
FieldRendererId(element.UniqueRendererFormControlId());
......
......@@ -68,6 +68,8 @@ class BLINK_EXPORT WebElement : public WebNode {
bool IsEditable() const;
// Returns the qualified name, which may contain a prefix and a colon.
WebString TagName() const;
// Returns the id attribute.
WebString GetIdAttribute() const;
// Check if this element has the specified local tag name, and the HTML
// namespace. Tag name matching is case-insensitive.
bool HasHTMLTagName(const WebString&) const;
......
......@@ -80,6 +80,10 @@ WebString WebElement::TagName() const {
return ConstUnwrap<Element>()->tagName();
}
WebString WebElement::GetIdAttribute() const {
return ConstUnwrap<Element>()->GetIdAttribute();
}
bool WebElement::HasHTMLTagName(const WebString& tag_name) const {
// How to create class nodeName localName
// createElement('input') HTMLInputElement INPUT input
......
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