Bug 172372, when loading XML as data, we need to disable scripts and styles. r=sicking, sr=bzbarsky, a=asa.

This commit is contained in:
heikki%netscape.com 2002-10-11 00:38:29 +00:00
Родитель 424961c55a
Коммит 919aef29e4
13 изменённых файлов: 207 добавлений и 84 удалений

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

@ -75,18 +75,11 @@ interface nsIScriptLoader : nsISupports {
in nsIScriptLoaderObserver aObserver);
/**
* Suspend processing of new script elements. Any call to
* processScriptElement() will fail with a return code of
* NS_ERROR_NOT_AVAILABLE. Note that this DOES NOT suspend
* currently loading or executing scripts. All calls to
* suspend() must be matched with an equal number of calls
* to resume() before processing of new script elements
* continues.
* Whether the loader is enabled or not.
* When disabled, processing of new script elements is disabled.
* Any call to processScriptElement() will fail with a return code of
* NS_ERROR_NOT_AVAILABLE. Note that this DOES NOT disable
* currently loading or executing scripts.
*/
void suspend();
/**
* Resume processing of new script elements.
*/
void resume();
attribute boolean enabled;
};

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

@ -69,9 +69,9 @@ public:
nsCOMPtr<nsIDOMHTMLScriptElement> mElement;
nsCOMPtr<nsIScriptLoaderObserver> mObserver;
PRBool mLoading; // Are we still waiting for a load to complete?
PRBool mWasPending; // Processed immediately or pending
PRBool mIsInline; // Is the script inline or loaded?
PRPackedBool mLoading; // Are we still waiting for a load to complete?
PRPackedBool mWasPending; // Processed immediately or pending
PRPackedBool mIsInline; // Is the script inline or loaded?
// nsSharableString mScriptText; // Holds script for loaded scripts
nsString mScriptText;
const char* mJSVersion; // We don't own this string
@ -124,7 +124,7 @@ nsScriptLoadRequest::FireScriptEvaluated(nsresult aResult)
//////////////////////////////////////////////////////////////
nsScriptLoader::nsScriptLoader()
: mDocument(nsnull), mSuspendCount(0)
: mDocument(nsnull), mEnabled(PR_TRUE)
{
NS_INIT_ISUPPORTS();
}
@ -251,7 +251,7 @@ nsScriptLoader::ProcessScriptElement(nsIDOMHTMLScriptElement *aElement,
// Check to see that the element is not in a container that
// suppresses script evaluation within it.
if (mSuspendCount || InNonScriptingContainer(aElement)) {
if (!mEnabled || InNonScriptingContainer(aElement)) {
return FireErrorNotification(NS_ERROR_NOT_AVAILABLE, aElement, aObserver);
}
@ -834,18 +834,16 @@ nsScriptLoader::OnStreamComplete(nsIStreamLoader* aLoader,
}
NS_IMETHODIMP
nsScriptLoader::Suspend()
nsScriptLoader::GetEnabled(PRBool *aEnabled)
{
mSuspendCount++;
NS_ENSURE_ARG_POINTER(aEnabled);
*aEnabled = mEnabled;
return NS_OK;
}
NS_IMETHODIMP
nsScriptLoader::Resume()
nsScriptLoader::SetEnabled(PRBool aEnabled)
{
NS_ASSERTION((mSuspendCount > 0), "nsScriptLoader call to resume() unbalanced");
mSuspendCount--;
mEnabled = aEnabled;
return NS_OK;
}

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

@ -68,7 +68,7 @@ protected:
nsIDocument* mDocument; // [WEAK]
nsSupportsArray mObservers;
nsSupportsArray mPendingRequests;
PRInt32 mSuspendCount;
PRBool mEnabled;
};
#endif //__nsScriptLoader_h__

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

@ -553,7 +553,7 @@ nsSyncLoadService::LoadLocalXBLDocument(nsIChannel* aChannel,
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIStreamListener> listener;
rv = doc->StartDocumentLoad(kLoadAsData,
rv = doc->StartDocumentLoad("loadAsInteractiveData",
aChannel,
loadGroup,
nsnull,

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

@ -5612,7 +5612,7 @@ HTMLContentSink::ProcessSCRIPTTag(const nsIParserNode& aNode)
if (mDocument) {
mDocument->GetScriptLoader(getter_AddRefs(loader));
if (loader) {
loader->Suspend();
loader->SetEnabled(PR_FALSE);
}
}
} else {
@ -5645,7 +5645,7 @@ HTMLContentSink::ProcessSCRIPTTag(const nsIParserNode& aNode)
// suspended the script loader. Now that the script content
// has been handled let's resume the script loader.
if (loader) {
loader->Resume();
loader->SetEnabled(PR_TRUE);
}
// If the act of insertion evaluated the script, we're fine.

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

@ -130,6 +130,16 @@ public:
// stop loading one sheet
NS_IMETHOD StopLoadingSheet(nsIURI* aURL) = 0;
/**
* Whether the loader is enabled or not.
* When disabled, processing of new styles is disabled and an attempt
* to do so will fail with a return code of
* NS_ERROR_NOT_AVAILABLE. Note that this DOES NOT disable
* currently loading styles or already processed styles.
*/
NS_IMETHOD GetEnabled(PRBool *aEnabled) = 0;
NS_IMETHOD SetEnabled(PRBool aEnabled) = 0;
};
extern NS_EXPORT nsresult

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

@ -291,9 +291,26 @@ public:
nsresult LoadSheet(URLKey& aKey, SheetLoadData* aData);
// stop loading all sheets
NS_IMETHOD Stop(void);
// stop loading one sheet
NS_IMETHOD StopLoadingSheet(nsIURI* aURL);
/**
* Is the loader enabled or not.
* When disabled, processing of new styles is disabled and an attempt
* to do so will fail with a return code of
* NS_ERROR_NOT_AVAILABLE. Note that this DOES NOT disable
* currently loading styles or already processed styles.
*/
NS_IMETHOD GetEnabled(PRBool *aEnabled);
NS_IMETHOD SetEnabled(PRBool aEnabled);
nsIDocument* mDocument; // the document we live for
PRBool mCaseSensitive; // is document CSS case sensitive
PRPackedBool mCaseSensitive; // is document CSS case sensitive
PRPackedBool mEnabled; // is enabled to load new styles
nsCompatibility mCompatMode;
nsString mPreferredSheet; // title of preferred sheet
@ -310,12 +327,6 @@ public:
nsHashtable mSheetMapTable; // map to insertion index arrays
// stop loading all sheets
NS_IMETHOD Stop(void);
// stop loading one sheet
NS_IMETHOD StopLoadingSheet(nsIURI* aURL);
#ifdef NS_DEBUG
PRBool mSyncCallback;
#endif
@ -427,12 +438,13 @@ SheetLoadData::~SheetLoadData(void)
}
CSSLoaderImpl::CSSLoaderImpl(void)
: mDocument(nsnull),
mCaseSensitive(PR_FALSE),
mEnabled(PR_TRUE),
mCompatMode(eCompatibility_FullStandards),
mParsers(nsnull)
{
NS_INIT_ISUPPORTS();
mDocument = nsnull;
mCaseSensitive = PR_FALSE;
mCompatMode = eCompatibility_FullStandards;
mParsers = nsnull;
}
static PRBool PR_CALLBACK ReleaseSheet(nsHashKey* aKey, void* aData, void* aClosure)
@ -1636,6 +1648,9 @@ CSSLoaderImpl::LoadInlineStyle(nsIContent* aElement,
PRBool& aCompleted,
nsICSSLoaderObserver* aObserver)
{
if (!mEnabled)
return NS_ERROR_NOT_AVAILABLE;
NS_ASSERTION(mDocument, "not initialized");
if (! mDocument) {
return NS_ERROR_NOT_INITIALIZED;
@ -1679,6 +1694,9 @@ CSSLoaderImpl::LoadStyleLink(nsIContent* aElement,
PRBool& aCompleted,
nsICSSLoaderObserver* aObserver)
{
if (!mEnabled)
return NS_ERROR_NOT_AVAILABLE;
NS_ASSERTION(mDocument, "not initialized");
if (! mDocument) {
return NS_ERROR_NOT_INITIALIZED;
@ -1778,6 +1796,9 @@ CSSLoaderImpl::LoadChildSheet(nsICSSStyleSheet* aParentSheet,
PRInt32 aIndex,
nsICSSImportRule* aParentRule)
{
if (!mEnabled)
return NS_ERROR_NOT_AVAILABLE;
nsresult result = NS_ERROR_NULL_POINTER;
if (aURL) {
@ -1865,6 +1886,9 @@ CSSLoaderImpl::LoadAgentSheet(nsIURI* aURL,
PRBool& aCompleted,
nsICSSLoaderObserver* aObserver)
{
if (!mEnabled)
return NS_ERROR_NOT_AVAILABLE;
nsresult result = NS_ERROR_NULL_POINTER;
if (aURL) {
// Get an input stream from the url
@ -1997,3 +2021,18 @@ CSSLoaderImpl::StopLoadingSheet(nsIURI* aURL)
}
return NS_OK;
}
NS_IMETHODIMP
CSSLoaderImpl::GetEnabled(PRBool *aEnabled)
{
NS_ENSURE_ARG_POINTER(aEnabled);
*aEnabled = mEnabled;
return NS_OK;
}
NS_IMETHODIMP
CSSLoaderImpl::SetEnabled(PRBool aEnabled)
{
mEnabled = aEnabled;
return NS_OK;
}

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

@ -1193,7 +1193,7 @@ nsXBLService::FetchBindingDocument(nsIContent* aBoundElement, nsIDocument* aBoun
if (!xblSink)
return NS_ERROR_FAILURE;
if (NS_FAILED(rv = doc->StartDocumentLoad("loadAsData",
if (NS_FAILED(rv = doc->StartDocumentLoad("loadAsInteractiveData",
channel,
loadGroup,
nsnull,
@ -1203,6 +1203,7 @@ nsXBLService::FetchBindingDocument(nsIContent* aBoundElement, nsIDocument* aBoun
NS_ERROR("Failure to init XBL doc prior to load.");
return rv;
}
// We can be asynchronous
nsXBLStreamListener* xblListener = new nsXBLStreamListener(this, listener, aBoundDocument, doc);
NS_ENSURE_TRUE(xblListener,NS_ERROR_OUT_OF_MEMORY);

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

@ -125,6 +125,8 @@
static char kNameSpaceSeparator = ':';
#define kXSLType "text/xsl"
static const char* kLoadAsData = "loadAsData";
static NS_DEFINE_CID(kNameSpaceManagerCID, NS_NAMESPACEMANAGER_CID);
static NS_DEFINE_CID(kXMLDocumentCID, NS_XMLDOCUMENT_CID);
@ -854,6 +856,11 @@ nsXMLContentSink::ProcessStyleLink(nsIContent* aElement,
nsresult rv = NS_OK;
mPrettyPrintXML = PR_FALSE;
nsAutoString cmd;
if (mParser) mParser->GetCommand(cmd);
if (cmd.EqualsWithConversion(kLoadAsData))
return NS_OK; // Do not load stylesheets when loading as data
if (aType.EqualsIgnoreCase(kXSLType) ||
aType.EqualsIgnoreCase(kXMLTextContentType) ||
aType.EqualsIgnoreCase(kXMLApplicationContentType)) {

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

@ -469,6 +469,32 @@ nsXMLDocument::StartDocumentLoad(const char* aCommand,
PRBool aReset,
nsIContentSink* aSink)
{
if (nsCRT::strcmp(kLoadAsData, aCommand) == 0) {
// We need to disable script & style loading in this case.
// We leave them disabled even in EndLoad(), and let anyone
// who puts the document on display to worry about enabling.
// scripts
nsCOMPtr<nsIScriptLoader> loader;
nsresult rv = GetScriptLoader(getter_AddRefs(loader));
if (NS_FAILED(rv))
return rv;
if (loader) {
loader->SetEnabled(PR_FALSE); // Do not load/process scripts when loading as data
}
// styles
nsCOMPtr<nsICSSLoader> cssLoader;
rv = GetCSSLoader(*getter_AddRefs(cssLoader));
if (NS_FAILED(rv))
return rv;
if (cssLoader) {
cssLoader->SetEnabled(PR_FALSE); // Do not load/process styles when loading as data
}
} else if (nsCRT::strcmp("loadAsInteractiveData", aCommand) == 0) {
aCommand = kLoadAsData; // XBL, for example, needs scripts and styles
}
nsresult rv = nsDocument::StartDocumentLoad(aCommand,
aChannel, aLoadGroup,
aContainer,

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

@ -94,7 +94,7 @@ nsXSLContentSink::Init(nsITransformMediator* aTM,
rv = mDocument->GetScriptLoader(getter_AddRefs(loader));
NS_ENSURE_SUCCESS(rv, rv);
loader->Suspend();
loader->SetEnabled(PR_FALSE);
loader->RemoveObserver(this);
return rv;

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

@ -291,9 +291,26 @@ public:
nsresult LoadSheet(URLKey& aKey, SheetLoadData* aData);
// stop loading all sheets
NS_IMETHOD Stop(void);
// stop loading one sheet
NS_IMETHOD StopLoadingSheet(nsIURI* aURL);
/**
* Is the loader enabled or not.
* When disabled, processing of new styles is disabled and an attempt
* to do so will fail with a return code of
* NS_ERROR_NOT_AVAILABLE. Note that this DOES NOT disable
* currently loading styles or already processed styles.
*/
NS_IMETHOD GetEnabled(PRBool *aEnabled);
NS_IMETHOD SetEnabled(PRBool aEnabled);
nsIDocument* mDocument; // the document we live for
PRBool mCaseSensitive; // is document CSS case sensitive
PRPackedBool mCaseSensitive; // is document CSS case sensitive
PRPackedBool mEnabled; // is enabled to load new styles
nsCompatibility mCompatMode;
nsString mPreferredSheet; // title of preferred sheet
@ -310,12 +327,6 @@ public:
nsHashtable mSheetMapTable; // map to insertion index arrays
// stop loading all sheets
NS_IMETHOD Stop(void);
// stop loading one sheet
NS_IMETHOD StopLoadingSheet(nsIURI* aURL);
#ifdef NS_DEBUG
PRBool mSyncCallback;
#endif
@ -427,12 +438,13 @@ SheetLoadData::~SheetLoadData(void)
}
CSSLoaderImpl::CSSLoaderImpl(void)
: mDocument(nsnull),
mCaseSensitive(PR_FALSE),
mEnabled(PR_TRUE),
mCompatMode(eCompatibility_FullStandards),
mParsers(nsnull)
{
NS_INIT_ISUPPORTS();
mDocument = nsnull;
mCaseSensitive = PR_FALSE;
mCompatMode = eCompatibility_FullStandards;
mParsers = nsnull;
}
static PRBool PR_CALLBACK ReleaseSheet(nsHashKey* aKey, void* aData, void* aClosure)
@ -1636,6 +1648,9 @@ CSSLoaderImpl::LoadInlineStyle(nsIContent* aElement,
PRBool& aCompleted,
nsICSSLoaderObserver* aObserver)
{
if (!mEnabled)
return NS_ERROR_NOT_AVAILABLE;
NS_ASSERTION(mDocument, "not initialized");
if (! mDocument) {
return NS_ERROR_NOT_INITIALIZED;
@ -1679,6 +1694,9 @@ CSSLoaderImpl::LoadStyleLink(nsIContent* aElement,
PRBool& aCompleted,
nsICSSLoaderObserver* aObserver)
{
if (!mEnabled)
return NS_ERROR_NOT_AVAILABLE;
NS_ASSERTION(mDocument, "not initialized");
if (! mDocument) {
return NS_ERROR_NOT_INITIALIZED;
@ -1778,6 +1796,9 @@ CSSLoaderImpl::LoadChildSheet(nsICSSStyleSheet* aParentSheet,
PRInt32 aIndex,
nsICSSImportRule* aParentRule)
{
if (!mEnabled)
return NS_ERROR_NOT_AVAILABLE;
nsresult result = NS_ERROR_NULL_POINTER;
if (aURL) {
@ -1865,6 +1886,9 @@ CSSLoaderImpl::LoadAgentSheet(nsIURI* aURL,
PRBool& aCompleted,
nsICSSLoaderObserver* aObserver)
{
if (!mEnabled)
return NS_ERROR_NOT_AVAILABLE;
nsresult result = NS_ERROR_NULL_POINTER;
if (aURL) {
// Get an input stream from the url
@ -1997,3 +2021,18 @@ CSSLoaderImpl::StopLoadingSheet(nsIURI* aURL)
}
return NS_OK;
}
NS_IMETHODIMP
CSSLoaderImpl::GetEnabled(PRBool *aEnabled)
{
NS_ENSURE_ARG_POINTER(aEnabled);
*aEnabled = mEnabled;
return NS_OK;
}
NS_IMETHODIMP
CSSLoaderImpl::SetEnabled(PRBool aEnabled)
{
mEnabled = aEnabled;
return NS_OK;
}

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

@ -130,6 +130,16 @@ public:
// stop loading one sheet
NS_IMETHOD StopLoadingSheet(nsIURI* aURL) = 0;
/**
* Whether the loader is enabled or not.
* When disabled, processing of new styles is disabled and an attempt
* to do so will fail with a return code of
* NS_ERROR_NOT_AVAILABLE. Note that this DOES NOT disable
* currently loading styles or already processed styles.
*/
NS_IMETHOD GetEnabled(PRBool *aEnabled) = 0;
NS_IMETHOD SetEnabled(PRBool aEnabled) = 0;
};
extern NS_EXPORT nsresult