Bug 63558, we now store XML declaration in the document and can serialize it. There is fix for 158617 as well, newlines behave properly around doctype. r=bzbarsky, sr=jst.
git-svn-id: svn://10.0.0.236/trunk@127185 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
@@ -57,6 +57,17 @@ public:
|
||||
NS_DEFINE_STATIC_IID_ACCESSOR(NS_IXMLDOCUMENT_IID)
|
||||
|
||||
NS_IMETHOD SetDefaultStylesheets(nsIURI* aUrl)=0;
|
||||
|
||||
/**
|
||||
* Set and get XML declaration. Notice that if version is empty,
|
||||
* there can be no XML declaration (it is a required part).
|
||||
*/
|
||||
NS_IMETHOD SetXMLDeclaration(const nsAString& aVersion,
|
||||
const nsAString& aEncoding,
|
||||
const nsAString& Standalone)=0;
|
||||
NS_IMETHOD GetXMLDeclaration(nsAString& aVersion,
|
||||
nsAString& aEncoding,
|
||||
nsAString& Standalone)=0;
|
||||
};
|
||||
|
||||
#endif // nsIXMLDocument_h___
|
||||
|
||||
@@ -1832,6 +1832,8 @@ nsXMLContentSink::HandleDoctypeDecl(const nsAString & aSubset,
|
||||
const nsAString & aPublicId,
|
||||
nsISupports* aCatalogData)
|
||||
{
|
||||
FlushText();
|
||||
|
||||
nsresult rv = NS_OK;
|
||||
|
||||
nsCOMPtr<nsIDOMDocument> doc(do_QueryInterface(mDocument));
|
||||
@@ -1949,6 +1951,32 @@ nsXMLContentSink::HandleProcessingInstruction(const PRUnichar *aTarget,
|
||||
return result;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsXMLContentSink::HandleXMLDeclaration(const PRUnichar *aData,
|
||||
PRUint32 aLength)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aData);
|
||||
// strlen("<?xml version='a'?>") == 19, shortest decl
|
||||
NS_ENSURE_TRUE(aLength >= 19, NS_ERROR_INVALID_ARG);
|
||||
|
||||
nsCOMPtr<nsIXMLDocument> xml(do_QueryInterface(mDocument));
|
||||
NS_WARN_IF_FALSE(xml, "why is XML sink building non-XML document?");
|
||||
if (!xml)
|
||||
return NS_OK;
|
||||
|
||||
// <?xml version="a" encoding="a" standalone="yes|no"?>
|
||||
const nsAString& data = Substring(aData + 6, aData + aLength - 2); // strip out "<?xml " and "?>"
|
||||
|
||||
nsAutoString version, encoding, standalone;
|
||||
|
||||
// XXX If this is too slow we need to parse this here
|
||||
nsParserUtils::GetQuotedAttributeValue(data, NS_LITERAL_STRING("version"), version);
|
||||
nsParserUtils::GetQuotedAttributeValue(data, NS_LITERAL_STRING("encoding"), encoding);
|
||||
nsParserUtils::GetQuotedAttributeValue(data, NS_LITERAL_STRING("standalone"), standalone);
|
||||
|
||||
return xml->SetXMLDeclaration(version, encoding, standalone);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsXMLContentSink::ReportError(const PRUnichar* aErrorText,
|
||||
const PRUnichar* aSourceText)
|
||||
|
||||
@@ -221,7 +221,7 @@ NS_NewXMLDocument(nsIDocument** aInstancePtrResult)
|
||||
nsXMLDocument::nsXMLDocument()
|
||||
: mAttrStyleSheet(nsnull), mInlineStyleSheet(nsnull),
|
||||
mCountCatalogSheets(0), mParser(nsnull),
|
||||
mCrossSiteAccessEnabled(PR_FALSE)
|
||||
mCrossSiteAccessEnabled(PR_FALSE), mXMLDeclarationBits(0)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -422,9 +422,12 @@ nsXMLDocument::Load(const nsAString& aUrl)
|
||||
|
||||
// Find out if UniversalBrowserRead privileges are enabled - we will need this
|
||||
// in case of a redirect
|
||||
rv = secMan->IsCapabilityEnabled("UniversalBrowserRead", &mCrossSiteAccessEnabled);
|
||||
PRBool crossSiteAccessEnabled;
|
||||
rv = secMan->IsCapabilityEnabled("UniversalBrowserRead", &crossSiteAccessEnabled);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
mCrossSiteAccessEnabled = crossSiteAccessEnabled;
|
||||
|
||||
// Create a channel
|
||||
rv = NS_NewChannel(getter_AddRefs(channel), uri, nsnull, nsnull, this);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
@@ -1094,6 +1097,63 @@ nsXMLDocument::SetDefaultStylesheets(nsIURI* aUrl)
|
||||
return result;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsXMLDocument::SetXMLDeclaration(const nsAString& aVersion,
|
||||
const nsAString& aEncoding,
|
||||
const nsAString& aStandalone)
|
||||
{
|
||||
if (aVersion.IsEmpty()) {
|
||||
mXMLDeclarationBits = 0;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
mXMLDeclarationBits = XML_DECLARATION_BITS_DECLARATION_EXISTS;
|
||||
|
||||
if (!aEncoding.IsEmpty()) {
|
||||
mXMLDeclarationBits |= XML_DECLARATION_BITS_ENCODING_EXISTS;
|
||||
}
|
||||
|
||||
if (aStandalone.Equals(NS_LITERAL_STRING("yes"))) {
|
||||
mXMLDeclarationBits |= XML_DECLARATION_BITS_STANDALONE_EXISTS |
|
||||
XML_DECLARATION_BITS_STANDALONE_YES;
|
||||
} else if (aStandalone.Equals(NS_LITERAL_STRING("no"))) {
|
||||
mXMLDeclarationBits |= XML_DECLARATION_BITS_STANDALONE_EXISTS;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsXMLDocument::GetXMLDeclaration(nsAString& aVersion,
|
||||
nsAString& aEncoding,
|
||||
nsAString& aStandalone)
|
||||
{
|
||||
aVersion.Truncate();
|
||||
aEncoding.Truncate();
|
||||
aStandalone.Truncate();
|
||||
|
||||
if (!(mXMLDeclarationBits & XML_DECLARATION_BITS_DECLARATION_EXISTS)) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
aVersion.Assign(NS_LITERAL_STRING("1.0")); // always until we start supporting 1.1 etc.
|
||||
|
||||
if (mXMLDeclarationBits & XML_DECLARATION_BITS_ENCODING_EXISTS) {
|
||||
GetDocumentCharacterSet(aEncoding); // This is what we have stored, not necessarily what was written in the original
|
||||
}
|
||||
|
||||
if (mXMLDeclarationBits & XML_DECLARATION_BITS_STANDALONE_EXISTS) {
|
||||
if (mXMLDeclarationBits & XML_DECLARATION_BITS_STANDALONE_YES) {
|
||||
aStandalone.Assign(NS_LITERAL_STRING("yes"));
|
||||
} else {
|
||||
aStandalone.Assign(NS_LITERAL_STRING("no"));
|
||||
}
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsXMLDocument::SetBaseTarget(const nsAString &aBaseTarget)
|
||||
{
|
||||
|
||||
@@ -53,6 +53,11 @@ class nsIDOMNode;
|
||||
class nsICSSLoader;
|
||||
class nsIURI;
|
||||
|
||||
#define XML_DECLARATION_BITS_DECLARATION_EXISTS 1
|
||||
#define XML_DECLARATION_BITS_ENCODING_EXISTS 2
|
||||
#define XML_DECLARATION_BITS_STANDALONE_EXISTS 4
|
||||
#define XML_DECLARATION_BITS_STANDALONE_YES 8
|
||||
|
||||
class nsXMLDocument : public nsMarkupDocument,
|
||||
public nsIXMLDocument,
|
||||
public nsIHTMLContentContainer,
|
||||
@@ -107,6 +112,12 @@ public:
|
||||
|
||||
// nsIXMLDocument interface
|
||||
NS_IMETHOD SetDefaultStylesheets(nsIURI* aUrl);
|
||||
NS_IMETHOD SetXMLDeclaration(const nsAString& aVersion,
|
||||
const nsAString& aEncoding,
|
||||
const nsAString& Standalone);
|
||||
NS_IMETHOD GetXMLDeclaration(nsAString& aVersion,
|
||||
nsAString& aEncoding,
|
||||
nsAString& Standalone);
|
||||
|
||||
// nsIHTMLContentContainer
|
||||
NS_IMETHOD GetAttributeStyleSheet(nsIHTMLStyleSheet** aResult);
|
||||
@@ -142,7 +153,9 @@ protected:
|
||||
nsIParser *mParser;
|
||||
|
||||
nsCOMPtr<nsIScriptContext> mScriptContext;
|
||||
PRBool mCrossSiteAccessEnabled;
|
||||
PRPackedBool mCrossSiteAccessEnabled;
|
||||
|
||||
PRUint8 mXMLDeclarationBits;
|
||||
};
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user