Commit 4882d426 authored by Han Leon's avatar Han Leon Committed by Commit Bot

[OnionSoup] Move blink.mojom.ServiceWorkerHost endpoint into Blink

This CL moves the blink::mojom::ServiceWorkerHostAssociatedPtr from
Content into Blink, now Blink can use it directly to do IPCs rather than
requesting Content to do so via public Web interfaces.

To avoid too big a CL, this CL tries to do the movement only and is
leaving some refactoring work as TODOs, i.e. some public Web
structs/callbacks no longer need to cross the boundary of Content and
Blink, so some of them should be just removed and some should be hidden
inside Blink. Follow-up CLs will do these cleanup.

BUG=789857

Change-Id: I080e3f40b4f1e5a79cf37cd62bc6e8d3172b54c4
Reviewed-on: https://chromium-review.googlesource.com/1214709
Commit-Queue: Leon Han <leon.han@intel.com>
Reviewed-by: default avatarMakoto Shimazu <shimazu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#591218}
parent fda5c221
...@@ -70,7 +70,7 @@ ...@@ -70,7 +70,7 @@
#include "third_party/blink/public/platform/modules/notifications/web_notification_data.h" #include "third_party/blink/public/platform/modules/notifications/web_notification_data.h"
#include "third_party/blink/public/platform/modules/payments/web_payment_handler_response.h" #include "third_party/blink/public/platform/modules/payments/web_payment_handler_response.h"
#include "third_party/blink/public/platform/modules/payments/web_payment_request_event_data.h" #include "third_party/blink/public/platform/modules/payments/web_payment_request_event_data.h"
#include "third_party/blink/public/platform/modules/service_worker/web_service_worker_client_query_options.h" #include "third_party/blink/public/platform/modules/service_worker/web_service_worker_clients_info.h"
#include "third_party/blink/public/platform/modules/service_worker/web_service_worker_error.h" #include "third_party/blink/public/platform/modules/service_worker/web_service_worker_error.h"
#include "third_party/blink/public/platform/modules/service_worker/web_service_worker_network_provider.h" #include "third_party/blink/public/platform/modules/service_worker/web_service_worker_network_provider.h"
#include "third_party/blink/public/platform/modules/service_worker/web_service_worker_request.h" #include "third_party/blink/public/platform/modules/service_worker/web_service_worker_request.h"
...@@ -336,108 +336,6 @@ base::OnceCallback<void(int /* event_id */)> CreateAbortCallback(MapType* map, ...@@ -336,108 +336,6 @@ base::OnceCallback<void(int /* event_id */)> CreateAbortCallback(MapType* map,
map, std::forward<Args>(args)..., base::Time::Now()); map, std::forward<Args>(args)..., base::Time::Now());
} }
void DidGetClients(
std::unique_ptr<blink::WebServiceWorkerClientsCallbacks> callbacks,
std::vector<blink::mojom::ServiceWorkerClientInfoPtr> clients) {
blink::WebServiceWorkerClientsInfo info;
blink::WebVector<blink::WebServiceWorkerClientInfo> web_clients(
clients.size());
for (size_t i = 0; i < clients.size(); ++i)
web_clients[i] = ToWebServiceWorkerClientInfo(std::move(clients[i]));
info.clients.Swap(web_clients);
callbacks->OnSuccess(info);
}
void DidClaimClients(
std::unique_ptr<blink::WebServiceWorkerClientsClaimCallbacks> callbacks,
blink::mojom::ServiceWorkerErrorType error,
const base::Optional<std::string>& error_msg) {
if (error != blink::mojom::ServiceWorkerErrorType::kNone) {
callbacks->OnError(blink::WebServiceWorkerError(
error, blink::WebString::FromUTF8(*error_msg)));
return;
}
DCHECK(!error_msg);
callbacks->OnSuccess();
}
void DidGetClient(
std::unique_ptr<blink::WebServiceWorkerClientCallbacks> callbacks,
blink::mojom::ServiceWorkerClientInfoPtr client) {
std::unique_ptr<blink::WebServiceWorkerClientInfo> web_client;
if (client) {
web_client = std::make_unique<blink::WebServiceWorkerClientInfo>(
ToWebServiceWorkerClientInfo(std::move(client)));
}
callbacks->OnSuccess(std::move(web_client));
}
void DidSkipWaiting(
std::unique_ptr<blink::WebServiceWorkerSkipWaitingCallbacks> callbacks,
bool success) {
// OnError() should not be called here since per spec the promise returned by
// skipWaiting() can never reject.
if (!success)
return;
callbacks->OnSuccess();
}
void DidOpenWindow(
std::unique_ptr<blink::WebServiceWorkerClientCallbacks> callbacks,
bool success,
blink::mojom::ServiceWorkerClientInfoPtr client,
const base::Optional<std::string>& error_msg) {
if (!success) {
DCHECK(!client);
callbacks->OnError(blink::WebServiceWorkerError(
blink::mojom::ServiceWorkerErrorType::kNavigation,
blink::WebString::FromUTF8(*error_msg)));
return;
}
std::unique_ptr<blink::WebServiceWorkerClientInfo> web_client;
if (client) {
web_client = std::make_unique<blink::WebServiceWorkerClientInfo>(
ToWebServiceWorkerClientInfo(std::move(client)));
}
callbacks->OnSuccess(std::move(web_client));
}
void DidFocusClient(
std::unique_ptr<blink::WebServiceWorkerClientCallbacks> callbacks,
blink::mojom::ServiceWorkerClientInfoPtr client) {
if (!client) {
callbacks->OnError(blink::WebServiceWorkerError(
blink::mojom::ServiceWorkerErrorType::kNotFound,
"The client was not found."));
return;
}
auto web_client = std::make_unique<blink::WebServiceWorkerClientInfo>(
ToWebServiceWorkerClientInfo(std::move(client)));
callbacks->OnSuccess(std::move(web_client));
}
void DidNavigateClient(
std::unique_ptr<blink::WebServiceWorkerClientCallbacks> callbacks,
bool success,
blink::mojom::ServiceWorkerClientInfoPtr client,
const base::Optional<std::string>& error_msg) {
if (!success) {
DCHECK(!client);
callbacks->OnError(blink::WebServiceWorkerError(
blink::mojom::ServiceWorkerErrorType::kNavigation,
blink::WebString::FromUTF8(*error_msg)));
return;
}
std::unique_ptr<blink::WebServiceWorkerClientInfo> web_client;
if (client) {
web_client = std::make_unique<blink::WebServiceWorkerClientInfo>(
ToWebServiceWorkerClientInfo(std::move(client)));
}
callbacks->OnSuccess(std::move(web_client));
}
} // namespace } // namespace
// Holding data that needs to be bound to the worker context on the // Holding data that needs to be bound to the worker context on the
...@@ -457,10 +355,6 @@ struct ServiceWorkerContextClient::WorkerContextData { ...@@ -457,10 +355,6 @@ struct ServiceWorkerContextClient::WorkerContextData {
mojo::Binding<mojom::ServiceWorker> service_worker_binding; mojo::Binding<mojom::ServiceWorker> service_worker_binding;
// Bound by the first Mojo call received on the service worker thread
// ServiceWorker::InitializeGlobalScope().
blink::mojom::ServiceWorkerHostAssociatedPtr service_worker_host;
// Maps for inflight event callbacks. // Maps for inflight event callbacks.
// These are mapped from an event id issued from ServiceWorkerTimeoutTimer to // These are mapped from an event id issued from ServiceWorkerTimeoutTimer to
// the Mojo callback to notify the end of the event. // the Mojo callback to notify the end of the event.
...@@ -748,51 +642,6 @@ ServiceWorkerContextClient::GetOrCreateServiceWorkerObject( ...@@ -748,51 +642,6 @@ ServiceWorkerContextClient::GetOrCreateServiceWorkerObject(
std::move(info)); std::move(info));
} }
void ServiceWorkerContextClient::GetClient(
const blink::WebString& id,
std::unique_ptr<blink::WebServiceWorkerClientCallbacks> callbacks) {
DCHECK(callbacks);
context_->service_worker_host->GetClient(
id.Utf8(), base::BindOnce(&DidGetClient, std::move(callbacks)));
}
void ServiceWorkerContextClient::GetClients(
const blink::WebServiceWorkerClientQueryOptions& weboptions,
std::unique_ptr<blink::WebServiceWorkerClientsCallbacks> callbacks) {
DCHECK(callbacks);
auto options = blink::mojom::ServiceWorkerClientQueryOptions::New(
weboptions.include_uncontrolled, weboptions.client_type);
context_->service_worker_host->GetClients(
std::move(options), base::BindOnce(&DidGetClients, std::move(callbacks)));
}
void ServiceWorkerContextClient::OpenNewTab(
const blink::WebURL& url,
std::unique_ptr<blink::WebServiceWorkerClientCallbacks> callbacks) {
DCHECK(callbacks);
context_->service_worker_host->OpenNewTab(
url, base::BindOnce(&DidOpenWindow, std::move(callbacks)));
}
void ServiceWorkerContextClient::OpenPaymentHandlerWindow(
const blink::WebURL& url,
std::unique_ptr<blink::WebServiceWorkerClientCallbacks> callbacks) {
DCHECK(callbacks);
context_->service_worker_host->OpenPaymentHandlerWindow(
url, base::BindOnce(&DidOpenWindow, std::move(callbacks)));
}
void ServiceWorkerContextClient::SetCachedMetadata(const blink::WebURL& url,
const char* data,
size_t size) {
context_->service_worker_host->SetCachedMetadata(
url, std::vector<uint8_t>(data, data + size));
}
void ServiceWorkerContextClient::ClearCachedMetadata(const blink::WebURL& url) {
context_->service_worker_host->ClearCachedMetadata(url);
}
void ServiceWorkerContextClient::WorkerReadyForInspection() { void ServiceWorkerContextClient::WorkerReadyForInspection() {
DCHECK(main_thread_task_runner_->RunsTasksInCurrentSequence()); DCHECK(main_thread_task_runner_->RunsTasksInCurrentSequence());
(*instance_host_)->OnReadyForInspection(); (*instance_host_)->OnReadyForInspection();
...@@ -1417,45 +1266,6 @@ ServiceWorkerContextClient::CreateServiceWorkerProvider() { ...@@ -1417,45 +1266,6 @@ ServiceWorkerContextClient::CreateServiceWorkerProvider() {
provider_context_.get()); provider_context_.get());
} }
void ServiceWorkerContextClient::PostMessageToClient(
const blink::WebString& uuid,
blink::TransferableMessage message) {
context_->service_worker_host->PostMessageToClient(uuid.Utf8(),
std::move(message));
}
void ServiceWorkerContextClient::Focus(
const blink::WebString& uuid,
std::unique_ptr<blink::WebServiceWorkerClientCallbacks> callbacks) {
DCHECK(callbacks);
context_->service_worker_host->FocusClient(
uuid.Utf8(), base::BindOnce(&DidFocusClient, std::move(callbacks)));
}
void ServiceWorkerContextClient::Navigate(
const blink::WebString& uuid,
const blink::WebURL& url,
std::unique_ptr<blink::WebServiceWorkerClientCallbacks> callbacks) {
DCHECK(callbacks);
context_->service_worker_host->NavigateClient(
uuid.Utf8(), url,
base::BindOnce(&DidNavigateClient, std::move(callbacks)));
}
void ServiceWorkerContextClient::SkipWaiting(
std::unique_ptr<blink::WebServiceWorkerSkipWaitingCallbacks> callbacks) {
DCHECK(callbacks);
context_->service_worker_host->SkipWaiting(
base::BindOnce(&DidSkipWaiting, std::move(callbacks)));
}
void ServiceWorkerContextClient::Claim(
std::unique_ptr<blink::WebServiceWorkerClientsClaimCallbacks> callbacks) {
DCHECK(callbacks);
context_->service_worker_host->ClaimClients(
base::BindOnce(&DidClaimClients, std::move(callbacks)));
}
void ServiceWorkerContextClient::DispatchOrQueueFetchEvent( void ServiceWorkerContextClient::DispatchOrQueueFetchEvent(
blink::mojom::DispatchFetchEventParamsPtr params, blink::mojom::DispatchFetchEventParamsPtr params,
blink::mojom::ServiceWorkerFetchResponseCallbackPtr response_callback, blink::mojom::ServiceWorkerFetchResponseCallbackPtr response_callback,
...@@ -1666,8 +1476,7 @@ void ServiceWorkerContextClient::InitializeGlobalScope( ...@@ -1666,8 +1476,7 @@ void ServiceWorkerContextClient::InitializeGlobalScope(
blink::mojom::ServiceWorkerRegistrationObjectInfoPtr registration_info) { blink::mojom::ServiceWorkerRegistrationObjectInfoPtr registration_info) {
DCHECK(worker_task_runner_->RunsTasksInCurrentSequence()); DCHECK(worker_task_runner_->RunsTasksInCurrentSequence());
// Connect to the blink::mojom::ServiceWorkerHost. // Connect to the blink::mojom::ServiceWorkerHost.
DCHECK(!context_->service_worker_host); proxy_->BindServiceWorkerHost(service_worker_host.PassHandle());
context_->service_worker_host.Bind(std::move(service_worker_host));
// Set ServiceWorkerGlobalScope#registration. // Set ServiceWorkerGlobalScope#registration.
DCHECK_NE(registration_info->registration_id, DCHECK_NE(registration_info->registration_id,
blink::mojom::kInvalidServiceWorkerRegistrationId); blink::mojom::kInvalidServiceWorkerRegistrationId);
......
...@@ -46,7 +46,6 @@ class TaskRunner; ...@@ -46,7 +46,6 @@ class TaskRunner;
namespace blink { namespace blink {
struct PlatformNotificationData; struct PlatformNotificationData;
struct WebServiceWorkerClientQueryOptions;
class WebDataConsumerHandle; class WebDataConsumerHandle;
class WebServiceWorkerContextProxy; class WebServiceWorkerContextProxy;
class WebServiceWorkerProvider; class WebServiceWorkerProvider;
...@@ -111,22 +110,6 @@ class CONTENT_EXPORT ServiceWorkerContextClient ...@@ -111,22 +110,6 @@ class CONTENT_EXPORT ServiceWorkerContextClient
blink::mojom::ServiceWorkerObjectInfoPtr info); blink::mojom::ServiceWorkerObjectInfoPtr info);
// WebServiceWorkerContextClient overrides. // WebServiceWorkerContextClient overrides.
void GetClient(
const blink::WebString& client_id,
std::unique_ptr<blink::WebServiceWorkerClientCallbacks>) override;
void GetClients(
const blink::WebServiceWorkerClientQueryOptions&,
std::unique_ptr<blink::WebServiceWorkerClientsCallbacks>) override;
void OpenNewTab(
const blink::WebURL&,
std::unique_ptr<blink::WebServiceWorkerClientCallbacks>) override;
void OpenPaymentHandlerWindow(
const blink::WebURL&,
std::unique_ptr<blink::WebServiceWorkerClientCallbacks>) override;
void SetCachedMetadata(const blink::WebURL&,
const char* data,
size_t size) override;
void ClearCachedMetadata(const blink::WebURL&) override;
void WorkerReadyForInspection() override; void WorkerReadyForInspection() override;
void WorkerContextFailedToStart() override; void WorkerContextFailedToStart() override;
void FailedToLoadInstalledScript() override; void FailedToLoadInstalledScript() override;
...@@ -231,18 +214,6 @@ class CONTENT_EXPORT ServiceWorkerContextClient ...@@ -231,18 +214,6 @@ class CONTENT_EXPORT ServiceWorkerContextClient
blink::WebServiceWorkerNetworkProvider*) override; blink::WebServiceWorkerNetworkProvider*) override;
std::unique_ptr<blink::WebServiceWorkerProvider> CreateServiceWorkerProvider() std::unique_ptr<blink::WebServiceWorkerProvider> CreateServiceWorkerProvider()
override; override;
void PostMessageToClient(const blink::WebString& uuid,
blink::TransferableMessage message) override;
void Focus(const blink::WebString& uuid,
std::unique_ptr<blink::WebServiceWorkerClientCallbacks>) override;
void Navigate(
const blink::WebString& uuid,
const blink::WebURL&,
std::unique_ptr<blink::WebServiceWorkerClientCallbacks>) override;
void SkipWaiting(std::unique_ptr<blink::WebServiceWorkerSkipWaitingCallbacks>
callbacks) override;
void Claim(std::unique_ptr<blink::WebServiceWorkerClientsClaimCallbacks>
callbacks) override;
// Dispatches the fetch event if the worker is running normally, and queues it // Dispatches the fetch event if the worker is running normally, and queues it
// instead if the worker has already requested to be terminated by the // instead if the worker has already requested to be terminated by the
......
...@@ -66,12 +66,14 @@ class MockWebServiceWorkerContextProxy ...@@ -66,12 +66,14 @@ class MockWebServiceWorkerContextProxy
public: public:
~MockWebServiceWorkerContextProxy() override = default; ~MockWebServiceWorkerContextProxy() override = default;
void ReadyToEvaluateScript() override {} void BindServiceWorkerHost(
mojo::ScopedInterfaceEndpointHandle service_worker_host) override {}
void SetRegistration( void SetRegistration(
std::unique_ptr<blink::WebServiceWorkerRegistration::Handle> handle) std::unique_ptr<blink::WebServiceWorkerRegistration::Handle> handle)
override { override {
registration_handle_ = std::move(handle); registration_handle_ = std::move(handle);
} }
void ReadyToEvaluateScript() override {}
bool HasFetchEventHandler() override { return false; } bool HasFetchEventHandler() override { return false; }
void DispatchFetchEvent(int fetch_event_id, void DispatchFetchEvent(int fetch_event_id,
const blink::WebServiceWorkerRequest& web_request, const blink::WebServiceWorkerRequest& web_request,
......
...@@ -33,11 +33,7 @@ ...@@ -33,11 +33,7 @@
#include <memory> #include <memory>
#include "third_party/blink/public/common/messaging/transferable_message.h"
#include "third_party/blink/public/mojom/service_worker/service_worker_event_status.mojom-shared.h" #include "third_party/blink/public/mojom/service_worker/service_worker_event_status.mojom-shared.h"
#include "third_party/blink/public/platform/modules/service_worker/web_service_worker_clients_claim_callbacks.h"
#include "third_party/blink/public/platform/modules/service_worker/web_service_worker_clients_info.h"
#include "third_party/blink/public/platform/modules/service_worker/web_service_worker_skip_waiting_callbacks.h"
#include "third_party/blink/public/platform/modules/service_worker/web_service_worker_stream_handle.h" #include "third_party/blink/public/platform/modules/service_worker/web_service_worker_stream_handle.h"
#include "third_party/blink/public/platform/web_feature.mojom-shared.h" #include "third_party/blink/public/platform/web_feature.mojom-shared.h"
#include "third_party/blink/public/platform/web_url.h" #include "third_party/blink/public/platform/web_url.h"
...@@ -47,7 +43,6 @@ ...@@ -47,7 +43,6 @@
namespace blink { namespace blink {
struct WebPaymentHandlerResponse; struct WebPaymentHandlerResponse;
struct WebServiceWorkerClientQueryOptions;
class WebServiceWorkerContextProxy; class WebServiceWorkerContextProxy;
class WebServiceWorkerNetworkProvider; class WebServiceWorkerNetworkProvider;
class WebServiceWorkerProvider; class WebServiceWorkerProvider;
...@@ -66,33 +61,6 @@ class WebServiceWorkerContextClient { ...@@ -66,33 +61,6 @@ class WebServiceWorkerContextClient {
public: public:
virtual ~WebServiceWorkerContextClient() = default; virtual ~WebServiceWorkerContextClient() = default;
// For Clients#get(id). Requests the embedder to return the specified Client.
virtual void GetClient(const WebString& client_id,
std::unique_ptr<WebServiceWorkerClientCallbacks>) = 0;
// For Clients#matchAll(options). Requests the embedder to return all matching
// Clients.
virtual void GetClients(
const WebServiceWorkerClientQueryOptions&,
std::unique_ptr<WebServiceWorkerClientsCallbacks>) = 0;
// For Clients#openWindow(url). Requests the embedder to open a tab.
virtual void OpenNewTab(const WebURL&,
std::unique_ptr<WebServiceWorkerClientCallbacks>) = 0;
// Similar to OpenNewTab above. For PaymentRequestEvent#openWindow().
virtual void OpenPaymentHandlerWindow(
const WebURL&,
std::unique_ptr<WebServiceWorkerClientCallbacks>) = 0;
// A suggestion to cache this metadata in association with this URL.
virtual void SetCachedMetadata(const WebURL& url,
const char* data,
size_t size) {}
// A suggestion to clear the cached metadata in association with this URL.
virtual void ClearCachedMetadata(const WebURL& url) {}
// ServiceWorker has prepared everything for script loading and is now ready // ServiceWorker has prepared everything for script loading and is now ready
// for DevTools inspection. // for DevTools inspection.
virtual void WorkerReadyForInspection() {} virtual void WorkerReadyForInspection() {}
...@@ -315,28 +283,6 @@ class WebServiceWorkerContextClient { ...@@ -315,28 +283,6 @@ class WebServiceWorkerContextClient {
// Called on the main thread. // Called on the main thread.
virtual std::unique_ptr<WebServiceWorkerProvider> virtual std::unique_ptr<WebServiceWorkerProvider>
CreateServiceWorkerProvider() = 0; CreateServiceWorkerProvider() = 0;
// The message is only valid during this method call, unless callee calls
// EnsureDataIsOwned on the message.
virtual void PostMessageToClient(const WebString& uuid,
TransferableMessage) = 0;
// For WindowClient#focus(). Requests the embedder to focus a window.
virtual void Focus(const WebString& uuid,
std::unique_ptr<WebServiceWorkerClientCallbacks>) = 0;
// For WindowClient#navigate(). Requests the embedder to navigate to a URL.
virtual void Navigate(const WebString& uuid,
const WebURL&,
std::unique_ptr<WebServiceWorkerClientCallbacks>) = 0;
// For ServiceWorkerGlobalScope#skipWaiting().
virtual void SkipWaiting(
std::unique_ptr<WebServiceWorkerSkipWaitingCallbacks>) = 0;
// For Clients#claim().
virtual void Claim(
std::unique_ptr<WebServiceWorkerClientsClaimCallbacks>) = 0;
}; };
} // namespace blink } // namespace blink
......
...@@ -32,6 +32,7 @@ ...@@ -32,6 +32,7 @@
#define THIRD_PARTY_BLINK_PUBLIC_WEB_MODULES_SERVICE_WORKER_WEB_SERVICE_WORKER_CONTEXT_PROXY_H_ #define THIRD_PARTY_BLINK_PUBLIC_WEB_MODULES_SERVICE_WORKER_WEB_SERVICE_WORKER_CONTEXT_PROXY_H_
#include "base/time/time.h" #include "base/time/time.h"
#include "mojo/public/cpp/bindings/scoped_interface_endpoint_handle.h"
#include "third_party/blink/public/common/messaging/transferable_message.h" #include "third_party/blink/public/common/messaging/transferable_message.h"
#include "third_party/blink/public/platform/modules/background_fetch/background_fetch.mojom-shared.h" #include "third_party/blink/public/platform/modules/background_fetch/background_fetch.mojom-shared.h"
#include "third_party/blink/public/platform/modules/background_fetch/web_background_fetch_registration.h" #include "third_party/blink/public/platform/modules/background_fetch/web_background_fetch_registration.h"
...@@ -60,6 +61,9 @@ class WebServiceWorkerContextProxy { ...@@ -60,6 +61,9 @@ class WebServiceWorkerContextProxy {
public: public:
virtual ~WebServiceWorkerContextProxy() = default; virtual ~WebServiceWorkerContextProxy() = default;
virtual void BindServiceWorkerHost(
mojo::ScopedInterfaceEndpointHandle service_worker_host) = 0;
virtual void SetRegistration( virtual void SetRegistration(
std::unique_ptr<WebServiceWorkerRegistration::Handle>) = 0; std::unique_ptr<WebServiceWorkerRegistration::Handle>) = 0;
......
...@@ -120,7 +120,7 @@ void ServiceWorkerClient::postMessage(ScriptState* script_state, ...@@ -120,7 +120,7 @@ void ServiceWorkerClient::postMessage(ScriptState* script_state,
return; return;
ServiceWorkerGlobalScopeClient::From(context)->PostMessageToClient( ServiceWorkerGlobalScopeClient::From(context)->PostMessageToClient(
uuid_, ToTransferableMessage(std::move(msg))); uuid_, std::move(msg));
} }
} // namespace blink } // namespace blink
...@@ -181,6 +181,13 @@ void ServiceWorkerGlobalScope::ImportModuleScript( ...@@ -181,6 +181,13 @@ void ServiceWorkerGlobalScope::ImportModuleScript(
new WorkerModuleTreeClient(modulator)); new WorkerModuleTreeClient(modulator));
} }
void ServiceWorkerGlobalScope::Dispose() {
DCHECK(IsContextThread());
ServiceWorkerGlobalScopeClient::From(GetExecutionContext())
->WillDestroyWorkerContext();
WorkerGlobalScope::Dispose();
}
void ServiceWorkerGlobalScope::CountWorkerScript(size_t script_size, void ServiceWorkerGlobalScope::CountWorkerScript(size_t script_size,
size_t cached_metadata_size) { size_t cached_metadata_size) {
DEFINE_THREAD_SAFE_STATIC_LOCAL( DEFINE_THREAD_SAFE_STATIC_LOCAL(
...@@ -261,6 +268,12 @@ ScriptPromise ServiceWorkerGlobalScope::skipWaiting(ScriptState* script_state) { ...@@ -261,6 +268,12 @@ ScriptPromise ServiceWorkerGlobalScope::skipWaiting(ScriptState* script_state) {
return promise; return promise;
} }
void ServiceWorkerGlobalScope::BindServiceWorkerHost(
mojom::blink::ServiceWorkerHostAssociatedPtrInfo service_worker_host) {
ServiceWorkerGlobalScopeClient::From(GetExecutionContext())
->BindServiceWorkerHost(std::move(service_worker_host));
}
void ServiceWorkerGlobalScope::SetRegistration( void ServiceWorkerGlobalScope::SetRegistration(
std::unique_ptr<WebServiceWorkerRegistration::Handle> handle) { std::unique_ptr<WebServiceWorkerRegistration::Handle> handle) {
if (!GetExecutionContext()) if (!GetExecutionContext())
......
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
#define THIRD_PARTY_BLINK_RENDERER_MODULES_SERVICE_WORKER_SERVICE_WORKER_GLOBAL_SCOPE_H_ #define THIRD_PARTY_BLINK_RENDERER_MODULES_SERVICE_WORKER_SERVICE_WORKER_GLOBAL_SCOPE_H_
#include <memory> #include <memory>
#include "third_party/blink/public/mojom/service_worker/service_worker.mojom-blink.h"
#include "third_party/blink/public/platform/modules/cache_storage/cache_storage.mojom-blink.h" #include "third_party/blink/public/platform/modules/cache_storage/cache_storage.mojom-blink.h"
#include "third_party/blink/public/platform/modules/service_worker/web_service_worker_registration.h" #include "third_party/blink/public/platform/modules/service_worker/web_service_worker_registration.h"
#include "third_party/blink/renderer/bindings/core/v8/request_or_usv_string.h" #include "third_party/blink/renderer/bindings/core/v8/request_or_usv_string.h"
...@@ -76,6 +77,7 @@ class MODULES_EXPORT ServiceWorkerGlobalScope final : public WorkerGlobalScope { ...@@ -76,6 +77,7 @@ class MODULES_EXPORT ServiceWorkerGlobalScope final : public WorkerGlobalScope {
const KURL& module_url_record, const KURL& module_url_record,
FetchClientSettingsObjectSnapshot* outside_settings_object, FetchClientSettingsObjectSnapshot* outside_settings_object,
network::mojom::FetchCredentialsMode) override; network::mojom::FetchCredentialsMode) override;
void Dispose() override;
// Counts an evaluated script and its size. Called for the main worker script. // Counts an evaluated script and its size. Called for the main worker script.
void CountWorkerScript(size_t script_size, size_t cached_metadata_size); void CountWorkerScript(size_t script_size, size_t cached_metadata_size);
...@@ -98,6 +100,8 @@ class MODULES_EXPORT ServiceWorkerGlobalScope final : public WorkerGlobalScope { ...@@ -98,6 +100,8 @@ class MODULES_EXPORT ServiceWorkerGlobalScope final : public WorkerGlobalScope {
ScriptPromise skipWaiting(ScriptState*); ScriptPromise skipWaiting(ScriptState*);
void BindServiceWorkerHost(mojom::blink::ServiceWorkerHostAssociatedPtrInfo);
void SetRegistration(std::unique_ptr<WebServiceWorkerRegistration::Handle>); void SetRegistration(std::unique_ptr<WebServiceWorkerRegistration::Handle>);
// EventTarget // EventTarget
......
...@@ -35,6 +35,7 @@ ...@@ -35,6 +35,7 @@
#include "base/macros.h" #include "base/macros.h"
#include "third_party/blink/public/common/messaging/transferable_message.h" #include "third_party/blink/public/common/messaging/transferable_message.h"
#include "third_party/blink/public/mojom/service_worker/service_worker.mojom-blink.h"
#include "third_party/blink/public/mojom/service_worker/service_worker_event_status.mojom-blink.h" #include "third_party/blink/public/mojom/service_worker/service_worker_event_status.mojom-blink.h"
#include "third_party/blink/public/platform/modules/service_worker/web_service_worker_clients_claim_callbacks.h" #include "third_party/blink/public/platform/modules/service_worker/web_service_worker_clients_claim_callbacks.h"
#include "third_party/blink/public/platform/modules/service_worker/web_service_worker_clients_info.h" #include "third_party/blink/public/platform/modules/service_worker/web_service_worker_clients_info.h"
...@@ -43,6 +44,7 @@ ...@@ -43,6 +44,7 @@
#include "third_party/blink/renderer/core/messaging/message_port.h" #include "third_party/blink/renderer/core/messaging/message_port.h"
#include "third_party/blink/renderer/core/workers/worker_clients.h" #include "third_party/blink/renderer/core/workers/worker_clients.h"
#include "third_party/blink/renderer/modules/modules_export.h" #include "third_party/blink/renderer/modules/modules_export.h"
#include "third_party/blink/renderer/platform/wtf/text/wtf_string.h"
namespace blink { namespace blink {
...@@ -51,13 +53,13 @@ struct WebServiceWorkerClientQueryOptions; ...@@ -51,13 +53,13 @@ struct WebServiceWorkerClientQueryOptions;
class ExecutionContext; class ExecutionContext;
class WebServiceWorkerContextClient; class WebServiceWorkerContextClient;
class WebServiceWorkerResponse; class WebServiceWorkerResponse;
class WebURL; class KURL;
class WorkerClients; class WorkerClients;
// See WebServiceWorkerContextClient for documentation for the methods in this // See WebServiceWorkerContextClient for documentation for the methods in this
// class. // class.
class MODULES_EXPORT ServiceWorkerGlobalScopeClient class MODULES_EXPORT ServiceWorkerGlobalScopeClient final
: public GarbageCollected<ServiceWorkerGlobalScopeClient>, : public GarbageCollectedFinalized<ServiceWorkerGlobalScopeClient>,
public Supplement<WorkerClients> { public Supplement<WorkerClients> {
USING_GARBAGE_COLLECTED_MIXIN(ServiceWorkerGlobalScopeClient); USING_GARBAGE_COLLECTED_MIXIN(ServiceWorkerGlobalScopeClient);
...@@ -67,17 +69,25 @@ class MODULES_EXPORT ServiceWorkerGlobalScopeClient ...@@ -67,17 +69,25 @@ class MODULES_EXPORT ServiceWorkerGlobalScopeClient
explicit ServiceWorkerGlobalScopeClient(WebServiceWorkerContextClient&); explicit ServiceWorkerGlobalScopeClient(WebServiceWorkerContextClient&);
// Called from ServiceWorkerClients. // Called from ServiceWorkerClients.
void GetClient(const WebString&, void GetClient(const String&,
std::unique_ptr<WebServiceWorkerClientCallbacks>); std::unique_ptr<WebServiceWorkerClientCallbacks>);
void GetClients(const WebServiceWorkerClientQueryOptions&, void GetClients(const WebServiceWorkerClientQueryOptions&,
std::unique_ptr<WebServiceWorkerClientsCallbacks>); std::unique_ptr<WebServiceWorkerClientsCallbacks>);
void OpenWindowForClients(const WebURL&, void OpenWindowForClients(const KURL&,
std::unique_ptr<WebServiceWorkerClientCallbacks>); std::unique_ptr<WebServiceWorkerClientCallbacks>);
void OpenWindowForPaymentHandler( void OpenWindowForPaymentHandler(
const WebURL&, const KURL&,
std::unique_ptr<WebServiceWorkerClientCallbacks>); std::unique_ptr<WebServiceWorkerClientCallbacks>);
void SetCachedMetadata(const WebURL&, const char*, size_t); void SetCachedMetadata(const KURL&, const char*, size_t);
void ClearCachedMetadata(const WebURL&); void ClearCachedMetadata(const KURL&);
void PostMessageToClient(const String& client_uuid, BlinkTransferableMessage);
void SkipWaiting(std::unique_ptr<WebServiceWorkerSkipWaitingCallbacks>);
void Claim(std::unique_ptr<WebServiceWorkerClientsClaimCallbacks>);
void Focus(const String& client_uuid,
std::unique_ptr<WebServiceWorkerClientCallbacks>);
void Navigate(const String& client_uuid,
const KURL&,
std::unique_ptr<WebServiceWorkerClientCallbacks>);
void DidHandleActivateEvent(int event_id, void DidHandleActivateEvent(int event_id,
mojom::ServiceWorkerEventStatus, mojom::ServiceWorkerEventStatus,
...@@ -145,14 +155,11 @@ class MODULES_EXPORT ServiceWorkerGlobalScopeClient ...@@ -145,14 +155,11 @@ class MODULES_EXPORT ServiceWorkerGlobalScopeClient
void DidHandlePaymentRequestEvent(int payment_request_event_id, void DidHandlePaymentRequestEvent(int payment_request_event_id,
mojom::ServiceWorkerEventStatus, mojom::ServiceWorkerEventStatus,
double event_dispatch_time); double event_dispatch_time);
void PostMessageToClient(const WebString& client_uuid, TransferableMessage);
void SkipWaiting(std::unique_ptr<WebServiceWorkerSkipWaitingCallbacks>); void BindServiceWorkerHost(
void Claim(std::unique_ptr<WebServiceWorkerClientsClaimCallbacks>); mojom::blink::ServiceWorkerHostAssociatedPtrInfo service_worker_host);
void Focus(const WebString& client_uuid,
std::unique_ptr<WebServiceWorkerClientCallbacks>); void WillDestroyWorkerContext();
void Navigate(const WebString& client_uuid,
const WebURL&,
std::unique_ptr<WebServiceWorkerClientCallbacks>);
static ServiceWorkerGlobalScopeClient* From(ExecutionContext*); static ServiceWorkerGlobalScopeClient* From(ExecutionContext*);
...@@ -161,6 +168,12 @@ class MODULES_EXPORT ServiceWorkerGlobalScopeClient ...@@ -161,6 +168,12 @@ class MODULES_EXPORT ServiceWorkerGlobalScopeClient
private: private:
WebServiceWorkerContextClient& client_; WebServiceWorkerContextClient& client_;
// Lives on the service worker thread, is bound by BindServiceWorkerHost()
// which is triggered by the first Mojo call received on the service worker
// thread content::mojom::ServiceWorker::InitializeGlobalScope(), and is
// closed by WillDestroyWorkerContext().
mojom::blink::ServiceWorkerHostAssociatedPtr service_worker_host_;
DISALLOW_COPY_AND_ASSIGN(ServiceWorkerGlobalScopeClient); DISALLOW_COPY_AND_ASSIGN(ServiceWorkerGlobalScopeClient);
}; };
......
...@@ -182,8 +182,13 @@ void ServiceWorkerGlobalScopeProxy::Trace(blink::Visitor* visitor) { ...@@ -182,8 +182,13 @@ void ServiceWorkerGlobalScopeProxy::Trace(blink::Visitor* visitor) {
visitor->Trace(parent_execution_context_task_runners_); visitor->Trace(parent_execution_context_task_runners_);
} }
void ServiceWorkerGlobalScopeProxy::ReadyToEvaluateScript() { void ServiceWorkerGlobalScopeProxy::BindServiceWorkerHost(
WorkerGlobalScope()->ReadyToEvaluateScript(); mojo::ScopedInterfaceEndpointHandle service_worker_host) {
DCHECK(WorkerGlobalScope()->IsContextThread());
WorkerGlobalScope()->BindServiceWorkerHost(
mojom::blink::ServiceWorkerHostAssociatedPtrInfo(
std::move(service_worker_host),
mojom::blink::ServiceWorkerHost::Version_));
} }
void ServiceWorkerGlobalScopeProxy::SetRegistration( void ServiceWorkerGlobalScopeProxy::SetRegistration(
...@@ -192,6 +197,10 @@ void ServiceWorkerGlobalScopeProxy::SetRegistration( ...@@ -192,6 +197,10 @@ void ServiceWorkerGlobalScopeProxy::SetRegistration(
WorkerGlobalScope()->SetRegistration(std::move(handle)); WorkerGlobalScope()->SetRegistration(std::move(handle));
} }
void ServiceWorkerGlobalScopeProxy::ReadyToEvaluateScript() {
WorkerGlobalScope()->ReadyToEvaluateScript();
}
void ServiceWorkerGlobalScopeProxy::DispatchBackgroundFetchAbortEvent( void ServiceWorkerGlobalScopeProxy::DispatchBackgroundFetchAbortEvent(
int event_id, int event_id,
const WebBackgroundFetchRegistration& registration) { const WebBackgroundFetchRegistration& registration) {
......
...@@ -77,9 +77,13 @@ class ServiceWorkerGlobalScopeProxy final ...@@ -77,9 +77,13 @@ class ServiceWorkerGlobalScopeProxy final
~ServiceWorkerGlobalScopeProxy() override; ~ServiceWorkerGlobalScopeProxy() override;
// WebServiceWorkerContextProxy overrides: // WebServiceWorkerContextProxy overrides:
void ReadyToEvaluateScript() override; void BindServiceWorkerHost(
mojo::ScopedInterfaceEndpointHandle service_worker_host) override;
void SetRegistration( void SetRegistration(
std::unique_ptr<WebServiceWorkerRegistration::Handle>) override; std::unique_ptr<WebServiceWorkerRegistration::Handle>) override;
// Must be called after the above BindServiceWorkerHost() and
// SetRegistration() got called.
void ReadyToEvaluateScript() override;
void DispatchActivateEvent(int) override; void DispatchActivateEvent(int) override;
void DispatchBackgroundFetchAbortEvent( void DispatchBackgroundFetchAbortEvent(
int event_id, int event_id,
......
...@@ -64,43 +64,6 @@ class MockServiceWorkerContextClient : public WebServiceWorkerContextClient { ...@@ -64,43 +64,6 @@ class MockServiceWorkerContextClient : public WebServiceWorkerContextClient {
return std::unique_ptr<WebServiceWorkerProvider>( return std::unique_ptr<WebServiceWorkerProvider>(
CreateServiceWorkerProviderProxy()); CreateServiceWorkerProviderProxy());
} }
void GetClient(const WebString&,
std::unique_ptr<WebServiceWorkerClientCallbacks>) override {
NOTREACHED();
}
void GetClients(const WebServiceWorkerClientQueryOptions&,
std::unique_ptr<WebServiceWorkerClientsCallbacks>) override {
NOTREACHED();
}
void OpenNewTab(const WebURL&,
std::unique_ptr<WebServiceWorkerClientCallbacks>) override {
NOTREACHED();
}
void OpenPaymentHandlerWindow(
const WebURL&,
std::unique_ptr<WebServiceWorkerClientCallbacks>) override {
NOTREACHED();
}
void PostMessageToClient(const WebString& uuid,
TransferableMessage) override {
NOTREACHED();
}
void SkipWaiting(
std::unique_ptr<WebServiceWorkerSkipWaitingCallbacks>) override {
NOTREACHED();
}
void Claim(std::unique_ptr<WebServiceWorkerClientsClaimCallbacks>) override {
NOTREACHED();
}
void Focus(const WebString& uuid,
std::unique_ptr<WebServiceWorkerClientCallbacks>) override {
NOTREACHED();
}
void Navigate(const WebString& uuid,
const WebURL&,
std::unique_ptr<WebServiceWorkerClientCallbacks>) override {
NOTREACHED();
}
void WorkerContextDestroyed() override { termination_event_.Signal(); } void WorkerContextDestroyed() override { termination_event_.Signal(); }
void WaitUntilScriptEvaluated() { script_evaluated_event_.Wait(); } void WaitUntilScriptEvaluated() { script_evaluated_event_.Wait(); }
......
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