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 "config.h" | 5 #include "config.h" |
6 #include "modules/serviceworkers/Headers.h" | 6 #include "modules/serviceworkers/Headers.h" |
7 | 7 |
8 #include "bindings/core/v8/Dictionary.h" | 8 #include "bindings/core/v8/Dictionary.h" |
9 #include "bindings/core/v8/ExceptionState.h" | 9 #include "bindings/core/v8/ExceptionState.h" |
10 #include "core/fetch/CrossOriginAccessControl.h" | 10 #include "core/fetch/CrossOriginAccessControl.h" |
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
246 object.getOwnPropertyNames(keys); | 246 object.getOwnPropertyNames(keys); |
247 if (keys.size() == 0) | 247 if (keys.size() == 0) |
248 return; | 248 return; |
249 | 249 |
250 // Because of the restrictions in IDL compiler of blink we recieve | 250 // Because of the restrictions in IDL compiler of blink we recieve |
251 // sequence<sequence<ByteString>> as a Dictionary, which is a type of union | 251 // sequence<sequence<ByteString>> as a Dictionary, which is a type of union |
252 // type of HeadersInit defined in the spec. | 252 // type of HeadersInit defined in the spec. |
253 // http://fetch.spec.whatwg.org/#headers-class | 253 // http://fetch.spec.whatwg.org/#headers-class |
254 // FIXME: Support sequence<sequence<ByteString>>. | 254 // FIXME: Support sequence<sequence<ByteString>>. |
255 Vector<String> keyValuePair; | 255 Vector<String> keyValuePair; |
256 if (object.get(keys[0], keyValuePair)) { | 256 if (DictionaryHelper::get(object, keys[0], keyValuePair)) { |
257 // "2. Otherwise, if |object| is a sequence, then for each |header| in | 257 // "2. Otherwise, if |object| is a sequence, then for each |header| in |
258 // |object|, run these substeps: | 258 // |object|, run these substeps: |
259 // 1. If |header| does not contain exactly two items, throw a | 259 // 1. If |header| does not contain exactly two items, throw a |
260 // TypeError. | 260 // TypeError. |
261 // 2. Append |header|'s first item/|header|'s second item to | 261 // 2. Append |header|'s first item/|header|'s second item to |
262 // |headers|. Rethrow any exception." | 262 // |headers|. Rethrow any exception." |
263 for (size_t i = 0; i < keys.size(); ++i) { | 263 for (size_t i = 0; i < keys.size(); ++i) { |
264 // We've already got the keyValuePair for key[0]. | 264 // We've already got the keyValuePair for key[0]. |
265 if (i > 0) { | 265 if (i > 0) { |
266 if (!object.get(keys[i], keyValuePair)) { | 266 if (!DictionaryHelper::get(object, keys[i], keyValuePair)) { |
267 exceptionState.throwTypeError("Invalid value"); | 267 exceptionState.throwTypeError("Invalid value"); |
268 return; | 268 return; |
269 } | 269 } |
270 } | 270 } |
271 if (keyValuePair.size() != 2) { | 271 if (keyValuePair.size() != 2) { |
272 exceptionState.throwTypeError("Invalid value"); | 272 exceptionState.throwTypeError("Invalid value"); |
273 return; | 273 return; |
274 } | 274 } |
275 append(keyValuePair[0], keyValuePair[1], exceptionState); | 275 append(keyValuePair[0], keyValuePair[1], exceptionState); |
276 if (exceptionState.hadException()) | 276 if (exceptionState.hadException()) |
277 return; | 277 return; |
278 keyValuePair.clear(); | 278 keyValuePair.clear(); |
279 } | 279 } |
280 return; | 280 return; |
281 } | 281 } |
282 // "3. Otherwise, if |object| is an open-ended dictionary, then for each | 282 // "3. Otherwise, if |object| is an open-ended dictionary, then for each |
283 // |header| in object, run these substeps: | 283 // |header| in object, run these substeps: |
284 // 1. Set |header|'s key to |header|'s key, converted to ByteString. | 284 // 1. Set |header|'s key to |header|'s key, converted to ByteString. |
285 // Rethrow any exception. | 285 // Rethrow any exception. |
286 // 2. Append |header|'s key/|header|'s value to |headers|. Rethrow any | 286 // 2. Append |header|'s key/|header|'s value to |headers|. Rethrow any |
287 // exception." | 287 // exception." |
288 // FIXME: Support OpenEndedDictionary<ByteString>. | 288 // FIXME: Support OpenEndedDictionary<ByteString>. |
289 for (size_t i = 0; i < keys.size(); ++i) { | 289 for (size_t i = 0; i < keys.size(); ++i) { |
290 String value; | 290 String value; |
291 if (!object.get(keys[i], value)) { | 291 if (!DictionaryHelper::get(object, keys[i], value)) { |
292 exceptionState.throwTypeError("Invalid value"); | 292 exceptionState.throwTypeError("Invalid value"); |
293 return; | 293 return; |
294 } | 294 } |
295 append(keys[i], value, exceptionState); | 295 append(keys[i], value, exceptionState); |
296 if (exceptionState.hadException()) | 296 if (exceptionState.hadException()) |
297 return; | 297 return; |
298 } | 298 } |
299 } | 299 } |
300 | 300 |
301 Headers::Headers() | 301 Headers::Headers() |
(...skipping 18 matching lines...) Expand all Loading... |
320 if (thisArg) | 320 if (thisArg) |
321 callback->handleItem(*thisArg, m_headerList->list()[i]->second, m_he
aderList->list()[i]->first, this); | 321 callback->handleItem(*thisArg, m_headerList->list()[i]->second, m_he
aderList->list()[i]->first, this); |
322 else | 322 else |
323 callback->handleItem(m_headerList->list()[i]->second, m_headerList->
list()[i]->first, this); | 323 callback->handleItem(m_headerList->list()[i]->second, m_headerList->
list()[i]->first, this); |
324 if (exceptionState.hadException()) | 324 if (exceptionState.hadException()) |
325 break; | 325 break; |
326 } | 326 } |
327 } | 327 } |
328 | 328 |
329 } // namespace WebCore | 329 } // namespace WebCore |
OLD | NEW |