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/. */
10 #include "nsIJARURI.h"
11 #include "nsISerializable.h"
14 #include "nsINestedURI.h"
15 #include "nsIURIMutator.h"
17 #define NS_THIS_JARURI_IMPL_CID \
18 { /* 9a55f629-730b-4d08-b75b-fa7d9570a691 */ \
19 0x9a55f629, 0x730b, 0x4d08, { \
20 0xb7, 0x5b, 0xfa, 0x7d, 0x95, 0x70, 0xa6, 0x91 \
24 #define NS_JARURI_CID \
25 { /* 245abae2-b947-4ded-a46d-9829d3cca462 */ \
26 0x245abae2, 0xb947, 0x4ded, { \
27 0xa4, 0x6d, 0x98, 0x29, 0xd3, 0xcc, 0xa4, 0x62 \
31 #define NS_JARURIMUTATOR_CID \
32 { /* 19d9161b-a2a9-4518-b2c9-fcb8296d6dcd */ \
33 0x19d9161b, 0xa2a9, 0x4518, { \
34 0xb2, 0xc9, 0xfc, 0xb8, 0x29, 0x6d, 0x6d, 0xcd \
38 class nsJARURI final
: public nsIJARURI
,
39 public nsISerializable
,
42 NS_DECL_THREADSAFE_ISUPPORTS
46 NS_DECL_NSISERIALIZABLE
49 NS_DECLARE_STATIC_IID_ACCESSOR(NS_THIS_JARURI_IMPL_CID
)
52 nsresult
FormatSpec(const nsACString
& entryPath
, nsACString
& result
,
53 bool aIncludeScheme
= true);
54 nsresult
CreateEntryURL(const nsACString
& entryFilename
, const char* charset
,
60 nsresult
SetJAREntry(const nsACString
& entryPath
);
61 nsresult
Init(const char* charsetHint
);
62 nsresult
SetSpecWithBase(const nsACString
& aSpec
, nsIURI
* aBaseURL
);
64 // enum used in a few places to specify how .ref attribute should be handled
65 enum RefHandlingEnum
{ eIgnoreRef
, eHonorRef
, eReplaceRef
};
67 // Helper to share code between Equals methods.
68 virtual nsresult
EqualsInternal(nsIURI
* other
,
69 RefHandlingEnum refHandlingMode
,
72 nsCOMPtr
<nsIURI
> mJARFile
;
73 // mJarEntry stored as a URL so that we can easily access things
74 // like extensions, refs, etc.
75 nsCOMPtr
<nsIURL
> mJAREntry
;
76 nsCString mCharsetHint
;
79 nsresult
Clone(nsIURI
** aURI
);
80 nsresult
SetSpecInternal(const nsACString
& input
);
81 nsresult
SetScheme(const nsACString
& input
);
82 nsresult
SetUserPass(const nsACString
& input
);
83 nsresult
SetUsername(const nsACString
& input
);
84 nsresult
SetPassword(const nsACString
& input
);
85 nsresult
SetHostPort(const nsACString
& aValue
);
86 nsresult
SetHost(const nsACString
& input
);
87 nsresult
SetPort(int32_t port
);
88 nsresult
SetPathQueryRef(const nsACString
& input
);
89 nsresult
SetRef(const nsACString
& input
);
90 nsresult
SetFilePath(const nsACString
& input
);
91 nsresult
SetQuery(const nsACString
& input
);
92 nsresult
SetQueryWithEncoding(const nsACString
& input
,
93 const mozilla::Encoding
* encoding
);
94 bool Deserialize(const mozilla::ipc::URIParams
&);
95 nsresult
ReadPrivate(nsIObjectInputStream
* aStream
);
97 nsresult
SetFileNameInternal(const nsACString
& fileName
);
98 nsresult
SetFileBaseNameInternal(const nsACString
& fileBaseName
);
99 nsresult
SetFileExtensionInternal(const nsACString
& fileExtension
);
102 class Mutator final
: public nsIURIMutator
,
103 public BaseURIMutator
<nsJARURI
>,
104 public nsIURLMutator
,
105 public nsISerializable
,
106 public nsIJARURIMutator
{
108 NS_FORWARD_SAFE_NSIURISETTERS_RET(mURI
)
109 NS_DEFINE_NSIMUTATOR_COMMON
110 NS_DECL_NSIURLMUTATOR
113 Write(nsIObjectOutputStream
* aOutputStream
) override
{
114 return NS_ERROR_NOT_IMPLEMENTED
;
117 [[nodiscard
]] NS_IMETHOD
Read(nsIObjectInputStream
* aStream
) override
{
118 return InitFromInputStream(aStream
);
122 SetSpecBaseCharset(const nsACString
& aSpec
, nsIURI
* aBaseURI
,
123 const char* aCharset
) override
{
124 RefPtr
<nsJARURI
> uri
;
128 uri
= new nsJARURI();
131 nsresult rv
= uri
->Init(aCharset
);
132 NS_ENSURE_SUCCESS(rv
, rv
);
134 rv
= uri
->SetSpecWithBase(aSpec
, aBaseURI
);
143 explicit Mutator() {}
146 virtual ~Mutator() {}
148 friend class nsJARURI
;
151 friend BaseURIMutator
<nsJARURI
>;
154 NS_DEFINE_STATIC_IID_ACCESSOR(nsJARURI
, NS_THIS_JARURI_IMPL_CID
)
156 #endif // nsJARURI_h__