mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-27 23:02:20 +00:00
Bug 1131348 - Use fallible Append in content serializers. r=smaug,nfroyd
--HG-- extra : rebase_source : b14e676c057c7a3e02f9beddbfdffabdcd688b60
This commit is contained in:
parent
3a695ddab1
commit
71814e4b31
@ -67,7 +67,7 @@ nsHTMLContentSerializer::AppendDocumentStart(nsIDocument *aDocument,
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
void
|
||||
bool
|
||||
nsHTMLContentSerializer::SerializeHTMLAttributes(nsIContent* aContent,
|
||||
nsIContent *aOriginalElement,
|
||||
nsAString& aTagPrefix,
|
||||
@ -78,7 +78,7 @@ nsHTMLContentSerializer::SerializeHTMLAttributes(nsIContent* aContent,
|
||||
{
|
||||
int32_t count = aContent->GetAttrCount();
|
||||
if (!count)
|
||||
return;
|
||||
return true;
|
||||
|
||||
nsresult rv;
|
||||
nsAutoString valueStr;
|
||||
@ -169,8 +169,11 @@ nsHTMLContentSerializer::SerializeHTMLAttributes(nsIContent* aContent,
|
||||
valueStr.IsEmpty()) {
|
||||
valueStr = nameStr;
|
||||
}
|
||||
SerializeAttr(prefix, nameStr, valueStr, aStr, !isJS);
|
||||
NS_ENSURE_TRUE(SerializeAttr(prefix, nameStr, valueStr,
|
||||
aStr, !isJS), false);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
@ -183,10 +186,13 @@ nsHTMLContentSerializer::AppendElementStart(Element* aElement,
|
||||
nsIContent* content = aElement;
|
||||
|
||||
bool forceFormat = false;
|
||||
if (!CheckElementStart(content, forceFormat, aStr)) {
|
||||
return NS_OK;
|
||||
nsresult rv = NS_OK;
|
||||
if (!CheckElementStart(content, forceFormat, aStr, rv)) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
nsIAtom *name = content->NodeInfo()->NameAtom();
|
||||
int32_t ns = content->GetNameSpaceID();
|
||||
|
||||
@ -194,39 +200,41 @@ nsHTMLContentSerializer::AppendElementStart(Element* aElement,
|
||||
|
||||
if ((mDoFormat || forceFormat) && !mDoRaw && !PreLevel()) {
|
||||
if (mColPos && lineBreakBeforeOpen) {
|
||||
AppendNewLineToString(aStr);
|
||||
NS_ENSURE_TRUE(AppendNewLineToString(aStr), NS_ERROR_OUT_OF_MEMORY);
|
||||
}
|
||||
else {
|
||||
MaybeAddNewlineForRootNode(aStr);
|
||||
NS_ENSURE_TRUE(MaybeAddNewlineForRootNode(aStr), NS_ERROR_OUT_OF_MEMORY);
|
||||
}
|
||||
if (!mColPos) {
|
||||
AppendIndentation(aStr);
|
||||
NS_ENSURE_TRUE(AppendIndentation(aStr), NS_ERROR_OUT_OF_MEMORY);
|
||||
}
|
||||
else if (mAddSpace) {
|
||||
AppendToString(char16_t(' '), aStr);
|
||||
bool result = AppendToString(char16_t(' '), aStr);
|
||||
mAddSpace = false;
|
||||
NS_ENSURE_TRUE(result, NS_ERROR_OUT_OF_MEMORY);
|
||||
}
|
||||
}
|
||||
else if (mAddSpace) {
|
||||
AppendToString(char16_t(' '), aStr);
|
||||
bool result = AppendToString(char16_t(' '), aStr);
|
||||
mAddSpace = false;
|
||||
NS_ENSURE_TRUE(result, NS_ERROR_OUT_OF_MEMORY);
|
||||
}
|
||||
else {
|
||||
MaybeAddNewlineForRootNode(aStr);
|
||||
NS_ENSURE_TRUE(MaybeAddNewlineForRootNode(aStr), NS_ERROR_OUT_OF_MEMORY);
|
||||
}
|
||||
// Always reset to avoid false newlines in case MaybeAddNewlineForRootNode wasn't
|
||||
// called
|
||||
mAddNewlineForRootNode = false;
|
||||
|
||||
AppendToString(kLessThan, aStr);
|
||||
|
||||
AppendToString(nsDependentAtomString(name), aStr);
|
||||
NS_ENSURE_TRUE(AppendToString(kLessThan, aStr), NS_ERROR_OUT_OF_MEMORY);
|
||||
|
||||
NS_ENSURE_TRUE(AppendToString(nsDependentAtomString(name), aStr), NS_ERROR_OUT_OF_MEMORY);
|
||||
|
||||
MaybeEnterInPreContent(content);
|
||||
|
||||
// for block elements, we increase the indentation
|
||||
if ((mDoFormat || forceFormat) && !mDoRaw && !PreLevel())
|
||||
IncrIndentation(name);
|
||||
NS_ENSURE_TRUE(IncrIndentation(name), NS_ERROR_OUT_OF_MEMORY);
|
||||
|
||||
// Need to keep track of OL and LI elements in order to get ordinal number
|
||||
// for the LI.
|
||||
@ -255,22 +263,22 @@ nsHTMLContentSerializer::AppendElementStart(Element* aElement,
|
||||
mIsFirstChildOfOL = IsFirstChildOfOL(aOriginalElement);
|
||||
if (mIsFirstChildOfOL){
|
||||
// If OL is parent of this LI, serialize attributes in different manner.
|
||||
SerializeLIValueAttribute(aElement, aStr);
|
||||
NS_ENSURE_TRUE(SerializeLIValueAttribute(aElement, aStr), NS_ERROR_OUT_OF_MEMORY);
|
||||
}
|
||||
}
|
||||
|
||||
// Even LI passed above have to go through this
|
||||
// for serializing attributes other than "value".
|
||||
nsAutoString dummyPrefix;
|
||||
SerializeHTMLAttributes(content,
|
||||
aOriginalElement,
|
||||
dummyPrefix,
|
||||
EmptyString(),
|
||||
name,
|
||||
ns,
|
||||
aStr);
|
||||
NS_ENSURE_TRUE(SerializeHTMLAttributes(content,
|
||||
aOriginalElement,
|
||||
dummyPrefix,
|
||||
EmptyString(),
|
||||
name,
|
||||
ns,
|
||||
aStr), NS_ERROR_OUT_OF_MEMORY);
|
||||
|
||||
AppendToString(kGreaterThan, aStr);
|
||||
NS_ENSURE_TRUE(AppendToString(kGreaterThan, aStr), NS_ERROR_OUT_OF_MEMORY);
|
||||
|
||||
if (ns == kNameSpaceID_XHTML &&
|
||||
(name == nsGkAtoms::script ||
|
||||
@ -282,10 +290,10 @@ nsHTMLContentSerializer::AppendElementStart(Element* aElement,
|
||||
|
||||
if ((mDoFormat || forceFormat) && !mDoRaw && !PreLevel() &&
|
||||
LineBreakAfterOpen(ns, name)) {
|
||||
AppendNewLineToString(aStr);
|
||||
NS_ENSURE_TRUE(AppendNewLineToString(aStr), NS_ERROR_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
AfterElementStart(content, aOriginalElement, aStr);
|
||||
NS_ENSURE_TRUE(AfterElementStart(content, aOriginalElement, aStr), NS_ERROR_OUT_OF_MEMORY);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
@ -356,30 +364,32 @@ nsHTMLContentSerializer::AppendElementEnd(Element* aElement,
|
||||
bool lineBreakBeforeClose = LineBreakBeforeClose(ns, name);
|
||||
|
||||
if (mColPos && lineBreakBeforeClose) {
|
||||
AppendNewLineToString(aStr);
|
||||
NS_ENSURE_TRUE(AppendNewLineToString(aStr), NS_ERROR_OUT_OF_MEMORY);
|
||||
}
|
||||
if (!mColPos) {
|
||||
AppendIndentation(aStr);
|
||||
NS_ENSURE_TRUE(AppendIndentation(aStr), NS_ERROR_OUT_OF_MEMORY);
|
||||
}
|
||||
else if (mAddSpace) {
|
||||
AppendToString(char16_t(' '), aStr);
|
||||
bool result = AppendToString(char16_t(' '), aStr);
|
||||
mAddSpace = false;
|
||||
NS_ENSURE_TRUE(result, NS_ERROR_OUT_OF_MEMORY);
|
||||
}
|
||||
}
|
||||
else if (mAddSpace) {
|
||||
AppendToString(char16_t(' '), aStr);
|
||||
bool result = AppendToString(char16_t(' '), aStr);
|
||||
mAddSpace = false;
|
||||
NS_ENSURE_TRUE(result, NS_ERROR_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
AppendToString(kEndTag, aStr);
|
||||
AppendToString(nsDependentAtomString(name), aStr);
|
||||
AppendToString(kGreaterThan, aStr);
|
||||
NS_ENSURE_TRUE(AppendToString(kEndTag, aStr), NS_ERROR_OUT_OF_MEMORY);
|
||||
NS_ENSURE_TRUE(AppendToString(nsDependentAtomString(name), aStr), NS_ERROR_OUT_OF_MEMORY);
|
||||
NS_ENSURE_TRUE(AppendToString(kGreaterThan, aStr), NS_ERROR_OUT_OF_MEMORY);
|
||||
|
||||
MaybeLeaveFromPreContent(content);
|
||||
|
||||
if ((mDoFormat || forceFormat)&& !mDoRaw && !PreLevel()
|
||||
&& LineBreakAfterClose(ns, name)) {
|
||||
AppendNewLineToString(aStr);
|
||||
NS_ENSURE_TRUE(AppendNewLineToString(aStr), NS_ERROR_OUT_OF_MEMORY);
|
||||
}
|
||||
else {
|
||||
MaybeFlagNewlineForRootNode(aElement);
|
||||
@ -451,17 +461,16 @@ uint32_t FindNextBasicEntity(const nsAString& aStr,
|
||||
return aIndex;
|
||||
}
|
||||
|
||||
void
|
||||
bool
|
||||
nsHTMLContentSerializer::AppendAndTranslateEntities(const nsAString& aStr,
|
||||
nsAString& aOutputStr)
|
||||
{
|
||||
if (mBodyOnly && !mInBody) {
|
||||
return;
|
||||
return true;
|
||||
}
|
||||
|
||||
if (mDisableEntityEncoding) {
|
||||
aOutputStr.Append(aStr);
|
||||
return;
|
||||
return aOutputStr.Append(aStr, mozilla::fallible);
|
||||
}
|
||||
|
||||
bool nonBasicEntities =
|
||||
@ -479,20 +488,21 @@ nsHTMLContentSerializer::AppendAndTranslateEntities(const nsAString& aStr,
|
||||
i = FindNextBasicEntity(aStr, len, i, entityTable, &entity);
|
||||
uint32_t normalTextLen = i - start;
|
||||
if (normalTextLen) {
|
||||
aOutputStr.Append(Substring(aStr, start, normalTextLen));
|
||||
NS_ENSURE_TRUE(aOutputStr.Append(Substring(aStr, start, normalTextLen),
|
||||
mozilla::fallible), false);
|
||||
}
|
||||
if (entity) {
|
||||
aOutputStr.AppendASCII(entity);
|
||||
NS_ENSURE_TRUE(aOutputStr.AppendASCII(entity, mozilla::fallible), false);
|
||||
start = i + 1;
|
||||
}
|
||||
}
|
||||
return;
|
||||
return true;
|
||||
} else if (nonBasicEntities) {
|
||||
nsIParserService* parserService = nsContentUtils::GetParserService();
|
||||
|
||||
if (!parserService) {
|
||||
NS_ERROR("Can't get parser service");
|
||||
return;
|
||||
return true;
|
||||
}
|
||||
|
||||
nsReadingIterator<char16_t> done_reading;
|
||||
@ -563,25 +573,29 @@ nsHTMLContentSerializer::AppendAndTranslateEntities(const nsAString& aStr,
|
||||
}
|
||||
}
|
||||
|
||||
aOutputStr.Append(fragmentStart, advanceLength);
|
||||
bool result = aOutputStr.Append(fragmentStart, advanceLength, mozilla::fallible);
|
||||
if (entityText) {
|
||||
aOutputStr.Append(char16_t('&'));
|
||||
AppendASCIItoUTF16(entityText, aOutputStr);
|
||||
aOutputStr.Append(char16_t(';'));
|
||||
NS_ENSURE_TRUE(aOutputStr.Append(char16_t('&'), mozilla::fallible), false);
|
||||
NS_ENSURE_TRUE(AppendASCIItoUTF16(entityText, aOutputStr, mozilla::fallible), false);
|
||||
NS_ENSURE_TRUE(aOutputStr.Append(char16_t(';'), mozilla::fallible), false);
|
||||
advanceLength++;
|
||||
}
|
||||
else if (fullConstEntityText) {
|
||||
aOutputStr.AppendASCII(fullConstEntityText);
|
||||
NS_ENSURE_TRUE(aOutputStr.AppendASCII(fullConstEntityText, mozilla::fallible), false);
|
||||
++advanceLength;
|
||||
}
|
||||
// if it comes from nsIEntityConverter, it already has '&' and ';'
|
||||
else if (fullEntityText) {
|
||||
AppendASCIItoUTF16(fullEntityText, aOutputStr);
|
||||
bool ok = AppendASCIItoUTF16(fullEntityText, aOutputStr, mozilla::fallible);
|
||||
nsMemory::Free(fullEntityText);
|
||||
advanceLength += lengthReplaced;
|
||||
NS_ENSURE_TRUE(ok, false);
|
||||
}
|
||||
NS_ENSURE_TRUE(result, false);
|
||||
}
|
||||
} else {
|
||||
nsXMLContentSerializer::AppendAndTranslateEntities(aStr, aOutputStr);
|
||||
NS_ENSURE_TRUE(nsXMLContentSerializer::AppendAndTranslateEntities(aStr, aOutputStr), false);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -36,7 +36,8 @@ class nsHTMLContentSerializer : public nsXHTMLContentSerializer {
|
||||
nsAString& aStr) MOZ_OVERRIDE;
|
||||
protected:
|
||||
|
||||
virtual void SerializeHTMLAttributes(nsIContent* aContent,
|
||||
NS_WARN_UNUSED_RESULT
|
||||
virtual bool SerializeHTMLAttributes(nsIContent* aContent,
|
||||
nsIContent *aOriginalElement,
|
||||
nsAString& aTagPrefix,
|
||||
const nsAString& aTagNamespaceURI,
|
||||
@ -44,7 +45,8 @@ class nsHTMLContentSerializer : public nsXHTMLContentSerializer {
|
||||
int32_t aNamespace,
|
||||
nsAString& aStr);
|
||||
|
||||
virtual void AppendAndTranslateEntities(const nsAString& aStr,
|
||||
NS_WARN_UNUSED_RESULT
|
||||
virtual bool AppendAndTranslateEntities(const nsAString& aStr,
|
||||
nsAString& aOutputStr) MOZ_OVERRIDE;
|
||||
|
||||
};
|
||||
|
@ -134,24 +134,25 @@ nsXHTMLContentSerializer::AppendText(nsIContent* aText,
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
if (mDoRaw || PreLevel() > 0) {
|
||||
AppendToStringConvertLF(data, aStr);
|
||||
NS_ENSURE_TRUE(AppendToStringConvertLF(data, aStr), NS_ERROR_OUT_OF_MEMORY);
|
||||
}
|
||||
else if (mDoFormat) {
|
||||
AppendToStringFormatedWrapped(data, aStr);
|
||||
NS_ENSURE_TRUE(AppendToStringFormatedWrapped(data, aStr), NS_ERROR_OUT_OF_MEMORY);
|
||||
}
|
||||
else if (mDoWrap) {
|
||||
AppendToStringWrapped(data, aStr);
|
||||
NS_ENSURE_TRUE(AppendToStringWrapped(data, aStr), NS_ERROR_OUT_OF_MEMORY);
|
||||
}
|
||||
else {
|
||||
int32_t lastNewlineOffset = kNotFound;
|
||||
if (HasLongLines(data, lastNewlineOffset)) {
|
||||
// We have long lines, rewrap
|
||||
mDoWrap = true;
|
||||
AppendToStringWrapped(data, aStr);
|
||||
bool result = AppendToStringWrapped(data, aStr);
|
||||
mDoWrap = false;
|
||||
NS_ENSURE_TRUE(result, NS_ERROR_OUT_OF_MEMORY);
|
||||
}
|
||||
else {
|
||||
AppendToStringConvertLF(data, aStr);
|
||||
NS_ENSURE_TRUE(AppendToStringConvertLF(data, aStr), NS_ERROR_OUT_OF_MEMORY);
|
||||
}
|
||||
}
|
||||
|
||||
@ -222,7 +223,7 @@ nsXHTMLContentSerializer::EscapeURI(nsIContent* aContent, const nsAString& aURI,
|
||||
return rv;
|
||||
}
|
||||
|
||||
void
|
||||
bool
|
||||
nsXHTMLContentSerializer::SerializeAttributes(nsIContent* aContent,
|
||||
nsIContent *aOriginalElement,
|
||||
nsAString& aTagPrefix,
|
||||
@ -271,7 +272,7 @@ nsXHTMLContentSerializer::SerializeAttributes(nsIContent* aContent,
|
||||
mIsFirstChildOfOL = IsFirstChildOfOL(aOriginalElement);
|
||||
if (mIsFirstChildOfOL) {
|
||||
// If OL is parent of this LI, serialize attributes in different manner.
|
||||
SerializeLIValueAttribute(aContent, aStr);
|
||||
NS_ENSURE_TRUE(SerializeLIValueAttribute(aContent, aStr), false);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -281,10 +282,14 @@ nsXHTMLContentSerializer::SerializeAttributes(nsIContent* aContent,
|
||||
if (aAddNSAttr) {
|
||||
if (aTagPrefix.IsEmpty()) {
|
||||
// Serialize default namespace decl
|
||||
SerializeAttr(EmptyString(), xmlnsStr, aTagNamespaceURI, aStr, true);
|
||||
NS_ENSURE_TRUE(SerializeAttr(EmptyString(), xmlnsStr,
|
||||
aTagNamespaceURI,
|
||||
aStr, true), false);
|
||||
} else {
|
||||
// Serialize namespace decl
|
||||
SerializeAttr(xmlnsStr, aTagPrefix, aTagNamespaceURI, aStr, true);
|
||||
NS_ENSURE_TRUE(SerializeAttr(xmlnsStr, aTagPrefix,
|
||||
aTagNamespaceURI,
|
||||
aStr, true), false);
|
||||
}
|
||||
PushNameSpaceDecl(aTagPrefix, aTagNamespaceURI, aOriginalElement);
|
||||
}
|
||||
@ -395,19 +400,21 @@ nsXHTMLContentSerializer::SerializeAttributes(nsIContent* aContent,
|
||||
isJS = IsJavaScript(aContent, attrName, namespaceID, valueStr);
|
||||
}
|
||||
|
||||
SerializeAttr(prefixStr, nameStr, valueStr, aStr, !isJS);
|
||||
NS_ENSURE_TRUE(SerializeAttr(prefixStr, nameStr, valueStr, aStr, !isJS), false);
|
||||
|
||||
if (addNSAttr) {
|
||||
NS_ASSERTION(!prefixStr.IsEmpty(),
|
||||
"Namespaced attributes must have a prefix");
|
||||
SerializeAttr(xmlnsStr, prefixStr, uriStr, aStr, true);
|
||||
NS_ENSURE_TRUE(SerializeAttr(xmlnsStr, prefixStr, uriStr, aStr, true), false);
|
||||
PushNameSpaceDecl(prefixStr, uriStr, aOriginalElement);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
bool
|
||||
nsXHTMLContentSerializer::AppendEndOfElementStart(nsIContent *aOriginalElement,
|
||||
nsIAtom * aName,
|
||||
int32_t aNamespaceID,
|
||||
@ -418,9 +425,8 @@ nsXHTMLContentSerializer::AppendEndOfElementStart(nsIContent *aOriginalElement,
|
||||
NS_ASSERTION(!mIsHTMLSerializer, "nsHTMLContentSerializer shouldn't call this method !");
|
||||
|
||||
if (kNameSpaceID_XHTML != aNamespaceID) {
|
||||
nsXMLContentSerializer::AppendEndOfElementStart(aOriginalElement, aName,
|
||||
aNamespaceID, aStr);
|
||||
return;
|
||||
return nsXMLContentSerializer::AppendEndOfElementStart(aOriginalElement, aName,
|
||||
aNamespaceID, aStr);
|
||||
}
|
||||
|
||||
nsIContent* content = aOriginalElement;
|
||||
@ -441,17 +447,16 @@ nsXHTMLContentSerializer::AppendEndOfElementStart(nsIContent *aOriginalElement,
|
||||
// for backward compatibility with HTML 4 user agents
|
||||
// only non-container HTML elements can be closed immediatly,
|
||||
// and a space is added before />
|
||||
AppendToString(NS_LITERAL_STRING(" />"), aStr);
|
||||
return;
|
||||
return AppendToString(NS_LITERAL_STRING(" />"), aStr);
|
||||
}
|
||||
}
|
||||
}
|
||||
AppendToString(kGreaterThan, aStr);
|
||||
return AppendToString(kGreaterThan, aStr);
|
||||
}
|
||||
|
||||
void
|
||||
nsXHTMLContentSerializer::AfterElementStart(nsIContent * aContent,
|
||||
nsIContent *aOriginalElement,
|
||||
bool
|
||||
nsXHTMLContentSerializer::AfterElementStart(nsIContent* aContent,
|
||||
nsIContent* aOriginalElement,
|
||||
nsAString& aStr)
|
||||
{
|
||||
if (mRewriteEncodingDeclaration &&
|
||||
@ -477,20 +482,22 @@ nsXHTMLContentSerializer::AfterElementStart(nsIContent * aContent,
|
||||
}
|
||||
|
||||
if (!hasMeta) {
|
||||
AppendNewLineToString(aStr);
|
||||
NS_ENSURE_TRUE(AppendNewLineToString(aStr), false);
|
||||
if (mDoFormat) {
|
||||
AppendIndentation(aStr);
|
||||
NS_ENSURE_TRUE(AppendIndentation(aStr), false);
|
||||
}
|
||||
NS_ENSURE_TRUE(AppendToString(NS_LITERAL_STRING("<meta http-equiv=\"content-type\""), aStr), false);
|
||||
NS_ENSURE_TRUE(AppendToString(NS_LITERAL_STRING(" content=\"text/html; charset="), aStr), false);
|
||||
NS_ENSURE_TRUE(AppendToString(NS_ConvertASCIItoUTF16(mCharset), aStr), false);
|
||||
if (mIsHTMLSerializer) {
|
||||
NS_ENSURE_TRUE(AppendToString(NS_LITERAL_STRING("\">"), aStr), false);
|
||||
} else {
|
||||
NS_ENSURE_TRUE(AppendToString(NS_LITERAL_STRING("\" />"), aStr), false);
|
||||
}
|
||||
AppendToString(NS_LITERAL_STRING("<meta http-equiv=\"content-type\""),
|
||||
aStr);
|
||||
AppendToString(NS_LITERAL_STRING(" content=\"text/html; charset="), aStr);
|
||||
AppendToString(NS_ConvertASCIItoUTF16(mCharset), aStr);
|
||||
if (mIsHTMLSerializer)
|
||||
AppendToString(NS_LITERAL_STRING("\">"), aStr);
|
||||
else
|
||||
AppendToString(NS_LITERAL_STRING("\" />"), aStr);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void
|
||||
@ -520,8 +527,11 @@ nsXHTMLContentSerializer::AppendDocumentStart(nsIDocument *aDocument,
|
||||
bool
|
||||
nsXHTMLContentSerializer::CheckElementStart(nsIContent * aContent,
|
||||
bool & aForceFormat,
|
||||
nsAString& aStr)
|
||||
nsAString& aStr,
|
||||
nsresult& aResult)
|
||||
{
|
||||
aResult = NS_OK;
|
||||
|
||||
// The _moz_dirty attribute is emitted by the editor to
|
||||
// indicate that this element should be pretty printed
|
||||
// even if we're not in pretty printing mode
|
||||
@ -531,7 +541,7 @@ nsXHTMLContentSerializer::CheckElementStart(nsIContent * aContent,
|
||||
if (aContent->IsHTMLElement(nsGkAtoms::br) &&
|
||||
(mFlags & nsIDocumentEncoder::OutputNoFormattingInPre) &&
|
||||
PreLevel() > 0) {
|
||||
AppendNewLineToString(aStr);
|
||||
aResult = AppendNewLineToString(aStr) ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -591,20 +601,19 @@ nsXHTMLContentSerializer::CheckElementEnd(nsIContent * aContent,
|
||||
return nsXMLContentSerializer::CheckElementEnd(aContent, dummyFormat, aStr);
|
||||
}
|
||||
|
||||
void
|
||||
bool
|
||||
nsXHTMLContentSerializer::AppendAndTranslateEntities(const nsAString& aStr,
|
||||
nsAString& aOutputStr)
|
||||
{
|
||||
if (mBodyOnly && !mInBody) {
|
||||
return;
|
||||
return true;
|
||||
}
|
||||
|
||||
if (mDisableEntityEncoding) {
|
||||
aOutputStr.Append(aStr);
|
||||
return;
|
||||
return aOutputStr.Append(aStr, mozilla::fallible);
|
||||
}
|
||||
|
||||
nsXMLContentSerializer::AppendAndTranslateEntities(aStr, aOutputStr);
|
||||
|
||||
return nsXMLContentSerializer::AppendAndTranslateEntities(aStr, aOutputStr);
|
||||
}
|
||||
|
||||
bool
|
||||
@ -884,7 +893,7 @@ nsXHTMLContentSerializer::IsElementPreformatted(nsIContent* aNode)
|
||||
return false;
|
||||
}
|
||||
|
||||
void
|
||||
bool
|
||||
nsXHTMLContentSerializer::SerializeLIValueAttribute(nsIContent* aElement,
|
||||
nsAString& aStr)
|
||||
{
|
||||
@ -936,7 +945,8 @@ nsXHTMLContentSerializer::SerializeLIValueAttribute(nsIContent* aElement,
|
||||
if (offset == 0 && found) {
|
||||
// offset = 0 => LI itself has the value attribute and we did not need to traverse back.
|
||||
// Just serialize value attribute like other tags.
|
||||
SerializeAttr(EmptyString(), NS_LITERAL_STRING("value"), valueStr, aStr, false);
|
||||
NS_ENSURE_TRUE(SerializeAttr(EmptyString(), NS_LITERAL_STRING("value"),
|
||||
valueStr, aStr, false), false);
|
||||
}
|
||||
else if (offset == 1 && !found) {
|
||||
/*(offset = 1 && !found) means either LI is the first child node of OL
|
||||
@ -951,8 +961,11 @@ nsXHTMLContentSerializer::SerializeLIValueAttribute(nsIContent* aElement,
|
||||
|
||||
//As serializer needs to use this valueAttr we are creating here,
|
||||
valueStr.AppendInt(startVal + offset);
|
||||
SerializeAttr(EmptyString(), NS_LITERAL_STRING("value"), valueStr, aStr, false);
|
||||
NS_ENSURE_TRUE(SerializeAttr(EmptyString(), NS_LITERAL_STRING("value"),
|
||||
valueStr, aStr, false), false);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
|
@ -43,16 +43,19 @@ class nsXHTMLContentSerializer : public nsXMLContentSerializer {
|
||||
|
||||
virtual bool CheckElementStart(nsIContent * aContent,
|
||||
bool & aForceFormat,
|
||||
nsAString& aStr) MOZ_OVERRIDE;
|
||||
nsAString& aStr,
|
||||
nsresult& aResult) MOZ_OVERRIDE;
|
||||
|
||||
virtual void AppendEndOfElementStart(nsIContent *aOriginalElement,
|
||||
NS_WARN_UNUSED_RESULT
|
||||
virtual bool AppendEndOfElementStart(nsIContent *aOriginalElement,
|
||||
nsIAtom * aName,
|
||||
int32_t aNamespaceID,
|
||||
nsAString& aStr) MOZ_OVERRIDE;
|
||||
|
||||
virtual void AfterElementStart(nsIContent * aContent,
|
||||
nsIContent *aOriginalElement,
|
||||
nsAString& aStr) MOZ_OVERRIDE;
|
||||
NS_WARN_UNUSED_RESULT
|
||||
virtual bool AfterElementStart(nsIContent* aContent,
|
||||
nsIContent* aOriginalElement,
|
||||
nsAString& aStr) MOZ_OVERRIDE;
|
||||
|
||||
virtual bool CheckElementEnd(nsIContent * aContent,
|
||||
bool & aForceFormat,
|
||||
@ -72,7 +75,8 @@ class nsXHTMLContentSerializer : public nsXMLContentSerializer {
|
||||
virtual void MaybeEnterInPreContent(nsIContent* aNode) MOZ_OVERRIDE;
|
||||
virtual void MaybeLeaveFromPreContent(nsIContent* aNode) MOZ_OVERRIDE;
|
||||
|
||||
virtual void SerializeAttributes(nsIContent* aContent,
|
||||
NS_WARN_UNUSED_RESULT
|
||||
virtual bool SerializeAttributes(nsIContent* aContent,
|
||||
nsIContent *aOriginalElement,
|
||||
nsAString& aTagPrefix,
|
||||
const nsAString& aTagNamespaceURI,
|
||||
@ -83,12 +87,16 @@ class nsXHTMLContentSerializer : public nsXMLContentSerializer {
|
||||
|
||||
bool IsFirstChildOfOL(nsIContent* aElement);
|
||||
|
||||
void SerializeLIValueAttribute(nsIContent* aElement,
|
||||
NS_WARN_UNUSED_RESULT
|
||||
bool SerializeLIValueAttribute(nsIContent* aElement,
|
||||
nsAString& aStr);
|
||||
bool IsShorthandAttr(const nsIAtom* aAttrName,
|
||||
const nsIAtom* aElementName);
|
||||
virtual void AppendAndTranslateEntities(const nsAString& aStr,
|
||||
|
||||
NS_WARN_UNUSED_RESULT
|
||||
virtual bool AppendAndTranslateEntities(const nsAString& aStr,
|
||||
nsAString& aOutputStr) MOZ_OVERRIDE;
|
||||
|
||||
nsresult EscapeURI(nsIContent* aContent,
|
||||
const nsAString& aURI,
|
||||
nsAString& aEscapedURI);
|
||||
|
@ -154,18 +154,22 @@ nsXMLContentSerializer::AppendTextData(nsIContent* aNode,
|
||||
if (frag->Is2b()) {
|
||||
const char16_t *strStart = frag->Get2b() + aStartOffset;
|
||||
if (aTranslateEntities) {
|
||||
AppendAndTranslateEntities(Substring(strStart, strStart + length), aStr);
|
||||
NS_ENSURE_TRUE(AppendAndTranslateEntities(Substring(strStart, strStart + length), aStr),
|
||||
NS_ERROR_OUT_OF_MEMORY);
|
||||
}
|
||||
else {
|
||||
aStr.Append(Substring(strStart, strStart + length));
|
||||
NS_ENSURE_TRUE(aStr.Append(Substring(strStart, strStart + length), mozilla::fallible),
|
||||
NS_ERROR_OUT_OF_MEMORY);
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (aTranslateEntities) {
|
||||
AppendAndTranslateEntities(NS_ConvertASCIItoUTF16(frag->Get1b()+aStartOffset, length), aStr);
|
||||
NS_ENSURE_TRUE(AppendAndTranslateEntities(NS_ConvertASCIItoUTF16(frag->Get1b()+aStartOffset, length), aStr),
|
||||
NS_ERROR_OUT_OF_MEMORY);
|
||||
}
|
||||
else {
|
||||
aStr.Append(NS_ConvertASCIItoUTF16(frag->Get1b()+aStartOffset, length));
|
||||
NS_ENSURE_TRUE(aStr.Append(NS_ConvertASCIItoUTF16(frag->Get1b()+aStartOffset, length), mozilla::fallible),
|
||||
NS_ERROR_OUT_OF_MEMORY);
|
||||
}
|
||||
}
|
||||
|
||||
@ -188,16 +192,16 @@ nsXMLContentSerializer::AppendText(nsIContent* aText,
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
if (mDoRaw || PreLevel() > 0) {
|
||||
AppendToStringConvertLF(data, aStr);
|
||||
NS_ENSURE_TRUE(AppendToStringConvertLF(data, aStr), NS_ERROR_OUT_OF_MEMORY);
|
||||
}
|
||||
else if (mDoFormat) {
|
||||
AppendToStringFormatedWrapped(data, aStr);
|
||||
NS_ENSURE_TRUE(AppendToStringFormatedWrapped(data, aStr), NS_ERROR_OUT_OF_MEMORY);
|
||||
}
|
||||
else if (mDoWrap) {
|
||||
AppendToStringWrapped(data, aStr);
|
||||
NS_ENSURE_TRUE(AppendToStringWrapped(data, aStr), NS_ERROR_OUT_OF_MEMORY);
|
||||
}
|
||||
else {
|
||||
AppendToStringConvertLF(data, aStr);
|
||||
NS_ENSURE_TRUE(AppendToStringConvertLF(data, aStr), NS_ERROR_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
@ -215,25 +219,25 @@ nsXMLContentSerializer::AppendCDATASection(nsIContent* aCDATASection,
|
||||
NS_NAMED_LITERAL_STRING(cdata , "<![CDATA[");
|
||||
|
||||
if (mDoRaw || PreLevel() > 0) {
|
||||
AppendToString(cdata, aStr);
|
||||
NS_ENSURE_TRUE(AppendToString(cdata, aStr), NS_ERROR_OUT_OF_MEMORY);
|
||||
}
|
||||
else if (mDoFormat) {
|
||||
AppendToStringFormatedWrapped(cdata, aStr);
|
||||
NS_ENSURE_TRUE(AppendToStringFormatedWrapped(cdata, aStr), NS_ERROR_OUT_OF_MEMORY);
|
||||
}
|
||||
else if (mDoWrap) {
|
||||
AppendToStringWrapped(cdata, aStr);
|
||||
NS_ENSURE_TRUE(AppendToStringWrapped(cdata, aStr), NS_ERROR_OUT_OF_MEMORY);
|
||||
}
|
||||
else {
|
||||
AppendToString(cdata, aStr);
|
||||
NS_ENSURE_TRUE(AppendToString(cdata, aStr), NS_ERROR_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
nsAutoString data;
|
||||
rv = AppendTextData(aCDATASection, aStartOffset, aEndOffset, data, false);
|
||||
if (NS_FAILED(rv)) return NS_ERROR_FAILURE;
|
||||
|
||||
AppendToStringConvertLF(data, aStr);
|
||||
NS_ENSURE_TRUE(AppendToStringConvertLF(data, aStr), NS_ERROR_OUT_OF_MEMORY);
|
||||
|
||||
AppendToString(NS_LITERAL_STRING("]]>"), aStr);
|
||||
NS_ENSURE_TRUE(AppendToString(NS_LITERAL_STRING("]]>"), aStr), NS_ERROR_OUT_OF_MEMORY);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
@ -249,7 +253,7 @@ nsXMLContentSerializer::AppendProcessingInstruction(nsIContent* aPI,
|
||||
nsresult rv;
|
||||
nsAutoString target, data, start;
|
||||
|
||||
MaybeAddNewlineForRootNode(aStr);
|
||||
NS_ENSURE_TRUE(MaybeAddNewlineForRootNode(aStr), NS_ERROR_OUT_OF_MEMORY);
|
||||
|
||||
rv = pi->GetTarget(target);
|
||||
if (NS_FAILED(rv)) return NS_ERROR_FAILURE;
|
||||
@ -257,30 +261,30 @@ nsXMLContentSerializer::AppendProcessingInstruction(nsIContent* aPI,
|
||||
rv = pi->GetData(data);
|
||||
if (NS_FAILED(rv)) return NS_ERROR_FAILURE;
|
||||
|
||||
start.AppendLiteral("<?");
|
||||
start.Append(target);
|
||||
NS_ENSURE_TRUE(start.AppendLiteral("<?", mozilla::fallible), NS_ERROR_OUT_OF_MEMORY);
|
||||
NS_ENSURE_TRUE(start.Append(target, mozilla::fallible), NS_ERROR_OUT_OF_MEMORY);
|
||||
|
||||
if (mDoRaw || PreLevel() > 0) {
|
||||
AppendToString(start, aStr);
|
||||
NS_ENSURE_TRUE(AppendToString(start, aStr), NS_ERROR_OUT_OF_MEMORY);
|
||||
}
|
||||
else if (mDoFormat) {
|
||||
if (mAddSpace) {
|
||||
AppendNewLineToString(aStr);
|
||||
NS_ENSURE_TRUE(AppendNewLineToString(aStr), NS_ERROR_OUT_OF_MEMORY);
|
||||
}
|
||||
AppendToStringFormatedWrapped(start, aStr);
|
||||
NS_ENSURE_TRUE(AppendToStringFormatedWrapped(start, aStr), NS_ERROR_OUT_OF_MEMORY);
|
||||
}
|
||||
else if (mDoWrap) {
|
||||
AppendToStringWrapped(start, aStr);
|
||||
NS_ENSURE_TRUE(AppendToStringWrapped(start, aStr), NS_ERROR_OUT_OF_MEMORY);
|
||||
}
|
||||
else {
|
||||
AppendToString(start, aStr);
|
||||
NS_ENSURE_TRUE(AppendToString(start, aStr), NS_ERROR_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
if (!data.IsEmpty()) {
|
||||
AppendToString(char16_t(' '), aStr);
|
||||
AppendToStringConvertLF(data, aStr);
|
||||
NS_ENSURE_TRUE(AppendToString(char16_t(' '), aStr), NS_ERROR_OUT_OF_MEMORY);
|
||||
NS_ENSURE_TRUE(AppendToStringConvertLF(data, aStr), NS_ERROR_OUT_OF_MEMORY);
|
||||
}
|
||||
AppendToString(NS_LITERAL_STRING("?>"), aStr);
|
||||
NS_ENSURE_TRUE(AppendToString(NS_LITERAL_STRING("?>"), aStr), NS_ERROR_OUT_OF_MEMORY);
|
||||
|
||||
MaybeFlagNewlineForRootNode(aPI);
|
||||
|
||||
@ -314,30 +318,30 @@ nsXMLContentSerializer::AppendComment(nsIContent* aComment,
|
||||
data.Assign(frag);
|
||||
}
|
||||
|
||||
MaybeAddNewlineForRootNode(aStr);
|
||||
NS_ENSURE_TRUE(MaybeAddNewlineForRootNode(aStr), NS_ERROR_OUT_OF_MEMORY);
|
||||
|
||||
NS_NAMED_LITERAL_STRING(startComment, "<!--");
|
||||
|
||||
if (mDoRaw || PreLevel() > 0) {
|
||||
AppendToString(startComment, aStr);
|
||||
NS_ENSURE_TRUE(AppendToString(startComment, aStr), NS_ERROR_OUT_OF_MEMORY);
|
||||
}
|
||||
else if (mDoFormat) {
|
||||
if (mAddSpace) {
|
||||
AppendNewLineToString(aStr);
|
||||
NS_ENSURE_TRUE(AppendNewLineToString(aStr), NS_ERROR_OUT_OF_MEMORY);
|
||||
}
|
||||
AppendToStringFormatedWrapped(startComment, aStr);
|
||||
NS_ENSURE_TRUE(AppendToStringFormatedWrapped(startComment, aStr), NS_ERROR_OUT_OF_MEMORY);
|
||||
}
|
||||
else if (mDoWrap) {
|
||||
AppendToStringWrapped(startComment, aStr);
|
||||
NS_ENSURE_TRUE(AppendToStringWrapped(startComment, aStr), NS_ERROR_OUT_OF_MEMORY);
|
||||
}
|
||||
else {
|
||||
AppendToString(startComment, aStr);
|
||||
NS_ENSURE_TRUE(AppendToString(startComment, aStr), NS_ERROR_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
// Even if mDoformat, we don't format the content because it
|
||||
// could have been preformated by the author
|
||||
AppendToStringConvertLF(data, aStr);
|
||||
AppendToString(NS_LITERAL_STRING("-->"), aStr);
|
||||
NS_ENSURE_TRUE(AppendToStringConvertLF(data, aStr), NS_ERROR_OUT_OF_MEMORY);
|
||||
NS_ENSURE_TRUE(AppendToString(NS_LITERAL_STRING("-->"), aStr), NS_ERROR_OUT_OF_MEMORY);
|
||||
|
||||
MaybeFlagNewlineForRootNode(aComment);
|
||||
|
||||
@ -362,35 +366,35 @@ nsXMLContentSerializer::AppendDoctype(nsIContent* aDocType,
|
||||
rv = docType->GetInternalSubset(internalSubset);
|
||||
if (NS_FAILED(rv)) return NS_ERROR_FAILURE;
|
||||
|
||||
MaybeAddNewlineForRootNode(aStr);
|
||||
NS_ENSURE_TRUE(MaybeAddNewlineForRootNode(aStr), NS_ERROR_OUT_OF_MEMORY);
|
||||
|
||||
AppendToString(NS_LITERAL_STRING("<!DOCTYPE "), aStr);
|
||||
AppendToString(name, aStr);
|
||||
NS_ENSURE_TRUE(AppendToString(NS_LITERAL_STRING("<!DOCTYPE "), aStr), NS_ERROR_OUT_OF_MEMORY);
|
||||
NS_ENSURE_TRUE(AppendToString(name, aStr), NS_ERROR_OUT_OF_MEMORY);
|
||||
|
||||
char16_t quote;
|
||||
if (!publicId.IsEmpty()) {
|
||||
AppendToString(NS_LITERAL_STRING(" PUBLIC "), aStr);
|
||||
NS_ENSURE_TRUE(AppendToString(NS_LITERAL_STRING(" PUBLIC "), aStr), NS_ERROR_OUT_OF_MEMORY);
|
||||
if (publicId.FindChar(char16_t('"')) == -1) {
|
||||
quote = char16_t('"');
|
||||
}
|
||||
else {
|
||||
quote = char16_t('\'');
|
||||
}
|
||||
AppendToString(quote, aStr);
|
||||
AppendToString(publicId, aStr);
|
||||
AppendToString(quote, aStr);
|
||||
NS_ENSURE_TRUE(AppendToString(quote, aStr), NS_ERROR_OUT_OF_MEMORY);
|
||||
NS_ENSURE_TRUE(AppendToString(publicId, aStr), NS_ERROR_OUT_OF_MEMORY);
|
||||
NS_ENSURE_TRUE(AppendToString(quote, aStr), NS_ERROR_OUT_OF_MEMORY);
|
||||
|
||||
if (!systemId.IsEmpty()) {
|
||||
AppendToString(char16_t(' '), aStr);
|
||||
NS_ENSURE_TRUE(AppendToString(char16_t(' '), aStr), NS_ERROR_OUT_OF_MEMORY);
|
||||
if (systemId.FindChar(char16_t('"')) == -1) {
|
||||
quote = char16_t('"');
|
||||
}
|
||||
else {
|
||||
quote = char16_t('\'');
|
||||
}
|
||||
AppendToString(quote, aStr);
|
||||
AppendToString(systemId, aStr);
|
||||
AppendToString(quote, aStr);
|
||||
NS_ENSURE_TRUE(AppendToString(quote, aStr), NS_ERROR_OUT_OF_MEMORY);
|
||||
NS_ENSURE_TRUE(AppendToString(systemId, aStr), NS_ERROR_OUT_OF_MEMORY);
|
||||
NS_ENSURE_TRUE(AppendToString(quote, aStr), NS_ERROR_OUT_OF_MEMORY);
|
||||
}
|
||||
}
|
||||
else if (!systemId.IsEmpty()) {
|
||||
@ -400,19 +404,19 @@ nsXMLContentSerializer::AppendDoctype(nsIContent* aDocType,
|
||||
else {
|
||||
quote = char16_t('\'');
|
||||
}
|
||||
AppendToString(NS_LITERAL_STRING(" SYSTEM "), aStr);
|
||||
AppendToString(quote, aStr);
|
||||
AppendToString(systemId, aStr);
|
||||
AppendToString(quote, aStr);
|
||||
NS_ENSURE_TRUE(AppendToString(NS_LITERAL_STRING(" SYSTEM "), aStr), NS_ERROR_OUT_OF_MEMORY);
|
||||
NS_ENSURE_TRUE(AppendToString(quote, aStr), NS_ERROR_OUT_OF_MEMORY);
|
||||
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()) {
|
||||
AppendToString(NS_LITERAL_STRING(" ["), aStr);
|
||||
AppendToString(internalSubset, aStr);
|
||||
AppendToString(char16_t(']'), aStr);
|
||||
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);
|
||||
}
|
||||
|
||||
AppendToString(kGreaterThan, aStr);
|
||||
NS_ENSURE_TRUE(AppendToString(kGreaterThan, aStr), NS_ERROR_OUT_OF_MEMORY);
|
||||
MaybeFlagNewlineForRootNode(aDocType);
|
||||
|
||||
return NS_OK;
|
||||
@ -606,7 +610,7 @@ nsXMLContentSerializer::GenerateNewPrefix(nsAString& aPrefix)
|
||||
AppendASCIItoUTF16(buf, aPrefix);
|
||||
}
|
||||
|
||||
void
|
||||
bool
|
||||
nsXMLContentSerializer::SerializeAttr(const nsAString& aPrefix,
|
||||
const nsAString& aName,
|
||||
const nsAString& aValue,
|
||||
@ -619,25 +623,26 @@ nsXMLContentSerializer::SerializeAttr(const nsAString& aPrefix,
|
||||
bool rawAppend = mDoRaw && aDoEscapeEntities;
|
||||
nsAString& attrString = (rawAppend) ? aStr : attrString_;
|
||||
|
||||
attrString.Append(char16_t(' '));
|
||||
NS_ENSURE_TRUE(attrString.Append(char16_t(' '), mozilla::fallible), false);
|
||||
if (!aPrefix.IsEmpty()) {
|
||||
attrString.Append(aPrefix);
|
||||
attrString.Append(char16_t(':'));
|
||||
NS_ENSURE_TRUE(attrString.Append(aPrefix, mozilla::fallible), false);
|
||||
NS_ENSURE_TRUE(attrString.Append(char16_t(':'), mozilla::fallible), false);
|
||||
}
|
||||
attrString.Append(aName);
|
||||
NS_ENSURE_TRUE(attrString.Append(aName, mozilla::fallible), false);
|
||||
|
||||
if (aDoEscapeEntities) {
|
||||
// if problem characters are turned into character entity references
|
||||
// then there will be no problem with the value delimiter characters
|
||||
attrString.AppendLiteral("=\"");
|
||||
NS_ENSURE_TRUE(attrString.AppendLiteral("=\"", mozilla::fallible), false);
|
||||
|
||||
mInAttribute = true;
|
||||
AppendAndTranslateEntities(aValue, attrString);
|
||||
bool result = AppendAndTranslateEntities(aValue, attrString);
|
||||
mInAttribute = false;
|
||||
NS_ENSURE_TRUE(result, false);
|
||||
|
||||
attrString.Append(char16_t('"'));
|
||||
NS_ENSURE_TRUE(attrString.Append(char16_t('"'), mozilla::fallible), false);
|
||||
if (rawAppend) {
|
||||
return;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else {
|
||||
@ -681,30 +686,32 @@ nsXMLContentSerializer::SerializeAttr(const nsAString& aPrefix,
|
||||
// TRUE TRUE " TRUE
|
||||
char16_t cDelimiter =
|
||||
(bIncludesDouble && !bIncludesSingle) ? char16_t('\'') : char16_t('"');
|
||||
attrString.Append(char16_t('='));
|
||||
attrString.Append(cDelimiter);
|
||||
NS_ENSURE_TRUE(attrString.Append(char16_t('='), mozilla::fallible), false);
|
||||
NS_ENSURE_TRUE(attrString.Append(cDelimiter, mozilla::fallible), false);
|
||||
nsAutoString sValue(aValue);
|
||||
sValue.ReplaceSubstring(NS_LITERAL_STRING("&"),
|
||||
NS_LITERAL_STRING("&"));
|
||||
NS_ENSURE_TRUE(sValue.ReplaceSubstring(NS_LITERAL_STRING("&"),
|
||||
NS_LITERAL_STRING("&"), mozilla::fallible), false);
|
||||
if (bIncludesDouble && bIncludesSingle) {
|
||||
sValue.ReplaceSubstring(NS_LITERAL_STRING("\""),
|
||||
NS_LITERAL_STRING("""));
|
||||
NS_ENSURE_TRUE(sValue.ReplaceSubstring(NS_LITERAL_STRING("\""),
|
||||
NS_LITERAL_STRING("""), mozilla::fallible), false);
|
||||
}
|
||||
attrString.Append(sValue);
|
||||
attrString.Append(cDelimiter);
|
||||
NS_ENSURE_TRUE(attrString.Append(sValue, mozilla::fallible), false);
|
||||
NS_ENSURE_TRUE(attrString.Append(cDelimiter, mozilla::fallible), false);
|
||||
}
|
||||
if (mDoRaw || PreLevel() > 0) {
|
||||
AppendToStringConvertLF(attrString, aStr);
|
||||
NS_ENSURE_TRUE(AppendToStringConvertLF(attrString, aStr), false);
|
||||
}
|
||||
else if (mDoFormat) {
|
||||
AppendToStringFormatedWrapped(attrString, aStr);
|
||||
NS_ENSURE_TRUE(AppendToStringFormatedWrapped(attrString, aStr), false);
|
||||
}
|
||||
else if (mDoWrap) {
|
||||
AppendToStringWrapped(attrString, aStr);
|
||||
NS_ENSURE_TRUE(AppendToStringWrapped(attrString, aStr), false);
|
||||
}
|
||||
else {
|
||||
AppendToStringConvertLF(attrString, aStr);
|
||||
NS_ENSURE_TRUE(AppendToStringConvertLF(attrString, aStr), false);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
uint32_t
|
||||
@ -792,7 +799,7 @@ nsXMLContentSerializer::IsJavaScript(nsIContent * aContent, nsIAtom* aAttrNameAt
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
bool
|
||||
nsXMLContentSerializer::SerializeAttributes(nsIContent* aContent,
|
||||
nsIContent *aOriginalElement,
|
||||
nsAString& aTagPrefix,
|
||||
@ -813,11 +820,11 @@ nsXMLContentSerializer::SerializeAttributes(nsIContent* aContent,
|
||||
if (aAddNSAttr) {
|
||||
if (aTagPrefix.IsEmpty()) {
|
||||
// Serialize default namespace decl
|
||||
SerializeAttr(EmptyString(), xmlnsStr, aTagNamespaceURI, aStr, true);
|
||||
NS_ENSURE_TRUE(SerializeAttr(EmptyString(), xmlnsStr, aTagNamespaceURI, aStr, true), false);
|
||||
}
|
||||
else {
|
||||
// Serialize namespace decl
|
||||
SerializeAttr(xmlnsStr, aTagPrefix, aTagNamespaceURI, aStr, true);
|
||||
NS_ENSURE_TRUE(SerializeAttr(xmlnsStr, aTagPrefix, aTagNamespaceURI, aStr, true), false);
|
||||
}
|
||||
PushNameSpaceDecl(aTagPrefix, aTagNamespaceURI, aOriginalElement);
|
||||
}
|
||||
@ -862,15 +869,17 @@ nsXMLContentSerializer::SerializeAttributes(nsIContent* aContent,
|
||||
nsDependentAtomString nameStr(attrName);
|
||||
bool isJS = IsJavaScript(aContent, attrName, namespaceID, valueStr);
|
||||
|
||||
SerializeAttr(prefixStr, nameStr, valueStr, aStr, !isJS);
|
||||
NS_ENSURE_TRUE(SerializeAttr(prefixStr, nameStr, valueStr, aStr, !isJS), false);
|
||||
|
||||
if (addNSAttr) {
|
||||
NS_ASSERTION(!prefixStr.IsEmpty(),
|
||||
"Namespaced attributes must have a prefix");
|
||||
SerializeAttr(xmlnsStr, prefixStr, uriStr, aStr, true);
|
||||
NS_ENSURE_TRUE(SerializeAttr(xmlnsStr, prefixStr, uriStr, aStr, true), false);
|
||||
PushNameSpaceDecl(prefixStr, uriStr, aOriginalElement);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
@ -883,10 +892,13 @@ nsXMLContentSerializer::AppendElementStart(Element* aElement,
|
||||
nsIContent* content = aElement;
|
||||
|
||||
bool forceFormat = false;
|
||||
if (!CheckElementStart(content, forceFormat, aStr)) {
|
||||
return NS_OK;
|
||||
nsresult rv = NS_OK;
|
||||
if (!CheckElementStart(content, forceFormat, aStr, rv)) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
nsAutoString tagPrefix, tagLocalName, tagNamespaceURI;
|
||||
aElement->NodeInfo()->GetPrefix(tagPrefix);
|
||||
aElement->NodeInfo()->GetName(tagLocalName);
|
||||
@ -900,25 +912,25 @@ nsXMLContentSerializer::AppendElementStart(Element* aElement,
|
||||
|
||||
if ((mDoFormat || forceFormat) && !mDoRaw && !PreLevel()) {
|
||||
if (mColPos && lineBreakBeforeOpen) {
|
||||
AppendNewLineToString(aStr);
|
||||
NS_ENSURE_TRUE(AppendNewLineToString(aStr), NS_ERROR_OUT_OF_MEMORY);
|
||||
}
|
||||
else {
|
||||
MaybeAddNewlineForRootNode(aStr);
|
||||
NS_ENSURE_TRUE(MaybeAddNewlineForRootNode(aStr), NS_ERROR_OUT_OF_MEMORY);
|
||||
}
|
||||
if (!mColPos) {
|
||||
AppendIndentation(aStr);
|
||||
NS_ENSURE_TRUE(AppendIndentation(aStr), NS_ERROR_OUT_OF_MEMORY);
|
||||
}
|
||||
else if (mAddSpace) {
|
||||
AppendToString(char16_t(' '), aStr);
|
||||
NS_ENSURE_TRUE(AppendToString(char16_t(' '), aStr), NS_ERROR_OUT_OF_MEMORY);
|
||||
mAddSpace = false;
|
||||
}
|
||||
}
|
||||
else if (mAddSpace) {
|
||||
AppendToString(char16_t(' '), aStr);
|
||||
NS_ENSURE_TRUE(AppendToString(char16_t(' '), aStr), NS_ERROR_OUT_OF_MEMORY);
|
||||
mAddSpace = false;
|
||||
}
|
||||
else {
|
||||
MaybeAddNewlineForRootNode(aStr);
|
||||
NS_ENSURE_TRUE(MaybeAddNewlineForRootNode(aStr), NS_ERROR_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
// Always reset to avoid false newlines in case MaybeAddNewlineForRootNode wasn't
|
||||
@ -930,36 +942,38 @@ nsXMLContentSerializer::AppendElementStart(Element* aElement,
|
||||
false);
|
||||
|
||||
// Serialize the qualified name of the element
|
||||
AppendToString(kLessThan, aStr);
|
||||
NS_ENSURE_TRUE(AppendToString(kLessThan, aStr), NS_ERROR_OUT_OF_MEMORY);
|
||||
if (!tagPrefix.IsEmpty()) {
|
||||
AppendToString(tagPrefix, aStr);
|
||||
AppendToString(NS_LITERAL_STRING(":"), aStr);
|
||||
NS_ENSURE_TRUE(AppendToString(tagPrefix, aStr), NS_ERROR_OUT_OF_MEMORY);
|
||||
NS_ENSURE_TRUE(AppendToString(NS_LITERAL_STRING(":"), aStr), NS_ERROR_OUT_OF_MEMORY);
|
||||
}
|
||||
AppendToString(tagLocalName, aStr);
|
||||
NS_ENSURE_TRUE(AppendToString(tagLocalName, aStr), NS_ERROR_OUT_OF_MEMORY);
|
||||
|
||||
MaybeEnterInPreContent(content);
|
||||
|
||||
if ((mDoFormat || forceFormat) && !mDoRaw && !PreLevel()) {
|
||||
IncrIndentation(name);
|
||||
NS_ENSURE_TRUE(IncrIndentation(name), NS_ERROR_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
SerializeAttributes(content, aOriginalElement, tagPrefix, tagNamespaceURI,
|
||||
name, aStr, skipAttr, addNSAttr);
|
||||
NS_ENSURE_TRUE(SerializeAttributes(content, aOriginalElement, tagPrefix, tagNamespaceURI,
|
||||
name, aStr, skipAttr, addNSAttr),
|
||||
NS_ERROR_OUT_OF_MEMORY);
|
||||
|
||||
AppendEndOfElementStart(aOriginalElement, name, content->GetNameSpaceID(),
|
||||
aStr);
|
||||
NS_ENSURE_TRUE(AppendEndOfElementStart(aOriginalElement, name,
|
||||
content->GetNameSpaceID(), aStr),
|
||||
NS_ERROR_OUT_OF_MEMORY);
|
||||
|
||||
if ((mDoFormat || forceFormat) && !mDoRaw && !PreLevel()
|
||||
&& LineBreakAfterOpen(content->GetNameSpaceID(), name)) {
|
||||
AppendNewLineToString(aStr);
|
||||
NS_ENSURE_TRUE(AppendNewLineToString(aStr), NS_ERROR_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
AfterElementStart(content, aOriginalElement, aStr);
|
||||
NS_ENSURE_TRUE(AfterElementStart(content, aOriginalElement, aStr), NS_ERROR_OUT_OF_MEMORY);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
void
|
||||
bool
|
||||
nsXMLContentSerializer::AppendEndOfElementStart(nsIContent *aOriginalElement,
|
||||
nsIAtom * aName,
|
||||
int32_t aNamespaceID,
|
||||
@ -967,10 +981,10 @@ nsXMLContentSerializer::AppendEndOfElementStart(nsIContent *aOriginalElement,
|
||||
{
|
||||
// We don't output a separate end tag for empty elements
|
||||
if (!aOriginalElement->GetChildCount()) {
|
||||
AppendToString(NS_LITERAL_STRING("/>"), aStr);
|
||||
return AppendToString(NS_LITERAL_STRING("/>"), aStr);
|
||||
}
|
||||
else {
|
||||
AppendToString(kGreaterThan, aStr);
|
||||
return AppendToString(kGreaterThan, aStr);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1014,28 +1028,28 @@ nsXMLContentSerializer::AppendElementEnd(Element* aElement,
|
||||
bool lineBreakBeforeClose = LineBreakBeforeClose(content->GetNameSpaceID(), name);
|
||||
|
||||
if (mColPos && lineBreakBeforeClose) {
|
||||
AppendNewLineToString(aStr);
|
||||
NS_ENSURE_TRUE(AppendNewLineToString(aStr), NS_ERROR_OUT_OF_MEMORY);
|
||||
}
|
||||
if (!mColPos) {
|
||||
AppendIndentation(aStr);
|
||||
NS_ENSURE_TRUE(AppendIndentation(aStr), NS_ERROR_OUT_OF_MEMORY);
|
||||
}
|
||||
else if (mAddSpace) {
|
||||
AppendToString(char16_t(' '), aStr);
|
||||
NS_ENSURE_TRUE(AppendToString(char16_t(' '), aStr), NS_ERROR_OUT_OF_MEMORY);
|
||||
mAddSpace = false;
|
||||
}
|
||||
}
|
||||
else if (mAddSpace) {
|
||||
AppendToString(char16_t(' '), aStr);
|
||||
NS_ENSURE_TRUE(AppendToString(char16_t(' '), aStr), NS_ERROR_OUT_OF_MEMORY);
|
||||
mAddSpace = false;
|
||||
}
|
||||
|
||||
AppendToString(kEndTag, aStr);
|
||||
NS_ENSURE_TRUE(AppendToString(kEndTag, aStr), NS_ERROR_OUT_OF_MEMORY);
|
||||
if (!tagPrefix.IsEmpty()) {
|
||||
AppendToString(tagPrefix, aStr);
|
||||
AppendToString(NS_LITERAL_STRING(":"), aStr);
|
||||
NS_ENSURE_TRUE(AppendToString(tagPrefix, aStr), NS_ERROR_OUT_OF_MEMORY);
|
||||
NS_ENSURE_TRUE(AppendToString(NS_LITERAL_STRING(":"), aStr), NS_ERROR_OUT_OF_MEMORY);
|
||||
}
|
||||
AppendToString(tagLocalName, aStr);
|
||||
AppendToString(kGreaterThan, aStr);
|
||||
NS_ENSURE_TRUE(AppendToString(tagLocalName, aStr), NS_ERROR_OUT_OF_MEMORY);
|
||||
NS_ENSURE_TRUE(AppendToString(kGreaterThan, aStr), NS_ERROR_OUT_OF_MEMORY);
|
||||
|
||||
PopNameSpaceDeclsFor(aElement);
|
||||
|
||||
@ -1043,7 +1057,7 @@ nsXMLContentSerializer::AppendElementEnd(Element* aElement,
|
||||
|
||||
if ((mDoFormat || forceFormat) && !mDoRaw && !PreLevel()
|
||||
&& LineBreakAfterClose(content->GetNameSpaceID(), name)) {
|
||||
AppendNewLineToString(aStr);
|
||||
NS_ENSURE_TRUE(AppendNewLineToString(aStr), NS_ERROR_OUT_OF_MEMORY);
|
||||
}
|
||||
else {
|
||||
MaybeFlagNewlineForRootNode(aElement);
|
||||
@ -1086,7 +1100,7 @@ nsXMLContentSerializer::AppendDocumentStart(nsIDocument *aDocument,
|
||||
aStr += NS_LITERAL_STRING(" standalone=\"") + standalone + endQuote;
|
||||
}
|
||||
|
||||
aStr.AppendLiteral("?>");
|
||||
NS_ENSURE_TRUE(aStr.AppendLiteral("?>", mozilla::fallible), NS_ERROR_OUT_OF_MEMORY);
|
||||
mAddNewlineForRootNode = true;
|
||||
|
||||
return NS_OK;
|
||||
@ -1095,8 +1109,10 @@ nsXMLContentSerializer::AppendDocumentStart(nsIDocument *aDocument,
|
||||
bool
|
||||
nsXMLContentSerializer::CheckElementStart(nsIContent * aContent,
|
||||
bool & aForceFormat,
|
||||
nsAString& aStr)
|
||||
nsAString& aStr,
|
||||
nsresult& aResult)
|
||||
{
|
||||
aResult = NS_OK;
|
||||
aForceFormat = false;
|
||||
return true;
|
||||
}
|
||||
@ -1111,26 +1127,26 @@ nsXMLContentSerializer::CheckElementEnd(nsIContent * aContent,
|
||||
return aContent->GetChildCount() > 0;
|
||||
}
|
||||
|
||||
void
|
||||
bool
|
||||
nsXMLContentSerializer::AppendToString(const char16_t aChar,
|
||||
nsAString& aOutputStr)
|
||||
{
|
||||
if (mBodyOnly && !mInBody) {
|
||||
return;
|
||||
return true;
|
||||
}
|
||||
mColPos += 1;
|
||||
aOutputStr.Append(aChar);
|
||||
return aOutputStr.Append(aChar, mozilla::fallible);
|
||||
}
|
||||
|
||||
void
|
||||
bool
|
||||
nsXMLContentSerializer::AppendToString(const nsAString& aStr,
|
||||
nsAString& aOutputStr)
|
||||
{
|
||||
if (mBodyOnly && !mInBody) {
|
||||
return;
|
||||
return true;
|
||||
}
|
||||
mColPos += aStr.Length();
|
||||
aOutputStr.Append(aStr);
|
||||
return aOutputStr.Append(aStr, mozilla::fallible);
|
||||
}
|
||||
|
||||
|
||||
@ -1155,7 +1171,7 @@ static const char* kAttrEntities[] = {
|
||||
"<", "", ">"
|
||||
};
|
||||
|
||||
void
|
||||
bool
|
||||
nsXMLContentSerializer::AppendAndTranslateEntities(const nsAString& aStr,
|
||||
nsAString& aOutputStr)
|
||||
{
|
||||
@ -1188,20 +1204,24 @@ nsXMLContentSerializer::AppendAndTranslateEntities(const nsAString& aStr,
|
||||
}
|
||||
}
|
||||
|
||||
aOutputStr.Append(fragmentStart, advanceLength);
|
||||
NS_ENSURE_TRUE(aOutputStr.Append(fragmentStart, advanceLength, mozilla::fallible), false);
|
||||
if (entityText) {
|
||||
AppendASCIItoUTF16(entityText, aOutputStr);
|
||||
NS_ENSURE_TRUE(AppendASCIItoUTF16(entityText, aOutputStr, mozilla::fallible), false);
|
||||
advanceLength++;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void
|
||||
bool
|
||||
nsXMLContentSerializer::MaybeAddNewlineForRootNode(nsAString& aStr)
|
||||
{
|
||||
if (mAddNewlineForRootNode) {
|
||||
AppendNewLineToString(aStr);
|
||||
return AppendNewLineToString(aStr);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void
|
||||
@ -1239,26 +1259,28 @@ nsXMLContentSerializer::MaybeLeaveFromPreContent(nsIContent* aNode)
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
bool
|
||||
nsXMLContentSerializer::AppendNewLineToString(nsAString& aStr)
|
||||
{
|
||||
AppendToString(mLineBreak, aStr);
|
||||
bool result = AppendToString(mLineBreak, aStr);
|
||||
mMayIgnoreLineBreakSequence = true;
|
||||
mColPos = 0;
|
||||
mAddSpace = false;
|
||||
mIsIndentationAddedOnCurrentLine = false;
|
||||
return result;
|
||||
}
|
||||
|
||||
void
|
||||
bool
|
||||
nsXMLContentSerializer::AppendIndentation(nsAString& aStr)
|
||||
{
|
||||
mIsIndentationAddedOnCurrentLine = true;
|
||||
AppendToString(mIndent, aStr);
|
||||
bool result = AppendToString(mIndent, aStr);
|
||||
mAddSpace = false;
|
||||
mMayIgnoreLineBreakSequence = false;
|
||||
return result;
|
||||
}
|
||||
|
||||
void
|
||||
bool
|
||||
nsXMLContentSerializer::IncrIndentation(nsIAtom* aName)
|
||||
{
|
||||
// we want to keep the source readable
|
||||
@ -1267,8 +1289,10 @@ nsXMLContentSerializer::IncrIndentation(nsIAtom* aName)
|
||||
++mIndentOverflow;
|
||||
}
|
||||
else {
|
||||
mIndent.AppendLiteral(INDENT_STRING);
|
||||
return mIndent.AppendLiteral(INDENT_STRING, mozilla::fallible);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void
|
||||
@ -1304,16 +1328,16 @@ nsXMLContentSerializer::LineBreakAfterClose(int32_t aNamespaceID, nsIAtom* aName
|
||||
return false;
|
||||
}
|
||||
|
||||
void
|
||||
bool
|
||||
nsXMLContentSerializer::AppendToStringConvertLF(const nsAString& aStr,
|
||||
nsAString& aOutputStr)
|
||||
{
|
||||
if (mBodyOnly && !mInBody) {
|
||||
return;
|
||||
return true;
|
||||
}
|
||||
|
||||
if (mDoRaw) {
|
||||
AppendToString(aStr, aOutputStr);
|
||||
NS_ENSURE_TRUE(AppendToString(aStr, aOutputStr), false);
|
||||
}
|
||||
else {
|
||||
// Convert line-endings to mLineBreak
|
||||
@ -1323,7 +1347,7 @@ nsXMLContentSerializer::AppendToStringConvertLF(const nsAString& aStr,
|
||||
int32_t eol = aStr.FindChar('\n', start);
|
||||
if (eol == kNotFound) {
|
||||
nsDependentSubstring dataSubstring(aStr, start, theLen - start);
|
||||
AppendToString(dataSubstring, aOutputStr);
|
||||
NS_ENSURE_TRUE(AppendToString(dataSubstring, aOutputStr), false);
|
||||
start = theLen;
|
||||
// if there was a line break before this substring
|
||||
// AppendNewLineToString was called, so we should reverse
|
||||
@ -1332,15 +1356,17 @@ nsXMLContentSerializer::AppendToStringConvertLF(const nsAString& aStr,
|
||||
}
|
||||
else {
|
||||
nsDependentSubstring dataSubstring(aStr, start, eol - start);
|
||||
AppendToString(dataSubstring, aOutputStr);
|
||||
AppendNewLineToString(aOutputStr);
|
||||
NS_ENSURE_TRUE(AppendToString(dataSubstring, aOutputStr), false);
|
||||
NS_ENSURE_TRUE(AppendNewLineToString(aOutputStr), false);
|
||||
start = eol + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void
|
||||
bool
|
||||
nsXMLContentSerializer::AppendFormatedWrapped_WhitespaceSequence(
|
||||
nsASingleFragmentString::const_char_iterator &aPos,
|
||||
const nsASingleFragmentString::const_char_iterator aEnd,
|
||||
@ -1393,10 +1419,11 @@ nsXMLContentSerializer::AppendFormatedWrapped_WhitespaceSequence(
|
||||
if (mDoWrap && mColPos + 1 >= mMaxColumn) {
|
||||
// no much sense in delaying, we only have one slot left,
|
||||
// let's write a break now
|
||||
aOutputStr.Append(mLineBreak);
|
||||
bool result = aOutputStr.Append(mLineBreak, mozilla::fallible);
|
||||
mColPos = 0;
|
||||
mIsIndentationAddedOnCurrentLine = false;
|
||||
mMayIgnoreLineBreakSequence = true;
|
||||
NS_ENSURE_TRUE(result, false);
|
||||
}
|
||||
else {
|
||||
// do not write out yet, we may write out either a space or a linebreak
|
||||
@ -1410,12 +1437,14 @@ nsXMLContentSerializer::AppendFormatedWrapped_WhitespaceSequence(
|
||||
// transform a linebreak into a space.
|
||||
// Since we only saw linebreaks, but no spaces or tabs,
|
||||
// let's write a linebreak now.
|
||||
AppendNewLineToString(aOutputStr);
|
||||
NS_ENSURE_TRUE(AppendNewLineToString(aOutputStr), false);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void
|
||||
bool
|
||||
nsXMLContentSerializer::AppendWrapped_NonWhitespaceSequence(
|
||||
nsASingleFragmentString::const_char_iterator &aPos,
|
||||
const nsASingleFragmentString::const_char_iterator aEnd,
|
||||
@ -1476,15 +1505,16 @@ nsXMLContentSerializer::AppendWrapped_NonWhitespaceSequence(
|
||||
if (aPos == aEnd || foundWhitespaceInLoop) {
|
||||
// there is enough room for the complete block we found
|
||||
if (mDoFormat && !mColPos) {
|
||||
AppendIndentation(aOutputStr);
|
||||
NS_ENSURE_TRUE(AppendIndentation(aOutputStr), false);
|
||||
}
|
||||
else if (mAddSpace) {
|
||||
aOutputStr.Append(char16_t(' '));
|
||||
bool result = aOutputStr.Append(char16_t(' '), mozilla::fallible);
|
||||
mAddSpace = false;
|
||||
NS_ENSURE_TRUE(result, false);
|
||||
}
|
||||
|
||||
mColPos += length;
|
||||
aOutputStr.Append(aSequenceStart, aPos - aSequenceStart);
|
||||
NS_ENSURE_TRUE(aOutputStr.Append(aSequenceStart, aPos - aSequenceStart, mozilla::fallible), false);
|
||||
|
||||
// We have not yet reached the max column, we will continue to
|
||||
// fill the current line in the next outer loop iteration
|
||||
@ -1501,7 +1531,7 @@ nsXMLContentSerializer::AppendWrapped_NonWhitespaceSequence(
|
||||
// We can avoid to wrap. We try to add the whole block
|
||||
// in an empty new line
|
||||
|
||||
AppendNewLineToString(aOutputStr);
|
||||
NS_ENSURE_TRUE(AppendNewLineToString(aOutputStr), false);
|
||||
aPos = aSequenceStart;
|
||||
thisSequenceStartsAtBeginningOfLine = true;
|
||||
onceAgainBecauseWeAddedBreakInFront = true;
|
||||
@ -1531,15 +1561,16 @@ nsXMLContentSerializer::AppendWrapped_NonWhitespaceSequence(
|
||||
|
||||
if (foundWrapPosition) {
|
||||
if (!mColPos && mDoFormat) {
|
||||
AppendIndentation(aOutputStr);
|
||||
NS_ENSURE_TRUE(AppendIndentation(aOutputStr), false);
|
||||
}
|
||||
else if (mAddSpace) {
|
||||
aOutputStr.Append(char16_t(' '));
|
||||
bool result = aOutputStr.Append(char16_t(' '), mozilla::fallible);
|
||||
mAddSpace = false;
|
||||
NS_ENSURE_TRUE(result, false);
|
||||
}
|
||||
aOutputStr.Append(aSequenceStart, wrapPosition);
|
||||
NS_ENSURE_TRUE(aOutputStr.Append(aSequenceStart, wrapPosition, mozilla::fallible), false);
|
||||
|
||||
AppendNewLineToString(aOutputStr);
|
||||
NS_ENSURE_TRUE(AppendNewLineToString(aOutputStr), false);
|
||||
aPos = aSequenceStart + wrapPosition;
|
||||
aMayIgnoreStartOfLineWhitespaceSequence = true;
|
||||
}
|
||||
@ -1563,23 +1594,26 @@ nsXMLContentSerializer::AppendWrapped_NonWhitespaceSequence(
|
||||
} while (aPos < aEnd);
|
||||
|
||||
if (mAddSpace) {
|
||||
aOutputStr.Append(char16_t(' '));
|
||||
bool result = aOutputStr.Append(char16_t(' '), mozilla::fallible);
|
||||
mAddSpace = false;
|
||||
NS_ENSURE_TRUE(result, false);
|
||||
}
|
||||
aOutputStr.Append(aSequenceStart, aPos - aSequenceStart);
|
||||
NS_ENSURE_TRUE(aOutputStr.Append(aSequenceStart, aPos - aSequenceStart, mozilla::fallible), false);
|
||||
}
|
||||
}
|
||||
aSequenceStartAfterAWhiteSpace = false;
|
||||
}
|
||||
} while (onceAgainBecauseWeAddedBreakInFront);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void
|
||||
bool
|
||||
nsXMLContentSerializer::AppendToStringFormatedWrapped(const nsASingleFragmentString& aStr,
|
||||
nsAString& aOutputStr)
|
||||
{
|
||||
if (mBodyOnly && !mInBody) {
|
||||
return;
|
||||
return true;
|
||||
}
|
||||
|
||||
nsASingleFragmentString::const_char_iterator pos, end, sequenceStart;
|
||||
@ -1609,17 +1643,20 @@ nsXMLContentSerializer::AppendToStringFormatedWrapped(const nsASingleFragmentStr
|
||||
|
||||
// if beginning of a whitespace sequence
|
||||
if (*pos == ' ' || *pos == '\n' || *pos == '\t') {
|
||||
AppendFormatedWrapped_WhitespaceSequence(pos, end, sequenceStart,
|
||||
mayIgnoreStartOfLineWhitespaceSequence, aOutputStr);
|
||||
NS_ENSURE_TRUE(AppendFormatedWrapped_WhitespaceSequence(pos, end, sequenceStart,
|
||||
mayIgnoreStartOfLineWhitespaceSequence, aOutputStr), false);
|
||||
}
|
||||
else { // any other non-whitespace char
|
||||
AppendWrapped_NonWhitespaceSequence(pos, end, sequenceStart,
|
||||
mayIgnoreStartOfLineWhitespaceSequence, sequenceStartAfterAWhitespace, aOutputStr);
|
||||
NS_ENSURE_TRUE(AppendWrapped_NonWhitespaceSequence(pos, end, sequenceStart,
|
||||
mayIgnoreStartOfLineWhitespaceSequence, sequenceStartAfterAWhitespace,
|
||||
aOutputStr), false);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void
|
||||
bool
|
||||
nsXMLContentSerializer::AppendWrapped_WhitespaceSequence(
|
||||
nsASingleFragmentString::const_char_iterator &aPos,
|
||||
const nsASingleFragmentString::const_char_iterator aEnd,
|
||||
@ -1642,9 +1679,9 @@ nsXMLContentSerializer::AppendWrapped_WhitespaceSequence(
|
||||
// if there are too many spaces on a line, we wrap
|
||||
if (mColPos >= mMaxColumn) {
|
||||
if (lastPos != aPos) {
|
||||
aOutputStr.Append(lastPos, aPos - lastPos);
|
||||
NS_ENSURE_TRUE(aOutputStr.Append(lastPos, aPos - lastPos, mozilla::fallible), false);
|
||||
}
|
||||
AppendToString(mLineBreak, aOutputStr);
|
||||
NS_ENSURE_TRUE(AppendToString(mLineBreak, aOutputStr), false);
|
||||
mColPos = 0;
|
||||
lastPos = aPos;
|
||||
}
|
||||
@ -1654,9 +1691,9 @@ nsXMLContentSerializer::AppendWrapped_WhitespaceSequence(
|
||||
break;
|
||||
case '\n':
|
||||
if (lastPos != aPos) {
|
||||
aOutputStr.Append(lastPos, aPos - lastPos);
|
||||
NS_ENSURE_TRUE(aOutputStr.Append(lastPos, aPos - lastPos, mozilla::fallible), false);
|
||||
}
|
||||
AppendToString(mLineBreak, aOutputStr);
|
||||
NS_ENSURE_TRUE(AppendToString(mLineBreak, aOutputStr), false);
|
||||
mColPos = 0;
|
||||
++aPos;
|
||||
lastPos = aPos;
|
||||
@ -1668,16 +1705,18 @@ nsXMLContentSerializer::AppendWrapped_WhitespaceSequence(
|
||||
} while (!leaveLoop && aPos < aEnd);
|
||||
|
||||
if (lastPos != aPos) {
|
||||
aOutputStr.Append(lastPos, aPos - lastPos);
|
||||
NS_ENSURE_TRUE(aOutputStr.Append(lastPos, aPos - lastPos, mozilla::fallible), false);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void
|
||||
bool
|
||||
nsXMLContentSerializer::AppendToStringWrapped(const nsASingleFragmentString& aStr,
|
||||
nsAString& aOutputStr)
|
||||
{
|
||||
if (mBodyOnly && !mInBody) {
|
||||
return;
|
||||
return true;
|
||||
}
|
||||
|
||||
nsASingleFragmentString::const_char_iterator pos, end, sequenceStart;
|
||||
@ -1705,13 +1744,17 @@ nsXMLContentSerializer::AppendToStringWrapped(const nsASingleFragmentString& aSt
|
||||
// if beginning of a whitespace sequence
|
||||
if (*pos == ' ' || *pos == '\n' || *pos == '\t') {
|
||||
sequenceStartAfterAWhitespace = true;
|
||||
AppendWrapped_WhitespaceSequence(pos, end, sequenceStart, aOutputStr);
|
||||
NS_ENSURE_TRUE(AppendWrapped_WhitespaceSequence(pos, end,
|
||||
sequenceStart, aOutputStr), false);
|
||||
}
|
||||
else { // any other non-whitespace char
|
||||
AppendWrapped_NonWhitespaceSequence(pos, end, sequenceStart,
|
||||
mayIgnoreStartOfLineWhitespaceSequence, sequenceStartAfterAWhitespace, aOutputStr);
|
||||
NS_ENSURE_TRUE(AppendWrapped_NonWhitespaceSequence(pos, end, sequenceStart,
|
||||
mayIgnoreStartOfLineWhitespaceSequence,
|
||||
sequenceStartAfterAWhitespace, aOutputStr), false);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
|
@ -72,13 +72,15 @@ class nsXMLContentSerializer : public nsIContentSerializer {
|
||||
/**
|
||||
* Appends a char16_t character and increments the column position
|
||||
*/
|
||||
void AppendToString(const char16_t aChar,
|
||||
NS_WARN_UNUSED_RESULT
|
||||
bool AppendToString(const char16_t aChar,
|
||||
nsAString& aOutputStr);
|
||||
|
||||
/**
|
||||
* Appends a nsAString string and increments the column position
|
||||
*/
|
||||
void AppendToString(const nsAString& aStr,
|
||||
NS_WARN_UNUSED_RESULT
|
||||
bool AppendToString(const nsAString& aStr,
|
||||
nsAString& aOutputStr);
|
||||
|
||||
/**
|
||||
@ -86,32 +88,37 @@ class nsXMLContentSerializer : public nsIContentSerializer {
|
||||
* by mLineBreak, except in the case of raw output.
|
||||
* It increments the column position.
|
||||
*/
|
||||
void AppendToStringConvertLF(const nsAString& aStr,
|
||||
NS_WARN_UNUSED_RESULT
|
||||
bool AppendToStringConvertLF(const nsAString& aStr,
|
||||
nsAString& aOutputStr);
|
||||
|
||||
/**
|
||||
* Appends a string by wrapping it when necessary.
|
||||
* It updates the column position.
|
||||
*/
|
||||
void AppendToStringWrapped(const nsASingleFragmentString& aStr,
|
||||
NS_WARN_UNUSED_RESULT
|
||||
bool AppendToStringWrapped(const nsASingleFragmentString& aStr,
|
||||
nsAString& aOutputStr);
|
||||
|
||||
/**
|
||||
* Appends a string by formating and wrapping it when necessary
|
||||
* It updates the column position.
|
||||
*/
|
||||
void AppendToStringFormatedWrapped(const nsASingleFragmentString& aStr,
|
||||
NS_WARN_UNUSED_RESULT
|
||||
bool AppendToStringFormatedWrapped(const nsASingleFragmentString& aStr,
|
||||
nsAString& aOutputStr);
|
||||
|
||||
// used by AppendToStringWrapped
|
||||
void AppendWrapped_WhitespaceSequence(
|
||||
NS_WARN_UNUSED_RESULT
|
||||
bool AppendWrapped_WhitespaceSequence(
|
||||
nsASingleFragmentString::const_char_iterator &aPos,
|
||||
const nsASingleFragmentString::const_char_iterator aEnd,
|
||||
const nsASingleFragmentString::const_char_iterator aSequenceStart,
|
||||
nsAString &aOutputStr);
|
||||
|
||||
// used by AppendToStringFormatedWrapped
|
||||
void AppendFormatedWrapped_WhitespaceSequence(
|
||||
NS_WARN_UNUSED_RESULT
|
||||
bool AppendFormatedWrapped_WhitespaceSequence(
|
||||
nsASingleFragmentString::const_char_iterator &aPos,
|
||||
const nsASingleFragmentString::const_char_iterator aEnd,
|
||||
const nsASingleFragmentString::const_char_iterator aSequenceStart,
|
||||
@ -119,7 +126,8 @@ class nsXMLContentSerializer : public nsIContentSerializer {
|
||||
nsAString &aOutputStr);
|
||||
|
||||
// used by AppendToStringWrapped and AppendToStringFormatedWrapped
|
||||
void AppendWrapped_NonWhitespaceSequence(
|
||||
NS_WARN_UNUSED_RESULT
|
||||
bool AppendWrapped_NonWhitespaceSequence(
|
||||
nsASingleFragmentString::const_char_iterator &aPos,
|
||||
const nsASingleFragmentString::const_char_iterator aEnd,
|
||||
const nsASingleFragmentString::const_char_iterator aSequenceStart,
|
||||
@ -131,14 +139,16 @@ class nsXMLContentSerializer : public nsIContentSerializer {
|
||||
* add mLineBreak to the string
|
||||
* It updates the column position and other flags.
|
||||
*/
|
||||
void AppendNewLineToString(nsAString& aOutputStr);
|
||||
NS_WARN_UNUSED_RESULT
|
||||
bool AppendNewLineToString(nsAString& aOutputStr);
|
||||
|
||||
|
||||
/**
|
||||
* Appends a string by translating entities
|
||||
* It doesn't increment the column position
|
||||
*/
|
||||
virtual void AppendAndTranslateEntities(const nsAString& aStr,
|
||||
NS_WARN_UNUSED_RESULT
|
||||
virtual bool AppendAndTranslateEntities(const nsAString& aStr,
|
||||
nsAString& aOutputStr);
|
||||
|
||||
/**
|
||||
@ -187,7 +197,8 @@ class nsXMLContentSerializer : public nsIContentSerializer {
|
||||
nsIContent *aOriginalElement,
|
||||
const nsAString& aTagNamespaceURI);
|
||||
|
||||
virtual void SerializeAttributes(nsIContent* aContent,
|
||||
NS_WARN_UNUSED_RESULT
|
||||
virtual bool SerializeAttributes(nsIContent* aContent,
|
||||
nsIContent *aOriginalElement,
|
||||
nsAString& aTagPrefix,
|
||||
const nsAString& aTagNamespaceURI,
|
||||
@ -196,7 +207,8 @@ class nsXMLContentSerializer : public nsIContentSerializer {
|
||||
uint32_t aSkipAttr,
|
||||
bool aAddNSAttr);
|
||||
|
||||
void SerializeAttr(const nsAString& aPrefix,
|
||||
NS_WARN_UNUSED_RESULT
|
||||
bool SerializeAttr(const nsAString& aPrefix,
|
||||
const nsAString& aName,
|
||||
const nsAString& aValue,
|
||||
nsAString& aStr,
|
||||
@ -217,13 +229,15 @@ class nsXMLContentSerializer : public nsIContentSerializer {
|
||||
*/
|
||||
virtual bool CheckElementStart(nsIContent * aContent,
|
||||
bool & aForceFormat,
|
||||
nsAString& aStr);
|
||||
nsAString& aStr,
|
||||
nsresult& aResult);
|
||||
|
||||
/**
|
||||
* this method is responsible to finish the start tag,
|
||||
* in particulary to append the "greater than" sign
|
||||
*/
|
||||
virtual void AppendEndOfElementStart(nsIContent *aOriginalElement,
|
||||
NS_WARN_UNUSED_RESULT
|
||||
virtual bool AppendEndOfElementStart(nsIContent *aOriginalElement,
|
||||
nsIAtom * aName,
|
||||
int32_t aNamespaceID,
|
||||
nsAString& aStr);
|
||||
@ -233,9 +247,10 @@ class nsXMLContentSerializer : public nsIContentSerializer {
|
||||
* after the serialization ot the start tag.
|
||||
* (called at the end of AppendElementStart)
|
||||
*/
|
||||
virtual void AfterElementStart(nsIContent * aContent,
|
||||
nsIContent *aOriginalElement,
|
||||
nsAString& aStr) { };
|
||||
NS_WARN_UNUSED_RESULT
|
||||
virtual bool AfterElementStart(nsIContent* aContent,
|
||||
nsIContent* aOriginalElement,
|
||||
nsAString& aStr) { return true; };
|
||||
|
||||
/**
|
||||
* This method can be redefined to check if the element can be serialized.
|
||||
@ -281,13 +296,17 @@ class nsXMLContentSerializer : public nsIContentSerializer {
|
||||
* add intendation. Call only in the case of formating and if the current
|
||||
* position is at 0. It updates the column position.
|
||||
*/
|
||||
void AppendIndentation(nsAString& aStr);
|
||||
void IncrIndentation(nsIAtom* aName);
|
||||
NS_WARN_UNUSED_RESULT
|
||||
bool AppendIndentation(nsAString& aStr);
|
||||
|
||||
NS_WARN_UNUSED_RESULT
|
||||
bool IncrIndentation(nsIAtom* aName);
|
||||
void DecrIndentation(nsIAtom* aName);
|
||||
|
||||
// Functions to check for newlines that needs to be added between nodes in
|
||||
// the root of a document. See mAddNewlineForRootNode
|
||||
void MaybeAddNewlineForRootNode(nsAString& aStr);
|
||||
NS_WARN_UNUSED_RESULT
|
||||
bool MaybeAddNewlineForRootNode(nsAString& aStr);
|
||||
void MaybeFlagNewlineForRootNode(nsINode* aNode);
|
||||
|
||||
// Functions to check if we enter in or leave from a preformated content
|
||||
|
@ -146,6 +146,16 @@ LossyAppendUTF16toASCII(const char16_t* aSource, nsACString& aDest)
|
||||
}
|
||||
}
|
||||
|
||||
bool
|
||||
AppendASCIItoUTF16(const char* aSource, nsAString& aDest, const mozilla::fallible_t& aFallible)
|
||||
{
|
||||
if (aSource) {
|
||||
return AppendASCIItoUTF16(nsDependentCString(aSource), aDest, aFallible);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void
|
||||
AppendASCIItoUTF16(const char* aSource, nsAString& aDest)
|
||||
{
|
||||
|
@ -55,6 +55,9 @@ NS_WARN_UNUSED_RESULT bool AppendASCIItoUTF16(const nsACString& aSource,
|
||||
const mozilla::fallible_t&);
|
||||
|
||||
void LossyAppendUTF16toASCII(const char16_t* aSource, nsACString& aDest);
|
||||
NS_WARN_UNUSED_RESULT bool AppendASCIItoUTF16(const char* aSource,
|
||||
nsAString& aDest,
|
||||
const mozilla::fallible_t&);
|
||||
void AppendASCIItoUTF16(const char* aSource, nsAString& aDest);
|
||||
|
||||
void AppendUTF16toUTF8(const nsAString& aSource, nsACString& aDest);
|
||||
|
@ -545,6 +545,16 @@ nsTSubstring_CharT::Replace(index_type aCutStart, size_type aCutLength,
|
||||
void
|
||||
nsTSubstring_CharT::ReplaceASCII(index_type aCutStart, size_type aCutLength,
|
||||
const char* aData, size_type aLength)
|
||||
{
|
||||
if (!ReplaceASCII(aCutStart, aCutLength, aData, aLength, mozilla::fallible)) {
|
||||
AllocFailed(Length() - aCutLength + 1);
|
||||
}
|
||||
}
|
||||
|
||||
bool
|
||||
nsTSubstring_CharT::ReplaceASCII(index_type aCutStart, size_type aCutLength,
|
||||
const char* aData, size_type aLength,
|
||||
const fallible_t& aFallible)
|
||||
{
|
||||
if (aLength == size_type(-1)) {
|
||||
aLength = strlen(aData);
|
||||
@ -555,16 +565,22 @@ nsTSubstring_CharT::ReplaceASCII(index_type aCutStart, size_type aCutLength,
|
||||
#ifdef CharT_is_char
|
||||
if (IsDependentOn(aData, aData + aLength)) {
|
||||
nsTAutoString_CharT temp(aData, aLength);
|
||||
Replace(aCutStart, aCutLength, temp);
|
||||
return;
|
||||
return Replace(aCutStart, aCutLength, temp, aFallible);
|
||||
}
|
||||
#endif
|
||||
|
||||
aCutStart = XPCOM_MIN(aCutStart, Length());
|
||||
|
||||
if (ReplacePrep(aCutStart, aCutLength, aLength) && aLength > 0) {
|
||||
bool ok = ReplacePrep(aCutStart, aCutLength, aLength);
|
||||
if (!ok) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (aLength > 0) {
|
||||
char_traits::copyASCII(mData + aCutStart, aData, aLength);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -504,6 +504,11 @@ public:
|
||||
const char* aData,
|
||||
size_type aLength = size_type(-1));
|
||||
|
||||
NS_WARN_UNUSED_RESULT bool NS_FASTCALL ReplaceASCII(index_type aCutStart, size_type aCutLength,
|
||||
const char* aData,
|
||||
size_type aLength,
|
||||
const fallible_t&);
|
||||
|
||||
// ReplaceLiteral must ONLY be applied to an actual literal string.
|
||||
// Do not attempt to use it with a regular char* pointer, or with a char
|
||||
// array variable. Use Replace or ReplaceASCII for those.
|
||||
@ -544,6 +549,10 @@ public:
|
||||
{
|
||||
Replace(mLength, 0, aStr);
|
||||
}
|
||||
NS_WARN_UNUSED_RESULT bool Append(const self_type& aStr, const fallible_t& aFallible)
|
||||
{
|
||||
return Replace(mLength, 0, aStr, aFallible);
|
||||
}
|
||||
void Append(const substring_tuple_type& aTuple)
|
||||
{
|
||||
Replace(mLength, 0, aTuple);
|
||||
@ -554,6 +563,16 @@ public:
|
||||
ReplaceASCII(mLength, 0, aData, aLength);
|
||||
}
|
||||
|
||||
NS_WARN_UNUSED_RESULT bool AppendASCII(const char* aData, const fallible_t& aFallible)
|
||||
{
|
||||
return ReplaceASCII(mLength, 0, aData, size_type(-1), aFallible);
|
||||
}
|
||||
|
||||
NS_WARN_UNUSED_RESULT bool AppendASCII(const char* aData, size_type aLength, const fallible_t& aFallible)
|
||||
{
|
||||
return ReplaceASCII(mLength, 0, aData, aLength, aFallible);
|
||||
}
|
||||
|
||||
/**
|
||||
* Append a formatted string to the current string. Uses the format
|
||||
* codes documented in prprf.h
|
||||
@ -618,6 +637,12 @@ public:
|
||||
{
|
||||
AppendASCII(aStr, N - 1);
|
||||
}
|
||||
|
||||
template<int N>
|
||||
NS_WARN_UNUSED_RESULT bool AppendLiteral(const char (&aStr)[N], const fallible_t& aFallible)
|
||||
{
|
||||
return AppendASCII(aStr, N - 1, aFallible);
|
||||
}
|
||||
#endif
|
||||
|
||||
self_type& operator+=(char_type aChar)
|
||||
|
Loading…
Reference in New Issue
Block a user