Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef Headers_h | 5 #ifndef Headers_h |
| 6 #define Headers_h | 6 #define Headers_h |
| 7 | 7 |
| 8 #include "bindings/core/v8/Iterable.h" | 8 #include "bindings/core/v8/Iterable.h" |
| 9 #include "bindings/core/v8/ScriptState.h" | 9 #include "bindings/core/v8/ScriptState.h" |
| 10 #include "bindings/core/v8/ScriptWrappable.h" | 10 #include "bindings/core/v8/ScriptWrappable.h" |
| 11 #include "modules/ModulesExport.h" | 11 #include "modules/ModulesExport.h" |
| 12 #include "modules/fetch/FetchHeaderList.h" | 12 #include "modules/fetch/FetchHeaderList.h" |
| 13 #include "platform/wtf/Forward.h" | 13 #include "platform/wtf/Forward.h" |
| 14 | 14 |
| 15 namespace blink { | 15 namespace blink { |
| 16 | 16 |
| 17 class ByteStringSequenceSequenceOrByteStringByteStringRecordOrHeaders; | 17 class ByteStringSequenceSequenceOrByteStringByteStringRecordOrHeaders; |
| 18 class ExceptionState; | 18 class ExceptionState; |
| 19 | 19 |
| 20 typedef ByteStringSequenceSequenceOrByteStringByteStringRecordOrHeaders | |
| 21 HeadersInit; | |
|
yhirano
2017/05/01 10:36:40
Though I call both "typedef", "using" is better, I
Raphael Kubo da Costa (rakuco)
2017/05/01 10:46:32
Done too :)
| |
| 22 | |
| 20 // http://fetch.spec.whatwg.org/#headers-class | 23 // http://fetch.spec.whatwg.org/#headers-class |
| 21 class MODULES_EXPORT Headers final : public GarbageCollected<Headers>, | 24 class MODULES_EXPORT Headers final : public GarbageCollected<Headers>, |
| 22 public ScriptWrappable, | 25 public ScriptWrappable, |
| 23 public PairIterable<String, String> { | 26 public PairIterable<String, String> { |
| 24 DEFINE_WRAPPERTYPEINFO(); | 27 DEFINE_WRAPPERTYPEINFO(); |
| 25 | 28 |
| 26 public: | 29 public: |
| 27 enum Guard { | 30 enum Guard { |
| 28 kImmutableGuard, | 31 kImmutableGuard, |
| 29 kRequestGuard, | 32 kRequestGuard, |
| 30 kRequestNoCORSGuard, | 33 kRequestNoCORSGuard, |
| 31 kResponseGuard, | 34 kResponseGuard, |
| 32 kNoneGuard | 35 kNoneGuard |
| 33 }; | 36 }; |
| 34 | 37 |
| 35 static Headers* Create(ExceptionState&); | 38 static Headers* Create(ExceptionState&); |
| 36 static Headers* Create( | 39 static Headers* Create(const HeadersInit&, ExceptionState&); |
| 37 const ByteStringSequenceSequenceOrByteStringByteStringRecordOrHeaders&, | |
| 38 ExceptionState&); | |
| 39 | 40 |
| 40 // Shares the FetchHeaderList. Called when creating a Request or Response. | 41 // Shares the FetchHeaderList. Called when creating a Request or Response. |
| 41 static Headers* Create(FetchHeaderList*); | 42 static Headers* Create(FetchHeaderList*); |
| 42 | 43 |
| 43 Headers* Clone() const; | 44 Headers* Clone() const; |
| 44 | 45 |
| 45 // Headers.idl implementation. | 46 // Headers.idl implementation. |
| 46 void append(const String& name, const String& value, ExceptionState&); | 47 void append(const String& name, const String& value, ExceptionState&); |
| 47 void remove(const String& key, ExceptionState&); | 48 void remove(const String& key, ExceptionState&); |
| 48 String get(const String& key, ExceptionState&); | 49 String get(const String& key, ExceptionState&); |
| 49 bool has(const String& key, ExceptionState&); | 50 bool has(const String& key, ExceptionState&); |
| 50 void set(const String& key, const String& value, ExceptionState&); | 51 void set(const String& key, const String& value, ExceptionState&); |
| 51 | 52 |
| 52 void SetGuard(Guard guard) { guard_ = guard; } | 53 void SetGuard(Guard guard) { guard_ = guard; } |
| 53 Guard GetGuard() const { return guard_; } | 54 Guard GetGuard() const { return guard_; } |
| 54 | 55 |
| 55 // These methods should only be called when size() would return 0. | 56 // These methods should only be called when size() would return 0. |
| 56 void FillWith(const Headers*, ExceptionState&); | 57 void FillWith(const Headers*, ExceptionState&); |
| 57 void FillWith(const Vector<Vector<String>>&, ExceptionState&); | 58 void FillWith(const HeadersInit&, ExceptionState&); |
| 58 void FillWith(const Vector<std::pair<String, String>>&, ExceptionState&); | |
| 59 | 59 |
| 60 FetchHeaderList* HeaderList() const { return header_list_; } | 60 FetchHeaderList* HeaderList() const { return header_list_; } |
| 61 DECLARE_TRACE(); | 61 DECLARE_TRACE(); |
| 62 | 62 |
| 63 private: | 63 private: |
| 64 Headers(); | 64 Headers(); |
| 65 // Shares the FetchHeaderList. Called when creating a Request or Response. | 65 // Shares the FetchHeaderList. Called when creating a Request or Response. |
| 66 explicit Headers(FetchHeaderList*); | 66 explicit Headers(FetchHeaderList*); |
| 67 | 67 |
| 68 // These methods should only be called when size() would return 0. | |
| 69 void FillWith(const Vector<Vector<String>>&, ExceptionState&); | |
| 70 void FillWith(const Vector<std::pair<String, String>>&, ExceptionState&); | |
| 71 | |
| 68 Member<FetchHeaderList> header_list_; | 72 Member<FetchHeaderList> header_list_; |
| 69 Guard guard_; | 73 Guard guard_; |
| 70 | 74 |
| 71 IterationSource* StartIteration(ScriptState*, ExceptionState&) override; | 75 IterationSource* StartIteration(ScriptState*, ExceptionState&) override; |
| 72 }; | 76 }; |
| 73 | 77 |
| 74 } // namespace blink | 78 } // namespace blink |
| 75 | 79 |
| 76 #endif // Headers_h | 80 #endif // Headers_h |
| OLD | NEW |