Commit 0610cf3b authored by ch.dumez@samsung.com's avatar ch.dumez@samsung.com

Add Element::subResourceAttributeName() virtual function

Add Element::subResourceAttributeName() virtual function to distribute the code
to each HTML class, instead of having a complex function with a lot of branching
to determine the subresource attribute name of an Element.

R=tkent, adamk

Review URL: https://codereview.chromium.org/202633009

git-svn-id: svn://svn.chromium.org/blink/trunk@169558 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent 3346464e
......@@ -1071,6 +1071,11 @@ bool Element::hasLegalLinkAttribute(const QualifiedName&) const
return false;
}
const QualifiedName& Element::subResourceAttributeName() const
{
return nullQName();
}
inline void Element::attributeChangedFromParserOrByCloning(const QualifiedName& name, const AtomicString& newValue, AttributeModificationReason reason)
{
if (name == isAttr)
......
......@@ -312,6 +312,7 @@ public:
virtual void parseAttribute(const QualifiedName&, const AtomicString&) { }
virtual bool hasLegalLinkAttribute(const QualifiedName&) const;
virtual const QualifiedName& subResourceAttributeName() const;
// Only called by the parser immediately after element construction.
void parserSetAttributes(const Vector<Attribute>&);
......
......@@ -184,6 +184,11 @@ bool HTMLBodyElement::hasLegalLinkAttribute(const QualifiedName& name) const
return name == backgroundAttr || HTMLElement::hasLegalLinkAttribute(name);
}
const QualifiedName& HTMLBodyElement::subResourceAttributeName() const
{
return backgroundAttr;
}
bool HTMLBodyElement::supportsFocus() const
{
// This override is needed because the inherited method bails if the parent is editable.
......
......@@ -54,6 +54,7 @@ private:
virtual bool isURLAttribute(const Attribute&) const OVERRIDE;
virtual bool hasLegalLinkAttribute(const QualifiedName&) const OVERRIDE;
virtual const QualifiedName& subResourceAttributeName() const OVERRIDE;
virtual bool supportsFocus() const OVERRIDE;
......
......@@ -190,6 +190,11 @@ bool HTMLEmbedElement::isURLAttribute(const Attribute& attribute) const
return attribute.name() == srcAttr || HTMLPlugInElement::isURLAttribute(attribute);
}
const QualifiedName& HTMLEmbedElement::subResourceAttributeName() const
{
return srcAttr;
}
const AtomicString HTMLEmbedElement::imageSourceURL() const
{
return getAttribute(srcAttr);
......
......@@ -43,6 +43,7 @@ private:
virtual bool rendererIsNeeded(const RenderStyle&) OVERRIDE;
virtual bool isURLAttribute(const Attribute&) const OVERRIDE;
virtual const QualifiedName& subResourceAttributeName() const OVERRIDE;
virtual const AtomicString imageSourceURL() const OVERRIDE;
virtual RenderWidget* existingRenderWidget() const OVERRIDE;
......
......@@ -327,6 +327,11 @@ bool HTMLImageElement::hasLegalLinkAttribute(const QualifiedName& name) const
return name == srcAttr || HTMLElement::hasLegalLinkAttribute(name);
}
const QualifiedName& HTMLImageElement::subResourceAttributeName() const
{
return srcAttr;
}
const AtomicString& HTMLImageElement::alt() const
{
return fastGetAttribute(altAttr);
......
......@@ -110,6 +110,7 @@ private:
virtual bool isURLAttribute(const Attribute&) const OVERRIDE;
virtual bool hasLegalLinkAttribute(const QualifiedName&) const OVERRIDE;
virtual const QualifiedName& subResourceAttributeName() const OVERRIDE;
virtual bool draggable() const OVERRIDE;
......
......@@ -1211,6 +1211,11 @@ bool HTMLInputElement::hasLegalLinkAttribute(const QualifiedName& name) const
return m_inputType->hasLegalLinkAttribute(name) || HTMLTextFormControlElement::hasLegalLinkAttribute(name);
}
const QualifiedName& HTMLInputElement::subResourceAttributeName() const
{
return m_inputType->subResourceAttributeName();
}
const AtomicString& HTMLInputElement::defaultValue() const
{
return fastGetAttribute(valueAttr);
......
......@@ -339,6 +339,7 @@ private:
virtual bool isURLAttribute(const Attribute&) const OVERRIDE FINAL;
virtual bool hasLegalLinkAttribute(const QualifiedName&) const OVERRIDE FINAL;
virtual const QualifiedName& subResourceAttributeName() const OVERRIDE FINAL;
virtual bool isInRange() const OVERRIDE FINAL;
virtual bool isOutOfRange() const OVERRIDE FINAL;
......
......@@ -405,6 +405,17 @@ bool HTMLLinkElement::hasLegalLinkAttribute(const QualifiedName& name) const
return name == hrefAttr || HTMLElement::hasLegalLinkAttribute(name);
}
const QualifiedName& HTMLLinkElement::subResourceAttributeName() const
{
// If the link element is not css, ignore it.
if (equalIgnoringCase(getAttribute(typeAttr), "text/css")) {
// FIXME: Add support for extracting links of sub-resources which
// are inside style-sheet such as @import, @font-face, url(), etc.
return hrefAttr;
}
return HTMLElement::subResourceAttributeName();
}
KURL HTMLLinkElement::href() const
{
return document().completeURL(getAttribute(hrefAttr));
......
......@@ -182,6 +182,7 @@ private:
virtual void removedFrom(ContainerNode*) OVERRIDE;
virtual bool isURLAttribute(const Attribute&) const OVERRIDE;
virtual bool hasLegalLinkAttribute(const QualifiedName&) const OVERRIDE;
virtual const QualifiedName& subResourceAttributeName() const OVERRIDE;
virtual bool sheetLoaded() OVERRIDE;
virtual void notifyLoadedSheetAndAllCriticalSubresources(bool errorOccurred) OVERRIDE;
virtual void startLoadingDynamicSheet() OVERRIDE;
......
......@@ -50,4 +50,9 @@ bool HTMLModElement::hasLegalLinkAttribute(const QualifiedName& name) const
return name == citeAttr || HTMLElement::hasLegalLinkAttribute(name);
}
const QualifiedName& HTMLModElement::subResourceAttributeName() const
{
return citeAttr;
}
}
......@@ -37,6 +37,7 @@ private:
virtual bool isURLAttribute(const Attribute&) const OVERRIDE;
virtual bool hasLegalLinkAttribute(const QualifiedName&) const OVERRIDE;
virtual const QualifiedName& subResourceAttributeName() const OVERRIDE;
};
} //namespace
......
......@@ -375,6 +375,11 @@ bool HTMLObjectElement::hasLegalLinkAttribute(const QualifiedName& name) const
return name == classidAttr || name == dataAttr || name == codebaseAttr || HTMLPlugInElement::hasLegalLinkAttribute(name);
}
const QualifiedName& HTMLObjectElement::subResourceAttributeName() const
{
return dataAttr;
}
const AtomicString HTMLObjectElement::imageSourceURL() const
{
return getAttribute(dataAttr);
......
......@@ -82,6 +82,7 @@ private:
virtual bool isURLAttribute(const Attribute&) const OVERRIDE;
virtual bool hasLegalLinkAttribute(const QualifiedName&) const OVERRIDE;
virtual const QualifiedName& subResourceAttributeName() const OVERRIDE;
virtual const AtomicString imageSourceURL() const OVERRIDE;
virtual RenderWidget* existingRenderWidget() const OVERRIDE;
......
......@@ -53,4 +53,9 @@ bool HTMLQuoteElement::hasLegalLinkAttribute(const QualifiedName& name) const
return name == citeAttr || HTMLElement::hasLegalLinkAttribute(name);
}
const QualifiedName& HTMLQuoteElement::subResourceAttributeName() const
{
return citeAttr;
}
}
......@@ -38,6 +38,7 @@ private:
virtual bool isURLAttribute(const Attribute&) const OVERRIDE;
virtual bool hasLegalLinkAttribute(const QualifiedName&) const OVERRIDE;
virtual const QualifiedName& subResourceAttributeName() const OVERRIDE;
};
} //namespace
......
......@@ -59,6 +59,11 @@ bool HTMLScriptElement::hasLegalLinkAttribute(const QualifiedName& name) const
return name == srcAttr || HTMLElement::hasLegalLinkAttribute(name);
}
const QualifiedName& HTMLScriptElement::subResourceAttributeName() const
{
return srcAttr;
}
void HTMLScriptElement::childrenChanged(bool changedByParser, Node* beforeChange, Node* afterChange, int childCountDelta)
{
HTMLElement::childrenChanged(changedByParser, beforeChange, afterChange, childCountDelta);
......
......@@ -55,6 +55,7 @@ private:
virtual bool isURLAttribute(const Attribute&) const OVERRIDE;
virtual bool hasLegalLinkAttribute(const QualifiedName&) const OVERRIDE;
virtual const QualifiedName& subResourceAttributeName() const OVERRIDE;
virtual String sourceAttributeValue() const OVERRIDE;
virtual String charsetAttributeValue() const OVERRIDE;
......
......@@ -133,6 +133,11 @@ bool HTMLTableCellElement::hasLegalLinkAttribute(const QualifiedName& name) cons
return (hasLocalName(tdTag) && name == backgroundAttr) || HTMLTablePartElement::hasLegalLinkAttribute(name);
}
const QualifiedName& HTMLTableCellElement::subResourceAttributeName() const
{
return hasLocalName(tdTag) ? backgroundAttr : HTMLTablePartElement::subResourceAttributeName();
}
const AtomicString& HTMLTableCellElement::abbr() const
{
return fastGetAttribute(abbrAttr);
......
......@@ -60,6 +60,7 @@ private:
virtual bool isURLAttribute(const Attribute&) const OVERRIDE;
virtual bool hasLegalLinkAttribute(const QualifiedName&) const OVERRIDE;
virtual const QualifiedName& subResourceAttributeName() const OVERRIDE;
};
inline bool isHTMLTableCellElement(const Element& element)
......
......@@ -541,6 +541,11 @@ bool HTMLTableElement::hasLegalLinkAttribute(const QualifiedName& name) const
return name == backgroundAttr || HTMLElement::hasLegalLinkAttribute(name);
}
const QualifiedName& HTMLTableElement::subResourceAttributeName() const
{
return backgroundAttr;
}
PassRefPtr<HTMLCollection> HTMLTableElement::rows()
{
return ensureCachedHTMLCollection(TableRows);
......
......@@ -76,6 +76,7 @@ private:
virtual void collectStyleForPresentationAttribute(const QualifiedName&, const AtomicString&, MutableStylePropertySet*) OVERRIDE;
virtual bool isURLAttribute(const Attribute&) const OVERRIDE;
virtual bool hasLegalLinkAttribute(const QualifiedName&) const OVERRIDE;
virtual const QualifiedName& subResourceAttributeName() const OVERRIDE;
// Used to obtain either a solid or outset border decl and to deal with the frame and rules attributes.
virtual const StylePropertySet* additionalPresentationAttributeStyle() OVERRIDE;
......
......@@ -49,6 +49,11 @@ bool HTMLTableRowElement::hasLegalLinkAttribute(const QualifiedName& name) const
return name == backgroundAttr || HTMLTablePartElement::hasLegalLinkAttribute(name);
}
const QualifiedName& HTMLTableRowElement::subResourceAttributeName() const
{
return backgroundAttr;
}
PassRefPtr<HTMLTableRowElement> HTMLTableRowElement::create(Document& document)
{
return adoptRef(new HTMLTableRowElement(document));
......
......@@ -49,6 +49,7 @@ private:
explicit HTMLTableRowElement(Document&);
virtual bool hasLegalLinkAttribute(const QualifiedName&) const OVERRIDE;
virtual const QualifiedName& subResourceAttributeName() const OVERRIDE;
};
} // namespace
......
......@@ -240,4 +240,9 @@ bool ImageInputType::hasLegalLinkAttribute(const QualifiedName& name) const
return name == srcAttr || BaseButtonInputType::hasLegalLinkAttribute(name);
}
const QualifiedName& ImageInputType::subResourceAttributeName() const
{
return srcAttr;
}
} // namespace WebCore
......@@ -62,6 +62,7 @@ private:
virtual unsigned height() const OVERRIDE;
virtual unsigned width() const OVERRIDE;
virtual bool hasLegalLinkAttribute(const QualifiedName&) const OVERRIDE;
virtual const QualifiedName& subResourceAttributeName() const OVERRIDE;
IntPoint m_clickLocation; // Valid only during HTMLFormElement::prepareForSubmission().
};
......
......@@ -763,6 +763,11 @@ bool InputType::hasLegalLinkAttribute(const QualifiedName&) const
return false;
}
const QualifiedName& InputType::subResourceAttributeName() const
{
return nullQName();
}
bool InputType::supportsIndeterminateAppearance() const
{
return false;
......
......@@ -192,6 +192,7 @@ public:
virtual Decimal findClosestTickMarkValue(const Decimal&);
virtual void handleDOMActivateEvent(Event*);
virtual bool hasLegalLinkAttribute(const QualifiedName&) const;
virtual const QualifiedName& subResourceAttributeName() const;
// Parses the specified string for the type, and return
// the Decimal value for the parsing result if the parsing
......
......@@ -65,38 +65,11 @@ namespace {
KURL getSubResourceURLFromElement(Element* element)
{
ASSERT(element);
const QualifiedName* attributeName = 0;
if (element->hasTagName(HTMLNames::imgTag) || element->hasTagName(HTMLNames::scriptTag))
attributeName = &HTMLNames::srcAttr;
else if (element->hasTagName(HTMLNames::inputTag)) {
if (toHTMLInputElement(element)->isImageButton())
attributeName = &HTMLNames::srcAttr;
} else if (element->hasTagName(HTMLNames::bodyTag)
|| element->hasTagName(HTMLNames::tableTag)
|| element->hasTagName(HTMLNames::trTag)
|| element->hasTagName(HTMLNames::tdTag))
attributeName = &HTMLNames::backgroundAttr;
else if (element->hasTagName(HTMLNames::blockquoteTag)
|| element->hasTagName(HTMLNames::qTag)
|| element->hasTagName(HTMLNames::delTag)
|| element->hasTagName(HTMLNames::insTag))
attributeName = &HTMLNames::citeAttr;
else if (element->hasTagName(HTMLNames::linkTag)) {
// If the link element is not css, ignore it.
if (equalIgnoringCase(element->getAttribute(HTMLNames::typeAttr), "text/css")) {
// FIXME: Add support for extracting links of sub-resources which
// are inside style-sheet such as @import, @font-face, url(), etc.
attributeName = &HTMLNames::hrefAttr;
}
} else if (element->hasTagName(HTMLNames::objectTag))
attributeName = &HTMLNames::dataAttr;
else if (element->hasTagName(HTMLNames::embedTag))
attributeName = &HTMLNames::srcAttr;
if (!attributeName)
const QualifiedName& attributeName = element->subResourceAttributeName();
if (attributeName == nullQName())
return KURL();
String value = element->getAttribute(*attributeName);
String value = element->getAttribute(attributeName);
// Ignore javascript content.
if (value.isEmpty() || value.stripWhiteSpace().startsWith("javascript:", false))
return KURL();
......
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