Backed out 22 changesets (bug 1839396) for causing build bustages on js/Printer.h...
[gecko.git] / dom / url / URLSearchParams.h
blob4e8b09bc8c32131855e5848f0e6abda8cb76d856
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/. */
7 #ifndef mozilla_dom_URLSearchParams_h
8 #define mozilla_dom_URLSearchParams_h
10 #include <cstdint>
11 #include "ErrorList.h"
12 #include "js/RootingAPI.h"
13 #include "mozilla/AlreadyAddRefed.h"
14 #include "mozilla/Assertions.h"
15 #include "mozilla/RefPtr.h"
16 #include "mozilla/UniquePtr.h"
17 #include "nsCOMPtr.h"
18 #include "nsCycleCollectionParticipant.h"
19 #include "nsISupports.h"
20 #include "nsString.h"
21 #include "nsTArray.h"
22 #include "nsWrapperCache.h"
24 class JSObject;
25 class nsIGlobalObject;
26 class nsIInputStream;
27 struct JSContext;
28 struct JSStructuredCloneReader;
29 struct JSStructuredCloneWriter;
31 namespace mozilla {
33 class ErrorResult;
34 class URLParams;
36 namespace dom {
38 class GlobalObject;
39 class URLSearchParams;
40 class USVStringSequenceSequenceOrUSVStringUSVStringRecordOrUSVString;
41 template <typename T>
42 class Optional;
44 class URLSearchParamsObserver : public nsISupports {
45 public:
46 virtual ~URLSearchParamsObserver() = default;
48 virtual void URLSearchParamsUpdated(URLSearchParams* aFromThis) = 0;
51 class URLSearchParams final : public nsISupports, public nsWrapperCache {
52 ~URLSearchParams();
54 public:
55 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
56 NS_DECL_CYCLE_COLLECTION_WRAPPERCACHE_CLASS(URLSearchParams)
58 explicit URLSearchParams(nsISupports* aParent,
59 URLSearchParamsObserver* aObserver = nullptr);
61 // WebIDL methods
62 nsISupports* GetParentObject() const { return mParent; }
64 virtual JSObject* WrapObject(JSContext* aCx,
65 JS::Handle<JSObject*> aGivenProto) override;
67 static already_AddRefed<URLSearchParams> Constructor(
68 const GlobalObject& aGlobal,
69 const USVStringSequenceSequenceOrUSVStringUSVStringRecordOrUSVString&
70 aInit,
71 ErrorResult& aRv);
73 void ParseInput(const nsACString& aInput);
75 void Serialize(nsAString& aValue) const;
77 uint32_t Size() const;
79 void Get(const nsAString& aName, nsString& aRetval);
81 void GetAll(const nsAString& aName, nsTArray<nsString>& aRetval);
83 void Set(const nsAString& aName, const nsAString& aValue);
85 void Append(const nsAString& aName, const nsAString& aValue);
87 bool Has(const nsAString& aName, const Optional<nsAString>& aValue);
89 void Delete(const nsAString& aName, const Optional<nsAString>& aValue);
91 uint32_t GetIterableLength() const;
92 const nsAString& GetKeyAtIndex(uint32_t aIndex) const;
93 const nsAString& GetValueAtIndex(uint32_t aIndex) const;
95 void Sort(ErrorResult& aRv);
97 void Stringify(nsString& aRetval) const { Serialize(aRetval); }
99 static already_AddRefed<URLSearchParams> ReadStructuredClone(
100 JSContext* aCx, nsIGlobalObject* aGlobal,
101 JSStructuredCloneReader* aReader);
103 bool WriteStructuredClone(JSContext* aCx,
104 JSStructuredCloneWriter* aWriter) const;
106 nsresult GetSendInfo(nsIInputStream** aBody, uint64_t* aContentLength,
107 nsACString& aContentTypeWithCharset,
108 nsACString& aCharset) const;
110 private:
111 bool ReadStructuredClone(JSStructuredCloneReader* aReader);
113 bool WriteStructuredClone(JSStructuredCloneWriter* aWriter) const;
115 void AppendInternal(const nsAString& aName, const nsAString& aValue);
117 void DeleteAll();
119 void NotifyObserver();
121 UniquePtr<URLParams> mParams;
122 nsCOMPtr<nsISupports> mParent;
123 RefPtr<URLSearchParamsObserver> mObserver;
126 } // namespace dom
127 } // namespace mozilla
129 #endif /* mozilla_dom_URLSearchParams_h */