Bug 1825212 [wpt PR 39266] - [@scope] Propagate proximity from SubResult, a=testonly
[gecko.git] / dom / url / URLSearchParams.h
blobc534e2fa64807a38342f56185a51037bb58b7015
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;
42 class URLSearchParamsObserver : public nsISupports {
43 public:
44 virtual ~URLSearchParamsObserver() = default;
46 virtual void URLSearchParamsUpdated(URLSearchParams* aFromThis) = 0;
49 class URLSearchParams final : public nsISupports, public nsWrapperCache {
50 ~URLSearchParams();
52 public:
53 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
54 NS_DECL_CYCLE_COLLECTION_WRAPPERCACHE_CLASS(URLSearchParams)
56 explicit URLSearchParams(nsISupports* aParent,
57 URLSearchParamsObserver* aObserver = nullptr);
59 // WebIDL methods
60 nsISupports* GetParentObject() const { return mParent; }
62 virtual JSObject* WrapObject(JSContext* aCx,
63 JS::Handle<JSObject*> aGivenProto) override;
65 static already_AddRefed<URLSearchParams> Constructor(
66 const GlobalObject& aGlobal,
67 const USVStringSequenceSequenceOrUSVStringUSVStringRecordOrUSVString&
68 aInit,
69 ErrorResult& aRv);
71 void ParseInput(const nsACString& aInput);
73 void Serialize(nsAString& aValue) const;
75 uint32_t Size() const;
77 void Get(const nsAString& aName, nsString& aRetval);
79 void GetAll(const nsAString& aName, nsTArray<nsString>& aRetval);
81 void Set(const nsAString& aName, const nsAString& aValue);
83 void Append(const nsAString& aName, const nsAString& aValue);
85 bool Has(const nsAString& aName);
87 void Delete(const nsAString& aName);
89 uint32_t GetIterableLength() const;
90 const nsAString& GetKeyAtIndex(uint32_t aIndex) const;
91 const nsAString& GetValueAtIndex(uint32_t aIndex) const;
93 void Sort(ErrorResult& aRv);
95 void Stringify(nsString& aRetval) const { Serialize(aRetval); }
97 static already_AddRefed<URLSearchParams> ReadStructuredClone(
98 JSContext* aCx, nsIGlobalObject* aGlobal,
99 JSStructuredCloneReader* aReader);
101 bool WriteStructuredClone(JSContext* aCx,
102 JSStructuredCloneWriter* aWriter) const;
104 nsresult GetSendInfo(nsIInputStream** aBody, uint64_t* aContentLength,
105 nsACString& aContentTypeWithCharset,
106 nsACString& aCharset) const;
108 private:
109 bool ReadStructuredClone(JSStructuredCloneReader* aReader);
111 bool WriteStructuredClone(JSStructuredCloneWriter* aWriter) const;
113 void AppendInternal(const nsAString& aName, const nsAString& aValue);
115 void DeleteAll();
117 void NotifyObserver();
119 UniquePtr<URLParams> mParams;
120 nsCOMPtr<nsISupports> mParent;
121 RefPtr<URLSearchParamsObserver> mObserver;
124 } // namespace dom
125 } // namespace mozilla
127 #endif /* mozilla_dom_URLSearchParams_h */