Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 4 | |
michael@0 | 5 | #include "nsHostObjectURI.h" |
michael@0 | 6 | |
michael@0 | 7 | #include "nsAutoPtr.h" |
michael@0 | 8 | #include "nsIObjectInputStream.h" |
michael@0 | 9 | #include "nsIObjectOutputStream.h" |
michael@0 | 10 | #include "nsIProgrammingLanguage.h" |
michael@0 | 11 | |
michael@0 | 12 | static NS_DEFINE_CID(kHOSTOBJECTURICID, NS_HOSTOBJECTURI_CID); |
michael@0 | 13 | |
michael@0 | 14 | static NS_DEFINE_CID(kThisSimpleURIImplementationCID, |
michael@0 | 15 | NS_THIS_SIMPLEURI_IMPLEMENTATION_CID); |
michael@0 | 16 | |
michael@0 | 17 | NS_IMPL_ADDREF_INHERITED(nsHostObjectURI, nsSimpleURI) |
michael@0 | 18 | NS_IMPL_RELEASE_INHERITED(nsHostObjectURI, nsSimpleURI) |
michael@0 | 19 | |
michael@0 | 20 | NS_INTERFACE_MAP_BEGIN(nsHostObjectURI) |
michael@0 | 21 | NS_INTERFACE_MAP_ENTRY(nsIURIWithPrincipal) |
michael@0 | 22 | if (aIID.Equals(kHOSTOBJECTURICID)) |
michael@0 | 23 | foundInterface = static_cast<nsIURI*>(this); |
michael@0 | 24 | else if (aIID.Equals(kThisSimpleURIImplementationCID)) { |
michael@0 | 25 | // Need to return explicitly here, because if we just set foundInterface |
michael@0 | 26 | // to null the NS_INTERFACE_MAP_END_INHERITING will end up calling into |
michael@0 | 27 | // nsSimplURI::QueryInterface and finding something for this CID. |
michael@0 | 28 | *aInstancePtr = nullptr; |
michael@0 | 29 | return NS_NOINTERFACE; |
michael@0 | 30 | } |
michael@0 | 31 | else |
michael@0 | 32 | NS_INTERFACE_MAP_END_INHERITING(nsSimpleURI) |
michael@0 | 33 | |
michael@0 | 34 | // nsIURIWithPrincipal methods: |
michael@0 | 35 | |
michael@0 | 36 | NS_IMETHODIMP |
michael@0 | 37 | nsHostObjectURI::GetPrincipal(nsIPrincipal** aPrincipal) |
michael@0 | 38 | { |
michael@0 | 39 | NS_IF_ADDREF(*aPrincipal = mPrincipal); |
michael@0 | 40 | |
michael@0 | 41 | return NS_OK; |
michael@0 | 42 | } |
michael@0 | 43 | |
michael@0 | 44 | NS_IMETHODIMP |
michael@0 | 45 | nsHostObjectURI::GetPrincipalUri(nsIURI** aUri) |
michael@0 | 46 | { |
michael@0 | 47 | if (mPrincipal) { |
michael@0 | 48 | mPrincipal->GetURI(aUri); |
michael@0 | 49 | } |
michael@0 | 50 | else { |
michael@0 | 51 | *aUri = nullptr; |
michael@0 | 52 | } |
michael@0 | 53 | |
michael@0 | 54 | return NS_OK; |
michael@0 | 55 | } |
michael@0 | 56 | |
michael@0 | 57 | // nsISerializable methods: |
michael@0 | 58 | |
michael@0 | 59 | NS_IMETHODIMP |
michael@0 | 60 | nsHostObjectURI::Read(nsIObjectInputStream* aStream) |
michael@0 | 61 | { |
michael@0 | 62 | nsresult rv = nsSimpleURI::Read(aStream); |
michael@0 | 63 | NS_ENSURE_SUCCESS(rv, rv); |
michael@0 | 64 | |
michael@0 | 65 | nsCOMPtr<nsISupports> supports; |
michael@0 | 66 | rv = NS_ReadOptionalObject(aStream, true, getter_AddRefs(supports)); |
michael@0 | 67 | NS_ENSURE_SUCCESS(rv, rv); |
michael@0 | 68 | |
michael@0 | 69 | mPrincipal = do_QueryInterface(supports, &rv); |
michael@0 | 70 | return rv; |
michael@0 | 71 | } |
michael@0 | 72 | |
michael@0 | 73 | NS_IMETHODIMP |
michael@0 | 74 | nsHostObjectURI::Write(nsIObjectOutputStream* aStream) |
michael@0 | 75 | { |
michael@0 | 76 | nsresult rv = nsSimpleURI::Write(aStream); |
michael@0 | 77 | NS_ENSURE_SUCCESS(rv, rv); |
michael@0 | 78 | |
michael@0 | 79 | return NS_WriteOptionalCompoundObject(aStream, mPrincipal, |
michael@0 | 80 | NS_GET_IID(nsIPrincipal), |
michael@0 | 81 | true); |
michael@0 | 82 | } |
michael@0 | 83 | |
michael@0 | 84 | // nsIURI methods: |
michael@0 | 85 | nsresult |
michael@0 | 86 | nsHostObjectURI::CloneInternal(nsSimpleURI::RefHandlingEnum aRefHandlingMode, |
michael@0 | 87 | nsIURI** aClone) |
michael@0 | 88 | { |
michael@0 | 89 | nsCOMPtr<nsIURI> simpleClone; |
michael@0 | 90 | nsresult rv = |
michael@0 | 91 | nsSimpleURI::CloneInternal(aRefHandlingMode, getter_AddRefs(simpleClone)); |
michael@0 | 92 | NS_ENSURE_SUCCESS(rv, rv); |
michael@0 | 93 | |
michael@0 | 94 | #ifdef DEBUG |
michael@0 | 95 | nsRefPtr<nsHostObjectURI> uriCheck; |
michael@0 | 96 | rv = simpleClone->QueryInterface(kHOSTOBJECTURICID, getter_AddRefs(uriCheck)); |
michael@0 | 97 | NS_ABORT_IF_FALSE(NS_SUCCEEDED(rv) && uriCheck, |
michael@0 | 98 | "Unexpected!"); |
michael@0 | 99 | #endif |
michael@0 | 100 | |
michael@0 | 101 | nsHostObjectURI* u = static_cast<nsHostObjectURI*>(simpleClone.get()); |
michael@0 | 102 | |
michael@0 | 103 | u->mPrincipal = mPrincipal; |
michael@0 | 104 | |
michael@0 | 105 | simpleClone.forget(aClone); |
michael@0 | 106 | return NS_OK; |
michael@0 | 107 | } |
michael@0 | 108 | |
michael@0 | 109 | /* virtual */ nsresult |
michael@0 | 110 | nsHostObjectURI::EqualsInternal(nsIURI* aOther, |
michael@0 | 111 | nsSimpleURI::RefHandlingEnum aRefHandlingMode, |
michael@0 | 112 | bool* aResult) |
michael@0 | 113 | { |
michael@0 | 114 | if (!aOther) { |
michael@0 | 115 | *aResult = false; |
michael@0 | 116 | return NS_OK; |
michael@0 | 117 | } |
michael@0 | 118 | |
michael@0 | 119 | nsRefPtr<nsHostObjectURI> otherUri; |
michael@0 | 120 | aOther->QueryInterface(kHOSTOBJECTURICID, getter_AddRefs(otherUri)); |
michael@0 | 121 | if (!otherUri) { |
michael@0 | 122 | *aResult = false; |
michael@0 | 123 | return NS_OK; |
michael@0 | 124 | } |
michael@0 | 125 | |
michael@0 | 126 | // Compare the member data that our base class knows about. |
michael@0 | 127 | if (!nsSimpleURI::EqualsInternal(otherUri, aRefHandlingMode)) { |
michael@0 | 128 | *aResult = false; |
michael@0 | 129 | return NS_OK; |
michael@0 | 130 | } |
michael@0 | 131 | |
michael@0 | 132 | // Compare the piece of additional member data that we add to base class. |
michael@0 | 133 | if (mPrincipal && otherUri->mPrincipal) { |
michael@0 | 134 | // Both of us have mPrincipals. Compare them. |
michael@0 | 135 | return mPrincipal->Equals(otherUri->mPrincipal, aResult); |
michael@0 | 136 | } |
michael@0 | 137 | // else, at least one of us lacks a principal; only equal if *both* lack it. |
michael@0 | 138 | *aResult = (!mPrincipal && !otherUri->mPrincipal); |
michael@0 | 139 | return NS_OK; |
michael@0 | 140 | } |
michael@0 | 141 | |
michael@0 | 142 | // nsIClassInfo methods: |
michael@0 | 143 | NS_IMETHODIMP |
michael@0 | 144 | nsHostObjectURI::GetInterfaces(uint32_t *count, nsIID * **array) |
michael@0 | 145 | { |
michael@0 | 146 | *count = 0; |
michael@0 | 147 | *array = nullptr; |
michael@0 | 148 | return NS_OK; |
michael@0 | 149 | } |
michael@0 | 150 | |
michael@0 | 151 | NS_IMETHODIMP |
michael@0 | 152 | nsHostObjectURI::GetHelperForLanguage(uint32_t language, nsISupports **_retval) |
michael@0 | 153 | { |
michael@0 | 154 | *_retval = nullptr; |
michael@0 | 155 | return NS_OK; |
michael@0 | 156 | } |
michael@0 | 157 | |
michael@0 | 158 | NS_IMETHODIMP |
michael@0 | 159 | nsHostObjectURI::GetContractID(char * *aContractID) |
michael@0 | 160 | { |
michael@0 | 161 | // Make sure to modify any subclasses as needed if this ever |
michael@0 | 162 | // changes. |
michael@0 | 163 | *aContractID = nullptr; |
michael@0 | 164 | return NS_OK; |
michael@0 | 165 | } |
michael@0 | 166 | |
michael@0 | 167 | NS_IMETHODIMP |
michael@0 | 168 | nsHostObjectURI::GetClassDescription(char * *aClassDescription) |
michael@0 | 169 | { |
michael@0 | 170 | *aClassDescription = nullptr; |
michael@0 | 171 | return NS_OK; |
michael@0 | 172 | } |
michael@0 | 173 | |
michael@0 | 174 | NS_IMETHODIMP |
michael@0 | 175 | nsHostObjectURI::GetClassID(nsCID * *aClassID) |
michael@0 | 176 | { |
michael@0 | 177 | // Make sure to modify any subclasses as needed if this ever |
michael@0 | 178 | // changes to not call the virtual GetClassIDNoAlloc. |
michael@0 | 179 | *aClassID = (nsCID*) nsMemory::Alloc(sizeof(nsCID)); |
michael@0 | 180 | NS_ENSURE_TRUE(*aClassID, NS_ERROR_OUT_OF_MEMORY); |
michael@0 | 181 | |
michael@0 | 182 | return GetClassIDNoAlloc(*aClassID); |
michael@0 | 183 | } |
michael@0 | 184 | |
michael@0 | 185 | NS_IMETHODIMP |
michael@0 | 186 | nsHostObjectURI::GetImplementationLanguage(uint32_t *aImplementationLanguage) |
michael@0 | 187 | { |
michael@0 | 188 | *aImplementationLanguage = nsIProgrammingLanguage::CPLUSPLUS; |
michael@0 | 189 | return NS_OK; |
michael@0 | 190 | } |
michael@0 | 191 | |
michael@0 | 192 | NS_IMETHODIMP |
michael@0 | 193 | nsHostObjectURI::GetFlags(uint32_t *aFlags) |
michael@0 | 194 | { |
michael@0 | 195 | *aFlags = nsIClassInfo::MAIN_THREAD_ONLY; |
michael@0 | 196 | return NS_OK; |
michael@0 | 197 | } |
michael@0 | 198 | |
michael@0 | 199 | NS_IMETHODIMP |
michael@0 | 200 | nsHostObjectURI::GetClassIDNoAlloc(nsCID *aClassIDNoAlloc) |
michael@0 | 201 | { |
michael@0 | 202 | *aClassIDNoAlloc = kHOSTOBJECTURICID; |
michael@0 | 203 | return NS_OK; |
michael@0 | 204 | } |