mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-09 03:15:11 +00:00
Make nsJSURI inherit from nsSimpleURI. Bug 647570, r=bzbarsky
This commit is contained in:
parent
85664af740
commit
69a7d078c2
@ -61,6 +61,7 @@ EXPORTS = $(srcdir)/nsJSProtocolHandler.h
|
|||||||
LOCAL_INCLUDES += \
|
LOCAL_INCLUDES += \
|
||||||
-I$(srcdir) \
|
-I$(srcdir) \
|
||||||
-I$(topsrcdir)/dom/base \
|
-I$(topsrcdir)/dom/base \
|
||||||
|
-I$(topsrcdir)/netwerk/base/src \
|
||||||
|
|
||||||
EXTRA_DSO_LDOPTS = \
|
EXTRA_DSO_LDOPTS = \
|
||||||
$(MOZ_COMPONENT_LIBS) \
|
$(MOZ_COMPONENT_LIBS) \
|
||||||
|
@ -22,6 +22,7 @@
|
|||||||
*
|
*
|
||||||
* Contributor(s):
|
* Contributor(s):
|
||||||
* Pierre Phaneuf <pp@ludusdesign.com>
|
* Pierre Phaneuf <pp@ludusdesign.com>
|
||||||
|
* Emanuele Costa <emanuele.costa@gmail.com>
|
||||||
*
|
*
|
||||||
* Alternatively, the contents of this file may be used under the terms of
|
* Alternatively, the contents of this file may be used under the terms of
|
||||||
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
||||||
@ -1219,10 +1220,7 @@ nsJSProtocolHandler::NewURI(const nsACString &aSpec,
|
|||||||
// provided by standard URLs, so there is no "outer" object given to
|
// provided by standard URLs, so there is no "outer" object given to
|
||||||
// CreateInstance.
|
// CreateInstance.
|
||||||
|
|
||||||
nsCOMPtr<nsIURI> url = do_CreateInstance(NS_SIMPLEURI_CONTRACTID, &rv);
|
nsCOMPtr<nsIURI> url = new nsJSURI(aBaseURI);
|
||||||
|
|
||||||
if (NS_FAILED(rv))
|
|
||||||
return rv;
|
|
||||||
|
|
||||||
if (!aCharset || !nsCRT::strcasecmp("UTF-8", aCharset))
|
if (!aCharset || !nsCRT::strcasecmp("UTF-8", aCharset))
|
||||||
rv = url->SetSpec(aSpec);
|
rv = url->SetSpec(aSpec);
|
||||||
@ -1241,10 +1239,7 @@ nsJSProtocolHandler::NewURI(const nsACString &aSpec,
|
|||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
*result = new nsJSURI(aBaseURI, url);
|
url.forget(result);
|
||||||
NS_ENSURE_TRUE(*result, NS_ERROR_OUT_OF_MEMORY);
|
|
||||||
|
|
||||||
NS_ADDREF(*result);
|
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1281,34 +1276,34 @@ nsJSProtocolHandler::AllowPort(PRInt32 port, const char *scheme, PRBool *_retval
|
|||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
// nsJSURI implementation
|
// nsJSURI implementation
|
||||||
|
static NS_DEFINE_CID(kThisSimpleURIImplementationCID,
|
||||||
|
NS_THIS_SIMPLEURI_IMPLEMENTATION_CID);
|
||||||
|
|
||||||
NS_IMPL_ADDREF(nsJSURI)
|
|
||||||
NS_IMPL_RELEASE(nsJSURI)
|
NS_IMPL_ADDREF_INHERITED(nsJSURI, nsSimpleURI)
|
||||||
|
NS_IMPL_RELEASE_INHERITED(nsJSURI, nsSimpleURI)
|
||||||
|
|
||||||
NS_INTERFACE_MAP_BEGIN(nsJSURI)
|
NS_INTERFACE_MAP_BEGIN(nsJSURI)
|
||||||
NS_INTERFACE_MAP_ENTRY(nsIURI)
|
|
||||||
NS_INTERFACE_MAP_ENTRY(nsISerializable)
|
|
||||||
NS_INTERFACE_MAP_ENTRY(nsIClassInfo)
|
|
||||||
NS_INTERFACE_MAP_ENTRY(nsIMutable)
|
|
||||||
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIURI)
|
|
||||||
if (aIID.Equals(kJSURICID))
|
if (aIID.Equals(kJSURICID))
|
||||||
foundInterface = static_cast<nsIURI*>(this);
|
foundInterface = static_cast<nsIURI*>(this);
|
||||||
|
else if (aIID.Equals(kThisSimpleURIImplementationCID)) {
|
||||||
|
// Need to return explicitly here, because if we just set foundInterface
|
||||||
|
// to null the NS_INTERFACE_MAP_END_INHERITING will end up calling into
|
||||||
|
// nsSimplURI::QueryInterface and finding something for this CID.
|
||||||
|
*aInstancePtr = nsnull;
|
||||||
|
return NS_NOINTERFACE;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
NS_INTERFACE_MAP_END
|
NS_INTERFACE_MAP_END_INHERITING(nsSimpleURI)
|
||||||
|
|
||||||
// nsISerializable methods:
|
// nsISerializable methods:
|
||||||
|
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
nsJSURI::Read(nsIObjectInputStream* aStream)
|
nsJSURI::Read(nsIObjectInputStream* aStream)
|
||||||
{
|
{
|
||||||
nsresult rv;
|
nsresult rv = nsSimpleURI::Read(aStream);
|
||||||
|
|
||||||
rv = aStream->ReadObject(PR_TRUE, getter_AddRefs(mSimpleURI));
|
|
||||||
if (NS_FAILED(rv)) return rv;
|
if (NS_FAILED(rv)) return rv;
|
||||||
|
|
||||||
mMutable = do_QueryInterface(mSimpleURI);
|
|
||||||
NS_ENSURE_TRUE(mMutable, NS_ERROR_UNEXPECTED);
|
|
||||||
|
|
||||||
PRBool haveBase;
|
PRBool haveBase;
|
||||||
rv = aStream->ReadBoolean(&haveBase);
|
rv = aStream->ReadBoolean(&haveBase);
|
||||||
if (NS_FAILED(rv)) return rv;
|
if (NS_FAILED(rv)) return rv;
|
||||||
@ -1324,9 +1319,7 @@ nsJSURI::Read(nsIObjectInputStream* aStream)
|
|||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
nsJSURI::Write(nsIObjectOutputStream* aStream)
|
nsJSURI::Write(nsIObjectOutputStream* aStream)
|
||||||
{
|
{
|
||||||
nsresult rv;
|
nsresult rv = nsSimpleURI::Write(aStream);
|
||||||
|
|
||||||
rv = aStream->WriteObject(mSimpleURI, PR_TRUE);
|
|
||||||
if (NS_FAILED(rv)) return rv;
|
if (NS_FAILED(rv)) return rv;
|
||||||
|
|
||||||
rv = aStream->WriteBoolean(mBaseURI != nsnull);
|
rv = aStream->WriteBoolean(mBaseURI != nsnull);
|
||||||
@ -1341,99 +1334,47 @@ nsJSURI::Write(nsIObjectOutputStream* aStream)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// nsIURI methods:
|
// nsIURI methods:
|
||||||
|
/* virtual */ nsSimpleURI*
|
||||||
NS_IMETHODIMP
|
nsJSURI::StartClone(nsSimpleURI::RefHandlingEnum /* ignored */)
|
||||||
nsJSURI::Clone(nsIURI** aClone)
|
|
||||||
{
|
{
|
||||||
nsCOMPtr<nsIURI> simpleClone;
|
|
||||||
nsresult rv = mSimpleURI->Clone(getter_AddRefs(simpleClone));
|
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
|
||||||
|
|
||||||
nsCOMPtr<nsIURI> baseClone;
|
nsCOMPtr<nsIURI> baseClone;
|
||||||
if (mBaseURI) {
|
if (mBaseURI) {
|
||||||
rv = mBaseURI->Clone(getter_AddRefs(baseClone));
|
nsresult rv = mBaseURI->Clone(getter_AddRefs(baseClone));
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
if (NS_FAILED(rv)) {
|
||||||
|
return nsnull;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
nsIURI* newURI = new nsJSURI(baseClone, simpleClone);
|
return new nsJSURI(baseClone);
|
||||||
NS_ENSURE_TRUE(newURI, NS_ERROR_OUT_OF_MEMORY);
|
|
||||||
|
|
||||||
NS_ADDREF(*aClone = newURI);
|
|
||||||
return NS_OK;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
nsJSURI::Equals(nsIURI* aOther, PRBool *aResult)
|
nsJSURI::Equals(nsIURI* other, PRBool *result)
|
||||||
{
|
{
|
||||||
if (!aOther) {
|
*result = PR_FALSE;
|
||||||
*aResult = PR_FALSE;
|
|
||||||
return NS_OK;
|
if (other) {
|
||||||
}
|
nsRefPtr<nsJSURI> otherJSURI;
|
||||||
|
nsresult rv = other->QueryInterface(kJSURICID,
|
||||||
nsRefPtr<nsJSURI> otherJSUri;
|
getter_AddRefs(otherJSURI));
|
||||||
aOther->QueryInterface(kJSURICID, getter_AddRefs(otherJSUri));
|
if (!otherJSURI) {
|
||||||
if (!otherJSUri) {
|
*result = PR_FALSE;
|
||||||
*aResult = PR_FALSE;
|
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
*result = nsSimpleURI::EqualsInternal(otherJSURI, eHonorRef);
|
||||||
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
|
if (!*result)
|
||||||
|
return NS_OK;
|
||||||
|
|
||||||
|
nsIURI* otherBaseURI = otherJSURI->GetBaseURI();
|
||||||
|
|
||||||
|
if (mBaseURI)
|
||||||
|
return mBaseURI->Equals(otherBaseURI, result);
|
||||||
|
|
||||||
|
*result = !otherBaseURI;
|
||||||
}
|
}
|
||||||
|
|
||||||
return mSimpleURI->Equals(otherJSUri->mSimpleURI, aResult);
|
|
||||||
}
|
|
||||||
|
|
||||||
// nsIClassInfo methods:
|
|
||||||
NS_IMETHODIMP
|
|
||||||
nsJSURI::GetInterfaces(PRUint32 *count, nsIID * **array)
|
|
||||||
{
|
|
||||||
*count = 0;
|
|
||||||
*array = nsnull;
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_IMETHODIMP
|
|
||||||
nsJSURI::GetHelperForLanguage(PRUint32 language, nsISupports **_retval)
|
|
||||||
{
|
|
||||||
*_retval = nsnull;
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_IMETHODIMP
|
|
||||||
nsJSURI::GetContractID(char * *aContractID)
|
|
||||||
{
|
|
||||||
// Make sure to modify any subclasses as needed if this ever
|
|
||||||
// changes.
|
|
||||||
*aContractID = nsnull;
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_IMETHODIMP
|
|
||||||
nsJSURI::GetClassDescription(char * *aClassDescription)
|
|
||||||
{
|
|
||||||
*aClassDescription = nsnull;
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_IMETHODIMP
|
|
||||||
nsJSURI::GetClassID(nsCID * *aClassID)
|
|
||||||
{
|
|
||||||
// Make sure to modify any subclasses as needed if this ever
|
|
||||||
// changes to not call the virtual GetClassIDNoAlloc.
|
|
||||||
*aClassID = (nsCID*) nsMemory::Alloc(sizeof(nsCID));
|
|
||||||
if (!*aClassID)
|
|
||||||
return NS_ERROR_OUT_OF_MEMORY;
|
|
||||||
return GetClassIDNoAlloc(*aClassID);
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_IMETHODIMP
|
|
||||||
nsJSURI::GetImplementationLanguage(PRUint32 *aImplementationLanguage)
|
|
||||||
{
|
|
||||||
*aImplementationLanguage = nsIProgrammingLanguage::CPLUSPLUS;
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_IMETHODIMP
|
|
||||||
nsJSURI::GetFlags(PRUint32 *aFlags)
|
|
||||||
{
|
|
||||||
*aFlags = nsIClassInfo::MAIN_THREAD_ONLY;
|
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1443,3 +1384,4 @@ nsJSURI::GetClassIDNoAlloc(nsCID *aClassIDNoAlloc)
|
|||||||
*aClassIDNoAlloc = kJSURICID;
|
*aClassIDNoAlloc = kJSURICID;
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
* the Initial Developer. All Rights Reserved.
|
* the Initial Developer. All Rights Reserved.
|
||||||
*
|
*
|
||||||
* Contributor(s):
|
* Contributor(s):
|
||||||
|
* Emanuele Costa <emanuele.costa@gmail.com>
|
||||||
*
|
*
|
||||||
* Alternatively, the contents of this file may be used under the terms of
|
* Alternatively, the contents of this file may be used under the terms of
|
||||||
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
||||||
@ -44,6 +45,7 @@
|
|||||||
#include "nsIMutable.h"
|
#include "nsIMutable.h"
|
||||||
#include "nsISerializable.h"
|
#include "nsISerializable.h"
|
||||||
#include "nsIClassInfo.h"
|
#include "nsIClassInfo.h"
|
||||||
|
#include "nsSimpleURI.h"
|
||||||
|
|
||||||
#define NS_JSPROTOCOLHANDLER_CID \
|
#define NS_JSPROTOCOLHANDLER_CID \
|
||||||
{ /* bfc310d2-38a0-11d3-8cd3-0060b0fc14a3 */ \
|
{ /* bfc310d2-38a0-11d3-8cd3-0060b0fc14a3 */ \
|
||||||
@ -90,58 +92,37 @@ protected:
|
|||||||
nsCOMPtr<nsITextToSubURI> mTextToSubURI;
|
nsCOMPtr<nsITextToSubURI> mTextToSubURI;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Use an extra base object to avoid having to manually retype all the
|
|
||||||
// nsIURI methods. I wish we could just inherit from nsSimpleURI instead.
|
class nsJSURI : public nsSimpleURI
|
||||||
class nsJSURI_base : public nsIURI,
|
|
||||||
public nsIMutable
|
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
nsJSURI_base(nsIURI* aSimpleURI) :
|
|
||||||
mSimpleURI(aSimpleURI)
|
nsJSURI() {}
|
||||||
|
|
||||||
|
nsJSURI(nsIURI* aBaseURI) : mBaseURI(aBaseURI) {}
|
||||||
|
|
||||||
|
nsIURI* GetBaseURI() const
|
||||||
{
|
{
|
||||||
mMutable = do_QueryInterface(mSimpleURI);
|
|
||||||
NS_ASSERTION(aSimpleURI && mMutable, "This isn't going to work out");
|
|
||||||
}
|
|
||||||
virtual ~nsJSURI_base() {}
|
|
||||||
|
|
||||||
// For use only from deserialization
|
|
||||||
nsJSURI_base() {}
|
|
||||||
|
|
||||||
NS_FORWARD_NSIURI(mSimpleURI->)
|
|
||||||
NS_FORWARD_NSIMUTABLE(mMutable->)
|
|
||||||
|
|
||||||
protected:
|
|
||||||
nsCOMPtr<nsIURI> mSimpleURI;
|
|
||||||
nsCOMPtr<nsIMutable> mMutable;
|
|
||||||
};
|
|
||||||
|
|
||||||
class nsJSURI : public nsJSURI_base,
|
|
||||||
public nsISerializable,
|
|
||||||
public nsIClassInfo
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
nsJSURI(nsIURI* aBaseURI, nsIURI* aSimpleURI) :
|
|
||||||
nsJSURI_base(aSimpleURI), mBaseURI(aBaseURI)
|
|
||||||
{}
|
|
||||||
virtual ~nsJSURI() {}
|
|
||||||
|
|
||||||
// For use only from deserialization
|
|
||||||
nsJSURI() : nsJSURI_base() {}
|
|
||||||
|
|
||||||
NS_DECL_ISUPPORTS
|
|
||||||
NS_DECL_NSISERIALIZABLE
|
|
||||||
NS_DECL_NSICLASSINFO
|
|
||||||
|
|
||||||
// Override Clone() and Equals()
|
|
||||||
NS_IMETHOD Clone(nsIURI** aClone);
|
|
||||||
NS_IMETHOD Equals(nsIURI* aOther, PRBool *aResult);
|
|
||||||
|
|
||||||
nsIURI* GetBaseURI() const {
|
|
||||||
return mBaseURI;
|
return mBaseURI;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
NS_DECL_ISUPPORTS_INHERITED
|
||||||
|
|
||||||
|
// nsIURI overrides
|
||||||
|
NS_IMETHOD Equals(nsIURI* other, PRBool *result);
|
||||||
|
virtual nsSimpleURI* StartClone(RefHandlingEnum refHandlingMode);
|
||||||
|
|
||||||
|
// nsISerializable overrides
|
||||||
|
NS_IMETHOD Read(nsIObjectInputStream* aStream);
|
||||||
|
NS_IMETHOD Write(nsIObjectOutputStream* aStream);
|
||||||
|
|
||||||
|
// Override the nsIClassInfo method GetClassIDNoAlloc to make sure our
|
||||||
|
// nsISerializable impl works right.
|
||||||
|
NS_IMETHOD GetClassIDNoAlloc(nsCID *aClassIDNoAlloc);
|
||||||
|
//NS_IMETHOD QueryInterface( const nsIID& aIID, void** aInstancePtr );
|
||||||
|
|
||||||
private:
|
private:
|
||||||
nsCOMPtr<nsIURI> mBaseURI;
|
nsCOMPtr<nsIURI> mBaseURI;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* nsJSProtocolHandler_h___ */
|
#endif /* nsJSProtocolHandler_h___ */
|
||||||
|
@ -336,6 +336,7 @@ LOCAL_INCLUDES += -I$(srcdir)/../base \
|
|||||||
-I$(topsrcdir)/js/src/xpconnect/src \
|
-I$(topsrcdir)/js/src/xpconnect/src \
|
||||||
-I$(topsrcdir)/js/src/xpconnect/loader \
|
-I$(topsrcdir)/js/src/xpconnect/loader \
|
||||||
-I$(topsrcdir)/caps/include \
|
-I$(topsrcdir)/caps/include \
|
||||||
|
-I$(topsrcdir)/netwerk/base/src \
|
||||||
$(NULL)
|
$(NULL)
|
||||||
|
|
||||||
ifdef MOZ_MATHML
|
ifdef MOZ_MATHML
|
||||||
|
@ -449,15 +449,22 @@ nsSimpleURI::EqualsInternal(nsIURI* other,
|
|||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
*result = (mScheme == otherUri->mScheme &&
|
*result = EqualsInternal(otherUri, refHandlingMode);
|
||||||
mPath == otherUri->mPath);
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
if (*result && refHandlingMode == eHonorRef) {
|
bool
|
||||||
*result = (mIsRefValid == otherUri->mIsRefValid &&
|
nsSimpleURI::EqualsInternal(nsSimpleURI* otherUri, RefHandlingEnum refHandlingMode)
|
||||||
(!mIsRefValid || mRef == otherUri->mRef));
|
{
|
||||||
|
bool result = (mScheme == otherUri->mScheme &&
|
||||||
|
mPath == otherUri->mPath);
|
||||||
|
|
||||||
|
if (result && refHandlingMode == eHonorRef) {
|
||||||
|
result = (mIsRefValid == otherUri->mIsRefValid &&
|
||||||
|
(!mIsRefValid || mRef == otherUri->mRef));
|
||||||
}
|
}
|
||||||
|
|
||||||
return NS_OK;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
|
@ -85,6 +85,11 @@ protected:
|
|||||||
RefHandlingEnum refHandlingMode,
|
RefHandlingEnum refHandlingMode,
|
||||||
PRBool* result);
|
PRBool* result);
|
||||||
|
|
||||||
|
// Helper to be used by inherited classes who want to test
|
||||||
|
// equality given and assumed nsSimpleURI. This must NOT check
|
||||||
|
// the passed-in other for QI to our CID.
|
||||||
|
bool EqualsInternal(nsSimpleURI* otherUri, RefHandlingEnum refHandlingMode);
|
||||||
|
|
||||||
// NOTE: This takes the refHandlingMode as an argument because
|
// NOTE: This takes the refHandlingMode as an argument because
|
||||||
// nsSimpleNestedURI's specialized version needs to know how to clone
|
// nsSimpleNestedURI's specialized version needs to know how to clone
|
||||||
// its inner URI.
|
// its inner URI.
|
||||||
|
Loading…
Reference in New Issue
Block a user