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

Unified Diff: Source/web/WebPageSerializerImpl.cpp

Issue 436603003: Make Element::attributes() less error-prone and simplify call sites (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Take feedback into consideration Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/core/xml/parser/XMLDocumentParser.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/web/WebPageSerializerImpl.cpp
diff --git a/Source/web/WebPageSerializerImpl.cpp b/Source/web/WebPageSerializerImpl.cpp
index cbf846f0cc1eb63b18d42ea2cb2a1de31dcac962..45b1381ca8c2ba2efc76ae3576dbbbaa8a1516be 100644
--- a/Source/web/WebPageSerializerImpl.cpp
+++ b/Source/web/WebPageSerializerImpl.cpp
@@ -302,49 +302,48 @@ void WebPageSerializerImpl::openTagToString(Element* element,
result.append('<');
result.append(element->nodeName().lower());
// Go through all attributes and serialize them.
- if (element->hasAttributes()) {
- AttributeCollection attributes = element->attributes();
- AttributeCollection::const_iterator end = attributes.end();
- for (AttributeCollection::const_iterator it = attributes.begin(); it != end; ++it) {
- result.append(' ');
- // Add attribute pair
- result.append(it->name().toString());
- result.appendLiteral("=\"");
- if (!it->value().isEmpty()) {
- const String& attrValue = it->value();
-
- // Check whether we need to replace some resource links
- // with local resource paths.
- const QualifiedName& attrName = it->name();
- if (element->hasLegalLinkAttribute(attrName)) {
- // For links start with "javascript:", we do not change it.
- if (attrValue.startsWith("javascript:", false))
- result.append(attrValue);
- else {
- // Get the absolute link
- WebLocalFrameImpl* subFrame = WebLocalFrameImpl::fromFrameOwnerElement(element);
- String completeURL = subFrame ? subFrame->frame()->document()->url() :
- param->document->completeURL(attrValue);
- // Check whether we have local files for those link.
- if (m_localLinks.contains(completeURL)) {
- if (!param->directoryName.isEmpty()) {
- result.appendLiteral("./");
- result.append(param->directoryName);
- result.append('/');
- }
- result.append(m_localLinks.get(completeURL));
- } else
- result.append(completeURL);
- }
+ AttributeCollection attributes = element->attributes();
+ AttributeCollection::const_iterator end = attributes.end();
+ for (AttributeCollection::const_iterator it = attributes.begin(); it != end; ++it) {
+ result.append(' ');
+ // Add attribute pair
+ result.append(it->name().toString());
+ result.appendLiteral("=\"");
+ if (!it->value().isEmpty()) {
+ const String& attrValue = it->value();
+
+ // Check whether we need to replace some resource links
+ // with local resource paths.
+ const QualifiedName& attrName = it->name();
+ if (element->hasLegalLinkAttribute(attrName)) {
+ // For links start with "javascript:", we do not change it.
+ if (attrValue.startsWith("javascript:", false)) {
+ result.append(attrValue);
} else {
- if (param->isHTMLDocument)
- result.append(m_htmlEntities.convertEntitiesInString(attrValue));
- else
- result.append(m_xmlEntities.convertEntitiesInString(attrValue));
+ // Get the absolute link
+ WebLocalFrameImpl* subFrame = WebLocalFrameImpl::fromFrameOwnerElement(element);
+ String completeURL = subFrame ? subFrame->frame()->document()->url() :
+ param->document->completeURL(attrValue);
+ // Check whether we have local files for those link.
+ if (m_localLinks.contains(completeURL)) {
+ if (!param->directoryName.isEmpty()) {
+ result.appendLiteral("./");
+ result.append(param->directoryName);
+ result.append('/');
+ }
+ result.append(m_localLinks.get(completeURL));
+ } else {
+ result.append(completeURL);
+ }
}
+ } else {
+ if (param->isHTMLDocument)
+ result.append(m_htmlEntities.convertEntitiesInString(attrValue));
+ else
+ result.append(m_xmlEntities.convertEntitiesInString(attrValue));
}
- result.append('\"');
}
+ result.append('\"');
}
// Do post action for open tag.
« no previous file with comments | « Source/core/xml/parser/XMLDocumentParser.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698