Commit 1f69cbbc authored by Eriko Kurimoto's avatar Eriko Kurimoto Committed by Commit Bot

Added mojom::blink::WorkerOptions in mojom::blink::SharedWorkerInfo

In this CL, existing argument |name| is replaced by WorkerOptions#name.
Other fields in WorkerOptions (#type and #credentials) are not used yet.
It doesn't change any behavior.

Bug: 824646
Change-Id: Iabdf68cbbd5d64389d85cef3c692d68d8134091f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1990883
Commit-Queue: Eriko Kurimoto <elkurin@google.com>
Reviewed-by: default avatarKinuko Yasuda <kinuko@chromium.org>
Reviewed-by: default avatarKouhei Ueno <kouhei@chromium.org>
Reviewed-by: default avatarHiroki Nakagawa <nhiroki@chromium.org>
Reviewed-by: default avatarMatt Falkenhagen <falken@chromium.org>
Cr-Commit-Position: refs/heads/master@{#731872}
parent c71f37ec
...@@ -81,7 +81,7 @@ bool MockSharedWorkerFactory::CheckReceivedCreateSharedWorker( ...@@ -81,7 +81,7 @@ bool MockSharedWorkerFactory::CheckReceivedCreateSharedWorker(
return false; return false;
if (!CheckEquality(expected_url, create_params->info->url)) if (!CheckEquality(expected_url, create_params->info->url))
return false; return false;
if (!CheckEquality(expected_name, create_params->info->name)) if (!CheckEquality(expected_name, create_params->info->options->name))
return false; return false;
if (!CheckEquality(expected_content_security_policy_type, if (!CheckEquality(expected_content_security_policy_type,
create_params->info->content_security_policy_type)) create_params->info->content_security_policy_type))
......
...@@ -143,8 +143,12 @@ void SharedWorkerHost::Start( ...@@ -143,8 +143,12 @@ void SharedWorkerHost::Start(
started_ = true; started_ = true;
// TODO(https://crbug.com/824646): options->type and options->credentials are
// temporarily using default values, but should be set by instance_.
auto options = blink::mojom::WorkerOptions::New();
options->name = instance_.name();
blink::mojom::SharedWorkerInfoPtr info(blink::mojom::SharedWorkerInfo::New( blink::mojom::SharedWorkerInfoPtr info(blink::mojom::SharedWorkerInfo::New(
instance_.url(), instance_.name(), instance_.content_security_policy(), instance_.url(), std::move(options), instance_.content_security_policy(),
instance_.content_security_policy_type(), instance_.content_security_policy_type(),
instance_.creation_address_space())); instance_.creation_address_space()));
......
...@@ -133,7 +133,8 @@ void SharedWorkerServiceImpl::ConnectToWorker( ...@@ -133,7 +133,8 @@ void SharedWorkerServiceImpl::ConnectToWorker(
if (!GetContentClient()->browser()->AllowSharedWorker( if (!GetContentClient()->browser()->AllowSharedWorker(
info->url, info->url,
render_frame_host->ComputeSiteForCookies().RepresentativeUrl(), render_frame_host->ComputeSiteForCookies().RepresentativeUrl(),
main_frame->GetLastCommittedOrigin(), info->name, constructor_origin, main_frame->GetLastCommittedOrigin(), info->options->name,
constructor_origin,
WebContentsImpl::FromRenderFrameHostID(client_render_frame_host_id) WebContentsImpl::FromRenderFrameHostID(client_render_frame_host_id)
->GetBrowserContext(), ->GetBrowserContext(),
client_render_frame_host_id.child_id, client_render_frame_host_id.child_id,
...@@ -142,8 +143,8 @@ void SharedWorkerServiceImpl::ConnectToWorker( ...@@ -142,8 +143,8 @@ void SharedWorkerServiceImpl::ConnectToWorker(
return; return;
} }
SharedWorkerHost* host = SharedWorkerHost* host = FindMatchingSharedWorkerHost(
FindMatchingSharedWorkerHost(info->url, info->name, constructor_origin); info->url, info->options->name, constructor_origin);
if (host) { if (host) {
// Non-secure contexts cannot connect to secure workers, and secure contexts // Non-secure contexts cannot connect to secure workers, and secure contexts
// cannot connect to non-secure workers: // cannot connect to non-secure workers:
...@@ -173,7 +174,7 @@ void SharedWorkerServiceImpl::ConnectToWorker( ...@@ -173,7 +174,7 @@ void SharedWorkerServiceImpl::ConnectToWorker(
/*can_be_default=*/true, &storage_domain, &partition_name, &in_memory); /*can_be_default=*/true, &storage_domain, &partition_name, &in_memory);
SharedWorkerInstance instance( SharedWorkerInstance instance(
next_shared_worker_instance_id_++, info->url, info->name, next_shared_worker_instance_id_++, info->url, info->options->name,
constructor_origin, info->content_security_policy, constructor_origin, info->content_security_policy,
info->content_security_policy_type, info->creation_address_space, info->content_security_policy_type, info->creation_address_space,
creation_context_type); creation_context_type);
......
...@@ -49,8 +49,10 @@ void ConnectToSharedWorker( ...@@ -49,8 +49,10 @@ void ConnectToSharedWorker(
const std::string& name, const std::string& name,
MockSharedWorkerClient* client, MockSharedWorkerClient* client,
MessagePortChannel* local_port) { MessagePortChannel* local_port) {
auto options = blink::mojom::WorkerOptions::New();
options->name = name;
blink::mojom::SharedWorkerInfoPtr info(blink::mojom::SharedWorkerInfo::New( blink::mojom::SharedWorkerInfoPtr info(blink::mojom::SharedWorkerInfo::New(
url, name, std::string(), url, std::move(options), std::string(),
network::mojom::ContentSecurityPolicyType::kReport, network::mojom::ContentSecurityPolicyType::kReport,
network::mojom::IPAddressSpace::kPublic)); network::mojom::IPAddressSpace::kPublic));
......
...@@ -99,7 +99,7 @@ EmbeddedSharedWorkerStub::EmbeddedSharedWorkerStub( ...@@ -99,7 +99,7 @@ EmbeddedSharedWorkerStub::EmbeddedSharedWorkerStub(
impl_ = blink::WebSharedWorker::Create(this); impl_ = blink::WebSharedWorker::Create(this);
impl_->StartWorkerContext( impl_->StartWorkerContext(
url_, blink::WebString::FromUTF8(info->name), url_, blink::WebString::FromUTF8(info->options->name),
blink::WebString::FromUTF8(user_agent), blink::WebString::FromUTF8(user_agent),
blink::WebString::FromUTF8(info->content_security_policy), blink::WebString::FromUTF8(info->content_security_policy),
info->content_security_policy_type, info->creation_address_space, info->content_security_policy_type, info->creation_address_space,
......
...@@ -154,6 +154,7 @@ mojom("mojom_platform") { ...@@ -154,6 +154,7 @@ mojom("mojom_platform") {
"worker/subresource_loader_updater.mojom", "worker/subresource_loader_updater.mojom",
"worker/worker_content_settings_proxy.mojom", "worker/worker_content_settings_proxy.mojom",
"worker/worker_main_script_load_params.mojom", "worker/worker_main_script_load_params.mojom",
"worker/worker_options.mojom",
] ]
if (!is_android) { if (!is_android) {
......
...@@ -6,6 +6,7 @@ module blink.mojom; ...@@ -6,6 +6,7 @@ module blink.mojom;
import "services/network/public/mojom/content_security_policy.mojom"; import "services/network/public/mojom/content_security_policy.mojom";
import "services/network/public/mojom/ip_address_space.mojom"; import "services/network/public/mojom/ip_address_space.mojom";
import "third_party/blink/public/mojom/worker/worker_options.mojom";
import "url/mojom/url.mojom"; import "url/mojom/url.mojom";
// Meta data that is necessary to create a new shared worker context. This // Meta data that is necessary to create a new shared worker context. This
...@@ -14,7 +15,7 @@ import "url/mojom/url.mojom"; ...@@ -14,7 +15,7 @@ import "url/mojom/url.mojom";
// process where the shared worker runs. // process where the shared worker runs.
struct SharedWorkerInfo { struct SharedWorkerInfo {
url.mojom.Url url; url.mojom.Url url;
string name; WorkerOptions options;
string content_security_policy; string content_security_policy;
network.mojom.ContentSecurityPolicyType content_security_policy_type; network.mojom.ContentSecurityPolicyType content_security_policy_type;
network.mojom.IPAddressSpace creation_address_space; network.mojom.IPAddressSpace creation_address_space;
......
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
module blink.mojom;
// Used for constructing shared workers
// TODO(https://crbug.com/824646): ScriptType and
// network.mojom.CredentialsMode should be added to WorkerOptions
// https://html.spec.whatwg.org/multipage/workers.html#workeroptions
struct WorkerOptions {
string name = "";
};
...@@ -34,6 +34,7 @@ ...@@ -34,6 +34,7 @@
#include "mojo/public/cpp/bindings/pending_remote.h" #include "mojo/public/cpp/bindings/pending_remote.h"
#include "third_party/blink/public/common/blob/blob_utils.h" #include "third_party/blink/public/common/blob/blob_utils.h"
#include "third_party/blink/public/mojom/fetch/fetch_api_request.mojom-blink.h" #include "third_party/blink/public/mojom/fetch/fetch_api_request.mojom-blink.h"
#include "third_party/blink/public/mojom/worker/shared_worker_info.mojom-blink.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/fileapi/public_url_manager.h" #include "third_party/blink/renderer/core/fileapi/public_url_manager.h"
#include "third_party/blink/renderer/core/messaging/message_channel.h" #include "third_party/blink/renderer/core/messaging/message_channel.h"
...@@ -68,7 +69,7 @@ SharedWorker::SharedWorker(ExecutionContext* context) ...@@ -68,7 +69,7 @@ SharedWorker::SharedWorker(ExecutionContext* context)
SharedWorker* SharedWorker::Create(ExecutionContext* context, SharedWorker* SharedWorker::Create(ExecutionContext* context,
const String& url, const String& url,
const StringOrWorkerOptions& options, const StringOrWorkerOptions& name_or_options,
ExceptionState& exception_state) { ExceptionState& exception_state) {
DCHECK(IsMainThread()); DCHECK(IsMainThread());
...@@ -106,11 +107,11 @@ SharedWorker* SharedWorker::Create(ExecutionContext* context, ...@@ -106,11 +107,11 @@ SharedWorker* SharedWorker::Create(ExecutionContext* context,
script_url, blob_url_token.InitWithNewPipeAndPassReceiver()); script_url, blob_url_token.InitWithNewPipeAndPassReceiver());
} }
String worker_name; auto options = mojom::blink::WorkerOptions::New();
if (options.IsString()) { if (name_or_options.IsString()) {
worker_name = options.GetAsString(); options->name = name_or_options.GetAsString();
} else if (options.IsWorkerOptions()) { } else if (name_or_options.IsWorkerOptions()) {
WorkerOptions* worker_options = options.GetAsWorkerOptions(); WorkerOptions* worker_options = name_or_options.GetAsWorkerOptions();
if (worker_options->type() == "module" && if (worker_options->type() == "module" &&
!RuntimeEnabledFeatures::ModuleSharedWorkerEnabled()) { !RuntimeEnabledFeatures::ModuleSharedWorkerEnabled()) {
exception_state.ThrowTypeError( exception_state.ThrowTypeError(
...@@ -118,15 +119,15 @@ SharedWorker* SharedWorker::Create(ExecutionContext* context, ...@@ -118,15 +119,15 @@ SharedWorker* SharedWorker::Create(ExecutionContext* context,
"(see https://crbug.com/824646)"); "(see https://crbug.com/824646)");
return nullptr; return nullptr;
} }
worker_name = worker_options->name(); options->name = worker_options->name();
} else { } else {
NOTREACHED(); NOTREACHED();
} }
DCHECK(!worker_name.IsNull()); DCHECK(!options->name.IsNull());
SharedWorkerClientHolder::From(*document)->Connect( SharedWorkerClientHolder::From(*document)->Connect(
worker, std::move(remote_port), script_url, std::move(blob_url_token), worker, std::move(remote_port), script_url, std::move(blob_url_token),
worker_name); std::move(options));
return worker; return worker;
} }
......
...@@ -81,9 +81,9 @@ void SharedWorkerClientHolder::Connect( ...@@ -81,9 +81,9 @@ void SharedWorkerClientHolder::Connect(
MessagePortChannel port, MessagePortChannel port,
const KURL& url, const KURL& url,
mojo::PendingRemote<mojom::blink::BlobURLToken> blob_url_token, mojo::PendingRemote<mojom::blink::BlobURLToken> blob_url_token,
const String& name) { mojom::blink::WorkerOptionsPtr options) {
DCHECK(IsMainThread()); DCHECK(IsMainThread());
DCHECK(!name.IsNull()); DCHECK(options);
// TODO(estark): this is broken, as it only uses the first header // TODO(estark): this is broken, as it only uses the first header
// when multiple might have been sent. Fix by making the // when multiple might have been sent. Fix by making the
...@@ -100,7 +100,7 @@ void SharedWorkerClientHolder::Connect( ...@@ -100,7 +100,7 @@ void SharedWorkerClientHolder::Connect(
} }
mojom::blink::SharedWorkerInfoPtr info(mojom::blink::SharedWorkerInfo::New( mojom::blink::SharedWorkerInfoPtr info(mojom::blink::SharedWorkerInfo::New(
url, name, header, header_type, url, std::move(options), header, header_type,
worker->GetExecutionContext()->GetSecurityContext().AddressSpace())); worker->GetExecutionContext()->GetSecurityContext().AddressSpace()));
mojo::PendingRemote<mojom::blink::SharedWorkerClient> client; mojo::PendingRemote<mojom::blink::SharedWorkerClient> client;
......
...@@ -41,9 +41,11 @@ ...@@ -41,9 +41,11 @@
#include "third_party/blink/public/mojom/blob/blob_url_store.mojom-blink-forward.h" #include "third_party/blink/public/mojom/blob/blob_url_store.mojom-blink-forward.h"
#include "third_party/blink/public/mojom/worker/shared_worker_client.mojom-blink-forward.h" #include "third_party/blink/public/mojom/worker/shared_worker_client.mojom-blink-forward.h"
#include "third_party/blink/public/mojom/worker/shared_worker_connector.mojom-blink.h" #include "third_party/blink/public/mojom/worker/shared_worker_connector.mojom-blink.h"
#include "third_party/blink/public/mojom/worker/shared_worker_info.mojom-blink.h"
#include "third_party/blink/renderer/core/core_export.h" #include "third_party/blink/renderer/core/core_export.h"
#include "third_party/blink/renderer/core/dom/document.h" #include "third_party/blink/renderer/core/dom/document.h"
#include "third_party/blink/renderer/core/execution_context/context_lifecycle_observer.h" #include "third_party/blink/renderer/core/execution_context/context_lifecycle_observer.h"
#include "third_party/blink/renderer/core/workers/worker_options.h"
#include "third_party/blink/renderer/platform/heap/garbage_collected.h" #include "third_party/blink/renderer/platform/heap/garbage_collected.h"
#include "third_party/blink/renderer/platform/wtf/forward.h" #include "third_party/blink/renderer/platform/wtf/forward.h"
...@@ -78,7 +80,7 @@ class CORE_EXPORT SharedWorkerClientHolder final ...@@ -78,7 +80,7 @@ class CORE_EXPORT SharedWorkerClientHolder final
MessagePortChannel, MessagePortChannel,
const KURL&, const KURL&,
mojo::PendingRemote<mojom::blink::BlobURLToken>, mojo::PendingRemote<mojom::blink::BlobURLToken>,
const String& name); mojom::blink::WorkerOptionsPtr options);
// Overrides ContextLifecycleObserver. // Overrides ContextLifecycleObserver.
void ContextDestroyed(ExecutionContext*) override; void ContextDestroyed(ExecutionContext*) override;
......
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