| 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/ExceptionState.h" | 7 #include "bindings/core/v8/ExceptionState.h" |
| 8 #include "bindings/core/v8/V8IteratorResultValue.h" | 8 #include "bindings/core/v8/V8IteratorResultValue.h" |
| 9 #include "bindings/modules/v8/ByteStringSequenceSequenceOrByteStringByteStringRe
cordOrHeaders.h" | 9 #include "bindings/modules/v8/ByteStringSequenceSequenceOrByteStringByteStringRe
cordOrHeaders.h" |
| 10 #include "core/dom/Iterator.h" | 10 #include "core/dom/Iterator.h" |
| (...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 231 // "5. Otherwise, if guard is |response| and |name| is a forbidden response | 231 // "5. Otherwise, if guard is |response| and |name| is a forbidden response |
| 232 // header name, return." | 232 // header name, return." |
| 233 if (guard_ == kResponseGuard && | 233 if (guard_ == kResponseGuard && |
| 234 FetchUtils::IsForbiddenResponseHeaderName(name)) | 234 FetchUtils::IsForbiddenResponseHeaderName(name)) |
| 235 return; | 235 return; |
| 236 // "6. Set |name|/|value| in header list." | 236 // "6. Set |name|/|value| in header list." |
| 237 header_list_->Set(name, value); | 237 header_list_->Set(name, value); |
| 238 } | 238 } |
| 239 | 239 |
| 240 void Headers::FillWith(const Headers* object, ExceptionState& exception_state) { | 240 void Headers::FillWith(const Headers* object, ExceptionState& exception_state) { |
| 241 ASSERT(header_list_->size() == 0); | 241 DCHECK(header_list_->size() == 0); |
| 242 // There used to be specific steps describing filling a Headers object with | 242 // There used to be specific steps describing filling a Headers object with |
| 243 // another Headers object, but it has since been removed because it should be | 243 // another Headers object, but it has since been removed because it should be |
| 244 // handled like a sequence (http://crbug.com/690428). | 244 // handled like a sequence (http://crbug.com/690428). |
| 245 for (size_t i = 0; i < object->header_list_->List().size(); ++i) { | 245 for (size_t i = 0; i < object->header_list_->List().size(); ++i) { |
| 246 append(object->header_list_->List()[i]->first, | 246 append(object->header_list_->List()[i]->first, |
| 247 object->header_list_->List()[i]->second, exception_state); | 247 object->header_list_->List()[i]->second, exception_state); |
| 248 if (exception_state.HadException()) | 248 if (exception_state.HadException()) |
| 249 return; | 249 return; |
| 250 } | 250 } |
| 251 } | 251 } |
| 252 | 252 |
| 253 void Headers::FillWith(const Vector<Vector<String>>& object, | 253 void Headers::FillWith(const Vector<Vector<String>>& object, |
| 254 ExceptionState& exception_state) { | 254 ExceptionState& exception_state) { |
| 255 ASSERT(!header_list_->size()); | 255 DCHECK(!header_list_->size()); |
| 256 // "1. If |object| is a sequence, then for each |header| in |object|, run | 256 // "1. If |object| is a sequence, then for each |header| in |object|, run |
| 257 // these substeps: | 257 // these substeps: |
| 258 // 1. If |header| does not contain exactly two items, then throw a | 258 // 1. If |header| does not contain exactly two items, then throw a |
| 259 // TypeError. | 259 // TypeError. |
| 260 // 2. Append |header|’s first item/|header|’s second item to |headers|. | 260 // 2. Append |header|’s first item/|header|’s second item to |headers|. |
| 261 // Rethrow any exception." | 261 // Rethrow any exception." |
| 262 for (size_t i = 0; i < object.size(); ++i) { | 262 for (size_t i = 0; i < object.size(); ++i) { |
| 263 if (object[i].size() != 2) { | 263 if (object[i].size() != 2) { |
| 264 exception_state.ThrowTypeError("Invalid value"); | 264 exception_state.ThrowTypeError("Invalid value"); |
| 265 return; | 265 return; |
| 266 } | 266 } |
| 267 append(object[i][0], object[i][1], exception_state); | 267 append(object[i][0], object[i][1], exception_state); |
| 268 if (exception_state.HadException()) | 268 if (exception_state.HadException()) |
| 269 return; | 269 return; |
| 270 } | 270 } |
| 271 } | 271 } |
| 272 | 272 |
| 273 void Headers::FillWith(const Vector<std::pair<String, String>>& object, | 273 void Headers::FillWith(const Vector<std::pair<String, String>>& object, |
| 274 ExceptionState& exception_state) { | 274 ExceptionState& exception_state) { |
| 275 ASSERT(!header_list_->size()); | 275 DCHECK(!header_list_->size()); |
| 276 | 276 |
| 277 for (const auto& item : object) { | 277 for (const auto& item : object) { |
| 278 append(item.first, item.second, exception_state); | 278 append(item.first, item.second, exception_state); |
| 279 if (exception_state.HadException()) | 279 if (exception_state.HadException()) |
| 280 return; | 280 return; |
| 281 } | 281 } |
| 282 } | 282 } |
| 283 | 283 |
| 284 Headers::Headers() | 284 Headers::Headers() |
| 285 : header_list_(FetchHeaderList::Create()), guard_(kNoneGuard) {} | 285 : header_list_(FetchHeaderList::Create()), guard_(kNoneGuard) {} |
| 286 | 286 |
| 287 Headers::Headers(FetchHeaderList* header_list) | 287 Headers::Headers(FetchHeaderList* header_list) |
| 288 : header_list_(header_list), guard_(kNoneGuard) {} | 288 : header_list_(header_list), guard_(kNoneGuard) {} |
| 289 | 289 |
| 290 DEFINE_TRACE(Headers) { | 290 DEFINE_TRACE(Headers) { |
| 291 visitor->Trace(header_list_); | 291 visitor->Trace(header_list_); |
| 292 } | 292 } |
| 293 | 293 |
| 294 PairIterable<String, String>::IterationSource* Headers::StartIteration( | 294 PairIterable<String, String>::IterationSource* Headers::StartIteration( |
| 295 ScriptState*, | 295 ScriptState*, |
| 296 ExceptionState&) { | 296 ExceptionState&) { |
| 297 return new HeadersIterationSource(header_list_); | 297 return new HeadersIterationSource(header_list_); |
| 298 } | 298 } |
| 299 | 299 |
| 300 } // namespace blink | 300 } // namespace blink |
| OLD | NEW |