Commit 3d7ea50b authored by nhiroki's avatar nhiroki Committed by Commit bot

ServiceWorker: Support SWRegistration.unregister() in SWGlobalScope [1/2]

SWRegistration.unregister() depends on WebSWProvider, but it's not available
in SWGlobalScope because the provider isn't supplied on the worker startup
sequence. This series of CLs make it available and support unregister() in
the service worker context.

This CL implements createServiceWorkerProvider() to supply a provider and
sets the document URL of its provider host to the worker script URL in
order to allow unregister() call on SWGlobalScope.

[1] Chromium: THIS PATCH
[2] Blink: https://codereview.chromium.org/900793002/

BUG=452910
TEST=compile

Review URL: https://codereview.chromium.org/893363003

Cr-Commit-Position: refs/heads/master@{#314979}
parent 83d6c652
...@@ -583,6 +583,10 @@ void ServiceWorkerDispatcherHost::OnSetHostedVersionId( ...@@ -583,6 +583,10 @@ void ServiceWorkerDispatcherHost::OnSetHostedVersionId(
GetContext()->GetLiveRegistration(version->registration_id()); GetContext()->GetLiveRegistration(version->registration_id());
DCHECK(registration); DCHECK(registration);
// Set the document URL to the script url in order to allow
// register/unregister/getRegistration on ServiceWorkerGlobalScope.
provider_host->SetDocumentUrl(version->script_url());
ServiceWorkerRegistrationObjectInfo info; ServiceWorkerRegistrationObjectInfo info;
ServiceWorkerVersionAttributes attrs; ServiceWorkerVersionAttributes attrs;
GetRegistrationObjectInfoAndVersionAttributes( GetRegistrationObjectInfoAndVersionAttributes(
......
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
#include "content/child/service_worker/service_worker_provider_context.h" #include "content/child/service_worker/service_worker_provider_context.h"
#include "content/child/service_worker/service_worker_registration_handle_reference.h" #include "content/child/service_worker/service_worker_registration_handle_reference.h"
#include "content/child/service_worker/web_service_worker_impl.h" #include "content/child/service_worker/web_service_worker_impl.h"
#include "content/child/service_worker/web_service_worker_provider_impl.h"
#include "content/child/service_worker/web_service_worker_registration_impl.h" #include "content/child/service_worker/web_service_worker_registration_impl.h"
#include "content/child/thread_safe_sender.h" #include "content/child/thread_safe_sender.h"
#include "content/child/worker_task_runner.h" #include "content/child/worker_task_runner.h"
...@@ -368,6 +369,16 @@ EmbeddedWorkerContextClient::createServiceWorkerNetworkProvider( ...@@ -368,6 +369,16 @@ EmbeddedWorkerContextClient::createServiceWorkerNetworkProvider(
return new WebServiceWorkerNetworkProviderImpl(); return new WebServiceWorkerNetworkProviderImpl();
} }
blink::WebServiceWorkerProvider*
EmbeddedWorkerContextClient::createServiceWorkerProvider() {
DCHECK(main_thread_proxy_->RunsTasksOnCurrentThread());
DCHECK(provider_context_);
// Blink is responsible for deleting the returned object.
return new WebServiceWorkerProviderImpl(
thread_safe_sender(), provider_context_.get());
}
void EmbeddedWorkerContextClient::postMessageToClient( void EmbeddedWorkerContextClient::postMessageToClient(
int client_id, int client_id,
const blink::WebString& message, const blink::WebString& message,
......
...@@ -20,6 +20,7 @@ class TaskRunner; ...@@ -20,6 +20,7 @@ class TaskRunner;
namespace blink { namespace blink {
class WebDataSource; class WebDataSource;
class WebServiceWorkerProvider;
} }
namespace content { namespace content {
...@@ -29,9 +30,7 @@ class ServiceWorkerScriptContext; ...@@ -29,9 +30,7 @@ class ServiceWorkerScriptContext;
class ThreadSafeSender; class ThreadSafeSender;
// This class provides access to/from an embedded worker's WorkerGlobalScope. // This class provides access to/from an embedded worker's WorkerGlobalScope.
// All methods other than the constructor (it's created on the main thread) // Unless otherwise noted, all methods are called on the worker thread.
// and createServiceWorkerNetworkProvider (also called on the main thread)
// are called on the worker thread.
// //
// TODO(kinuko): Currently EW/SW separation is made a little hazily. // TODO(kinuko): Currently EW/SW separation is made a little hazily.
// This should implement WebEmbeddedWorkerContextClient // This should implement WebEmbeddedWorkerContextClient
...@@ -46,6 +45,7 @@ class EmbeddedWorkerContextClient ...@@ -46,6 +45,7 @@ class EmbeddedWorkerContextClient
// new instance. // new instance.
static EmbeddedWorkerContextClient* ThreadSpecificInstance(); static EmbeddedWorkerContextClient* ThreadSpecificInstance();
// Called on the main thread.
EmbeddedWorkerContextClient(int embedded_worker_id, EmbeddedWorkerContextClient(int embedded_worker_id,
int64 service_worker_version_id, int64 service_worker_version_id,
const GURL& service_worker_scope, const GURL& service_worker_scope,
...@@ -67,7 +67,10 @@ class EmbeddedWorkerContextClient ...@@ -67,7 +67,10 @@ class EmbeddedWorkerContextClient
virtual void openWindow(const blink::WebURL&, virtual void openWindow(const blink::WebURL&,
blink::WebServiceWorkerClientCallbacks*); blink::WebServiceWorkerClientCallbacks*);
virtual void workerReadyForInspection(); virtual void workerReadyForInspection();
// Called on the main thread.
virtual void workerContextFailedToStart(); virtual void workerContextFailedToStart();
virtual void workerContextStarted(blink::WebServiceWorkerContextProxy* proxy); virtual void workerContextStarted(blink::WebServiceWorkerContextProxy* proxy);
virtual void didEvaluateWorkerScript(bool success); virtual void didEvaluateWorkerScript(bool success);
virtual void willDestroyWorkerContext(); virtual void willDestroyWorkerContext();
...@@ -100,8 +103,12 @@ class EmbeddedWorkerContextClient ...@@ -100,8 +103,12 @@ class EmbeddedWorkerContextClient
virtual void didHandleSyncEvent(int request_id); virtual void didHandleSyncEvent(int request_id);
virtual void didHandleCrossOriginConnectEvent(int request_id, virtual void didHandleCrossOriginConnectEvent(int request_id,
bool accept_connection); bool accept_connection);
// Called on the main thread.
virtual blink::WebServiceWorkerNetworkProvider* virtual blink::WebServiceWorkerNetworkProvider*
createServiceWorkerNetworkProvider(blink::WebDataSource* data_source); createServiceWorkerNetworkProvider(blink::WebDataSource* data_source);
virtual blink::WebServiceWorkerProvider* createServiceWorkerProvider();
virtual void postMessageToClient( virtual void postMessageToClient(
int client_id, int client_id,
const blink::WebString& message, const blink::WebString& message,
......
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