/work/obj-fuzz/dist/include/mozilla/dom/Headers.h
Line | Count | Source (jump to first uncovered line) |
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_Headers_h |
8 | | #define mozilla_dom_Headers_h |
9 | | |
10 | | #include "mozilla/dom/HeadersBinding.h" |
11 | | |
12 | | #include "nsClassHashtable.h" |
13 | | #include "nsWrapperCache.h" |
14 | | |
15 | | #include "InternalHeaders.h" |
16 | | |
17 | | namespace mozilla { |
18 | | |
19 | | class ErrorResult; |
20 | | |
21 | | namespace dom { |
22 | | |
23 | | template<typename K, typename V> class Record; |
24 | | class HeadersOrByteStringSequenceSequenceOrByteStringByteStringRecord; |
25 | | class OwningHeadersOrByteStringSequenceSequenceOrByteStringByteStringRecord; |
26 | | |
27 | | /** |
28 | | * This Headers class is only used to represent the content facing Headers |
29 | | * object. It is actually backed by an InternalHeaders implementation. Gecko |
30 | | * code should NEVER use this, except in the Request and Response |
31 | | * implementations, where they must always be created from the backing |
32 | | * InternalHeaders object. |
33 | | */ |
34 | | class Headers final : public nsISupports |
35 | | , public nsWrapperCache |
36 | | { |
37 | | NS_DECL_CYCLE_COLLECTING_ISUPPORTS |
38 | | NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(Headers) |
39 | | |
40 | | friend class Request; |
41 | | friend class Response; |
42 | | |
43 | | private: |
44 | | nsCOMPtr<nsISupports> mOwner; |
45 | | RefPtr<InternalHeaders> mInternalHeaders; |
46 | | |
47 | | public: |
48 | | explicit Headers(nsISupports* aOwner, InternalHeaders* aInternalHeaders) |
49 | | : mOwner(aOwner) |
50 | | , mInternalHeaders(aInternalHeaders) |
51 | 0 | { |
52 | 0 | } |
53 | | |
54 | | explicit Headers(const Headers& aOther) = delete; |
55 | | |
56 | | static bool PrefEnabled(JSContext* cx, JSObject* obj); |
57 | | |
58 | | static already_AddRefed<Headers> |
59 | | Constructor(const GlobalObject& aGlobal, |
60 | | const Optional<HeadersOrByteStringSequenceSequenceOrByteStringByteStringRecord>& aInit, |
61 | | ErrorResult& aRv); |
62 | | |
63 | | static already_AddRefed<Headers> |
64 | | Constructor(const GlobalObject& aGlobal, |
65 | | const OwningHeadersOrByteStringSequenceSequenceOrByteStringByteStringRecord& aInit, |
66 | | ErrorResult& aRv); |
67 | | |
68 | | static already_AddRefed<Headers> |
69 | | Create(nsIGlobalObject* aGlobalObject, |
70 | | const OwningHeadersOrByteStringSequenceSequenceOrByteStringByteStringRecord& aInit, |
71 | | ErrorResult& aRv); |
72 | | |
73 | | void Append(const nsACString& aName, const nsACString& aValue, |
74 | | ErrorResult& aRv) |
75 | 0 | { |
76 | 0 | mInternalHeaders->Append(aName, aValue, aRv); |
77 | 0 | } |
78 | | |
79 | | void Delete(const nsACString& aName, ErrorResult& aRv) |
80 | 0 | { |
81 | 0 | mInternalHeaders->Delete(aName, aRv); |
82 | 0 | } |
83 | | |
84 | | void Get(const nsACString& aName, nsACString& aValue, ErrorResult& aRv) const |
85 | 0 | { |
86 | 0 | mInternalHeaders->Get(aName, aValue, aRv); |
87 | 0 | } |
88 | | |
89 | | void GetFirst(const nsACString& aName, nsACString& aValue, ErrorResult& aRv) const |
90 | 0 | { |
91 | 0 | mInternalHeaders->GetFirst(aName, aValue, aRv); |
92 | 0 | } |
93 | | |
94 | | bool Has(const nsACString& aName, ErrorResult& aRv) const |
95 | 0 | { |
96 | 0 | return mInternalHeaders->Has(aName, aRv); |
97 | 0 | } |
98 | | |
99 | | void Set(const nsACString& aName, const nsACString& aValue, ErrorResult& aRv) |
100 | 0 | { |
101 | 0 | mInternalHeaders->Set(aName, aValue, aRv); |
102 | 0 | } |
103 | | |
104 | | uint32_t GetIterableLength() const |
105 | 0 | { |
106 | 0 | return mInternalHeaders->GetIterableLength(); |
107 | 0 | } |
108 | | const nsString GetKeyAtIndex(unsigned aIndex) const |
109 | 0 | { |
110 | 0 | return mInternalHeaders->GetKeyAtIndex(aIndex); |
111 | 0 | } |
112 | | const nsString GetValueAtIndex(unsigned aIndex) const |
113 | 0 | { |
114 | 0 | return mInternalHeaders->GetValueAtIndex(aIndex); |
115 | 0 | } |
116 | | |
117 | | // ChromeOnly |
118 | | HeadersGuardEnum Guard() const |
119 | 0 | { |
120 | 0 | return mInternalHeaders->Guard(); |
121 | 0 | } |
122 | | |
123 | | void SetGuard(HeadersGuardEnum aGuard, ErrorResult& aRv) |
124 | 0 | { |
125 | 0 | mInternalHeaders->SetGuard(aGuard, aRv); |
126 | 0 | } |
127 | | |
128 | | virtual JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override; |
129 | 0 | nsISupports* GetParentObject() const { return mOwner; } |
130 | | |
131 | | private: |
132 | | virtual ~Headers(); |
133 | | |
134 | | InternalHeaders* |
135 | | GetInternalHeaders() const |
136 | 0 | { |
137 | 0 | return mInternalHeaders; |
138 | 0 | } |
139 | | }; |
140 | | |
141 | | } // namespace dom |
142 | | } // namespace mozilla |
143 | | |
144 | | #endif // mozilla_dom_Headers_h |