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/fetch/Request.h" | 6 #include "modules/fetch/Request.h" |
7 | 7 |
8 #include "bindings/core/v8/Dictionary.h" | 8 #include "bindings/core/v8/Dictionary.h" |
9 #include "core/dom/Document.h" | 9 #include "core/dom/Document.h" |
10 #include "core/dom/ExecutionContext.h" | 10 #include "core/dom/ExecutionContext.h" |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 exceptionState.throwTypeError("Cannot construct a Request with a Req
uest object that has already been used."); | 67 exceptionState.throwTypeError("Cannot construct a Request with a Req
uest object that has already been used."); |
68 return nullptr; | 68 return nullptr; |
69 } | 69 } |
70 if (inputRequest->isBodyConsumed()) { | 70 if (inputRequest->isBodyConsumed()) { |
71 // Currently the only methods that can consume body data without | 71 // Currently the only methods that can consume body data without |
72 // setting 'body passed' flag consume entire body (e.g. text()). | 72 // setting 'body passed' flag consume entire body (e.g. text()). |
73 // Thus we can set an empty blob to the new request instead of | 73 // Thus we can set an empty blob to the new request instead of |
74 // creating a draining stream. | 74 // creating a draining stream. |
75 // TODO(yhirano): Fix this once Request.body is introduced. | 75 // TODO(yhirano): Fix this once Request.body is introduced. |
76 OwnPtr<BlobData> blobData = BlobData::create(); | 76 OwnPtr<BlobData> blobData = BlobData::create(); |
77 blobData->setContentType(inputRequest->blobDataHandle()->type()); | 77 blobData->setContentType(inputRequest->m_request->blobDataHandle()->
type()); |
78 temporaryBody = BlobDataHandle::create(blobData.release(), 0); | 78 temporaryBody = BlobDataHandle::create(blobData.release(), 0); |
79 } else { | 79 } else { |
80 temporaryBody = inputRequest->m_request->blobDataHandle(); | 80 temporaryBody = inputRequest->m_request->blobDataHandle(); |
81 } | 81 } |
82 } | 82 } |
83 | 83 |
84 // "3. Let |request| be |input|'s request, if |input| is a Request object, | 84 // "3. Let |request| be |input|'s request, if |input| is a Request object, |
85 // and a new request otherwise." | 85 // and a new request otherwise." |
86 // "4. Set |request| to a new request whose url is |request|'s url, method | 86 // "4. Set |request| to a new request whose url is |request|'s url, method |
87 // is |request|'s method, header list is a copy of |request|'s header list, | 87 // is |request|'s method, header list is a copy of |request|'s header list, |
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
313 | 313 |
314 Request* Request::create(ExecutionContext* context, const WebServiceWorkerReques
t& webRequest) | 314 Request* Request::create(ExecutionContext* context, const WebServiceWorkerReques
t& webRequest) |
315 { | 315 { |
316 Request* r = new Request(context, webRequest); | 316 Request* r = new Request(context, webRequest); |
317 r->suspendIfNeeded(); | 317 r->suspendIfNeeded(); |
318 return r; | 318 return r; |
319 } | 319 } |
320 | 320 |
321 Request::Request(ExecutionContext* context, const WebServiceWorkerRequest& webRe
quest) | 321 Request::Request(ExecutionContext* context, const WebServiceWorkerRequest& webRe
quest) |
322 : Body(context) | 322 : Body(context) |
323 , m_request(FetchRequestData::create(webRequest)) | 323 , m_request(FetchRequestData::create(context, webRequest)) |
324 , m_headers(Headers::create(m_request->headerList())) | 324 , m_headers(Headers::create(m_request->headerList())) |
325 { | 325 { |
326 m_headers->setGuard(Headers::RequestGuard); | 326 m_headers->setGuard(Headers::RequestGuard); |
327 } | 327 } |
328 | 328 |
329 String Request::method() const | 329 String Request::method() const |
330 { | 330 { |
331 // "The method attribute's getter must return request's method." | 331 // "The method attribute's getter must return request's method." |
332 return m_request->method(); | 332 return m_request->method(); |
333 } | 333 } |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
465 return ""; | 465 return ""; |
466 } | 466 } |
467 | 467 |
468 Request* Request::clone(ExceptionState& exceptionState) const | 468 Request* Request::clone(ExceptionState& exceptionState) const |
469 { | 469 { |
470 if (bodyUsed()) { | 470 if (bodyUsed()) { |
471 exceptionState.throwTypeError("Request body is already used"); | 471 exceptionState.throwTypeError("Request body is already used"); |
472 return nullptr; | 472 return nullptr; |
473 } | 473 } |
474 | 474 |
475 FetchRequestData* request = m_request->clone(); | 475 FetchRequestData* request = m_request->clone(executionContext()); |
476 if (blobDataHandle() && isBodyConsumed()) { | 476 if (m_request->blobDataHandle() && isBodyConsumed()) { |
477 // Currently the only methods that can consume body data without | 477 // Currently the only methods that can consume body data without |
478 // setting 'body passed' flag consume entire body (e.g. text()). Thus | 478 // setting 'body passed' flag consume entire body (e.g. text()). Thus |
479 // we can set an empty blob to the new request instead of creating a | 479 // we can set an empty blob to the new request instead of creating a |
480 // draining stream. | 480 // draining stream. |
481 // TODO(yhirano): Fix this once Request.body is introduced. | 481 // TODO(yhirano): Fix this once Request.body is introduced. |
482 OwnPtr<BlobData> blobData = BlobData::create(); | 482 OwnPtr<BlobData> blobData = BlobData::create(); |
483 blobData->setContentType(blobDataHandle()->type()); | 483 blobData->setContentType(m_request->blobDataHandle()->type()); |
484 request->setBlobDataHandle(BlobDataHandle::create(blobData.release(), 0)
); | 484 request->setBlobDataHandle(executionContext(), BlobDataHandle::create(bl
obData.release(), 0)); |
485 } | 485 } |
486 | 486 |
487 Headers* headers = Headers::create(request->headerList()); | 487 Headers* headers = Headers::create(request->headerList()); |
488 headers->setGuard(m_headers->guard()); | 488 headers->setGuard(m_headers->guard()); |
489 Request* r = new Request(executionContext(), request, headers); | 489 Request* r = new Request(executionContext(), request, headers); |
490 r->suspendIfNeeded(); | 490 r->suspendIfNeeded(); |
491 return r; | 491 return r; |
492 } | 492 } |
493 | 493 |
494 FetchRequestData* Request::passRequestData() | 494 FetchRequestData* Request::passRequestData() |
495 { | 495 { |
496 ASSERT(!bodyUsed()); | 496 ASSERT(!bodyUsed()); |
497 lockBody(PassBody); | 497 lockBody(PassBody); |
498 return m_request->pass(); | 498 return m_request->pass(executionContext()); |
499 } | 499 } |
500 | 500 |
501 void Request::populateWebServiceWorkerRequest(WebServiceWorkerRequest& webReques
t) const | 501 void Request::populateWebServiceWorkerRequest(WebServiceWorkerRequest& webReques
t) const |
502 { | 502 { |
503 webRequest.setMethod(method()); | 503 webRequest.setMethod(method()); |
504 webRequest.setRequestContext(m_request->context()); | 504 webRequest.setRequestContext(m_request->context()); |
505 // This strips off the fragment part. | 505 // This strips off the fragment part. |
506 webRequest.setURL(url()); | 506 webRequest.setURL(url()); |
507 | 507 |
508 const FetchHeaderList* headerList = m_headers->headerList(); | 508 const FetchHeaderList* headerList = m_headers->headerList(); |
509 for (size_t i = 0, size = headerList->size(); i < size; ++i) { | 509 for (size_t i = 0, size = headerList->size(); i < size; ++i) { |
510 const FetchHeaderList::Header& header = headerList->entry(i); | 510 const FetchHeaderList::Header& header = headerList->entry(i); |
511 webRequest.appendHeader(header.first, header.second); | 511 webRequest.appendHeader(header.first, header.second); |
512 } | 512 } |
513 | 513 |
514 webRequest.setReferrer(m_request->referrer().referrer().referrer, static_cas
t<WebReferrerPolicy>(m_request->referrer().referrer().referrerPolicy)); | 514 webRequest.setReferrer(m_request->referrer().referrer().referrer, static_cas
t<WebReferrerPolicy>(m_request->referrer().referrer().referrerPolicy)); |
515 // FIXME: How can we set isReload properly? What is the correct place to loa
d it in to the Request object? We should investigate the right way | 515 // FIXME: How can we set isReload properly? What is the correct place to loa
d it in to the Request object? We should investigate the right way |
516 // to plumb this information in to here. | 516 // to plumb this information in to here. |
517 } | 517 } |
518 | 518 |
519 void Request::setBodyBlobHandle(PassRefPtr<BlobDataHandle> blobDataHandle) | 519 void Request::setBodyBlobHandle(PassRefPtr<BlobDataHandle> blobDataHandle) |
520 { | 520 { |
521 m_request->setBlobDataHandle(blobDataHandle); | 521 m_request->setBlobDataHandle(executionContext(), blobDataHandle); |
522 setBody(m_request->blobDataHandle()); | 522 setBody(m_request->buffer()); |
523 } | 523 } |
524 | 524 |
525 void Request::clearHeaderList() | 525 void Request::clearHeaderList() |
526 { | 526 { |
527 m_request->headerList()->clearList(); | 527 m_request->headerList()->clearList(); |
528 } | 528 } |
529 | 529 |
530 PassRefPtr<BlobDataHandle> Request::blobDataHandle() const | 530 BodyStreamBuffer2* Request::buffer() const |
531 { | 531 { |
532 return m_request->blobDataHandle(); | 532 return m_request->buffer(); |
533 } | |
534 | |
535 BodyStreamBuffer* Request::buffer() const | |
536 { | |
537 // We don't support BodyStreamBuffer for Request yet. | |
538 return nullptr; | |
539 } | 533 } |
540 | 534 |
541 String Request::mimeType() const | 535 String Request::mimeType() const |
542 { | 536 { |
543 return m_request->mimeType(); | 537 return m_request->mimeType(); |
544 } | 538 } |
545 | 539 |
546 DEFINE_TRACE(Request) | 540 DEFINE_TRACE(Request) |
547 { | 541 { |
548 Body::trace(visitor); | 542 Body::trace(visitor); |
549 visitor->trace(m_request); | 543 visitor->trace(m_request); |
550 visitor->trace(m_headers); | 544 visitor->trace(m_headers); |
551 } | 545 } |
552 | 546 |
553 } // namespace blink | 547 } // namespace blink |
OLD | NEW |