1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/netwerk/base/src/nsSimpleNestedURI.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,137 @@ 1.4 +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +#include "base/basictypes.h" 1.10 + 1.11 +#include "nsSimpleNestedURI.h" 1.12 +#include "nsIObjectInputStream.h" 1.13 +#include "nsIObjectOutputStream.h" 1.14 +#include "nsNetUtil.h" 1.15 + 1.16 +NS_IMPL_ISUPPORTS_INHERITED(nsSimpleNestedURI, nsSimpleURI, nsINestedURI) 1.17 + 1.18 +nsSimpleNestedURI::nsSimpleNestedURI(nsIURI* innerURI) 1.19 + : mInnerURI(innerURI) 1.20 +{ 1.21 + NS_ASSERTION(innerURI, "Must have inner URI"); 1.22 + NS_TryToSetImmutable(innerURI); 1.23 +} 1.24 + 1.25 +// nsISerializable 1.26 + 1.27 +NS_IMETHODIMP 1.28 +nsSimpleNestedURI::Read(nsIObjectInputStream* aStream) 1.29 +{ 1.30 + nsresult rv = nsSimpleURI::Read(aStream); 1.31 + if (NS_FAILED(rv)) return rv; 1.32 + 1.33 + NS_ASSERTION(!mMutable, "How did that happen?"); 1.34 + 1.35 + nsCOMPtr<nsISupports> supports; 1.36 + rv = aStream->ReadObject(true, getter_AddRefs(supports)); 1.37 + if (NS_FAILED(rv)) return rv; 1.38 + 1.39 + mInnerURI = do_QueryInterface(supports, &rv); 1.40 + if (NS_FAILED(rv)) return rv; 1.41 + 1.42 + NS_TryToSetImmutable(mInnerURI); 1.43 + 1.44 + return rv; 1.45 +} 1.46 + 1.47 +NS_IMETHODIMP 1.48 +nsSimpleNestedURI::Write(nsIObjectOutputStream* aStream) 1.49 +{ 1.50 + nsCOMPtr<nsISerializable> serializable = do_QueryInterface(mInnerURI); 1.51 + if (!serializable) { 1.52 + // We can't serialize ourselves 1.53 + return NS_ERROR_NOT_AVAILABLE; 1.54 + } 1.55 + 1.56 + nsresult rv = nsSimpleURI::Write(aStream); 1.57 + if (NS_FAILED(rv)) return rv; 1.58 + 1.59 + rv = aStream->WriteCompoundObject(mInnerURI, NS_GET_IID(nsIURI), 1.60 + true); 1.61 + return rv; 1.62 +} 1.63 + 1.64 +// nsINestedURI 1.65 + 1.66 +NS_IMETHODIMP 1.67 +nsSimpleNestedURI::GetInnerURI(nsIURI** uri) 1.68 +{ 1.69 + NS_ENSURE_TRUE(mInnerURI, NS_ERROR_NOT_INITIALIZED); 1.70 + 1.71 + return NS_EnsureSafeToReturn(mInnerURI, uri); 1.72 +} 1.73 + 1.74 +NS_IMETHODIMP 1.75 +nsSimpleNestedURI::GetInnermostURI(nsIURI** uri) 1.76 +{ 1.77 + return NS_ImplGetInnermostURI(this, uri); 1.78 +} 1.79 + 1.80 +// nsSimpleURI overrides 1.81 +/* virtual */ nsresult 1.82 +nsSimpleNestedURI::EqualsInternal(nsIURI* other, 1.83 + nsSimpleURI::RefHandlingEnum refHandlingMode, 1.84 + bool* result) 1.85 +{ 1.86 + *result = false; 1.87 + NS_ENSURE_TRUE(mInnerURI, NS_ERROR_NOT_INITIALIZED); 1.88 + 1.89 + if (other) { 1.90 + bool correctScheme; 1.91 + nsresult rv = other->SchemeIs(mScheme.get(), &correctScheme); 1.92 + NS_ENSURE_SUCCESS(rv, rv); 1.93 + 1.94 + if (correctScheme) { 1.95 + nsCOMPtr<nsINestedURI> nest = do_QueryInterface(other); 1.96 + if (nest) { 1.97 + nsCOMPtr<nsIURI> otherInner; 1.98 + rv = nest->GetInnerURI(getter_AddRefs(otherInner)); 1.99 + NS_ENSURE_SUCCESS(rv, rv); 1.100 + 1.101 + return (refHandlingMode == eHonorRef) ? 1.102 + otherInner->Equals(mInnerURI, result) : 1.103 + otherInner->EqualsExceptRef(mInnerURI, result); 1.104 + } 1.105 + } 1.106 + } 1.107 + 1.108 + return NS_OK; 1.109 +} 1.110 + 1.111 +/* virtual */ nsSimpleURI* 1.112 +nsSimpleNestedURI::StartClone(nsSimpleURI::RefHandlingEnum refHandlingMode) 1.113 +{ 1.114 + NS_ENSURE_TRUE(mInnerURI, nullptr); 1.115 + 1.116 + nsCOMPtr<nsIURI> innerClone; 1.117 + nsresult rv = refHandlingMode == eHonorRef ? 1.118 + mInnerURI->Clone(getter_AddRefs(innerClone)) : 1.119 + mInnerURI->CloneIgnoringRef(getter_AddRefs(innerClone)); 1.120 + 1.121 + if (NS_FAILED(rv)) { 1.122 + return nullptr; 1.123 + } 1.124 + 1.125 + nsSimpleNestedURI* url = new nsSimpleNestedURI(innerClone); 1.126 + url->SetMutable(false); 1.127 + 1.128 + return url; 1.129 +} 1.130 + 1.131 +// nsIClassInfo overrides 1.132 + 1.133 +NS_IMETHODIMP 1.134 +nsSimpleNestedURI::GetClassIDNoAlloc(nsCID *aClassIDNoAlloc) 1.135 +{ 1.136 + static NS_DEFINE_CID(kSimpleNestedURICID, NS_SIMPLENESTEDURI_CID); 1.137 + 1.138 + *aClassIDNoAlloc = kSimpleNestedURICID; 1.139 + return NS_OK; 1.140 +}