1 // Copyright 2014 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef Headers_h 6 #define Headers_h 7 8 #include "bindings/core/v8/ScriptWrappable.h" 9 #include "modules/serviceworkers/FetchHeaderList.h" 10 #include "wtf/Forward.h" 11 #include "wtf/PassOwnPtr.h" 12 13 namespace blink { 14 15 class Dictionary; 16 class ExceptionState; 17 class HeadersForEachCallback; 18 class ScriptValue; 19 20 // http://fetch.spec.whatwg.org/#headers-class 21 class Headers FINAL : public GarbageCollected<Headers>, public ScriptWrappable { 22 DEFINE_WRAPPERTYPEINFO(); 23 public: 24 enum Guard { ImmutableGuard, RequestGuard, RequestNoCORSGuard, ResponseGuard, NoneGuard }; 25 26 static Headers* create(); 27 static Headers* create(ExceptionState&); 28 static Headers* create(const Headers*, ExceptionState&); 29 static Headers* create(const Dictionary&, ExceptionState&); 30 31 // Shares the FetchHeaderList. Called when creating a Request or Response. 32 static Headers* create(FetchHeaderList*); 33 34 Headers* createCopy() const; 35 36 // Headers.idl implementation. 37 void append(const String& name, const String& value, ExceptionState&); 38 void remove(const String& key, ExceptionState&); 39 String get(const String& key, ExceptionState&); 40 Vector<String> getAll(const String& key, ExceptionState&); 41 bool has(const String& key, ExceptionState&); 42 void set(const String& key, const String& value, ExceptionState&); 43 unsigned long size() const; 44 void forEach(HeadersForEachCallback*, const ScriptValue&); 45 void forEach(HeadersForEachCallback*); 46 47 void setGuard(Guard guard) { m_guard = guard; } 48 Guard guard() const { return m_guard; } 49 50 // These methods should only be called when size() would return 0. 51 void fillWith(const Headers*, ExceptionState&); 52 void fillWith(const Dictionary&, ExceptionState&); 53 54 void trace(Visitor*); 55 56 private: 57 Headers(); 58 // Shares the FetchHeaderList. Called when creating a Request or Response. 59 explicit Headers(FetchHeaderList*); 60 void forEachInternal(HeadersForEachCallback*, const ScriptValue*); 61 62 Member<FetchHeaderList> m_headerList; 63 Guard m_guard; 64 }; 65 66 } // namespace blink 67 68 #endif // Headers_h 69