OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "config.h" | |
6 #include "modules/serviceworkers/HeaderMap.h" | |
7 | |
8 #include "bindings/core/v8/ExceptionState.h" | |
9 #include "modules/serviceworkers/HeaderMapForEachCallback.h" | |
10 #include "wtf/PassRefPtr.h" | |
11 #include "wtf/RefPtr.h" | |
12 #include "wtf/text/WTFString.h" | |
13 | |
14 namespace WebCore { | |
15 | |
16 PassRefPtr<HeaderMap> HeaderMap::create() | |
17 { | |
18 return adoptRef(new HeaderMap); | |
19 } | |
20 | |
21 PassRefPtr<HeaderMap> HeaderMap::create(const HashMap<String, String>& headers) | |
22 { | |
23 return adoptRef(new HeaderMap(headers)); | |
24 } | |
25 | |
26 unsigned long HeaderMap::size() const | |
27 { | |
28 return m_headers.size(); | |
29 } | |
30 | |
31 void HeaderMap::clear() | |
32 { | |
33 m_headers.clear(); | |
34 } | |
35 | |
36 bool HeaderMap::remove(const String& key) | |
37 { | |
38 if (!has(key)) | |
39 return false; | |
40 m_headers.remove(key); | |
41 return true; | |
42 } | |
43 | |
44 String HeaderMap::get(const String& key) | |
45 { | |
46 return m_headers.get(key); | |
47 } | |
48 | |
49 bool HeaderMap::has(const String& key) | |
50 { | |
51 return m_headers.find(key) != m_headers.end(); | |
52 } | |
53 | |
54 void HeaderMap::set(const String& key, const String& value) | |
55 { | |
56 m_headers.set(key, value); | |
57 } | |
58 | |
59 void HeaderMap::forEach(PassOwnPtr<HeaderMapForEachCallback> callback, ScriptVal
ue& thisArg) | |
60 { | |
61 forEachInternal(callback, &thisArg); | |
62 } | |
63 | |
64 void HeaderMap::forEach(PassOwnPtr<HeaderMapForEachCallback> callback) | |
65 { | |
66 forEachInternal(callback, 0); | |
67 } | |
68 | |
69 HeaderMap::HeaderMap() | |
70 { | |
71 ScriptWrappable::init(this); | |
72 } | |
73 | |
74 HeaderMap::HeaderMap(const HashMap<String, String>& headers) | |
75 : m_headers(headers) | |
76 { | |
77 ScriptWrappable::init(this); | |
78 } | |
79 | |
80 void HeaderMap::forEachInternal(PassOwnPtr<HeaderMapForEachCallback> callback, S
criptValue* thisArg) | |
81 { | |
82 TrackExceptionState exceptionState; | |
83 for (HashMap<String, String>::const_iterator it = m_headers.begin(); it != m
_headers.end(); ++it) { | |
84 if (thisArg) | |
85 callback->handleItem(*thisArg, it->value, it->key, this); | |
86 else | |
87 callback->handleItem(it->value, it->key, this); | |
88 if (exceptionState.hadException()) | |
89 break; | |
90 } | |
91 } | |
92 | |
93 } // namespace WebCore | |
OLD | NEW |