| 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 : headers_(headers->Clone()), current_(0) { | 22 : headers_(headers->SortAndCombine()), current_(0) {} |
| 26 headers_->SortAndCombine(); | |
| 27 } | |
| 28 | 23 |
| 29 bool Next(ScriptState* script_state, | 24 bool Next(ScriptState* script_state, |
| 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 (current_ >= headers_->size()) | 31 if (current_ >= headers_.size()) |
| 37 return false; | 32 return false; |
| 38 | 33 |
| 39 const FetchHeaderList::Header& header = headers_->Entry(current_++); | 34 const FetchHeaderList::Header& header = headers_.at(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(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> headers_; | 45 Vector<std::pair<String, String>> headers_; |
| 52 size_t current_; | 46 size_t 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& exception_state) { | 246 void Headers::FillWith(const Headers* object, ExceptionState& exception_state) { |
| 253 ASSERT(header_list_->size() == 0); | 247 ASSERT(header_list_->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->header_list_->List().size(); ++i) { | 254 for (const auto& header : object->header_list_->List()) { |
| 261 append(object->header_list_->List()[i]->first, | 255 append(header.first, header.second, exception_state); |
| 262 object->header_list_->List()[i]->second, exception_state); | |
| 263 if (exception_state.HadException()) | 256 if (exception_state.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& exception_state) { | 262 ExceptionState& exception_state) { |
| 270 ASSERT(!header_list_->size()); | 263 ASSERT(!header_list_->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(header_list_); | 314 visitor->Trace(header_list_); |
| 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(header_list_); | 320 return new HeadersIterationSource(header_list_); |
| 328 } | 321 } |
| 329 | 322 |
| 330 } // namespace blink | 323 } // namespace blink |
| OLD | NEW |