URLSearchParams.h (3317B)
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 <cstdint> 11 12 #include "ErrorList.h" 13 #include "js/RootingAPI.h" 14 #include "mozilla/AlreadyAddRefed.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" 23 24 class JSObject; 25 class nsIGlobalObject; 26 class nsIInputStream; 27 struct JSContext; 28 struct JSStructuredCloneReader; 29 struct JSStructuredCloneWriter; 30 31 namespace mozilla { 32 33 class ErrorResult; 34 class URLParams; 35 36 namespace dom { 37 38 class GlobalObject; 39 class URLSearchParams; 40 class UTF8StringSequenceSequenceOrUTF8StringUTF8StringRecordOrUTF8String; 41 template <typename T> 42 class Optional; 43 44 class URLSearchParamsObserver : public nsISupports { 45 public: 46 virtual ~URLSearchParamsObserver() = default; 47 48 virtual void URLSearchParamsUpdated(URLSearchParams* aFromThis) = 0; 49 }; 50 51 class URLSearchParams final : public nsISupports, public nsWrapperCache { 52 ~URLSearchParams(); 53 54 public: 55 NS_DECL_CYCLE_COLLECTING_ISUPPORTS 56 NS_DECL_CYCLE_COLLECTION_WRAPPERCACHE_CLASS(URLSearchParams) 57 58 explicit URLSearchParams(nsISupports* aParent, 59 URLSearchParamsObserver* aObserver = nullptr); 60 61 // WebIDL methods 62 nsISupports* GetParentObject() const { return mParent; } 63 64 virtual JSObject* WrapObject(JSContext* aCx, 65 JS::Handle<JSObject*> aGivenProto) override; 66 67 static already_AddRefed<URLSearchParams> Constructor( 68 const GlobalObject& aGlobal, 69 const UTF8StringSequenceSequenceOrUTF8StringUTF8StringRecordOrUTF8String& 70 aInit, 71 ErrorResult& aRv); 72 73 void ParseInput(const nsACString& aInput); 74 75 void Serialize(nsACString& aValue) const; 76 77 uint32_t Size() const; 78 79 void Get(const nsACString& aName, nsACString& aRetval); 80 81 void GetAll(const nsACString& aName, nsTArray<nsCString>& aRetval); 82 83 void Set(const nsACString& aName, const nsACString& aValue); 84 85 void Append(const nsACString& aName, const nsACString& aValue); 86 87 bool Has(const nsACString& aName, const Optional<nsACString>& aValue); 88 89 void Delete(const nsACString& aName, const Optional<nsACString>& aValue); 90 91 uint32_t GetIterableLength() const; 92 const nsACString& GetKeyAtIndex(uint32_t aIndex) const; 93 const nsACString& GetValueAtIndex(uint32_t aIndex) const; 94 95 void Sort(ErrorResult& aRv); 96 97 void Stringify(nsAString&) const; 98 99 nsresult GetSendInfo(nsIInputStream** aBody, uint64_t* aContentLength, 100 nsACString& aContentTypeWithCharset, 101 nsACString& aCharset) const; 102 103 private: 104 void AppendInternal(const nsACString& aName, const nsACString& aValue); 105 106 void DeleteAll(); 107 108 void NotifyObserver(); 109 110 UniquePtr<URLParams> mParams; 111 nsCOMPtr<nsISupports> mParent; 112 RefPtr<URLSearchParamsObserver> mObserver; 113 }; 114 115 } // namespace dom 116 } // namespace mozilla 117 118 #endif /* mozilla_dom_URLSearchParams_h */