Pretttyprinted "special root" documents shouldn't load styleshets or execute

scripts.  Bug 230579, r=sicking, sr=peterv
This commit is contained in:
bzbarsky%mit.edu 2004-04-20 17:12:48 +00:00
Родитель 480d395c48
Коммит 1bec34f862
2 изменённых файлов: 42 добавлений и 18 удалений

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

@ -149,7 +149,8 @@ nsXMLContentSink::nsXMLContentSink()
mPrettyPrintXML(PR_TRUE),
mPrettyPrintHasSpecialRoot(PR_FALSE),
mPrettyPrintHasFactoredElements(PR_FALSE),
mHasProcessedBase(PR_FALSE)
mHasProcessedBase(PR_FALSE),
mAllowAutoXLinks(PR_TRUE)
{
}
@ -193,6 +194,16 @@ nsXMLContentSink::WillBuildModel(void)
{
// Notify document that the load is beginning
mDocument->BeginLoad();
// Check for correct load-command for maybe prettyprinting
if (mPrettyPrintXML) {
nsAutoString command;
mParser->GetCommand(command);
if (!command.Equals(NS_LITERAL_STRING("view"))) {
mPrettyPrintXML = PR_FALSE;
}
}
return NS_OK;
}
@ -206,15 +217,11 @@ nsXMLContentSink::MaybePrettyPrint()
return NS_OK;
}
// Check for correct load-command
nsAutoString command;
mParser->GetCommand(command);
if (!command.Equals(NS_LITERAL_STRING("view"))) {
mPrettyPrintXML = PR_FALSE;
return NS_OK;
// Reenable the CSSLoader so that the prettyprinting stylesheets can load
if (mCSSLoader) {
mCSSLoader->SetEnabled(PR_TRUE);
}
nsCOMPtr<nsXMLPrettyPrinter> printer;
nsresult rv = NS_NewXMLPrettyPrinter(getter_AddRefs(printer));
NS_ENSURE_SUCCESS(rv, rv);
@ -555,7 +562,10 @@ nsXMLContentSink::CloseElement(nsIContent* aContent, PRBool* aAppendContent)
rv = ProcessBASETag(aContent);
mHasProcessedBase = PR_TRUE;
}
else if (nodeInfo->Equals(nsHTMLAtoms::meta, kNameSpaceID_XHTML)) {
else if (nodeInfo->Equals(nsHTMLAtoms::meta, kNameSpaceID_XHTML) &&
// Need to check here to make sure this meta tag does not set
// mPrettyPrintXML to false when we have a special root!
(!mPrettyPrintXML || !mPrettyPrintHasSpecialRoot)) {
rv = ProcessMETATag(aContent);
}
else if (nodeInfo->Equals(nsHTMLAtoms::link, kNameSpaceID_XHTML) ||
@ -1087,6 +1097,18 @@ nsXMLContentSink::HandleStartElement(const PRUnichar *aName,
(tagAtom == nsLayoutAtoms::stylesheet ||
tagAtom == nsLayoutAtoms::transform))) {
mPrettyPrintHasSpecialRoot = PR_TRUE;
if (mPrettyPrintXML) {
// In this case, disable script execution, stylesheet
// loading, and auto XLinks since we plan to prettyprint.
mAllowAutoXLinks = PR_FALSE;
nsIScriptLoader* scriptLoader = mDocument->GetScriptLoader();
if (scriptLoader) {
scriptLoader->SetEnabled(PR_FALSE);
}
if (mCSSLoader) {
mCSSLoader->SetEnabled(PR_FALSE);
}
}
}
mDocElement = content;
@ -1519,7 +1541,7 @@ nsXMLContentSink::AddAttributes(const PRUnichar** aAtts,
}
// Give autoloading links a chance to fire
if (mDocShell) {
if (mDocShell && mAllowAutoXLinks) {
nsCOMPtr<nsIXMLContent> xmlcontent(do_QueryInterface(aContent));
if (xmlcontent) {
nsresult rv = xmlcontent->MaybeTriggerAutoLink(mDocShell);

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

@ -152,13 +152,15 @@ protected:
PRInt32 mTextSize;
PRUint32 mScriptLineNo;
PRPackedBool mConstrainSize;
PRPackedBool mInTitle;
PRPackedBool mPrettyPrintXML;
PRPackedBool mPrettyPrintHasSpecialRoot;
PRPackedBool mPrettyPrintHasFactoredElements;
PRPackedBool mHasProcessedBase;
PRUint8 mConstrainSize : 1;
PRUint8 mInTitle : 1;
PRUint8 mPrettyPrintXML : 1;
PRUint8 mPrettyPrintHasSpecialRoot : 1;
PRUint8 mPrettyPrintHasFactoredElements : 1;
PRUint8 mHasProcessedBase : 1;
PRUint8 mAllowAutoXLinks : 1;
PRUint8 unused : 1; // bit available if someone needs one
nsCOMArray<nsIContent> mContentStack;
nsCOMArray<nsINameSpace> mNameSpaceStack;
nsCOMPtr<nsIDocumentTransformer> mXSLTProcessor;