netwerk/base/src/nsSimpleNestedURI.cpp

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

mercurial