/src/mozilla-central/modules/libjar/nsJARURI.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* -*- Mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- |
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/. */ |
6 | | |
7 | | #ifndef nsJARURI_h__ |
8 | | #define nsJARURI_h__ |
9 | | |
10 | | #include "nsIJARURI.h" |
11 | | #include "nsISerializable.h" |
12 | | #include "nsIClassInfo.h" |
13 | | #include "nsCOMPtr.h" |
14 | | #include "nsString.h" |
15 | | #include "nsINestedURI.h" |
16 | | #include "nsIIPCSerializableURI.h" |
17 | | #include "nsIURIMutator.h" |
18 | | |
19 | | #define NS_THIS_JARURI_IMPL_CID \ |
20 | | { /* 9a55f629-730b-4d08-b75b-fa7d9570a691 */ \ |
21 | | 0x9a55f629, \ |
22 | | 0x730b, \ |
23 | | 0x4d08, \ |
24 | | {0xb7, 0x5b, 0xfa, 0x7d, 0x95, 0x70, 0xa6, 0x91} \ |
25 | | } |
26 | | |
27 | | #define NS_JARURI_CID \ |
28 | | { /* 245abae2-b947-4ded-a46d-9829d3cca462 */ \ |
29 | | 0x245abae2, \ |
30 | | 0xb947, \ |
31 | | 0x4ded, \ |
32 | | {0xa4, 0x6d, 0x98, 0x29, 0xd3, 0xcc, 0xa4, 0x62} \ |
33 | | } |
34 | | |
35 | | #define NS_JARURIMUTATOR_CID \ |
36 | | { /* 19d9161b-a2a9-4518-b2c9-fcb8296d6dcd */ \ |
37 | | 0x19d9161b, \ |
38 | | 0xa2a9, \ |
39 | | 0x4518, \ |
40 | | {0xb2, 0xc9, 0xfc, 0xb8, 0x29, 0x6d, 0x6d, 0xcd} \ |
41 | | } |
42 | | |
43 | | class nsJARURI final : public nsIJARURI, |
44 | | public nsISerializable, |
45 | | public nsIClassInfo, |
46 | | public nsINestedURI, |
47 | | public nsIIPCSerializableURI |
48 | | { |
49 | | public: |
50 | | NS_DECL_THREADSAFE_ISUPPORTS |
51 | | NS_DECL_NSIURI |
52 | | NS_DECL_NSIURL |
53 | | NS_DECL_NSIJARURI |
54 | | NS_DECL_NSISERIALIZABLE |
55 | | NS_DECL_NSICLASSINFO |
56 | | NS_DECL_NSINESTEDURI |
57 | | NS_DECL_NSIIPCSERIALIZABLEURI |
58 | | |
59 | | NS_DECLARE_STATIC_IID_ACCESSOR(NS_THIS_JARURI_IMPL_CID) |
60 | | |
61 | | // nsJARURI |
62 | | nsresult FormatSpec(const nsACString &entryPath, nsACString &result, |
63 | | bool aIncludeScheme = true); |
64 | | nsresult CreateEntryURL(const nsACString& entryFilename, |
65 | | const char* charset, |
66 | | nsIURL** url); |
67 | | |
68 | | protected: |
69 | | nsJARURI(); |
70 | | virtual ~nsJARURI(); |
71 | | nsresult SetJAREntry(const nsACString &entryPath); |
72 | | nsresult Init(const char *charsetHint); |
73 | | nsresult SetSpecWithBase(const nsACString& aSpec, nsIURI* aBaseURL); |
74 | | |
75 | | // enum used in a few places to specify how .ref attribute should be handled |
76 | | enum RefHandlingEnum { |
77 | | eIgnoreRef, |
78 | | eHonorRef, |
79 | | eReplaceRef |
80 | | }; |
81 | | |
82 | | // Helper to share code between Equals methods. |
83 | | virtual nsresult EqualsInternal(nsIURI* other, |
84 | | RefHandlingEnum refHandlingMode, |
85 | | bool* result); |
86 | | |
87 | | // Helpers to share code between Clone methods. |
88 | | nsresult CloneWithJARFileInternal(nsIURI *jarFile, |
89 | | RefHandlingEnum refHandlingMode, |
90 | | nsIJARURI **result); |
91 | | nsresult CloneWithJARFileInternal(nsIURI *jarFile, |
92 | | RefHandlingEnum refHandlingMode, |
93 | | const nsACString& newRef, |
94 | | nsIJARURI **result); |
95 | | nsCOMPtr<nsIURI> mJARFile; |
96 | | // mJarEntry stored as a URL so that we can easily access things |
97 | | // like extensions, refs, etc. |
98 | | nsCOMPtr<nsIURL> mJAREntry; |
99 | | nsCString mCharsetHint; |
100 | | |
101 | | private: |
102 | | nsresult Clone(nsIURI** aURI); |
103 | | nsresult SetSpecInternal(const nsACString &input); |
104 | | nsresult SetScheme(const nsACString &input); |
105 | | nsresult SetUserPass(const nsACString &input); |
106 | | nsresult SetUsername(const nsACString &input); |
107 | | nsresult SetPassword(const nsACString &input); |
108 | | nsresult SetHostPort(const nsACString &aValue); |
109 | | nsresult SetHost(const nsACString &input); |
110 | | nsresult SetPort(int32_t port); |
111 | | nsresult SetPathQueryRef(const nsACString &input); |
112 | | nsresult SetRef(const nsACString &input); |
113 | | nsresult SetFilePath(const nsACString &input); |
114 | | nsresult SetQuery(const nsACString &input); |
115 | | nsresult SetQueryWithEncoding(const nsACString &input, const mozilla::Encoding* encoding); |
116 | | bool Deserialize(const mozilla::ipc::URIParams&); |
117 | | nsresult ReadPrivate(nsIObjectInputStream *aStream); |
118 | | |
119 | | nsresult SetFileNameInternal(const nsACString& fileName); |
120 | | nsresult SetFileBaseNameInternal(const nsACString& fileBaseName); |
121 | | nsresult SetFileExtensionInternal(const nsACString& fileExtension); |
122 | | |
123 | | public: |
124 | | class Mutator final |
125 | | : public nsIURIMutator |
126 | | , public BaseURIMutator<nsJARURI> |
127 | | , public nsIURLMutator |
128 | | , public nsISerializable |
129 | | , public nsIJARURIMutator |
130 | | { |
131 | | NS_DECL_ISUPPORTS |
132 | | NS_FORWARD_SAFE_NSIURISETTERS_RET(mURI) |
133 | | NS_DEFINE_NSIMUTATOR_COMMON |
134 | | NS_DECL_NSIURLMUTATOR |
135 | | |
136 | | NS_IMETHOD |
137 | | Write(nsIObjectOutputStream *aOutputStream) override |
138 | 0 | { |
139 | 0 | return NS_ERROR_NOT_IMPLEMENTED; |
140 | 0 | } |
141 | | |
142 | | MOZ_MUST_USE NS_IMETHOD |
143 | | Read(nsIObjectInputStream* aStream) override |
144 | 0 | { |
145 | 0 | return InitFromInputStream(aStream); |
146 | 0 | } |
147 | | |
148 | | NS_IMETHOD |
149 | | SetSpecBaseCharset(const nsACString& aSpec, |
150 | | nsIURI* aBaseURI, |
151 | | const char* aCharset) override |
152 | 5.35k | { |
153 | 5.35k | RefPtr<nsJARURI> uri; |
154 | 5.35k | if (mURI) { |
155 | 0 | mURI.swap(uri); |
156 | 5.35k | } else { |
157 | 5.35k | uri = new nsJARURI(); |
158 | 5.35k | } |
159 | 5.35k | |
160 | 5.35k | nsresult rv = uri->Init(aCharset); |
161 | 5.35k | NS_ENSURE_SUCCESS(rv, rv); |
162 | 5.35k | |
163 | 5.35k | rv = uri->SetSpecWithBase(aSpec, aBaseURI); |
164 | 5.35k | if (NS_FAILED(rv)) { |
165 | 3.04k | return rv; |
166 | 3.04k | } |
167 | 2.31k | |
168 | 2.31k | mURI.swap(uri); |
169 | 2.31k | return NS_OK; |
170 | 2.31k | } |
171 | | |
172 | 5.35k | explicit Mutator() { } |
173 | | private: |
174 | 5.35k | virtual ~Mutator() { } |
175 | | |
176 | | friend class nsJARURI; |
177 | | }; |
178 | | |
179 | | friend BaseURIMutator<nsJARURI>; |
180 | | }; |
181 | | |
182 | | NS_DEFINE_STATIC_IID_ACCESSOR(nsJARURI, NS_THIS_JARURI_IMPL_CID) |
183 | | |
184 | | #endif // nsJARURI_h__ |