michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef mozilla_dom_URLSearchParams_h michael@0: #define mozilla_dom_URLSearchParams_h michael@0: michael@0: #include "mozilla/dom/BindingDeclarations.h" michael@0: #include "mozilla/ErrorResult.h" michael@0: #include "nsCycleCollectionParticipant.h" michael@0: #include "nsWrapperCache.h" michael@0: #include "nsClassHashtable.h" michael@0: #include "nsHashKeys.h" michael@0: #include "nsISupports.h" michael@0: michael@0: namespace mozilla { michael@0: namespace dom { michael@0: michael@0: class URLSearchParamsObserver : public nsISupports michael@0: { michael@0: public: michael@0: virtual ~URLSearchParamsObserver() {} michael@0: michael@0: virtual void URLSearchParamsUpdated() = 0; michael@0: }; michael@0: michael@0: class URLSearchParams MOZ_FINAL : public nsISupports, michael@0: public nsWrapperCache michael@0: { michael@0: public: michael@0: NS_DECL_CYCLE_COLLECTING_ISUPPORTS michael@0: NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(URLSearchParams) michael@0: michael@0: URLSearchParams(); michael@0: ~URLSearchParams(); michael@0: michael@0: // WebIDL methods michael@0: nsISupports* GetParentObject() const michael@0: { michael@0: return nullptr; michael@0: } michael@0: michael@0: virtual JSObject* michael@0: WrapObject(JSContext* aCx) MOZ_OVERRIDE; michael@0: michael@0: static already_AddRefed michael@0: Constructor(const GlobalObject& aGlobal, const nsAString& aInit, michael@0: ErrorResult& aRv); michael@0: michael@0: static already_AddRefed michael@0: Constructor(const GlobalObject& aGlobal, URLSearchParams& aInit, michael@0: ErrorResult& aRv); michael@0: michael@0: void ParseInput(const nsACString& aInput, michael@0: URLSearchParamsObserver* aObserver); michael@0: michael@0: void AddObserver(URLSearchParamsObserver* aObserver); michael@0: void RemoveObserver(URLSearchParamsObserver* aObserver); michael@0: michael@0: void Serialize(nsAString& aValue) const; michael@0: michael@0: void Get(const nsAString& aName, nsString& aRetval); michael@0: michael@0: void GetAll(const nsAString& aName, nsTArray& aRetval); michael@0: michael@0: void Set(const nsAString& aName, const nsAString& aValue); michael@0: michael@0: void Append(const nsAString& aName, const nsAString& aValue); michael@0: michael@0: bool Has(const nsAString& aName); michael@0: michael@0: void Delete(const nsAString& aName); michael@0: michael@0: void Stringify(nsString& aRetval) michael@0: { michael@0: Serialize(aRetval); michael@0: } michael@0: michael@0: private: michael@0: void AppendInternal(const nsAString& aName, const nsAString& aValue); michael@0: michael@0: void DeleteAll(); michael@0: michael@0: void DecodeString(const nsACString& aInput, nsACString& aOutput); michael@0: michael@0: void NotifyObservers(URLSearchParamsObserver* aExceptObserver); michael@0: michael@0: static PLDHashOperator michael@0: CopyEnumerator(const nsAString& aName, nsTArray* aArray, michael@0: void *userData); michael@0: michael@0: static PLDHashOperator michael@0: SerializeEnumerator(const nsAString& aName, nsTArray* aArray, michael@0: void *userData); michael@0: michael@0: nsClassHashtable> mSearchParams; michael@0: michael@0: nsTArray> mObservers; michael@0: }; michael@0: michael@0: } // namespace dom michael@0: } // namespace mozilla michael@0: michael@0: #endif /* mozilla_dom_URLSearchParams_h */