Commit 4fb331ac authored by Dominic Farolino's avatar Dominic Farolino Committed by Commit Bot

Move RequestInit constructor logic to Request

Before this CL we have some Request constructor logic in our
implementation of RequestInit. Once we generate RequestInit with the IDL
compiler, that logic will have to be inlined back into the Request
constructor. This CL moves that logic, revolving around the referrer
property, back to the Request constructor to minimize the size of the
CL that removes our implementation of RequestInit.

R=kinuko@chromium.org, kouhei@chromium.org, yhirano@chromium.org, yoav@yoav.ws

Bug: 836873
Change-Id: Id351d9503ead1ef4e377fa0bd1cc5eaac70cfbed
Reviewed-on: https://chromium-review.googlesource.com/1103786
Commit-Queue: Dominic Farolino <domfarolino@gmail.com>
Reviewed-by: default avatarKinuko Yasuda <kinuko@chromium.org>
Reviewed-by: default avatarYoav Weiss <yoav@yoav.ws>
Cr-Commit-Position: refs/heads/master@{#569721}
parent 11b1eb7d
...@@ -260,43 +260,29 @@ Request* Request::CreateRequestWithRequestOrString( ...@@ -260,43 +260,29 @@ Request* Request::CreateRequestWithRequestOrString(
// "Unset |request|'s history-navigation flag." // "Unset |request|'s history-navigation flag."
request->SetIsHistoryNavigation(false); request->SetIsHistoryNavigation(false);
// The substep "Set |request|'s referrer to "client"." is performed by // "Set |request|’s referrer to "client"."
// the code below as follows: request->SetReferrerString(FetchRequestData::ClientReferrerString());
// - |init.referrer.referrer| gets initialized by the RequestInit
// constructor to "about:client" when any of |options|'s members are // "Set |request|’s referrer policy to the empty string."
// present. request->SetReferrerPolicy(kReferrerPolicyDefault);
// - The code below does the equivalent as the step specified in the }
// spec by processing the "about:client".
// "If init’s referrer member is present, then:"
// The substep "Set |request|'s referrer policy to the empty string." if (!init.Referrer().IsNull()) {
// is also performed by the code below similarly.
}
// The following if-clause performs the following two steps:
// - "If |init|'s referrer member is present, run these substeps:"
// "If |init|'s referrerPolicy member is present, set |request|'s
// referrer policy to it."
//
// The condition "if any of |init|'s members are present"
// (areAnyMembersSet) is used for the if-clause instead of conditions
// indicating presence of each member as specified in the spec. This is to
// perform the substeps in the previous step together here.
if (init.AreAnyMembersSet()) {
// Nothing to do for the step "Let |referrer| be |init|'s referrer // Nothing to do for the step "Let |referrer| be |init|'s referrer
// member." // member."
if (init.GetReferrer().referrer.IsEmpty()) { if (init.Referrer().IsEmpty()) {
// "If |referrer| is the empty string, set |request|'s referrer to // "If |referrer| is the empty string, set |request|'s referrer to
// "no-referrer" and terminate these substeps." // "no-referrer" and terminate these substeps."
request->SetReferrerString(AtomicString(Referrer::NoReferrer())); request->SetReferrerString(AtomicString(Referrer::NoReferrer()));
} else { } else {
// "Let |parsedReferrer| be the result of parsing |referrer| with // "Let |parsedReferrer| be the result of parsing |referrer| with
// |baseURL|." // |baseURL|."
KURL parsed_referrer(base_url, init.GetReferrer().referrer); KURL parsed_referrer(base_url, init.Referrer());
if (!parsed_referrer.IsValid()) { if (!parsed_referrer.IsValid()) {
// "If |parsedReferrer| is failure, throw a TypeError." // "If |parsedReferrer| is failure, throw a TypeError."
exception_state.ThrowTypeError("Referrer '" + exception_state.ThrowTypeError("Referrer '" + init.Referrer() +
init.GetReferrer().referrer +
"' is not a valid URL."); "' is not a valid URL.");
return nullptr; return nullptr;
} }
...@@ -322,9 +308,13 @@ Request* Request::CreateRequestWithRequestOrString( ...@@ -322,9 +308,13 @@ Request* Request::CreateRequestWithRequestOrString(
request->SetReferrerString(AtomicString(parsed_referrer.GetString())); request->SetReferrerString(AtomicString(parsed_referrer.GetString()));
} }
} }
request->SetReferrerPolicy(init.GetReferrer().referrer_policy);
} }
// "If init's referrerPolicy member is present, set request's referrer
// policy to it."
if (init.GetReferrerPolicy().has_value())
request->SetReferrerPolicy(init.GetReferrerPolicy().value());
// The following code performs the following steps: // The following code performs the following steps:
// - "Let |mode| be |init|'s mode member if it is present, and // - "Let |mode| be |init|'s mode member if it is present, and
// |fallbackMode| otherwise." // |fallbackMode| otherwise."
......
...@@ -80,7 +80,7 @@ RequestInit::RequestInit(ScriptState* script_state, ...@@ -80,7 +80,7 @@ RequestInit::RequestInit(ScriptState* script_state,
if (exception_state.HadException()) if (exception_state.HadException())
return; return;
auto referrer_string = h.Get<IDLUSVString>("referrer"); referrer_ = h.Get<IDLUSVString>("referrer").value_or(String());
if (exception_state.HadException()) if (exception_state.HadException())
return; return;
...@@ -120,7 +120,7 @@ RequestInit::RequestInit(ScriptState* script_state, ...@@ -120,7 +120,7 @@ RequestInit::RequestInit(ScriptState* script_state,
are_any_members_set_ = h.AreAnyMembersSet(); are_any_members_set_ = h.AreAnyMembersSet();
CheckEnumValues(referrer_string, referrer_policy_string, exception_state); CheckEnumValues(referrer_policy_string, exception_state);
if (exception_state.HadException()) if (exception_state.HadException())
return; return;
...@@ -156,7 +156,6 @@ base::Optional<AbortSignal*> RequestInit::Signal() const { ...@@ -156,7 +156,6 @@ base::Optional<AbortSignal*> RequestInit::Signal() const {
} }
void RequestInit::CheckEnumValues( void RequestInit::CheckEnumValues(
const base::Optional<String>& referrer_string,
const base::Optional<String>& referrer_policy_string, const base::Optional<String>& referrer_policy_string,
ExceptionState& exception_state) { ExceptionState& exception_state) {
TRACE_EVENT0("blink", "RequestInit::CheckEnumValues"); TRACE_EVENT0("blink", "RequestInit::CheckEnumValues");
...@@ -198,36 +197,25 @@ void RequestInit::CheckEnumValues( ...@@ -198,36 +197,25 @@ void RequestInit::CheckEnumValues(
} }
// Validate referrer policy // Validate referrer policy
// A part of the Request constructor algorithm is performed here. See
// the comments in the Request constructor code for the detail.
// We need to use "about:client" instead of |clientReferrerString|,
// because "about:client" => |clientReferrerString| conversion is done
// in Request::createRequestWithRequestOrString.
referrer_ = Referrer("about:client", kReferrerPolicyDefault);
if (referrer_string.has_value())
referrer_.referrer = AtomicString(*referrer_string);
if (referrer_policy_string.has_value()) { if (referrer_policy_string.has_value()) {
if (*referrer_policy_string == "") { if (*referrer_policy_string == "") {
referrer_.referrer_policy = kReferrerPolicyDefault; referrer_policy_ = kReferrerPolicyDefault;
} else if (*referrer_policy_string == "no-referrer") { } else if (*referrer_policy_string == "no-referrer") {
referrer_.referrer_policy = kReferrerPolicyNever; referrer_policy_ = kReferrerPolicyNever;
} else if (*referrer_policy_string == "no-referrer-when-downgrade") { } else if (*referrer_policy_string == "no-referrer-when-downgrade") {
referrer_.referrer_policy = kReferrerPolicyNoReferrerWhenDowngrade; referrer_policy_ = kReferrerPolicyNoReferrerWhenDowngrade;
} else if (*referrer_policy_string == "origin") { } else if (*referrer_policy_string == "origin") {
referrer_.referrer_policy = kReferrerPolicyOrigin; referrer_policy_ = kReferrerPolicyOrigin;
} else if (*referrer_policy_string == "origin-when-cross-origin") { } else if (*referrer_policy_string == "origin-when-cross-origin") {
referrer_.referrer_policy = kReferrerPolicyOriginWhenCrossOrigin; referrer_policy_ = kReferrerPolicyOriginWhenCrossOrigin;
} else if (*referrer_policy_string == "same-origin") { } else if (*referrer_policy_string == "same-origin") {
referrer_.referrer_policy = kReferrerPolicySameOrigin; referrer_policy_ = kReferrerPolicySameOrigin;
} else if (*referrer_policy_string == "strict-origin") { } else if (*referrer_policy_string == "strict-origin") {
referrer_.referrer_policy = kReferrerPolicyStrictOrigin; referrer_policy_ = kReferrerPolicyStrictOrigin;
} else if (*referrer_policy_string == "unsafe-url") { } else if (*referrer_policy_string == "unsafe-url") {
referrer_.referrer_policy = kReferrerPolicyAlways; referrer_policy_ = kReferrerPolicyAlways;
} else if (*referrer_policy_string == "strict-origin-when-cross-origin") { } else if (*referrer_policy_string == "strict-origin-when-cross-origin") {
referrer_.referrer_policy = kReferrerPolicyStrictOriginWhenCrossOrigin; referrer_policy_ = kReferrerPolicyStrictOriginWhenCrossOrigin;
} else { } else {
exception_state.ThrowTypeError("Invalid referrer policy"); exception_state.ThrowTypeError("Invalid referrer policy");
return; return;
......
...@@ -31,7 +31,10 @@ class RequestInit { ...@@ -31,7 +31,10 @@ class RequestInit {
const String& Method() const { return method_; } const String& Method() const { return method_; }
const HeadersInit& GetHeaders() const { return headers_; } const HeadersInit& GetHeaders() const { return headers_; }
ScriptValue GetBody() const { return body_; } ScriptValue GetBody() const { return body_; }
const Referrer& GetReferrer() const { return referrer_; } const String& Referrer() const { return referrer_; }
base::Optional<ReferrerPolicy> GetReferrerPolicy() const {
return referrer_policy_;
}
const String& Mode() const { return mode_; } const String& Mode() const { return mode_; }
const String& Credentials() const { return credentials_; } const String& Credentials() const { return credentials_; }
const String& CacheMode() const { return cache_; } const String& CacheMode() const { return cache_; }
...@@ -49,8 +52,7 @@ class RequestInit { ...@@ -49,8 +52,7 @@ class RequestInit {
friend struct NativeValueTraits<IDLPassThrough>; friend struct NativeValueTraits<IDLPassThrough>;
friend struct NativeValueTraitsBase<IDLPassThrough>; friend struct NativeValueTraitsBase<IDLPassThrough>;
void CheckEnumValues(const base::Optional<String>& referrer_string, void CheckEnumValues(const base::Optional<String>& referrer_policy_string,
const base::Optional<String>& referrer_policy_string,
ExceptionState&); ExceptionState&);
void SetUpBody(ExecutionContext*, void SetUpBody(ExecutionContext*,
v8::Isolate*, v8::Isolate*,
...@@ -62,7 +64,8 @@ class RequestInit { ...@@ -62,7 +64,8 @@ class RequestInit {
// Having a ScriptValue is safe here because this struct is STACK_ALLOCATED // Having a ScriptValue is safe here because this struct is STACK_ALLOCATED
// and not intended to live long. // and not intended to live long.
ScriptValue body_; ScriptValue body_;
Referrer referrer_; String referrer_;
base::Optional<ReferrerPolicy> referrer_policy_;
String mode_; String mode_;
String credentials_; String credentials_;
String cache_; String cache_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment