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 mozilla_dom_URLSearchParams_h
7 #define mozilla_dom_URLSearchParams_h
9 #include "mozilla/dom/BindingDeclarations.h"
10 #include "mozilla/ErrorResult.h"
11 #include "nsCycleCollectionParticipant.h"
12 #include "nsWrapperCache.h"
13 #include "nsClassHashtable.h"
14 #include "nsHashKeys.h"
15 #include "nsISupports.h"
16 #include "nsIUnicodeDecoder.h"
21 class URLSearchParams
;
23 class URLSearchParamsObserver
: public nsISupports
26 virtual ~URLSearchParamsObserver() {}
28 virtual void URLSearchParamsUpdated(URLSearchParams
* aFromThis
) = 0;
31 class URLSearchParams MOZ_FINAL
: public nsISupports
,
37 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
38 NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(URLSearchParams
)
43 nsISupports
* GetParentObject() const
49 WrapObject(JSContext
* aCx
) MOZ_OVERRIDE
;
51 static already_AddRefed
<URLSearchParams
>
52 Constructor(const GlobalObject
& aGlobal
, const nsAString
& aInit
,
55 static already_AddRefed
<URLSearchParams
>
56 Constructor(const GlobalObject
& aGlobal
, URLSearchParams
& aInit
,
59 void ParseInput(const nsACString
& aInput
,
60 URLSearchParamsObserver
* aObserver
);
62 void AddObserver(URLSearchParamsObserver
* aObserver
);
63 void RemoveObserver(URLSearchParamsObserver
* aObserver
);
64 void RemoveObservers();
66 void Serialize(nsAString
& aValue
) const;
68 void Get(const nsAString
& aName
, nsString
& aRetval
);
70 void GetAll(const nsAString
& aName
, nsTArray
<nsString
>& aRetval
);
72 void Set(const nsAString
& aName
, const nsAString
& aValue
);
74 void Append(const nsAString
& aName
, const nsAString
& aValue
);
76 bool Has(const nsAString
& aName
);
78 void Delete(const nsAString
& aName
);
80 void Stringify(nsString
& aRetval
)
86 void AppendInternal(const nsAString
& aName
, const nsAString
& aValue
);
90 void DecodeString(const nsACString
& aInput
, nsAString
& aOutput
);
91 void ConvertString(const nsACString
& aInput
, nsAString
& aOutput
);
93 void NotifyObservers(URLSearchParamsObserver
* aExceptObserver
);
95 static PLDHashOperator
96 CopyEnumerator(const nsAString
& aName
, nsTArray
<nsString
>* aArray
,
99 static PLDHashOperator
100 SerializeEnumerator(const nsAString
& aName
, nsTArray
<nsString
>* aArray
,
103 nsClassHashtable
<nsStringHashKey
, nsTArray
<nsString
>> mSearchParams
;
105 nsTArray
<nsRefPtr
<URLSearchParamsObserver
>> mObservers
;
106 nsCOMPtr
<nsIUnicodeDecoder
> mDecoder
;
110 } // namespace mozilla
112 #endif /* mozilla_dom_URLSearchParams_h */