diff -r 000000000000 -r 6474c204b198 netwerk/base/src/nsSimpleNestedURI.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/netwerk/base/src/nsSimpleNestedURI.cpp Wed Dec 31 06:09:35 2014 +0100 @@ -0,0 +1,137 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* 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/. */ + +#include "base/basictypes.h" + +#include "nsSimpleNestedURI.h" +#include "nsIObjectInputStream.h" +#include "nsIObjectOutputStream.h" +#include "nsNetUtil.h" + +NS_IMPL_ISUPPORTS_INHERITED(nsSimpleNestedURI, nsSimpleURI, nsINestedURI) + +nsSimpleNestedURI::nsSimpleNestedURI(nsIURI* innerURI) + : mInnerURI(innerURI) +{ + 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?"); + + nsCOMPtr supports; + rv = aStream->ReadObject(true, getter_AddRefs(supports)); + if (NS_FAILED(rv)) return rv; + + mInnerURI = do_QueryInterface(supports, &rv); + if (NS_FAILED(rv)) return rv; + + NS_TryToSetImmutable(mInnerURI); + + return rv; +} + +NS_IMETHODIMP +nsSimpleNestedURI::Write(nsIObjectOutputStream* aStream) +{ + nsCOMPtr 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), + true); + return rv; +} + +// 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); +} + +// nsSimpleURI overrides +/* virtual */ nsresult +nsSimpleNestedURI::EqualsInternal(nsIURI* other, + nsSimpleURI::RefHandlingEnum refHandlingMode, + bool* result) +{ + *result = false; + NS_ENSURE_TRUE(mInnerURI, NS_ERROR_NOT_INITIALIZED); + + if (other) { + bool correctScheme; + nsresult rv = other->SchemeIs(mScheme.get(), &correctScheme); + NS_ENSURE_SUCCESS(rv, rv); + + if (correctScheme) { + nsCOMPtr nest = do_QueryInterface(other); + if (nest) { + nsCOMPtr otherInner; + rv = nest->GetInnerURI(getter_AddRefs(otherInner)); + NS_ENSURE_SUCCESS(rv, rv); + + return (refHandlingMode == eHonorRef) ? + otherInner->Equals(mInnerURI, result) : + otherInner->EqualsExceptRef(mInnerURI, result); + } + } + } + + return NS_OK; +} + +/* virtual */ nsSimpleURI* +nsSimpleNestedURI::StartClone(nsSimpleURI::RefHandlingEnum refHandlingMode) +{ + NS_ENSURE_TRUE(mInnerURI, nullptr); + + nsCOMPtr innerClone; + nsresult rv = refHandlingMode == eHonorRef ? + mInnerURI->Clone(getter_AddRefs(innerClone)) : + mInnerURI->CloneIgnoringRef(getter_AddRefs(innerClone)); + + if (NS_FAILED(rv)) { + return nullptr; + } + + nsSimpleNestedURI* url = new nsSimpleNestedURI(innerClone); + url->SetMutable(false); + + return url; +} + +// nsIClassInfo overrides + +NS_IMETHODIMP +nsSimpleNestedURI::GetClassIDNoAlloc(nsCID *aClassIDNoAlloc) +{ + static NS_DEFINE_CID(kSimpleNestedURICID, NS_SIMPLENESTEDURI_CID); + + *aClassIDNoAlloc = kSimpleNestedURICID; + return NS_OK; +}