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 #include "modules/fetch/Headers.h" | 5 #include "modules/fetch/Headers.h" |
6 | 6 |
7 #include "bindings/core/v8/Dictionary.h" | 7 #include "bindings/core/v8/Dictionary.h" |
8 #include "bindings/core/v8/ExceptionState.h" | 8 #include "bindings/core/v8/ExceptionState.h" |
9 #include "bindings/core/v8/V8IteratorResultValue.h" | 9 #include "bindings/core/v8/V8IteratorResultValue.h" |
10 #include "core/dom/Iterator.h" | 10 #include "core/dom/Iterator.h" |
11 #include "platform/loader/fetch/FetchUtils.h" | 11 #include "platform/loader/fetch/FetchUtils.h" |
12 #include "wtf/NotFound.h" | |
13 #include "wtf/PassRefPtr.h" | |
14 #include "wtf/RefPtr.h" | |
15 #include "wtf/text/WTFString.h" | 12 #include "wtf/text/WTFString.h" |
16 | 13 |
17 namespace blink { | 14 namespace blink { |
18 | 15 |
19 namespace { | 16 namespace { |
20 | 17 |
21 class HeadersIterationSource final | 18 class HeadersIterationSource final |
22 : public PairIterable<String, String>::IterationSource { | 19 : public PairIterable<String, String>::IterationSource { |
23 public: | 20 public: |
24 explicit HeadersIterationSource(const FetchHeaderList* headers) | 21 explicit HeadersIterationSource(const FetchHeaderList* headers) |
25 : m_headers(headers->clone()), m_current(0) { | 22 : m_headers(headers->sortAndCombine()), m_current(0) {} |
26 m_headers->sortAndCombine(); | |
27 } | |
28 | 23 |
29 bool next(ScriptState* scriptState, | 24 bool next(ScriptState* scriptState, |
30 String& key, | 25 String& key, |
31 String& value, | 26 String& value, |
32 ExceptionState& exception) override { | 27 ExceptionState& exception) override { |
33 // This simply advances an index and returns the next value if any; the | 28 // This simply advances an index and returns the next value if any; the |
34 // iterated list is not exposed to script so it will never be mutated | 29 // iterated list is not exposed to script so it will never be mutated |
35 // during iteration. | 30 // during iteration. |
36 if (m_current >= m_headers->size()) | 31 if (m_current >= m_headers.size()) |
37 return false; | 32 return false; |
38 | 33 |
39 const FetchHeaderList::Header& header = m_headers->entry(m_current++); | 34 const FetchHeaderList::Header& header = m_headers.at(m_current++); |
40 key = header.first; | 35 key = header.first; |
41 value = header.second; | 36 value = header.second; |
42 return true; | 37 return true; |
43 } | 38 } |
44 | 39 |
45 DEFINE_INLINE_VIRTUAL_TRACE() { | 40 DEFINE_INLINE_VIRTUAL_TRACE() { |
46 visitor->trace(m_headers); | |
47 PairIterable<String, String>::IterationSource::trace(visitor); | 41 PairIterable<String, String>::IterationSource::trace(visitor); |
48 } | 42 } |
49 | 43 |
50 private: | 44 private: |
51 const Member<FetchHeaderList> m_headers; | 45 Vector<std::pair<String, String>> m_headers; |
52 size_t m_current; | 46 size_t m_current; |
53 }; | 47 }; |
54 | 48 |
55 } // namespace | 49 } // namespace |
56 | 50 |
57 Headers* Headers::create() { | 51 Headers* Headers::create() { |
58 return new Headers; | 52 return new Headers; |
59 } | 53 } |
60 | 54 |
61 Headers* Headers::create(ExceptionState&) { | 55 Headers* Headers::create(ExceptionState&) { |
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
250 } | 244 } |
251 | 245 |
252 void Headers::fillWith(const Headers* object, ExceptionState& exceptionState) { | 246 void Headers::fillWith(const Headers* object, ExceptionState& exceptionState) { |
253 ASSERT(m_headerList->size() == 0); | 247 ASSERT(m_headerList->size() == 0); |
254 // "To fill a Headers object (|this|) with a given object (|object|), run | 248 // "To fill a Headers object (|this|) with a given object (|object|), run |
255 // these steps:" | 249 // these steps:" |
256 // "1. If |object| is a Headers object, copy its header list as | 250 // "1. If |object| is a Headers object, copy its header list as |
257 // |headerListCopy| and then for each |header| in |headerListCopy|, | 251 // |headerListCopy| and then for each |header| in |headerListCopy|, |
258 // retaining order, append header's |name|/|header|'s value to | 252 // retaining order, append header's |name|/|header|'s value to |
259 // |headers|. Rethrow any exception." | 253 // |headers|. Rethrow any exception." |
260 for (size_t i = 0; i < object->m_headerList->list().size(); ++i) { | 254 for (const auto& header : object->m_headerList->list()) { |
261 append(object->m_headerList->list()[i]->first, | 255 append(header.first, header.second, exceptionState); |
262 object->m_headerList->list()[i]->second, exceptionState); | |
263 if (exceptionState.hadException()) | 256 if (exceptionState.hadException()) |
264 return; | 257 return; |
265 } | 258 } |
266 } | 259 } |
267 | 260 |
268 void Headers::fillWith(const Vector<Vector<String>>& object, | 261 void Headers::fillWith(const Vector<Vector<String>>& object, |
269 ExceptionState& exceptionState) { | 262 ExceptionState& exceptionState) { |
270 ASSERT(!m_headerList->size()); | 263 ASSERT(!m_headerList->size()); |
271 // "2. Otherwise, if |object| is a sequence, then for each |header| in | 264 // "2. Otherwise, if |object| is a sequence, then for each |header| in |
272 // |object|, run these substeps: | 265 // |object|, run these substeps: |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
321 visitor->trace(m_headerList); | 314 visitor->trace(m_headerList); |
322 } | 315 } |
323 | 316 |
324 PairIterable<String, String>::IterationSource* Headers::startIteration( | 317 PairIterable<String, String>::IterationSource* Headers::startIteration( |
325 ScriptState*, | 318 ScriptState*, |
326 ExceptionState&) { | 319 ExceptionState&) { |
327 return new HeadersIterationSource(m_headerList); | 320 return new HeadersIterationSource(m_headerList); |
328 } | 321 } |
329 | 322 |
330 } // namespace blink | 323 } // namespace blink |
OLD | NEW |