michael@0: /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "base/basictypes.h" michael@0: michael@0: #include "nsSimpleNestedURI.h" michael@0: #include "nsIObjectInputStream.h" michael@0: #include "nsIObjectOutputStream.h" michael@0: #include "nsNetUtil.h" michael@0: michael@0: NS_IMPL_ISUPPORTS_INHERITED(nsSimpleNestedURI, nsSimpleURI, nsINestedURI) michael@0: michael@0: nsSimpleNestedURI::nsSimpleNestedURI(nsIURI* innerURI) michael@0: : mInnerURI(innerURI) michael@0: { michael@0: NS_ASSERTION(innerURI, "Must have inner URI"); michael@0: NS_TryToSetImmutable(innerURI); michael@0: } michael@0: michael@0: // nsISerializable michael@0: michael@0: NS_IMETHODIMP michael@0: nsSimpleNestedURI::Read(nsIObjectInputStream* aStream) michael@0: { michael@0: nsresult rv = nsSimpleURI::Read(aStream); michael@0: if (NS_FAILED(rv)) return rv; michael@0: michael@0: NS_ASSERTION(!mMutable, "How did that happen?"); michael@0: michael@0: nsCOMPtr supports; michael@0: rv = aStream->ReadObject(true, getter_AddRefs(supports)); michael@0: if (NS_FAILED(rv)) return rv; michael@0: michael@0: mInnerURI = do_QueryInterface(supports, &rv); michael@0: if (NS_FAILED(rv)) return rv; michael@0: michael@0: NS_TryToSetImmutable(mInnerURI); michael@0: michael@0: return rv; michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsSimpleNestedURI::Write(nsIObjectOutputStream* aStream) michael@0: { michael@0: nsCOMPtr serializable = do_QueryInterface(mInnerURI); michael@0: if (!serializable) { michael@0: // We can't serialize ourselves michael@0: return NS_ERROR_NOT_AVAILABLE; michael@0: } michael@0: michael@0: nsresult rv = nsSimpleURI::Write(aStream); michael@0: if (NS_FAILED(rv)) return rv; michael@0: michael@0: rv = aStream->WriteCompoundObject(mInnerURI, NS_GET_IID(nsIURI), michael@0: true); michael@0: return rv; michael@0: } michael@0: michael@0: // nsINestedURI michael@0: michael@0: NS_IMETHODIMP michael@0: nsSimpleNestedURI::GetInnerURI(nsIURI** uri) michael@0: { michael@0: NS_ENSURE_TRUE(mInnerURI, NS_ERROR_NOT_INITIALIZED); michael@0: michael@0: return NS_EnsureSafeToReturn(mInnerURI, uri); michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsSimpleNestedURI::GetInnermostURI(nsIURI** uri) michael@0: { michael@0: return NS_ImplGetInnermostURI(this, uri); michael@0: } michael@0: michael@0: // nsSimpleURI overrides michael@0: /* virtual */ nsresult michael@0: nsSimpleNestedURI::EqualsInternal(nsIURI* other, michael@0: nsSimpleURI::RefHandlingEnum refHandlingMode, michael@0: bool* result) michael@0: { michael@0: *result = false; michael@0: NS_ENSURE_TRUE(mInnerURI, NS_ERROR_NOT_INITIALIZED); michael@0: michael@0: if (other) { michael@0: bool correctScheme; michael@0: nsresult rv = other->SchemeIs(mScheme.get(), &correctScheme); michael@0: NS_ENSURE_SUCCESS(rv, rv); michael@0: michael@0: if (correctScheme) { michael@0: nsCOMPtr nest = do_QueryInterface(other); michael@0: if (nest) { michael@0: nsCOMPtr otherInner; michael@0: rv = nest->GetInnerURI(getter_AddRefs(otherInner)); michael@0: NS_ENSURE_SUCCESS(rv, rv); michael@0: michael@0: return (refHandlingMode == eHonorRef) ? michael@0: otherInner->Equals(mInnerURI, result) : michael@0: otherInner->EqualsExceptRef(mInnerURI, result); michael@0: } michael@0: } michael@0: } michael@0: michael@0: return NS_OK; michael@0: } michael@0: michael@0: /* virtual */ nsSimpleURI* michael@0: nsSimpleNestedURI::StartClone(nsSimpleURI::RefHandlingEnum refHandlingMode) michael@0: { michael@0: NS_ENSURE_TRUE(mInnerURI, nullptr); michael@0: michael@0: nsCOMPtr innerClone; michael@0: nsresult rv = refHandlingMode == eHonorRef ? michael@0: mInnerURI->Clone(getter_AddRefs(innerClone)) : michael@0: mInnerURI->CloneIgnoringRef(getter_AddRefs(innerClone)); michael@0: michael@0: if (NS_FAILED(rv)) { michael@0: return nullptr; michael@0: } michael@0: michael@0: nsSimpleNestedURI* url = new nsSimpleNestedURI(innerClone); michael@0: url->SetMutable(false); michael@0: michael@0: return url; michael@0: } michael@0: michael@0: // nsIClassInfo overrides michael@0: michael@0: NS_IMETHODIMP michael@0: nsSimpleNestedURI::GetClassIDNoAlloc(nsCID *aClassIDNoAlloc) michael@0: { michael@0: static NS_DEFINE_CID(kSimpleNestedURICID, NS_SIMPLENESTEDURI_CID); michael@0: michael@0: *aClassIDNoAlloc = kSimpleNestedURICID; michael@0: return NS_OK; michael@0: }