1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/base/URLSearchParams.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,105 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +#ifndef mozilla_dom_URLSearchParams_h 1.10 +#define mozilla_dom_URLSearchParams_h 1.11 + 1.12 +#include "mozilla/dom/BindingDeclarations.h" 1.13 +#include "mozilla/ErrorResult.h" 1.14 +#include "nsCycleCollectionParticipant.h" 1.15 +#include "nsWrapperCache.h" 1.16 +#include "nsClassHashtable.h" 1.17 +#include "nsHashKeys.h" 1.18 +#include "nsISupports.h" 1.19 + 1.20 +namespace mozilla { 1.21 +namespace dom { 1.22 + 1.23 +class URLSearchParamsObserver : public nsISupports 1.24 +{ 1.25 +public: 1.26 + virtual ~URLSearchParamsObserver() {} 1.27 + 1.28 + virtual void URLSearchParamsUpdated() = 0; 1.29 +}; 1.30 + 1.31 +class URLSearchParams MOZ_FINAL : public nsISupports, 1.32 + public nsWrapperCache 1.33 +{ 1.34 +public: 1.35 + NS_DECL_CYCLE_COLLECTING_ISUPPORTS 1.36 + NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(URLSearchParams) 1.37 + 1.38 + URLSearchParams(); 1.39 + ~URLSearchParams(); 1.40 + 1.41 + // WebIDL methods 1.42 + nsISupports* GetParentObject() const 1.43 + { 1.44 + return nullptr; 1.45 + } 1.46 + 1.47 + virtual JSObject* 1.48 + WrapObject(JSContext* aCx) MOZ_OVERRIDE; 1.49 + 1.50 + static already_AddRefed<URLSearchParams> 1.51 + Constructor(const GlobalObject& aGlobal, const nsAString& aInit, 1.52 + ErrorResult& aRv); 1.53 + 1.54 + static already_AddRefed<URLSearchParams> 1.55 + Constructor(const GlobalObject& aGlobal, URLSearchParams& aInit, 1.56 + ErrorResult& aRv); 1.57 + 1.58 + void ParseInput(const nsACString& aInput, 1.59 + URLSearchParamsObserver* aObserver); 1.60 + 1.61 + void AddObserver(URLSearchParamsObserver* aObserver); 1.62 + void RemoveObserver(URLSearchParamsObserver* aObserver); 1.63 + 1.64 + void Serialize(nsAString& aValue) const; 1.65 + 1.66 + void Get(const nsAString& aName, nsString& aRetval); 1.67 + 1.68 + void GetAll(const nsAString& aName, nsTArray<nsString >& aRetval); 1.69 + 1.70 + void Set(const nsAString& aName, const nsAString& aValue); 1.71 + 1.72 + void Append(const nsAString& aName, const nsAString& aValue); 1.73 + 1.74 + bool Has(const nsAString& aName); 1.75 + 1.76 + void Delete(const nsAString& aName); 1.77 + 1.78 + void Stringify(nsString& aRetval) 1.79 + { 1.80 + Serialize(aRetval); 1.81 + } 1.82 + 1.83 +private: 1.84 + void AppendInternal(const nsAString& aName, const nsAString& aValue); 1.85 + 1.86 + void DeleteAll(); 1.87 + 1.88 + void DecodeString(const nsACString& aInput, nsACString& aOutput); 1.89 + 1.90 + void NotifyObservers(URLSearchParamsObserver* aExceptObserver); 1.91 + 1.92 + static PLDHashOperator 1.93 + CopyEnumerator(const nsAString& aName, nsTArray<nsString>* aArray, 1.94 + void *userData); 1.95 + 1.96 + static PLDHashOperator 1.97 + SerializeEnumerator(const nsAString& aName, nsTArray<nsString>* aArray, 1.98 + void *userData); 1.99 + 1.100 + nsClassHashtable<nsStringHashKey, nsTArray<nsString>> mSearchParams; 1.101 + 1.102 + nsTArray<nsRefPtr<URLSearchParamsObserver>> mObservers; 1.103 +}; 1.104 + 1.105 +} // namespace dom 1.106 +} // namespace mozilla 1.107 + 1.108 +#endif /* mozilla_dom_URLSearchParams_h */