2014-07-28 23:28:20 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#ifndef mozilla_dom_Headers_h
|
|
|
|
#define mozilla_dom_Headers_h
|
|
|
|
|
|
|
|
#include "mozilla/dom/HeadersBinding.h"
|
2014-09-24 09:03:20 +04:00
|
|
|
|
2014-07-28 23:28:20 +04:00
|
|
|
#include "nsClassHashtable.h"
|
|
|
|
#include "nsWrapperCache.h"
|
|
|
|
|
2014-10-02 21:59:20 +04:00
|
|
|
#include "InternalHeaders.h"
|
|
|
|
|
2014-07-28 23:28:20 +04:00
|
|
|
namespace mozilla {
|
|
|
|
|
|
|
|
class ErrorResult;
|
|
|
|
|
|
|
|
namespace dom {
|
|
|
|
|
|
|
|
template<typename T> class MozMap;
|
|
|
|
class HeadersOrByteStringSequenceSequenceOrByteStringMozMap;
|
2014-10-01 22:43:26 +04:00
|
|
|
class OwningHeadersOrByteStringSequenceSequenceOrByteStringMozMap;
|
2014-07-28 23:28:20 +04:00
|
|
|
|
2014-10-02 21:59:20 +04:00
|
|
|
/**
|
|
|
|
* This Headers class is only used to represent the content facing Headers
|
|
|
|
* object. It is actually backed by an InternalHeaders implementation. Gecko
|
|
|
|
* code should NEVER use this, except in the Request and Response
|
|
|
|
* implementations, where they must always be created from the backing
|
|
|
|
* InternalHeaders object.
|
|
|
|
*/
|
2015-03-21 19:28:04 +03:00
|
|
|
class Headers final : public nsISupports
|
2015-03-27 21:52:19 +03:00
|
|
|
, public nsWrapperCache
|
2014-07-28 23:28:20 +04:00
|
|
|
{
|
|
|
|
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
|
|
|
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(Headers)
|
|
|
|
|
2014-10-02 21:59:20 +04:00
|
|
|
friend class Request;
|
|
|
|
friend class Response;
|
2014-07-28 23:28:20 +04:00
|
|
|
|
2014-10-02 21:59:20 +04:00
|
|
|
private:
|
2014-09-24 09:03:20 +04:00
|
|
|
nsCOMPtr<nsISupports> mOwner;
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<InternalHeaders> mInternalHeaders;
|
2014-07-28 23:28:20 +04:00
|
|
|
|
|
|
|
public:
|
2014-10-02 21:59:20 +04:00
|
|
|
explicit Headers(nsISupports* aOwner, InternalHeaders* aInternalHeaders)
|
2014-07-28 23:28:20 +04:00
|
|
|
: mOwner(aOwner)
|
2014-10-02 21:59:20 +04:00
|
|
|
, mInternalHeaders(aInternalHeaders)
|
2014-07-28 23:28:20 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2015-01-07 02:35:02 +03:00
|
|
|
explicit Headers(const Headers& aOther) = delete;
|
2014-09-24 09:03:20 +04:00
|
|
|
|
2014-07-30 01:24:22 +04:00
|
|
|
static bool PrefEnabled(JSContext* cx, JSObject* obj);
|
|
|
|
|
2014-07-28 23:28:20 +04:00
|
|
|
static already_AddRefed<Headers>
|
|
|
|
Constructor(const GlobalObject& aGlobal,
|
|
|
|
const Optional<HeadersOrByteStringSequenceSequenceOrByteStringMozMap>& aInit,
|
|
|
|
ErrorResult& aRv);
|
|
|
|
|
2014-09-24 09:03:20 +04:00
|
|
|
static already_AddRefed<Headers>
|
|
|
|
Constructor(const GlobalObject& aGlobal,
|
|
|
|
const OwningHeadersOrByteStringSequenceSequenceOrByteStringMozMap& aInit,
|
|
|
|
ErrorResult& aRv);
|
|
|
|
|
2015-03-19 21:41:42 +03:00
|
|
|
static already_AddRefed<Headers>
|
|
|
|
Create(nsIGlobalObject* aGlobalObject,
|
|
|
|
const OwningHeadersOrByteStringSequenceSequenceOrByteStringMozMap& aInit,
|
|
|
|
ErrorResult& aRv);
|
|
|
|
|
2014-07-28 23:28:20 +04:00
|
|
|
void Append(const nsACString& aName, const nsACString& aValue,
|
2014-10-02 21:59:20 +04:00
|
|
|
ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
mInternalHeaders->Append(aName, aValue, aRv);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Delete(const nsACString& aName, ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
mInternalHeaders->Delete(aName, aRv);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Get(const nsACString& aName, nsCString& aValue, ErrorResult& aRv) const
|
|
|
|
{
|
|
|
|
mInternalHeaders->Get(aName, aValue, aRv);
|
|
|
|
}
|
|
|
|
|
2014-07-28 23:28:20 +04:00
|
|
|
void GetAll(const nsACString& aName, nsTArray<nsCString>& aResults,
|
2014-10-02 21:59:20 +04:00
|
|
|
ErrorResult& aRv) const
|
|
|
|
{
|
|
|
|
mInternalHeaders->GetAll(aName, aResults, aRv);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Has(const nsACString& aName, ErrorResult& aRv) const
|
|
|
|
{
|
|
|
|
return mInternalHeaders->Has(aName, aRv);
|
|
|
|
}
|
2014-07-28 23:28:20 +04:00
|
|
|
|
2014-10-02 21:59:20 +04:00
|
|
|
void Set(const nsACString& aName, const nsACString& aValue, ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
mInternalHeaders->Set(aName, aValue, aRv);
|
|
|
|
}
|
2014-09-24 09:03:20 +04:00
|
|
|
|
2015-10-19 20:58:03 +03:00
|
|
|
uint32_t GetIterableLength() const
|
|
|
|
{
|
|
|
|
return mInternalHeaders->GetIterableLength();
|
|
|
|
}
|
|
|
|
const nsString GetKeyAtIndex(unsigned aIndex) const
|
|
|
|
{
|
|
|
|
return mInternalHeaders->GetKeyAtIndex(aIndex);
|
|
|
|
}
|
|
|
|
const nsString GetValueAtIndex(unsigned aIndex) const
|
|
|
|
{
|
|
|
|
return mInternalHeaders->GetValueAtIndex(aIndex);
|
|
|
|
}
|
|
|
|
|
2014-07-28 23:28:20 +04:00
|
|
|
// ChromeOnly
|
2014-10-02 21:59:20 +04:00
|
|
|
HeadersGuardEnum Guard() const
|
|
|
|
{
|
|
|
|
return mInternalHeaders->Guard();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetGuard(HeadersGuardEnum aGuard, ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
mInternalHeaders->SetGuard(aGuard, aRv);
|
|
|
|
}
|
2014-07-28 23:28:20 +04:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
|
2014-07-28 23:28:20 +04:00
|
|
|
nsISupports* GetParentObject() const { return mOwner; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
virtual ~Headers();
|
|
|
|
|
2014-10-02 21:59:20 +04:00
|
|
|
InternalHeaders*
|
|
|
|
GetInternalHeaders() const
|
2014-07-28 23:28:20 +04:00
|
|
|
{
|
2014-10-02 21:59:20 +04:00
|
|
|
return mInternalHeaders;
|
2014-07-28 23:28:20 +04:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // mozilla_dom_Headers_h
|