| 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 "modules/cachestorage/Cache.h" | 5 #include "modules/cachestorage/Cache.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <utility> | 8 #include <utility> |
| 9 #include "bindings/core/v8/CallbackPromiseAdapter.h" | 9 #include "bindings/core/v8/CallbackPromiseAdapter.h" |
| 10 #include "bindings/core/v8/ExceptionState.h" | 10 #include "bindings/core/v8/ExceptionState.h" |
| (...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 381 | 381 |
| 382 Cache* Cache::Create(GlobalFetch::ScopedFetcher* fetcher, | 382 Cache* Cache::Create(GlobalFetch::ScopedFetcher* fetcher, |
| 383 std::unique_ptr<WebServiceWorkerCache> web_cache) { | 383 std::unique_ptr<WebServiceWorkerCache> web_cache) { |
| 384 return new Cache(fetcher, std::move(web_cache)); | 384 return new Cache(fetcher, std::move(web_cache)); |
| 385 } | 385 } |
| 386 | 386 |
| 387 ScriptPromise Cache::match(ScriptState* script_state, | 387 ScriptPromise Cache::match(ScriptState* script_state, |
| 388 const RequestInfo& request, | 388 const RequestInfo& request, |
| 389 const CacheQueryOptions& options, | 389 const CacheQueryOptions& options, |
| 390 ExceptionState& exception_state) { | 390 ExceptionState& exception_state) { |
| 391 ASSERT(!request.isNull()); | 391 DCHECK(!request.isNull()); |
| 392 if (request.isRequest()) | 392 if (request.isRequest()) |
| 393 return MatchImpl(script_state, request.getAsRequest(), options); | 393 return MatchImpl(script_state, request.getAsRequest(), options); |
| 394 Request* new_request = | 394 Request* new_request = |
| 395 Request::Create(script_state, request.getAsUSVString(), exception_state); | 395 Request::Create(script_state, request.getAsUSVString(), exception_state); |
| 396 if (exception_state.HadException()) | 396 if (exception_state.HadException()) |
| 397 return ScriptPromise(); | 397 return ScriptPromise(); |
| 398 return MatchImpl(script_state, new_request, options); | 398 return MatchImpl(script_state, new_request, options); |
| 399 } | 399 } |
| 400 | 400 |
| 401 ScriptPromise Cache::matchAll(ScriptState* script_state, | 401 ScriptPromise Cache::matchAll(ScriptState* script_state, |
| 402 ExceptionState& exception_state) { | 402 ExceptionState& exception_state) { |
| 403 return MatchAllImpl(script_state); | 403 return MatchAllImpl(script_state); |
| 404 } | 404 } |
| 405 | 405 |
| 406 ScriptPromise Cache::matchAll(ScriptState* script_state, | 406 ScriptPromise Cache::matchAll(ScriptState* script_state, |
| 407 const RequestInfo& request, | 407 const RequestInfo& request, |
| 408 const CacheQueryOptions& options, | 408 const CacheQueryOptions& options, |
| 409 ExceptionState& exception_state) { | 409 ExceptionState& exception_state) { |
| 410 ASSERT(!request.isNull()); | 410 DCHECK(!request.isNull()); |
| 411 if (request.isRequest()) | 411 if (request.isRequest()) |
| 412 return MatchAllImpl(script_state, request.getAsRequest(), options); | 412 return MatchAllImpl(script_state, request.getAsRequest(), options); |
| 413 Request* new_request = | 413 Request* new_request = |
| 414 Request::Create(script_state, request.getAsUSVString(), exception_state); | 414 Request::Create(script_state, request.getAsUSVString(), exception_state); |
| 415 if (exception_state.HadException()) | 415 if (exception_state.HadException()) |
| 416 return ScriptPromise(); | 416 return ScriptPromise(); |
| 417 return MatchAllImpl(script_state, new_request, options); | 417 return MatchAllImpl(script_state, new_request, options); |
| 418 } | 418 } |
| 419 | 419 |
| 420 ScriptPromise Cache::add(ScriptState* script_state, | 420 ScriptPromise Cache::add(ScriptState* script_state, |
| 421 const RequestInfo& request, | 421 const RequestInfo& request, |
| 422 ExceptionState& exception_state) { | 422 ExceptionState& exception_state) { |
| 423 ASSERT(!request.isNull()); | 423 DCHECK(!request.isNull()); |
| 424 HeapVector<Member<Request>> requests; | 424 HeapVector<Member<Request>> requests; |
| 425 if (request.isRequest()) { | 425 if (request.isRequest()) { |
| 426 requests.push_back(request.getAsRequest()); | 426 requests.push_back(request.getAsRequest()); |
| 427 } else { | 427 } else { |
| 428 requests.push_back(Request::Create(script_state, request.getAsUSVString(), | 428 requests.push_back(Request::Create(script_state, request.getAsUSVString(), |
| 429 exception_state)); | 429 exception_state)); |
| 430 if (exception_state.HadException()) | 430 if (exception_state.HadException()) |
| 431 return ScriptPromise(); | 431 return ScriptPromise(); |
| 432 } | 432 } |
| 433 | 433 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 449 } | 449 } |
| 450 } | 450 } |
| 451 | 451 |
| 452 return AddAllImpl(script_state, requests, exception_state); | 452 return AddAllImpl(script_state, requests, exception_state); |
| 453 } | 453 } |
| 454 | 454 |
| 455 ScriptPromise Cache::deleteFunction(ScriptState* script_state, | 455 ScriptPromise Cache::deleteFunction(ScriptState* script_state, |
| 456 const RequestInfo& request, | 456 const RequestInfo& request, |
| 457 const CacheQueryOptions& options, | 457 const CacheQueryOptions& options, |
| 458 ExceptionState& exception_state) { | 458 ExceptionState& exception_state) { |
| 459 ASSERT(!request.isNull()); | 459 DCHECK(!request.isNull()); |
| 460 if (request.isRequest()) | 460 if (request.isRequest()) |
| 461 return DeleteImpl(script_state, request.getAsRequest(), options); | 461 return DeleteImpl(script_state, request.getAsRequest(), options); |
| 462 Request* new_request = | 462 Request* new_request = |
| 463 Request::Create(script_state, request.getAsUSVString(), exception_state); | 463 Request::Create(script_state, request.getAsUSVString(), exception_state); |
| 464 if (exception_state.HadException()) | 464 if (exception_state.HadException()) |
| 465 return ScriptPromise(); | 465 return ScriptPromise(); |
| 466 return DeleteImpl(script_state, new_request, options); | 466 return DeleteImpl(script_state, new_request, options); |
| 467 } | 467 } |
| 468 | 468 |
| 469 ScriptPromise Cache::put(ScriptState* script_state, | 469 ScriptPromise Cache::put(ScriptState* script_state, |
| 470 const RequestInfo& request, | 470 const RequestInfo& request, |
| 471 Response* response, | 471 Response* response, |
| 472 ExceptionState& exception_state) { | 472 ExceptionState& exception_state) { |
| 473 ASSERT(!request.isNull()); | 473 DCHECK(!request.isNull()); |
| 474 if (request.isRequest()) | 474 if (request.isRequest()) |
| 475 return PutImpl(script_state, | 475 return PutImpl(script_state, |
| 476 HeapVector<Member<Request>>(1, request.getAsRequest()), | 476 HeapVector<Member<Request>>(1, request.getAsRequest()), |
| 477 HeapVector<Member<Response>>(1, response)); | 477 HeapVector<Member<Response>>(1, response)); |
| 478 Request* new_request = | 478 Request* new_request = |
| 479 Request::Create(script_state, request.getAsUSVString(), exception_state); | 479 Request::Create(script_state, request.getAsUSVString(), exception_state); |
| 480 if (exception_state.HadException()) | 480 if (exception_state.HadException()) |
| 481 return ScriptPromise(); | 481 return ScriptPromise(); |
| 482 return PutImpl(script_state, HeapVector<Member<Request>>(1, new_request), | 482 return PutImpl(script_state, HeapVector<Member<Request>>(1, new_request), |
| 483 HeapVector<Member<Response>>(1, response)); | 483 HeapVector<Member<Response>>(1, response)); |
| 484 } | 484 } |
| 485 | 485 |
| 486 ScriptPromise Cache::keys(ScriptState* script_state, ExceptionState&) { | 486 ScriptPromise Cache::keys(ScriptState* script_state, ExceptionState&) { |
| 487 return KeysImpl(script_state); | 487 return KeysImpl(script_state); |
| 488 } | 488 } |
| 489 | 489 |
| 490 ScriptPromise Cache::keys(ScriptState* script_state, | 490 ScriptPromise Cache::keys(ScriptState* script_state, |
| 491 const RequestInfo& request, | 491 const RequestInfo& request, |
| 492 const CacheQueryOptions& options, | 492 const CacheQueryOptions& options, |
| 493 ExceptionState& exception_state) { | 493 ExceptionState& exception_state) { |
| 494 ASSERT(!request.isNull()); | 494 DCHECK(!request.isNull()); |
| 495 if (request.isRequest()) | 495 if (request.isRequest()) |
| 496 return KeysImpl(script_state, request.getAsRequest(), options); | 496 return KeysImpl(script_state, request.getAsRequest(), options); |
| 497 Request* new_request = | 497 Request* new_request = |
| 498 Request::Create(script_state, request.getAsUSVString(), exception_state); | 498 Request::Create(script_state, request.getAsUSVString(), exception_state); |
| 499 if (exception_state.HadException()) | 499 if (exception_state.HadException()) |
| 500 return ScriptPromise(); | 500 return ScriptPromise(); |
| 501 return KeysImpl(script_state, new_request, options); | 501 return KeysImpl(script_state, new_request, options); |
| 502 } | 502 } |
| 503 | 503 |
| 504 // static | 504 // static |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 630 if (!url.ProtocolIsInHTTPFamily()) { | 630 if (!url.ProtocolIsInHTTPFamily()) { |
| 631 barrier_callback->OnError("Request scheme '" + url.Protocol() + | 631 barrier_callback->OnError("Request scheme '" + url.Protocol() + |
| 632 "' is unsupported"); | 632 "' is unsupported"); |
| 633 return promise; | 633 return promise; |
| 634 } | 634 } |
| 635 if (requests[i]->method() != HTTPNames::GET) { | 635 if (requests[i]->method() != HTTPNames::GET) { |
| 636 barrier_callback->OnError("Request method '" + requests[i]->method() + | 636 barrier_callback->OnError("Request method '" + requests[i]->method() + |
| 637 "' is unsupported"); | 637 "' is unsupported"); |
| 638 return promise; | 638 return promise; |
| 639 } | 639 } |
| 640 ASSERT(!requests[i]->HasBody()); | 640 DCHECK(!requests[i]->HasBody()); |
| 641 | 641 |
| 642 if (VaryHeaderContainsAsterisk(responses[i])) { | 642 if (VaryHeaderContainsAsterisk(responses[i])) { |
| 643 barrier_callback->OnError("Vary header contains *"); | 643 barrier_callback->OnError("Vary header contains *"); |
| 644 return promise; | 644 return promise; |
| 645 } | 645 } |
| 646 if (responses[i]->status() == 206) { | 646 if (responses[i]->status() == 206) { |
| 647 barrier_callback->OnError( | 647 barrier_callback->OnError( |
| 648 "Partial response (status code 206) is unsupported"); | 648 "Partial response (status code 206) is unsupported"); |
| 649 return promise; | 649 return promise; |
| 650 } | 650 } |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 700 WTF::MakeUnique<CacheWithRequestsCallbacks>(resolver), web_request, | 700 WTF::MakeUnique<CacheWithRequestsCallbacks>(resolver), web_request, |
| 701 ToWebQueryParams(options)); | 701 ToWebQueryParams(options)); |
| 702 return promise; | 702 return promise; |
| 703 } | 703 } |
| 704 | 704 |
| 705 WebServiceWorkerCache* Cache::WebCache() const { | 705 WebServiceWorkerCache* Cache::WebCache() const { |
| 706 return web_cache_.get(); | 706 return web_cache_.get(); |
| 707 } | 707 } |
| 708 | 708 |
| 709 } // namespace blink | 709 } // namespace blink |
| OLD | NEW |