Bug 1288590: Use GetAttrInfoAt in nsXMLContentSerializer.cpp. r=bholley

MozReview-Commit-ID: 1mOIlXK8O5a
This commit is contained in:
Emilio Cobos Álvarez 2016-07-21 19:28:25 -07:00
Родитель 1f021d7738
Коммит 5b1b25967b
1 изменённых файлов: 35 добавлений и 33 удалений

Просмотреть файл

@ -73,7 +73,7 @@ nsXMLContentSerializer::~nsXMLContentSerializer()
NS_IMPL_ISUPPORTS(nsXMLContentSerializer, nsIContentSerializer)
NS_IMETHODIMP
NS_IMETHODIMP
nsXMLContentSerializer::Init(uint32_t aFlags, uint32_t aWrapColumn,
const char* aCharSet, bool aIsCopying,
bool aRewriteEncodingDeclaration)
@ -152,7 +152,7 @@ nsXMLContentSerializer::AppendTextData(nsIContent* aNode,
// error.
return NS_OK;
}
if (frag->Is2b()) {
const char16_t *strStart = frag->Get2b() + aStartOffset;
if (aTranslateEntities) {
@ -178,7 +178,7 @@ nsXMLContentSerializer::AppendTextData(nsIContent* aNode,
return NS_OK;
}
NS_IMETHODIMP
NS_IMETHODIMP
nsXMLContentSerializer::AppendText(nsIContent* aText,
int32_t aStartOffset,
int32_t aEndOffset,
@ -209,7 +209,7 @@ nsXMLContentSerializer::AppendText(nsIContent* aText,
return NS_OK;
}
NS_IMETHODIMP
NS_IMETHODIMP
nsXMLContentSerializer::AppendCDATASection(nsIContent* aCDATASection,
int32_t aStartOffset,
int32_t aEndOffset,
@ -244,7 +244,7 @@ nsXMLContentSerializer::AppendCDATASection(nsIContent* aCDATASection,
return NS_OK;
}
NS_IMETHODIMP
NS_IMETHODIMP
nsXMLContentSerializer::AppendProcessingInstruction(nsIContent* aPI,
int32_t aStartOffset,
int32_t aEndOffset,
@ -293,7 +293,7 @@ nsXMLContentSerializer::AppendProcessingInstruction(nsIContent* aPI,
return NS_OK;
}
NS_IMETHODIMP
NS_IMETHODIMP
nsXMLContentSerializer::AppendComment(nsIContent* aComment,
int32_t aStartOffset,
int32_t aEndOffset,
@ -350,7 +350,7 @@ nsXMLContentSerializer::AppendComment(nsIContent* aComment,
return NS_OK;
}
NS_IMETHODIMP
NS_IMETHODIMP
nsXMLContentSerializer::AppendDoctype(nsIContent* aDocType,
nsAString& aStr)
{
@ -411,13 +411,13 @@ nsXMLContentSerializer::AppendDoctype(nsIContent* aDocType,
NS_ENSURE_TRUE(AppendToString(systemId, aStr), NS_ERROR_OUT_OF_MEMORY);
NS_ENSURE_TRUE(AppendToString(quote, aStr), NS_ERROR_OUT_OF_MEMORY);
}
if (!internalSubset.IsEmpty()) {
NS_ENSURE_TRUE(AppendToString(NS_LITERAL_STRING(" ["), aStr), NS_ERROR_OUT_OF_MEMORY);
NS_ENSURE_TRUE(AppendToString(internalSubset, aStr), NS_ERROR_OUT_OF_MEMORY);
NS_ENSURE_TRUE(AppendToString(char16_t(']'), aStr), NS_ERROR_OUT_OF_MEMORY);
}
NS_ENSURE_TRUE(AppendToString(kGreaterThan, aStr), NS_ERROR_OUT_OF_MEMORY);
MaybeFlagNewlineForRootNode(aDocType);
@ -516,7 +516,7 @@ nsXMLContentSerializer::ConfirmPrefix(nsAString& aPrefix,
break;
}
haveSeenOurPrefix = true;
haveSeenOurPrefix = true;
// If they don't, and either:
// 1) We have a prefix (so we'd be redeclaring this prefix to point to a
@ -544,7 +544,7 @@ nsXMLContentSerializer::ConfirmPrefix(nsAString& aPrefix,
continue;
}
}
// If we've found a URI match, then record the first one
if (!uriMatch && aURI.Equals(decl.mURI)) {
// Need to check that decl->mPrefix is not declared anywhere closer to
@ -554,13 +554,13 @@ nsXMLContentSerializer::ConfirmPrefix(nsAString& aPrefix,
for (index2 = count-1; index2 > index && prefixOK; --index2) {
prefixOK = (mNameSpaceStack[index2].mPrefix != decl.mPrefix);
}
if (prefixOK) {
uriMatch = true;
closestURIMatch.Assign(decl.mPrefix);
}
}
--index;
}
@ -570,7 +570,7 @@ nsXMLContentSerializer::ConfirmPrefix(nsAString& aPrefix,
// 2) There is nothing on the namespace stack that has aPrefix as the prefix
// and a _different_ URI, except for the case aPrefix.IsEmpty (and
// possible default namespaces on ancestors)
// So if uriMatch is set it's OK to use the closestURIMatch prefix. The one
// exception is when closestURIMatch is actually empty (default namespace
// decl) and we must have a prefix.
@ -578,7 +578,7 @@ nsXMLContentSerializer::ConfirmPrefix(nsAString& aPrefix,
aPrefix.Assign(closestURIMatch);
return false;
}
if (aPrefix.IsEmpty()) {
// At this point, aPrefix is empty (which means we never had a prefix to
// start with). If we must have a prefix, just generate a new prefix and
@ -654,7 +654,7 @@ nsXMLContentSerializer::SerializeAttr(const nsAString& aPrefix,
// See http://www.w3.org/TR/REC-html40/appendix/notes.html#h-B.3.2.2 for
// the standard on character entity references in values. We also have to
// make sure to escape any '&' characters.
bool bIncludesSingle = false;
bool bIncludesDouble = false;
nsAString::const_iterator iCurr, iEnd;
@ -686,7 +686,7 @@ nsXMLContentSerializer::SerializeAttr(const nsAString& aPrefix,
// FALSE TRUE " FALSE
// TRUE FALSE ' FALSE
// TRUE TRUE " TRUE
char16_t cDelimiter =
char16_t cDelimiter =
(bIncludesDouble && !bIncludesSingle) ? char16_t('\'') : char16_t('"');
NS_ENSURE_TRUE(attrString.Append(char16_t('='), mozilla::fallible), false);
NS_ENSURE_TRUE(attrString.Append(cDelimiter, mozilla::fallible), false);
@ -716,7 +716,7 @@ nsXMLContentSerializer::SerializeAttr(const nsAString& aPrefix,
return true;
}
uint32_t
uint32_t
nsXMLContentSerializer::ScanNamespaceDeclarations(nsIContent* aContent,
nsIContent *aOriginalElement,
const nsAString& aTagNamespaceURI)
@ -729,11 +729,13 @@ nsXMLContentSerializer::ScanNamespaceDeclarations(nsIContent* aContent,
// First scan for namespace declarations, pushing each on the stack
uint32_t skipAttr = count;
for (index = 0; index < count; index++) {
const nsAttrName* name = aContent->GetAttrNameAt(index);
const nsAttrInfo info = aContent->GetAttrInfoAt(index);
const nsAttrName* name = info.mName;
int32_t namespaceID = name->NamespaceID();
nsIAtom *attrName = name->LocalName();
if (namespaceID == kNameSpaceID_XMLNS ||
// Also push on the stack attrs named "xmlns" in the null
// namespace... because once we serialize those out they'll look like
@ -742,7 +744,7 @@ nsXMLContentSerializer::ScanNamespaceDeclarations(nsIContent* aContent,
// in the xmlns namespace?
(namespaceID == kNameSpaceID_None &&
attrName == nsGkAtoms::xmlns)) {
aContent->GetAttr(namespaceID, attrName, uriStr);
info.mValue->ToString(uriStr);
if (!name->GetPrefix()) {
if (aTagNamespaceURI.IsEmpty() && !uriStr.IsEmpty()) {
@ -865,14 +867,14 @@ nsXMLContentSerializer::SerializeAttributes(nsIContent* aContent,
nsContentUtils::NameSpaceManager()->GetNameSpaceURI(namespaceID, uriStr);
addNSAttr = ConfirmPrefix(prefixStr, uriStr, aOriginalElement, true);
}
aContent->GetAttr(namespaceID, attrName, valueStr);
nsDependentAtomString nameStr(attrName);
bool isJS = IsJavaScript(aContent, attrName, namespaceID, valueStr);
NS_ENSURE_TRUE(SerializeAttr(prefixStr, nameStr, valueStr, aStr, !isJS), false);
if (addNSAttr) {
NS_ASSERTION(!prefixStr.IsEmpty(),
"Namespaced attributes must have a prefix");
@ -884,7 +886,7 @@ nsXMLContentSerializer::SerializeAttributes(nsIContent* aContent,
return true;
}
NS_IMETHODIMP
NS_IMETHODIMP
nsXMLContentSerializer::AppendElementStart(Element* aElement,
Element* aOriginalElement,
nsAString& aStr)
@ -1026,7 +1028,7 @@ nsXMLContentSerializer::AppendEndOfElementStart(Element* aElement,
return AppendToString(NS_LITERAL_STRING("/>"), aStr);
}
NS_IMETHODIMP
NS_IMETHODIMP
nsXMLContentSerializer::AppendElementEnd(Element* aElement,
nsAString& aStr)
{
@ -1050,7 +1052,7 @@ nsXMLContentSerializer::AppendElementEnd(Element* aElement,
}
nsAutoString tagPrefix, tagLocalName, tagNamespaceURI;
aElement->NodeInfo()->GetPrefix(tagPrefix);
aElement->NodeInfo()->GetName(tagLocalName);
aElement->NodeInfo()->GetNamespaceURI(tagNamespaceURI);
@ -1121,7 +1123,7 @@ nsXMLContentSerializer::AppendDocumentStart(nsIDocument *aDocument,
NS_NAMED_LITERAL_STRING(endQuote, "\"");
aStr += NS_LITERAL_STRING("<?xml version=\"") + version + endQuote;
if (!mCharset.IsEmpty()) {
aStr += NS_LITERAL_STRING(" encoding=\"") +
NS_ConvertASCIItoUTF16(mCharset) + endQuote;
@ -1367,19 +1369,19 @@ nsXMLContentSerializer::LineBreakBeforeOpen(int32_t aNamespaceID, nsIAtom* aName
return mAddSpace;
}
bool
bool
nsXMLContentSerializer::LineBreakAfterOpen(int32_t aNamespaceID, nsIAtom* aName)
{
return false;
}
bool
bool
nsXMLContentSerializer::LineBreakBeforeClose(int32_t aNamespaceID, nsIAtom* aName)
{
return mAddSpace;
}
bool
bool
nsXMLContentSerializer::LineBreakAfterClose(int32_t aNamespaceID, nsIAtom* aName)
{
return false;
@ -1581,11 +1583,11 @@ nsXMLContentSerializer::AppendWrapped_NonWhitespaceSequence(
}
else { // we reach the max column
if (!thisSequenceStartsAtBeginningOfLine &&
(mAddSpace || (!mDoFormat && aSequenceStartAfterAWhiteSpace))) {
(mAddSpace || (!mDoFormat && aSequenceStartAfterAWhiteSpace))) {
// when !mDoFormat, mAddSpace is not used, mAddSpace is always false
// so, in the case where mDoWrap && !mDoFormat, if we want to enter in this condition...
// We can avoid to wrap. We try to add the whole block
// We can avoid to wrap. We try to add the whole block
// in an empty new line
NS_ENSURE_TRUE(AppendNewLineToString(aOutputStr), false);