Commit 475c6e24 authored by Eriko Kurimoto's avatar Eriko Kurimoto Committed by Commit Bot

Return base::Optional<network::mojom::CredentialsMode> type in ParseCredentialsMode

Using base::Optional is modern format and it removes an unnecessary argument.
See the comment: https://chromium-review.googlesource.com/c/chromium/src/+/1990883/16/third_party/blink/renderer/core/script/script.cc#9
This change doesn't affect the behavior. Just for a cleanup.

Change-Id: Ie89f24d0089c90d59f64cd121fd7aa440d39af9d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1993073
Commit-Queue: Eriko Kurimoto <elkurin@google.com>
Reviewed-by: default avatarHiroki Nakagawa <nhiroki@chromium.org>
Cr-Commit-Position: refs/heads/master@{#731892}
parent 22ba3b50
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include "third_party/blink/renderer/core/fetch/request.h" #include "third_party/blink/renderer/core/fetch/request.h"
#include "base/optional.h"
#include "mojo/public/cpp/bindings/pending_remote.h" #include "mojo/public/cpp/bindings/pending_remote.h"
#include "services/network/public/cpp/request_destination.h" #include "services/network/public/cpp/request_destination.h"
#include "services/network/public/cpp/request_mode.h" #include "services/network/public/cpp/request_mode.h"
...@@ -417,9 +418,10 @@ Request* Request::CreateRequestWithRequestOrString( ...@@ -417,9 +418,10 @@ Request* Request::CreateRequestWithRequestOrString(
// "If |credentials| is non-null, set |request|'s credentials mode to // "If |credentials| is non-null, set |request|'s credentials mode to
// |credentials|." // |credentials|."
network::mojom::CredentialsMode credentials_mode; base::Optional<network::mojom::CredentialsMode> credentials_result =
if (ParseCredentialsMode(init->credentials(), &credentials_mode)) { ParseCredentialsMode(init->credentials());
request->SetCredentials(credentials_mode); if (credentials_result) {
request->SetCredentials(credentials_result.value());
} else if (!input_request) { } else if (!input_request) {
request->SetCredentials(network::mojom::CredentialsMode::kSameOrigin); request->SetCredentials(network::mojom::CredentialsMode::kSameOrigin);
} }
...@@ -651,21 +653,15 @@ Request* Request::Create( ...@@ -651,21 +653,15 @@ Request* Request::Create(
return MakeGarbageCollected<Request>(script_state, data); return MakeGarbageCollected<Request>(script_state, data);
} }
bool Request::ParseCredentialsMode(const String& credentials_mode, base::Optional<network::mojom::CredentialsMode> Request::ParseCredentialsMode(
network::mojom::CredentialsMode* result) { const String& credentials_mode) {
if (credentials_mode == "omit") { if (credentials_mode == "omit")
*result = network::mojom::CredentialsMode::kOmit; return network::mojom::CredentialsMode::kOmit;
return true; if (credentials_mode == "same-origin")
} return network::mojom::CredentialsMode::kSameOrigin;
if (credentials_mode == "same-origin") { if (credentials_mode == "include")
*result = network::mojom::CredentialsMode::kSameOrigin; return network::mojom::CredentialsMode::kInclude;
return true; return base::nullopt;
}
if (credentials_mode == "include") {
*result = network::mojom::CredentialsMode::kInclude;
return true;
}
return false;
} }
Request::Request(ScriptState* script_state, Request::Request(ScriptState* script_state,
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#ifndef THIRD_PARTY_BLINK_RENDERER_CORE_FETCH_REQUEST_H_ #ifndef THIRD_PARTY_BLINK_RENDERER_CORE_FETCH_REQUEST_H_
#define THIRD_PARTY_BLINK_RENDERER_CORE_FETCH_REQUEST_H_ #define THIRD_PARTY_BLINK_RENDERER_CORE_FETCH_REQUEST_H_
#include "base/optional.h"
#include "services/network/public/mojom/fetch_api.mojom-blink-forward.h" #include "services/network/public/mojom/fetch_api.mojom-blink-forward.h"
#include "third_party/blink/public/mojom/fetch/fetch_api_request.mojom-blink-forward.h" #include "third_party/blink/public/mojom/fetch/fetch_api_request.mojom-blink-forward.h"
#include "third_party/blink/public/platform/web_url_request.h" #include "third_party/blink/public/platform/web_url_request.h"
...@@ -61,10 +62,8 @@ class CORE_EXPORT Request final : public Body { ...@@ -61,10 +62,8 @@ class CORE_EXPORT Request final : public Body {
Request(ScriptState*, FetchRequestData*, Headers*, AbortSignal*); Request(ScriptState*, FetchRequestData*, Headers*, AbortSignal*);
Request(ScriptState*, FetchRequestData*); Request(ScriptState*, FetchRequestData*);
// Returns false if |credentials_mode| doesn't represent a valid credentials static base::Optional<network::mojom::CredentialsMode> ParseCredentialsMode(
// mode. const String& credentials_mode);
static bool ParseCredentialsMode(const String& credentials_mode,
network::mojom::CredentialsMode*);
// From Request.idl: // From Request.idl:
String method() const; String method() const;
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include <utility> #include <utility>
#include "base/feature_list.h" #include "base/feature_list.h"
#include "base/optional.h"
#include "mojo/public/cpp/bindings/pending_remote.h" #include "mojo/public/cpp/bindings/pending_remote.h"
#include "services/network/public/mojom/fetch_api.mojom-blink.h" #include "services/network/public/mojom/fetch_api.mojom-blink.h"
#include "third_party/blink/public/common/blob/blob_utils.h" #include "third_party/blink/public/common/blob/blob_utils.h"
...@@ -189,9 +190,10 @@ void DedicatedWorker::Start() { ...@@ -189,9 +190,10 @@ void DedicatedWorker::Start() {
// https://html.spec.whatwg.org/C/#workeroptions // https://html.spec.whatwg.org/C/#workeroptions
auto credentials_mode = network::mojom::CredentialsMode::kSameOrigin; auto credentials_mode = network::mojom::CredentialsMode::kSameOrigin;
if (options_->type() == "module") { if (options_->type() == "module") {
bool result = Request::ParseCredentialsMode(options_->credentials(), base::Optional<network::mojom::CredentialsMode> result =
&credentials_mode); Request::ParseCredentialsMode(options_->credentials());
DCHECK(result); DCHECK(result);
credentials_mode = result.value();
} }
mojo::PendingRemote<mojom::blink::BlobURLToken> blob_url_token; mojo::PendingRemote<mojom::blink::BlobURLToken> blob_url_token;
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include "third_party/blink/renderer/core/workers/dedicated_worker_messaging_proxy.h" #include "third_party/blink/renderer/core/workers/dedicated_worker_messaging_proxy.h"
#include <memory> #include <memory>
#include "base/optional.h"
#include "services/network/public/mojom/fetch_api.mojom-blink.h" #include "services/network/public/mojom/fetch_api.mojom-blink.h"
#include "third_party/blink/public/platform/task_type.h" #include "third_party/blink/public/platform/task_type.h"
#include "third_party/blink/renderer/bindings/core/v8/sanitize_script_errors.h" #include "third_party/blink/renderer/bindings/core/v8/sanitize_script_errors.h"
...@@ -90,16 +91,16 @@ void DedicatedWorkerMessagingProxy::StartWorkerGlobalScope( ...@@ -90,16 +91,16 @@ void DedicatedWorkerMessagingProxy::StartWorkerGlobalScope(
// settings." // settings."
UseCounter::Count(GetExecutionContext(), UseCounter::Count(GetExecutionContext(),
WebFeature::kModuleDedicatedWorker); WebFeature::kModuleDedicatedWorker);
network::mojom::CredentialsMode credentials_mode; base::Optional<network::mojom::CredentialsMode> credentials_mode =
bool result = Request::ParseCredentialsMode(options->credentials(), Request::ParseCredentialsMode(options->credentials());
&credentials_mode); DCHECK(credentials_mode);
DCHECK(result);
auto* resource_timing_notifier = auto* resource_timing_notifier =
WorkerResourceTimingNotifierImpl::CreateForOutsideResourceFetcher( WorkerResourceTimingNotifierImpl::CreateForOutsideResourceFetcher(
*GetExecutionContext()); *GetExecutionContext());
GetWorkerThread()->FetchAndRunModuleScript( GetWorkerThread()->FetchAndRunModuleScript(
script_url, outside_settings_object.CopyData(), script_url, outside_settings_object.CopyData(),
resource_timing_notifier, credentials_mode); resource_timing_notifier, *credentials_mode);
} else { } else {
NOTREACHED(); NOTREACHED();
} }
......
...@@ -45,7 +45,9 @@ ...@@ -45,7 +45,9 @@
#include "third_party/blink/public/web/blink.h" #include "third_party/blink/public/web/blink.h"
#include "third_party/blink/public/web/web_shared_worker.h" #include "third_party/blink/public/web/web_shared_worker.h"
#include "third_party/blink/renderer/core/execution_context/execution_context.h" #include "third_party/blink/renderer/core/execution_context/execution_context.h"
#include "third_party/blink/renderer/core/fetch/request.h"
#include "third_party/blink/renderer/core/frame/csp/content_security_policy.h" #include "third_party/blink/renderer/core/frame/csp/content_security_policy.h"
#include "third_party/blink/renderer/core/script/script.h"
#include "third_party/blink/renderer/core/workers/shared_worker.h" #include "third_party/blink/renderer/core/workers/shared_worker.h"
#include "third_party/blink/renderer/core/workers/shared_worker_client.h" #include "third_party/blink/renderer/core/workers/shared_worker_client.h"
#include "third_party/blink/renderer/platform/loader/fetch/fetch_client_settings_object_snapshot.h" #include "third_party/blink/renderer/platform/loader/fetch/fetch_client_settings_object_snapshot.h"
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include "third_party/blink/renderer/core/workers/worklet.h" #include "third_party/blink/renderer/core/workers/worklet.h"
#include "base/optional.h"
#include "base/single_thread_task_runner.h" #include "base/single_thread_task_runner.h"
#include "services/network/public/mojom/fetch_api.mojom-blink.h" #include "services/network/public/mojom/fetch_api.mojom-blink.h"
#include "third_party/blink/public/mojom/web_feature/web_feature.mojom-blink.h" #include "third_party/blink/public/mojom/web_feature/web_feature.mojom-blink.h"
...@@ -125,9 +126,9 @@ void Worklet::FetchAndInvokeScript(const KURL& module_url_record, ...@@ -125,9 +126,9 @@ void Worklet::FetchAndInvokeScript(const KURL& module_url_record,
return; return;
// Step 6: "Let credentialOptions be the credentials member of options." // Step 6: "Let credentialOptions be the credentials member of options."
network::mojom::CredentialsMode credentials_mode; base::Optional<network::mojom::CredentialsMode> credentials_mode =
bool result = Request::ParseCredentialsMode(credentials, &credentials_mode); Request::ParseCredentialsMode(credentials);
DCHECK(result); DCHECK(credentials_mode);
// Step 7: "Let outsideSettings be the relevant settings object of this." // Step 7: "Let outsideSettings be the relevant settings object of this."
auto* outside_settings_object = auto* outside_settings_object =
...@@ -175,7 +176,7 @@ void Worklet::FetchAndInvokeScript(const KURL& module_url_record, ...@@ -175,7 +176,7 @@ void Worklet::FetchAndInvokeScript(const KURL& module_url_record,
// moduleResponsesMap is already passed via CreateGlobalScope(). // moduleResponsesMap is already passed via CreateGlobalScope().
// TODO(nhiroki): Queue a task instead of executing this here. // TODO(nhiroki): Queue a task instead of executing this here.
for (const auto& proxy : proxies_) { for (const auto& proxy : proxies_) {
proxy->FetchAndInvokeScript(module_url_record, credentials_mode, proxy->FetchAndInvokeScript(module_url_record, *credentials_mode,
*outside_settings_object, *outside_settings_object,
*outside_resource_timing_notifier, *outside_resource_timing_notifier,
outside_settings_task_runner, pending_tasks); outside_settings_task_runner, pending_tasks);
......
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