/work/obj-fuzz/dist/include/mozilla/dom/URLSearchParams.h
Line | Count | Source (jump to first uncovered line) |
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 |
5 | | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
6 | | |
7 | | #ifndef mozilla_dom_URLSearchParams_h |
8 | | #define mozilla_dom_URLSearchParams_h |
9 | | |
10 | | #include "js/StructuredClone.h" |
11 | | #include "mozilla/dom/BindingDeclarations.h" |
12 | | #include "mozilla/ErrorResult.h" |
13 | | #include "nsCycleCollectionParticipant.h" |
14 | | #include "nsWrapperCache.h" |
15 | | #include "nsISupports.h" |
16 | | #include "nsIInputStream.h" |
17 | | |
18 | | namespace mozilla { |
19 | | namespace dom { |
20 | | |
21 | | class URLSearchParams; |
22 | | class USVStringSequenceSequenceOrUSVStringUSVStringRecordOrUSVString; |
23 | | |
24 | | class URLSearchParamsObserver : public nsISupports |
25 | | { |
26 | | public: |
27 | | virtual ~URLSearchParamsObserver() {} |
28 | | |
29 | | virtual void URLSearchParamsUpdated(URLSearchParams* aFromThis) = 0; |
30 | | }; |
31 | | |
32 | | // This class is used in BasePrincipal and it's _extremely_ important that the |
33 | | // attributes are kept in the correct order. If this changes, please, update |
34 | | // BasePrincipal code. |
35 | | |
36 | | class URLParams final |
37 | | { |
38 | | public: |
39 | 5.78k | URLParams() {} |
40 | | |
41 | | ~URLParams() |
42 | 5.78k | { |
43 | 5.78k | DeleteAll(); |
44 | 5.78k | } |
45 | | |
46 | | class ForEachIterator |
47 | | { |
48 | | public: |
49 | | virtual bool |
50 | | URLParamsIterator(const nsAString& aName, const nsAString& aValue) = 0; |
51 | | }; |
52 | | |
53 | | static bool |
54 | | Parse(const nsACString& aInput, ForEachIterator& aIterator); |
55 | | |
56 | | static bool |
57 | | Extract(const nsACString& aInput, const nsAString& aName, nsAString& aValue); |
58 | | |
59 | | void |
60 | | ParseInput(const nsACString& aInput); |
61 | | |
62 | | void Serialize(nsAString& aValue) const; |
63 | | |
64 | | void Get(const nsAString& aName, nsString& aRetval); |
65 | | |
66 | | void GetAll(const nsAString& aName, nsTArray<nsString>& aRetval); |
67 | | |
68 | | void Set(const nsAString& aName, const nsAString& aValue); |
69 | | |
70 | | void Append(const nsAString& aName, const nsAString& aValue); |
71 | | |
72 | | bool Has(const nsAString& aName); |
73 | | |
74 | | void Delete(const nsAString& aName); |
75 | | |
76 | | void DeleteAll() |
77 | 5.78k | { |
78 | 5.78k | mParams.Clear(); |
79 | 5.78k | } |
80 | | |
81 | | uint32_t Length() const |
82 | | { |
83 | | return mParams.Length(); |
84 | | } |
85 | | |
86 | | const nsAString& GetKeyAtIndex(uint32_t aIndex) const |
87 | | { |
88 | | MOZ_ASSERT(aIndex < mParams.Length()); |
89 | | return mParams[aIndex].mKey; |
90 | | } |
91 | | |
92 | | const nsAString& GetValueAtIndex(uint32_t aIndex) const |
93 | | { |
94 | | MOZ_ASSERT(aIndex < mParams.Length()); |
95 | | return mParams[aIndex].mValue; |
96 | | } |
97 | | |
98 | | nsresult Sort(); |
99 | | |
100 | | bool |
101 | | ReadStructuredClone(JSStructuredCloneReader* aReader); |
102 | | |
103 | | bool |
104 | | WriteStructuredClone(JSStructuredCloneWriter* aWriter) const; |
105 | | |
106 | | private: |
107 | | static void DecodeString(const nsACString& aInput, nsAString& aOutput); |
108 | | static void ConvertString(const nsACString& aInput, nsAString& aOutput); |
109 | | |
110 | | struct Param |
111 | | { |
112 | | nsString mKey; |
113 | | nsString mValue; |
114 | | }; |
115 | | |
116 | | nsTArray<Param> mParams; |
117 | | }; |
118 | | |
119 | | class URLSearchParams final : public nsISupports, |
120 | | public nsWrapperCache |
121 | | { |
122 | | ~URLSearchParams(); |
123 | | |
124 | | public: |
125 | | NS_DECL_CYCLE_COLLECTING_ISUPPORTS |
126 | | NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(URLSearchParams) |
127 | | |
128 | | explicit URLSearchParams(nsISupports* aParent, |
129 | | URLSearchParamsObserver* aObserver=nullptr); |
130 | | |
131 | | // WebIDL methods |
132 | | nsISupports* GetParentObject() const |
133 | 0 | { |
134 | 0 | return mParent; |
135 | 0 | } |
136 | | |
137 | | virtual JSObject* |
138 | | WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override; |
139 | | |
140 | | static already_AddRefed<URLSearchParams> |
141 | | Constructor(const GlobalObject& aGlobal, |
142 | | const USVStringSequenceSequenceOrUSVStringUSVStringRecordOrUSVString& aInit, |
143 | | ErrorResult& aRv); |
144 | | |
145 | | void ParseInput(const nsACString& aInput); |
146 | | |
147 | | void Serialize(nsAString& aValue) const; |
148 | | |
149 | | void Get(const nsAString& aName, nsString& aRetval); |
150 | | |
151 | | void GetAll(const nsAString& aName, nsTArray<nsString>& aRetval); |
152 | | |
153 | | void Set(const nsAString& aName, const nsAString& aValue); |
154 | | |
155 | | void Append(const nsAString& aName, const nsAString& aValue); |
156 | | |
157 | | bool Has(const nsAString& aName); |
158 | | |
159 | | void Delete(const nsAString& aName); |
160 | | |
161 | | uint32_t GetIterableLength() const; |
162 | | const nsAString& GetKeyAtIndex(uint32_t aIndex) const; |
163 | | const nsAString& GetValueAtIndex(uint32_t aIndex) const; |
164 | | |
165 | | void Sort(ErrorResult& aRv); |
166 | | |
167 | | void Stringify(nsString& aRetval) const |
168 | 0 | { |
169 | 0 | Serialize(aRetval); |
170 | 0 | } |
171 | | |
172 | | bool |
173 | | ReadStructuredClone(JSStructuredCloneReader* aReader); |
174 | | |
175 | | bool |
176 | | WriteStructuredClone(JSStructuredCloneWriter* aWriter) const; |
177 | | |
178 | | nsresult |
179 | | GetSendInfo(nsIInputStream** aBody, uint64_t* aContentLength, |
180 | | nsACString& aContentTypeWithCharset, |
181 | | nsACString& aCharset) const; |
182 | | |
183 | | private: |
184 | | void AppendInternal(const nsAString& aName, const nsAString& aValue); |
185 | | |
186 | | void DeleteAll(); |
187 | | |
188 | | void NotifyObserver(); |
189 | | |
190 | | UniquePtr<URLParams> mParams; |
191 | | nsCOMPtr<nsISupports> mParent; |
192 | | RefPtr<URLSearchParamsObserver> mObserver; |
193 | | }; |
194 | | |
195 | | } // namespace dom |
196 | | } // namespace mozilla |
197 | | |
198 | | #endif /* mozilla_dom_URLSearchParams_h */ |