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/Cache.h" | 6 #include "modules/serviceworkers/Cache.h" |
7 | 7 |
8 #include "bindings/core/v8/ExceptionState.h" | 8 #include "bindings/core/v8/ExceptionState.h" |
9 #include "bindings/core/v8/ScriptPromiseResolver.h" | 9 #include "bindings/core/v8/ScriptPromiseResolver.h" |
10 #include "bindings/core/v8/ScriptState.h" | 10 #include "bindings/core/v8/ScriptState.h" |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
212 } | 212 } |
213 | 213 |
214 ScriptPromise Cache::deleteFunction(ScriptState* scriptState, const String& requ estString, const CacheQueryOptions& options, ExceptionState& exceptionState) | 214 ScriptPromise Cache::deleteFunction(ScriptState* scriptState, const String& requ estString, const CacheQueryOptions& options, ExceptionState& exceptionState) |
215 { | 215 { |
216 Request* request = Request::create(scriptState->executionContext(), requestS tring, exceptionState); | 216 Request* request = Request::create(scriptState->executionContext(), requestS tring, exceptionState); |
217 if (exceptionState.hadException()) | 217 if (exceptionState.hadException()) |
218 return ScriptPromise(); | 218 return ScriptPromise(); |
219 return deleteImpl(scriptState, request, options); | 219 return deleteImpl(scriptState, request, options); |
220 } | 220 } |
221 | 221 |
222 ScriptPromise Cache::put(ScriptState* scriptState, Request* request, Response* r esponse) | 222 ScriptPromise Cache::put(ScriptState* scriptState, Request* request, Response* r esponse, ExceptionState& exceptionState) |
223 { | 223 { |
224 if (request->hasBody() && request->bodyUsed()) { | |
225 exceptionState.throwTypeError("The Request's body has already been used. "); | |
226 return ScriptPromise(); | |
227 } | |
228 | |
229 if (response->bodyUsed()) { | |
230 exceptionState.throwTypeError("The Response's body has already been used ."); | |
231 return ScriptPromise(); | |
232 } | |
233 | |
234 if (request->hasBody()) | |
235 request->setBodyUsed(); | |
236 response->setBodyUsed(); | |
bkelly
2014/11/07 20:35:19
While it will be a somewhat rare case, it is possi
| |
237 | |
224 return putImpl(scriptState, request, response); | 238 return putImpl(scriptState, request, response); |
225 } | 239 } |
226 | 240 |
227 ScriptPromise Cache::put(ScriptState* scriptState, const String& requestString, Response* response, ExceptionState& exceptionState) | 241 ScriptPromise Cache::put(ScriptState* scriptState, const String& requestString, Response* response, ExceptionState& exceptionState) |
228 { | 242 { |
229 Request* request = Request::create(scriptState->executionContext(), requestS tring, exceptionState); | 243 Request* request = Request::create(scriptState->executionContext(), requestS tring, exceptionState); |
230 if (exceptionState.hadException()) | 244 if (exceptionState.hadException()) |
231 return ScriptPromise(); | 245 return ScriptPromise(); |
246 | |
247 if (response->bodyUsed()) { | |
248 exceptionState.throwTypeError("The Response's body has already been used ."); | |
249 return ScriptPromise(); | |
250 } | |
251 response->setBodyUsed(); | |
bkelly
2014/11/07 20:35:19
Likewise, check hasBody() here as well.
| |
252 | |
232 return putImpl(scriptState, request, response); | 253 return putImpl(scriptState, request, response); |
233 } | 254 } |
234 | 255 |
235 ScriptPromise Cache::keys(ScriptState* scriptState) | 256 ScriptPromise Cache::keys(ScriptState* scriptState) |
236 { | 257 { |
237 return keysImpl(scriptState); | 258 return keysImpl(scriptState); |
238 } | 259 } |
239 | 260 |
240 ScriptPromise Cache::keys(ScriptState* scriptState, Request* request, const Cach eQueryOptions& options) | 261 ScriptPromise Cache::keys(ScriptState* scriptState, Request* request, const Cach eQueryOptions& options) |
241 { | 262 { |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
347 WebServiceWorkerRequest webRequest; | 368 WebServiceWorkerRequest webRequest; |
348 request->populateWebServiceWorkerRequest(webRequest); | 369 request->populateWebServiceWorkerRequest(webRequest); |
349 | 370 |
350 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scrip tState); | 371 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scrip tState); |
351 const ScriptPromise promise = resolver->promise(); | 372 const ScriptPromise promise = resolver->promise(); |
352 m_webCache->dispatchKeys(new CacheWithRequestsCallbacks(resolver), 0, toWebQ ueryParams(options)); | 373 m_webCache->dispatchKeys(new CacheWithRequestsCallbacks(resolver), 0, toWebQ ueryParams(options)); |
353 return promise; | 374 return promise; |
354 } | 375 } |
355 | 376 |
356 } // namespace blink | 377 } // namespace blink |
OLD | NEW |