Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(254)

Side by Side Diff: Source/modules/serviceworkers/Headers.cpp

Issue 534133002: [WIP] bindings: Introduce PropertyBag (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/FetchUtils.h" 10 #include "core/fetch/FetchUtils.h"
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 object.getOwnPropertyNames(keys); 241 object.getOwnPropertyNames(keys);
242 if (keys.size() == 0) 242 if (keys.size() == 0)
243 return; 243 return;
244 244
245 // Because of the restrictions in IDL compiler of blink we recieve 245 // Because of the restrictions in IDL compiler of blink we recieve
246 // sequence<sequence<ByteString>> as a Dictionary, which is a type of union 246 // sequence<sequence<ByteString>> as a Dictionary, which is a type of union
247 // type of HeadersInit defined in the spec. 247 // type of HeadersInit defined in the spec.
248 // http://fetch.spec.whatwg.org/#headers-class 248 // http://fetch.spec.whatwg.org/#headers-class
249 // FIXME: Support sequence<sequence<ByteString>>. 249 // FIXME: Support sequence<sequence<ByteString>>.
250 Vector<String> keyValuePair; 250 Vector<String> keyValuePair;
251 if (DictionaryHelper::get(object, keys[0], keyValuePair)) { 251 if (object.get(keys[0], keyValuePair)) {
252 // "2. Otherwise, if |object| is a sequence, then for each |header| in 252 // "2. Otherwise, if |object| is a sequence, then for each |header| in
253 // |object|, run these substeps: 253 // |object|, run these substeps:
254 // 1. If |header| does not contain exactly two items, throw a 254 // 1. If |header| does not contain exactly two items, throw a
255 // TypeError. 255 // TypeError.
256 // 2. Append |header|'s first item/|header|'s second item to 256 // 2. Append |header|'s first item/|header|'s second item to
257 // |headers|. Rethrow any exception." 257 // |headers|. Rethrow any exception."
258 for (size_t i = 0; i < keys.size(); ++i) { 258 for (size_t i = 0; i < keys.size(); ++i) {
259 // We've already got the keyValuePair for key[0]. 259 // We've already got the keyValuePair for key[0].
260 if (i > 0) { 260 if (i > 0) {
261 if (!DictionaryHelper::get(object, keys[i], keyValuePair)) { 261 if (!object.get(keys[i], keyValuePair)) {
262 exceptionState.throwTypeError("Invalid value"); 262 exceptionState.throwTypeError("Invalid value");
263 return; 263 return;
264 } 264 }
265 } 265 }
266 if (keyValuePair.size() != 2) { 266 if (keyValuePair.size() != 2) {
267 exceptionState.throwTypeError("Invalid value"); 267 exceptionState.throwTypeError("Invalid value");
268 return; 268 return;
269 } 269 }
270 append(keyValuePair[0], keyValuePair[1], exceptionState); 270 append(keyValuePair[0], keyValuePair[1], exceptionState);
271 if (exceptionState.hadException()) 271 if (exceptionState.hadException())
272 return; 272 return;
273 keyValuePair.clear(); 273 keyValuePair.clear();
274 } 274 }
275 return; 275 return;
276 } 276 }
277 // "3. Otherwise, if |object| is an open-ended dictionary, then for each 277 // "3. Otherwise, if |object| is an open-ended dictionary, then for each
278 // |header| in object, run these substeps: 278 // |header| in object, run these substeps:
279 // 1. Set |header|'s key to |header|'s key, converted to ByteString. 279 // 1. Set |header|'s key to |header|'s key, converted to ByteString.
280 // Rethrow any exception. 280 // Rethrow any exception.
281 // 2. Append |header|'s key/|header|'s value to |headers|. Rethrow any 281 // 2. Append |header|'s key/|header|'s value to |headers|. Rethrow any
282 // exception." 282 // exception."
283 // FIXME: Support OpenEndedDictionary<ByteString>. 283 // FIXME: Support OpenEndedDictionary<ByteString>.
284 for (size_t i = 0; i < keys.size(); ++i) { 284 for (size_t i = 0; i < keys.size(); ++i) {
285 String value; 285 String value;
286 if (!DictionaryHelper::get(object, keys[i], value)) { 286 if (!object.get(keys[i], value)) {
287 exceptionState.throwTypeError("Invalid value"); 287 exceptionState.throwTypeError("Invalid value");
288 return; 288 return;
289 } 289 }
290 append(keys[i], value, exceptionState); 290 append(keys[i], value, exceptionState);
291 if (exceptionState.hadException()) 291 if (exceptionState.hadException())
292 return; 292 return;
293 } 293 }
294 } 294 }
295 295
296 Headers::Headers() 296 Headers::Headers()
(...skipping 20 matching lines...) Expand all
317 break; 317 break;
318 } 318 }
319 } 319 }
320 320
321 void Headers::trace(Visitor* visitor) 321 void Headers::trace(Visitor* visitor)
322 { 322 {
323 visitor->trace(m_headerList); 323 visitor->trace(m_headerList);
324 } 324 }
325 325
326 } // namespace blink 326 } // namespace blink
OLDNEW
« no previous file with comments | « Source/modules/notifications/Notification.cpp ('k') | Source/modules/serviceworkers/RegistrationOptionList.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698