Bug 908997 - Simplify XPathEvaluator - remove nsIXPathEvaluatorInternal. r=bz.

--HG--
rename : content/xslt/src/xpath/nsXPathEvaluator.cpp => content/xslt/src/xpath/XPathEvaluator.cpp
rename : content/xslt/src/xpath/nsXPathEvaluator.h => content/xslt/src/xpath/XPathEvaluator.h
extra : rebase_source : 3aa2f8f50c683b641904a0653a128c06cf1afb30
This commit is contained in:
Peter Van der Beken 2013-07-04 17:29:29 +02:00
parent be4411155f
commit 1d7a65fbba
6 changed files with 6 additions and 162 deletions

View File

@ -61,7 +61,6 @@ EXPORTS += [
'nsINodeList.h',
'nsIScriptElement.h',
'nsIStyleSheetLinkingElement.h',
'nsIXPathEvaluatorInternal.h',
'nsLineBreaker.h',
'nsReferencedElement.h',
'nsTreeSanitizer.h',

View File

@ -1,43 +0,0 @@
/* -*- Mode: IDL; 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 nsIXPathEvaluatorInternal_h__
#define nsIXPathEvaluatorInternal_h__
#include "nsCOMArray.h"
#include "nsTArray.h"
#include "nsStringGlue.h"
class nsIDOMDocument;
class nsIDOMXPathExpression;
class nsIDOMXPathNSResolver;
#define NS_IXPATHEVALUATORINTERNAL_IID \
{0xb4b72daa, 0x65d6, 0x440f, \
{ 0xb6, 0x08, 0xe2, 0xee, 0x9a, 0x82, 0xf3, 0x13 }}
class nsIXPathEvaluatorInternal : public nsISupports
{
public:
NS_DECLARE_STATIC_IID_ACCESSOR(NS_IXPATHEVALUATORINTERNAL_IID)
/**
* Sets the document this evaluator corresponds to
*/
NS_IMETHOD SetDocument(nsIDOMDocument* aDocument) = 0;
NS_IMETHOD CreateExpression(const nsAString &aExpression,
nsIDOMXPathNSResolver *aResolver,
nsTArray<nsString> *aNamespaceURIs,
nsTArray<nsCString> *aContractIDs,
nsCOMArray<nsISupports> *aState,
nsIDOMXPathExpression **aResult) = 0;
};
NS_DEFINE_STATIC_IID_ACCESSOR(nsIXPathEvaluatorInternal,
NS_IXPATHEVALUATORINTERNAL_IID)
#endif //nsIXPathEvaluatorInternal_h__

View File

@ -102,7 +102,6 @@
#include "nsIDOMXPathEvaluator.h"
#include "nsIDOMXPathExpression.h"
#include "nsIDOMXPathNSResolver.h"
#include "nsIXPathEvaluatorInternal.h"
#include "nsIParserService.h"
#include "nsContentCreatorFunctions.h"
@ -1586,8 +1585,7 @@ NS_INTERFACE_TABLE_HEAD(nsDocument)
NS_INTERFACE_TABLE_TO_MAP_SEGUE_CYCLE_COLLECTION(nsDocument)
NS_INTERFACE_MAP_ENTRY_TEAROFF(nsIDOMXPathNSResolver,
new nsNode3Tearoff(this))
if (aIID.Equals(NS_GET_IID(nsIDOMXPathEvaluator)) ||
aIID.Equals(NS_GET_IID(nsIXPathEvaluatorInternal))) {
if (aIID.Equals(NS_GET_IID(nsIDOMXPathEvaluator))) {
if (!mXPathEvaluatorTearoff) {
nsresult rv;
mXPathEvaluatorTearoff =

View File

@ -34,20 +34,11 @@ class XPathEvaluatorParseContext : public txIParseContext
{
public:
XPathEvaluatorParseContext(nsIDOMXPathNSResolver* aResolver,
nsTArray<int32_t> *aNamespaceIDs,
nsTArray<nsCString> *aContractIDs,
nsCOMArray<nsISupports> *aState,
bool aIsCaseSensitive)
: mResolver(aResolver),
mNamespaceIDs(aNamespaceIDs),
mContractIDs(aContractIDs),
mState(aState),
mLastError(NS_OK),
mIsCaseSensitive(aIsCaseSensitive)
{
NS_ASSERTION(mContractIDs ||
(!mNamespaceIDs || mNamespaceIDs->Length() == 0),
"Need contract IDs if there are namespaces.");
}
nsresult getError()
@ -63,9 +54,6 @@ public:
private:
nsIDOMXPathNSResolver* mResolver;
nsTArray<int32_t> *mNamespaceIDs;
nsTArray<nsCString> *mContractIDs;
nsCOMArray<nsISupports> *mState;
nsresult mLastError;
bool mIsCaseSensitive;
};
@ -73,31 +61,14 @@ private:
NS_IMPL_AGGREGATED(XPathEvaluator)
NS_INTERFACE_MAP_BEGIN_AGGREGATED(XPathEvaluator)
NS_INTERFACE_MAP_ENTRY(nsIDOMXPathEvaluator)
NS_INTERFACE_MAP_ENTRY(nsIXPathEvaluatorInternal)
NS_INTERFACE_MAP_END
XPathEvaluator::XPathEvaluator(nsISupports *aOuter)
: mDocument(do_GetWeakReference(aOuter))
{
NS_INIT_AGGREGATED(aOuter);
}
nsresult
XPathEvaluator::Init()
{
nsCOMPtr<nsIDOMDocument> document = do_QueryInterface(fOuter);
return document ? SetDocument(document) : NS_OK;
}
NS_IMETHODIMP
XPathEvaluator::CreateExpression(const nsAString & aExpression,
nsIDOMXPathNSResolver *aResolver,
nsIDOMXPathExpression **aResult)
{
return CreateExpression(aExpression, aResolver, (nsTArray<int32_t>*)nullptr,
nullptr, nullptr, aResult);
}
NS_IMETHODIMP
XPathEvaluator::CreateNSResolver(nsIDOMNode *aNodeResolver,
nsIDOMXPathNSResolver **aResult)
@ -130,54 +101,9 @@ XPathEvaluator::Evaluate(const nsAString & aExpression,
}
NS_IMETHODIMP
XPathEvaluator::SetDocument(nsIDOMDocument* aDocument)
{
mDocument = do_GetWeakReference(aDocument);
return NS_OK;
}
NS_IMETHODIMP
XPathEvaluator::CreateExpression(const nsAString & aExpression,
nsIDOMXPathNSResolver *aResolver,
nsTArray<nsString> *aNamespaceURIs,
nsTArray<nsCString> *aContractIDs,
nsCOMArray<nsISupports> *aState,
nsIDOMXPathExpression **aResult)
{
nsTArray<int32_t> namespaceIDs;
if (aNamespaceURIs) {
uint32_t count = aNamespaceURIs->Length();
if (!aContractIDs || aContractIDs->Length() != count) {
return NS_ERROR_FAILURE;
}
if (!namespaceIDs.SetLength(count)) {
return NS_ERROR_OUT_OF_MEMORY;
}
uint32_t i;
for (i = 0; i < count; ++i) {
if (aContractIDs->ElementAt(i).IsEmpty()) {
return NS_ERROR_FAILURE;
}
nsContentUtils::NameSpaceManager()->RegisterNameSpace(aNamespaceURIs->ElementAt(i), namespaceIDs[i]);
}
}
return CreateExpression(aExpression, aResolver, &namespaceIDs, aContractIDs,
aState, aResult);
}
nsresult
XPathEvaluator::CreateExpression(const nsAString & aExpression,
nsIDOMXPathNSResolver *aResolver,
nsTArray<int32_t> *aNamespaceIDs,
nsTArray<nsCString> *aContractIDs,
nsCOMArray<nsISupports> *aState,
nsIDOMXPathExpression **aResult)
{
nsresult rv;
@ -192,9 +118,7 @@ XPathEvaluator::CreateExpression(const nsAString & aExpression,
}
nsCOMPtr<nsIDocument> doc = do_QueryReferent(mDocument);
XPathEvaluatorParseContext pContext(aResolver, aNamespaceIDs,
aContractIDs, aState,
!(doc && doc->IsHTML()));
XPathEvaluatorParseContext pContext(aResolver, !(doc && doc->IsHTML()));
nsAutoPtr<Expr> expression;
rv = txExprParser::createExpr(PromiseFlatString(aExpression), &pContext,
@ -230,7 +154,6 @@ XPathEvaluator::Constructor(const GlobalObject& aGlobal,
ErrorResult& rv)
{
nsRefPtr<XPathEvaluator> newObj = new XPathEvaluator(nullptr);
newObj->Init();
return newObj.forget();
}
@ -309,21 +232,7 @@ XPathEvaluatorParseContext::resolveFunctionCall(nsIAtom* aName,
int32_t aID,
FunctionCall** aFn)
{
nsresult rv = NS_ERROR_XPATH_UNKNOWN_FUNCTION;
uint32_t i, count = mNamespaceIDs ? mNamespaceIDs->Length() : 0;
for (i = 0; i < count; ++i) {
if (mNamespaceIDs->ElementAt(i) == aID) {
nsISupports *state = mState ? mState->SafeObjectAt(i) : nullptr;
rv = TX_ResolveFunctionCallXPCOM(mContractIDs->ElementAt(i), aID,
aName, state, aFn);
if (NS_SUCCEEDED(rv)) {
break;
}
}
}
return rv;
return NS_ERROR_XPATH_UNKNOWN_FUNCTION;
}
bool XPathEvaluatorParseContext::caseInsensitiveNameTests()

View File

@ -7,13 +7,11 @@
#define mozilla_dom_XPathEvaluator_h
#include "nsIDOMXPathEvaluator.h"
#include "nsIXPathEvaluatorInternal.h"
#include "nsIWeakReference.h"
#include "nsAutoPtr.h"
#include "nsString.h"
#include "txResultRecycler.h"
#include "nsAgg.h"
#include "nsTArray.h"
#include "mozilla/Attributes.h"
#include "mozilla/ErrorResult.h"
@ -27,8 +25,7 @@ class GlobalObject;
/**
* A class for evaluating an XPath expression string
*/
class XPathEvaluator MOZ_FINAL : public nsIDOMXPathEvaluator,
public nsIXPathEvaluatorInternal
class XPathEvaluator MOZ_FINAL : public nsIDOMXPathEvaluator
{
public:
XPathEvaluator(nsISupports *aOuter);
@ -41,15 +38,6 @@ public:
// nsIDOMXPathEvaluator interface
NS_DECL_NSIDOMXPATHEVALUATOR
// nsIXPathEvaluatorInternal interface
NS_IMETHOD SetDocument(nsIDOMDocument* aDocument) MOZ_OVERRIDE;
NS_IMETHOD CreateExpression(const nsAString &aExpression,
nsIDOMXPathNSResolver *aResolver,
nsTArray<nsString> *aNamespaceURIs,
nsTArray<nsCString> *aContractIDs,
nsCOMArray<nsISupports> *aState,
nsIDOMXPathExpression **aResult) MOZ_OVERRIDE;
// WebIDL API
JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aScope);
static already_AddRefed<XPathEvaluator>
@ -65,13 +53,6 @@ public:
nsIDOMXPathNSResolver* aResolver, uint16_t aType,
nsISupports* aResult, ErrorResult& rv);
private:
nsresult CreateExpression(const nsAString & aExpression,
nsIDOMXPathNSResolver *aResolver,
nsTArray<int32_t> *aNamespaceIDs,
nsTArray<nsCString> *aContractIDs,
nsCOMArray<nsISupports> *aState,
nsIDOMXPathExpression **aResult);
nsWeakPtr mDocument;
nsRefPtr<txResultRecycler> mRecycler;
};

View File

@ -262,7 +262,7 @@ using mozilla::dom::time::TimeService;
// Factory Constructor
NS_GENERIC_FACTORY_CONSTRUCTOR(txMozillaXSLTProcessor)
NS_GENERIC_AGGREGATED_CONSTRUCTOR_INIT(XPathEvaluator, Init)
NS_GENERIC_AGGREGATED_CONSTRUCTOR(XPathEvaluator)
NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(txNodeSetAdaptor, Init)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsDOMSerializer)
NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsXMLHttpRequest, Init)