Commit 58895766 authored by Darin Fisher's avatar Darin Fisher Committed by Commit Bot

Use mojo IPC for communicating w/ the shared worker instance

This change introduces a new service (SharedWorkerFactory) exported
from renderer processes to support the instantiation of shared worker
instances.

The SharedWorkerFactory is instantiated from within the
SharedWorkerServiceImpl::TryReserve function, which runs on the UI
thread. This way we defer connecting to that service until we want
to create a shared worker. It also allows the unit tests to swap in
a mock implementation of SharedWorkerFactory.

In a future CL, it'll be possible to remove the
SharedWorkerMessageFilter. Even though that class now no longer
filters any Chrome IPC messages, its other functionality is still
needed. Similarly, we still need to allocate a routing ID for the
shared worker even though that is not needed by the shared worker
infrastructure. Dev Tools uses the routing ID to help lookup the
shared worker, so that'll need to change before we clean this up.

Also, in a future CL, it'll be possible to move the shared worker
service code to run entirely on the UI thread. This will allow a lot
of code simplification as we'll no longer have to deal w/ the race
conditions during process reservation. A bunch of complexity will
disappear. To try to keep this CL manageable, I chose to postpone
the threading changes to a follow-up CL.

The lifetime of the SharedWorker instance in the renderer process is
a bit squirrely thanks to how WebSharedWorker manages its lifetime.
This CL does not attempt any changes there.

Bug: 612308
Change-Id: Ifc355d42d0c869519acee853c953342a2bcf691a
Reviewed-on: https://chromium-review.googlesource.com/659139Reviewed-by: default avatarDaniel Cheng <dcheng@chromium.org>
Reviewed-by: default avatarKinuko Yasuda (slow) <kinuko@chromium.org>
Reviewed-by: default avatarHiroki Nakagawa <nhiroki@chromium.org>
Commit-Queue: Darin Fisher <darin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#502910}
parent 497d5a91
......@@ -4,7 +4,6 @@
#include "content/browser/devtools/shared_worker_devtools_agent_host.h"
#include "base/strings/utf_string_conversions.h"
#include "content/browser/devtools/shared_worker_devtools_manager.h"
#include "content/browser/shared_worker/shared_worker_instance.h"
#include "content/browser/shared_worker/shared_worker_service_impl.h"
......@@ -35,7 +34,7 @@ std::string SharedWorkerDevToolsAgentHost::GetType() {
}
std::string SharedWorkerDevToolsAgentHost::GetTitle() {
return base::UTF16ToUTF8(shared_worker_->name());
return shared_worker_->name();
}
GURL SharedWorkerDevToolsAgentHost::GetURL() {
......
......@@ -105,7 +105,7 @@ TEST_F(SharedWorkerDevToolsManagerTest, BasicTest) {
scoped_refptr<DevToolsAgentHostImpl> agent_host;
SharedWorkerInstance instance1(
GURL("http://example.com/w.js"), base::string16(), base::string16(),
GURL("http://example.com/w.js"), std::string(), std::string(),
blink::kWebContentSecurityPolicyTypeReport, blink::kWebAddressSpacePublic,
browser_context_->GetResourceContext(), partition_id_,
blink::mojom::SharedWorkerCreationContextType::kNonsecure,
......@@ -188,13 +188,13 @@ TEST_F(SharedWorkerDevToolsManagerTest, AttachTest) {
scoped_refptr<DevToolsAgentHostImpl> agent_host2;
SharedWorkerInstance instance1(
GURL("http://example.com/w1.js"), base::string16(), base::string16(),
GURL("http://example.com/w1.js"), std::string(), std::string(),
blink::kWebContentSecurityPolicyTypeReport, blink::kWebAddressSpacePublic,
browser_context_->GetResourceContext(), partition_id_,
blink::mojom::SharedWorkerCreationContextType::kNonsecure,
false /* data_saver_enabled */);
SharedWorkerInstance instance2(
GURL("http://example.com/w2.js"), base::string16(), base::string16(),
GURL("http://example.com/w2.js"), std::string(), std::string(),
blink::kWebContentSecurityPolicyTypeReport, blink::kWebAddressSpacePublic,
browser_context_->GetResourceContext(), partition_id_,
blink::mojom::SharedWorkerCreationContextType::kNonsecure,
......@@ -275,7 +275,7 @@ TEST_F(SharedWorkerDevToolsManagerTest, AttachTest) {
TEST_F(SharedWorkerDevToolsManagerTest, ReattachTest) {
SharedWorkerInstance instance(
GURL("http://example.com/w3.js"), base::string16(), base::string16(),
GURL("http://example.com/w3.js"), std::string(), std::string(),
blink::kWebContentSecurityPolicyTypeReport, blink::kWebAddressSpacePublic,
browser_context_->GetResourceContext(), partition_id_,
blink::mojom::SharedWorkerCreationContextType::kNonsecure,
......@@ -307,7 +307,7 @@ TEST_F(SharedWorkerDevToolsManagerTest, ReattachTest) {
TEST_F(SharedWorkerDevToolsManagerTest, PauseOnStartTest) {
SharedWorkerInstance instance(
GURL("http://example.com/w3.js"), base::string16(), base::string16(),
GURL("http://example.com/w3.js"), std::string(), std::string(),
blink::kWebContentSecurityPolicyTypeReport, blink::kWebAddressSpacePublic,
browser_context_->GetResourceContext(), partition_id_,
blink::mojom::SharedWorkerCreationContextType::kNonsecure,
......
......@@ -72,11 +72,12 @@ SharedWorkerConnectorImpl::SharedWorkerConnectorImpl(
void SharedWorkerConnectorImpl::Connect(
mojom::SharedWorkerInfoPtr info,
mojom::SharedWorkerClientPtr client,
blink::mojom::SharedWorkerCreationContextType creation_context_type,
mojo::ScopedMessagePipeHandle message_port) {
SharedWorkerServiceImpl::GetInstance()->CreateWorker(
process_id_, frame_id_, std::move(info), std::move(client),
MessagePort(std::move(message_port)), resource_context_,
WorkerStoragePartitionId(worker_storage_partition_));
creation_context_type, MessagePort(std::move(message_port)),
resource_context_, WorkerStoragePartitionId(worker_storage_partition_));
}
} // namespace content
......@@ -38,9 +38,11 @@ class CONTENT_EXPORT SharedWorkerConnectorImpl
const WorkerStoragePartition& worker_storage_partition);
// mojom::SharedWorkerConnector methods:
void Connect(mojom::SharedWorkerInfoPtr info,
mojom::SharedWorkerClientPtr client,
mojo::ScopedMessagePipeHandle message_port) override;
void Connect(
mojom::SharedWorkerInfoPtr info,
mojom::SharedWorkerClientPtr client,
blink::mojom::SharedWorkerCreationContextType creation_context_type,
mojo::ScopedMessagePipeHandle message_port) override;
const int process_id_;
const int frame_id_;
......
......@@ -15,20 +15,19 @@
#include "base/memory/weak_ptr.h"
#include "base/strings/string16.h"
#include "base/time/time.h"
#include "content/common/shared_worker/shared_worker.mojom.h"
#include "content/common/shared_worker/shared_worker_client.mojom.h"
#include "content/common/shared_worker/shared_worker_factory.mojom.h"
#include "content/common/shared_worker/shared_worker_host.mojom.h"
#include "mojo/public/cpp/bindings/binding.h"
class GURL;
namespace IPC {
class Message;
}
namespace content {
class MessagePort;
class SharedWorkerContentSettingsProxyImpl;
class SharedWorkerInstance;
class SharedWorkerMessageFilter;
// The SharedWorkerHost is the interface that represents the browser side of
// the browser <-> worker communication channel. This is owned by
......@@ -37,23 +36,16 @@ class SharedWorkerMessageFilter;
//
// NOTE: This class is intended to only be used on the IO thread.
//
class SharedWorkerHost {
class SharedWorkerHost : public mojom::SharedWorkerHost {
public:
SharedWorkerHost(SharedWorkerInstance* instance,
SharedWorkerMessageFilter* filter,
int worker_route_id);
~SharedWorkerHost();
int process_id,
int route_id);
~SharedWorkerHost() override;
// Starts the SharedWorker in the renderer process.
void Start(bool pause_on_start);
void CountFeature(blink::mojom::WebFeature feature);
void WorkerContextClosed();
void WorkerContextDestroyed();
void WorkerReadyForInspection();
void WorkerScriptLoaded();
void WorkerScriptLoadFailed();
void WorkerConnected(int connection_request_id);
void Start(mojom::SharedWorkerFactoryPtr factory, bool pause_on_start);
void AllowFileSystem(const GURL& url,
base::OnceCallback<void(bool)> callback);
bool AllowIndexedDB(const GURL& url, const base::string16& name);
......@@ -70,11 +62,8 @@ class SharedWorkerHost {
bool ServesExternalClient();
SharedWorkerInstance* instance() { return instance_.get(); }
SharedWorkerMessageFilter* worker_render_filter() const {
return worker_render_filter_;
}
int process_id() const { return worker_process_id_; }
int worker_route_id() const { return worker_route_id_; }
int process_id() const { return process_id_; }
int route_id() const { return route_id_; }
bool IsAvailable() const;
private:
......@@ -92,26 +81,30 @@ class SharedWorkerHost {
using ClientList = std::list<ClientInfo>;
// mojom::SharedWorkerHost methods:
void OnConnected(int connection_request_id) override;
void OnContextClosed() override;
void OnReadyForInspection() override;
void OnScriptLoaded() override;
void OnScriptLoadFailed() override;
void OnFeatureUsed(blink::mojom::WebFeature feature) override;
// Return a vector of all the render process/render frame IDs.
std::vector<std::pair<int, int>> GetRenderFrameIDsForWorker();
void AllowFileSystemResponse(base::OnceCallback<void(bool)> callback,
bool allowed);
void OnClientConnectionLost();
void OnWorkerConnectionLost();
// Sends |message| to the SharedWorker.
bool Send(IPC::Message* message);
mojo::Binding<mojom::SharedWorkerHost> binding_;
std::unique_ptr<SharedWorkerInstance> instance_;
ClientList clients_;
// A message filter for a renderer process that hosts a worker. This is always
// valid because this host is destructed immediately after the filter is
// closed (see SharedWorkerServiceImpl::OnSharedWorkerMessageFilterClosing).
SharedWorkerMessageFilter* worker_render_filter_;
mojom::SharedWorkerPtr worker_;
const int worker_process_id_;
const int worker_route_id_;
const int process_id_;
const int route_id_;
int next_connection_request_id_;
bool termination_message_sent_ = false;
bool closed_ = false;
......@@ -125,6 +118,7 @@ class SharedWorkerHost {
DISALLOW_COPY_AND_ASSIGN(SharedWorkerHost);
};
} // namespace content
#endif // CONTENT_BROWSER_SHARED_WORKER_SHARED_WORKER_HOST_H_
......@@ -10,8 +10,8 @@ namespace content {
SharedWorkerInstance::SharedWorkerInstance(
const GURL& url,
const base::string16& name,
const base::string16& content_security_policy,
const std::string& name,
const std::string& content_security_policy,
blink::WebContentSecurityPolicyType security_policy_type,
blink::WebAddressSpace creation_address_space,
ResourceContext* resource_context,
......@@ -21,7 +21,7 @@ SharedWorkerInstance::SharedWorkerInstance(
: url_(url),
name_(name),
content_security_policy_(content_security_policy),
security_policy_type_(security_policy_type),
content_security_policy_type_(security_policy_type),
creation_address_space_(creation_address_space),
resource_context_(resource_context),
partition_id_(partition_id),
......@@ -34,7 +34,7 @@ SharedWorkerInstance::SharedWorkerInstance(const SharedWorkerInstance& other)
: url_(other.url_),
name_(other.name_),
content_security_policy_(other.content_security_policy_),
security_policy_type_(other.security_policy_type_),
content_security_policy_type_(other.content_security_policy_type_),
creation_address_space_(other.creation_address_space_),
resource_context_(other.resource_context_),
partition_id_(other.partition_id_),
......@@ -44,7 +44,7 @@ SharedWorkerInstance::SharedWorkerInstance(const SharedWorkerInstance& other)
SharedWorkerInstance::~SharedWorkerInstance() {}
bool SharedWorkerInstance::Matches(const GURL& match_url,
const base::string16& match_name,
const std::string& match_name,
const WorkerStoragePartitionId& partition_id,
ResourceContext* resource_context) const {
// ResourceContext equivalence is being used as a proxy to ensure we only
......
......@@ -23,9 +23,9 @@ class CONTENT_EXPORT SharedWorkerInstance {
public:
SharedWorkerInstance(
const GURL& url,
const base::string16& name,
const base::string16& content_security_policy,
blink::WebContentSecurityPolicyType security_policy_type,
const std::string& name,
const std::string& content_security_policy,
blink::WebContentSecurityPolicyType content_security_policy_type,
blink::WebAddressSpace creation_address_space,
ResourceContext* resource_context,
const WorkerStoragePartitionId& partition_id,
......@@ -41,19 +41,19 @@ class CONTENT_EXPORT SharedWorkerInstance {
// -or-
// b) the names are both empty, and the urls are equal.
bool Matches(const GURL& url,
const base::string16& name,
const std::string& name,
const WorkerStoragePartitionId& partition,
ResourceContext* resource_context) const;
bool Matches(const SharedWorkerInstance& other) const;
// Accessors.
const GURL& url() const { return url_; }
const base::string16 name() const { return name_; }
const base::string16 content_security_policy() const {
const std::string name() const { return name_; }
const std::string content_security_policy() const {
return content_security_policy_;
}
blink::WebContentSecurityPolicyType security_policy_type() const {
return security_policy_type_;
blink::WebContentSecurityPolicyType content_security_policy_type() const {
return content_security_policy_type_;
}
blink::WebAddressSpace creation_address_space() const {
return creation_address_space_;
......@@ -69,9 +69,9 @@ class CONTENT_EXPORT SharedWorkerInstance {
private:
const GURL url_;
const base::string16 name_;
const base::string16 content_security_policy_;
const blink::WebContentSecurityPolicyType security_policy_type_;
const std::string name_;
const std::string content_security_policy_;
const blink::WebContentSecurityPolicyType content_security_policy_type_;
const blink::WebAddressSpace creation_address_space_;
ResourceContext* const resource_context_;
const WorkerStoragePartitionId partition_id_;
......
......@@ -36,9 +36,7 @@ class SharedWorkerInstanceTest : public testing::Test {
bool Matches(const SharedWorkerInstance& instance,
const std::string& url,
const base::StringPiece& name) {
return instance.Matches(GURL(url),
base::ASCIIToUTF16(name),
partition_id_,
return instance.Matches(GURL(url), name.as_string(), partition_id_,
browser_context_->GetResourceContext());
}
......@@ -53,7 +51,7 @@ class SharedWorkerInstanceTest : public testing::Test {
TEST_F(SharedWorkerInstanceTest, MatchesTest) {
SharedWorkerInstance instance1(
GURL("http://example.com/w.js"), base::string16(), base::string16(),
GURL("http://example.com/w.js"), std::string(), std::string(),
blink::kWebContentSecurityPolicyTypeReport, blink::kWebAddressSpacePublic,
browser_context_->GetResourceContext(), partition_id_,
blink::mojom::SharedWorkerCreationContextType::kNonsecure,
......@@ -68,10 +66,10 @@ TEST_F(SharedWorkerInstanceTest, MatchesTest) {
EXPECT_FALSE(Matches(instance1, "http://example.net/w2.js", "name"));
SharedWorkerInstance instance2(
GURL("http://example.com/w.js"), base::ASCIIToUTF16("name"),
base::string16(), blink::kWebContentSecurityPolicyTypeReport,
blink::kWebAddressSpacePublic, browser_context_->GetResourceContext(),
partition_id_, blink::mojom::SharedWorkerCreationContextType::kNonsecure,
GURL("http://example.com/w.js"), "name", std::string(),
blink::kWebContentSecurityPolicyTypeReport, blink::kWebAddressSpacePublic,
browser_context_->GetResourceContext(), partition_id_,
blink::mojom::SharedWorkerCreationContextType::kNonsecure,
false /* data_saver_enabled */);
EXPECT_FALSE(Matches(instance2, "http://example.com/w.js", ""));
EXPECT_FALSE(Matches(instance2, "http://example.com/w2.js", ""));
......@@ -90,8 +88,8 @@ TEST_F(SharedWorkerInstanceTest, MatchesTest) {
TEST_F(SharedWorkerInstanceTest, AddressSpace) {
for (int i = 0; i < static_cast<int>(blink::kWebAddressSpaceLast); i++) {
SharedWorkerInstance instance(
GURL("http://example.com/w.js"), base::ASCIIToUTF16("name"),
base::string16(), blink::kWebContentSecurityPolicyTypeReport,
GURL("http://example.com/w.js"), "name", std::string(),
blink::kWebContentSecurityPolicyTypeReport,
static_cast<blink::WebAddressSpace>(i),
browser_context_->GetResourceContext(), partition_id_,
blink::mojom::SharedWorkerCreationContextType::kNonsecure,
......
......@@ -10,22 +10,13 @@
#include "content/browser/shared_worker/shared_worker_service_impl.h"
#include "content/common/devtools_messages.h"
#include "content/common/view_messages.h"
#include "content/common/worker_messages.h"
namespace content {
namespace {
const uint32_t kFilteredMessageClasses[] = {
WorkerMsgStart,
};
} // namespace
SharedWorkerMessageFilter::SharedWorkerMessageFilter(
int render_process_id,
const NextRoutingIDCallback& next_routing_id_callback)
: BrowserMessageFilter(kFilteredMessageClasses,
arraysize(kFilteredMessageClasses)),
: BrowserMessageFilter(0 /* none */),
render_process_id_(render_process_id),
next_routing_id_callback_(next_routing_id_callback) {}
......@@ -44,38 +35,11 @@ void SharedWorkerMessageFilter::OnFilterRemoved() {
}
void SharedWorkerMessageFilter::OnChannelClosing() {
SharedWorkerServiceImpl::GetInstance()->OnSharedWorkerMessageFilterClosing(
this);
SharedWorkerServiceImpl::GetInstance()->OnProcessClosing(render_process_id_);
}
bool SharedWorkerMessageFilter::OnMessageReceived(const IPC::Message& message) {
bool handled = true;
IPC_BEGIN_MESSAGE_MAP_WITH_PARAM(SharedWorkerMessageFilter, message, this)
// Sent from SharedWorker in renderer.
IPC_MESSAGE_FORWARD(WorkerHostMsg_CountFeature,
SharedWorkerServiceImpl::GetInstance(),
SharedWorkerServiceImpl::CountFeature)
IPC_MESSAGE_FORWARD(WorkerHostMsg_WorkerContextClosed,
SharedWorkerServiceImpl::GetInstance(),
SharedWorkerServiceImpl::WorkerContextClosed)
IPC_MESSAGE_FORWARD(WorkerHostMsg_WorkerContextDestroyed,
SharedWorkerServiceImpl::GetInstance(),
SharedWorkerServiceImpl::WorkerContextDestroyed)
IPC_MESSAGE_FORWARD(WorkerHostMsg_WorkerReadyForInspection,
SharedWorkerServiceImpl::GetInstance(),
SharedWorkerServiceImpl::WorkerReadyForInspection)
IPC_MESSAGE_FORWARD(WorkerHostMsg_WorkerScriptLoaded,
SharedWorkerServiceImpl::GetInstance(),
SharedWorkerServiceImpl::WorkerScriptLoaded)
IPC_MESSAGE_FORWARD(WorkerHostMsg_WorkerScriptLoadFailed,
SharedWorkerServiceImpl::GetInstance(),
SharedWorkerServiceImpl::WorkerScriptLoadFailed)
IPC_MESSAGE_FORWARD(WorkerHostMsg_WorkerConnected,
SharedWorkerServiceImpl::GetInstance(),
SharedWorkerServiceImpl::WorkerConnected)
IPC_MESSAGE_UNHANDLED(handled = false)
IPC_END_MESSAGE_MAP()
return handled;
return false;
}
} // namespace content
......@@ -11,8 +11,9 @@
namespace content {
// Handles SharedWorker related IPC messages for one renderer process by
// forwarding them to the SharedWorkerServiceImpl singleton.
// TODO(darin): Delete this class as it is no longer actually needed to filter
// messages. It is only used to convey the GetNextRoutingID method and watch
// for process shutdown, and there are better ways to do those things.
class CONTENT_EXPORT SharedWorkerMessageFilter : public BrowserMessageFilter {
public:
using NextRoutingIDCallback = base::Callback<int(void)>;
......
......@@ -15,7 +15,9 @@
#include "base/macros.h"
#include "base/memory/singleton.h"
#include "base/observer_list.h"
#include "content/browser/shared_worker/shared_worker_host.h"
#include "content/common/shared_worker/shared_worker_connector.mojom.h"
#include "content/common/shared_worker/shared_worker_factory.mojom.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h"
#include "content/public/browser/worker_service.h"
......@@ -47,54 +49,41 @@ class CONTENT_EXPORT SharedWorkerServiceImpl : public WorkerService {
void RemoveObserver(WorkerServiceObserver* observer) override;
// These methods correspond to worker related IPCs.
void CreateWorker(int process_id,
int frame_id,
mojom::SharedWorkerInfoPtr info,
mojom::SharedWorkerClientPtr client,
const MessagePort& port,
ResourceContext* resource_context,
const WorkerStoragePartitionId& partition_id);
void CountFeature(SharedWorkerMessageFilter* filter,
int worker_route_id,
uint32_t feature);
void WorkerContextClosed(SharedWorkerMessageFilter* filter,
int worker_route_id);
void WorkerContextDestroyed(SharedWorkerMessageFilter* filter,
int worker_route_id);
void WorkerReadyForInspection(SharedWorkerMessageFilter* filter,
int worker_route_id);
void WorkerScriptLoaded(SharedWorkerMessageFilter* filter,
int worker_route_id);
void WorkerScriptLoadFailed(SharedWorkerMessageFilter* filter,
int worker_route_id);
void WorkerConnected(SharedWorkerMessageFilter* filter,
int connection_request_id,
int worker_route_id);
void OnSharedWorkerMessageFilterClosing(
SharedWorkerMessageFilter* filter);
void CreateWorker(
int process_id,
int frame_id,
mojom::SharedWorkerInfoPtr info,
mojom::SharedWorkerClientPtr client,
blink::mojom::SharedWorkerCreationContextType creation_context_type,
const MessagePort& port,
ResourceContext* resource_context,
const WorkerStoragePartitionId& partition_id);
void OnProcessClosing(int process_id);
// Checks the worker dependency of renderer processes and calls
// IncrementWorkerRefCount and DecrementWorkerRefCount of
// RenderProcessHostImpl on UI thread if necessary.
void CheckWorkerDependency();
void NotifyWorkerDestroyed(int worker_process_id, int worker_route_id);
void NotifyWorkerDestroyed(int process_id, int route_id);
void DestroyHost(int process_id, int route_id);
private:
class SharedWorkerPendingInstance;
class SharedWorkerReserver;
friend struct base::DefaultSingletonTraits<SharedWorkerServiceImpl>;
friend class SharedWorkerServiceImplTest;
using UpdateWorkerDependencyFunc = void (*)(const std::vector<int>&,
const std::vector<int>&);
using TryIncrementWorkerRefCountFunc = bool (*)(bool);
using TryReserveWorkerFunc = bool (*)(int /* process_id */,
mojom::SharedWorkerFactoryPtrInfo*);
// Pair of render_process_id and worker_route_id.
using ProcessRouteIdPair = std::pair<int, int>;
using WorkerHostMap =
std::map<ProcessRouteIdPair, std::unique_ptr<SharedWorkerHost>>;
using WorkerID = std::pair<int /* process_id */, int /* route_id */>;
using WorkerHostMap = std::map<WorkerID, std::unique_ptr<SharedWorkerHost>>;
using PendingInstanceMap =
std::map<int, std::unique_ptr<SharedWorkerPendingInstance>>;
......@@ -103,7 +92,7 @@ class CONTENT_EXPORT SharedWorkerServiceImpl : public WorkerService {
void ResetForTesting();
scoped_refptr<SharedWorkerMessageFilter> GetFilter(int render_process_id);
SharedWorkerMessageFilter* GetFilter(int render_process_id);
// Reserves the render process to create Shared Worker. This reservation
// procedure will be executed on UI thread and
......@@ -118,19 +107,21 @@ class CONTENT_EXPORT SharedWorkerServiceImpl : public WorkerService {
int worker_process_id,
int worker_route_id,
bool is_new_worker,
mojom::SharedWorkerFactoryPtrInfo factory,
bool pause_on_start);
// Called after the fast shutdown is detected while reserving the render
// process to create Shared Worker in it.
void RenderProcessReserveFailedCallback(int pending_instance_id,
int worker_process_id,
int worker_route_id,
bool is_new_worker,
bool pause_on_start);
void RenderProcessReserveFailedCallback(
int pending_instance_id,
int worker_process_id,
int worker_route_id,
bool is_new_worker,
mojom::SharedWorkerFactoryPtrInfo factory,
bool pause_on_start);
// Returns nullptr if there is no host for given ids.
SharedWorkerHost* FindSharedWorkerHost(int render_process_id,
int worker_route_id);
SharedWorkerHost* FindSharedWorkerHost(int process_id, int route_id);
SharedWorkerHost* FindSharedWorkerHost(const SharedWorkerInstance& instance);
SharedWorkerPendingInstance* FindPendingInstance(
......@@ -142,14 +133,14 @@ class CONTENT_EXPORT SharedWorkerServiceImpl : public WorkerService {
void ChangeUpdateWorkerDependencyFuncForTesting(
UpdateWorkerDependencyFunc new_func);
void ChangeTryIncrementWorkerRefCountFuncForTesting(bool (*new_func)(int));
void ChangeTryReserveWorkerFuncForTesting(TryReserveWorkerFunc new_func);
std::set<int> last_worker_depended_renderers_;
// Function ptr to update worker dependency, tests may override this.
UpdateWorkerDependencyFunc update_worker_dependency_;
// Function ptr to increment worker ref count, tests may override this.
static bool (*s_try_increment_worker_ref_count_)(int);
// Function ptr to reserve worker on UI thread, tests may override this.
static TryReserveWorkerFunc s_try_reserve_worker_func_;
WorkerHostMap worker_hosts_;
PendingInstanceMap pending_instances_;
......
......@@ -367,7 +367,6 @@ source_set("common") {
"user_agent.cc",
"view_message_enums.h",
"view_messages.h",
"worker_messages.h",
"zygote_commands_linux.h",
]
......@@ -658,8 +657,12 @@ mojom("mojo_bindings") {
"service_worker/service_worker_installed_scripts_manager.mojom",
"service_worker/service_worker_provider.mojom",
"service_worker/service_worker_types.mojom",
"shared_worker/shared_worker.mojom",
"shared_worker/shared_worker_client.mojom",
"shared_worker/shared_worker_connector.mojom",
"shared_worker/shared_worker_factory.mojom",
"shared_worker/shared_worker_host.mojom",
"shared_worker/shared_worker_info.mojom",
"storage_partition_service.mojom",
"video_capture.mojom",
"web_database.mojom",
......
......@@ -167,11 +167,6 @@
#ifndef CONTENT_COMMON_VIEW_MESSAGES_H_
#error "Failed to include content/common/view_messages.h"
#endif
#undef CONTENT_COMMON_WORKER_MESSAGES_H_
#include "content/common/worker_messages.h"
#ifndef CONTENT_COMMON_WORKER_MESSAGES_H_
#error "Failed to include content/common/worker_messages.h"
#endif
#include "media/media_features.h"
#if BUILDFLAG(ENABLE_WEBRTC)
......
// Copyright 2017 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 content.mojom;
// Interface used by the host to control the shared worker.
interface SharedWorker {
// Called to establish a new client connection to the shared worker. The
// |connection_id| parameter will be echoed back to the host via the
// OnConnected method.
Connect(int32 connection_id, handle<message_pipe> message_port);
// Called to terminate the shared worker. This results in the shared worker
// closing its end of the mojo connection.
Terminate();
};
......@@ -5,20 +5,8 @@
module content.mojom;
import "content/common/shared_worker/shared_worker_client.mojom";
import "third_party/WebKit/public/platform/address_space.mojom";
import "third_party/WebKit/public/platform/content_security_policy.mojom";
import "content/common/shared_worker/shared_worker_info.mojom";
import "third_party/WebKit/public/web/shared_worker_creation_context_type.mojom";
import "url/mojo/url.mojom";
struct SharedWorkerInfo {
url.mojom.Url url;
string name;
string content_security_policy;
blink.mojom.ContentSecurityPolicyType content_security_policy_type;
blink.mojom.AddressSpace creation_address_space;
blink.mojom.SharedWorkerCreationContextType creation_context_type;
bool data_saver_enabled;
};
// This interface is exposed to enable a client to create and connect to a
// shared worker.
......@@ -27,5 +15,6 @@ interface SharedWorkerConnector {
// The SharedWorker will be terminated if all clients go away.
Connect(SharedWorkerInfo info,
SharedWorkerClient client,
blink.mojom.SharedWorkerCreationContextType creation_context_type,
handle<message_pipe> message_port);
};
// Copyright 2017 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 content.mojom;
import "content/common/shared_worker/shared_worker.mojom";
import "content/common/shared_worker/shared_worker_host.mojom";
import "content/common/shared_worker/shared_worker_info.mojom";
import "third_party/WebKit/public/web/worker_content_settings_proxy.mojom";
// This interface is used to instantiate a shared worker. It is exported from a
// child process where the shared worker should run.
interface SharedWorkerFactory {
// Create a new shared worker. The |host| interface receives events from the
// shared worker.
//
// TODO(darin): Eliminate |route_id| corresponding to legacy Chrome IPC,
// which is only needed for DevTools.
//
CreateSharedWorker(SharedWorkerInfo info,
bool pause_on_start,
int32 route_id,
blink.mojom.WorkerContentSettingsProxy content_settings,
SharedWorkerHost host,
SharedWorker& shared_worker);
};
// Copyright 2017 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 content.mojom;
import "third_party/WebKit/public/platform/web_feature.mojom";
// Each shared worker has a corresponding host. The host controls the lifetime
// of the shared worker. This interface is used by the shared worker to talk to
// its host.
interface SharedWorkerHost {
// Called in response to SharedWorker's Connect method. The |connection_id|
// parameter is the same value passed to the Connect method.
OnConnected(int32 connection_id);
// Indicates that the shared worker self-closed. This should trigger the host
// to terminate the shared worker.
OnContextClosed();
// Indicates that the shared worker is ready for inspection.
OnReadyForInspection();
// Indicates that the script successfully loaded.
OnScriptLoaded();
// Indicates that the script failed to load.
OnScriptLoadFailed();
// Indicates that the shared worker used a feature. This is intended to be
// logged by the client-side feature logging infrastructure.
OnFeatureUsed(blink.mojom.WebFeature feature);
};
// Copyright 2017 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 content.mojom;
import "third_party/WebKit/public/platform/address_space.mojom";
import "third_party/WebKit/public/platform/content_security_policy.mojom";
import "url/mojo/url.mojom";
// Meta data that is necessary to create a new shared worker context. This
// structure gets populated when a new SharedWorker object is created in the
// parent context (e.g. Document), and passed onto the destination child
// process where the shared worker runs.
struct SharedWorkerInfo {
url.mojom.Url url;
string name;
string content_security_policy;
blink.mojom.ContentSecurityPolicyType content_security_policy_type;
blink.mojom.AddressSpace creation_address_space;
bool data_saver_enabled;
};
// Copyright (c) 2012 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.
#ifndef CONTENT_COMMON_WORKER_MESSAGES_H_
#define CONTENT_COMMON_WORKER_MESSAGES_H_
// Defines messages between the browser and worker process, as well as between
// the renderer and worker process.
#include <string>
#include <utility>
#include <vector>
#include "base/strings/string16.h"
#include "content/common/content_export.h"
#include "content/common/content_param_traits.h"
#include "content/common/message_port.h"
#include "ipc/ipc_message_macros.h"
#include "ipc/ipc_message_utils.h"
#include "mojo/public/cpp/system/handle.h"
#include "mojo/public/cpp/system/message_pipe.h"
#include "url/gurl.h"
#undef IPC_MESSAGE_EXPORT
#define IPC_MESSAGE_EXPORT CONTENT_EXPORT
#define IPC_MESSAGE_START WorkerMsgStart
// Parameter structure for WorkerProcessMsg_CreateWorker.
IPC_STRUCT_BEGIN(WorkerProcessMsg_CreateWorker_Params)
IPC_STRUCT_MEMBER(GURL, url)
IPC_STRUCT_MEMBER(base::string16, name)
IPC_STRUCT_MEMBER(base::string16, content_security_policy)
IPC_STRUCT_MEMBER(blink::WebContentSecurityPolicyType, security_policy_type)
IPC_STRUCT_MEMBER(blink::WebAddressSpace, creation_address_space)
IPC_STRUCT_MEMBER(bool, pause_on_start)
IPC_STRUCT_MEMBER(int, route_id)
IPC_STRUCT_MEMBER(bool, data_saver_enabled)
// For blink::mojom::SharedWorkerContentSettingsProxy
IPC_STRUCT_MEMBER(mojo::MessagePipeHandle, content_settings_handle)
IPC_STRUCT_END()
//-----------------------------------------------------------------------------
// WorkerProcess messages
// These are messages sent from the browser to the worker process.
IPC_MESSAGE_CONTROL1(WorkerProcessMsg_CreateWorker,
WorkerProcessMsg_CreateWorker_Params)
//-----------------------------------------------------------------------------
// Worker messages
// These are messages sent from the renderer process to the worker process.
IPC_MESSAGE_ROUTED0(WorkerMsg_TerminateWorkerContext)
IPC_MESSAGE_ROUTED2(WorkerMsg_Connect,
int /* connection_request_id */,
content::MessagePort /* sent_message_port */)
IPC_MESSAGE_ROUTED0(WorkerMsg_WorkerObjectDestroyed)
//-----------------------------------------------------------------------------
// WorkerHost messages
// These are messages sent from the worker (renderer process) to the worker
// host (browser process).
// Sent when the worker calls API that should be recored in UseCounter.
// |feature| must be one of the values from blink::UseCounter::Feature
// enum.
IPC_MESSAGE_CONTROL2(WorkerHostMsg_CountFeature,
int /* worker_route_id */,
uint32_t /* feature */)
IPC_MESSAGE_CONTROL1(WorkerHostMsg_WorkerContextClosed,
int /* worker_route_id */)
IPC_MESSAGE_CONTROL1(WorkerHostMsg_WorkerContextDestroyed,
int /* worker_route_id */)
// Renderer -> Browser message to indicate that the worker is ready for
// inspection.
IPC_MESSAGE_CONTROL1(WorkerHostMsg_WorkerReadyForInspection,
int /* worker_route_id */)
IPC_MESSAGE_CONTROL1(WorkerHostMsg_WorkerScriptLoaded,
int /* worker_route_id */)
IPC_MESSAGE_CONTROL1(WorkerHostMsg_WorkerScriptLoadFailed,
int /* worker_route_id */)
IPC_MESSAGE_CONTROL2(WorkerHostMsg_WorkerConnected,
int /* connection_request_id */,
int /* worker_route_id */)
#endif // CONTENT_COMMON_WORKER_MESSAGES_H_
......@@ -10,6 +10,7 @@
"content::mojom::EmbeddedWorkerSetup",
"content::mojom::FrameFactory",
"content::mojom::RenderWidgetWindowTreeClientFactory",
"content::mojom::SharedWorkerFactory",
"content::mojom::WebDatabase",
"IPC::mojom::ChannelBootstrap",
"visitedlink::mojom::VisitedLinkNotificationSink",
......
......@@ -373,6 +373,8 @@ target(link_target_type, "renderer") {
"shared_worker/embedded_shared_worker_stub.h",
"shared_worker/shared_worker_client_impl.cc",
"shared_worker/shared_worker_client_impl.h",
"shared_worker/shared_worker_factory_impl.cc",
"shared_worker/shared_worker_factory_impl.h",
"shared_worker/shared_worker_repository.cc",
"shared_worker/shared_worker_repository.h",
"skia_benchmarking_extension.cc",
......
......@@ -85,7 +85,6 @@
#include "content/common/resource_messages.h"
#include "content/common/site_isolation_policy.h"
#include "content/common/view_messages.h"
#include "content/common/worker_messages.h"
#include "content/public/common/content_constants.h"
#include "content/public/common/content_features.h"
#include "content/public/common/content_paths.h"
......@@ -134,6 +133,7 @@
#include "content/renderer/service_worker/service_worker_context_client.h"
#include "content/renderer/service_worker/service_worker_context_message_filter.h"
#include "content/renderer/shared_worker/embedded_shared_worker_stub.h"
#include "content/renderer/shared_worker/shared_worker_factory_impl.h"
#include "device/gamepad/public/cpp/gamepads.h"
#include "gin/public/debug.h"
#include "gpu/GLES2/gl2extchromium.h"
......@@ -751,26 +751,34 @@ void RenderThreadImpl::Init(
AddFilter((new ServiceWorkerContextMessageFilter())->GetFilter());
// Register exported services:
#if defined(USE_AURA)
if (IsRunningInMash()) {
CreateRenderWidgetWindowTreeClientFactory(GetServiceManagerConnection());
}
#endif
auto registry = base::MakeUnique<service_manager::BinderRegistry>();
registry->AddInterface(base::Bind(&WebDatabaseImpl::Create),
GetIOTaskRunner());
GetServiceManagerConnection()->AddConnectionFilter(
base::MakeUnique<SimpleConnectionFilter>(std::move(registry)));
auto registry_with_source_info =
base::MakeUnique<service_manager::BinderRegistryWithArgs<
const service_manager::BindSourceInfo&>>();
registry_with_source_info->AddInterface(base::Bind(&CreateFrameFactory),
base::ThreadTaskRunnerHandle::Get());
GetServiceManagerConnection()->AddConnectionFilter(
base::MakeUnique<SimpleConnectionFilterWithSourceInfo>(
std::move(registry_with_source_info)));
{
auto registry = std::make_unique<service_manager::BinderRegistry>();
registry->AddInterface(base::Bind(&WebDatabaseImpl::Create),
GetIOTaskRunner());
registry->AddInterface(base::Bind(&SharedWorkerFactoryImpl::Create),
base::ThreadTaskRunnerHandle::Get());
GetServiceManagerConnection()->AddConnectionFilter(
std::make_unique<SimpleConnectionFilter>(std::move(registry)));
}
{
auto registry_with_source_info =
base::MakeUnique<service_manager::BinderRegistryWithArgs<
const service_manager::BindSourceInfo&>>();
registry_with_source_info->AddInterface(
base::Bind(&CreateFrameFactory), base::ThreadTaskRunnerHandle::Get());
GetServiceManagerConnection()->AddConnectionFilter(
base::MakeUnique<SimpleConnectionFilterWithSourceInfo>(
std::move(registry_with_source_info)));
}
GetContentClient()->renderer()->RenderThreadStarted();
......@@ -1682,13 +1690,7 @@ bool RenderThreadImpl::OnControlMessageReceived(const IPC::Message& msg) {
dom_storage_dispatcher_->OnMessageReceived(msg)) {
return true;
}
bool handled = true;
IPC_BEGIN_MESSAGE_MAP(RenderThreadImpl, msg)
IPC_MESSAGE_HANDLER(WorkerProcessMsg_CreateWorker, OnCreateNewSharedWorker)
IPC_MESSAGE_UNHANDLED(handled = false)
IPC_END_MESSAGE_MAP()
return handled;
return false;
}
void RenderThreadImpl::OnProcessBackgrounded(bool backgrounded) {
......@@ -2288,16 +2290,6 @@ void RenderThreadImpl::PurgePluginListCache(bool reload_pages) {
#endif
}
void RenderThreadImpl::OnCreateNewSharedWorker(
const WorkerProcessMsg_CreateWorker_Params& params) {
// EmbeddedSharedWorkerStub will self-destruct.
new EmbeddedSharedWorkerStub(
params.url, params.name, params.content_security_policy,
params.security_policy_type, params.creation_address_space,
params.pause_on_start, params.route_id, params.data_saver_enabled,
mojo::ScopedMessagePipeHandle(params.content_settings_handle));
}
void RenderThreadImpl::OnMemoryPressure(
base::MemoryPressureListener::MemoryPressureLevel memory_pressure_level) {
TRACE_EVENT0("memory","RenderThreadImpl::OnMemoryPressure");
......
......@@ -63,7 +63,6 @@
#endif
class SkBitmap;
struct WorkerProcessMsg_CreateWorker_Params;
namespace blink {
namespace scheduler {
......@@ -580,8 +579,6 @@ class CONTENT_EXPORT RenderThreadImpl
void OnMemoryPressure(
base::MemoryPressureListener::MemoryPressureLevel memory_pressure_level);
void OnCreateNewSharedWorker(
const WorkerProcessMsg_CreateWorker_Params& params);
bool RendererIsHidden() const;
void OnRendererHidden();
void OnRendererVisible();
......
......@@ -18,7 +18,6 @@
#include "content/child/service_worker/service_worker_provider_context.h"
#include "content/child/shared_worker_devtools_agent.h"
#include "content/child/webmessageportchannel_impl.h"
#include "content/common/worker_messages.h"
#include "content/public/child/child_url_loader_factory_getter.h"
#include "content/public/common/appcache_info.h"
#include "content/public/common/content_features.h"
......@@ -127,16 +126,17 @@ class WebServiceWorkerNetworkProviderForSharedWorker
} // namespace
EmbeddedSharedWorkerStub::EmbeddedSharedWorkerStub(
const GURL& url,
const base::string16& name,
const base::string16& content_security_policy,
blink::WebContentSecurityPolicyType security_policy_type,
blink::WebAddressSpace creation_address_space,
mojom::SharedWorkerInfoPtr info,
bool pause_on_start,
int route_id,
bool data_saver_enabled,
mojo::ScopedMessagePipeHandle content_settings_handle)
: route_id_(route_id), name_(name), url_(url) {
blink::mojom::WorkerContentSettingsProxyPtr content_settings,
mojom::SharedWorkerHostPtr host,
mojom::SharedWorkerRequest request)
: binding_(this, std::move(request)),
host_(std::move(host)),
route_id_(route_id),
name_(info->name),
url_(info->url) {
RenderThreadImpl::current()->AddEmbeddedWorkerRoute(route_id_, this);
impl_ = blink::WebSharedWorker::Create(this);
if (pause_on_start) {
......@@ -147,10 +147,14 @@ EmbeddedSharedWorkerStub::EmbeddedSharedWorkerStub(
worker_devtools_agent_.reset(
new SharedWorkerDevToolsAgent(route_id, impl_));
impl_->StartWorkerContext(
url, blink::WebString::FromUTF16(name_),
blink::WebString::FromUTF16(content_security_policy),
security_policy_type, creation_address_space, data_saver_enabled,
std::move(content_settings_handle));
url_, blink::WebString::FromUTF8(name_),
blink::WebString::FromUTF8(info->content_security_policy),
info->content_security_policy_type, info->creation_address_space,
info->data_saver_enabled, content_settings.PassInterface().PassHandle());
// If the host drops its connection, then self-destruct.
binding_.set_connection_error_handler(base::BindOnce(
&EmbeddedSharedWorkerStub::Terminate, base::Unretained(this)));
}
EmbeddedSharedWorkerStub::~EmbeddedSharedWorkerStub() {
......@@ -158,30 +162,21 @@ EmbeddedSharedWorkerStub::~EmbeddedSharedWorkerStub() {
DCHECK(!impl_);
}
bool EmbeddedSharedWorkerStub::OnMessageReceived(
const IPC::Message& message) {
if (worker_devtools_agent_->OnMessageReceived(message))
return true;
bool handled = true;
IPC_BEGIN_MESSAGE_MAP(EmbeddedSharedWorkerStub, message)
IPC_MESSAGE_HANDLER(WorkerMsg_TerminateWorkerContext,
OnTerminateWorkerContext)
IPC_MESSAGE_HANDLER(WorkerMsg_Connect, OnConnect)
IPC_MESSAGE_UNHANDLED(handled = false)
IPC_END_MESSAGE_MAP()
return handled;
bool EmbeddedSharedWorkerStub::OnMessageReceived(const IPC::Message& message) {
// Just a simply pass-through for now until we can rework the DevTools IPC.
return worker_devtools_agent_->OnMessageReceived(message);
}
void EmbeddedSharedWorkerStub::OnChannelError() {
OnTerminateWorkerContext();
Terminate();
}
void EmbeddedSharedWorkerStub::WorkerReadyForInspection() {
Send(new WorkerHostMsg_WorkerReadyForInspection(route_id_));
host_->OnReadyForInspection();
}
void EmbeddedSharedWorkerStub::WorkerScriptLoaded() {
Send(new WorkerHostMsg_WorkerScriptLoaded(route_id_));
host_->OnScriptLoaded();
running_ = true;
// Process any pending connections.
for (auto& item : pending_channels_)
......@@ -190,21 +185,20 @@ void EmbeddedSharedWorkerStub::WorkerScriptLoaded() {
}
void EmbeddedSharedWorkerStub::WorkerScriptLoadFailed() {
Send(new WorkerHostMsg_WorkerScriptLoadFailed(route_id_));
host_->OnScriptLoadFailed();
pending_channels_.clear();
Shutdown();
}
void EmbeddedSharedWorkerStub::CountFeature(uint32_t feature) {
Send(new WorkerHostMsg_CountFeature(route_id_, feature));
void EmbeddedSharedWorkerStub::CountFeature(blink::mojom::WebFeature feature) {
host_->OnFeatureUsed(feature);
}
void EmbeddedSharedWorkerStub::WorkerContextClosed() {
Send(new WorkerHostMsg_WorkerContextClosed(route_id_));
host_->OnContextClosed();
}
void EmbeddedSharedWorkerStub::WorkerContextDestroyed() {
Send(new WorkerHostMsg_WorkerContextDestroyed(route_id_));
Shutdown();
}
......@@ -303,36 +297,35 @@ void EmbeddedSharedWorkerStub::Shutdown() {
// WebSharedWorker must be already deleted in the blink side
// when this is called.
impl_ = nullptr;
delete this;
}
bool EmbeddedSharedWorkerStub::Send(IPC::Message* message) {
return RenderThreadImpl::current()->Send(message);
// This closes our connection to the host, triggering the host to cleanup and
// notify clients of this worker going away.
delete this;
}
void EmbeddedSharedWorkerStub::ConnectToChannel(
int connection_request_id,
std::unique_ptr<WebMessagePortChannelImpl> channel) {
impl_->Connect(std::move(channel));
Send(new WorkerHostMsg_WorkerConnected(connection_request_id, route_id_));
host_->OnConnected(connection_request_id);
}
void EmbeddedSharedWorkerStub::OnConnect(int connection_request_id,
const MessagePort& port) {
auto channel = base::MakeUnique<WebMessagePortChannelImpl>(port);
void EmbeddedSharedWorkerStub::Connect(int connection_request_id,
mojo::ScopedMessagePipeHandle port) {
auto channel =
std::make_unique<WebMessagePortChannelImpl>(MessagePort(std::move(port)));
if (running_) {
ConnectToChannel(connection_request_id, std::move(channel));
} else {
// If two documents try to load a SharedWorker at the same time, the
// WorkerMsg_Connect for one of the documents can come in before the
// worker is started. Just queue up the connect and deliver it once the
// worker starts.
pending_channels_.emplace_back(
std::make_pair(connection_request_id, std::move(channel)));
// mojom::SharedWorker::Connect() for one of the documents can come in
// before the worker is started. Just queue up the connect and deliver it
// once the worker starts.
pending_channels_.emplace_back(connection_request_id, std::move(channel));
}
}
void EmbeddedSharedWorkerStub::OnTerminateWorkerContext() {
void EmbeddedSharedWorkerStub::Terminate() {
// After this we wouldn't get any IPC for this stub.
running_ = false;
impl_->TerminateWorkerContext();
......
......@@ -11,13 +11,17 @@
#include "base/macros.h"
#include "content/child/child_message_filter.h"
#include "content/child/scoped_child_process_reference.h"
#include "content/common/shared_worker/shared_worker.mojom.h"
#include "content/common/shared_worker/shared_worker_host.mojom.h"
#include "content/common/shared_worker/shared_worker_info.mojom.h"
#include "ipc/ipc_listener.h"
#include "mojo/public/cpp/system/message_pipe.h"
#include "mojo/public/cpp/bindings/binding.h"
#include "third_party/WebKit/public/platform/WebAddressSpace.h"
#include "third_party/WebKit/public/platform/WebContentSecurityPolicy.h"
#include "third_party/WebKit/public/platform/WebContentSettingsClient.h"
#include "third_party/WebKit/public/platform/WebString.h"
#include "third_party/WebKit/public/web/WebSharedWorkerClient.h"
#include "third_party/WebKit/public/web/worker_content_settings_proxy.mojom.h"
#include "url/gurl.h"
namespace blink {
......@@ -28,7 +32,6 @@ class WebSharedWorker;
}
namespace content {
class MessagePort;
class SharedWorkerDevToolsAgent;
class WebApplicationCacheHostImpl;
class WebMessagePortChannelImpl;
......@@ -44,25 +47,24 @@ class WebMessagePortChannelImpl;
// In either case the corresponding blink::WebSharedWorker also deletes
// itself.
class EmbeddedSharedWorkerStub : public IPC::Listener,
public blink::WebSharedWorkerClient {
public blink::WebSharedWorkerClient,
public mojom::SharedWorker {
public:
EmbeddedSharedWorkerStub(
const GURL& url,
const base::string16& name,
const base::string16& content_security_policy,
blink::WebContentSecurityPolicyType security_policy_type,
blink::WebAddressSpace creation_address_space,
mojom::SharedWorkerInfoPtr info,
bool pause_on_start,
int route_id,
bool data_saver_enabled,
mojo::ScopedMessagePipeHandle content_settings_handle);
blink::mojom::WorkerContentSettingsProxyPtr content_settings,
mojom::SharedWorkerHostPtr host,
mojom::SharedWorkerRequest request);
~EmbeddedSharedWorkerStub() override;
// IPC::Listener implementation.
bool OnMessageReceived(const IPC::Message& message) override;
void OnChannelError() override;
// blink::WebSharedWorkerClient implementation.
void CountFeature(uint32_t feature) override;
void CountFeature(blink::mojom::WebFeature feature) override;
void WorkerContextClosed() override;
void WorkerContextDestroyed() override;
void WorkerReadyForInspection() override;
......@@ -84,21 +86,21 @@ class EmbeddedSharedWorkerStub : public IPC::Listener,
blink::WebServiceWorkerNetworkProvider*) override;
private:
~EmbeddedSharedWorkerStub() override;
void Shutdown();
bool Send(IPC::Message* message);
// WebSharedWorker will own |channel|.
void ConnectToChannel(int connection_request_id,
std::unique_ptr<WebMessagePortChannelImpl> channel);
void OnConnect(int connection_request_id,
const MessagePort& sent_message_port);
void OnTerminateWorkerContext();
// mojom::SharedWorker methods:
void Connect(int connection_request_id,
mojo::ScopedMessagePipeHandle port) override;
void Terminate() override;
int route_id_;
base::string16 name_;
mojo::Binding<mojom::SharedWorker> binding_;
mojom::SharedWorkerHostPtr host_;
const int route_id_;
const std::string name_;
bool running_ = false;
GURL url_;
blink::WebSharedWorker* impl_ = nullptr;
......
// Copyright 2017 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.
#include "content/renderer/shared_worker/shared_worker_factory_impl.h"
#include "base/memory/ptr_util.h"
#include "content/renderer/shared_worker/embedded_shared_worker_stub.h"
#include "mojo/public/cpp/bindings/strong_binding.h"
namespace content {
// static
void SharedWorkerFactoryImpl::Create(
mojom::SharedWorkerFactoryRequest request) {
mojo::MakeStrongBinding<mojom::SharedWorkerFactory>(
base::WrapUnique(new SharedWorkerFactoryImpl()), std::move(request));
}
SharedWorkerFactoryImpl::SharedWorkerFactoryImpl() {}
void SharedWorkerFactoryImpl::CreateSharedWorker(
mojom::SharedWorkerInfoPtr info,
bool pause_on_start,
int32_t route_id,
blink::mojom::WorkerContentSettingsProxyPtr content_settings,
mojom::SharedWorkerHostPtr host,
mojom::SharedWorkerRequest request) {
// Bound to the lifetime of the underlying blink::WebSharedWorker instance.
new EmbeddedSharedWorkerStub(std::move(info), pause_on_start, route_id,
std::move(content_settings), std::move(host),
std::move(request));
}
} // namespace content
// Copyright 2017 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.
#ifndef CONTENT_RENDERER_SHARED_WORKER_SHARED_WORKER_FACTORY_IMPL_H_
#define CONTENT_RENDERER_SHARED_WORKER_SHARED_WORKER_FACTORY_IMPL_H_
#include "base/macros.h"
#include "content/common/shared_worker/shared_worker_factory.mojom.h"
namespace content {
class SharedWorkerFactoryImpl : public mojom::SharedWorkerFactory {
public:
static void Create(mojom::SharedWorkerFactoryRequest request);
private:
SharedWorkerFactoryImpl();
// mojom::SharedWorkerFactory methods:
void CreateSharedWorker(
mojom::SharedWorkerInfoPtr info,
bool pause_on_start,
int32_t route_id,
blink::mojom::WorkerContentSettingsProxyPtr content_settings,
mojom::SharedWorkerHostPtr host,
mojom::SharedWorkerRequest request) override;
DISALLOW_COPY_AND_ASSIGN(SharedWorkerFactoryImpl);
};
} // namespace content
#endif // CONTENT_RENDERER_SHARED_WORKER_SHARED_WORKER_FACTORY_IMPL_H_
......@@ -36,14 +36,14 @@ void SharedWorkerRepository::Connect(
mojom::SharedWorkerInfoPtr info(mojom::SharedWorkerInfo::New(
url, name.Utf8(), content_security_policy.Utf8(),
content_security_policy_type, creation_address_space,
creation_context_type, data_saver_enabled));
data_saver_enabled));
mojom::SharedWorkerClientPtr client;
AddWorker(document_id,
std::make_unique<SharedWorkerClientImpl>(std::move(listener)),
mojo::MakeRequest(&client));
connector_->Connect(std::move(info), std::move(client),
connector_->Connect(std::move(info), std::move(client), creation_context_type,
static_cast<WebMessagePortChannelImpl*>(channel.get())
->ReleaseMessagePort()
.ReleaseHandle());
......
......@@ -163,7 +163,7 @@ WebSharedWorkerImpl::CreateClientMessageLoop() {
void WebSharedWorkerImpl::CountFeature(WebFeature feature) {
DCHECK(IsMainThread());
client_->CountFeature(static_cast<uint32_t>(feature));
client_->CountFeature(feature);
}
void WebSharedWorkerImpl::PostMessageToPageInspector(int session_id,
......
......@@ -34,6 +34,7 @@
#include "public/platform/WebContentSettingsClient.h"
#include "public/platform/WebMessagePortChannel.h"
#include "public/platform/WebWorkerFetchContext.h"
#include "public/platform/web_feature.mojom-shared.h"
#include "public/web/WebDevToolsAgentClient.h"
namespace blink {
......@@ -52,7 +53,7 @@ class WebString;
// or workerContextDestroyed() is called).
class WebSharedWorkerClient {
public:
virtual void CountFeature(uint32_t) = 0;
virtual void CountFeature(mojom::WebFeature) = 0;
virtual void WorkerContextClosed() = 0;
virtual void WorkerContextDestroyed() = 0;
virtual void WorkerReadyForInspection() {}
......
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