| 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 24 matching lines...) Expand all Loading... |
| 35 DOMWrapperWorld& world = scriptState->world(); | 35 DOMWrapperWorld& world = scriptState->world(); |
| 36 if (world.isIsolatedWorld()) | 36 if (world.isIsolatedWorld()) |
| 37 request->setOrigin(world.isolatedWorldSecurityOrigin()); | 37 request->setOrigin(world.isolatedWorldSecurityOrigin()); |
| 38 else | 38 else |
| 39 request->setOrigin(scriptState->getExecutionContext()->getSecurityOrigin
()); | 39 request->setOrigin(scriptState->getExecutionContext()->getSecurityOrigin
()); |
| 40 // FIXME: Set ForceOriginHeaderFlag. | 40 // FIXME: Set ForceOriginHeaderFlag. |
| 41 request->setSameOriginDataURLFlag(true); | 41 request->setSameOriginDataURLFlag(true); |
| 42 request->setReferrer(original->referrer()); | 42 request->setReferrer(original->referrer()); |
| 43 request->setMode(original->mode()); | 43 request->setMode(original->mode()); |
| 44 request->setCredentials(original->credentials()); | 44 request->setCredentials(original->credentials()); |
| 45 request->setAttachedCredential(original->attachedCredential()); |
| 45 request->setRedirect(original->redirect()); | 46 request->setRedirect(original->redirect()); |
| 46 request->setIntegrity(original->integrity()); | 47 request->setIntegrity(original->integrity()); |
| 47 // FIXME: Set cache mode. | 48 // FIXME: Set cache mode. |
| 48 // TODO(yhirano): Set redirect mode. | 49 // TODO(yhirano): Set redirect mode. |
| 49 return request; | 50 return request; |
| 50 } | 51 } |
| 51 | 52 |
| 52 Request* Request::createRequestWithRequestOrString(ScriptState* scriptState, Req
uest* inputRequest, const String& inputString, RequestInit& init, ExceptionState
& exceptionState) | 53 Request* Request::createRequestWithRequestOrString(ScriptState* scriptState, Req
uest* inputRequest, const String& inputString, RequestInit& init, ExceptionState
& exceptionState) |
| 53 { | 54 { |
| 54 // - "If |input| is a Request object and it is disturbed, throw a | 55 // - "If |input| is a Request object and it is disturbed, throw a |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 209 // "Let |credentials| be |init|'s credentials member if it is present, and | 210 // "Let |credentials| be |init|'s credentials member if it is present, and |
| 210 // |fallbackCredentials| otherwise." | 211 // |fallbackCredentials| otherwise." |
| 211 // "If |credentials| is non-null, set |request|'s credentials mode to | 212 // "If |credentials| is non-null, set |request|'s credentials mode to |
| 212 // |credentials|." | 213 // |credentials|." |
| 213 if (init.credentials == "omit") { | 214 if (init.credentials == "omit") { |
| 214 request->setCredentials(WebURLRequest::FetchCredentialsModeOmit); | 215 request->setCredentials(WebURLRequest::FetchCredentialsModeOmit); |
| 215 } else if (init.credentials == "same-origin") { | 216 } else if (init.credentials == "same-origin") { |
| 216 request->setCredentials(WebURLRequest::FetchCredentialsModeSameOrigin); | 217 request->setCredentials(WebURLRequest::FetchCredentialsModeSameOrigin); |
| 217 } else if (init.credentials == "include") { | 218 } else if (init.credentials == "include") { |
| 218 request->setCredentials(WebURLRequest::FetchCredentialsModeInclude); | 219 request->setCredentials(WebURLRequest::FetchCredentialsModeInclude); |
| 220 } else if (init.credentials == "password") { |
| 221 if (!init.attachedCredential.get()) { |
| 222 exceptionState.throwTypeError("Cannot construct a Request with a cre
dential mode of 'password' without a PasswordCredential."); |
| 223 return nullptr; |
| 224 } |
| 225 request->setCredentials(WebURLRequest::FetchCredentialsModePassword); |
| 226 request->setAttachedCredential(init.attachedCredential); |
| 227 request->setRedirect(WebURLRequest::FetchRedirectModeManual); |
| 219 } else { | 228 } else { |
| 220 if (!inputRequest) | 229 if (!inputRequest) |
| 221 request->setCredentials(WebURLRequest::FetchCredentialsModeOmit); | 230 request->setCredentials(WebURLRequest::FetchCredentialsModeOmit); |
| 222 } | 231 } |
| 223 | 232 |
| 224 // TODO(yhirano): Implement the following step: | 233 // TODO(yhirano): Implement the following step: |
| 225 // "If |init|'s cache member is present, set |request|'s cache mode to | 234 // "If |init|'s cache member is present, set |request|'s cache mode to |
| 226 // it." | 235 // it." |
| 227 | 236 |
| 228 // "If |init|'s redirect member is present, set |request|'s redirect mode | 237 // "If |init|'s redirect member is present, set |request|'s redirect mode |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 298 r->getHeaders()->fillWith(init.headersDictionary, exceptionState); | 307 r->getHeaders()->fillWith(init.headersDictionary, exceptionState); |
| 299 } else { | 308 } else { |
| 300 ASSERT(headers); | 309 ASSERT(headers); |
| 301 r->getHeaders()->fillWith(headers, exceptionState); | 310 r->getHeaders()->fillWith(headers, exceptionState); |
| 302 } | 311 } |
| 303 if (exceptionState.hadException()) | 312 if (exceptionState.hadException()) |
| 304 return nullptr; | 313 return nullptr; |
| 305 | 314 |
| 306 // "If either |init|'s body member is present or |temporaryBody| is | 315 // "If either |init|'s body member is present or |temporaryBody| is |
| 307 // non-null, and |request|'s method is `GET` or `HEAD`, throw a TypeError. | 316 // non-null, and |request|'s method is `GET` or `HEAD`, throw a TypeError. |
| 308 if (init.body || temporaryBody) { | 317 if (init.body || temporaryBody || request->credentials() == WebURLRequest::F
etchCredentialsModePassword) { |
| 309 if (request->method() == HTTPNames::GET || request->method() == HTTPName
s::HEAD) { | 318 if (request->method() == HTTPNames::GET || request->method() == HTTPName
s::HEAD) { |
| 310 exceptionState.throwTypeError("Request with GET/HEAD method cannot h
ave body."); | 319 exceptionState.throwTypeError("Request with GET/HEAD method cannot h
ave body."); |
| 311 return nullptr; | 320 return nullptr; |
| 312 } | 321 } |
| 313 } | 322 } |
| 314 | 323 |
| 324 // TODO(mkwst): See the comment in RequestInit about serializing the attache
d credential |
| 325 // prior to hitting the Service Worker machinery. |
| 326 if (request->credentials() == WebURLRequest::FetchCredentialsModePassword) { |
| 327 r->getHeaders()->append(HTTPNames::Content_Type, init.contentType, excep
tionState); |
| 328 |
| 329 // TODO(mkwst): This should be a registrable-domain match. |
| 330 if (!origin->canRequest(r->url())) { |
| 331 exceptionState.throwTypeError("Credentials may only be submitted to
same-origin endpoints."); |
| 332 return nullptr; |
| 333 } |
| 334 } |
| 335 |
| 315 // "If |init|'s body member is present, run these substeps:" | 336 // "If |init|'s body member is present, run these substeps:" |
| 316 if (init.body) { | 337 if (init.body) { |
| 317 // Perform the following steps: | 338 // Perform the following steps: |
| 318 // - "Let |stream| and |Content-Type| be the result of extracting | 339 // - "Let |stream| and |Content-Type| be the result of extracting |
| 319 // |init|'s body member." | 340 // |init|'s body member." |
| 320 // - "Set |temporaryBody| to |stream|. | 341 // - "Set |temporaryBody| to |stream|. |
| 321 // - "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 |
| 322 // contains no header named `Content-Type`, append | 343 // contains no header named `Content-Type`, append |
| 323 // `Content-Type`/|Content-Type| to |r|'s Headers object. Rethrow any | 344 // `Content-Type`/|Content-Type| to |r|'s Headers object. Rethrow any |
| 324 // exception." | 345 // exception." |
| 325 temporaryBody = new BodyStreamBuffer(init.body.release()); | 346 temporaryBody = new BodyStreamBuffer(init.body.release()); |
| 326 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)) { |
| 327 r->getHeaders()->append(HTTPNames::Content_Type, init.contentType, e
xceptionState); | 348 r->getHeaders()->append(HTTPNames::Content_Type, init.contentType, e
xceptionState); |
| 328 } | 349 } |
| 329 if (exceptionState.hadException()) | 350 if (exceptionState.hadException()) |
| 330 return nullptr; | 351 return nullptr; |
| 331 } | 352 } |
| 332 | 353 |
| 333 // "Set |r|'s request's body to |temporaryBody|. | 354 // "Set |r|'s request's body to |temporaryBody|. |
| 334 if (temporaryBody) | 355 if (temporaryBody) |
| 335 r->m_request->setBuffer(temporaryBody); | 356 r->m_request->setBuffer(temporaryBody); |
| 336 | 357 |
| 337 // https://w3c.github.io/webappsec-credential-management/#monkey-patching-fe
tch-3 | |
| 338 // "If |init|'s body member is a 'Credential' object:" | |
| 339 if (init.isCredentialRequest) { | |
| 340 // "1. If |r|'s url is not the same as |r|'s client’s origin, throw a Ty
peError." | |
| 341 if (!origin->canRequest(r->url())) { | |
| 342 exceptionState.throwTypeError("Credentials may only be submitted to
same-origin endpoints."); | |
| 343 return nullptr; | |
| 344 } | |
| 345 // "2. Set |r|'s redirect mode to "error"." | |
| 346 r->m_request->setRedirect(WebURLRequest::FetchRedirectModeError); | |
| 347 // "3. Set |r|'s skip-service-worker flag." | |
| 348 // TODO(mkwst): Set this flag. | |
| 349 // "4. Set |r|'s opaque flag." | |
| 350 r->setOpaque(); | |
| 351 } | |
| 352 | |
| 353 // "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 |
| 354 // request's header list." | 359 // request's header list." |
| 355 r->m_request->setMIMEType(r->m_request->headerList()->extractMIMEType()); | 360 r->m_request->setMIMEType(r->m_request->headerList()->extractMIMEType()); |
| 356 | 361 |
| 357 // "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 |
| 358 // non-null, run these substeps:" | 363 // non-null, run these substeps:" |
| 359 if (inputRequest && inputRequest->bodyBuffer()) { | 364 if (inputRequest && inputRequest->bodyBuffer()) { |
| 360 // "Set |input|'s body to an empty byte stream." | 365 // "Set |input|'s body to an empty byte stream." |
| 361 inputRequest->m_request->setBuffer(new BodyStreamBuffer(createFetchDataC
onsumerHandleFromWebHandle(createDoneDataConsumerHandle()))); | 366 inputRequest->m_request->setBuffer(new BodyStreamBuffer(createFetchDataC
onsumerHandleFromWebHandle(createDoneDataConsumerHandle()))); |
| 362 // "Set |input|'s disturbed flag." | 367 // "Set |input|'s disturbed flag." |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 553 // "The credentials attribute's getter must return the value corresponding | 558 // "The credentials attribute's getter must return the value corresponding |
| 554 // to the first matching statement, switching on request's credentials | 559 // to the first matching statement, switching on request's credentials |
| 555 // mode:" | 560 // mode:" |
| 556 switch (m_request->credentials()) { | 561 switch (m_request->credentials()) { |
| 557 case WebURLRequest::FetchCredentialsModeOmit: | 562 case WebURLRequest::FetchCredentialsModeOmit: |
| 558 return "omit"; | 563 return "omit"; |
| 559 case WebURLRequest::FetchCredentialsModeSameOrigin: | 564 case WebURLRequest::FetchCredentialsModeSameOrigin: |
| 560 return "same-origin"; | 565 return "same-origin"; |
| 561 case WebURLRequest::FetchCredentialsModeInclude: | 566 case WebURLRequest::FetchCredentialsModeInclude: |
| 562 return "include"; | 567 return "include"; |
| 568 case WebURLRequest::FetchCredentialsModePassword: |
| 569 return "password"; |
| 563 } | 570 } |
| 564 ASSERT_NOT_REACHED(); | 571 ASSERT_NOT_REACHED(); |
| 565 return ""; | 572 return ""; |
| 566 } | 573 } |
| 567 | 574 |
| 568 String Request::redirect() const | 575 String Request::redirect() const |
| 569 { | 576 { |
| 570 // "The redirect attribute's getter must return request's redirect mode." | 577 // "The redirect attribute's getter must return request's redirect mode." |
| 571 switch (m_request->redirect()) { | 578 switch (m_request->redirect()) { |
| 572 case WebURLRequest::FetchRedirectModeFollow: | 579 case WebURLRequest::FetchRedirectModeFollow: |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 639 } | 646 } |
| 640 | 647 |
| 641 DEFINE_TRACE(Request) | 648 DEFINE_TRACE(Request) |
| 642 { | 649 { |
| 643 Body::trace(visitor); | 650 Body::trace(visitor); |
| 644 visitor->trace(m_request); | 651 visitor->trace(m_request); |
| 645 visitor->trace(m_headers); | 652 visitor->trace(m_headers); |
| 646 } | 653 } |
| 647 | 654 |
| 648 } // namespace blink | 655 } // namespace blink |
| OLD | NEW |