/src/mozilla-central/dom/file/uri/BlobURL.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
2 | | /* vim: set ts=8 sts=2 et sw=2 tw=80: */ |
3 | | /* This Source Code Form is subject to the terms of the Mozilla Public |
4 | | * License, v. 2.0. If a copy of the MPL was not distributed with this |
5 | | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
6 | | |
7 | | #include "nsIObjectInputStream.h" |
8 | | #include "nsIObjectOutputStream.h" |
9 | | |
10 | | #include "mozilla/dom/BlobURL.h" |
11 | | #include "mozilla/dom/BlobURLProtocolHandler.h" |
12 | | #include "mozilla/ipc/BackgroundUtils.h" |
13 | | #include "mozilla/ipc/URIUtils.h" |
14 | | |
15 | | using namespace mozilla::dom; |
16 | | |
17 | | static NS_DEFINE_CID(kHOSTOBJECTURICID, NS_HOSTOBJECTURI_CID); |
18 | | |
19 | | static NS_DEFINE_CID(kThisSimpleURIImplementationCID, |
20 | | NS_THIS_SIMPLEURI_IMPLEMENTATION_CID); |
21 | | |
22 | | NS_IMPL_ADDREF_INHERITED(BlobURL, mozilla::net::nsSimpleURI) |
23 | | NS_IMPL_RELEASE_INHERITED(BlobURL, mozilla::net::nsSimpleURI) |
24 | | |
25 | 1.77k | NS_INTERFACE_MAP_BEGIN(BlobURL) |
26 | 1.77k | if (aIID.Equals(kHOSTOBJECTURICID)) |
27 | 1.77k | foundInterface = static_cast<nsIURI*>(this); |
28 | 0 | else if (aIID.Equals(kThisSimpleURIImplementationCID)) { |
29 | 0 | // Need to return explicitly here, because if we just set foundInterface |
30 | 0 | // to null the NS_INTERFACE_MAP_END_INHERITING will end up calling into |
31 | 0 | // nsSimplURI::QueryInterface and finding something for this CID. |
32 | 0 | *aInstancePtr = nullptr; |
33 | 0 | return NS_NOINTERFACE; |
34 | 0 | } |
35 | 0 | else |
36 | 0 | NS_INTERFACE_MAP_END_INHERITING(mozilla::net::nsSimpleURI) |
37 | | |
38 | | BlobURL::BlobURL() |
39 | | : mRevoked(false) |
40 | 1.77k | {} |
41 | | |
42 | | // nsISerializable methods: |
43 | | |
44 | | NS_IMETHODIMP |
45 | | BlobURL::Read(nsIObjectInputStream* aStream) |
46 | 0 | { |
47 | 0 | MOZ_ASSERT_UNREACHABLE("Use nsIURIMutator.read() instead"); |
48 | 0 | return NS_ERROR_NOT_IMPLEMENTED; |
49 | 0 | } |
50 | | |
51 | | nsresult |
52 | | BlobURL::ReadPrivate(nsIObjectInputStream *aStream) |
53 | 0 | { |
54 | 0 | nsresult rv = mozilla::net::nsSimpleURI::ReadPrivate(aStream); |
55 | 0 | NS_ENSURE_SUCCESS(rv, rv); |
56 | 0 |
|
57 | 0 | rv = aStream->ReadBoolean(&mRevoked); |
58 | 0 | NS_ENSURE_SUCCESS(rv, rv); |
59 | 0 |
|
60 | 0 | return NS_OK; |
61 | 0 | } |
62 | | |
63 | | NS_IMETHODIMP |
64 | | BlobURL::Write(nsIObjectOutputStream* aStream) |
65 | 0 | { |
66 | 0 | nsresult rv = mozilla::net::nsSimpleURI::Write(aStream); |
67 | 0 | NS_ENSURE_SUCCESS(rv, rv); |
68 | 0 |
|
69 | 0 | rv = aStream->WriteBoolean(mRevoked); |
70 | 0 | NS_ENSURE_SUCCESS(rv, rv); |
71 | 0 |
|
72 | 0 | return NS_OK; |
73 | 0 | } |
74 | | |
75 | | // nsIIPCSerializableURI methods: |
76 | | void |
77 | | BlobURL::Serialize(mozilla::ipc::URIParams& aParams) |
78 | 0 | { |
79 | 0 | using namespace mozilla::ipc; |
80 | 0 |
|
81 | 0 | HostObjectURIParams hostParams; |
82 | 0 | URIParams simpleParams; |
83 | 0 |
|
84 | 0 | mozilla::net::nsSimpleURI::Serialize(simpleParams); |
85 | 0 | hostParams.simpleParams() = simpleParams; |
86 | 0 |
|
87 | 0 | hostParams.revoked() = mRevoked; |
88 | 0 |
|
89 | 0 | aParams = hostParams; |
90 | 0 | } |
91 | | |
92 | | bool |
93 | | BlobURL::Deserialize(const mozilla::ipc::URIParams& aParams) |
94 | 0 | { |
95 | 0 | using namespace mozilla::ipc; |
96 | 0 |
|
97 | 0 | if (aParams.type() != URIParams::THostObjectURIParams) { |
98 | 0 | NS_ERROR("Received unknown parameters from the other process!"); |
99 | 0 | return false; |
100 | 0 | } |
101 | 0 |
|
102 | 0 | const HostObjectURIParams& hostParams = aParams.get_HostObjectURIParams(); |
103 | 0 |
|
104 | 0 | if (!mozilla::net::nsSimpleURI::Deserialize(hostParams.simpleParams())) { |
105 | 0 | return false; |
106 | 0 | } |
107 | 0 | |
108 | 0 | mRevoked = hostParams.revoked(); |
109 | 0 | return true; |
110 | 0 | } |
111 | | |
112 | | nsresult |
113 | | BlobURL::SetScheme(const nsACString& aScheme) |
114 | 0 | { |
115 | 0 | // Disallow setting the scheme, since that could cause us to be associated |
116 | 0 | // with a different protocol handler. |
117 | 0 | return NS_ERROR_FAILURE; |
118 | 0 | } |
119 | | |
120 | | // nsIURI methods: |
121 | | nsresult |
122 | | BlobURL::CloneInternal(mozilla::net::nsSimpleURI::RefHandlingEnum aRefHandlingMode, |
123 | | const nsACString& newRef, |
124 | | nsIURI** aClone) |
125 | 0 | { |
126 | 0 | nsCOMPtr<nsIURI> simpleClone; |
127 | 0 | nsresult rv = |
128 | 0 | mozilla::net::nsSimpleURI::CloneInternal(aRefHandlingMode, newRef, getter_AddRefs(simpleClone)); |
129 | 0 | NS_ENSURE_SUCCESS(rv, rv); |
130 | 0 |
|
131 | | #ifdef DEBUG |
132 | | RefPtr<BlobURL> uriCheck; |
133 | | rv = simpleClone->QueryInterface(kHOSTOBJECTURICID, getter_AddRefs(uriCheck)); |
134 | | MOZ_ASSERT(NS_SUCCEEDED(rv) && uriCheck); |
135 | | #endif |
136 | |
|
137 | 0 | BlobURL* u = static_cast<BlobURL*>(simpleClone.get()); |
138 | 0 | u->mRevoked = mRevoked; |
139 | 0 |
|
140 | 0 | simpleClone.forget(aClone); |
141 | 0 | return NS_OK; |
142 | 0 | } |
143 | | |
144 | | /* virtual */ nsresult |
145 | | BlobURL::EqualsInternal(nsIURI* aOther, |
146 | | mozilla::net::nsSimpleURI::RefHandlingEnum aRefHandlingMode, |
147 | | bool* aResult) |
148 | 0 | { |
149 | 0 | if (!aOther) { |
150 | 0 | *aResult = false; |
151 | 0 | return NS_OK; |
152 | 0 | } |
153 | 0 | |
154 | 0 | RefPtr<BlobURL> otherUri; |
155 | 0 | aOther->QueryInterface(kHOSTOBJECTURICID, getter_AddRefs(otherUri)); |
156 | 0 | if (!otherUri) { |
157 | 0 | *aResult = false; |
158 | 0 | return NS_OK; |
159 | 0 | } |
160 | 0 | |
161 | 0 | // Compare the member data that our base class knows about. |
162 | 0 | *aResult = mozilla::net::nsSimpleURI::EqualsInternal(otherUri, |
163 | 0 | aRefHandlingMode); |
164 | 0 |
|
165 | 0 | // We don't want to compare the revoked flag. |
166 | 0 | return NS_OK; |
167 | 0 | } |
168 | | |
169 | | // Queries this list of interfaces. If none match, it queries mURI. |
170 | | NS_IMPL_NSIURIMUTATOR_ISUPPORTS(BlobURL::Mutator, |
171 | | nsIURISetters, |
172 | | nsIURIMutator, |
173 | | nsISerializable) |
174 | | |
175 | | NS_IMETHODIMP |
176 | | BlobURL::Mutate(nsIURIMutator** aMutator) |
177 | 0 | { |
178 | 0 | RefPtr<BlobURL::Mutator> mutator = new BlobURL::Mutator(); |
179 | 0 | nsresult rv = mutator->InitFromURI(this); |
180 | 0 | if (NS_FAILED(rv)) { |
181 | 0 | return rv; |
182 | 0 | } |
183 | 0 | mutator.forget(aMutator); |
184 | 0 | return NS_OK; |
185 | 0 | } |
186 | | |
187 | | // nsIClassInfo methods: |
188 | | NS_IMETHODIMP |
189 | | BlobURL::GetInterfaces(uint32_t *count, nsIID * **array) |
190 | 0 | { |
191 | 0 | *count = 0; |
192 | 0 | *array = nullptr; |
193 | 0 | return NS_OK; |
194 | 0 | } |
195 | | |
196 | | NS_IMETHODIMP |
197 | | BlobURL::GetScriptableHelper(nsIXPCScriptable **_retval) |
198 | 0 | { |
199 | 0 | *_retval = nullptr; |
200 | 0 | return NS_OK; |
201 | 0 | } |
202 | | |
203 | | NS_IMETHODIMP |
204 | | BlobURL::GetContractID(nsACString& aContractID) |
205 | 0 | { |
206 | 0 | // Make sure to modify any subclasses as needed if this ever |
207 | 0 | // changes. |
208 | 0 | aContractID.SetIsVoid(true); |
209 | 0 | return NS_OK; |
210 | 0 | } |
211 | | |
212 | | NS_IMETHODIMP |
213 | | BlobURL::GetClassDescription(nsACString& aClassDescription) |
214 | 0 | { |
215 | 0 | aClassDescription.SetIsVoid(true); |
216 | 0 | return NS_OK; |
217 | 0 | } |
218 | | |
219 | | NS_IMETHODIMP |
220 | | BlobURL::GetClassID(nsCID * *aClassID) |
221 | 0 | { |
222 | 0 | // Make sure to modify any subclasses as needed if this ever |
223 | 0 | // changes to not call the virtual GetClassIDNoAlloc. |
224 | 0 | *aClassID = (nsCID*) moz_xmalloc(sizeof(nsCID)); |
225 | 0 |
|
226 | 0 | return GetClassIDNoAlloc(*aClassID); |
227 | 0 | } |
228 | | |
229 | | NS_IMETHODIMP |
230 | | BlobURL::GetFlags(uint32_t *aFlags) |
231 | 0 | { |
232 | 0 | *aFlags = nsIClassInfo::MAIN_THREAD_ONLY; |
233 | 0 | return NS_OK; |
234 | 0 | } |
235 | | |
236 | | NS_IMETHODIMP |
237 | | BlobURL::GetClassIDNoAlloc(nsCID *aClassIDNoAlloc) |
238 | 0 | { |
239 | 0 | *aClassIDNoAlloc = kHOSTOBJECTURICID; |
240 | 0 | return NS_OK; |
241 | 0 | } |