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(
GetContext()->GetLiveRegistration(version->registration_id());
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;
ServiceWorkerVersionAttributes attrs;
GetRegistrationObjectInfoAndVersionAttributes(
......
......@@ -21,6 +21,7 @@
#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/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/thread_safe_sender.h"
#include "content/child/worker_task_runner.h"
......@@ -368,6 +369,16 @@ EmbeddedWorkerContextClient::createServiceWorkerNetworkProvider(
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(
int client_id,
const blink::WebString& message,
......
......@@ -20,6 +20,7 @@ class TaskRunner;
namespace blink {
class WebDataSource;
class WebServiceWorkerProvider;
}
namespace content {
......@@ -29,9 +30,7 @@ class ServiceWorkerScriptContext;
class ThreadSafeSender;
// This class provides access to/from an embedded worker's WorkerGlobalScope.
// All methods other than the constructor (it's created on the main thread)
// and createServiceWorkerNetworkProvider (also called on the main thread)
// are called on the worker thread.
// Unless otherwise noted, all methods are called on the worker thread.
//
// TODO(kinuko): Currently EW/SW separation is made a little hazily.
// This should implement WebEmbeddedWorkerContextClient
......@@ -46,6 +45,7 @@ class EmbeddedWorkerContextClient
// new instance.
static EmbeddedWorkerContextClient* ThreadSpecificInstance();
// Called on the main thread.
EmbeddedWorkerContextClient(int embedded_worker_id,
int64 service_worker_version_id,
const GURL& service_worker_scope,
......@@ -67,7 +67,10 @@ class EmbeddedWorkerContextClient
virtual void openWindow(const blink::WebURL&,
blink::WebServiceWorkerClientCallbacks*);
virtual void workerReadyForInspection();
// Called on the main thread.
virtual void workerContextFailedToStart();
virtual void workerContextStarted(blink::WebServiceWorkerContextProxy* proxy);
virtual void didEvaluateWorkerScript(bool success);
virtual void willDestroyWorkerContext();
......@@ -100,8 +103,12 @@ class EmbeddedWorkerContextClient
virtual void didHandleSyncEvent(int request_id);
virtual void didHandleCrossOriginConnectEvent(int request_id,
bool accept_connection);
// Called on the main thread.
virtual blink::WebServiceWorkerNetworkProvider*
createServiceWorkerNetworkProvider(blink::WebDataSource* data_source);
virtual blink::WebServiceWorkerProvider* createServiceWorkerProvider();
virtual void postMessageToClient(
int client_id,
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