2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2012-05-21 04:12:37 -07: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/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-08-23 12:33:46 -07:00
|
|
|
#include "base/basictypes.h"
|
2010-10-11 04:35:10 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsSimpleNestedURI.h"
|
|
|
|
#include "nsIObjectInputStream.h"
|
|
|
|
#include "nsIObjectOutputStream.h"
|
|
|
|
#include "nsNetUtil.h"
|
|
|
|
|
2014-04-27 00:06:00 -07:00
|
|
|
NS_IMPL_ISUPPORTS_INHERITED(nsSimpleNestedURI, nsSimpleURI, nsINestedURI)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsSimpleNestedURI::nsSimpleNestedURI(nsIURI* innerURI)
|
2010-06-12 13:40:05 -07:00
|
|
|
: mInnerURI(innerURI)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
NS_ASSERTION(innerURI, "Must have inner URI");
|
|
|
|
NS_TryToSetImmutable(innerURI);
|
|
|
|
}
|
|
|
|
|
|
|
|
// nsISerializable
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSimpleNestedURI::Read(nsIObjectInputStream* aStream)
|
|
|
|
{
|
|
|
|
nsresult rv = nsSimpleURI::Read(aStream);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
NS_ASSERTION(!mMutable, "How did that happen?");
|
|
|
|
|
2014-03-15 12:00:17 -07:00
|
|
|
nsCOMPtr<nsISupports> supports;
|
|
|
|
rv = aStream->ReadObject(true, getter_AddRefs(supports));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
mInnerURI = do_QueryInterface(supports, &rv);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
NS_TryToSetImmutable(mInnerURI);
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSimpleNestedURI::Write(nsIObjectOutputStream* aStream)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsISerializable> serializable = do_QueryInterface(mInnerURI);
|
|
|
|
if (!serializable) {
|
|
|
|
// We can't serialize ourselves
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult rv = nsSimpleURI::Write(aStream);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
rv = aStream->WriteCompoundObject(mInnerURI, NS_GET_IID(nsIURI),
|
2011-10-17 07:59:28 -07:00
|
|
|
true);
|
2007-03-22 10:30:00 -07:00
|
|
|
return rv;
|
2010-10-11 04:35:10 -07:00
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// nsINestedURI
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSimpleNestedURI::GetInnerURI(nsIURI** uri)
|
|
|
|
{
|
|
|
|
NS_ENSURE_TRUE(mInnerURI, NS_ERROR_NOT_INITIALIZED);
|
|
|
|
|
|
|
|
return NS_EnsureSafeToReturn(mInnerURI, uri);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSimpleNestedURI::GetInnermostURI(nsIURI** uri)
|
|
|
|
{
|
|
|
|
return NS_ImplGetInnermostURI(this, uri);
|
|
|
|
}
|
|
|
|
|
2011-05-21 18:12:45 -07:00
|
|
|
// nsSimpleURI overrides
|
|
|
|
/* virtual */ nsresult
|
|
|
|
nsSimpleNestedURI::EqualsInternal(nsIURI* other,
|
|
|
|
nsSimpleURI::RefHandlingEnum refHandlingMode,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool* result)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2011-10-17 07:59:28 -07:00
|
|
|
*result = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ENSURE_TRUE(mInnerURI, NS_ERROR_NOT_INITIALIZED);
|
|
|
|
|
|
|
|
if (other) {
|
2011-09-28 23:19:26 -07:00
|
|
|
bool correctScheme;
|
2007-03-22 10:30:00 -07:00
|
|
|
nsresult rv = other->SchemeIs(mScheme.get(), &correctScheme);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
if (correctScheme) {
|
|
|
|
nsCOMPtr<nsINestedURI> nest = do_QueryInterface(other);
|
|
|
|
if (nest) {
|
|
|
|
nsCOMPtr<nsIURI> otherInner;
|
|
|
|
rv = nest->GetInnerURI(getter_AddRefs(otherInner));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2011-05-21 18:12:45 -07:00
|
|
|
return (refHandlingMode == eHonorRef) ?
|
|
|
|
otherInner->Equals(mInnerURI, result) :
|
|
|
|
otherInner->EqualsExceptRef(mInnerURI, result);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* virtual */ nsSimpleURI*
|
2011-05-21 18:12:45 -07:00
|
|
|
nsSimpleNestedURI::StartClone(nsSimpleURI::RefHandlingEnum refHandlingMode)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-07-30 07:20:58 -07:00
|
|
|
NS_ENSURE_TRUE(mInnerURI, nullptr);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsCOMPtr<nsIURI> innerClone;
|
2011-05-21 18:12:45 -07:00
|
|
|
nsresult rv = refHandlingMode == eHonorRef ?
|
|
|
|
mInnerURI->Clone(getter_AddRefs(innerClone)) :
|
|
|
|
mInnerURI->CloneIgnoringRef(getter_AddRefs(innerClone));
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
if (NS_FAILED(rv)) {
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsSimpleNestedURI* url = new nsSimpleNestedURI(innerClone);
|
2011-10-17 07:59:28 -07:00
|
|
|
url->SetMutable(false);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
return url;
|
|
|
|
}
|
|
|
|
|
|
|
|
// nsIClassInfo overrides
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSimpleNestedURI::GetClassIDNoAlloc(nsCID *aClassIDNoAlloc)
|
|
|
|
{
|
|
|
|
static NS_DEFINE_CID(kSimpleNestedURICID, NS_SIMPLENESTEDURI_CID);
|
|
|
|
|
|
|
|
*aClassIDNoAlloc = kSimpleNestedURICID;
|
|
|
|
return NS_OK;
|
|
|
|
}
|