mirror of
https://github.com/roytam1/UXP.git
synced 2026-05-26 14:54:25 +00:00
[DOM] Check state before compiling/transforming.
This commit is contained in:
@@ -85,11 +85,13 @@ interface XSLTProcessor {
|
||||
* the processor use the default-value for all parameters as specified in
|
||||
* the stylesheet.
|
||||
*/
|
||||
[Throws]
|
||||
void clearParameters();
|
||||
|
||||
/**
|
||||
* Remove all parameters and stylesheets from this nsIXSLTProcessor.
|
||||
*/
|
||||
[Throws]
|
||||
void reset();
|
||||
|
||||
/**
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include "nsContentCID.h"
|
||||
#include "nsError.h"
|
||||
#include "nsIChannel.h"
|
||||
#include "mozilla/AutoRestore.h"
|
||||
#include "mozilla/dom/Element.h"
|
||||
#include "nsIDOMElement.h"
|
||||
#include "nsIDOMText.h"
|
||||
@@ -570,6 +571,8 @@ public:
|
||||
|
||||
NS_IMETHOD Run() override
|
||||
{
|
||||
MOZ_RELEASE_ASSERT(mProcessor->mState ==
|
||||
txMozillaXSLTProcessor::State::None);
|
||||
mProcessor->TransformToDoc(nullptr, false);
|
||||
return NS_OK;
|
||||
}
|
||||
@@ -604,6 +607,12 @@ txMozillaXSLTProcessor::ImportStylesheet(nsIDOMNode *aStyle)
|
||||
NS_ENSURE_TRUE(!mStylesheetDocument && !mStylesheet,
|
||||
NS_ERROR_NOT_IMPLEMENTED);
|
||||
|
||||
if (mState != State::None) {
|
||||
return NS_ERROR_DOM_INVALID_STATE_ERR;
|
||||
}
|
||||
mozilla::AutoRestore<State> restore(mState);
|
||||
mState = State::Compiling;
|
||||
|
||||
// Reset mCompileResult when importing.
|
||||
mCompileResult = NS_OK;
|
||||
|
||||
@@ -650,9 +659,17 @@ txMozillaXSLTProcessor::TransformToDocument(nsIDOMNode *aSource,
|
||||
return NS_ERROR_DOM_SECURITY_ERR;
|
||||
}
|
||||
|
||||
if (mState != State::None) {
|
||||
return NS_ERROR_DOM_INVALID_STATE_ERR;
|
||||
}
|
||||
|
||||
nsresult rv = ensureStylesheet();
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
MOZ_RELEASE_ASSERT(mState == State::None);
|
||||
mozilla::AutoRestore<State> restore(mState);
|
||||
mState = State::Transforming;
|
||||
|
||||
mSource = do_QueryInterface(aSource);
|
||||
|
||||
return TransformToDoc(aResult, true);
|
||||
@@ -729,9 +746,17 @@ txMozillaXSLTProcessor::TransformToFragment(nsIDOMNode *aSource,
|
||||
return NS_ERROR_DOM_SECURITY_ERR;
|
||||
}
|
||||
|
||||
if (mState != State::None) {
|
||||
return NS_ERROR_DOM_INVALID_STATE_ERR;
|
||||
}
|
||||
|
||||
nsresult rv = ensureStylesheet();
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
MOZ_RELEASE_ASSERT(mState == State::None);
|
||||
mozilla::AutoRestore<State> restore(mState);
|
||||
mState = State::Transforming;
|
||||
|
||||
nsAutoPtr<txXPathNode> sourceNode(txXPathNativeNode::createXPathNode(aSource));
|
||||
if (!sourceNode) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
@@ -767,6 +792,9 @@ txMozillaXSLTProcessor::SetParameter(const nsAString & aNamespaceURI,
|
||||
nsIVariant *aValue)
|
||||
{
|
||||
NS_ENSURE_ARG(aValue);
|
||||
if (mState != State::None) {
|
||||
return NS_ERROR_DOM_INVALID_STATE_ERR;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIVariant> value = aValue;
|
||||
|
||||
@@ -990,6 +1018,10 @@ NS_IMETHODIMP
|
||||
txMozillaXSLTProcessor::RemoveParameter(const nsAString& aNamespaceURI,
|
||||
const nsAString& aLocalName)
|
||||
{
|
||||
if (mState != State::None) {
|
||||
return NS_ERROR_DOM_INVALID_STATE_ERR;
|
||||
}
|
||||
|
||||
int32_t nsId = kNameSpaceID_Unknown;
|
||||
nsresult rv = nsContentUtils::NameSpaceManager()->
|
||||
RegisterNameSpace(aNamespaceURI, nsId);
|
||||
@@ -1004,6 +1036,10 @@ txMozillaXSLTProcessor::RemoveParameter(const nsAString& aNamespaceURI,
|
||||
NS_IMETHODIMP
|
||||
txMozillaXSLTProcessor::ClearParameters()
|
||||
{
|
||||
if (mState != State::None) {
|
||||
return NS_ERROR_DOM_INVALID_STATE_ERR;
|
||||
}
|
||||
|
||||
mVariables.clear();
|
||||
|
||||
return NS_OK;
|
||||
@@ -1012,6 +1048,10 @@ txMozillaXSLTProcessor::ClearParameters()
|
||||
NS_IMETHODIMP
|
||||
txMozillaXSLTProcessor::Reset()
|
||||
{
|
||||
if (mState != State::None) {
|
||||
return NS_ERROR_DOM_INVALID_STATE_ERR;
|
||||
}
|
||||
|
||||
if (mStylesheetDocument) {
|
||||
mStylesheetDocument->RemoveMutationObserver(this);
|
||||
}
|
||||
@@ -1215,6 +1255,12 @@ txMozillaXSLTProcessor::notifyError()
|
||||
nsresult
|
||||
txMozillaXSLTProcessor::ensureStylesheet()
|
||||
{
|
||||
if (mState != State::None) {
|
||||
return NS_ERROR_DOM_INVALID_STATE_ERR;
|
||||
}
|
||||
mozilla::AutoRestore<State> restore(mState);
|
||||
mState = State::Compiling;
|
||||
|
||||
if (mStylesheet) {
|
||||
return NS_OK;
|
||||
}
|
||||
@@ -1311,10 +1357,10 @@ txMozillaXSLTProcessor::Constructor(const GlobalObject& aGlobal,
|
||||
}
|
||||
|
||||
void
|
||||
txMozillaXSLTProcessor::ImportStylesheet(nsINode& stylesheet,
|
||||
txMozillaXSLTProcessor::ImportStylesheet(nsINode& aStylesheet,
|
||||
mozilla::ErrorResult& aRv)
|
||||
{
|
||||
aRv = ImportStylesheet(stylesheet.AsDOMNode());
|
||||
aRv = ImportStylesheet(aStylesheet.AsDOMNode());
|
||||
}
|
||||
|
||||
already_AddRefed<DocumentFragment>
|
||||
@@ -1333,11 +1379,11 @@ txMozillaXSLTProcessor::TransformToFragment(nsINode& source,
|
||||
}
|
||||
|
||||
already_AddRefed<nsIDocument>
|
||||
txMozillaXSLTProcessor::TransformToDocument(nsINode& source,
|
||||
txMozillaXSLTProcessor::TransformToDocument(nsINode& aSource,
|
||||
mozilla::ErrorResult& aRv)
|
||||
{
|
||||
nsCOMPtr<nsIDOMDocument> document;
|
||||
aRv = TransformToDocument(source.AsDOMNode(), getter_AddRefs(document));
|
||||
aRv = TransformToDocument(aSource.AsDOMNode(), getter_AddRefs(document));
|
||||
nsCOMPtr<nsIDocument> domDoc = do_QueryInterface(document);
|
||||
return domDoc.forget();
|
||||
}
|
||||
|
||||
@@ -110,12 +110,12 @@ public:
|
||||
Constructor(const mozilla::dom::GlobalObject& aGlobal,
|
||||
mozilla::ErrorResult& aRv);
|
||||
|
||||
void ImportStylesheet(nsINode& stylesheet,
|
||||
void ImportStylesheet(nsINode& aStylesheet,
|
||||
mozilla::ErrorResult& aRv);
|
||||
already_AddRefed<mozilla::dom::DocumentFragment>
|
||||
TransformToFragment(nsINode& source, nsIDocument& docVal, mozilla::ErrorResult& aRv);
|
||||
TransformToFragment(nsINode& source, nsIDocument& docVal, mozilla::ErrorResult& aRv);
|
||||
already_AddRefed<nsIDocument>
|
||||
TransformToDocument(nsINode& source, mozilla::ErrorResult& aRv);
|
||||
TransformToDocument(nsINode& aSource, mozilla::ErrorResult& aRv);
|
||||
|
||||
void SetParameter(JSContext* aCx,
|
||||
const nsAString& aNamespaceURI,
|
||||
@@ -131,6 +131,12 @@ public:
|
||||
{
|
||||
aRv = RemoveParameter(aNamespaceURI, aLocalName);
|
||||
}
|
||||
void ClearParameters(mozilla::ErrorResult& aRv) {
|
||||
aRv = ClearParameters();
|
||||
};
|
||||
void Reset(mozilla::ErrorResult& aRv) {
|
||||
aRv = Reset();
|
||||
};
|
||||
|
||||
uint32_t Flags()
|
||||
{
|
||||
@@ -160,6 +166,8 @@ public:
|
||||
static void Shutdown();
|
||||
|
||||
private:
|
||||
friend class nsTransformBlockerEvent;
|
||||
|
||||
explicit txMozillaXSLTProcessor(nsISupports* aOwner);
|
||||
/**
|
||||
* Default destructor for txMozillaXSLTProcessor
|
||||
@@ -186,6 +194,13 @@ private:
|
||||
RefPtr<txResultRecycler> mRecycler;
|
||||
|
||||
uint32_t mFlags;
|
||||
|
||||
enum class State {
|
||||
None,
|
||||
Compiling,
|
||||
Transforming,
|
||||
};
|
||||
State mState = State::None;
|
||||
};
|
||||
|
||||
extern nsresult TX_LoadSheet(nsIURI* aUri, txMozillaXSLTProcessor* aProcessor,
|
||||
|
||||
Reference in New Issue
Block a user