Commit 5c84c027 authored by Dave Tapuska's avatar Dave Tapuska Committed by Commit Bot

Add dedicated worker host mojo interface.

The mojo interface will be used to communicate the new lifecycle state
of the worker. This will be useful for filtering out frozen state for
dedicated workers in the client matching APIs.

BUG=968417,907125

Change-Id: Ic9f32a83ea6fd8e88dd59c63b8e2966d86ca6bac
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1756623Reviewed-by: default avatarKinuko Yasuda <kinuko@chromium.org>
Reviewed-by: default avatarMatt Falkenhagen <falken@chromium.org>
Commit-Queue: Dave Tapuska <dtapuska@chromium.org>
Cr-Commit-Position: refs/heads/master@{#689432}
parent db6e5118
......@@ -33,14 +33,17 @@
namespace content {
DedicatedWorkerHost::DedicatedWorkerHost(int worker_process_id,
int ancestor_render_frame_id,
int creator_render_frame_id,
const url::Origin& origin)
DedicatedWorkerHost::DedicatedWorkerHost(
int worker_process_id,
int ancestor_render_frame_id,
int creator_render_frame_id,
const url::Origin& origin,
mojo::PendingReceiver<blink::mojom::DedicatedWorkerHost> host)
: worker_process_id_(worker_process_id),
ancestor_render_frame_id_(ancestor_render_frame_id),
creator_render_frame_id_(creator_render_frame_id),
origin_(origin) {
origin_(origin),
host_receiver_(this, std::move(host)) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
RegisterMojoInterfaces();
}
......@@ -71,6 +74,24 @@ void DedicatedWorkerHost::BindBrowserInterfaceBrokerReceiver(
broker_receiver_.Bind(std::move(receiver));
}
void DedicatedWorkerHost::LifecycleStateChanged(
blink::mojom::FrameLifecycleState state) {
switch (state) {
case blink::mojom::FrameLifecycleState::kFrozen:
case blink::mojom::FrameLifecycleState::kFrozenAutoResumeMedia:
is_frozen_ = true;
break;
case blink::mojom::FrameLifecycleState::kRunning:
is_frozen_ = false;
break;
case blink::mojom::FrameLifecycleState::kPaused:
// This shouldn't be reached, the render process does not send this
// state.
NOTREACHED();
break;
}
}
void DedicatedWorkerHost::StartScriptLoad(
const GURL& script_url,
const url::Origin& request_initiator_origin,
......@@ -409,7 +430,9 @@ class DedicatedWorkerHostFactoryImpl
const url::Origin& origin,
service_manager::mojom::InterfaceProviderRequest request,
mojo::PendingReceiver<blink::mojom::BrowserInterfaceBroker>
broker_receiver) override {
broker_receiver,
mojo::PendingReceiver<blink::mojom::DedicatedWorkerHost> host_receiver)
override {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
if (base::FeatureList::IsEnabled(blink::features::kPlzDedicatedWorker)) {
mojo::ReportBadMessage("DWH_INVALID_WORKER_CREATION");
......@@ -422,7 +445,7 @@ class DedicatedWorkerHostFactoryImpl
// (Document or DedicatedWorkerGlobalScope), or is unique.
auto host = std::make_unique<DedicatedWorkerHost>(
creator_process_id_, ancestor_render_frame_id_,
creator_render_frame_id_, origin);
creator_render_frame_id_, origin, std::move(host_receiver));
host->BindBrowserInterfaceBrokerReceiver(std::move(broker_receiver));
mojo::MakeStrongBinding(std::move(host),
FilterRendererExposedInterfaces(
......@@ -439,7 +462,9 @@ class DedicatedWorkerHostFactoryImpl
outside_fetch_client_settings_object,
blink::mojom::BlobURLTokenPtr blob_url_token,
mojo::PendingRemote<blink::mojom::DedicatedWorkerHostFactoryClient>
client) override {
client,
mojo::PendingReceiver<blink::mojom::DedicatedWorkerHost> host_receiver)
override {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
if (!base::FeatureList::IsEnabled(blink::features::kPlzDedicatedWorker)) {
mojo::ReportBadMessage("DWH_BROWSER_SCRIPT_FETCH_DISABLED");
......@@ -455,7 +480,8 @@ class DedicatedWorkerHostFactoryImpl
// (Document or DedicatedWorkerGlobalScope), or is unique.
auto host = std::make_unique<DedicatedWorkerHost>(
creator_process_id_, ancestor_render_frame_id_,
creator_render_frame_id_, request_initiator_origin);
creator_render_frame_id_, request_initiator_origin,
std::move(host_receiver));
mojo::PendingRemote<blink::mojom::BrowserInterfaceBroker> broker;
host->BindBrowserInterfaceBrokerReceiver(
broker.InitWithNewPipeAndPassReceiver());
......
......@@ -16,6 +16,7 @@
#include "third_party/blink/public/mojom/idle/idle_manager.mojom-forward.h"
#include "third_party/blink/public/mojom/usb/web_usb_service.mojom-forward.h"
#include "third_party/blink/public/mojom/websockets/websocket_connector.mojom-forward.h"
#include "third_party/blink/public/mojom/worker/dedicated_worker_host.mojom.h"
#include "third_party/blink/public/mojom/worker/dedicated_worker_host_factory.mojom.h"
namespace url {
......@@ -41,12 +42,15 @@ void CreateDedicatedWorkerHostFactory(
// DedicatedWorkerGlobalScope of the corresponding worker in the renderer via a
// StrongBinding. This lives on the UI thread.
class DedicatedWorkerHost final
: public service_manager::mojom::InterfaceProvider {
: public service_manager::mojom::InterfaceProvider,
public blink::mojom::DedicatedWorkerHost {
public:
DedicatedWorkerHost(int worker_process_id,
int ancestor_render_frame_id,
int creator_render_frame_id,
const url::Origin& origin);
DedicatedWorkerHost(
int worker_process_id,
int ancestor_render_frame_id,
int creator_render_frame_id,
const url::Origin& origin,
mojo::PendingReceiver<blink::mojom::DedicatedWorkerHost> host);
~DedicatedWorkerHost() final;
void BindBrowserInterfaceBrokerReceiver(
......@@ -67,6 +71,14 @@ class DedicatedWorkerHost final
void GetInterface(const std::string& interface_name,
mojo::ScopedMessagePipeHandle interface_pipe) override;
// blink::mojom::DedicatedWorkerHost:
void LifecycleStateChanged(blink::mojom::FrameLifecycleState state) override;
// TODO(dtapuska): This state needs to be hooked up to the
// ServiceWorkerProviderHost so the correct state is queried when looking
// for frozen dedicated workers. crbug.com/968417
bool is_frozen() const { return is_frozen_; }
// PlzDedicatedWorker:
void StartScriptLoad(
const GURL& script_url,
......@@ -159,6 +171,10 @@ class DedicatedWorkerHost final
this};
mojo::Receiver<blink::mojom::BrowserInterfaceBroker> broker_receiver_{
&broker_};
mojo::Receiver<blink::mojom::DedicatedWorkerHost> host_receiver_;
// The liveness state of the dedicated worker in the renderer.
bool is_frozen_ = false;
base::WeakPtrFactory<DedicatedWorkerHost> weak_factory_{this};
......
......@@ -39,7 +39,8 @@ void DedicatedWorkerHostFactoryClient::CreateWorkerHostDeprecated(
browser_interface_broker;
factory_->CreateWorkerHost(
script_origin, mojo::MakeRequest(&interface_provider_ptr),
browser_interface_broker.InitWithNewPipeAndPassReceiver());
browser_interface_broker.InitWithNewPipeAndPassReceiver(),
remote_host_.BindNewPipeAndPassReceiver());
OnWorkerHostCreated(std::move(interface_provider_ptr),
std::move(browser_interface_broker));
}
......@@ -71,7 +72,8 @@ void DedicatedWorkerHostFactoryClient::CreateWorkerHost(
std::move(outside_fetch_client_settings_object),
blink::mojom::BlobURLTokenPtr(blink::mojom::BlobURLTokenPtrInfo(
std::move(blob_url_token), blink::mojom::BlobURLToken::Version_)),
receiver_.BindNewPipeAndPassRemote());
receiver_.BindNewPipeAndPassRemote(),
remote_host_.BindNewPipeAndPassReceiver());
}
scoped_refptr<blink::WebWorkerFetchContext>
......@@ -97,6 +99,12 @@ DedicatedWorkerHostFactoryClient::CloneWorkerFetchContext(
return worker_fetch_context;
}
void DedicatedWorkerHostFactoryClient::LifecycleStateChanged(
blink::mojom::FrameLifecycleState state) {
if (remote_host_)
remote_host_->LifecycleStateChanged(state);
}
scoped_refptr<WebWorkerFetchContextImpl>
DedicatedWorkerHostFactoryClient::CreateWorkerFetchContext(
blink::mojom::RendererPreferences renderer_preference,
......
......@@ -11,6 +11,7 @@
#include "services/service_manager/public/cpp/interface_provider.h"
#include "third_party/blink/public/mojom/renderer_preference_watcher.mojom.h"
#include "third_party/blink/public/mojom/renderer_preferences.mojom.h"
#include "third_party/blink/public/mojom/worker/dedicated_worker_host.mojom.h"
#include "third_party/blink/public/mojom/worker/dedicated_worker_host_factory.mojom.h"
#include "third_party/blink/public/platform/web_dedicated_worker_host_factory_client.h"
......@@ -56,6 +57,7 @@ class DedicatedWorkerHostFactoryClient final
scoped_refptr<blink::WebWorkerFetchContext> CloneWorkerFetchContext(
blink::WebWorkerFetchContext* web_worker_fetch_context,
scoped_refptr<base::SingleThreadTaskRunner> task_runner) override;
void LifecycleStateChanged(blink::mojom::FrameLifecycleState state) override;
scoped_refptr<WebWorkerFetchContextImpl> CreateWorkerFetchContext(
blink::mojom::RendererPreferences renderer_preference,
......@@ -88,6 +90,7 @@ class DedicatedWorkerHostFactoryClient final
mojo::Remote<blink::mojom::DedicatedWorkerHostFactory> factory_;
mojo::Receiver<blink::mojom::DedicatedWorkerHostFactoryClient> receiver_{
this};
mojo::Remote<blink::mojom::DedicatedWorkerHost> remote_host_;
};
} // namespace content
......
......@@ -133,6 +133,7 @@ mojom("mojom_platform") {
"webdatabase/web_database.mojom",
"websockets/websocket_connector.mojom",
"window_features/window_features.mojom",
"worker/dedicated_worker_host.mojom",
"worker/shared_worker.mojom",
"worker/shared_worker_client.mojom",
"worker/shared_worker_connector.mojom",
......
// Copyright 2019 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;
import "third_party/blink/public/mojom/frame/lifecycle.mojom";
// Each dedicated worker has a corresponding host that is implemented in
// the browser process.
interface DedicatedWorkerHost {
// A dedicated worker's lifecycle state changed because the owning document's
// lifecycle state changed as well.
LifecycleStateChanged(FrameLifecycleState state);
};
\ No newline at end of file
......@@ -10,6 +10,7 @@ import "third_party/blink/public/mojom/blob/blob_url_store.mojom";
import "third_party/blink/public/mojom/browser_interface_broker.mojom";
import "third_party/blink/public/mojom/loader/fetch_client_settings_object.mojom";
import "third_party/blink/public/mojom/loader/url_loader_factory_bundle.mojom";
import "third_party/blink/public/mojom/worker/dedicated_worker_host.mojom";
import "third_party/blink/public/mojom/worker/worker_main_script_load_params.mojom";
import "third_party/blink/public/mojom/service_worker/controller_service_worker.mojom";
import "third_party/blink/public/mojom/service_worker/service_worker_provider.mojom";
......@@ -84,7 +85,8 @@ interface DedicatedWorkerHostFactory {
// TODO(crbug.com/990845): remove when no longer used.
service_manager.mojom.InterfaceProvider& worker_interface_provider,
pending_receiver<blink.mojom.BrowserInterfaceBroker>
browser_interface_broker);
browser_interface_broker,
pending_receiver<DedicatedWorkerHost> host);
// PlzDedicatedWorker:
// The factory client should call this instead of CreateWorkerHost() when
......@@ -105,5 +107,6 @@ interface DedicatedWorkerHostFactory {
blink.mojom.FetchClientSettingsObject
outside_fetch_client_settings_object,
blink.mojom.BlobURLToken? blob_url_token,
pending_remote<DedicatedWorkerHostFactoryClient> client);
pending_remote<DedicatedWorkerHostFactoryClient> client,
pending_receiver<DedicatedWorkerHost> host);
};
......@@ -9,6 +9,7 @@
#include "mojo/public/cpp/system/message_pipe.h"
#include "services/network/public/mojom/fetch_api.mojom-shared.h"
#include "services/network/public/mojom/referrer_policy.mojom-shared.h"
#include "third_party/blink/public/mojom/frame/lifecycle.mojom-shared.h"
#include "third_party/blink/public/platform/web_insecure_request_policy.h"
namespace base {
......@@ -50,6 +51,10 @@ class WebDedicatedWorkerHostFactoryClient {
virtual scoped_refptr<WebWorkerFetchContext> CloneWorkerFetchContext(
WebWorkerFetchContext*,
scoped_refptr<base::SingleThreadTaskRunner>) = 0;
// Called when a dedicated worker's lifecycle will change.
virtual void LifecycleStateChanged(
blink::mojom::FrameLifecycleState state) = 0;
};
} // namespace blink
......
......@@ -517,12 +517,14 @@ void DedicatedWorker::ContextLifecycleStateChanged(
break;
case mojom::FrameLifecycleState::kFrozen:
case mojom::FrameLifecycleState::kFrozenAutoResumeMedia:
factory_client_->LifecycleStateChanged(state);
if (!requested_frozen_) {
requested_frozen_ = true;
context_proxy_->Freeze();
}
break;
case mojom::FrameLifecycleState::kRunning:
factory_client_->LifecycleStateChanged(state);
if (requested_frozen_) {
context_proxy_->Resume();
requested_frozen_ = false;
......
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