diff --git a/content/base/public/nsIContentSerializer.h b/content/base/public/nsIContentSerializer.h index 6731ece4f9c..367c0ba94b1 100644 --- a/content/base/public/nsIContentSerializer.h +++ b/content/base/public/nsIContentSerializer.h @@ -52,8 +52,8 @@ class nsAString; /* starting interface: nsIContentSerializer */ #define NS_ICONTENTSERIALIZER_IID \ -{ 0x0921afbc, 0x4c6f, 0x4249, \ - { 0xa7, 0xf5, 0x32, 0xe4, 0x91, 0xbf, 0x6e, 0x32 } } +{ 0x34769de0, 0x30d0, 0x4cef, \ + { 0x89, 0x4a, 0xfc, 0xd8, 0xbb, 0x27, 0xc4, 0xb4 } } class nsIContentSerializer : public nsISupports { public: @@ -61,7 +61,8 @@ class nsIContentSerializer : public nsISupports { NS_DECLARE_STATIC_IID_ACCESSOR(NS_ICONTENTSERIALIZER_IID) NS_IMETHOD Init(PRUint32 flags, PRUint32 aWrapColumn, - const char* aCharSet, PRBool aIsCopying) = 0; + const char* aCharSet, PRBool aIsCopying, + PRBool aIsWholeDocument) = 0; NS_IMETHOD AppendText(nsIDOMText* aText, PRInt32 aStartOffset, PRInt32 aEndOffset, nsAString& aStr) = 0; diff --git a/content/base/src/mozSanitizingSerializer.cpp b/content/base/src/mozSanitizingSerializer.cpp index 53359478541..74eece9a397 100644 --- a/content/base/src/mozSanitizingSerializer.cpp +++ b/content/base/src/mozSanitizingSerializer.cpp @@ -126,7 +126,8 @@ NS_IMPL_ISUPPORTS4(mozSanitizingHTMLSerializer, NS_IMETHODIMP mozSanitizingHTMLSerializer::Init(PRUint32 aFlags, PRUint32 dummy, - const char* aCharSet, PRBool aIsCopying) + const char* aCharSet, PRBool aIsCopying, + PRBool aIsWholeDocument) { NS_ENSURE_TRUE(nsContentUtils::GetParserService(), NS_ERROR_UNEXPECTED); @@ -138,7 +139,7 @@ mozSanitizingHTMLSerializer::Initialize(nsAString* aOutString, PRUint32 aFlags, const nsAString& allowedTags) { - nsresult rv = Init(aFlags, 0, nsnull, PR_FALSE); + nsresult rv = Init(aFlags, 0, nsnull, PR_FALSE, PR_FALSE); NS_ENSURE_SUCCESS(rv, rv); // XXX This is wrong. It violates XPCOM string ownership rules. diff --git a/content/base/src/mozSanitizingSerializer.h b/content/base/src/mozSanitizingSerializer.h index ca15f415c00..6b3473eb6f9 100644 --- a/content/base/src/mozSanitizingSerializer.h +++ b/content/base/src/mozSanitizingSerializer.h @@ -72,7 +72,7 @@ public: // nsIContentSerializer NS_IMETHOD Init(PRUint32 flags, PRUint32 dummy, const char* aCharSet, - PRBool aIsCopying); + PRBool aIsCopying, PRBool aIsWholeDocument); NS_IMETHOD AppendText(nsIDOMText* aText, PRInt32 aStartOffset, PRInt32 aEndOffset, nsAString& aStr); diff --git a/content/base/src/nsDocumentEncoder.cpp b/content/base/src/nsDocumentEncoder.cpp index 120f7a1263b..43ea060e106 100644 --- a/content/base/src/nsDocumentEncoder.cpp +++ b/content/base/src/nsDocumentEncoder.cpp @@ -893,7 +893,9 @@ nsDocumentEncoder::EncodeToString(nsAString& aOutputString) NS_ENSURE_SUCCESS(rv, rv); } } - mSerializer->Init(mFlags, mWrapColumn, mCharset.get(), mIsCopying); + + PRBool isWholeDocument = !(mSelection || mRange || mNode); + mSerializer->Init(mFlags, mWrapColumn, mCharset.get(), mIsCopying, isWholeDocument); if (mSelection) { nsCOMPtr range; diff --git a/content/base/src/nsHTMLContentSerializer.cpp b/content/base/src/nsHTMLContentSerializer.cpp index 0eae3d73886..8ec31220fe5 100644 --- a/content/base/src/nsHTMLContentSerializer.cpp +++ b/content/base/src/nsHTMLContentSerializer.cpp @@ -93,6 +93,7 @@ nsHTMLContentSerializer::nsHTMLContentSerializer() mInBody(PR_FALSE), mAddSpace(PR_FALSE), mMayIgnoreLineBreakSequence(PR_FALSE), + mIsWholeDocument(PR_FALSE), mInCDATA(PR_FALSE), mNeedLineBreaker(PR_TRUE) { @@ -112,7 +113,8 @@ nsHTMLContentSerializer::~nsHTMLContentSerializer() NS_IMETHODIMP nsHTMLContentSerializer::Init(PRUint32 aFlags, PRUint32 aWrapColumn, - const char* aCharSet, PRBool aIsCopying) + const char* aCharSet, PRBool aIsCopying, + PRBool aIsWholeDocument) { mFlags = aFlags; if (!aWrapColumn) { @@ -122,6 +124,7 @@ nsHTMLContentSerializer::Init(PRUint32 aFlags, PRUint32 aWrapColumn, mMaxColumn = aWrapColumn; } + mIsWholeDocument = aIsWholeDocument; mIsCopying = aIsCopying; mIsFirstChildOfOL = PR_FALSE; mDoFormat = (mFlags & nsIDocumentEncoder::OutputFormatted) ? PR_TRUE @@ -636,7 +639,7 @@ nsHTMLContentSerializer::AppendElementStart(nsIDOMElement *aElement, // We need too skip any meta tags that set the content type // becase we set our own later. - if (name == nsGkAtoms::meta) { + if (mIsWholeDocument && name == nsGkAtoms::meta) { nsAutoString header; content->GetAttr(kNameSpaceID_None, nsGkAtoms::httpEquiv, header); if (header.LowerCaseEqualsLiteral("content-type")) { @@ -738,7 +741,7 @@ nsHTMLContentSerializer::AppendElementStart(nsIDOMElement *aElement, mInCDATA = PR_TRUE; } - if (name == nsGkAtoms::head) { + if (mIsWholeDocument && name == nsGkAtoms::head) { AppendToString(mLineBreak, aStr); AppendToString(NS_LITERAL_STRING("Tag(); // So that we don't mess up the line breaks. - if (name == nsGkAtoms::meta) { + if (mIsWholeDocument && name == nsGkAtoms::meta) { nsAutoString header; content->GetAttr(kNameSpaceID_None, nsGkAtoms::httpEquiv, header); if (header.LowerCaseEqualsLiteral("content-type")) { diff --git a/content/base/src/nsHTMLContentSerializer.h b/content/base/src/nsHTMLContentSerializer.h index 94c9d2c256a..8cf89f2e880 100644 --- a/content/base/src/nsHTMLContentSerializer.h +++ b/content/base/src/nsHTMLContentSerializer.h @@ -58,7 +58,8 @@ class nsHTMLContentSerializer : public nsXMLContentSerializer { virtual ~nsHTMLContentSerializer(); NS_IMETHOD Init(PRUint32 flags, PRUint32 aWrapColumn, - const char* aCharSet, PRBool aIsCopying); + const char* aCharSet, PRBool aIsCopying, + PRBool aIsWholeDocument); NS_IMETHOD AppendText(nsIDOMText* aText, PRInt32 aStartOffset, @@ -139,6 +140,10 @@ class nsHTMLContentSerializer : public nsXMLContentSerializer { PRPackedBool mAddSpace; PRPackedBool mMayIgnoreLineBreakSequence; + // This is to ensure that we only do meta tag fixups when dealing with + // whole documents. + PRPackedBool mIsWholeDocument; + // To keep track of First LI child of OL in selected range PRPackedBool mIsFirstChildOfOL; PRInt32 mPreLevel; diff --git a/content/base/src/nsPlainTextSerializer.cpp b/content/base/src/nsPlainTextSerializer.cpp index ff512b5e27e..ef3146520a7 100644 --- a/content/base/src/nsPlainTextSerializer.cpp +++ b/content/base/src/nsPlainTextSerializer.cpp @@ -149,7 +149,8 @@ NS_IMPL_ISUPPORTS4(nsPlainTextSerializer, NS_IMETHODIMP nsPlainTextSerializer::Init(PRUint32 aFlags, PRUint32 aWrapColumn, - const char* aCharSet, PRBool aIsCopying) + const char* aCharSet, PRBool aIsCopying, + PRBool aIsWholeDocument) { #ifdef DEBUG // Check if the major control flags are set correctly. @@ -274,7 +275,7 @@ NS_IMETHODIMP nsPlainTextSerializer::Initialize(nsAString* aOutString, PRUint32 aFlags, PRUint32 aWrapCol) { - nsresult rv = Init(aFlags, aWrapCol, nsnull, PR_FALSE); + nsresult rv = Init(aFlags, aWrapCol, nsnull, PR_FALSE, PR_FALSE); NS_ENSURE_SUCCESS(rv, rv); // XXX This is wrong. It violates XPCOM string ownership rules. diff --git a/content/base/src/nsPlainTextSerializer.h b/content/base/src/nsPlainTextSerializer.h index c46f267404a..cccf5a3ff6e 100644 --- a/content/base/src/nsPlainTextSerializer.h +++ b/content/base/src/nsPlainTextSerializer.h @@ -69,7 +69,8 @@ public: // nsIContentSerializer NS_IMETHOD Init(PRUint32 flags, PRUint32 aWrapColumn, - const char* aCharSet, PRBool aIsCopying); + const char* aCharSet, PRBool aIsCopying, + PRBool aIsWholeDocument); NS_IMETHOD AppendText(nsIDOMText* aText, PRInt32 aStartOffset, PRInt32 aEndOffset, nsAString& aStr); diff --git a/content/base/src/nsXMLContentSerializer.cpp b/content/base/src/nsXMLContentSerializer.cpp index 20e10fa7c16..19a04757a89 100644 --- a/content/base/src/nsXMLContentSerializer.cpp +++ b/content/base/src/nsXMLContentSerializer.cpp @@ -93,7 +93,8 @@ NS_IMPL_ISUPPORTS1(nsXMLContentSerializer, nsIContentSerializer) NS_IMETHODIMP nsXMLContentSerializer::Init(PRUint32 flags, PRUint32 aWrapColumn, - const char* aCharSet, PRBool aIsCopying) + const char* aCharSet, PRBool aIsCopying, + PRBool aIsWholeDocument) { mCharset = aCharSet; return NS_OK; diff --git a/content/base/src/nsXMLContentSerializer.h b/content/base/src/nsXMLContentSerializer.h index 556eb578d76..e0ae47988af 100644 --- a/content/base/src/nsXMLContentSerializer.h +++ b/content/base/src/nsXMLContentSerializer.h @@ -60,7 +60,8 @@ class nsXMLContentSerializer : public nsIContentSerializer { NS_DECL_ISUPPORTS NS_IMETHOD Init(PRUint32 flags, PRUint32 aWrapColumn, - const char* aCharSet, PRBool aIsCopying); + const char* aCharSet, PRBool aIsCopying, + PRBool aIsWholeDocument); NS_IMETHOD AppendText(nsIDOMText* aText, PRInt32 aStartOffset, PRInt32 aEndOffset, nsAString& aStr); diff --git a/content/base/test/Makefile.in b/content/base/test/Makefile.in index dcbd8d909b0..fa56b4dcf9a 100644 --- a/content/base/test/Makefile.in +++ b/content/base/test/Makefile.in @@ -86,6 +86,7 @@ _TEST_FILES = test_bug5141.html \ test_bug373181.xhtml \ test_bug375314.html \ test_bug382113.html \ + test_bug390735.html \ bug382113_object.html \ test_CrossSiteXHR.html \ file_CrossSiteXHR_fail1.xml \ diff --git a/content/base/test/test_bug390735.html b/content/base/test/test_bug390735.html new file mode 100644 index 00000000000..92248c9a06b --- /dev/null +++ b/content/base/test/test_bug390735.html @@ -0,0 +1,29 @@ + + + + + + Test for Bug 390735 + + + + + +

+ +
+
+
+ +