Bug 1804798 - Explicitly set auto page name (and corresponding debug flag) when inser...
[gecko.git] / netwerk / base / nsSimpleNestedURI.cpp
blob6427009c84fe8da7de30a22464ee313584526941
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #include "base/basictypes.h"
8 #include "nsNetCID.h"
9 #include "nsNetUtil.h"
10 #include "nsSimpleNestedURI.h"
11 #include "nsIObjectInputStream.h"
12 #include "nsIObjectOutputStream.h"
14 #include "mozilla/ipc/URIUtils.h"
16 namespace mozilla {
17 namespace net {
19 NS_IMPL_CLASSINFO(nsSimpleNestedURI, nullptr, nsIClassInfo::THREADSAFE,
20 NS_SIMPLENESTEDURI_CID)
21 // Empty CI getter. We only need nsIClassInfo for Serialization
22 NS_IMPL_CI_INTERFACE_GETTER0(nsSimpleNestedURI)
24 NS_IMPL_ADDREF_INHERITED(nsSimpleNestedURI, nsSimpleURI)
25 NS_IMPL_RELEASE_INHERITED(nsSimpleNestedURI, nsSimpleURI)
26 NS_IMPL_QUERY_INTERFACE_CI_INHERITED(nsSimpleNestedURI, nsSimpleURI,
27 nsINestedURI)
29 nsSimpleNestedURI::nsSimpleNestedURI(nsIURI* innerURI) : mInnerURI(innerURI) {
30 NS_ASSERTION(innerURI, "Must have inner URI");
33 nsresult nsSimpleNestedURI::SetPathQueryRef(const nsACString& aPathQueryRef) {
34 NS_ENSURE_TRUE(mInnerURI, NS_ERROR_NOT_INITIALIZED);
36 nsCOMPtr<nsIURI> inner;
37 nsresult rv =
38 NS_MutateURI(mInnerURI).SetPathQueryRef(aPathQueryRef).Finalize(inner);
39 NS_ENSURE_SUCCESS(rv, rv);
40 rv = nsSimpleURI::SetPathQueryRef(aPathQueryRef);
41 NS_ENSURE_SUCCESS(rv, rv);
42 // If the regular SetPathQueryRef worked, also set it on the inner URI
43 mInnerURI = inner;
44 return NS_OK;
47 nsresult nsSimpleNestedURI::SetQuery(const nsACString& aQuery) {
48 NS_ENSURE_TRUE(mInnerURI, NS_ERROR_NOT_INITIALIZED);
50 nsCOMPtr<nsIURI> inner;
51 nsresult rv = NS_MutateURI(mInnerURI).SetQuery(aQuery).Finalize(inner);
52 NS_ENSURE_SUCCESS(rv, rv);
53 rv = nsSimpleURI::SetQuery(aQuery);
54 NS_ENSURE_SUCCESS(rv, rv);
55 // If the regular SetQuery worked, also set it on the inner URI
56 mInnerURI = inner;
57 return NS_OK;
60 nsresult nsSimpleNestedURI::SetRef(const nsACString& aRef) {
61 NS_ENSURE_TRUE(mInnerURI, NS_ERROR_NOT_INITIALIZED);
63 nsCOMPtr<nsIURI> inner;
64 nsresult rv = NS_MutateURI(mInnerURI).SetRef(aRef).Finalize(inner);
65 NS_ENSURE_SUCCESS(rv, rv);
66 rv = nsSimpleURI::SetRef(aRef);
67 NS_ENSURE_SUCCESS(rv, rv);
68 // If the regular SetRef worked, also set it on the inner URI
69 mInnerURI = inner;
70 return NS_OK;
73 // nsISerializable
75 NS_IMETHODIMP
76 nsSimpleNestedURI::Read(nsIObjectInputStream* aStream) {
77 MOZ_ASSERT_UNREACHABLE("Use nsIURIMutator.read() instead");
78 return NS_ERROR_NOT_IMPLEMENTED;
81 nsresult nsSimpleNestedURI::ReadPrivate(nsIObjectInputStream* aStream) {
82 nsresult rv = nsSimpleURI::ReadPrivate(aStream);
83 if (NS_FAILED(rv)) return rv;
85 nsCOMPtr<nsISupports> supports;
86 rv = aStream->ReadObject(true, getter_AddRefs(supports));
87 if (NS_FAILED(rv)) return rv;
89 mInnerURI = do_QueryInterface(supports, &rv);
90 if (NS_FAILED(rv)) return rv;
92 return rv;
95 NS_IMETHODIMP
96 nsSimpleNestedURI::Write(nsIObjectOutputStream* aStream) {
97 nsCOMPtr<nsISerializable> serializable = do_QueryInterface(mInnerURI);
98 if (!serializable) {
99 // We can't serialize ourselves
100 return NS_ERROR_NOT_AVAILABLE;
103 nsresult rv = nsSimpleURI::Write(aStream);
104 if (NS_FAILED(rv)) return rv;
106 rv = aStream->WriteCompoundObject(mInnerURI, NS_GET_IID(nsIURI), true);
107 return rv;
110 NS_IMETHODIMP_(void)
111 nsSimpleNestedURI::Serialize(mozilla::ipc::URIParams& aParams) {
112 using namespace mozilla::ipc;
114 SimpleNestedURIParams params;
115 URIParams simpleParams;
117 nsSimpleURI::Serialize(simpleParams);
118 params.simpleParams() = simpleParams;
120 SerializeURI(mInnerURI, params.innerURI());
122 aParams = params;
125 bool nsSimpleNestedURI::Deserialize(const mozilla::ipc::URIParams& aParams) {
126 using namespace mozilla::ipc;
128 if (aParams.type() != URIParams::TSimpleNestedURIParams) {
129 NS_ERROR("Received unknown parameters from the other process!");
130 return false;
133 const SimpleNestedURIParams& params = aParams.get_SimpleNestedURIParams();
134 if (!nsSimpleURI::Deserialize(params.simpleParams())) return false;
136 mInnerURI = DeserializeURI(params.innerURI());
137 return true;
140 // nsINestedURI
142 NS_IMETHODIMP
143 nsSimpleNestedURI::GetInnerURI(nsIURI** aURI) {
144 NS_ENSURE_TRUE(mInnerURI, NS_ERROR_NOT_INITIALIZED);
146 nsCOMPtr<nsIURI> uri = mInnerURI;
147 uri.forget(aURI);
148 return NS_OK;
151 NS_IMETHODIMP
152 nsSimpleNestedURI::GetInnermostURI(nsIURI** uri) {
153 return NS_ImplGetInnermostURI(this, uri);
156 // nsSimpleURI overrides
157 /* virtual */
158 nsresult nsSimpleNestedURI::EqualsInternal(
159 nsIURI* other, nsSimpleURI::RefHandlingEnum refHandlingMode, bool* result) {
160 *result = false;
161 NS_ENSURE_TRUE(mInnerURI, NS_ERROR_NOT_INITIALIZED);
163 if (other) {
164 bool correctScheme;
165 nsresult rv = other->SchemeIs(mScheme.get(), &correctScheme);
166 NS_ENSURE_SUCCESS(rv, rv);
168 if (correctScheme) {
169 nsCOMPtr<nsINestedURI> nest = do_QueryInterface(other);
170 if (nest) {
171 nsCOMPtr<nsIURI> otherInner;
172 rv = nest->GetInnerURI(getter_AddRefs(otherInner));
173 NS_ENSURE_SUCCESS(rv, rv);
175 return (refHandlingMode == eHonorRef)
176 ? otherInner->Equals(mInnerURI, result)
177 : otherInner->EqualsExceptRef(mInnerURI, result);
182 return NS_OK;
185 /* virtual */
186 nsSimpleURI* nsSimpleNestedURI::StartClone(
187 nsSimpleURI::RefHandlingEnum refHandlingMode, const nsACString& newRef) {
188 NS_ENSURE_TRUE(mInnerURI, nullptr);
190 nsCOMPtr<nsIURI> innerClone;
191 nsresult rv = NS_OK;
192 if (refHandlingMode == eHonorRef) {
193 innerClone = mInnerURI;
194 } else if (refHandlingMode == eReplaceRef) {
195 rv = NS_GetURIWithNewRef(mInnerURI, newRef, getter_AddRefs(innerClone));
196 } else {
197 rv = NS_GetURIWithoutRef(mInnerURI, getter_AddRefs(innerClone));
200 if (NS_FAILED(rv)) {
201 return nullptr;
204 nsSimpleNestedURI* url = new nsSimpleNestedURI(innerClone);
205 SetRefOnClone(url, refHandlingMode, newRef);
207 return url;
210 // Queries this list of interfaces. If none match, it queries mURI.
211 NS_IMPL_NSIURIMUTATOR_ISUPPORTS(nsSimpleNestedURI::Mutator, nsIURISetters,
212 nsIURIMutator, nsISerializable,
213 nsINestedURIMutator)
215 NS_IMETHODIMP
216 nsSimpleNestedURI::Mutate(nsIURIMutator** aMutator) {
217 RefPtr<nsSimpleNestedURI::Mutator> mutator = new nsSimpleNestedURI::Mutator();
218 nsresult rv = mutator->InitFromURI(this);
219 if (NS_FAILED(rv)) {
220 return rv;
222 mutator.forget(aMutator);
223 return NS_OK;
226 } // namespace net
227 } // namespace mozilla