Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(72)

Side by Side Diff: third_party/WebKit/Source/modules/fetch/Request.cpp

Issue 2816543002: Move ScriptState::GetExecutionContext (Part 5) (Closed)
Patch Set: Rebase Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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->SetAttachedCredential(original->AttachedCredential()); 49 request->SetAttachedCredential(original->AttachedCredential());
49 request->SetRedirect(original->Redirect()); 50 request->SetRedirect(original->Redirect());
50 request->SetIntegrity(original->Integrity()); 51 request->SetIntegrity(original->Integrity());
51 // FIXME: Set cache mode. 52 // FIXME: Set cache mode.
52 // TODO(yhirano): Set redirect mode. 53 // TODO(yhirano): Set redirect mode.
(...skipping 16 matching lines...) Expand all
69 } 70 }
70 // - "Let |temporaryBody| be |input|'s request's body if |input| is a 71 // - "Let |temporaryBody| be |input|'s request's body if |input| is a
71 // Request object, and null otherwise." 72 // Request object, and null otherwise."
72 BodyStreamBuffer* temporary_body = 73 BodyStreamBuffer* temporary_body =
73 input_request ? input_request->BodyBuffer() : nullptr; 74 input_request ? input_request->BodyBuffer() : nullptr;
74 75
75 // "Let |request| be |input|'s request, if |input| is a Request object, 76 // "Let |request| be |input|'s request, if |input| is a Request object,
76 // and a new request otherwise." 77 // and a new request otherwise."
77 78
78 RefPtr<SecurityOrigin> origin = 79 RefPtr<SecurityOrigin> origin =
79 script_state->GetExecutionContext()->GetSecurityOrigin(); 80 ExecutionContext::From(script_state)->GetSecurityOrigin();
80 81
81 // TODO(yhirano): Implement the following steps: 82 // TODO(yhirano): Implement the following steps:
82 // - "Let |window| be client." 83 // - "Let |window| be client."
83 // - "If |request|'s window is an environment settings object and its 84 // - "If |request|'s window is an environment settings object and its
84 // origin is same origin with entry settings object's origin, set 85 // origin is same origin with entry settings object's origin, set
85 // |window| to |request|'s window." 86 // |window| to |request|'s window."
86 // - "If |init|'s window member is present and it is not null, throw a 87 // - "If |init|'s window member is present and it is not null, throw a
87 // TypeError." 88 // TypeError."
88 // - "If |init|'s window member is present, set |window| to no-window." 89 // - "If |init|'s window member is present, set |window| to no-window."
89 // 90 //
(...skipping 13 matching lines...) Expand all
103 104
104 // We don't use fallback values. We set these flags directly in below. 105 // We don't use fallback values. We set these flags directly in below.
105 // - "Let |fallbackMode| be null." 106 // - "Let |fallbackMode| be null."
106 // - "Let |fallbackCredentials| be null." 107 // - "Let |fallbackCredentials| be null."
107 // - "Let |baseURL| be entry settings object's API base URL." 108 // - "Let |baseURL| be entry settings object's API base URL."
108 109
109 // "If |input| is a string, run these substeps:" 110 // "If |input| is a string, run these substeps:"
110 if (!input_request) { 111 if (!input_request) {
111 // "Let |parsedURL| be the result of parsing |input| with |baseURL|." 112 // "Let |parsedURL| be the result of parsing |input| with |baseURL|."
112 KURL parsed_url = 113 KURL parsed_url =
113 script_state->GetExecutionContext()->CompleteURL(input_string); 114 ExecutionContext::From(script_state)->CompleteURL(input_string);
114 // "If |parsedURL| is failure, throw a TypeError." 115 // "If |parsedURL| is failure, throw a TypeError."
115 if (!parsed_url.IsValid()) { 116 if (!parsed_url.IsValid()) {
116 exception_state.ThrowTypeError("Failed to parse URL from " + 117 exception_state.ThrowTypeError("Failed to parse URL from " +
117 input_string); 118 input_string);
118 return nullptr; 119 return nullptr;
119 } 120 }
120 // "If |parsedURL| includes credentials, throw a TypeError." 121 // "If |parsedURL| includes credentials, throw a TypeError."
121 if (!parsed_url.User().IsEmpty() || !parsed_url.Pass().IsEmpty()) { 122 if (!parsed_url.User().IsEmpty() || !parsed_url.Pass().IsEmpty()) {
122 exception_state.ThrowTypeError( 123 exception_state.ThrowTypeError(
123 "Request cannot be constructed from a URL that includes " 124 "Request cannot be constructed from a URL that includes "
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 // Nothing to do for the step "Let |referrer| be |init|'s referrer 173 // Nothing to do for the step "Let |referrer| be |init|'s referrer
173 // member." 174 // member."
174 175
175 if (init.referrer.referrer.IsEmpty()) { 176 if (init.referrer.referrer.IsEmpty()) {
176 // "If |referrer| is the empty string, set |request|'s referrer to 177 // "If |referrer| is the empty string, set |request|'s referrer to
177 // "no-referrer" and terminate these substeps." 178 // "no-referrer" and terminate these substeps."
178 request->SetReferrerString(AtomicString(Referrer::NoReferrer())); 179 request->SetReferrerString(AtomicString(Referrer::NoReferrer()));
179 } else { 180 } else {
180 // "Let |parsedReferrer| be the result of parsing |referrer| with 181 // "Let |parsedReferrer| be the result of parsing |referrer| with
181 // |baseURL|." 182 // |baseURL|."
182 KURL parsed_referrer = script_state->GetExecutionContext()->CompleteURL( 183 KURL parsed_referrer = ExecutionContext::From(script_state)
183 init.referrer.referrer); 184 ->CompleteURL(init.referrer.referrer);
184 if (!parsed_referrer.IsValid()) { 185 if (!parsed_referrer.IsValid()) {
185 // "If |parsedReferrer| is failure, throw a TypeError." 186 // "If |parsedReferrer| is failure, throw a TypeError."
186 exception_state.ThrowTypeError("Referrer '" + init.referrer.referrer + 187 exception_state.ThrowTypeError("Referrer '" + init.referrer.referrer +
187 "' is not a valid URL."); 188 "' is not a valid URL.");
188 return nullptr; 189 return nullptr;
189 } 190 }
190 if (parsed_referrer.ProtocolIsAbout() && 191 if (parsed_referrer.ProtocolIsAbout() &&
191 parsed_referrer.Host().IsEmpty() && 192 parsed_referrer.Host().IsEmpty() &&
192 parsed_referrer.GetPath() == "client") { 193 parsed_referrer.GetPath() == "client") {
193 // "If |parsedReferrer|'s non-relative flag is set, scheme is 194 // "If |parsedReferrer|'s non-relative flag is set, scheme is
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after
435 Request* Request::Create(ScriptState* script_state, 436 Request* Request::Create(ScriptState* script_state,
436 const String& input, 437 const String& input,
437 ExceptionState& exception_state) { 438 ExceptionState& exception_state) {
438 return Create(script_state, input, Dictionary(), exception_state); 439 return Create(script_state, input, Dictionary(), exception_state);
439 } 440 }
440 441
441 Request* Request::Create(ScriptState* script_state, 442 Request* Request::Create(ScriptState* script_state,
442 const String& input, 443 const String& input,
443 const Dictionary& init, 444 const Dictionary& init,
444 ExceptionState& exception_state) { 445 ExceptionState& exception_state) {
445 RequestInit request_init(script_state->GetExecutionContext(), init, 446 RequestInit request_init(ExecutionContext::From(script_state), init,
446 exception_state); 447 exception_state);
447 return CreateRequestWithRequestOrString(script_state, nullptr, input, 448 return CreateRequestWithRequestOrString(script_state, nullptr, input,
448 request_init, exception_state); 449 request_init, exception_state);
449 } 450 }
450 451
451 Request* Request::Create(ScriptState* script_state, 452 Request* Request::Create(ScriptState* script_state,
452 Request* input, 453 Request* input,
453 ExceptionState& exception_state) { 454 ExceptionState& exception_state) {
454 return Create(script_state, input, Dictionary(), exception_state); 455 return Create(script_state, input, Dictionary(), exception_state);
455 } 456 }
456 457
457 Request* Request::Create(ScriptState* script_state, 458 Request* Request::Create(ScriptState* script_state,
458 Request* input, 459 Request* input,
459 const Dictionary& init, 460 const Dictionary& init,
460 ExceptionState& exception_state) { 461 ExceptionState& exception_state) {
461 RequestInit request_init(script_state->GetExecutionContext(), init, 462 RequestInit request_init(ExecutionContext::From(script_state), init,
462 exception_state); 463 exception_state);
463 return CreateRequestWithRequestOrString(script_state, input, String(), 464 return CreateRequestWithRequestOrString(script_state, input, String(),
464 request_init, exception_state); 465 request_init, exception_state);
465 } 466 }
466 467
467 Request* Request::Create(ScriptState* script_state, FetchRequestData* request) { 468 Request* Request::Create(ScriptState* script_state, FetchRequestData* request) {
468 return new Request(script_state, request); 469 return new Request(script_state, request);
469 } 470 }
470 471
471 Request* Request::Create(ScriptState* script_state, 472 Request* Request::Create(ScriptState* script_state,
472 const WebServiceWorkerRequest& web_request) { 473 const WebServiceWorkerRequest& web_request) {
473 FetchRequestData* request = 474 FetchRequestData* request =
474 FetchRequestData::Create(script_state, web_request); 475 FetchRequestData::Create(script_state, web_request);
475 return new Request(script_state, request); 476 return new Request(script_state, request);
476 } 477 }
477 478
478 Request::Request(ScriptState* script_state, 479 Request::Request(ScriptState* script_state,
479 FetchRequestData* request, 480 FetchRequestData* request,
480 Headers* headers) 481 Headers* headers)
481 : Body(script_state->GetExecutionContext()), 482 : Body(ExecutionContext::From(script_state)),
482 request_(request), 483 request_(request),
483 headers_(headers) { 484 headers_(headers) {
484 RefreshBody(script_state); 485 RefreshBody(script_state);
485 } 486 }
486 487
487 Request::Request(ScriptState* script_state, FetchRequestData* request) 488 Request::Request(ScriptState* script_state, FetchRequestData* request)
488 : Request(script_state, request, Headers::Create(request->HeaderList())) { 489 : Request(script_state, request, Headers::Create(request->HeaderList())) {
489 headers_->SetGuard(Headers::kRequestGuard); 490 headers_->SetGuard(Headers::kRequestGuard);
490 } 491 }
491 492
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after
733 .Set(request.As<v8::Object>(), body_buffer); 734 .Set(request.As<v8::Object>(), body_buffer);
734 } 735 }
735 736
736 DEFINE_TRACE(Request) { 737 DEFINE_TRACE(Request) {
737 Body::Trace(visitor); 738 Body::Trace(visitor);
738 visitor->Trace(request_); 739 visitor->Trace(request_);
739 visitor->Trace(headers_); 740 visitor->Trace(headers_);
740 } 741 }
741 742
742 } // namespace blink 743 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/modules/fetch/FetchRequestData.cpp ('k') | third_party/WebKit/Source/modules/fetch/Response.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698