--- a/dom/base/nsDOMClassInfo.cpp
+++ b/dom/base/nsDOMClassInfo.cpp
@@ -67,20 +67,16 @@
#include "nsIDOMEventTarget.h"
// CSS related includes
#include "nsCSSRules.h"
#include "nsIDOMCSSRule.h"
#include "nsAutoPtr.h"
#include "nsMemory.h"
-// Tranformiix
-#include "nsIXSLTProcessor.h"
-#include "nsIXSLTProcessorPrivate.h"
-
// includes needed for the prototype chain interfaces
#include "nsIDOMCSSCharsetRule.h"
#include "nsIDOMCSSImportRule.h"
#include "nsIDOMCSSMediaRule.h"
#include "nsIDOMCSSFontFaceRule.h"
#include "nsIDOMCSSMozDocumentRule.h"
#include "nsIDOMCSSSupportsRule.h"
#include "nsIDOMMozCSSKeyframeRule.h"
@@ -278,19 +274,16 @@ static nsDOMClassInfoData sClassInfoData
#endif
NS_DEFINE_CLASSINFO_DATA(CSSMozDocumentRule, nsDOMGenericSH,
DOM_DEFAULT_SCRIPTABLE_FLAGS)
NS_DEFINE_CLASSINFO_DATA(CSSSupportsRule, nsDOMGenericSH,
DOM_DEFAULT_SCRIPTABLE_FLAGS)
- NS_DEFINE_CLASSINFO_DATA(XSLTProcessor, nsDOMGenericSH,
- DOM_DEFAULT_SCRIPTABLE_FLAGS)
-
NS_DEFINE_CLASSINFO_DATA(XPathNSResolver, nsDOMGenericSH,
DOM_DEFAULT_SCRIPTABLE_FLAGS)
NS_DEFINE_CLASSINFO_DATA(MozSmsMessage, nsDOMGenericSH,
DOM_DEFAULT_SCRIPTABLE_FLAGS)
NS_DEFINE_CLASSINFO_DATA(MozMmsMessage, nsDOMGenericSH,
DOM_DEFAULT_SCRIPTABLE_FLAGS)
@@ -331,46 +324,16 @@ static nsDOMClassInfoData sClassInfoData
NS_DEFINE_CHROME_XBL_CLASSINFO_DATA(XULButtonElement, nsDOMGenericSH,
DOM_DEFAULT_SCRIPTABLE_FLAGS)
NS_DEFINE_CHROME_XBL_CLASSINFO_DATA(XULCheckboxElement, nsDOMGenericSH,
DOM_DEFAULT_SCRIPTABLE_FLAGS)
NS_DEFINE_CHROME_XBL_CLASSINFO_DATA(XULPopupElement, nsDOMGenericSH,
DOM_DEFAULT_SCRIPTABLE_FLAGS)
};
-#define NS_DEFINE_CONTRACT_CTOR(_class, _contract_id) \
- static nsresult \
- _class##Ctor(nsISupports** aInstancePtrResult) \
- { \
- nsresult rv = NS_OK; \
- nsCOMPtr<nsISupports> native = do_CreateInstance(_contract_id, &rv); \
- native.forget(aInstancePtrResult); \
- return rv; \
- }
-
-NS_DEFINE_CONTRACT_CTOR(XSLTProcessor,
- "@mozilla.org/document-transformer;1?type=xslt")
-
-#undef NS_DEFINE_CONTRACT_CTOR
-
-struct nsConstructorFuncMapData
-{
- int32_t mDOMClassInfoID;
- nsDOMConstructorFunc mConstructorFunc;
-};
-
-#define NS_DEFINE_CONSTRUCTOR_FUNC_DATA(_class, _func) \
- { eDOMClassInfo_##_class##_id, _func },
-
-static const nsConstructorFuncMapData kConstructorFuncMap[] =
-{
- NS_DEFINE_CONSTRUCTOR_FUNC_DATA(XSLTProcessor, XSLTProcessorCtor)
-};
-#undef NS_DEFINE_CONSTRUCTOR_FUNC_DATA
-
nsIXPConnect *nsDOMClassInfo::sXPConnect = nullptr;
bool nsDOMClassInfo::sIsInitialized = false;
jsid nsDOMClassInfo::sConstructor_id = JSID_VOID;
jsid nsDOMClassInfo::sWrappedJSObject_id = JSID_VOID;
static const JSClass *sObjectClass = nullptr;
@@ -769,21 +732,16 @@ nsDOMClassInfo::Init()
DOM_CLASSINFO_MAP_BEGIN(CSSMozDocumentRule, nsIDOMCSSMozDocumentRule)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMCSSMozDocumentRule)
DOM_CLASSINFO_MAP_END
DOM_CLASSINFO_MAP_BEGIN(CSSSupportsRule, nsIDOMCSSSupportsRule)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMCSSSupportsRule)
DOM_CLASSINFO_MAP_END
- DOM_CLASSINFO_MAP_BEGIN(XSLTProcessor, nsIXSLTProcessor)
- DOM_CLASSINFO_MAP_ENTRY(nsIXSLTProcessor)
- DOM_CLASSINFO_MAP_ENTRY(nsIXSLTProcessorPrivate)
- DOM_CLASSINFO_MAP_END
-
DOM_CLASSINFO_MAP_BEGIN(XPathNSResolver, nsIDOMXPathNSResolver)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMXPathNSResolver)
DOM_CLASSINFO_MAP_END
DOM_CLASSINFO_MAP_BEGIN(MozSmsMessage, nsIDOMMozSmsMessage)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMMozSmsMessage)
DOM_CLASSINFO_MAP_END
@@ -1432,22 +1390,16 @@ nsDOMClassInfo::ShutDown()
NS_IF_RELEASE(sXPConnect);
sIsInitialized = false;
}
static nsDOMConstructorFunc
FindConstructorFunc(const nsDOMClassInfoData *aDOMClassInfoData)
{
- for (uint32_t i = 0; i < ArrayLength(kConstructorFuncMap); ++i) {
- if (&sClassInfoData[kConstructorFuncMap[i].mDOMClassInfoID] ==
- aDOMClassInfoData) {
- return kConstructorFuncMap[i].mConstructorFunc;
- }
- }
return nullptr;
}
static nsresult
BaseStubConstructor(nsIWeakReference* aWeakOwner,
const nsGlobalNameStruct *name_struct, JSContext *cx,
JS::Handle<JSObject*> obj, const JS::CallArgs &args)
{
--- a/dom/base/nsDOMClassInfoClasses.h
+++ b/dom/base/nsDOMClassInfoClasses.h
@@ -32,19 +32,16 @@ DOMCI_CLASS(XULTreeBuilder)
#ifdef MOZ_XUL
DOMCI_CLASS(TreeColumn)
#endif
DOMCI_CLASS(CSSMozDocumentRule)
DOMCI_CLASS(CSSSupportsRule)
-// XSLTProcessor
-DOMCI_CLASS(XSLTProcessor)
-
// DOM Level 3 XPath objects
DOMCI_CLASS(XPathNSResolver)
DOMCI_CLASS(MozSmsMessage)
DOMCI_CLASS(MozMmsMessage)
DOMCI_CLASS(MozMobileMessageThread)
// @font-face in CSS
--- a/dom/bindings/Bindings.conf
+++ b/dom/bindings/Bindings.conf
@@ -1528,16 +1528,20 @@ DOMInterfaces = {
'wrapperCache': False
},
'XPathExpression': {
'wrapperCache': False,
'nativeOwnership': 'owned',
},
+'XSLTProcessor': {
+ 'nativeType': 'txMozillaXSLTProcessor',
+},
+
'XULDocument': {
'headerFile': 'XULDocument.h'
},
'XULElement': {
'nativeType': 'nsXULElement',
},
copy from dom/xslt/nsIXSLTProcessor.idl
copy to dom/webidl/XSLTProcessor.webidl
--- a/dom/xslt/nsIXSLTProcessor.idl
+++ b/dom/webidl/XSLTProcessor.webidl
@@ -1,100 +1,109 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-#include "domstubs.idl"
-
interface nsIVariant;
-[scriptable, uuid(4a91aeb3-4100-43ee-a21e-9866268757c5)]
-interface nsIXSLTProcessor : nsISupports
-{
+[Constructor]
+interface XSLTProcessor {
/**
* Import the stylesheet into this XSLTProcessor for transformations.
*
* @param style The root-node of a XSLT stylesheet. This can be either
* a document node or an element node. If a document node
* then the document can contain either a XSLT stylesheet
* or a LRE stylesheet.
* If the argument is an element node it must be the
* xsl:stylesheet (or xsl:transform) element of an XSLT
* stylesheet.
- *
- * @exception nsIXSLTException
*/
- void importStylesheet(in nsIDOMNode style);
+ [Throws]
+ void importStylesheet(Node style);
/**
* Transforms the node source applying the stylesheet given by
* the importStylesheet() function. The owner document of the output node
* owns the returned document fragment.
*
* @param source The node to be transformed
* @param output This document is used to generate the output
* @return DocumentFragment The result of the transformation
- *
- * @exception nsIXSLTException
*/
- nsIDOMDocumentFragment transformToFragment(in nsIDOMNode source,
- in nsIDOMDocument output);
+ [Throws]
+ DocumentFragment transformToFragment(Node source,
+ Document output);
/**
* Transforms the node source applying the stylesheet given by the
* importStylesheet() function.
*
* @param source The node to be transformed
* @return Document The result of the transformation
- *
- * @exception nsIXSLTException
*/
- nsIDOMDocument transformToDocument(in nsIDOMNode source);
+ [Throws]
+ Document transformToDocument(Node source);
/**
* Sets a parameter to be used in subsequent transformations with this
* nsIXSLTProcessor. If the parameter doesn't exist in the stylesheet the
* parameter will be ignored.
*
* @param namespaceURI The namespaceURI of the XSLT parameter
* @param localName The local name of the XSLT parameter
* @param value The new value of the XSLT parameter
- *
- * @exception NS_ERROR_ILLEGAL_VALUE The datatype of value is
- * not supported
*/
- void setParameter(in DOMString namespaceURI,
- in DOMString localName,
- in nsIVariant value);
+ [Throws]
+ void setParameter([TreatNullAs=EmptyString] DOMString namespaceURI,
+ DOMString localName,
+ any value);
/**
* Gets a parameter if previously set by setParameter. Returns null
* otherwise.
*
* @param namespaceURI The namespaceURI of the XSLT parameter
* @param localName The local name of the XSLT parameter
* @return nsIVariant The value of the XSLT parameter
*/
- nsIVariant getParameter(in DOMString namespaceURI,
- in DOMString localName);
+ [Throws]
+ nsIVariant? getParameter([TreatNullAs=EmptyString] DOMString namespaceURI,
+ DOMString localName);
/**
* Removes a parameter, if set. This will make the processor use the
* default-value for the parameter as specified in the stylesheet.
*
* @param namespaceURI The namespaceURI of the XSLT parameter
* @param localName The local name of the XSLT parameter
*/
- void removeParameter(in DOMString namespaceURI,
- in DOMString localName);
+ [Throws]
+ void removeParameter([TreatNullAs=EmptyString] DOMString namespaceURI,
+ DOMString localName);
/**
* Removes all set parameters from this nsIXSLTProcessor. This will make
* the processor use the default-value for all parameters as specified in
* the stylesheet.
*/
void clearParameters();
/**
* Remove all parameters and stylesheets from this nsIXSLTProcessor.
*/
void reset();
+
+ /**
+ * Disables all loading of external documents, such as from
+ * <xsl:import> and document()
+ * Defaults to off and is *not* reset by calls to reset()
+ */
+ [ChromeOnly]
+ const unsigned long DISABLE_ALL_LOADS = 1;
+
+ /**
+ * Flags for this processor. Defaults to 0. See individual flags above
+ * for documentation for effect of reset()
+ */
+ [ChromeOnly]
+ attribute unsigned long flags;
};
--- a/dom/webidl/moz.build
+++ b/dom/webidl/moz.build
@@ -523,16 +523,17 @@ WEBIDL_FILES = [
'XMLHttpRequest.webidl',
'XMLHttpRequestEventTarget.webidl',
'XMLHttpRequestUpload.webidl',
'XMLSerializer.webidl',
'XMLStylesheetProcessingInstruction.webidl',
'XPathEvaluator.webidl',
'XPathExpression.webidl',
'XPathResult.webidl',
+ 'XSLTProcessor.webidl',
'XULCommandEvent.webidl',
'XULDocument.webidl',
'XULElement.webidl',
]
if CONFIG['MOZ_AUDIO_CHANNEL_MANAGER']:
WEBIDL_FILES += [
'AudioChannelManager.webidl',
--- a/dom/xslt/base/moz.build
+++ b/dom/xslt/base/moz.build
@@ -1,16 +1,17 @@
# -*- Mode: python; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 40 -*-
# vim: set filetype=python:
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
UNIFIED_SOURCES += [
'txDouble.cpp',
+ 'txExpandedName.cpp',
'txExpandedNameMap.cpp',
'txList.cpp',
'txNamespaceMap.cpp',
'txURIUtils.cpp',
]
FAIL_ON_WARNINGS = True
copy from dom/xslt/xml/txXMLUtils.cpp
copy to dom/xslt/base/txExpandedName.cpp
--- a/dom/xslt/xml/txXMLUtils.cpp
+++ b/dom/xslt/base/txExpandedName.cpp
@@ -1,25 +1,19 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-/*
- * XML utility classes
- */
-
-#include "txXMLUtils.h"
+#include "txExpandedName.h"
#include "nsString.h"
#include "nsReadableUtils.h"
-#include "nsGkAtoms.h"
#include "txStringUtils.h"
#include "txNamespaceMap.h"
-#include "txXPathTreeWalker.h"
-#include "nsContentUtils.h"
+#include "txXMLUtils.h"
nsresult
txExpandedName::init(const nsAString& aQName, txNamespaceMap* aResolver,
bool aUseDefault)
{
const nsAFlatString& qName = PromiseFlatString(aQName);
const char16_t* colon;
bool valid = XMLUtils::isValidQName(qName, &colon);
@@ -40,172 +34,8 @@ txExpandedName::init(const nsAString& aQ
}
else {
mNamespaceID = aUseDefault ? aResolver->lookupNamespace(nullptr) :
kNameSpaceID_None;
mLocalName = do_GetAtom(aQName);
}
return NS_OK;
}
-
- //------------------------------/
- //- Implementation of XMLUtils -/
-//------------------------------/
-
-// static
-nsresult
-XMLUtils::splitExpatName(const char16_t *aExpatName, nsIAtom **aPrefix,
- nsIAtom **aLocalName, int32_t* aNameSpaceID)
-{
- /**
- * Expat can send the following:
- * localName
- * namespaceURI<separator>localName
- * namespaceURI<separator>localName<separator>prefix
- */
-
- const char16_t *uriEnd = nullptr;
- const char16_t *nameEnd = nullptr;
- const char16_t *pos;
- for (pos = aExpatName; *pos; ++pos) {
- if (*pos == kExpatSeparatorChar) {
- if (uriEnd) {
- nameEnd = pos;
- }
- else {
- uriEnd = pos;
- }
- }
- }
-
- const char16_t *nameStart;
- if (uriEnd) {
- *aNameSpaceID =
- txNamespaceManager::getNamespaceID(nsDependentSubstring(aExpatName,
- uriEnd));
- if (*aNameSpaceID == kNameSpaceID_Unknown) {
- return NS_ERROR_FAILURE;
- }
-
- nameStart = (uriEnd + 1);
- if (nameEnd) {
- const char16_t *prefixStart = nameEnd + 1;
- *aPrefix = NS_NewAtom(Substring(prefixStart, pos)).take();
- if (!*aPrefix) {
- return NS_ERROR_OUT_OF_MEMORY;
- }
- }
- else {
- nameEnd = pos;
- *aPrefix = nullptr;
- }
- }
- else {
- *aNameSpaceID = kNameSpaceID_None;
- nameStart = aExpatName;
- nameEnd = pos;
- *aPrefix = nullptr;
- }
-
- *aLocalName = NS_NewAtom(Substring(nameStart, nameEnd)).take();
-
- return *aLocalName ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
-}
-
-nsresult
-XMLUtils::splitQName(const nsAString& aName, nsIAtom** aPrefix,
- nsIAtom** aLocalName)
-{
- const nsAFlatString& qName = PromiseFlatString(aName);
- const char16_t* colon;
- bool valid = XMLUtils::isValidQName(qName, &colon);
- if (!valid) {
- return NS_ERROR_FAILURE;
- }
-
- if (colon) {
- const char16_t *end;
- qName.EndReading(end);
-
- *aPrefix = NS_NewAtom(Substring(qName.get(), colon)).take();
- *aLocalName = NS_NewAtom(Substring(colon + 1, end)).take();
- }
- else {
- *aPrefix = nullptr;
- *aLocalName = NS_NewAtom(aName).take();
- }
-
- return NS_OK;
-}
-
-/**
- * Returns true if the given string has only whitespace characters
- */
-bool XMLUtils::isWhitespace(const nsAFlatString& aText)
-{
- nsAFlatString::const_char_iterator start, end;
- aText.BeginReading(start);
- aText.EndReading(end);
- for ( ; start != end; ++start) {
- if (!isWhitespace(*start)) {
- return false;
- }
- }
- return true;
-}
-
-/**
- * Normalizes the value of a XML processing instruction
-**/
-void XMLUtils::normalizePIValue(nsAString& piValue)
-{
- nsAutoString origValue(piValue);
- uint32_t origLength = origValue.Length();
- uint32_t conversionLoop = 0;
- char16_t prevCh = 0;
- piValue.Truncate();
-
- while (conversionLoop < origLength) {
- char16_t ch = origValue.CharAt(conversionLoop);
- switch (ch) {
- case '>':
- {
- if (prevCh == '?') {
- piValue.Append(char16_t(' '));
- }
- break;
- }
- default:
- {
- break;
- }
- }
- piValue.Append(ch);
- prevCh = ch;
- ++conversionLoop;
- }
-}
-
-//static
-bool XMLUtils::isValidQName(const nsAFlatString& aQName,
- const char16_t** aColon)
-{
- return NS_SUCCEEDED(nsContentUtils::CheckQName(aQName, true, aColon));
-}
-
-//static
-bool XMLUtils::getXMLSpacePreserve(const txXPathNode& aNode)
-{
- nsAutoString value;
- txXPathTreeWalker walker(aNode);
- do {
- if (walker.getAttr(nsGkAtoms::space, kNameSpaceID_XML, value)) {
- if (TX_StringEqualsAtom(value, nsGkAtoms::preserve)) {
- return true;
- }
- if (TX_StringEqualsAtom(value, nsGkAtoms::_default)) {
- return false;
- }
- }
- } while (walker.moveToParent());
-
- return false;
-}
copy from dom/xslt/xml/txXMLUtils.h
copy to dom/xslt/base/txExpandedName.h
--- a/dom/xslt/xml/txXMLUtils.h
+++ b/dom/xslt/base/txExpandedName.h
@@ -1,32 +1,20 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-/**
- * An XML Utility class
-**/
+#ifndef TRANSFRMX_EXPANDEDNAME_H
+#define TRANSFRMX_EXPANDEDNAME_H
-#ifndef MITRE_XMLUTILS_H
-#define MITRE_XMLUTILS_H
-
-#include "txCore.h"
#include "nsCOMPtr.h"
-#include "nsDependentSubstring.h"
#include "nsIAtom.h"
-#include "txXPathNode.h"
+#include "mozilla/dom/NameSpaceConstants.h"
-#define kExpatSeparatorChar 0xFFFF
-
-extern "C" int MOZ_XMLIsLetter(const char* ptr);
-extern "C" int MOZ_XMLIsNCNameChar(const char* ptr);
-
-class nsIAtom;
class txNamespaceMap;
class txExpandedName {
public:
txExpandedName() : mNamespaceID(kNameSpaceID_None)
{
}
@@ -74,67 +62,9 @@ public:
return ((mLocalName != rhs.mLocalName) ||
(mNamespaceID != rhs.mNamespaceID));
}
int32_t mNamespaceID;
nsCOMPtr<nsIAtom> mLocalName;
};
-class XMLUtils {
-
-public:
- static nsresult splitExpatName(const char16_t *aExpatName,
- nsIAtom **aPrefix, nsIAtom **aLocalName,
- int32_t* aNameSpaceID);
- static nsresult splitQName(const nsAString& aName, nsIAtom** aPrefix,
- nsIAtom** aLocalName);
-
- /*
- * Returns true if the given character is whitespace.
- */
- static bool isWhitespace(const char16_t& aChar)
- {
- return (aChar <= ' ' &&
- (aChar == ' ' || aChar == '\r' ||
- aChar == '\n'|| aChar == '\t'));
- }
-
- /**
- * Returns true if the given string has only whitespace characters
- */
- static bool isWhitespace(const nsAFlatString& aText);
-
- /**
- * Normalizes the value of a XML processingInstruction
- **/
- static void normalizePIValue(nsAString& attValue);
-
- /**
- * Returns true if the given string is a valid XML QName
- */
- static bool isValidQName(const nsAFlatString& aQName,
- const char16_t** aColon);
-
- /**
- * Returns true if the given character represents an Alpha letter
- */
- static bool isLetter(char16_t aChar)
- {
- return !!MOZ_XMLIsLetter(reinterpret_cast<const char*>(&aChar));
- }
-
- /**
- * Returns true if the given character is an allowable NCName character
- */
- static bool isNCNameChar(char16_t aChar)
- {
- return !!MOZ_XMLIsNCNameChar(reinterpret_cast<const char*>(&aChar));
- }
-
- /*
- * Walks up the document tree and returns true if the closest xml:space
- * attribute is "preserve"
- */
- static bool getXMLSpacePreserve(const txXPathNode& aNode);
-};
-
#endif
--- a/dom/xslt/base/txExpandedNameMap.h
+++ b/dom/xslt/base/txExpandedNameMap.h
@@ -1,18 +1,19 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef TRANSFRMX_EXPANDEDNAMEMAP_H
#define TRANSFRMX_EXPANDEDNAMEMAP_H
+#include "nsAutoPtr.h"
#include "nsError.h"
-#include "txXMLUtils.h"
+#include "txExpandedName.h"
#include "nsTArray.h"
class txExpandedNameMap_base {
protected:
/**
* Adds an item, if an item with this key already exists an error is
* returned
* @param aKey key for item to add
--- a/dom/xslt/tests/mochitest/mochitest.ini
+++ b/dom/xslt/tests/mochitest/mochitest.ini
@@ -10,8 +10,9 @@
[test_bug551412.html]
[test_bug551654.html]
[test_bug566629.html]
[test_bug566629.xhtml]
[test_bug603159.html]
[test_bug616774.html]
[test_bug667315.html]
[test_exslt_regex.html]
+[test_parameter.html]
new file mode 100644
--- /dev/null
+++ b/dom/xslt/tests/mochitest/test_parameter.html
@@ -0,0 +1,31 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+ <title>Test for setParameter/getParameter</title>
+ <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+ <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
+</head>
+<body>
+<p id="display"></p>
+<div id="content" style="display: none"></div>
+<pre id="test">
+<script>
+ var processor = new XSLTProcessor();
+
+ processor.setParameter(null, "test", "hello");
+ is(processor.getParameter(null, "test"), "hello", "null namespace works");
+
+ processor.setParameter("foo", "bar", "foobar");
+ is(processor.getParameter("foo", "bar"), "foobar", "non-null namespace works");
+
+ processor.setParameter(null, "test", 123);
+ is(processor.getParameter(null, "test"), 123, "number value works");
+
+ processor.removeParameter(null, "test");
+ is(processor.getParameter(null, "test"), null, "removeParameter works");
+
+ is(processor.getParameter(null, "not-here"), null, "nonexistant parameter");
+</script>
+</pre>
+</body>
+</html>
--- a/dom/xslt/xml/txXMLUtils.cpp
+++ b/dom/xslt/xml/txXMLUtils.cpp
@@ -11,48 +11,18 @@
#include "nsString.h"
#include "nsReadableUtils.h"
#include "nsGkAtoms.h"
#include "txStringUtils.h"
#include "txNamespaceMap.h"
#include "txXPathTreeWalker.h"
#include "nsContentUtils.h"
-nsresult
-txExpandedName::init(const nsAString& aQName, txNamespaceMap* aResolver,
- bool aUseDefault)
-{
- const nsAFlatString& qName = PromiseFlatString(aQName);
- const char16_t* colon;
- bool valid = XMLUtils::isValidQName(qName, &colon);
- if (!valid) {
- return NS_ERROR_FAILURE;
- }
-
- if (colon) {
- nsCOMPtr<nsIAtom> prefix = do_GetAtom(Substring(qName.get(), colon));
- int32_t namespaceID = aResolver->lookupNamespace(prefix);
- if (namespaceID == kNameSpaceID_Unknown)
- return NS_ERROR_FAILURE;
- mNamespaceID = namespaceID;
-
- const char16_t *end;
- qName.EndReading(end);
- mLocalName = do_GetAtom(Substring(colon + 1, end));
- }
- else {
- mNamespaceID = aUseDefault ? aResolver->lookupNamespace(nullptr) :
- kNameSpaceID_None;
- mLocalName = do_GetAtom(aQName);
- }
- return NS_OK;
-}
-
- //------------------------------/
- //- Implementation of XMLUtils -/
+//------------------------------/
+//- Implementation of XMLUtils -/
//------------------------------/
// static
nsresult
XMLUtils::splitExpatName(const char16_t *aExpatName, nsIAtom **aPrefix,
nsIAtom **aLocalName, int32_t* aNameSpaceID)
{
/**
--- a/dom/xslt/xml/txXMLUtils.h
+++ b/dom/xslt/xml/txXMLUtils.h
@@ -6,83 +6,25 @@
/**
* An XML Utility class
**/
#ifndef MITRE_XMLUTILS_H
#define MITRE_XMLUTILS_H
#include "txCore.h"
-#include "nsCOMPtr.h"
#include "nsDependentSubstring.h"
-#include "nsIAtom.h"
#include "txXPathNode.h"
#define kExpatSeparatorChar 0xFFFF
extern "C" int MOZ_XMLIsLetter(const char* ptr);
extern "C" int MOZ_XMLIsNCNameChar(const char* ptr);
class nsIAtom;
-class txNamespaceMap;
-
-class txExpandedName {
-public:
- txExpandedName() : mNamespaceID(kNameSpaceID_None)
- {
- }
-
- txExpandedName(int32_t aNsID,
- nsIAtom* aLocalName) : mNamespaceID(aNsID),
- mLocalName(aLocalName)
- {
- }
-
- txExpandedName(const txExpandedName& aOther) :
- mNamespaceID(aOther.mNamespaceID),
- mLocalName(aOther.mLocalName)
- {
- }
-
- nsresult init(const nsAString& aQName, txNamespaceMap* aResolver,
- bool aUseDefault);
-
- void reset()
- {
- mNamespaceID = kNameSpaceID_None;
- mLocalName = nullptr;
- }
-
- bool isNull()
- {
- return mNamespaceID == kNameSpaceID_None && !mLocalName;
- }
-
- txExpandedName& operator = (const txExpandedName& rhs)
- {
- mNamespaceID = rhs.mNamespaceID;
- mLocalName = rhs.mLocalName;
- return *this;
- }
-
- bool operator == (const txExpandedName& rhs) const
- {
- return ((mLocalName == rhs.mLocalName) &&
- (mNamespaceID == rhs.mNamespaceID));
- }
-
- bool operator != (const txExpandedName& rhs) const
- {
- return ((mLocalName != rhs.mLocalName) ||
- (mNamespaceID != rhs.mNamespaceID));
- }
-
- int32_t mNamespaceID;
- nsCOMPtr<nsIAtom> mLocalName;
-};
class XMLUtils {
public:
static nsresult splitExpatName(const char16_t *aExpatName,
nsIAtom **aPrefix, nsIAtom **aLocalName,
int32_t* aNameSpaceID);
static nsresult splitQName(const nsAString& aName, nsIAtom** aPrefix,
--- a/dom/xslt/xslt/moz.build
+++ b/dom/xslt/xslt/moz.build
@@ -1,14 +1,18 @@
# -*- Mode: python; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 40 -*-
# vim: set filetype=python:
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+EXPORTS.mozilla.dom += [
+ 'txMozillaXSLTProcessor.h'
+]
+
UNIFIED_SOURCES += [
'txBufferingHandler.cpp',
'txCurrentFunctionCall.cpp',
'txDocumentFunctionCall.cpp',
'txExecutionState.cpp',
'txEXSLTFunctions.cpp',
'txFormatNumberFunctionCall.cpp',
'txGenerateIdFunctionCall.cpp',
--- a/dom/xslt/xslt/txInstructions.h
+++ b/dom/xslt/xslt/txInstructions.h
@@ -5,16 +5,17 @@
#ifndef TRANSFRMX_TXINSTRUCTIONS_H
#define TRANSFRMX_TXINSTRUCTIONS_H
#include "nsCOMPtr.h"
#include "txCore.h"
#include "nsString.h"
#include "txXMLUtils.h"
+#include "txExpandedName.h"
#include "txNamespaceMap.h"
#include "nsAutoPtr.h"
#include "txXSLTNumber.h"
#include "nsTArray.h"
class nsIAtom;
class txExecutionState;
--- a/dom/xslt/xslt/txMozillaXSLTProcessor.cpp
+++ b/dom/xslt/xslt/txMozillaXSLTProcessor.cpp
@@ -6,17 +6,16 @@
#include "txMozillaXSLTProcessor.h"
#include "nsContentCID.h"
#include "nsError.h"
#include "nsIChannel.h"
#include "mozilla/dom/Element.h"
#include "nsIDOMElement.h"
#include "nsIDOMText.h"
#include "nsIDocument.h"
-#include "nsDOMClassInfoID.h"
#include "nsIDOMDocument.h"
#include "nsIDOMDocumentFragment.h"
#include "nsIDOMNodeList.h"
#include "nsIIOService.h"
#include "nsILoadGroup.h"
#include "nsIStringBundle.h"
#include "nsIURI.h"
#include "nsNetUtil.h"
@@ -31,16 +30,18 @@
#include "nsIPrincipal.h"
#include "nsThreadUtils.h"
#include "jsapi.h"
#include "txExprParser.h"
#include "nsIErrorService.h"
#include "nsIScriptSecurityManager.h"
#include "nsJSUtils.h"
#include "nsIXPConnect.h"
+#include "mozilla/dom/DocumentFragment.h"
+#include "mozilla/dom/XSLTProcessorBinding.h"
using namespace mozilla::dom;
static NS_DEFINE_CID(kXMLDocumentCID, NS_XMLDOCUMENT_CID);
/**
* Output Handler Factories
*/
@@ -321,37 +322,47 @@ ImplCycleCollectionTraverse(nsCycleColle
aName, aFlags);
}
}
/**
* txMozillaXSLTProcessor
*/
-NS_IMPL_CYCLE_COLLECTION(txMozillaXSLTProcessor, mEmbeddedStylesheetRoot,
- mSource, mVariables)
+NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(txMozillaXSLTProcessor,
+ mOwner, mEmbeddedStylesheetRoot,
+ mSource, mVariables)
NS_IMPL_CYCLE_COLLECTING_ADDREF(txMozillaXSLTProcessor)
NS_IMPL_CYCLE_COLLECTING_RELEASE(txMozillaXSLTProcessor)
-DOMCI_DATA(XSLTProcessor, txMozillaXSLTProcessor)
-
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(txMozillaXSLTProcessor)
+ NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
NS_INTERFACE_MAP_ENTRY(nsIXSLTProcessor)
NS_INTERFACE_MAP_ENTRY(nsIXSLTProcessorPrivate)
NS_INTERFACE_MAP_ENTRY(nsIDocumentTransformer)
NS_INTERFACE_MAP_ENTRY(nsIMutationObserver)
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIXSLTProcessor)
- NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(XSLTProcessor)
NS_INTERFACE_MAP_END
-txMozillaXSLTProcessor::txMozillaXSLTProcessor() : mStylesheetDocument(nullptr),
- mTransformResult(NS_OK),
- mCompileResult(NS_OK),
- mFlags(0)
+txMozillaXSLTProcessor::txMozillaXSLTProcessor()
+ : mOwner(nullptr),
+ mStylesheetDocument(nullptr),
+ mTransformResult(NS_OK),
+ mCompileResult(NS_OK),
+ mFlags(0)
+{
+}
+
+txMozillaXSLTProcessor::txMozillaXSLTProcessor(nsISupports* aOwner)
+ : mOwner(aOwner),
+ mStylesheetDocument(nullptr),
+ mTransformResult(NS_OK),
+ mCompileResult(NS_OK),
+ mFlags(0)
{
}
txMozillaXSLTProcessor::~txMozillaXSLTProcessor()
{
if (mStylesheetDocument) {
mStylesheetDocument->RemoveMutationObserver(this);
}
@@ -1257,16 +1268,90 @@ txMozillaXSLTProcessor::ContentRemoved(n
nsIContent* aContainer,
nsIContent* aChild,
int32_t aIndexInContainer,
nsIContent* aPreviousSibling)
{
mStylesheet = nullptr;
}
+/* virtual */ JSObject*
+txMozillaXSLTProcessor::WrapObject(JSContext* aCx)
+{
+ return XSLTProcessorBinding::Wrap(aCx, this);
+}
+
+
+/* static */ already_AddRefed<txMozillaXSLTProcessor>
+txMozillaXSLTProcessor::Constructor(const GlobalObject& aGlobal,
+ mozilla::ErrorResult& aRv)
+{
+ nsRefPtr<txMozillaXSLTProcessor> processor =
+ new txMozillaXSLTProcessor(aGlobal.GetAsSupports());
+ return processor.forget();
+}
+
+void
+txMozillaXSLTProcessor::ImportStylesheet(nsINode& stylesheet,
+ mozilla::ErrorResult& aRv)
+{
+ aRv = ImportStylesheet(stylesheet.AsDOMNode());
+}
+
+already_AddRefed<DocumentFragment>
+txMozillaXSLTProcessor::TransformToFragment(nsINode& source,
+ nsIDocument& docVal,
+ mozilla::ErrorResult& aRv)
+{
+ nsCOMPtr<nsIDOMDocumentFragment> fragment;
+ nsCOMPtr<nsIDOMDocument> domDoc = do_QueryInterface(&docVal);
+ if (!domDoc) {
+ aRv.Throw(NS_ERROR_FAILURE);
+ return nullptr;
+ }
+ aRv = TransformToFragment(source.AsDOMNode(), domDoc, getter_AddRefs(fragment));
+ return fragment.forget().downcast<DocumentFragment>();
+}
+
+already_AddRefed<nsIDocument>
+txMozillaXSLTProcessor::TransformToDocument(nsINode& source,
+ mozilla::ErrorResult& aRv)
+{
+ nsCOMPtr<nsIDOMDocument> document;
+ aRv = TransformToDocument(source.AsDOMNode(), getter_AddRefs(document));
+ nsCOMPtr<nsIDocument> domDoc = do_QueryInterface(document);
+ return domDoc.forget();
+}
+
+void
+txMozillaXSLTProcessor::SetParameter(JSContext* aCx,
+ const nsAString& aNamespaceURI,
+ const nsAString& aLocalName,
+ JS::Handle<JS::Value> aValue,
+ mozilla::ErrorResult& aRv)
+{
+ nsCOMPtr<nsIVariant> val;
+ aRv = nsContentUtils::XPConnect()->JSToVariant(aCx, aValue,
+ getter_AddRefs(val));
+ if (aRv.Failed()) {
+ return;
+ }
+ aRv = SetParameter(aNamespaceURI, aLocalName, val);
+}
+
+nsIVariant*
+txMozillaXSLTProcessor::GetParameter(const nsAString& aNamespaceURI,
+ const nsAString& aLocalName,
+ mozilla::ErrorResult& aRv)
+{
+ nsCOMPtr<nsIVariant> val;
+ aRv = GetParameter(aNamespaceURI, aLocalName, getter_AddRefs(val));
+ return val;
+}
+
/* static*/
nsresult
txMozillaXSLTProcessor::Startup()
{
if (!txXSLTProcessor::init()) {
return NS_ERROR_OUT_OF_MEMORY;
}
--- a/dom/xslt/xslt/txMozillaXSLTProcessor.h
+++ b/dom/xslt/xslt/txMozillaXSLTProcessor.h
@@ -9,52 +9,66 @@
#include "nsAutoPtr.h"
#include "nsStubMutationObserver.h"
#include "nsIDocumentTransformer.h"
#include "nsIXSLTProcessor.h"
#include "nsIXSLTProcessorPrivate.h"
#include "txExpandedNameMap.h"
#include "txNamespaceMap.h"
#include "nsCycleCollectionParticipant.h"
+#include "nsWrapperCache.h"
#include "mozilla/Attributes.h"
+#include "mozilla/ErrorResult.h"
+class nsINode;
class nsIDOMNode;
class nsIURI;
class nsIXMLContentSink;
class txStylesheet;
class txResultRecycler;
class txIGlobalParameter;
+namespace mozilla {
+namespace dom {
+
+class Document;
+class DocumentFragment;
+class GlobalObject;
+
+}
+}
+
/* bacd8ad0-552f-11d3-a9f7-000064657374 */
#define TRANSFORMIIX_XSLT_PROCESSOR_CID \
{ 0x618ee71d, 0xd7a7, 0x41a1, {0xa3, 0xfb, 0xc2, 0xbe, 0xdc, 0x6a, 0x21, 0x7e} }
#define TRANSFORMIIX_XSLT_PROCESSOR_CONTRACTID \
"@mozilla.org/document-transformer;1?type=xslt"
#define XSLT_MSGS_URL "chrome://global/locale/xslt/xslt.properties"
/**
* txMozillaXSLTProcessor is a front-end to the XSLT Processor.
*/
class txMozillaXSLTProcessor MOZ_FINAL : public nsIXSLTProcessor,
public nsIXSLTProcessorPrivate,
public nsIDocumentTransformer,
- public nsStubMutationObserver
+ public nsStubMutationObserver,
+ public nsWrapperCache
{
public:
/**
* Creates a new txMozillaXSLTProcessor
*/
txMozillaXSLTProcessor();
// nsISupports interface
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
- NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(txMozillaXSLTProcessor,
- nsIXSLTProcessor)
+ NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_AMBIGUOUS(txMozillaXSLTProcessor,
+ nsIXSLTProcessor)
// nsIXSLTProcessor interface
NS_DECL_NSIXSLTPROCESSOR
// nsIXSLTProcessorPrivate interface
NS_DECL_NSIXSLTPROCESSORPRIVATE
// nsIDocumentTransformer interface
@@ -73,16 +87,59 @@ public:
// nsIMutationObserver interface
NS_DECL_NSIMUTATIONOBSERVER_CHARACTERDATACHANGED
NS_DECL_NSIMUTATIONOBSERVER_ATTRIBUTECHANGED
NS_DECL_NSIMUTATIONOBSERVER_CONTENTAPPENDED
NS_DECL_NSIMUTATIONOBSERVER_CONTENTINSERTED
NS_DECL_NSIMUTATIONOBSERVER_CONTENTREMOVED
NS_DECL_NSIMUTATIONOBSERVER_NODEWILLBEDESTROYED
+ // nsWrapperCache
+ virtual JSObject* WrapObject(JSContext* aCx) MOZ_OVERRIDE;
+
+ // WebIDL
+ nsISupports*
+ GetParentObject() const
+ {
+ return mOwner;
+ }
+
+ static already_AddRefed<txMozillaXSLTProcessor>
+ Constructor(const mozilla::dom::GlobalObject& aGlobal,
+ mozilla::ErrorResult& aRv);
+
+ void ImportStylesheet(nsINode& stylesheet,
+ mozilla::ErrorResult& aRv);
+ already_AddRefed<mozilla::dom::DocumentFragment>
+ TransformToFragment(nsINode& source, nsIDocument& docVal, mozilla::ErrorResult& aRv);
+ already_AddRefed<nsIDocument>
+ TransformToDocument(nsINode& source, mozilla::ErrorResult& aRv);
+
+ void SetParameter(JSContext* aCx,
+ const nsAString& aNamespaceURI,
+ const nsAString& aLocalName,
+ JS::Handle<JS::Value> aValue,
+ mozilla::ErrorResult& aRv);
+ nsIVariant* GetParameter(const nsAString& aNamespaceURI,
+ const nsAString& aLocalName,
+ mozilla::ErrorResult& aRv);
+ void RemoveParameter(const nsAString& aNamespaceURI,
+ const nsAString& aLocalName,
+ mozilla::ErrorResult& aRv)
+ {
+ aRv = RemoveParameter(aNamespaceURI, aLocalName);
+ }
+
+ uint32_t Flags()
+ {
+ uint32_t flags;
+ GetFlags(&flags);
+ return flags;
+ }
+
nsresult setStylesheet(txStylesheet* aStylesheet);
void reportError(nsresult aResult, const char16_t *aErrorText,
const char16_t *aSourceText);
nsIDOMNode *GetSourceContentModel()
{
return mSource;
}
@@ -94,25 +151,28 @@ public:
{
return (mFlags & DISABLE_ALL_LOADS) != 0;
}
static nsresult Startup();
static void Shutdown();
private:
+ txMozillaXSLTProcessor(nsISupports* aOwner);
/**
* Default destructor for txMozillaXSLTProcessor
*/
~txMozillaXSLTProcessor();
nsresult DoTransform();
void notifyError();
nsresult ensureStylesheet();
+ nsCOMPtr<nsISupports> mOwner;
+
nsRefPtr<txStylesheet> mStylesheet;
nsIDocument* mStylesheetDocument; // weak
nsCOMPtr<nsIContent> mEmbeddedStylesheetRoot;
nsCOMPtr<nsIDOMNode> mSource;
nsresult mTransformResult;
nsresult mCompileResult;
nsString mErrorText, mSourceText;
--- a/dom/xslt/xslt/txOutputFormat.cpp
+++ b/dom/xslt/xslt/txOutputFormat.cpp
@@ -1,15 +1,16 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "txOutputFormat.h"
#include "txXMLUtils.h"
+#include "txExpandedName.h"
txOutputFormat::txOutputFormat() : mMethod(eMethodNotSet),
mOmitXMLDeclaration(eNotSet),
mStandalone(eNotSet),
mIndent(eNotSet)
{
}
--- a/dom/xslt/xslt/txXSLTEnvironmentFunctionCall.cpp
+++ b/dom/xslt/xslt/txXSLTEnvironmentFunctionCall.cpp
@@ -3,16 +3,17 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "txIXPathContext.h"
#include "nsGkAtoms.h"
#include "nsError.h"
#include "txXMLUtils.h"
#include "txXSLTFunctions.h"
+#include "txExpandedName.h"
#include "txNamespaceMap.h"
nsresult
txXSLTEnvironmentFunctionCall::evaluate(txIEvalContext* aContext,
txAExprResult** aResult)
{
*aResult = nullptr;
--- a/dom/xslt/xslt/txXSLTPatterns.h
+++ b/dom/xslt/xslt/txXSLTPatterns.h
@@ -2,16 +2,17 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef TX_XSLT_PATTERNS_H
#define TX_XSLT_PATTERNS_H
#include "mozilla/Attributes.h"
+#include "txExpandedName.h"
#include "txExpr.h"
#include "txXMLUtils.h"
class ProcessorState;
class txPattern
{
public: