Bug 458861. Validate TrueType headers before activating downloaded font. r=roc, sr...
[wine-gecko.git] / netwerk / base / src / nsSimpleNestedURI.cpp
blobbcefbd075224fbadaed0345813419579b062bcc3
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
13 * License.
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.
22 * Contributor(s):
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),
48 mInnerURI(innerURI)
50 NS_ASSERTION(innerURI, "Must have inner URI");
51 NS_TryToSetImmutable(innerURI);
54 // nsISerializable
56 NS_IMETHODIMP
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);
69 return rv;
72 NS_IMETHODIMP
73 nsSimpleNestedURI::Write(nsIObjectOutputStream* aStream)
75 nsCOMPtr<nsISerializable> serializable = do_QueryInterface(mInnerURI);
76 if (!serializable) {
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),
85 PR_TRUE);
86 return rv;
89 // nsINestedURI
91 NS_IMETHODIMP
92 nsSimpleNestedURI::GetInnerURI(nsIURI** uri)
94 NS_ENSURE_TRUE(mInnerURI, NS_ERROR_NOT_INITIALIZED);
96 return NS_EnsureSafeToReturn(mInnerURI, uri);
99 NS_IMETHODIMP
100 nsSimpleNestedURI::GetInnermostURI(nsIURI** uri)
102 return NS_ImplGetInnermostURI(this, uri);
105 // nsIURI overrides
107 NS_IMETHODIMP
108 nsSimpleNestedURI::Equals(nsIURI* other, PRBool *result)
110 *result = PR_FALSE;
111 NS_ENSURE_TRUE(mInnerURI, NS_ERROR_NOT_INITIALIZED);
113 if (other) {
114 PRBool correctScheme;
115 nsresult rv = other->SchemeIs(mScheme.get(), &correctScheme);
116 NS_ENSURE_SUCCESS(rv, rv);
118 if (correctScheme) {
119 nsCOMPtr<nsINestedURI> nest = do_QueryInterface(other);
120 if (nest) {
121 nsCOMPtr<nsIURI> otherInner;
122 rv = nest->GetInnerURI(getter_AddRefs(otherInner));
123 NS_ENSURE_SUCCESS(rv, rv);
125 return otherInner->Equals(mInnerURI, result);
130 return NS_OK;
133 /* virtual */ nsSimpleURI*
134 nsSimpleNestedURI::StartClone()
136 NS_ENSURE_TRUE(mInnerURI, nsnull);
138 nsCOMPtr<nsIURI> innerClone;
139 nsresult rv = mInnerURI->Clone(getter_AddRefs(innerClone));
140 if (NS_FAILED(rv)) {
141 return nsnull;
144 nsSimpleNestedURI* url = new nsSimpleNestedURI(innerClone);
145 if (url) {
146 url->SetMutable(PR_FALSE);
149 return url;
152 // nsIClassInfo overrides
154 NS_IMETHODIMP
155 nsSimpleNestedURI::GetClassIDNoAlloc(nsCID *aClassIDNoAlloc)
157 static NS_DEFINE_CID(kSimpleNestedURICID, NS_SIMPLENESTEDURI_CID);
159 *aClassIDNoAlloc = kSimpleNestedURICID;
160 return NS_OK;