Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
michael@0 | 2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | #include "base/basictypes.h" |
michael@0 | 7 | |
michael@0 | 8 | #include "nsSimpleNestedURI.h" |
michael@0 | 9 | #include "nsIObjectInputStream.h" |
michael@0 | 10 | #include "nsIObjectOutputStream.h" |
michael@0 | 11 | #include "nsNetUtil.h" |
michael@0 | 12 | |
michael@0 | 13 | NS_IMPL_ISUPPORTS_INHERITED(nsSimpleNestedURI, nsSimpleURI, nsINestedURI) |
michael@0 | 14 | |
michael@0 | 15 | nsSimpleNestedURI::nsSimpleNestedURI(nsIURI* innerURI) |
michael@0 | 16 | : mInnerURI(innerURI) |
michael@0 | 17 | { |
michael@0 | 18 | NS_ASSERTION(innerURI, "Must have inner URI"); |
michael@0 | 19 | NS_TryToSetImmutable(innerURI); |
michael@0 | 20 | } |
michael@0 | 21 | |
michael@0 | 22 | // nsISerializable |
michael@0 | 23 | |
michael@0 | 24 | NS_IMETHODIMP |
michael@0 | 25 | nsSimpleNestedURI::Read(nsIObjectInputStream* aStream) |
michael@0 | 26 | { |
michael@0 | 27 | nsresult rv = nsSimpleURI::Read(aStream); |
michael@0 | 28 | if (NS_FAILED(rv)) return rv; |
michael@0 | 29 | |
michael@0 | 30 | NS_ASSERTION(!mMutable, "How did that happen?"); |
michael@0 | 31 | |
michael@0 | 32 | nsCOMPtr<nsISupports> supports; |
michael@0 | 33 | rv = aStream->ReadObject(true, getter_AddRefs(supports)); |
michael@0 | 34 | if (NS_FAILED(rv)) return rv; |
michael@0 | 35 | |
michael@0 | 36 | mInnerURI = do_QueryInterface(supports, &rv); |
michael@0 | 37 | if (NS_FAILED(rv)) return rv; |
michael@0 | 38 | |
michael@0 | 39 | NS_TryToSetImmutable(mInnerURI); |
michael@0 | 40 | |
michael@0 | 41 | return rv; |
michael@0 | 42 | } |
michael@0 | 43 | |
michael@0 | 44 | NS_IMETHODIMP |
michael@0 | 45 | nsSimpleNestedURI::Write(nsIObjectOutputStream* aStream) |
michael@0 | 46 | { |
michael@0 | 47 | nsCOMPtr<nsISerializable> serializable = do_QueryInterface(mInnerURI); |
michael@0 | 48 | if (!serializable) { |
michael@0 | 49 | // We can't serialize ourselves |
michael@0 | 50 | return NS_ERROR_NOT_AVAILABLE; |
michael@0 | 51 | } |
michael@0 | 52 | |
michael@0 | 53 | nsresult rv = nsSimpleURI::Write(aStream); |
michael@0 | 54 | if (NS_FAILED(rv)) return rv; |
michael@0 | 55 | |
michael@0 | 56 | rv = aStream->WriteCompoundObject(mInnerURI, NS_GET_IID(nsIURI), |
michael@0 | 57 | true); |
michael@0 | 58 | return rv; |
michael@0 | 59 | } |
michael@0 | 60 | |
michael@0 | 61 | // nsINestedURI |
michael@0 | 62 | |
michael@0 | 63 | NS_IMETHODIMP |
michael@0 | 64 | nsSimpleNestedURI::GetInnerURI(nsIURI** uri) |
michael@0 | 65 | { |
michael@0 | 66 | NS_ENSURE_TRUE(mInnerURI, NS_ERROR_NOT_INITIALIZED); |
michael@0 | 67 | |
michael@0 | 68 | return NS_EnsureSafeToReturn(mInnerURI, uri); |
michael@0 | 69 | } |
michael@0 | 70 | |
michael@0 | 71 | NS_IMETHODIMP |
michael@0 | 72 | nsSimpleNestedURI::GetInnermostURI(nsIURI** uri) |
michael@0 | 73 | { |
michael@0 | 74 | return NS_ImplGetInnermostURI(this, uri); |
michael@0 | 75 | } |
michael@0 | 76 | |
michael@0 | 77 | // nsSimpleURI overrides |
michael@0 | 78 | /* virtual */ nsresult |
michael@0 | 79 | nsSimpleNestedURI::EqualsInternal(nsIURI* other, |
michael@0 | 80 | nsSimpleURI::RefHandlingEnum refHandlingMode, |
michael@0 | 81 | bool* result) |
michael@0 | 82 | { |
michael@0 | 83 | *result = false; |
michael@0 | 84 | NS_ENSURE_TRUE(mInnerURI, NS_ERROR_NOT_INITIALIZED); |
michael@0 | 85 | |
michael@0 | 86 | if (other) { |
michael@0 | 87 | bool correctScheme; |
michael@0 | 88 | nsresult rv = other->SchemeIs(mScheme.get(), &correctScheme); |
michael@0 | 89 | NS_ENSURE_SUCCESS(rv, rv); |
michael@0 | 90 | |
michael@0 | 91 | if (correctScheme) { |
michael@0 | 92 | nsCOMPtr<nsINestedURI> nest = do_QueryInterface(other); |
michael@0 | 93 | if (nest) { |
michael@0 | 94 | nsCOMPtr<nsIURI> otherInner; |
michael@0 | 95 | rv = nest->GetInnerURI(getter_AddRefs(otherInner)); |
michael@0 | 96 | NS_ENSURE_SUCCESS(rv, rv); |
michael@0 | 97 | |
michael@0 | 98 | return (refHandlingMode == eHonorRef) ? |
michael@0 | 99 | otherInner->Equals(mInnerURI, result) : |
michael@0 | 100 | otherInner->EqualsExceptRef(mInnerURI, result); |
michael@0 | 101 | } |
michael@0 | 102 | } |
michael@0 | 103 | } |
michael@0 | 104 | |
michael@0 | 105 | return NS_OK; |
michael@0 | 106 | } |
michael@0 | 107 | |
michael@0 | 108 | /* virtual */ nsSimpleURI* |
michael@0 | 109 | nsSimpleNestedURI::StartClone(nsSimpleURI::RefHandlingEnum refHandlingMode) |
michael@0 | 110 | { |
michael@0 | 111 | NS_ENSURE_TRUE(mInnerURI, nullptr); |
michael@0 | 112 | |
michael@0 | 113 | nsCOMPtr<nsIURI> innerClone; |
michael@0 | 114 | nsresult rv = refHandlingMode == eHonorRef ? |
michael@0 | 115 | mInnerURI->Clone(getter_AddRefs(innerClone)) : |
michael@0 | 116 | mInnerURI->CloneIgnoringRef(getter_AddRefs(innerClone)); |
michael@0 | 117 | |
michael@0 | 118 | if (NS_FAILED(rv)) { |
michael@0 | 119 | return nullptr; |
michael@0 | 120 | } |
michael@0 | 121 | |
michael@0 | 122 | nsSimpleNestedURI* url = new nsSimpleNestedURI(innerClone); |
michael@0 | 123 | url->SetMutable(false); |
michael@0 | 124 | |
michael@0 | 125 | return url; |
michael@0 | 126 | } |
michael@0 | 127 | |
michael@0 | 128 | // nsIClassInfo overrides |
michael@0 | 129 | |
michael@0 | 130 | NS_IMETHODIMP |
michael@0 | 131 | nsSimpleNestedURI::GetClassIDNoAlloc(nsCID *aClassIDNoAlloc) |
michael@0 | 132 | { |
michael@0 | 133 | static NS_DEFINE_CID(kSimpleNestedURICID, NS_SIMPLENESTEDURI_CID); |
michael@0 | 134 | |
michael@0 | 135 | *aClassIDNoAlloc = kSimpleNestedURICID; |
michael@0 | 136 | return NS_OK; |
michael@0 | 137 | } |