1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /* ***** BEGIN LICENSE BLOCK *****
3 : * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 : *
5 : * The contents of this file are subject to the Mozilla Public License Version
6 : * 1.1 (the "License"); you may not use this file except in compliance with
7 : * the License. You may obtain a copy of the License at
8 : * http://www.mozilla.org/MPL/
9 : *
10 : * Software distributed under the License is distributed on an "AS IS" basis,
11 : * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 : * for the specific language governing rights and limitations under the
13 : * License.
14 : *
15 : * The Original Code is mozilla.org code.
16 : *
17 : * The Initial Developer of the Original Code is
18 : * the Mozilla Corporation.
19 : * Portions created by the Initial Developer are Copyright (C) 2006
20 : * the Initial Developer. All Rights Reserved.
21 : *
22 : * Contributor(s):
23 : * Boris Zbarsky <bzbarsky@mit.edu> (Original author)
24 : *
25 : * Alternatively, the contents of this file may be used under the terms of
26 : * either of the GNU General Public License Version 2 or later (the "GPL"),
27 : * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 : * in which case the provisions of the GPL or the LGPL are applicable instead
29 : * of those above. If you wish to allow use of your version of this file only
30 : * under the terms of either the GPL or the LGPL, and not to allow others to
31 : * use your version of this file under the terms of the MPL, indicate your
32 : * decision by deleting the provisions above and replace them with the notice
33 : * and other provisions required by the GPL or the LGPL. If you do not delete
34 : * the provisions above, a recipient may use your version of this file under
35 : * the terms of any one of the MPL, the GPL or the LGPL.
36 : *
37 : * ***** END LICENSE BLOCK ***** */
38 :
39 : #include "IPCMessageUtils.h"
40 : #include "mozilla/net/NeckoMessageUtils.h"
41 :
42 : #include "nsSimpleNestedURI.h"
43 : #include "nsIObjectInputStream.h"
44 : #include "nsIObjectOutputStream.h"
45 : #include "nsNetUtil.h"
46 :
47 22374 : NS_IMPL_ISUPPORTS_INHERITED1(nsSimpleNestedURI, nsSimpleURI, nsINestedURI)
48 :
49 684 : nsSimpleNestedURI::nsSimpleNestedURI(nsIURI* innerURI)
50 684 : : mInnerURI(innerURI)
51 : {
52 684 : NS_ASSERTION(innerURI, "Must have inner URI");
53 684 : NS_TryToSetImmutable(innerURI);
54 684 : }
55 :
56 : // nsISerializable
57 :
58 : NS_IMETHODIMP
59 1 : nsSimpleNestedURI::Read(nsIObjectInputStream* aStream)
60 : {
61 1 : nsresult rv = nsSimpleURI::Read(aStream);
62 1 : if (NS_FAILED(rv)) return rv;
63 :
64 1 : NS_ASSERTION(!mMutable, "How did that happen?");
65 :
66 1 : rv = aStream->ReadObject(true, getter_AddRefs(mInnerURI));
67 1 : if (NS_FAILED(rv)) return rv;
68 :
69 1 : NS_TryToSetImmutable(mInnerURI);
70 :
71 1 : return rv;
72 : }
73 :
74 : NS_IMETHODIMP
75 1 : nsSimpleNestedURI::Write(nsIObjectOutputStream* aStream)
76 : {
77 2 : nsCOMPtr<nsISerializable> serializable = do_QueryInterface(mInnerURI);
78 1 : if (!serializable) {
79 : // We can't serialize ourselves
80 0 : return NS_ERROR_NOT_AVAILABLE;
81 : }
82 :
83 1 : nsresult rv = nsSimpleURI::Write(aStream);
84 1 : if (NS_FAILED(rv)) return rv;
85 :
86 : rv = aStream->WriteCompoundObject(mInnerURI, NS_GET_IID(nsIURI),
87 1 : true);
88 1 : return rv;
89 : }
90 :
91 : // nsIIPCSerializable
92 :
93 : bool
94 0 : nsSimpleNestedURI::Read(const IPC::Message *aMsg, void **aIter)
95 : {
96 0 : if (!nsSimpleURI::Read(aMsg, aIter))
97 0 : return false;
98 :
99 0 : IPC::URI uri;
100 0 : if (!ReadParam(aMsg, aIter, &uri))
101 0 : return false;
102 :
103 0 : mInnerURI = uri;
104 :
105 0 : return true;
106 : }
107 :
108 : void
109 0 : nsSimpleNestedURI::Write(IPC::Message *aMsg)
110 : {
111 0 : nsSimpleURI::Write(aMsg);
112 :
113 0 : IPC::URI uri(mInnerURI);
114 0 : WriteParam(aMsg, uri);
115 0 : }
116 :
117 : // nsINestedURI
118 :
119 : NS_IMETHODIMP
120 312 : nsSimpleNestedURI::GetInnerURI(nsIURI** uri)
121 : {
122 312 : NS_ENSURE_TRUE(mInnerURI, NS_ERROR_NOT_INITIALIZED);
123 :
124 312 : return NS_EnsureSafeToReturn(mInnerURI, uri);
125 : }
126 :
127 : NS_IMETHODIMP
128 10 : nsSimpleNestedURI::GetInnermostURI(nsIURI** uri)
129 : {
130 10 : return NS_ImplGetInnermostURI(this, uri);
131 : }
132 :
133 : // nsSimpleURI overrides
134 : /* virtual */ nsresult
135 298 : nsSimpleNestedURI::EqualsInternal(nsIURI* other,
136 : nsSimpleURI::RefHandlingEnum refHandlingMode,
137 : bool* result)
138 : {
139 298 : *result = false;
140 298 : NS_ENSURE_TRUE(mInnerURI, NS_ERROR_NOT_INITIALIZED);
141 :
142 298 : if (other) {
143 : bool correctScheme;
144 295 : nsresult rv = other->SchemeIs(mScheme.get(), &correctScheme);
145 295 : NS_ENSURE_SUCCESS(rv, rv);
146 :
147 295 : if (correctScheme) {
148 584 : nsCOMPtr<nsINestedURI> nest = do_QueryInterface(other);
149 292 : if (nest) {
150 584 : nsCOMPtr<nsIURI> otherInner;
151 292 : rv = nest->GetInnerURI(getter_AddRefs(otherInner));
152 292 : NS_ENSURE_SUCCESS(rv, rv);
153 :
154 : return (refHandlingMode == eHonorRef) ?
155 156 : otherInner->Equals(mInnerURI, result) :
156 448 : otherInner->EqualsExceptRef(mInnerURI, result);
157 : }
158 : }
159 : }
160 :
161 6 : return NS_OK;
162 : }
163 :
164 : /* virtual */ nsSimpleURI*
165 24 : nsSimpleNestedURI::StartClone(nsSimpleURI::RefHandlingEnum refHandlingMode)
166 : {
167 24 : NS_ENSURE_TRUE(mInnerURI, nsnull);
168 :
169 48 : nsCOMPtr<nsIURI> innerClone;
170 : nsresult rv = refHandlingMode == eHonorRef ?
171 48 : mInnerURI->Clone(getter_AddRefs(innerClone)) :
172 48 : mInnerURI->CloneIgnoringRef(getter_AddRefs(innerClone));
173 :
174 24 : if (NS_FAILED(rv)) {
175 0 : return nsnull;
176 : }
177 :
178 48 : nsSimpleNestedURI* url = new nsSimpleNestedURI(innerClone);
179 24 : url->SetMutable(false);
180 :
181 24 : return url;
182 : }
183 :
184 : // nsIClassInfo overrides
185 :
186 : NS_IMETHODIMP
187 0 : nsSimpleNestedURI::GetClassIDNoAlloc(nsCID *aClassIDNoAlloc)
188 : {
189 : static NS_DEFINE_CID(kSimpleNestedURICID, NS_SIMPLENESTEDURI_CID);
190 :
191 0 : *aClassIDNoAlloc = kSimpleNestedURICID;
192 0 : return NS_OK;
193 : }
|