Bug 132300. A better way to bootstrap XPathEvaluator by following the specs recommendation and making documents implement the interface.

r=pike sr=jst a=asa


git-svn-id: svn://10.0.0.236/branches/MOZILLA_1_0_BRANCH@119393 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
sicking%bigfoot.com
2002-04-19 13:26:19 +00:00
parent 31f63c43ed
commit a8674b4e10
7 changed files with 95 additions and 8 deletions

View File

@@ -440,12 +440,41 @@ nsDocumentChildNodes::DropReference()
mDocument = nsnull;
}
class nsXPathDocumentTearoff : public nsIDOMXPathEvaluator
{
public:
nsXPathDocumentTearoff(nsIDOMXPathEvaluator* aEvaluator,
nsIDocument* aDocument) : mEvaluator(aEvaluator),
mDocument(aDocument)
{
}
virtual ~nsXPathDocumentTearoff()
{
}
NS_DECL_ISUPPORTS_INHERITED
NS_FORWARD_NSIDOMXPATHEVALUATOR(mEvaluator->)
private:
nsCOMPtr<nsIDOMXPathEvaluator> mEvaluator;
nsIDocument* mDocument;
};
NS_INTERFACE_MAP_BEGIN(nsXPathDocumentTearoff)
NS_INTERFACE_MAP_ENTRY(nsIDOMXPathEvaluator)
NS_INTERFACE_MAP_END_AGGREGATED(mDocument)
NS_IMPL_ADDREF_USING_AGGREGATOR(nsXPathDocumentTearoff, mDocument)
NS_IMPL_RELEASE_USING_AGGREGATOR(nsXPathDocumentTearoff, mDocument)
// ==================================================================
// =
// ==================================================================
nsDocument::nsDocument() : mIsGoingAway(PR_FALSE),
mCSSLoader(nsnull)
mCSSLoader(nsnull),
mXPathDocument(nsnull)
{
NS_INIT_REFCNT();
@@ -478,6 +507,8 @@ nsDocument::nsDocument() : mIsGoingAway(PR_FALSE),
nsDocument::~nsDocument()
{
delete mXPathDocument;
// XXX Inform any remaining observers that we are going away.
// Note that this currently contradicts the rule that all
// observers must hold on to live references to the document.
@@ -575,6 +606,9 @@ nsDocument::~nsDocument()
}
}
PRBool gCheckedForXPathDOM = PR_FALSE;
PRBool gHaveXPathDOM = PR_FALSE;
NS_INTERFACE_MAP_BEGIN(nsDocument)
NS_INTERFACE_MAP_ENTRY(nsIDocument)
NS_INTERFACE_MAP_ENTRY(nsIDOMDocument)
@@ -592,6 +626,24 @@ NS_INTERFACE_MAP_BEGIN(nsDocument)
NS_INTERFACE_MAP_ENTRY(nsIDOM3Node)
NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference)
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDocument)
if (aIID.Equals(NS_GET_IID(nsIDOMXPathEvaluator)) &&
(!gCheckedForXPathDOM || gHaveXPathDOM)) {
if (!mXPathDocument) {
nsCOMPtr<nsIDOMXPathEvaluator> evaluator;
nsresult rv;
evaluator = do_CreateInstance(NS_XPATH_EVALUATOR_CONTRACTID, &rv);
gCheckedForXPathDOM = PR_TRUE;
gHaveXPathDOM = (evaluator != nsnull);
if (rv == NS_ERROR_FACTORY_NOT_REGISTERED) {
return NS_ERROR_NO_INTERFACE;
}
NS_ENSURE_SUCCESS(rv, rv);
mXPathDocument = new nsXPathDocumentTearoff(evaluator, this);
NS_ENSURE_TRUE(mXPathDocument, NS_ERROR_OUT_OF_MEMORY);
}
foundInterface = mXPathDocument;
}
else
NS_INTERFACE_MAP_END
NS_IMPL_ADDREF(nsDocument)

View File

@@ -68,12 +68,14 @@
#include "nsIURI.h"
#include "nsScriptLoader.h"
#include "nsICSSLoader.h"
#include "nsIDOMXPathEvaluator.h"
class nsIEventListenerManager;
class nsDOMStyleSheetList;
class nsIOutputStream;
class nsDocument;
class nsIDTD;
class nsXPathDocumentTearoff;
#if 0
@@ -630,6 +632,8 @@ private:
// These are not implemented and not supported.
nsDocument(const nsDocument& aOther);
nsDocument& operator=(const nsDocument& aOther);
nsXPathDocumentTearoff* mXPathDocument;
};

View File

@@ -100,6 +100,7 @@
// baseURI
#include "nsIXMLDocument.h"
#include "nsIDOMXPathEvaluator.h"
#ifdef DEBUG_waterson
@@ -828,6 +829,9 @@ nsGenericElement::SetPrefix(const nsAString& aPrefix)
return NS_OK;
}
extern PRBool gCheckedForXPathDOM;
extern PRBool gHaveXPathDOM;
nsresult
nsGenericElement::InternalIsSupported(const nsAString& aFeature,
const nsAString& aVersion,
@@ -858,6 +862,16 @@ nsGenericElement::InternalIsSupported(const nsAString& aFeature,
if (aVersion.IsEmpty() || aVersion.Equals(NS_LITERAL_STRING("2.0"))) {
*aReturn = PR_TRUE;
}
} else if ((!gCheckedForXPathDOM || gHaveXPathDOM) &&
feature.Equals(NS_LITERAL_STRING("XPath"), nsCaseInsensitiveStringComparator()) &&
(aVersion.IsEmpty() || aVersion.Equals(NS_LITERAL_STRING("3.0")))) {
if (!gCheckedForXPathDOM) {
nsCOMPtr<nsIDOMXPathEvaluator> evaluator;
evaluator = do_CreateInstance(NS_XPATH_EVALUATOR_CONTRACTID);
gHaveXPathDOM = (evaluator != nsnull);
gCheckedForXPathDOM = PR_TRUE;
}
*aReturn = gHaveXPathDOM;
}
return NS_OK;

View File

@@ -60,4 +60,6 @@
#define NS_CRYPTO_CONTRACTID "@mozilla.org/security/crypto;1"
#define NS_PKCS11_CONTRACTID "@mozilla.org/security/pkcs11;1"
#define NS_XPATH_EVALUATOR_CONTRACTID "@mozilla.org/dom/xpath-evaluator;1"
#endif /* nsDOMCID_h__ */

View File

@@ -42,6 +42,7 @@
#include "nsCRT.h"
#include "nsIServiceManager.h"
#include "nsICategoryManager.h"
#include "nsIComponentRegistrar.h"
#include "nsISupportsPrimitives.h"
#include "nsIXPConnect.h"
#include "nsIJSContextStack.h"
@@ -267,6 +268,7 @@
#include "nsITreeSelection.h"
#include "nsITreeContentView.h"
#include "nsITreeView.h"
#include "nsIDOMXPathEvaluator.h"
#ifdef MOZ_SVG
#include "nsIDOMSVGAnimatedLength.h"
@@ -1162,6 +1164,10 @@ nsDOMClassInfo::RegisterExternalClasses()
DOM_CLASSINFO_MAP_ENTRY(nsIDOMEventTarget) \
DOM_CLASSINFO_MAP_ENTRY(nsIDOM3Node)
#define DOM_CLASSINFO_MAP_END_WITH_XPATH \
xpathEvaluatorIID, \
DOM_CLASSINFO_MAP_END
nsresult
nsDOMClassInfo::Init()
{
@@ -1171,6 +1177,18 @@ nsDOMClassInfo::Init()
"BAD! You'll need to adjust the size of PtrBits to the size "
"of a pointer on your platform.");
nsCOMPtr<nsIComponentRegistrar> cr;
NS_GetComponentRegistrar(getter_AddRefs(cr));
const nsIID* xpathEvaluatorIID = nsnull;
if (cr) {
PRBool haveXPathDOM;
cr->IsContractIDRegistered(NS_XPATH_EVALUATOR_CONTRACTID,
&haveXPathDOM);
if (haveXPathDOM) {
xpathEvaluatorIID = &NS_GET_IID(nsIDOMXPathEvaluator);
}
}
DOM_CLASSINFO_MAP_BEGIN(Window, nsIDOMWindow)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMWindow)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMJSWindow)
@@ -1231,7 +1249,7 @@ nsDOMClassInfo::Init()
DOM_CLASSINFO_MAP_ENTRY(nsIDOMDocumentTraversal)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMDocumentXBL)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMEventTarget)
DOM_CLASSINFO_MAP_END
DOM_CLASSINFO_MAP_END_WITH_XPATH
DOM_CLASSINFO_MAP_BEGIN(DocumentType, nsIDOMDocumentType)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMDocumentType)
@@ -1333,7 +1351,7 @@ nsDOMClassInfo::Init()
DOM_CLASSINFO_MAP_ENTRY(nsIDOMDocumentTraversal)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMDocumentXBL)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMEventTarget)
DOM_CLASSINFO_MAP_END
DOM_CLASSINFO_MAP_END_WITH_XPATH
DOM_CLASSINFO_MAP_BEGIN(HTMLCollection, nsIDOMHTMLCollection)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMNodeList)
@@ -1840,7 +1858,7 @@ nsDOMClassInfo::Init()
DOM_CLASSINFO_MAP_ENTRY(nsIDOMDocumentXBL)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMDocumentStyle)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMDocumentRange)
DOM_CLASSINFO_MAP_END
DOM_CLASSINFO_MAP_END_WITH_XPATH
DOM_CLASSINFO_MAP_BEGIN(SVGSVGElement, nsIDOMSVGSVGElement)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMEventTarget)

View File

@@ -232,7 +232,7 @@ static const nsModuleComponentInfo gComponents[] = {
RegisterTransformiix },
{ "XPathEvaluator",
TRANSFORMIIX_XPATH_EVALUATOR_CID,
TRANSFORMIIX_XPATH_EVALUATOR_CONTRACTID,
NS_XPATH_EVALUATOR_CONTRACTID,
nsXPathEvaluatorConstructor },
{ "Transformiix Synchronous Loader",
TRANSFORMIIX_SYNCLOADER_CID,

View File

@@ -66,7 +66,4 @@ private:
#define TRANSFORMIIX_XPATH_EVALUATOR_CID \
{ 0xd0a75e02, 0xb5e7, 0x11d5, { 0xa7, 0xf2, 0xdf, 0x10, 0x9f, 0xb8, 0xa1, 0xfc } }
#define TRANSFORMIIX_XPATH_EVALUATOR_CONTRACTID \
"@mozilla.org/transformiix/xpath-evaluator;1"
#endif