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/fetch/Request.h" | 5 #include "modules/fetch/Request.h" |
6 | 6 |
7 #include "bindings/core/v8/Dictionary.h" | 7 #include "bindings/core/v8/Dictionary.h" |
8 #include "core/dom/Document.h" | 8 #include "core/dom/Document.h" |
9 #include "core/dom/ExecutionContext.h" | 9 #include "core/dom/ExecutionContext.h" |
10 #include "core/fetch/FetchUtils.h" | 10 #include "core/fetch/FetchUtils.h" |
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
261 if (FetchUtils::isForbiddenMethod(init.method)) { | 261 if (FetchUtils::isForbiddenMethod(init.method)) { |
262 exceptionState.throwTypeError("'" + init.method + "' HTTP method is unsupported."); | 262 exceptionState.throwTypeError("'" + init.method + "' HTTP method is unsupported."); |
263 return nullptr; | 263 return nullptr; |
264 } | 264 } |
265 // "Normalize |method|." | 265 // "Normalize |method|." |
266 // "Set |request|'s method to |method|." | 266 // "Set |request|'s method to |method|." |
267 request->setMethod(FetchUtils::normalizeMethod(AtomicString(init.method) )); | 267 request->setMethod(FetchUtils::normalizeMethod(AtomicString(init.method) )); |
268 } | 268 } |
269 // "Let |r| be a new Request object associated with |request| and a new | 269 // "Let |r| be a new Request object associated with |request| and a new |
270 // Headers object whose guard is "request"." | 270 // Headers object whose guard is "request"." |
271 Request* r = Request::create(scriptState->getExecutionContext(), request); | 271 Request* r = Request::create(scriptState, request); |
272 // Perform the following steps: | 272 // Perform the following steps: |
273 // - "Let |headers| be a copy of |r|'s Headers object." | 273 // - "Let |headers| be a copy of |r|'s Headers object." |
274 // - "If |init|'s headers member is present, set |headers| to |init|'s | 274 // - "If |init|'s headers member is present, set |headers| to |init|'s |
275 // headers member." | 275 // headers member." |
276 // | 276 // |
277 // We don't create a copy of r's Headers object when init's headers member | 277 // We don't create a copy of r's Headers object when init's headers member |
278 // is present. | 278 // is present. |
279 Headers* headers = nullptr; | 279 Headers* headers = nullptr; |
280 if (!init.headers && init.headersDictionary.isUndefinedOrNull()) { | 280 if (!init.headers && init.headersDictionary.isUndefinedOrNull()) { |
281 headers = r->getHeaders()->clone(); | 281 headers = r->getHeaders()->clone(); |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
336 // "If |init|'s body member is present, run these substeps:" | 336 // "If |init|'s body member is present, run these substeps:" |
337 if (init.body) { | 337 if (init.body) { |
338 // Perform the following steps: | 338 // Perform the following steps: |
339 // - "Let |stream| and |Content-Type| be the result of extracting | 339 // - "Let |stream| and |Content-Type| be the result of extracting |
340 // |init|'s body member." | 340 // |init|'s body member." |
341 // - "Set |temporaryBody| to |stream|. | 341 // - "Set |temporaryBody| to |stream|. |
342 // - "If |Content-Type| is non-null and |r|'s request's header list | 342 // - "If |Content-Type| is non-null and |r|'s request's header list |
343 // contains no header named `Content-Type`, append | 343 // contains no header named `Content-Type`, append |
344 // `Content-Type`/|Content-Type| to |r|'s Headers object. Rethrow any | 344 // `Content-Type`/|Content-Type| to |r|'s Headers object. Rethrow any |
345 // exception." | 345 // exception." |
346 temporaryBody = new BodyStreamBuffer(init.body.release()); | 346 temporaryBody = new BodyStreamBuffer(scriptState, init.body.release()); |
347 if (!init.contentType.isEmpty() && !r->getHeaders()->has(HTTPNames::Cont ent_Type, exceptionState)) { | 347 if (!init.contentType.isEmpty() && !r->getHeaders()->has(HTTPNames::Cont ent_Type, exceptionState)) { |
348 r->getHeaders()->append(HTTPNames::Content_Type, init.contentType, e xceptionState); | 348 r->getHeaders()->append(HTTPNames::Content_Type, init.contentType, e xceptionState); |
349 } | 349 } |
350 if (exceptionState.hadException()) | 350 if (exceptionState.hadException()) |
351 return nullptr; | 351 return nullptr; |
352 } | 352 } |
353 | 353 |
354 // "Set |r|'s request's body to |temporaryBody|. | 354 // "Set |r|'s request's body to |temporaryBody|. |
355 if (temporaryBody) | 355 if (temporaryBody) |
356 r->m_request->setBuffer(temporaryBody); | 356 r->m_request->setBuffer(temporaryBody); |
357 | 357 |
358 // "Set |r|'s MIME type to the result of extracting a MIME type from |r|'s | 358 // "Set |r|'s MIME type to the result of extracting a MIME type from |r|'s |
359 // request's header list." | 359 // request's header list." |
360 r->m_request->setMIMEType(r->m_request->headerList()->extractMIMEType()); | 360 r->m_request->setMIMEType(r->m_request->headerList()->extractMIMEType()); |
361 | 361 |
362 // "If |input| is a Request object and |input|'s request's body is | 362 // "If |input| is a Request object and |input|'s request's body is |
363 // non-null, run these substeps:" | 363 // non-null, run these substeps:" |
364 if (inputRequest && inputRequest->bodyBuffer()) { | 364 if (inputRequest && inputRequest->bodyBuffer()) { |
365 // "Set |input|'s body to an empty byte stream." | 365 // "Set |input|'s body to an empty byte stream." |
366 inputRequest->m_request->setBuffer(new BodyStreamBuffer(createFetchDataC onsumerHandleFromWebHandle(createDoneDataConsumerHandle()))); | 366 inputRequest->m_request->setBuffer(new BodyStreamBuffer(scriptState, cre ateFetchDataConsumerHandleFromWebHandle(createDoneDataConsumerHandle()))); |
367 // "Set |input|'s disturbed flag." | 367 // "Set |input|'s disturbed flag." |
368 inputRequest->bodyBuffer()->stream()->setIsDisturbed(); | 368 inputRequest->bodyBuffer()->setDisturbed(); |
369 } | 369 } |
370 | 370 |
371 // "Return |r|." | 371 // "Return |r|." |
372 return r; | 372 return r; |
373 } | 373 } |
374 | 374 |
375 Request* Request::create(ScriptState* scriptState, const RequestInfo& input, con st Dictionary& init, ExceptionState& exceptionState) | 375 Request* Request::create(ScriptState* scriptState, const RequestInfo& input, con st Dictionary& init, ExceptionState& exceptionState) |
376 { | 376 { |
377 ASSERT(!input.isNull()); | 377 ASSERT(!input.isNull()); |
378 if (input.isUSVString()) | 378 if (input.isUSVString()) |
(...skipping 16 matching lines...) Expand all Loading... | |
395 { | 395 { |
396 return create(scriptState, input, Dictionary(), exceptionState); | 396 return create(scriptState, input, Dictionary(), exceptionState); |
397 } | 397 } |
398 | 398 |
399 Request* Request::create(ScriptState* scriptState, Request* input, const Diction ary& init, ExceptionState& exceptionState) | 399 Request* Request::create(ScriptState* scriptState, Request* input, const Diction ary& init, ExceptionState& exceptionState) |
400 { | 400 { |
401 RequestInit requestInit(scriptState->getExecutionContext(), init, exceptionS tate); | 401 RequestInit requestInit(scriptState->getExecutionContext(), init, exceptionS tate); |
402 return createRequestWithRequestOrString(scriptState, input, String(), reques tInit, exceptionState); | 402 return createRequestWithRequestOrString(scriptState, input, String(), reques tInit, exceptionState); |
403 } | 403 } |
404 | 404 |
405 Request* Request::create(ExecutionContext* context, FetchRequestData* request) | 405 Request* Request::create(ScriptState* scriptState, FetchRequestData* request) |
406 { | 406 { |
407 return new Request(context, request); | 407 return new Request(scriptState, request); |
408 } | 408 } |
409 | 409 |
410 Request::Request(ExecutionContext* context, FetchRequestData* request) | 410 Request* Request::create(ScriptState* scriptState, const WebServiceWorkerRequest & webRequest) |
411 : Body(context) | 411 { |
412 , m_request(request) | 412 return new Request(scriptState, webRequest); |
413 , m_headers(Headers::create(m_request->headerList())) | 413 } |
414 | |
415 Request::Request(ScriptState* scriptState, FetchRequestData* request) | |
416 : Request(scriptState, request, Headers::create(request->headerList())) | |
414 { | 417 { |
415 m_headers->setGuard(Headers::RequestGuard); | 418 m_headers->setGuard(Headers::RequestGuard); |
416 } | 419 } |
417 | 420 |
418 Request::Request(ExecutionContext* context, FetchRequestData* request, Headers* headers) | 421 Request::Request(ScriptState* scriptState, FetchRequestData* request, Headers* h eaders) |
419 : Body(context) , m_request(request) , m_headers(headers) {} | 422 : Body(scriptState->getExecutionContext()) |
420 | 423 , m_request(request) |
421 Request* Request::create(ExecutionContext* context, const WebServiceWorkerReques t& webRequest) | 424 , m_headers(headers) |
422 { | 425 { |
423 return new Request(context, webRequest); | |
424 } | 426 } |
425 | 427 |
426 Request::Request(ExecutionContext* context, const WebServiceWorkerRequest& webRe quest) | 428 Request::Request(ScriptState* scriptState, const WebServiceWorkerRequest& webReq uest) |
427 : Body(context) | 429 : Request(scriptState, FetchRequestData::create(scriptState, webRequest)) |
428 , m_request(FetchRequestData::create(context, webRequest)) | |
429 , m_headers(Headers::create(m_request->headerList())) | |
430 { | 430 { |
431 m_headers->setGuard(Headers::RequestGuard); | 431 m_headers->setGuard(Headers::RequestGuard); |
tyoshino (SeeGerritForStatus)
2016/04/21 07:46:24
this will be invoked again in Request(ScriptState,
yhirano
2016/04/21 08:14:22
Done.
| |
432 } | 432 } |
433 | 433 |
434 String Request::method() const | 434 String Request::method() const |
435 { | 435 { |
436 // "The method attribute's getter must return request's method." | 436 // "The method attribute's getter must return request's method." |
437 return m_request->method(); | 437 return m_request->method(); |
438 } | 438 } |
439 | 439 |
440 KURL Request::url() const | 440 KURL Request::url() const |
441 { | 441 { |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
585 } | 585 } |
586 ASSERT_NOT_REACHED(); | 586 ASSERT_NOT_REACHED(); |
587 return ""; | 587 return ""; |
588 } | 588 } |
589 | 589 |
590 String Request::integrity() const | 590 String Request::integrity() const |
591 { | 591 { |
592 return m_request->integrity(); | 592 return m_request->integrity(); |
593 } | 593 } |
594 | 594 |
595 Request* Request::clone(ExceptionState& exceptionState) | 595 Request* Request::clone(ScriptState* scriptState, ExceptionState& exceptionState ) |
596 { | 596 { |
597 if (isBodyLocked() || bodyUsed()) { | 597 if (isBodyLocked() || bodyUsed()) { |
598 exceptionState.throwTypeError("Request body is already used"); | 598 exceptionState.throwTypeError("Request body is already used"); |
599 return nullptr; | 599 return nullptr; |
600 } | 600 } |
601 | 601 |
602 FetchRequestData* request = m_request->clone(getExecutionContext()); | 602 FetchRequestData* request = m_request->clone(scriptState); |
603 Headers* headers = Headers::create(request->headerList()); | 603 Headers* headers = Headers::create(request->headerList()); |
604 headers->setGuard(m_headers->getGuard()); | 604 headers->setGuard(m_headers->getGuard()); |
605 return new Request(getExecutionContext(), request, headers); | 605 return new Request(scriptState, request, headers); |
606 } | 606 } |
607 | 607 |
608 FetchRequestData* Request::passRequestData() | 608 FetchRequestData* Request::passRequestData(ScriptState* scriptState) |
609 { | 609 { |
610 ASSERT(!bodyUsed()); | 610 ASSERT(!bodyUsed()); |
611 return m_request->pass(getExecutionContext()); | 611 return m_request->pass(scriptState); |
612 } | 612 } |
613 | 613 |
614 bool Request::hasBody() const | 614 bool Request::hasBody() const |
615 { | 615 { |
616 return bodyBuffer(); | 616 return bodyBuffer(); |
617 } | 617 } |
618 | 618 |
619 void Request::stop() | 619 void Request::stop() |
620 { | 620 { |
621 if (bodyBuffer()) | 621 if (bodyBuffer()) |
(...skipping 24 matching lines...) Expand all Loading... | |
646 } | 646 } |
647 | 647 |
648 DEFINE_TRACE(Request) | 648 DEFINE_TRACE(Request) |
649 { | 649 { |
650 Body::trace(visitor); | 650 Body::trace(visitor); |
651 visitor->trace(m_request); | 651 visitor->trace(m_request); |
652 visitor->trace(m_headers); | 652 visitor->trace(m_headers); |
653 } | 653 } |
654 | 654 |
655 } // namespace blink | 655 } // namespace blink |
OLD | NEW |