From 41bff5a09a70ecc2cbadc23168fda46366912d2e Mon Sep 17 00:00:00 2001 From: Peter Van der Beken Date: Thu, 4 Jul 2013 17:39:24 +0200 Subject: [PATCH] Bug 908997 - Simplify XPathEvaluator - remove aggregation from XPathEvaluator. 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 : 163d25a36f52f8f8fa8b6952bcf1bc83de14230b --- content/base/public/nsIDocument.h | 5 ++ content/base/src/Makefile.in | 1 + content/base/src/nsDocument.cpp | 86 +++++++++++------------ content/base/src/nsDocument.h | 8 ++- content/xslt/src/xpath/XPathEvaluator.cpp | 12 ++-- content/xslt/src/xpath/XPathEvaluator.h | 16 +++-- layout/build/nsLayoutModule.cpp | 2 +- 7 files changed, 66 insertions(+), 64 deletions(-) diff --git a/content/base/public/nsIDocument.h b/content/base/public/nsIDocument.h index be1bc4339fcb..baf00e96f392 100644 --- a/content/base/public/nsIDocument.h +++ b/content/base/public/nsIDocument.h @@ -108,6 +108,7 @@ class ProcessingInstruction; class Touch; class TreeWalker; class UndoManager; +class XPathEvaluator; template class OwningNonNull; template class Sequence; @@ -2171,6 +2172,8 @@ protected: return mContentType; } + mozilla::dom::XPathEvaluator* XPathEvaluator(); + nsCString mReferrer; nsString mLastModified; @@ -2426,6 +2429,8 @@ protected: uint8_t mDefaultElementType; uint32_t mInSyncOperationCount; + + nsRefPtr mXPathEvaluator; }; NS_DEFINE_STATIC_IID_ACCESSOR(nsIDocument, NS_IDOCUMENT_IID) diff --git a/content/base/src/Makefile.in b/content/base/src/Makefile.in index f931ab856eb1..6822000914fa 100644 --- a/content/base/src/Makefile.in +++ b/content/base/src/Makefile.in @@ -27,6 +27,7 @@ LOCAL_INCLUDES += \ -I$(topsrcdir)/content/xbl/src \ -I$(topsrcdir)/content/xml/content/src \ -I$(topsrcdir)/content/xml/document/src \ + -I$(topsrcdir)/content/xslt/src/xpath \ -I$(topsrcdir)/content/xul/content/src \ -I$(topsrcdir)/content/xul/document/src \ -I$(topsrcdir)/dom/base \ diff --git a/content/base/src/nsDocument.cpp b/content/base/src/nsDocument.cpp index 25fd3d9f99e1..b5715e994c6e 100644 --- a/content/base/src/nsDocument.cpp +++ b/content/base/src/nsDocument.cpp @@ -99,7 +99,6 @@ #include "nsBidiUtils.h" #include "nsIDOMUserDataHandler.h" -#include "nsIDOMXPathEvaluator.h" #include "nsIDOMXPathExpression.h" #include "nsIDOMXPathNSResolver.h" #include "nsIParserService.h" @@ -212,6 +211,7 @@ #include "nsIHttpChannelInternal.h" #include "nsISecurityConsoleMessage.h" #include "nsCharSeparatedTokenizer.h" +#include "mozilla/dom/XPathEvaluator.h" using namespace mozilla; using namespace mozilla::dom; @@ -1581,22 +1581,11 @@ NS_INTERFACE_TABLE_HEAD(nsDocument) NS_INTERFACE_TABLE_ENTRY(nsDocument, nsIMutationObserver) NS_INTERFACE_TABLE_ENTRY(nsDocument, nsIApplicationCacheContainer) NS_INTERFACE_TABLE_ENTRY(nsDocument, nsIObserver) + NS_INTERFACE_TABLE_ENTRY(nsDocument, nsIDOMXPathEvaluator) NS_INTERFACE_TABLE_END 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))) { - if (!mXPathEvaluatorTearoff) { - nsresult rv; - mXPathEvaluatorTearoff = - do_CreateInstance(NS_XPATH_EVALUATOR_CONTRACTID, - static_cast(this), &rv); - NS_ENSURE_SUCCESS(rv, rv); - } - - return mXPathEvaluatorTearoff->QueryInterface(aIID, aInstancePtr); - } - else NS_INTERFACE_MAP_END @@ -1782,7 +1771,7 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INTERNAL(nsDocument) NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mChannel) NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mStyleAttrStyleSheet) - NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mXPathEvaluatorTearoff) + NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mXPathEvaluator) NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mLayoutHistoryState) NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mOnloadBlocker) NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mFirstBaseNodeWithHref) @@ -1869,7 +1858,7 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsDocument) } tmp->mFirstChild = nullptr; - NS_IMPL_CYCLE_COLLECTION_UNLINK(mXPathEvaluatorTearoff) + NS_IMPL_CYCLE_COLLECTION_UNLINK(mXPathEvaluator) tmp->mCachedRootElement = nullptr; // Avoid a dangling pointer NS_IMPL_CYCLE_COLLECTION_UNLINK(mDisplayDocument) NS_IMPL_CYCLE_COLLECTION_UNLINK(mFirstBaseNodeWithHref) @@ -11288,31 +11277,14 @@ nsIDocument::CreateExpression(const nsAString& aExpression, nsIDOMXPathNSResolver* aResolver, ErrorResult& rv) { - nsCOMPtr evaluator = do_QueryInterface(this); - if (!evaluator) { - rv.Throw(NS_ERROR_FAILURE); - return nullptr; - } - - nsCOMPtr expr; - rv = evaluator->CreateExpression(aExpression, aResolver, getter_AddRefs(expr)); - return expr.forget(); + return XPathEvaluator()->CreateExpression(aExpression, aResolver, rv); } already_AddRefed nsIDocument::CreateNSResolver(nsINode* aNodeResolver, ErrorResult& rv) { - nsCOMPtr evaluator = do_QueryInterface(this); - if (!evaluator) { - rv.Throw(NS_ERROR_FAILURE); - return nullptr; - } - - nsCOMPtr nodeResolver = do_QueryInterface(aNodeResolver); - nsCOMPtr res; - rv = evaluator->CreateNSResolver(nodeResolver, getter_AddRefs(res)); - return res.forget(); + return XPathEvaluator()->CreateNSResolver(aNodeResolver, rv); } already_AddRefed @@ -11320,19 +11292,34 @@ nsIDocument::Evaluate(const nsAString& aExpression, nsINode* aContextNode, nsIDOMXPathNSResolver* aResolver, uint16_t aType, nsISupports* aResult, ErrorResult& rv) { - nsCOMPtr evaluator = do_QueryInterface(this); - if (!evaluator) { - rv.Throw(NS_ERROR_FAILURE); - return nullptr; - } - - nsCOMPtr contextNode = do_QueryInterface(aContextNode); - nsCOMPtr res; - rv = evaluator->Evaluate(aExpression, contextNode, aResolver, aType, - aResult, getter_AddRefs(res)); - return res.forget(); + return XPathEvaluator()->Evaluate(aExpression, aContextNode, aResolver, aType, + aResult, rv); } +NS_IMETHODIMP +nsDocument::CreateExpression(const nsAString& aExpression, + nsIDOMXPathNSResolver* aResolver, + nsIDOMXPathExpression** aResult) +{ + return XPathEvaluator()->CreateExpression(aExpression, aResolver, aResult); +} + +NS_IMETHODIMP +nsDocument::CreateNSResolver(nsIDOMNode* aNodeResolver, + nsIDOMXPathNSResolver** aResult) +{ + return XPathEvaluator()->CreateNSResolver(aNodeResolver, aResult); +} + +NS_IMETHODIMP +nsDocument::Evaluate(const nsAString& aExpression, nsIDOMNode* aContextNode, + nsIDOMXPathNSResolver* aResolver, uint16_t aType, + nsISupports* aInResult, nsISupports** aResult) +{ + return XPathEvaluator()->Evaluate(aExpression, aContextNode, aResolver, aType, + aInResult, aResult); +} + // This is just a hack around the fact that window.document is not // [Unforgeable] yet. JSObject* @@ -11384,6 +11371,15 @@ nsIDocument::WrapObject(JSContext *aCx, JS::Handle aScope) return obj; } +XPathEvaluator* +nsIDocument::XPathEvaluator() +{ + if (!mXPathEvaluator) { + mXPathEvaluator = new dom::XPathEvaluator(this); + } + return mXPathEvaluator; +} + bool MarkDocumentTreeToBeInSyncOperation(nsIDocument* aDoc, void* aData) { diff --git a/content/base/src/nsDocument.h b/content/base/src/nsDocument.h index fdcf1ef3963b..f2d2b6a12189 100644 --- a/content/base/src/nsDocument.h +++ b/content/base/src/nsDocument.h @@ -68,6 +68,7 @@ #include "nsDataHashtable.h" #include "mozilla/TimeStamp.h" #include "mozilla/Attributes.h" +#include "nsIDOMXPathEvaluator.h" #define XML_DECLARATION_BITS_DECLARATION_EXISTS (1 << 0) #define XML_DECLARATION_BITS_ENCODING_EXISTS (1 << 1) @@ -504,7 +505,8 @@ class nsDocument : public nsIDocument, public nsIRadioGroupContainer, public nsIApplicationCacheContainer, public nsStubMutationObserver, - public nsIObserver + public nsIObserver, + public nsIDOMXPathEvaluator { public: typedef mozilla::dom::Element Element; @@ -786,6 +788,8 @@ public: // nsIObserver NS_DECL_NSIOBSERVER + NS_DECL_NSIDOMXPATHEVALUATOR + virtual nsresult Init(); virtual nsresult CreateElem(const nsAString& aName, nsIAtom *aPrefix, @@ -1345,8 +1349,6 @@ private: nsDocument(const nsDocument& aOther); nsDocument& operator=(const nsDocument& aOther); - nsCOMPtr mXPathEvaluatorTearoff; - // The layout history state that should be used by nodes in this // document. We only actually store a pointer to it when: // 1) We have no script global object. diff --git a/content/xslt/src/xpath/XPathEvaluator.cpp b/content/xslt/src/xpath/XPathEvaluator.cpp index c890363c64a6..a8429c820d8e 100644 --- a/content/xslt/src/xpath/XPathEvaluator.cpp +++ b/content/xslt/src/xpath/XPathEvaluator.cpp @@ -3,7 +3,7 @@ * 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 "XPathEvaluator.h" +#include "mozilla/dom/XPathEvaluator.h" #include "nsCOMPtr.h" #include "nsIAtom.h" #include "nsXPathExpression.h" @@ -58,15 +58,11 @@ private: bool mIsCaseSensitive; }; -NS_IMPL_AGGREGATED(XPathEvaluator) -NS_INTERFACE_MAP_BEGIN_AGGREGATED(XPathEvaluator) - NS_INTERFACE_MAP_ENTRY(nsIDOMXPathEvaluator) -NS_INTERFACE_MAP_END +NS_IMPL_ISUPPORTS1(XPathEvaluator, nsIDOMXPathEvaluator) -XPathEvaluator::XPathEvaluator(nsISupports *aOuter) - : mDocument(do_GetWeakReference(aOuter)) +XPathEvaluator::XPathEvaluator(nsIDocument* aDocument) + : mDocument(do_GetWeakReference(aDocument)) { - NS_INIT_AGGREGATED(aOuter); } NS_IMETHODIMP diff --git a/content/xslt/src/xpath/XPathEvaluator.h b/content/xslt/src/xpath/XPathEvaluator.h index 6808d6b5d83d..9080fe2f2f7d 100644 --- a/content/xslt/src/xpath/XPathEvaluator.h +++ b/content/xslt/src/xpath/XPathEvaluator.h @@ -10,12 +10,12 @@ #include "nsIWeakReference.h" #include "nsAutoPtr.h" #include "nsString.h" -#include "txResultRecycler.h" -#include "nsAgg.h" #include "mozilla/Attributes.h" #include "mozilla/ErrorResult.h" +#include "nsIDocument.h" class nsINode; +class txResultRecycler; namespace mozilla { namespace dom { @@ -28,18 +28,20 @@ class GlobalObject; class XPathEvaluator MOZ_FINAL : public nsIDOMXPathEvaluator { public: - XPathEvaluator(nsISupports *aOuter); + XPathEvaluator(nsIDocument* aDocument = nullptr); - nsresult Init(); - - // nsISupports interface (support aggregation) - NS_DECL_AGGREGATED + NS_DECL_ISUPPORTS // nsIDOMXPathEvaluator interface NS_DECL_NSIDOMXPATHEVALUATOR // WebIDL API JSObject* WrapObject(JSContext* aCx, JS::Handle aScope); + already_AddRefed GetParentObject() + { + nsCOMPtr doc = do_QueryReferent(mDocument); + return doc.forget(); + } static already_AddRefed Constructor(const GlobalObject& aGlobal, ErrorResult& rv); already_AddRefed diff --git a/layout/build/nsLayoutModule.cpp b/layout/build/nsLayoutModule.cpp index 188ef21169d8..64daeff89094 100644 --- a/layout/build/nsLayoutModule.cpp +++ b/layout/build/nsLayoutModule.cpp @@ -262,7 +262,7 @@ using mozilla::dom::time::TimeService; // Factory Constructor NS_GENERIC_FACTORY_CONSTRUCTOR(txMozillaXSLTProcessor) -NS_GENERIC_AGGREGATED_CONSTRUCTOR(XPathEvaluator) +NS_GENERIC_FACTORY_CONSTRUCTOR(XPathEvaluator) NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(txNodeSetAdaptor, Init) NS_GENERIC_FACTORY_CONSTRUCTOR(nsDOMSerializer) NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsXMLHttpRequest, Init)