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

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

Issue 379113002: Move fetch-related predicates to core/fetch. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 4 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/CrossOriginAccessControl.h" 10 #include "core/fetch/FetchUtils.h"
11 #include "core/xml/XMLHttpRequest.h" 11 #include "core/xml/XMLHttpRequest.h"
12 #include "modules/serviceworkers/HeadersForEachCallback.h" 12 #include "modules/serviceworkers/HeadersForEachCallback.h"
13 #include "wtf/NotFound.h" 13 #include "wtf/NotFound.h"
14 #include "wtf/PassRefPtr.h" 14 #include "wtf/PassRefPtr.h"
15 #include "wtf/RefPtr.h" 15 #include "wtf/RefPtr.h"
16 #include "wtf/text/WTFString.h" 16 #include "wtf/text/WTFString.h"
17 17
18 namespace blink { 18 namespace blink {
19 19
20 PassRefPtrWillBeRawPtr<Headers> Headers::create() 20 PassRefPtrWillBeRawPtr<Headers> Headers::create()
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 exceptionState.throwTypeError("Invalid value"); 83 exceptionState.throwTypeError("Invalid value");
84 return; 84 return;
85 } 85 }
86 // "2. If guard is |request|, throw a TypeError." 86 // "2. If guard is |request|, throw a TypeError."
87 if (m_guard == ImmutableGuard) { 87 if (m_guard == ImmutableGuard) {
88 exceptionState.throwTypeError("Headers are immutable"); 88 exceptionState.throwTypeError("Headers are immutable");
89 return; 89 return;
90 } 90 }
91 // "3. Otherwise, if guard is |request| and |name| is a forbidden header 91 // "3. Otherwise, if guard is |request| and |name| is a forbidden header
92 // name, return." 92 // name, return."
93 if (m_guard == RequestGuard && FetchHeaderList::isForbiddenHeaderName(name)) 93 if (m_guard == RequestGuard && FetchUtils::isForbiddenHeaderName(name))
94 return; 94 return;
95 // "4. Otherwise, if guard is |request-no-CORS| and |name|/|value| is not a 95 // "4. Otherwise, if guard is |request-no-CORS| and |name|/|value| is not a
96 // simple header, return." 96 // simple header, return."
97 if (m_guard == RequestNoCORSGuard && !FetchHeaderList::isSimpleHeader(name, value)) 97 if (m_guard == RequestNoCORSGuard && !FetchUtils::isSimpleHeader(AtomicStrin g(name), AtomicString(value)))
98 return; 98 return;
99 // "5. Otherwise, if guard is |response| and |name| is a forbidden response 99 // "5. Otherwise, if guard is |response| and |name| is a forbidden response
100 // header name, return." 100 // header name, return."
101 if (m_guard == ResponseGuard && FetchHeaderList::isForbiddenResponseHeaderNa me(name)) 101 if (m_guard == ResponseGuard && FetchUtils::isForbiddenResponseHeaderName(na me))
102 return; 102 return;
103 // "6. Append |name|/|value| to header list." 103 // "6. Append |name|/|value| to header list."
104 m_headerList->append(name, value); 104 m_headerList->append(name, value);
105 } 105 }
106 106
107 void Headers::remove(const String& name, ExceptionState& exceptionState) 107 void Headers::remove(const String& name, ExceptionState& exceptionState)
108 { 108 {
109 // "The delete(|name|) method, when invoked, must run these steps:" 109 // "The delete(|name|) method, when invoked, must run these steps:"
110 // "1. If name is not a name, throw a TypeError." 110 // "1. If name is not a name, throw a TypeError."
111 if (!FetchHeaderList::isValidHeaderName(name)) { 111 if (!FetchHeaderList::isValidHeaderName(name)) {
112 exceptionState.throwTypeError("Invalid name"); 112 exceptionState.throwTypeError("Invalid name");
113 return; 113 return;
114 } 114 }
115 // "2. If guard is |immutable|, throw a TypeError." 115 // "2. If guard is |immutable|, throw a TypeError."
116 if (m_guard == ImmutableGuard) { 116 if (m_guard == ImmutableGuard) {
117 exceptionState.throwTypeError("Headers are immutable"); 117 exceptionState.throwTypeError("Headers are immutable");
118 return; 118 return;
119 } 119 }
120 // "3. Otherwise, if guard is |request| and |name| is a forbidden header 120 // "3. Otherwise, if guard is |request| and |name| is a forbidden header
121 // name, return." 121 // name, return."
122 if (m_guard == RequestGuard && FetchHeaderList::isForbiddenHeaderName(name)) 122 if (m_guard == RequestGuard && FetchUtils::isForbiddenHeaderName(name))
123 return; 123 return;
124 // "4. Otherwise, if guard is |request-no-CORS| and |name|/`invalid` is not 124 // "4. Otherwise, if guard is |request-no-CORS| and |name|/`invalid` is not
125 // a simple header, return." 125 // a simple header, return."
126 if (m_guard == RequestNoCORSGuard && !FetchHeaderList::isSimpleHeader(name, "invalid")) 126 if (m_guard == RequestNoCORSGuard && !FetchUtils::isSimpleHeader(AtomicStrin g(name), "invalid"))
127 return; 127 return;
128 // "5. Otherwise, if guard is |response| and |name| is a forbidden response 128 // "5. Otherwise, if guard is |response| and |name| is a forbidden response
129 // header name, return." 129 // header name, return."
130 if (m_guard == ResponseGuard && FetchHeaderList::isForbiddenResponseHeaderNa me(name)) 130 if (m_guard == ResponseGuard && FetchUtils::isForbiddenResponseHeaderName(na me))
131 return; 131 return;
132 // "6. Delete |name| from header list." 132 // "6. Delete |name| from header list."
133 m_headerList->remove(name); 133 m_headerList->remove(name);
134 } 134 }
135 135
136 String Headers::get(const String& name, ExceptionState& exceptionState) 136 String Headers::get(const String& name, ExceptionState& exceptionState)
137 { 137 {
138 // "The get(|name|) method, when invoked, must run these steps:" 138 // "The get(|name|) method, when invoked, must run these steps:"
139 // "1. If |name| is not a name, throw a TypeError." 139 // "1. If |name| is not a name, throw a TypeError."
140 if (!FetchHeaderList::isValidHeaderName(name)) { 140 if (!FetchHeaderList::isValidHeaderName(name)) {
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 exceptionState.throwTypeError("Invalid value"); 189 exceptionState.throwTypeError("Invalid value");
190 return; 190 return;
191 } 191 }
192 // "2. If guard is |immutable|, throw a TypeError." 192 // "2. If guard is |immutable|, throw a TypeError."
193 if (m_guard == ImmutableGuard) { 193 if (m_guard == ImmutableGuard) {
194 exceptionState.throwTypeError("Headers are immutable"); 194 exceptionState.throwTypeError("Headers are immutable");
195 return; 195 return;
196 } 196 }
197 // "3. Otherwise, if guard is |request| and |name| is a forbidden header 197 // "3. Otherwise, if guard is |request| and |name| is a forbidden header
198 // name, return." 198 // name, return."
199 if (m_guard == RequestGuard && FetchHeaderList::isForbiddenHeaderName(name)) 199 if (m_guard == RequestGuard && FetchUtils::isForbiddenHeaderName(name))
200 return; 200 return;
201 // "4. Otherwise, if guard is |request-no-CORS| and |name|/|value| is not a 201 // "4. Otherwise, if guard is |request-no-CORS| and |name|/|value| is not a
202 // simple header, return." 202 // simple header, return."
203 if (m_guard == RequestNoCORSGuard && !FetchHeaderList::isSimpleHeader(name, value)) 203 if (m_guard == RequestNoCORSGuard && !FetchUtils::isSimpleHeader(AtomicStrin g(name), AtomicString(value)))
204 return; 204 return;
205 // "5. Otherwise, if guard is |response| and |name| is a forbidden response 205 // "5. Otherwise, if guard is |response| and |name| is a forbidden response
206 // header name, return." 206 // header name, return."
207 if (m_guard == ResponseGuard && FetchHeaderList::isForbiddenResponseHeaderNa me(name)) 207 if (m_guard == ResponseGuard && FetchUtils::isForbiddenResponseHeaderName(na me))
208 return; 208 return;
209 // "6. Set |name|/|value| in header list." 209 // "6. Set |name|/|value| in header list."
210 m_headerList->set(name, value); 210 m_headerList->set(name, value);
211 } 211 }
212 212
213 void Headers::forEach(PassOwnPtr<HeadersForEachCallback> callback, ScriptValue& thisArg) 213 void Headers::forEach(PassOwnPtr<HeadersForEachCallback> callback, ScriptValue& thisArg)
214 { 214 {
215 forEachInternal(callback, &thisArg); 215 forEachInternal(callback, &thisArg);
216 } 216 }
217 217
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
321 break; 321 break;
322 } 322 }
323 } 323 }
324 324
325 void Headers::trace(Visitor* visitor) 325 void Headers::trace(Visitor* visitor)
326 { 326 {
327 visitor->trace(m_headerList); 327 visitor->trace(m_headerList);
328 } 328 }
329 329
330 } // namespace blink 330 } // namespace blink
OLDNEW
« no previous file with comments | « Source/modules/serviceworkers/FetchManager.cpp ('k') | Source/modules/serviceworkers/Request.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698