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
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/
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
15 * The Original Code is mozilla.org code.
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.
23 * Boris Zbarsky <bzbarsky@mit.edu> (Original author)
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.
37 * ***** END LICENSE BLOCK ***** */
39 #include "nsSimpleNestedURI.h"
40 #include "nsIObjectInputStream.h"
41 #include "nsIObjectOutputStream.h"
42 #include "nsNetUtil.h"
44 NS_IMPL_ISUPPORTS_INHERITED1(nsSimpleNestedURI
, nsSimpleURI
, nsINestedURI
)
46 nsSimpleNestedURI::nsSimpleNestedURI(nsIURI
* innerURI
)
47 : nsSimpleURI(nsnull
),
50 NS_ASSERTION(innerURI
, "Must have inner URI");
51 NS_TryToSetImmutable(innerURI
);
57 nsSimpleNestedURI::Read(nsIObjectInputStream
* aStream
)
59 nsresult rv
= nsSimpleURI::Read(aStream
);
60 if (NS_FAILED(rv
)) return rv
;
62 NS_ASSERTION(!mMutable
, "How did that happen?");
64 rv
= aStream
->ReadObject(PR_TRUE
, getter_AddRefs(mInnerURI
));
65 if (NS_FAILED(rv
)) return rv
;
67 NS_TryToSetImmutable(mInnerURI
);
73 nsSimpleNestedURI::Write(nsIObjectOutputStream
* aStream
)
75 nsCOMPtr
<nsISerializable
> serializable
= do_QueryInterface(mInnerURI
);
77 // We can't serialize ourselves
78 return NS_ERROR_NOT_AVAILABLE
;
81 nsresult rv
= nsSimpleURI::Write(aStream
);
82 if (NS_FAILED(rv
)) return rv
;
84 rv
= aStream
->WriteCompoundObject(mInnerURI
, NS_GET_IID(nsIURI
),
92 nsSimpleNestedURI::GetInnerURI(nsIURI
** uri
)
94 NS_ENSURE_TRUE(mInnerURI
, NS_ERROR_NOT_INITIALIZED
);
96 return NS_EnsureSafeToReturn(mInnerURI
, uri
);
100 nsSimpleNestedURI::GetInnermostURI(nsIURI
** uri
)
102 return NS_ImplGetInnermostURI(this, uri
);
108 nsSimpleNestedURI::Equals(nsIURI
* other
, PRBool
*result
)
111 NS_ENSURE_TRUE(mInnerURI
, NS_ERROR_NOT_INITIALIZED
);
114 PRBool correctScheme
;
115 nsresult rv
= other
->SchemeIs(mScheme
.get(), &correctScheme
);
116 NS_ENSURE_SUCCESS(rv
, rv
);
119 nsCOMPtr
<nsINestedURI
> nest
= do_QueryInterface(other
);
121 nsCOMPtr
<nsIURI
> otherInner
;
122 rv
= nest
->GetInnerURI(getter_AddRefs(otherInner
));
123 NS_ENSURE_SUCCESS(rv
, rv
);
125 return otherInner
->Equals(mInnerURI
, result
);
133 /* virtual */ nsSimpleURI
*
134 nsSimpleNestedURI::StartClone()
136 NS_ENSURE_TRUE(mInnerURI
, nsnull
);
138 nsCOMPtr
<nsIURI
> innerClone
;
139 nsresult rv
= mInnerURI
->Clone(getter_AddRefs(innerClone
));
144 nsSimpleNestedURI
* url
= new nsSimpleNestedURI(innerClone
);
146 url
->SetMutable(PR_FALSE
);
152 // nsIClassInfo overrides
155 nsSimpleNestedURI::GetClassIDNoAlloc(nsCID
*aClassIDNoAlloc
)
157 static NS_DEFINE_CID(kSimpleNestedURICID
, NS_SIMPLENESTEDURI_CID
);
159 *aClassIDNoAlloc
= kSimpleNestedURICID
;