зеркало из https://github.com/mozilla/pjs.git
Fix for bug 132300 (Need a better way to bootstrap an XPathEvaluator). r=pike, sr=jst.
This commit is contained in:
Родитель
96a7a0d5ce
Коммит
02e9bfd150
|
@ -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)
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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__ */
|
||||
|
|
|
@ -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"
|
||||
|
@ -269,6 +270,7 @@
|
|||
#include "nsITreeSelection.h"
|
||||
#include "nsITreeContentView.h"
|
||||
#include "nsITreeView.h"
|
||||
#include "nsIDOMXPathEvaluator.h"
|
||||
|
||||
#ifdef MOZ_SVG
|
||||
#include "nsIDOMSVGAnimatedLength.h"
|
||||
|
@ -1166,6 +1168,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()
|
||||
{
|
||||
|
@ -1175,6 +1181,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)
|
||||
|
@ -1235,7 +1253,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)
|
||||
|
@ -1337,7 +1355,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)
|
||||
|
@ -1844,7 +1862,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)
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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
|
||||
|
|
Загрузка…
Ссылка в новой задаче