2012-08-02 06:02:29 +00:00
|
|
|
/* 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/. */
|
|
|
|
|
2012-09-25 03:24:44 +00:00
|
|
|
#include "nsHostObjectURI.h"
|
2012-08-02 06:02:29 +00:00
|
|
|
|
|
|
|
#include "nsAutoPtr.h"
|
|
|
|
#include "nsIObjectInputStream.h"
|
|
|
|
#include "nsIObjectOutputStream.h"
|
|
|
|
#include "nsIProgrammingLanguage.h"
|
|
|
|
|
2012-09-25 03:24:44 +00:00
|
|
|
static NS_DEFINE_CID(kHOSTOBJECTURICID, NS_HOSTOBJECTURI_CID);
|
2012-08-02 06:02:29 +00:00
|
|
|
|
|
|
|
static NS_DEFINE_CID(kThisSimpleURIImplementationCID,
|
|
|
|
NS_THIS_SIMPLEURI_IMPLEMENTATION_CID);
|
|
|
|
|
2012-09-25 03:24:44 +00:00
|
|
|
NS_IMPL_ADDREF_INHERITED(nsHostObjectURI, nsSimpleURI)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(nsHostObjectURI, nsSimpleURI)
|
2012-08-02 06:02:29 +00:00
|
|
|
|
2012-09-25 03:24:44 +00:00
|
|
|
NS_INTERFACE_MAP_BEGIN(nsHostObjectURI)
|
2012-08-02 06:02:29 +00:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIURIWithPrincipal)
|
2012-09-25 03:24:44 +00:00
|
|
|
if (aIID.Equals(kHOSTOBJECTURICID))
|
2012-08-02 06:02:29 +00:00
|
|
|
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 = nullptr;
|
|
|
|
return NS_NOINTERFACE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
NS_INTERFACE_MAP_END_INHERITING(nsSimpleURI)
|
|
|
|
|
|
|
|
// nsIURIWithPrincipal methods:
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-09-25 03:24:44 +00:00
|
|
|
nsHostObjectURI::GetPrincipal(nsIPrincipal** aPrincipal)
|
2012-08-02 06:02:29 +00:00
|
|
|
{
|
|
|
|
NS_IF_ADDREF(*aPrincipal = mPrincipal);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-09-25 03:24:44 +00:00
|
|
|
nsHostObjectURI::GetPrincipalUri(nsIURI** aUri)
|
2012-08-02 06:02:29 +00:00
|
|
|
{
|
|
|
|
if (mPrincipal) {
|
|
|
|
mPrincipal->GetURI(aUri);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
*aUri = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// nsISerializable methods:
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-09-25 03:24:44 +00:00
|
|
|
nsHostObjectURI::Read(nsIObjectInputStream* aStream)
|
2012-08-02 06:02:29 +00:00
|
|
|
{
|
|
|
|
nsresult rv = nsSimpleURI::Read(aStream);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2014-03-15 19:00:17 +00:00
|
|
|
nsCOMPtr<nsISupports> supports;
|
|
|
|
rv = NS_ReadOptionalObject(aStream, true, getter_AddRefs(supports));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
mPrincipal = do_QueryInterface(supports, &rv);
|
|
|
|
return rv;
|
2012-08-02 06:02:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-09-25 03:24:44 +00:00
|
|
|
nsHostObjectURI::Write(nsIObjectOutputStream* aStream)
|
2012-08-02 06:02:29 +00:00
|
|
|
{
|
|
|
|
nsresult rv = nsSimpleURI::Write(aStream);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
return NS_WriteOptionalCompoundObject(aStream, mPrincipal,
|
|
|
|
NS_GET_IID(nsIPrincipal),
|
|
|
|
true);
|
|
|
|
}
|
|
|
|
|
|
|
|
// nsIURI methods:
|
|
|
|
nsresult
|
2012-09-25 03:24:44 +00:00
|
|
|
nsHostObjectURI::CloneInternal(nsSimpleURI::RefHandlingEnum aRefHandlingMode,
|
|
|
|
nsIURI** aClone)
|
2012-08-02 06:02:29 +00:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsIURI> simpleClone;
|
|
|
|
nsresult rv =
|
|
|
|
nsSimpleURI::CloneInternal(aRefHandlingMode, getter_AddRefs(simpleClone));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
2012-09-25 03:24:44 +00:00
|
|
|
nsRefPtr<nsHostObjectURI> uriCheck;
|
|
|
|
rv = simpleClone->QueryInterface(kHOSTOBJECTURICID, getter_AddRefs(uriCheck));
|
2012-08-02 06:02:29 +00:00
|
|
|
NS_ABORT_IF_FALSE(NS_SUCCEEDED(rv) && uriCheck,
|
|
|
|
"Unexpected!");
|
|
|
|
#endif
|
|
|
|
|
2012-09-25 03:24:44 +00:00
|
|
|
nsHostObjectURI* u = static_cast<nsHostObjectURI*>(simpleClone.get());
|
2012-08-02 06:02:29 +00:00
|
|
|
|
2012-09-25 03:24:44 +00:00
|
|
|
u->mPrincipal = mPrincipal;
|
2012-08-02 06:02:29 +00:00
|
|
|
|
|
|
|
simpleClone.forget(aClone);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* virtual */ nsresult
|
2012-09-25 03:24:44 +00:00
|
|
|
nsHostObjectURI::EqualsInternal(nsIURI* aOther,
|
|
|
|
nsSimpleURI::RefHandlingEnum aRefHandlingMode,
|
|
|
|
bool* aResult)
|
2012-08-02 06:02:29 +00:00
|
|
|
{
|
|
|
|
if (!aOther) {
|
|
|
|
*aResult = false;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-09-25 03:24:44 +00:00
|
|
|
nsRefPtr<nsHostObjectURI> otherUri;
|
|
|
|
aOther->QueryInterface(kHOSTOBJECTURICID, getter_AddRefs(otherUri));
|
|
|
|
if (!otherUri) {
|
2012-08-02 06:02:29 +00:00
|
|
|
*aResult = false;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Compare the member data that our base class knows about.
|
2012-09-25 03:24:44 +00:00
|
|
|
if (!nsSimpleURI::EqualsInternal(otherUri, aRefHandlingMode)) {
|
2012-08-02 06:02:29 +00:00
|
|
|
*aResult = false;
|
|
|
|
return NS_OK;
|
2012-09-25 03:24:44 +00:00
|
|
|
}
|
2012-08-02 06:02:29 +00:00
|
|
|
|
|
|
|
// Compare the piece of additional member data that we add to base class.
|
2012-09-25 03:24:44 +00:00
|
|
|
if (mPrincipal && otherUri->mPrincipal) {
|
2012-08-02 06:02:29 +00:00
|
|
|
// Both of us have mPrincipals. Compare them.
|
2012-09-25 03:24:44 +00:00
|
|
|
return mPrincipal->Equals(otherUri->mPrincipal, aResult);
|
2012-08-02 06:02:29 +00:00
|
|
|
}
|
|
|
|
// else, at least one of us lacks a principal; only equal if *both* lack it.
|
2012-09-25 03:24:44 +00:00
|
|
|
*aResult = (!mPrincipal && !otherUri->mPrincipal);
|
2012-08-02 06:02:29 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// nsIClassInfo methods:
|
|
|
|
NS_IMETHODIMP
|
2012-09-25 03:24:44 +00:00
|
|
|
nsHostObjectURI::GetInterfaces(uint32_t *count, nsIID * **array)
|
2012-08-02 06:02:29 +00:00
|
|
|
{
|
|
|
|
*count = 0;
|
|
|
|
*array = nullptr;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-09-25 03:24:44 +00:00
|
|
|
nsHostObjectURI::GetHelperForLanguage(uint32_t language, nsISupports **_retval)
|
2012-08-02 06:02:29 +00:00
|
|
|
{
|
|
|
|
*_retval = nullptr;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-09-25 03:24:44 +00:00
|
|
|
nsHostObjectURI::GetContractID(char * *aContractID)
|
2012-08-02 06:02:29 +00:00
|
|
|
{
|
|
|
|
// Make sure to modify any subclasses as needed if this ever
|
|
|
|
// changes.
|
|
|
|
*aContractID = nullptr;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-09-25 03:24:44 +00:00
|
|
|
nsHostObjectURI::GetClassDescription(char * *aClassDescription)
|
2012-08-02 06:02:29 +00:00
|
|
|
{
|
|
|
|
*aClassDescription = nullptr;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-09-25 03:24:44 +00:00
|
|
|
nsHostObjectURI::GetClassID(nsCID * *aClassID)
|
2012-08-02 06:02:29 +00:00
|
|
|
{
|
|
|
|
// Make sure to modify any subclasses as needed if this ever
|
|
|
|
// changes to not call the virtual GetClassIDNoAlloc.
|
|
|
|
*aClassID = (nsCID*) nsMemory::Alloc(sizeof(nsCID));
|
|
|
|
NS_ENSURE_TRUE(*aClassID, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
|
|
|
|
return GetClassIDNoAlloc(*aClassID);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-09-25 03:24:44 +00:00
|
|
|
nsHostObjectURI::GetImplementationLanguage(uint32_t *aImplementationLanguage)
|
2012-08-02 06:02:29 +00:00
|
|
|
{
|
|
|
|
*aImplementationLanguage = nsIProgrammingLanguage::CPLUSPLUS;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-09-25 03:24:44 +00:00
|
|
|
nsHostObjectURI::GetFlags(uint32_t *aFlags)
|
2012-08-02 06:02:29 +00:00
|
|
|
{
|
|
|
|
*aFlags = nsIClassInfo::MAIN_THREAD_ONLY;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-09-25 03:24:44 +00:00
|
|
|
nsHostObjectURI::GetClassIDNoAlloc(nsCID *aClassIDNoAlloc)
|
2012-08-02 06:02:29 +00:00
|
|
|
{
|
2012-09-25 03:24:44 +00:00
|
|
|
*aClassIDNoAlloc = kHOSTOBJECTURICID;
|
2012-08-02 06:02:29 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|