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