mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
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:
parent
7e863a5326
commit
fe568cf0a5
@ -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
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user