SubstitutingJARURI.h (8654B)
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 file, 5 * You can obtain one at http://mozilla.org/MPL/2.0/. */ 6 7 #ifndef SubstitutingJARURI_h 8 #define SubstitutingJARURI_h 9 10 #include "nsIStandardURL.h" 11 #include "nsIURL.h" 12 #include "nsJARURI.h" 13 #include "nsISerializable.h" 14 15 namespace mozilla { 16 namespace net { 17 18 #define NS_SUBSTITUTINGJARURI_IMPL_CID \ 19 {/* 8f8c54ed-aba7-4ebf-ba6f-e58aec0aba4c */ \ 20 0x8f8c54ed, \ 21 0xaba7, \ 22 0x4ebf, \ 23 {0xba, 0x6f, 0xe5, 0x8a, 0xec, 0x0a, 0xba, 0x4c}} 24 25 // Provides a Substituting URI for resource://-like substitutions which 26 // allows consumers to access the underlying jar resource. 27 class SubstitutingJARURI : public nsIJARURI, 28 public nsIStandardURL, 29 public nsISerializable { 30 protected: 31 // Contains the resource://-like URI to be mapped. nsIURI and nsIURL will 32 // forward to this. 33 nsCOMPtr<nsIURL> mSource; 34 // Contains the resolved jar resource, nsIJARURI forwards to this to let 35 // consumer acccess the underlying jar resource. 36 nsCOMPtr<nsIJARURI> mResolved; 37 virtual ~SubstitutingJARURI() = default; 38 39 public: 40 SubstitutingJARURI(nsIURL* source, nsIJARURI* resolved); 41 // For deserializing 42 explicit SubstitutingJARURI() = default; 43 44 NS_DECL_THREADSAFE_ISUPPORTS 45 NS_DECL_NSISERIALIZABLE 46 47 NS_INLINE_DECL_STATIC_IID(NS_SUBSTITUTINGJARURI_IMPL_CID) 48 49 NS_FORWARD_SAFE_NSIURL(mSource) 50 NS_FORWARD_SAFE_NSIJARURI(mResolved) 51 52 // enum used in a few places to specify how .ref attribute should be handled 53 enum RefHandlingEnum { eIgnoreRef, eHonorRef }; 54 55 // We cannot forward Equals* methods to |mSource| so we override them here 56 NS_IMETHOD EqualsExceptRef(nsIURI* aOther, bool* aResult) override; 57 NS_IMETHOD Equals(nsIURI* aOther, bool* aResult) override; 58 59 // Helper to share code between Equals methods. 60 virtual nsresult EqualsInternal(nsIURI* aOther, 61 RefHandlingEnum aRefHandlingMode, 62 bool* aResult); 63 64 // Forward the rest of nsIURI to mSource 65 NS_IMETHOD GetSpec(nsACString& aSpec) override { 66 return !mSource ? NS_ERROR_NULL_POINTER : mSource->GetSpec(aSpec); 67 } 68 NS_IMETHOD GetPrePath(nsACString& aPrePath) override { 69 return !mSource ? NS_ERROR_NULL_POINTER : mSource->GetPrePath(aPrePath); 70 } 71 NS_IMETHOD GetScheme(nsACString& aScheme) override { 72 return !mSource ? NS_ERROR_NULL_POINTER : mSource->GetScheme(aScheme); 73 } 74 NS_IMETHOD GetUserPass(nsACString& aUserPass) override { 75 return !mSource ? NS_ERROR_NULL_POINTER : mSource->GetUserPass(aUserPass); 76 } 77 NS_IMETHOD GetUsername(nsACString& aUsername) override { 78 return !mSource ? NS_ERROR_NULL_POINTER : mSource->GetUsername(aUsername); 79 } 80 NS_IMETHOD GetPassword(nsACString& aPassword) override { 81 return !mSource ? NS_ERROR_NULL_POINTER : mSource->GetPassword(aPassword); 82 } 83 NS_IMETHOD GetHostPort(nsACString& aHostPort) override { 84 return !mSource ? NS_ERROR_NULL_POINTER : mSource->GetHostPort(aHostPort); 85 } 86 NS_IMETHOD GetHost(nsACString& aHost) override { 87 return !mSource ? NS_ERROR_NULL_POINTER : mSource->GetHost(aHost); 88 } 89 NS_IMETHOD GetPort(int32_t* aPort) override { 90 return !mSource ? NS_ERROR_NULL_POINTER : mSource->GetPort(aPort); 91 } 92 NS_IMETHOD GetPathQueryRef(nsACString& aPathQueryRef) override { 93 return !mSource ? NS_ERROR_NULL_POINTER 94 : mSource->GetPathQueryRef(aPathQueryRef); 95 } 96 NS_IMETHOD SchemeIs(const char* scheme, bool* _retval) override { 97 return !mSource ? NS_ERROR_NULL_POINTER 98 : mSource->SchemeIs(scheme, _retval); 99 } 100 NS_IMETHOD Resolve(const nsACString& relativePath, 101 nsACString& _retval) override { 102 return !mSource ? NS_ERROR_NULL_POINTER 103 : mSource->Resolve(relativePath, _retval); 104 } 105 NS_IMETHOD GetAsciiSpec(nsACString& aAsciiSpec) override { 106 return !mSource ? NS_ERROR_NULL_POINTER : mSource->GetAsciiSpec(aAsciiSpec); 107 } 108 NS_IMETHOD GetAsciiHostPort(nsACString& aAsciiHostPort) override { 109 return !mSource ? NS_ERROR_NULL_POINTER 110 : mSource->GetAsciiHostPort(aAsciiHostPort); 111 } 112 NS_IMETHOD GetAsciiHost(nsACString& aAsciiHost) override { 113 return !mSource ? NS_ERROR_NULL_POINTER : mSource->GetAsciiHost(aAsciiHost); 114 } 115 NS_IMETHOD GetRef(nsACString& aRef) override { 116 return !mSource ? NS_ERROR_NULL_POINTER : mSource->GetRef(aRef); 117 } 118 NS_IMETHOD GetSpecIgnoringRef(nsACString& aSpecIgnoringRef) override { 119 return !mSource ? NS_ERROR_NULL_POINTER 120 : mSource->GetSpecIgnoringRef(aSpecIgnoringRef); 121 } 122 NS_IMETHOD GetHasRef(bool* aHasRef) override { 123 return !mSource ? NS_ERROR_NULL_POINTER : mSource->GetHasRef(aHasRef); 124 } 125 NS_IMETHOD GetHasUserPass(bool* aHasUserPass) override { 126 return !mSource ? NS_ERROR_NULL_POINTER 127 : mSource->GetHasUserPass(aHasUserPass); 128 } 129 NS_IMETHOD GetHasQuery(bool* aHasQuery) override { 130 return !mSource ? NS_ERROR_NULL_POINTER : mSource->GetHasQuery(aHasQuery); 131 } 132 NS_IMETHOD GetFilePath(nsACString& aFilePath) override { 133 return !mSource ? NS_ERROR_NULL_POINTER : mSource->GetFilePath(aFilePath); 134 } 135 NS_IMETHOD GetQuery(nsACString& aQuery) override { 136 return !mSource ? NS_ERROR_NULL_POINTER : mSource->GetQuery(aQuery); 137 } 138 NS_IMETHOD GetDisplayHost(nsACString& aDisplayHost) override { 139 return !mSource ? NS_ERROR_NULL_POINTER 140 : mSource->GetDisplayHost(aDisplayHost); 141 } 142 NS_IMETHOD GetDisplayHostPort(nsACString& aDisplayHostPort) override { 143 return !mSource ? NS_ERROR_NULL_POINTER 144 : mSource->GetDisplayHostPort(aDisplayHostPort); 145 } 146 NS_IMETHOD GetDisplaySpec(nsACString& aDisplaySpec) override { 147 return !mSource ? NS_ERROR_NULL_POINTER 148 : mSource->GetDisplaySpec(aDisplaySpec); 149 } 150 NS_IMETHOD GetDisplayPrePath(nsACString& aDisplayPrePath) override { 151 return !mSource ? NS_ERROR_NULL_POINTER 152 : mSource->GetDisplayPrePath(aDisplayPrePath); 153 } 154 NS_IMETHOD Mutate(nsIURIMutator** _retval) override; 155 NS_IMETHOD_(void) Serialize(mozilla::ipc::URIParams& aParams) override; 156 virtual size_t SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) override; 157 158 private: 159 nsresult Clone(nsIURI** aURI); 160 nsresult SetSpecInternal(const nsACString& input) { 161 return NS_ERROR_NOT_IMPLEMENTED; 162 } 163 nsresult SetScheme(const nsACString& input) { 164 return NS_ERROR_NOT_IMPLEMENTED; 165 } 166 nsresult SetUserPass(const nsACString& aInput); 167 nsresult SetUsername(const nsACString& input) { 168 return NS_ERROR_NOT_IMPLEMENTED; 169 } 170 nsresult SetPassword(const nsACString& input) { 171 return NS_ERROR_NOT_IMPLEMENTED; 172 } 173 nsresult SetHostPort(const nsACString& aValue) { 174 return NS_ERROR_NOT_IMPLEMENTED; 175 } 176 nsresult SetHost(const nsACString& input) { return NS_ERROR_NOT_IMPLEMENTED; } 177 nsresult SetPort(int32_t aPort); 178 nsresult SetPathQueryRef(const nsACString& input) { 179 return NS_ERROR_NOT_IMPLEMENTED; 180 } 181 nsresult SetRef(const nsACString& input) { return NS_ERROR_NOT_IMPLEMENTED; } 182 nsresult SetFilePath(const nsACString& input) { 183 return NS_ERROR_NOT_IMPLEMENTED; 184 } 185 nsresult SetQuery(const nsACString& input) { 186 return NS_ERROR_NOT_IMPLEMENTED; 187 } 188 nsresult SetQueryWithEncoding(const nsACString& input, 189 const mozilla::Encoding* encoding) { 190 return NS_ERROR_NOT_IMPLEMENTED; 191 } 192 bool Deserialize(const mozilla::ipc::URIParams& aParams); 193 nsresult ReadPrivate(nsIObjectInputStream* aStream); 194 195 public: 196 class Mutator final : public nsIURIMutator, 197 public BaseURIMutator<SubstitutingJARURI>, 198 public nsISerializable { 199 NS_DECL_ISUPPORTS 200 NS_FORWARD_SAFE_NSIURISETTERS_RET(mURI) 201 NS_DEFINE_NSIMUTATOR_COMMON 202 203 // nsISerializable overrides 204 NS_IMETHOD 205 Write(nsIObjectOutputStream* aOutputStream) override { 206 return NS_ERROR_NOT_IMPLEMENTED; 207 } 208 209 NS_IMETHOD Read(nsIObjectInputStream* aStream) override { 210 return InitFromInputStream(aStream); 211 } 212 213 explicit Mutator() = default; 214 215 private: 216 virtual ~Mutator() = default; 217 218 friend SubstitutingJARURI; 219 }; 220 221 friend BaseURIMutator<SubstitutingJARURI>; 222 }; 223 224 } // namespace net 225 } // namespace mozilla 226 227 #endif /* SubstitutingJARURI_h */