|
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/. */ |
|
5 |
|
6 #ifndef mozilla_dom_URLSearchParams_h |
|
7 #define mozilla_dom_URLSearchParams_h |
|
8 |
|
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 |
|
17 namespace mozilla { |
|
18 namespace dom { |
|
19 |
|
20 class URLSearchParamsObserver : public nsISupports |
|
21 { |
|
22 public: |
|
23 virtual ~URLSearchParamsObserver() {} |
|
24 |
|
25 virtual void URLSearchParamsUpdated() = 0; |
|
26 }; |
|
27 |
|
28 class URLSearchParams MOZ_FINAL : public nsISupports, |
|
29 public nsWrapperCache |
|
30 { |
|
31 public: |
|
32 NS_DECL_CYCLE_COLLECTING_ISUPPORTS |
|
33 NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(URLSearchParams) |
|
34 |
|
35 URLSearchParams(); |
|
36 ~URLSearchParams(); |
|
37 |
|
38 // WebIDL methods |
|
39 nsISupports* GetParentObject() const |
|
40 { |
|
41 return nullptr; |
|
42 } |
|
43 |
|
44 virtual JSObject* |
|
45 WrapObject(JSContext* aCx) MOZ_OVERRIDE; |
|
46 |
|
47 static already_AddRefed<URLSearchParams> |
|
48 Constructor(const GlobalObject& aGlobal, const nsAString& aInit, |
|
49 ErrorResult& aRv); |
|
50 |
|
51 static already_AddRefed<URLSearchParams> |
|
52 Constructor(const GlobalObject& aGlobal, URLSearchParams& aInit, |
|
53 ErrorResult& aRv); |
|
54 |
|
55 void ParseInput(const nsACString& aInput, |
|
56 URLSearchParamsObserver* aObserver); |
|
57 |
|
58 void AddObserver(URLSearchParamsObserver* aObserver); |
|
59 void RemoveObserver(URLSearchParamsObserver* aObserver); |
|
60 |
|
61 void Serialize(nsAString& aValue) const; |
|
62 |
|
63 void Get(const nsAString& aName, nsString& aRetval); |
|
64 |
|
65 void GetAll(const nsAString& aName, nsTArray<nsString >& aRetval); |
|
66 |
|
67 void Set(const nsAString& aName, const nsAString& aValue); |
|
68 |
|
69 void Append(const nsAString& aName, const nsAString& aValue); |
|
70 |
|
71 bool Has(const nsAString& aName); |
|
72 |
|
73 void Delete(const nsAString& aName); |
|
74 |
|
75 void Stringify(nsString& aRetval) |
|
76 { |
|
77 Serialize(aRetval); |
|
78 } |
|
79 |
|
80 private: |
|
81 void AppendInternal(const nsAString& aName, const nsAString& aValue); |
|
82 |
|
83 void DeleteAll(); |
|
84 |
|
85 void DecodeString(const nsACString& aInput, nsACString& aOutput); |
|
86 |
|
87 void NotifyObservers(URLSearchParamsObserver* aExceptObserver); |
|
88 |
|
89 static PLDHashOperator |
|
90 CopyEnumerator(const nsAString& aName, nsTArray<nsString>* aArray, |
|
91 void *userData); |
|
92 |
|
93 static PLDHashOperator |
|
94 SerializeEnumerator(const nsAString& aName, nsTArray<nsString>* aArray, |
|
95 void *userData); |
|
96 |
|
97 nsClassHashtable<nsStringHashKey, nsTArray<nsString>> mSearchParams; |
|
98 |
|
99 nsTArray<nsRefPtr<URLSearchParamsObserver>> mObservers; |
|
100 }; |
|
101 |
|
102 } // namespace dom |
|
103 } // namespace mozilla |
|
104 |
|
105 #endif /* mozilla_dom_URLSearchParams_h */ |