Bug 1845134 - Part 4: Update existing ui-icons to use the latest source from acorn...
[gecko.git] / netwerk / base / nsSimpleURI.h
blob560dd560409f3373321afe19a7bb59fc96cb5e19
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #ifndef nsSimpleURI_h__
7 #define nsSimpleURI_h__
9 #include "mozilla/MemoryReporting.h"
10 #include "nsIURI.h"
11 #include "nsISerializable.h"
12 #include "nsString.h"
13 #include "nsIClassInfo.h"
14 #include "nsISizeOf.h"
15 #include "nsIURIMutator.h"
16 #include "nsISimpleURIMutator.h"
18 namespace mozilla {
19 namespace net {
21 #define NS_THIS_SIMPLEURI_IMPLEMENTATION_CID \
22 { /* 0b9bb0c2-fee6-470b-b9b9-9fd9462b5e19 */ \
23 0x0b9bb0c2, 0xfee6, 0x470b, { \
24 0xb9, 0xb9, 0x9f, 0xd9, 0x46, 0x2b, 0x5e, 0x19 \
25 } \
28 class nsSimpleURI : public nsIURI, public nsISerializable, public nsISizeOf {
29 protected:
30 nsSimpleURI() = default;
31 virtual ~nsSimpleURI() = default;
33 public:
34 NS_DECL_THREADSAFE_ISUPPORTS
35 NS_DECL_NSIURI
36 NS_DECL_NSISERIALIZABLE
38 static already_AddRefed<nsSimpleURI> From(nsIURI* aURI);
40 // nsSimpleURI methods:
42 bool Equals(nsSimpleURI* aOther) { return EqualsInternal(aOther, eHonorRef); }
44 // nsISizeOf
45 // Among the sub-classes that inherit (directly or indirectly) from
46 // nsSimpleURI, measurement of the following members may be added later if
47 // DMD finds it is worthwhile:
48 // - nsJSURI: mBaseURI
49 // - nsSimpleNestedURI: mInnerURI
50 // - nsBlobURI: mPrincipal
51 virtual size_t SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const override;
52 virtual size_t SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const override;
54 protected:
55 // enum used in a few places to specify how .ref attribute should be handled
56 enum RefHandlingEnum { eIgnoreRef, eHonorRef, eReplaceRef };
58 virtual nsresult Clone(nsIURI** result);
59 virtual nsresult SetSpecInternal(const nsACString& aSpec,
60 bool aStripWhitespace = false);
61 virtual nsresult SetScheme(const nsACString& input);
62 virtual nsresult SetUserPass(const nsACString& input);
63 nsresult SetUsername(const nsACString& input);
64 virtual nsresult SetPassword(const nsACString& input);
65 virtual nsresult SetHostPort(const nsACString& aValue);
66 virtual nsresult SetHost(const nsACString& input);
67 virtual nsresult SetPort(int32_t port);
68 virtual nsresult SetPathQueryRef(const nsACString& aPath);
69 virtual nsresult SetRef(const nsACString& aRef);
70 virtual nsresult SetFilePath(const nsACString& aFilePath);
71 virtual nsresult SetQuery(const nsACString& aQuery);
72 virtual nsresult SetQueryWithEncoding(const nsACString& aQuery,
73 const Encoding* encoding);
74 nsresult ReadPrivate(nsIObjectInputStream* stream);
76 // Helper to share code between Equals methods.
77 virtual nsresult EqualsInternal(nsIURI* other,
78 RefHandlingEnum refHandlingMode,
79 bool* result);
81 // Helper to be used by inherited classes who want to test
82 // equality given an assumed nsSimpleURI. This must NOT check
83 // the passed-in other for QI to our CID.
84 bool EqualsInternal(nsSimpleURI* otherUri, RefHandlingEnum refHandlingMode);
86 // Used by StartClone (and versions of StartClone in subclasses) to
87 // handle the ref in the right way for clones.
88 void SetRefOnClone(nsSimpleURI* url, RefHandlingEnum refHandlingMode,
89 const nsACString& newRef);
91 // NOTE: This takes the refHandlingMode as an argument because
92 // nsSimpleNestedURI's specialized version needs to know how to clone
93 // its inner URI.
94 virtual nsSimpleURI* StartClone(RefHandlingEnum refHandlingMode,
95 const nsACString& newRef);
97 // Helper to share code between Clone methods.
98 virtual nsresult CloneInternal(RefHandlingEnum refHandlingMode,
99 const nsACString& newRef, nsIURI** result);
101 void TrimTrailingCharactersFromPath();
102 nsresult EscapeAndSetPathQueryRef(const nsACString& aPath);
103 nsresult SetPathQueryRefInternal(const nsACString& aPath);
105 bool Deserialize(const mozilla::ipc::URIParams&);
107 nsCString mScheme;
108 nsCString mPath; // NOTE: mPath does not include ref, as an optimization
109 nsCString mRef; // so that URIs with different refs can share string data.
110 nsCString
111 mQuery; // so that URLs with different querys can share string data.
112 bool mIsRefValid{false}; // To distinguish between empty-ref and no-ref.
113 // To distinguish between empty-query and no-query.
114 bool mIsQueryValid{false};
116 public:
117 class Mutator final : public nsIURIMutator,
118 public BaseURIMutator<nsSimpleURI>,
119 public nsISimpleURIMutator,
120 public nsISerializable {
121 NS_DECL_ISUPPORTS
122 NS_FORWARD_SAFE_NSIURISETTERS_RET(mURI)
123 NS_DEFINE_NSIMUTATOR_COMMON
125 NS_IMETHOD
126 Write(nsIObjectOutputStream* aOutputStream) override {
127 return NS_ERROR_NOT_IMPLEMENTED;
130 [[nodiscard]] NS_IMETHOD Read(nsIObjectInputStream* aStream) override {
131 return InitFromInputStream(aStream);
134 [[nodiscard]] NS_IMETHOD SetSpecAndFilterWhitespace(
135 const nsACString& aSpec, nsIURIMutator** aMutator) override {
136 if (aMutator) {
137 *aMutator = do_AddRef(this).take();
140 nsresult rv = NS_OK;
141 RefPtr<nsSimpleURI> uri = new nsSimpleURI();
142 rv = uri->SetSpecInternal(aSpec, /* filterWhitespace */ true);
143 if (NS_FAILED(rv)) {
144 return rv;
146 mURI = std::move(uri);
147 return NS_OK;
150 explicit Mutator() = default;
152 private:
153 virtual ~Mutator() = default;
155 friend class nsSimpleURI;
158 friend BaseURIMutator<nsSimpleURI>;
161 } // namespace net
162 } // namespace mozilla
164 #endif // nsSimpleURI_h__