| 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 "bindings/core/v8/V8PrivateProperty.h" | 8 #include "bindings/core/v8/V8PrivateProperty.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 17 matching lines...) Expand all Loading... |
| 28 FetchRequestData* CreateCopyOfFetchRequestDataForFetch( | 28 FetchRequestData* CreateCopyOfFetchRequestDataForFetch( |
| 29 ScriptState* script_state, | 29 ScriptState* script_state, |
| 30 const FetchRequestData* original) { | 30 const FetchRequestData* original) { |
| 31 FetchRequestData* request = FetchRequestData::Create(); | 31 FetchRequestData* request = FetchRequestData::Create(); |
| 32 request->SetURL(original->Url()); | 32 request->SetURL(original->Url()); |
| 33 request->SetMethod(original->Method()); | 33 request->SetMethod(original->Method()); |
| 34 request->SetHeaderList(original->HeaderList()->Clone()); | 34 request->SetHeaderList(original->HeaderList()->Clone()); |
| 35 request->SetUnsafeRequestFlag(true); | 35 request->SetUnsafeRequestFlag(true); |
| 36 // FIXME: Set client. | 36 // FIXME: Set client. |
| 37 DOMWrapperWorld& world = script_state->World(); | 37 DOMWrapperWorld& world = script_state->World(); |
| 38 if (world.IsIsolatedWorld()) { | 38 if (world.IsIsolatedWorld()) |
| 39 request->SetOrigin(world.IsolatedWorldSecurityOrigin()); | 39 request->SetOrigin(world.IsolatedWorldSecurityOrigin()); |
| 40 } else { | 40 else |
| 41 request->SetOrigin( | 41 request->SetOrigin( |
| 42 ExecutionContext::From(script_state)->GetSecurityOrigin()); | 42 script_state->GetExecutionContext()->GetSecurityOrigin()); |
| 43 } | |
| 44 // FIXME: Set ForceOriginHeaderFlag. | 43 // FIXME: Set ForceOriginHeaderFlag. |
| 45 request->SetSameOriginDataURLFlag(true); | 44 request->SetSameOriginDataURLFlag(true); |
| 46 request->SetReferrer(original->GetReferrer()); | 45 request->SetReferrer(original->GetReferrer()); |
| 47 request->SetMode(original->Mode()); | 46 request->SetMode(original->Mode()); |
| 48 request->SetCredentials(original->Credentials()); | 47 request->SetCredentials(original->Credentials()); |
| 49 request->SetCacheMode(original->CacheMode()); | 48 request->SetCacheMode(original->CacheMode()); |
| 50 request->SetAttachedCredential(original->AttachedCredential()); | 49 request->SetAttachedCredential(original->AttachedCredential()); |
| 51 request->SetRedirect(original->Redirect()); | 50 request->SetRedirect(original->Redirect()); |
| 52 request->SetIntegrity(original->Integrity()); | 51 request->SetIntegrity(original->Integrity()); |
| 53 return request; | 52 return request; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 69 } | 68 } |
| 70 // - "Let |temporaryBody| be |input|'s request's body if |input| is a | 69 // - "Let |temporaryBody| be |input|'s request's body if |input| is a |
| 71 // Request object, and null otherwise." | 70 // Request object, and null otherwise." |
| 72 BodyStreamBuffer* temporary_body = | 71 BodyStreamBuffer* temporary_body = |
| 73 input_request ? input_request->BodyBuffer() : nullptr; | 72 input_request ? input_request->BodyBuffer() : nullptr; |
| 74 | 73 |
| 75 // "Let |request| be |input|'s request, if |input| is a Request object, | 74 // "Let |request| be |input|'s request, if |input| is a Request object, |
| 76 // and a new request otherwise." | 75 // and a new request otherwise." |
| 77 | 76 |
| 78 RefPtr<SecurityOrigin> origin = | 77 RefPtr<SecurityOrigin> origin = |
| 79 ExecutionContext::From(script_state)->GetSecurityOrigin(); | 78 script_state->GetExecutionContext()->GetSecurityOrigin(); |
| 80 | 79 |
| 81 // TODO(yhirano): Implement the following steps: | 80 // TODO(yhirano): Implement the following steps: |
| 82 // - "Let |window| be client." | 81 // - "Let |window| be client." |
| 83 // - "If |request|'s window is an environment settings object and its | 82 // - "If |request|'s window is an environment settings object and its |
| 84 // origin is same origin with entry settings object's origin, set | 83 // origin is same origin with entry settings object's origin, set |
| 85 // |window| to |request|'s window." | 84 // |window| to |request|'s window." |
| 86 // - "If |init|'s window member is present and it is not null, throw a | 85 // - "If |init|'s window member is present and it is not null, throw a |
| 87 // TypeError." | 86 // TypeError." |
| 88 // - "If |init|'s window member is present, set |window| to no-window." | 87 // - "If |init|'s window member is present, set |window| to no-window." |
| 89 // | 88 // |
| (...skipping 13 matching lines...) Expand all Loading... |
| 103 | 102 |
| 104 // We don't use fallback values. We set these flags directly in below. | 103 // We don't use fallback values. We set these flags directly in below. |
| 105 // - "Let |fallbackMode| be null." | 104 // - "Let |fallbackMode| be null." |
| 106 // - "Let |fallbackCredentials| be null." | 105 // - "Let |fallbackCredentials| be null." |
| 107 // - "Let |baseURL| be entry settings object's API base URL." | 106 // - "Let |baseURL| be entry settings object's API base URL." |
| 108 | 107 |
| 109 // "If |input| is a string, run these substeps:" | 108 // "If |input| is a string, run these substeps:" |
| 110 if (!input_request) { | 109 if (!input_request) { |
| 111 // "Let |parsedURL| be the result of parsing |input| with |baseURL|." | 110 // "Let |parsedURL| be the result of parsing |input| with |baseURL|." |
| 112 KURL parsed_url = | 111 KURL parsed_url = |
| 113 ExecutionContext::From(script_state)->CompleteURL(input_string); | 112 script_state->GetExecutionContext()->CompleteURL(input_string); |
| 114 // "If |parsedURL| is failure, throw a TypeError." | 113 // "If |parsedURL| is failure, throw a TypeError." |
| 115 if (!parsed_url.IsValid()) { | 114 if (!parsed_url.IsValid()) { |
| 116 exception_state.ThrowTypeError("Failed to parse URL from " + | 115 exception_state.ThrowTypeError("Failed to parse URL from " + |
| 117 input_string); | 116 input_string); |
| 118 return nullptr; | 117 return nullptr; |
| 119 } | 118 } |
| 120 // "If |parsedURL| includes credentials, throw a TypeError." | 119 // "If |parsedURL| includes credentials, throw a TypeError." |
| 121 if (!parsed_url.User().IsEmpty() || !parsed_url.Pass().IsEmpty()) { | 120 if (!parsed_url.User().IsEmpty() || !parsed_url.Pass().IsEmpty()) { |
| 122 exception_state.ThrowTypeError( | 121 exception_state.ThrowTypeError( |
| 123 "Request cannot be constructed from a URL that includes " | 122 "Request cannot be constructed from a URL that includes " |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 // Nothing to do for the step "Let |referrer| be |init|'s referrer | 171 // Nothing to do for the step "Let |referrer| be |init|'s referrer |
| 173 // member." | 172 // member." |
| 174 | 173 |
| 175 if (init.referrer.referrer.IsEmpty()) { | 174 if (init.referrer.referrer.IsEmpty()) { |
| 176 // "If |referrer| is the empty string, set |request|'s referrer to | 175 // "If |referrer| is the empty string, set |request|'s referrer to |
| 177 // "no-referrer" and terminate these substeps." | 176 // "no-referrer" and terminate these substeps." |
| 178 request->SetReferrerString(AtomicString(Referrer::NoReferrer())); | 177 request->SetReferrerString(AtomicString(Referrer::NoReferrer())); |
| 179 } else { | 178 } else { |
| 180 // "Let |parsedReferrer| be the result of parsing |referrer| with | 179 // "Let |parsedReferrer| be the result of parsing |referrer| with |
| 181 // |baseURL|." | 180 // |baseURL|." |
| 182 KURL parsed_referrer = ExecutionContext::From(script_state) | 181 KURL parsed_referrer = script_state->GetExecutionContext()->CompleteURL( |
| 183 ->CompleteURL(init.referrer.referrer); | 182 init.referrer.referrer); |
| 184 if (!parsed_referrer.IsValid()) { | 183 if (!parsed_referrer.IsValid()) { |
| 185 // "If |parsedReferrer| is failure, throw a TypeError." | 184 // "If |parsedReferrer| is failure, throw a TypeError." |
| 186 exception_state.ThrowTypeError("Referrer '" + init.referrer.referrer + | 185 exception_state.ThrowTypeError("Referrer '" + init.referrer.referrer + |
| 187 "' is not a valid URL."); | 186 "' is not a valid URL."); |
| 188 return nullptr; | 187 return nullptr; |
| 189 } | 188 } |
| 190 if (parsed_referrer.ProtocolIsAbout() && | 189 if (parsed_referrer.ProtocolIsAbout() && |
| 191 parsed_referrer.Host().IsEmpty() && | 190 parsed_referrer.Host().IsEmpty() && |
| 192 parsed_referrer.GetPath() == "client") { | 191 parsed_referrer.GetPath() == "client") { |
| 193 // "If |parsedReferrer|'s non-relative flag is set, scheme is | 192 // "If |parsedReferrer|'s non-relative flag is set, scheme is |
| (...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 446 Request* Request::Create(ScriptState* script_state, | 445 Request* Request::Create(ScriptState* script_state, |
| 447 const String& input, | 446 const String& input, |
| 448 ExceptionState& exception_state) { | 447 ExceptionState& exception_state) { |
| 449 return Create(script_state, input, Dictionary(), exception_state); | 448 return Create(script_state, input, Dictionary(), exception_state); |
| 450 } | 449 } |
| 451 | 450 |
| 452 Request* Request::Create(ScriptState* script_state, | 451 Request* Request::Create(ScriptState* script_state, |
| 453 const String& input, | 452 const String& input, |
| 454 const Dictionary& init, | 453 const Dictionary& init, |
| 455 ExceptionState& exception_state) { | 454 ExceptionState& exception_state) { |
| 456 RequestInit request_init(ExecutionContext::From(script_state), init, | 455 RequestInit request_init(script_state->GetExecutionContext(), init, |
| 457 exception_state); | 456 exception_state); |
| 458 return CreateRequestWithRequestOrString(script_state, nullptr, input, | 457 return CreateRequestWithRequestOrString(script_state, nullptr, input, |
| 459 request_init, exception_state); | 458 request_init, exception_state); |
| 460 } | 459 } |
| 461 | 460 |
| 462 Request* Request::Create(ScriptState* script_state, | 461 Request* Request::Create(ScriptState* script_state, |
| 463 Request* input, | 462 Request* input, |
| 464 ExceptionState& exception_state) { | 463 ExceptionState& exception_state) { |
| 465 return Create(script_state, input, Dictionary(), exception_state); | 464 return Create(script_state, input, Dictionary(), exception_state); |
| 466 } | 465 } |
| 467 | 466 |
| 468 Request* Request::Create(ScriptState* script_state, | 467 Request* Request::Create(ScriptState* script_state, |
| 469 Request* input, | 468 Request* input, |
| 470 const Dictionary& init, | 469 const Dictionary& init, |
| 471 ExceptionState& exception_state) { | 470 ExceptionState& exception_state) { |
| 472 RequestInit request_init(ExecutionContext::From(script_state), init, | 471 RequestInit request_init(script_state->GetExecutionContext(), init, |
| 473 exception_state); | 472 exception_state); |
| 474 return CreateRequestWithRequestOrString(script_state, input, String(), | 473 return CreateRequestWithRequestOrString(script_state, input, String(), |
| 475 request_init, exception_state); | 474 request_init, exception_state); |
| 476 } | 475 } |
| 477 | 476 |
| 478 Request* Request::Create(ScriptState* script_state, FetchRequestData* request) { | 477 Request* Request::Create(ScriptState* script_state, FetchRequestData* request) { |
| 479 return new Request(script_state, request); | 478 return new Request(script_state, request); |
| 480 } | 479 } |
| 481 | 480 |
| 482 Request* Request::Create(ScriptState* script_state, | 481 Request* Request::Create(ScriptState* script_state, |
| 483 const WebServiceWorkerRequest& web_request) { | 482 const WebServiceWorkerRequest& web_request) { |
| 484 FetchRequestData* request = | 483 FetchRequestData* request = |
| 485 FetchRequestData::Create(script_state, web_request); | 484 FetchRequestData::Create(script_state, web_request); |
| 486 return new Request(script_state, request); | 485 return new Request(script_state, request); |
| 487 } | 486 } |
| 488 | 487 |
| 489 Request::Request(ScriptState* script_state, | 488 Request::Request(ScriptState* script_state, |
| 490 FetchRequestData* request, | 489 FetchRequestData* request, |
| 491 Headers* headers) | 490 Headers* headers) |
| 492 : Body(ExecutionContext::From(script_state)), | 491 : Body(script_state->GetExecutionContext()), |
| 493 request_(request), | 492 request_(request), |
| 494 headers_(headers) { | 493 headers_(headers) { |
| 495 RefreshBody(script_state); | 494 RefreshBody(script_state); |
| 496 } | 495 } |
| 497 | 496 |
| 498 Request::Request(ScriptState* script_state, FetchRequestData* request) | 497 Request::Request(ScriptState* script_state, FetchRequestData* request) |
| 499 : Request(script_state, request, Headers::Create(request->HeaderList())) { | 498 : Request(script_state, request, Headers::Create(request->HeaderList())) { |
| 500 headers_->SetGuard(Headers::kRequestGuard); | 499 headers_->SetGuard(Headers::kRequestGuard); |
| 501 } | 500 } |
| 502 | 501 |
| (...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 764 .Set(request.As<v8::Object>(), body_buffer); | 763 .Set(request.As<v8::Object>(), body_buffer); |
| 765 } | 764 } |
| 766 | 765 |
| 767 DEFINE_TRACE(Request) { | 766 DEFINE_TRACE(Request) { |
| 768 Body::Trace(visitor); | 767 Body::Trace(visitor); |
| 769 visitor->Trace(request_); | 768 visitor->Trace(request_); |
| 770 visitor->Trace(headers_); | 769 visitor->Trace(headers_); |
| 771 } | 770 } |
| 772 | 771 |
| 773 } // namespace blink | 772 } // namespace blink |
| OLD | NEW |