Merge mozilla-central to autoland. CLOSED TREE
[gecko.git] / modules / libjar / nsJARURI.cpp
blobc55868cdfdf0d71f4197af13b23f613700045e86
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
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/. */
7 #include "base/basictypes.h"
9 #include "nsJARURI.h"
10 #include "nsNetUtil.h"
11 #include "nsIClassInfoImpl.h"
12 #include "nsIIOService.h"
13 #include "nsIStandardURL.h"
14 #include "nsCRT.h"
15 #include "nsReadableUtils.h"
16 #include "nsNetCID.h"
17 #include "nsIObjectInputStream.h"
18 #include "nsIObjectOutputStream.h"
19 #include "nsQueryObject.h"
20 #include "mozilla/ipc/URIUtils.h"
22 using namespace mozilla::ipc;
24 ////////////////////////////////////////////////////////////////////////////////
26 NS_IMPL_CLASSINFO(nsJARURI, nullptr, nsIClassInfo::THREADSAFE, NS_JARURI_CID)
27 // Empty CI getter. We only need nsIClassInfo for Serialization
28 NS_IMPL_CI_INTERFACE_GETTER0(nsJARURI)
30 nsJARURI::nsJARURI() {}
32 nsJARURI::~nsJARURI() {}
34 // XXX Why is this threadsafe?
35 NS_IMPL_ADDREF(nsJARURI)
36 NS_IMPL_RELEASE(nsJARURI)
37 NS_INTERFACE_MAP_BEGIN(nsJARURI)
38 NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIJARURI)
39 NS_INTERFACE_MAP_ENTRY(nsIURI)
40 NS_INTERFACE_MAP_ENTRY(nsIURL)
41 NS_INTERFACE_MAP_ENTRY(nsIJARURI)
42 NS_INTERFACE_MAP_ENTRY(nsISerializable)
43 NS_IMPL_QUERY_CLASSINFO(nsJARURI)
44 NS_INTERFACE_MAP_ENTRY(nsINestedURI)
45 NS_INTERFACE_MAP_ENTRY_CONCRETE(nsJARURI)
46 NS_INTERFACE_MAP_END
48 nsresult nsJARURI::Init(const char* charsetHint) {
49 mCharsetHint = charsetHint;
50 return NS_OK;
53 #define NS_JAR_SCHEME "jar:"_ns
54 #define NS_JAR_DELIMITER "!/"_ns
55 #define NS_BOGUS_ENTRY_SCHEME "x:///"_ns
57 // FormatSpec takes the entry spec (including the "x:///" at the
58 // beginning) and gives us a full JAR spec.
59 nsresult nsJARURI::FormatSpec(const nsACString& entrySpec, nsACString& result,
60 bool aIncludeScheme) {
61 // The entrySpec MUST start with "x:///"
62 NS_ASSERTION(StringBeginsWith(entrySpec, NS_BOGUS_ENTRY_SCHEME),
63 "bogus entry spec");
65 nsAutoCString fileSpec;
66 nsresult rv = mJARFile->GetSpec(fileSpec);
67 if (NS_FAILED(rv)) return rv;
69 if (aIncludeScheme)
70 result = NS_JAR_SCHEME;
71 else
72 result.Truncate();
74 result.Append(fileSpec + NS_JAR_DELIMITER +
75 Substring(entrySpec, 5, entrySpec.Length() - 5));
76 return NS_OK;
79 nsresult nsJARURI::CreateEntryURL(const nsACString& entryFilename,
80 const char* charset, nsIURL** url) {
81 *url = nullptr;
82 // Flatten the concatenation, just in case. See bug 128288
83 nsAutoCString spec(NS_BOGUS_ENTRY_SCHEME + entryFilename);
84 return NS_MutateURI(NS_STANDARDURLMUTATOR_CONTRACTID)
85 .Apply(&nsIStandardURLMutator::Init, nsIStandardURL::URLTYPE_NO_AUTHORITY,
86 -1, spec, charset, nullptr, nullptr)
87 .Finalize(url);
90 ////////////////////////////////////////////////////////////////////////////////
91 // nsISerializable methods:
93 NS_IMETHODIMP
94 nsJARURI::Read(nsIObjectInputStream* aStream) {
95 MOZ_ASSERT_UNREACHABLE("Use nsIURIMutator.read() instead");
96 return NS_ERROR_NOT_IMPLEMENTED;
99 nsresult nsJARURI::ReadPrivate(nsIObjectInputStream* aInputStream) {
100 nsresult rv;
102 nsCOMPtr<nsISupports> supports;
103 rv = aInputStream->ReadObject(true, getter_AddRefs(supports));
104 NS_ENSURE_SUCCESS(rv, rv);
106 mJARFile = do_QueryInterface(supports, &rv);
107 NS_ENSURE_SUCCESS(rv, rv);
109 rv = aInputStream->ReadObject(true, getter_AddRefs(supports));
110 NS_ENSURE_SUCCESS(rv, rv);
112 mJAREntry = do_QueryInterface(supports);
113 NS_ENSURE_SUCCESS(rv, rv);
115 rv = aInputStream->ReadCString(mCharsetHint);
116 return rv;
119 NS_IMETHODIMP
120 nsJARURI::Write(nsIObjectOutputStream* aOutputStream) {
121 nsresult rv;
123 rv = aOutputStream->WriteCompoundObject(mJARFile, NS_GET_IID(nsIURI), true);
124 NS_ENSURE_SUCCESS(rv, rv);
126 rv = aOutputStream->WriteCompoundObject(mJAREntry, NS_GET_IID(nsIURL), true);
127 NS_ENSURE_SUCCESS(rv, rv);
129 rv = aOutputStream->WriteStringZ(mCharsetHint.get());
130 return rv;
133 ////////////////////////////////////////////////////////////////////////////////
134 // nsIURI methods:
136 NS_IMETHODIMP
137 nsJARURI::GetSpec(nsACString& aSpec) {
138 nsAutoCString entrySpec;
139 mJAREntry->GetSpec(entrySpec);
140 return FormatSpec(entrySpec, aSpec);
143 NS_IMETHODIMP
144 nsJARURI::GetSpecIgnoringRef(nsACString& aSpec) {
145 nsAutoCString entrySpec;
146 mJAREntry->GetSpecIgnoringRef(entrySpec);
147 return FormatSpec(entrySpec, aSpec);
150 NS_IMETHODIMP
151 nsJARURI::GetDisplaySpec(nsACString& aUnicodeSpec) {
152 return GetSpec(aUnicodeSpec);
155 NS_IMETHODIMP
156 nsJARURI::GetDisplayHostPort(nsACString& aUnicodeHostPort) {
157 return GetHostPort(aUnicodeHostPort);
160 NS_IMETHODIMP
161 nsJARURI::GetDisplayPrePath(nsACString& aPrePath) {
162 return GetPrePath(aPrePath);
165 NS_IMETHODIMP
166 nsJARURI::GetDisplayHost(nsACString& aUnicodeHost) {
167 return GetHost(aUnicodeHost);
170 NS_IMETHODIMP
171 nsJARURI::GetHasRef(bool* result) { return mJAREntry->GetHasRef(result); }
173 NS_IMETHODIMP
174 nsJARURI::GetHasUserPass(bool* result) {
175 return mJAREntry->GetHasUserPass(result);
178 NS_IMETHODIMP
179 nsJARURI::GetHasQuery(bool* result) { return mJAREntry->GetHasQuery(result); }
181 nsresult nsJARURI::SetSpecInternal(const nsACString& aSpec) {
182 return SetSpecWithBase(aSpec, nullptr);
185 // Queries this list of interfaces. If none match, it queries mURI.
186 NS_IMPL_NSIURIMUTATOR_ISUPPORTS(nsJARURI::Mutator, nsIURISetters, nsIURIMutator,
187 nsIURLMutator, nsISerializable,
188 nsIJARURIMutator)
190 NS_IMETHODIMP
191 nsJARURI::Mutator::SetFileName(const nsACString& aFileName,
192 nsIURIMutator** aMutator) {
193 if (!mURI) {
194 return NS_ERROR_NULL_POINTER;
196 if (aMutator) {
197 nsCOMPtr<nsIURIMutator> mutator = this;
198 mutator.forget(aMutator);
200 return mURI->SetFileNameInternal(aFileName);
203 NS_IMETHODIMP
204 nsJARURI::Mutator::SetFileBaseName(const nsACString& aFileBaseName,
205 nsIURIMutator** aMutator) {
206 if (!mURI) {
207 return NS_ERROR_NULL_POINTER;
209 if (aMutator) {
210 nsCOMPtr<nsIURIMutator> mutator = this;
211 mutator.forget(aMutator);
213 return mURI->SetFileBaseNameInternal(aFileBaseName);
216 NS_IMETHODIMP
217 nsJARURI::Mutator::SetFileExtension(const nsACString& aFileExtension,
218 nsIURIMutator** aMutator) {
219 if (!mURI) {
220 return NS_ERROR_NULL_POINTER;
222 if (aMutator) {
223 nsCOMPtr<nsIURIMutator> mutator = this;
224 mutator.forget(aMutator);
226 return mURI->SetFileExtensionInternal(aFileExtension);
229 NS_IMETHODIMP
230 nsJARURI::Mutate(nsIURIMutator** aMutator) {
231 RefPtr<nsJARURI::Mutator> mutator = new nsJARURI::Mutator();
232 nsresult rv = mutator->InitFromURI(this);
233 if (NS_FAILED(rv)) {
234 return rv;
236 mutator.forget(aMutator);
237 return NS_OK;
240 nsresult nsJARURI::SetSpecWithBase(const nsACString& aSpec, nsIURI* aBaseURL) {
241 nsresult rv;
243 nsCOMPtr<nsIIOService> ioServ(do_GetIOService(&rv));
244 NS_ENSURE_SUCCESS(rv, rv);
246 nsAutoCString scheme;
247 rv = ioServ->ExtractScheme(aSpec, scheme);
248 if (NS_FAILED(rv)) {
249 // not an absolute URI
250 if (!aBaseURL) return NS_ERROR_MALFORMED_URI;
252 RefPtr<nsJARURI> otherJAR = do_QueryObject(aBaseURL);
253 NS_ENSURE_TRUE(otherJAR, NS_NOINTERFACE);
255 mJARFile = otherJAR->mJARFile;
257 nsCOMPtr<nsIURI> entry;
259 rv = NS_MutateURI(NS_STANDARDURLMUTATOR_CONTRACTID)
260 .Apply(&nsIStandardURLMutator::Init,
261 nsIStandardURL::URLTYPE_NO_AUTHORITY, -1, aSpec,
262 mCharsetHint.get(), otherJAR->mJAREntry, nullptr)
263 .Finalize(entry);
264 if (NS_FAILED(rv)) {
265 return rv;
268 mJAREntry = do_QueryInterface(entry);
269 if (!mJAREntry) return NS_NOINTERFACE;
271 return NS_OK;
274 NS_ENSURE_TRUE(scheme.EqualsLiteral("jar"), NS_ERROR_MALFORMED_URI);
276 nsACString::const_iterator begin, end;
277 aSpec.BeginReading(begin);
278 aSpec.EndReading(end);
280 while (begin != end && *begin != ':') ++begin;
282 ++begin; // now we're past the "jar:"
284 nsACString::const_iterator delim_begin = begin;
285 nsACString::const_iterator delim_end = end;
286 nsACString::const_iterator frag = begin;
288 if (FindInReadable(NS_JAR_DELIMITER, delim_begin, delim_end)) {
289 frag = delim_end;
291 while (frag != end && (*frag != '#' && *frag != '?')) {
292 ++frag;
294 if (frag != end) {
295 // there was a fragment or query, mark that as the end of the URL to scan
296 end = frag;
299 // Search backward from the end for the "!/" delimiter. Remember, jar URLs
300 // can nest, e.g.:
301 // jar:jar:http://www.foo.com/bar.jar!/a.jar!/b.html
302 // This gets the b.html document from out of the a.jar file, that's
303 // contained within the bar.jar file.
304 // Also, the outermost "inner" URI may be a relative URI:
305 // jar:../relative.jar!/a.html
307 delim_begin = begin;
308 delim_end = end;
310 if (!RFindInReadable(NS_JAR_DELIMITER, delim_begin, delim_end)) {
311 return NS_ERROR_MALFORMED_URI;
314 rv = ioServ->NewURI(Substring(begin, delim_begin), mCharsetHint.get(),
315 aBaseURL, getter_AddRefs(mJARFile));
316 if (NS_FAILED(rv)) return rv;
318 // skip over any extra '/' chars
319 while (*delim_end == '/') ++delim_end;
321 aSpec.EndReading(end); // set to the original 'end'
322 return SetJAREntry(Substring(delim_end, end));
325 NS_IMETHODIMP
326 nsJARURI::GetPrePath(nsACString& prePath) {
327 prePath = NS_JAR_SCHEME;
328 return NS_OK;
331 NS_IMETHODIMP
332 nsJARURI::GetScheme(nsACString& aScheme) {
333 aScheme = "jar";
334 return NS_OK;
337 nsresult nsJARURI::SetScheme(const nsACString& aScheme) {
338 // doesn't make sense to set the scheme of a jar: URL
339 return NS_ERROR_FAILURE;
342 NS_IMETHODIMP
343 nsJARURI::GetUserPass(nsACString& aUserPass) { return NS_ERROR_FAILURE; }
345 nsresult nsJARURI::SetUserPass(const nsACString& aUserPass) {
346 return NS_ERROR_FAILURE;
349 NS_IMETHODIMP
350 nsJARURI::GetUsername(nsACString& aUsername) { return NS_ERROR_FAILURE; }
352 nsresult nsJARURI::SetUsername(const nsACString& aUsername) {
353 return NS_ERROR_FAILURE;
356 NS_IMETHODIMP
357 nsJARURI::GetPassword(nsACString& aPassword) { return NS_ERROR_FAILURE; }
359 nsresult nsJARURI::SetPassword(const nsACString& aPassword) {
360 return NS_ERROR_FAILURE;
363 NS_IMETHODIMP
364 nsJARURI::GetHostPort(nsACString& aHostPort) { return NS_ERROR_FAILURE; }
366 nsresult nsJARURI::SetHostPort(const nsACString& aHostPort) {
367 return NS_ERROR_FAILURE;
370 NS_IMETHODIMP
371 nsJARURI::GetHost(nsACString& aHost) { return NS_ERROR_FAILURE; }
373 nsresult nsJARURI::SetHost(const nsACString& aHost) { return NS_ERROR_FAILURE; }
375 NS_IMETHODIMP
376 nsJARURI::GetPort(int32_t* aPort) { return NS_ERROR_FAILURE; }
378 nsresult nsJARURI::SetPort(int32_t aPort) { return NS_ERROR_FAILURE; }
380 nsresult nsJARURI::GetPathQueryRef(nsACString& aPath) {
381 nsAutoCString entrySpec;
382 mJAREntry->GetSpec(entrySpec);
383 return FormatSpec(entrySpec, aPath, false);
386 nsresult nsJARURI::SetPathQueryRef(const nsACString& aPath) {
387 return NS_ERROR_FAILURE;
390 NS_IMETHODIMP
391 nsJARURI::GetAsciiSpec(nsACString& aSpec) {
392 // XXX Shouldn't this like... make sure it returns ASCII or something?
393 return GetSpec(aSpec);
396 NS_IMETHODIMP
397 nsJARURI::GetAsciiHostPort(nsACString& aHostPort) { return NS_ERROR_FAILURE; }
399 NS_IMETHODIMP
400 nsJARURI::GetAsciiHost(nsACString& aHost) { return NS_ERROR_FAILURE; }
402 NS_IMETHODIMP
403 nsJARURI::Equals(nsIURI* other, bool* result) {
404 return EqualsInternal(other, eHonorRef, result);
407 NS_IMETHODIMP
408 nsJARURI::EqualsExceptRef(nsIURI* other, bool* result) {
409 return EqualsInternal(other, eIgnoreRef, result);
412 // Helper method:
413 /* virtual */
414 nsresult nsJARURI::EqualsInternal(nsIURI* other,
415 nsJARURI::RefHandlingEnum refHandlingMode,
416 bool* result) {
417 *result = false;
419 if (!other) return NS_OK; // not equal
421 RefPtr<nsJARURI> otherJAR = do_QueryObject(other);
422 if (!otherJAR) return NS_OK; // not equal
424 bool equal;
425 nsresult rv = mJARFile->Equals(otherJAR->mJARFile, &equal);
426 if (NS_FAILED(rv) || !equal) {
427 return rv; // not equal
430 return refHandlingMode == eHonorRef
431 ? mJAREntry->Equals(otherJAR->mJAREntry, result)
432 : mJAREntry->EqualsExceptRef(otherJAR->mJAREntry, result);
435 NS_IMETHODIMP
436 nsJARURI::SchemeIs(const char* i_Scheme, bool* o_Equals) {
437 MOZ_ASSERT(o_Equals);
438 if (!i_Scheme) {
439 *o_Equals = false;
440 return NS_OK;
443 *o_Equals = nsCRT::strcasecmp("jar", i_Scheme) == 0;
444 return NS_OK;
447 nsresult nsJARURI::Clone(nsIURI** result) {
448 RefPtr<nsJARURI> uri = new nsJARURI();
449 uri->mJARFile = mJARFile;
450 uri->mJAREntry = mJAREntry;
451 uri.forget(result);
453 return NS_OK;
456 NS_IMETHODIMP
457 nsJARURI::Resolve(const nsACString& relativePath, nsACString& result) {
458 nsresult rv;
460 nsCOMPtr<nsIIOService> ioServ(do_GetIOService(&rv));
461 if (NS_FAILED(rv)) return rv;
463 nsAutoCString scheme;
464 rv = ioServ->ExtractScheme(relativePath, scheme);
465 if (NS_SUCCEEDED(rv)) {
466 // then aSpec is absolute
467 result = relativePath;
468 return NS_OK;
471 nsAutoCString resolvedPath;
472 mJAREntry->Resolve(relativePath, resolvedPath);
474 return FormatSpec(resolvedPath, result);
477 ////////////////////////////////////////////////////////////////////////////////
478 // nsIURL methods:
480 NS_IMETHODIMP
481 nsJARURI::GetFilePath(nsACString& filePath) {
482 return mJAREntry->GetFilePath(filePath);
485 nsresult nsJARURI::SetFilePath(const nsACString& filePath) {
486 return NS_MutateURI(mJAREntry).SetFilePath(filePath).Finalize(mJAREntry);
489 NS_IMETHODIMP
490 nsJARURI::GetQuery(nsACString& query) { return mJAREntry->GetQuery(query); }
492 nsresult nsJARURI::SetQuery(const nsACString& query) {
493 return NS_MutateURI(mJAREntry).SetQuery(query).Finalize(mJAREntry);
496 nsresult nsJARURI::SetQueryWithEncoding(const nsACString& query,
497 const mozilla::Encoding* encoding) {
498 return NS_MutateURI(mJAREntry)
499 .SetQueryWithEncoding(query, encoding)
500 .Finalize(mJAREntry);
503 NS_IMETHODIMP
504 nsJARURI::GetRef(nsACString& ref) { return mJAREntry->GetRef(ref); }
506 nsresult nsJARURI::SetRef(const nsACString& ref) {
507 return NS_MutateURI(mJAREntry).SetRef(ref).Finalize(mJAREntry);
510 NS_IMETHODIMP
511 nsJARURI::GetDirectory(nsACString& directory) {
512 return mJAREntry->GetDirectory(directory);
515 NS_IMETHODIMP
516 nsJARURI::GetFileName(nsACString& fileName) {
517 return mJAREntry->GetFileName(fileName);
520 nsresult nsJARURI::SetFileNameInternal(const nsACString& fileName) {
521 return NS_MutateURI(mJAREntry)
522 .Apply(&nsIURLMutator::SetFileName, fileName, nullptr)
523 .Finalize(mJAREntry);
526 NS_IMETHODIMP
527 nsJARURI::GetFileBaseName(nsACString& fileBaseName) {
528 return mJAREntry->GetFileBaseName(fileBaseName);
531 nsresult nsJARURI::SetFileBaseNameInternal(const nsACString& fileBaseName) {
532 return NS_MutateURI(mJAREntry)
533 .Apply(&nsIURLMutator::SetFileBaseName, fileBaseName, nullptr)
534 .Finalize(mJAREntry);
537 NS_IMETHODIMP
538 nsJARURI::GetFileExtension(nsACString& fileExtension) {
539 return mJAREntry->GetFileExtension(fileExtension);
542 nsresult nsJARURI::SetFileExtensionInternal(const nsACString& fileExtension) {
543 return NS_MutateURI(mJAREntry)
544 .Apply(&nsIURLMutator::SetFileExtension, fileExtension, nullptr)
545 .Finalize(mJAREntry);
548 NS_IMETHODIMP
549 nsJARURI::GetCommonBaseSpec(nsIURI* uriToCompare, nsACString& commonSpec) {
550 commonSpec.Truncate();
552 NS_ENSURE_ARG_POINTER(uriToCompare);
554 commonSpec.Truncate();
555 nsCOMPtr<nsIJARURI> otherJARURI(do_QueryInterface(uriToCompare));
556 if (!otherJARURI) {
557 // Nothing in common
558 return NS_OK;
561 nsCOMPtr<nsIURI> otherJARFile;
562 nsresult rv = otherJARURI->GetJARFile(getter_AddRefs(otherJARFile));
563 if (NS_FAILED(rv)) return rv;
565 bool equal;
566 rv = mJARFile->Equals(otherJARFile, &equal);
567 if (NS_FAILED(rv)) return rv;
569 if (!equal) {
570 // See what the JAR file URIs have in common
571 nsCOMPtr<nsIURL> ourJARFileURL(do_QueryInterface(mJARFile));
572 if (!ourJARFileURL) {
573 // Not a URL, so nothing in common
574 return NS_OK;
576 nsAutoCString common;
577 rv = ourJARFileURL->GetCommonBaseSpec(otherJARFile, common);
578 if (NS_FAILED(rv)) return rv;
580 commonSpec = NS_JAR_SCHEME + common;
581 return NS_OK;
584 // At this point we have the same JAR file. Compare the JAREntrys
585 nsAutoCString otherEntry;
586 rv = otherJARURI->GetJAREntry(otherEntry);
587 if (NS_FAILED(rv)) return rv;
589 nsCOMPtr<nsIURL> url;
590 rv = CreateEntryURL(otherEntry, nullptr, getter_AddRefs(url));
591 if (NS_FAILED(rv)) return rv;
593 nsAutoCString common;
594 rv = mJAREntry->GetCommonBaseSpec(url, common);
595 if (NS_FAILED(rv)) return rv;
597 rv = FormatSpec(common, commonSpec);
598 return rv;
601 NS_IMETHODIMP
602 nsJARURI::GetRelativeSpec(nsIURI* uriToCompare, nsACString& relativeSpec) {
603 GetSpec(relativeSpec);
605 NS_ENSURE_ARG_POINTER(uriToCompare);
607 nsCOMPtr<nsIJARURI> otherJARURI(do_QueryInterface(uriToCompare));
608 if (!otherJARURI) {
609 // Nothing in common
610 return NS_OK;
613 nsCOMPtr<nsIURI> otherJARFile;
614 nsresult rv = otherJARURI->GetJARFile(getter_AddRefs(otherJARFile));
615 if (NS_FAILED(rv)) return rv;
617 bool equal;
618 rv = mJARFile->Equals(otherJARFile, &equal);
619 if (NS_FAILED(rv)) return rv;
621 if (!equal) {
622 // We live in different JAR files. Nothing in common.
623 return rv;
626 // Same JAR file. Compare the JAREntrys
627 nsAutoCString otherEntry;
628 rv = otherJARURI->GetJAREntry(otherEntry);
629 if (NS_FAILED(rv)) return rv;
631 nsCOMPtr<nsIURL> url;
632 rv = CreateEntryURL(otherEntry, nullptr, getter_AddRefs(url));
633 if (NS_FAILED(rv)) return rv;
635 nsAutoCString relativeEntrySpec;
636 rv = mJAREntry->GetRelativeSpec(url, relativeEntrySpec);
637 if (NS_FAILED(rv)) return rv;
639 if (!StringBeginsWith(relativeEntrySpec, NS_BOGUS_ENTRY_SCHEME)) {
640 // An actual relative spec!
641 relativeSpec = relativeEntrySpec;
643 return rv;
646 ////////////////////////////////////////////////////////////////////////////////
647 // nsIJARURI methods:
649 NS_IMETHODIMP
650 nsJARURI::GetJARFile(nsIURI** jarFile) { return GetInnerURI(jarFile); }
652 NS_IMETHODIMP
653 nsJARURI::GetJAREntry(nsACString& entryPath) {
654 nsAutoCString filePath;
655 mJAREntry->GetFilePath(filePath);
656 NS_ASSERTION(filePath.Length() > 0, "path should never be empty!");
657 // Trim off the leading '/'
658 entryPath = Substring(filePath, 1, filePath.Length() - 1);
659 return NS_OK;
662 nsresult nsJARURI::SetJAREntry(const nsACString& entryPath) {
663 return CreateEntryURL(entryPath, mCharsetHint.get(),
664 getter_AddRefs(mJAREntry));
667 ////////////////////////////////////////////////////////////////////////////////
669 NS_IMETHODIMP
670 nsJARURI::GetInnerURI(nsIURI** aURI) {
671 nsCOMPtr<nsIURI> uri = mJARFile;
672 uri.forget(aURI);
673 return NS_OK;
676 NS_IMETHODIMP
677 nsJARURI::GetInnermostURI(nsIURI** uri) {
678 return NS_ImplGetInnermostURI(this, uri);
681 void nsJARURI::Serialize(URIParams& aParams) {
682 JARURIParams params;
684 SerializeURI(mJARFile, params.jarFile());
685 SerializeURI(mJAREntry, params.jarEntry());
686 params.charset() = mCharsetHint;
688 aParams = params;
691 bool nsJARURI::Deserialize(const URIParams& aParams) {
692 if (aParams.type() != URIParams::TJARURIParams) {
693 NS_ERROR("Received unknown parameters from the other process!");
694 return false;
697 const JARURIParams& params = aParams.get_JARURIParams();
699 nsCOMPtr<nsIURI> file = DeserializeURI(params.jarFile());
700 if (!file) {
701 NS_ERROR("Couldn't deserialize jar file URI!");
702 return false;
705 nsCOMPtr<nsIURI> entry = DeserializeURI(params.jarEntry());
706 if (!entry) {
707 NS_ERROR("Couldn't deserialize jar entry URI!");
708 return false;
711 nsCOMPtr<nsIURL> entryURL = do_QueryInterface(entry);
712 if (!entryURL) {
713 NS_ERROR("Couldn't QI jar entry URI to nsIURL!");
714 return false;
717 mJARFile.swap(file);
718 mJAREntry.swap(entryURL);
719 mCharsetHint = params.charset();
721 return true;