Bug 1018658 - Convert XPathNSResolver to WebIDL bindings, support passing a node to CreateExpression. r=bz.

--HG--
extra : rebase_source : 347e0145d5caf1cc525bfed70af2ad81a57b2a06
This commit is contained in:
Peter Van der Beken 2013-09-02 18:01:55 +02:00
parent 7e863a5326
commit fe568cf0a5
3 changed files with 50 additions and 17 deletions

View File

@ -9,7 +9,6 @@
#include "nsIDOMNode.h"
#include "nsIDOMElement.h"
#include "nsIDOMEvent.h"
#include "nsIDOMXPathNSResolver.h"
#include "nsIDocument.h"
#include "nsIContent.h"
#include "nsComponentManagerUtils.h"
@ -428,13 +427,7 @@ nsXULTemplateQueryProcessorXML::CreateExpression(const nsAString& aExpr,
nsINode* aNode,
ErrorResult& aRv)
{
nsCOMPtr<nsIDOMXPathNSResolver> nsResolver =
aNode->OwnerDoc()->CreateNSResolver(aNode, aRv);
if (aRv.Failed()) {
return nullptr;
}
return mEvaluator->CreateExpression(aExpr, nsResolver, aRv);
return mEvaluator->CreateExpression(aExpr, aNode, aRv);
}
NS_IMETHODIMP

View File

@ -39,6 +39,15 @@ public:
XPathEvaluatorParseContext(nsIDOMXPathNSResolver* aResolver,
bool aIsCaseSensitive)
: mResolver(aResolver),
mResolverNode(nullptr),
mLastError(NS_OK),
mIsCaseSensitive(aIsCaseSensitive)
{
}
XPathEvaluatorParseContext(nsINode* aResolver,
bool aIsCaseSensitive)
: mResolver(nullptr),
mResolverNode(aResolver),
mLastError(NS_OK),
mIsCaseSensitive(aIsCaseSensitive)
{
@ -57,6 +66,7 @@ public:
private:
nsIDOMXPathNSResolver* mResolver;
nsINode* mResolverNode;
nsresult mLastError;
bool mIsCaseSensitive;
};
@ -120,21 +130,36 @@ XPathEvaluator::Evaluate(const nsAString & aExpression,
return NS_OK;
}
XPathExpression*
XPathEvaluator::CreateExpression(const nsAString& aExpression,
nsIDOMXPathNSResolver* aResolver, ErrorResult& aRv)
{
nsCOMPtr<nsIDocument> doc = do_QueryReferent(mDocument);
XPathEvaluatorParseContext pContext(aResolver, !(doc && doc->IsHTML()));
return CreateExpression(aExpression, &pContext, doc, aRv);
}
XPathExpression*
XPathEvaluator::CreateExpression(const nsAString& aExpression,
nsINode* aResolver, ErrorResult& aRv)
{
nsCOMPtr<nsIDocument> doc = do_QueryReferent(mDocument);
XPathEvaluatorParseContext pContext(aResolver, !(doc && doc->IsHTML()));
return CreateExpression(aExpression, &pContext, doc, aRv);
}
XPathExpression*
XPathEvaluator::CreateExpression(const nsAString & aExpression,
nsIDOMXPathNSResolver *aResolver,
txIParseContext* aContext,
nsIDocument* aDocument,
ErrorResult& aRv)
{
if (!mRecycler) {
mRecycler = new txResultRecycler;
}
nsCOMPtr<nsIDocument> doc = do_QueryReferent(mDocument);
XPathEvaluatorParseContext pContext(aResolver, !(doc && doc->IsHTML()));
nsAutoPtr<Expr> expression;
aRv = txExprParser::createExpr(PromiseFlatString(aExpression), &pContext,
aRv = txExprParser::createExpr(PromiseFlatString(aExpression), aContext,
getter_Transfers(expression));
if (aRv.Failed()) {
if (aRv.ErrorCode() != NS_ERROR_DOM_NAMESPACE_ERR) {
@ -144,7 +169,7 @@ XPathEvaluator::CreateExpression(const nsAString & aExpression,
return nullptr;
}
return new XPathExpression(Move(expression), mRecycler, doc);
return new XPathExpression(Move(expression), mRecycler, aDocument);
}
JSObject*
@ -197,7 +222,7 @@ nsresult XPathEvaluatorParseContext::resolveNamespacePrefix
{
aID = kNameSpaceID_Unknown;
if (!mResolver) {
if (!mResolver && !mResolverNode) {
return NS_ERROR_DOM_NAMESPACE_ERR;
}
@ -207,8 +232,12 @@ nsresult XPathEvaluatorParseContext::resolveNamespacePrefix
}
nsVoidableString ns;
nsresult rv = mResolver->LookupNamespaceURI(prefix, ns);
NS_ENSURE_SUCCESS(rv, rv);
if (mResolver) {
nsresult rv = mResolver->LookupNamespaceURI(prefix, ns);
NS_ENSURE_SUCCESS(rv, rv);
} else {
mResolverNode->LookupNamespaceURI(prefix, ns);
}
if (DOMStringIsNull(ns)) {
return NS_ERROR_DOM_NAMESPACE_ERR;

View File

@ -15,6 +15,7 @@
#include "nsIDocument.h"
class nsINode;
class txIParseContext;
class txResultRecycler;
namespace mozilla {
@ -54,12 +55,22 @@ public:
ErrorResult& rv);
already_AddRefed<nsIDOMXPathNSResolver>
CreateNSResolver(nsINode* aNodeResolver, ErrorResult& rv);
XPathExpression*
CreateExpression(const nsAString& aExpression,
nsINode* aResolver,
ErrorResult& aRv);
already_AddRefed<XPathResult>
Evaluate(JSContext* aCx, const nsAString& aExpression,
nsINode* aContextNode, nsIDOMXPathNSResolver* aResolver,
uint16_t aType, JS::Handle<JSObject*> aResult,
ErrorResult& rv);
private:
XPathExpression*
CreateExpression(const nsAString& aExpression,
txIParseContext* aContext,
nsIDocument* aDocument,
ErrorResult& aRv);
nsWeakPtr mDocument;
nsRefPtr<txResultRecycler> mRecycler;
};