Commit 02246af8 authored by kinuko@chromium.org's avatar kinuko@chromium.org

ServiceWorker: propagate provider_id to the browser process in .register

Remotely for event/object rewiring.

This also fixes all int32 used in IPC for in-memory object IDs to int

BUG=349919
TEST=no functional changes yet

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@262973 0039d316-1c4b-4281-b951-d872f2087c98
parent 7a1396be
......@@ -69,9 +69,13 @@ void ServiceWorkerContextCore::RegisterServiceWorker(
const GURL& pattern,
const GURL& script_url,
int source_process_id,
ServiceWorkerProviderHost* provider_host,
const RegistrationCallback& callback) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
// TODO(kinuko): Wire the provider_host so that we can tell which document
// is calling .register.
job_coordinator_->Register(
pattern,
script_url,
......@@ -84,9 +88,13 @@ void ServiceWorkerContextCore::RegisterServiceWorker(
void ServiceWorkerContextCore::UnregisterServiceWorker(
const GURL& pattern,
int source_process_id,
ServiceWorkerProviderHost* provider_host,
const UnregistrationCallback& callback) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
// TODO(kinuko): Wire the provider_host so that we can tell which document
// is calling .register.
job_coordinator_->Unregister(pattern, source_process_id, callback);
}
......
......@@ -74,14 +74,20 @@ class CONTENT_EXPORT ServiceWorkerContextCore
void RemoveAllProviderHostsForProcess(int process_id);
// The callback will be called on the IO thread.
// A child process of |source_process_id| may be used to run the created
// worker for initial installation.
// Non-null |provider_host| must be given if this is called from a document,
// whose process_id() must match with |source_process_id|.
void RegisterServiceWorker(const GURL& pattern,
const GURL& script_url,
int source_process_id,
ServiceWorkerProviderHost* provider_host,
const RegistrationCallback& callback);
// The callback will be called on the IO thread.
void UnregisterServiceWorker(const GURL& pattern,
int source_process_id,
ServiceWorkerProviderHost* provider_host,
const UnregistrationCallback& callback);
// This class maintains collections of live instances, this class
......
......@@ -116,6 +116,7 @@ TEST_F(ServiceWorkerContextTest, Register) {
GURL("http://www.example.com/*"),
GURL("http://www.example.com/service_worker.js"),
render_process_id_,
NULL,
MakeRegisteredCallback(&called, &registration_id, &version_id));
ASSERT_FALSE(called);
......@@ -168,6 +169,7 @@ TEST_F(ServiceWorkerContextTest, Register_RejectInstall) {
GURL("http://www.example.com/*"),
GURL("http://www.example.com/service_worker.js"),
render_process_id_,
NULL,
MakeRegisteredCallback(&called, &registration_id, &version_id));
ASSERT_FALSE(called);
......@@ -202,6 +204,7 @@ TEST_F(ServiceWorkerContextTest, Register_DuplicateScriptNoActiveWorker) {
GURL("http://www.example.com/*"),
GURL("http://www.example.com/service_worker.js"),
render_process_id_,
NULL,
MakeRegisteredCallback(&called, &old_registration_id, &old_version_id));
ASSERT_FALSE(called);
......@@ -219,6 +222,7 @@ TEST_F(ServiceWorkerContextTest, Register_DuplicateScriptNoActiveWorker) {
GURL("http://www.example.com/*"),
GURL("http://www.example.com/service_worker.js"),
render_process_id_,
NULL,
MakeRegisteredCallback(&called, &new_registration_id, &new_version_id));
ASSERT_FALSE(called);
......@@ -242,6 +246,7 @@ TEST_F(ServiceWorkerContextTest, Unregister) {
pattern,
GURL("http://www.example.com/service_worker.js"),
render_process_id_,
NULL,
MakeRegisteredCallback(&called, &registration_id, &version_id));
ASSERT_FALSE(called);
......@@ -252,7 +257,7 @@ TEST_F(ServiceWorkerContextTest, Unregister) {
called = false;
context_->UnregisterServiceWorker(
pattern, render_process_id_, MakeUnregisteredCallback(&called));
pattern, render_process_id_, NULL, MakeUnregisteredCallback(&called));
ASSERT_FALSE(called);
base::RunLoop().RunUntilIdle();
......@@ -280,6 +285,7 @@ TEST_F(ServiceWorkerContextTest, RegisterNewScript) {
pattern,
GURL("http://www.example.com/service_worker.js"),
render_process_id_,
NULL,
MakeRegisteredCallback(&called, &old_registration_id, &old_version_id));
ASSERT_FALSE(called);
......@@ -295,6 +301,7 @@ TEST_F(ServiceWorkerContextTest, RegisterNewScript) {
pattern,
GURL("http://www.example.com/service_worker_new.js"),
render_process_id_,
NULL,
MakeRegisteredCallback(&called, &new_registration_id, &new_version_id));
ASSERT_FALSE(called);
......@@ -322,6 +329,7 @@ TEST_F(ServiceWorkerContextTest, RegisterDuplicateScript) {
pattern,
script_url,
render_process_id_,
NULL,
MakeRegisteredCallback(&called, &old_registration_id, &old_version_id));
ASSERT_FALSE(called);
......@@ -337,6 +345,7 @@ TEST_F(ServiceWorkerContextTest, RegisterDuplicateScript) {
pattern,
script_url,
render_process_id_,
NULL,
MakeRegisteredCallback(&called, &new_registration_id, &new_version_id));
ASSERT_FALSE(called);
......
......@@ -83,6 +83,7 @@ void ServiceWorkerContextWrapper::RegisterServiceWorker(
pattern,
script_url,
source_process_id,
NULL /* provider_host */,
base::Bind(&FinishRegistrationOnIO, continuation));
}
......@@ -115,6 +116,7 @@ void ServiceWorkerContextWrapper::UnregisterServiceWorker(
context()->UnregisterServiceWorker(
pattern,
source_process_id,
NULL /* provider_host */,
base::Bind(&FinishUnregistrationOnIO, continuation));
}
......
......@@ -118,8 +118,9 @@ int ServiceWorkerDispatcherHost::RegisterServiceWorkerHandle(
}
void ServiceWorkerDispatcherHost::OnRegisterServiceWorker(
int32 thread_id,
int32 request_id,
int thread_id,
int request_id,
int provider_id,
const GURL& pattern,
const GURL& script_url) {
if (!context_ || !ServiceWorkerUtils::IsFeatureEnabled()) {
......@@ -143,10 +144,18 @@ void ServiceWorkerDispatcherHost::OnRegisterServiceWorker(
return;
}
ServiceWorkerProviderHost* provider_host = context_->GetProviderHost(
render_process_id_, provider_id);
if (!provider_host) {
BadMessageReceived();
return;
}
context_->RegisterServiceWorker(
pattern,
script_url,
render_process_id_,
provider_host,
base::Bind(&ServiceWorkerDispatcherHost::RegistrationComplete,
this,
thread_id,
......@@ -154,8 +163,9 @@ void ServiceWorkerDispatcherHost::OnRegisterServiceWorker(
}
void ServiceWorkerDispatcherHost::OnUnregisterServiceWorker(
int32 thread_id,
int32 request_id,
int thread_id,
int request_id,
int provider_id,
const GURL& pattern) {
// TODO(alecflett): This check is insufficient for release. Add a
// ServiceWorker-specific policy query in
......@@ -169,9 +179,17 @@ void ServiceWorkerDispatcherHost::OnUnregisterServiceWorker(
return;
}
ServiceWorkerProviderHost* provider_host = context_->GetProviderHost(
render_process_id_, provider_id);
if (!provider_host) {
BadMessageReceived();
return;
}
context_->UnregisterServiceWorker(
pattern,
render_process_id_,
provider_host,
base::Bind(&ServiceWorkerDispatcherHost::UnregistrationComplete,
this,
thread_id,
......@@ -263,8 +281,8 @@ void ServiceWorkerDispatcherHost::OnSetHostedVersionId(
}
void ServiceWorkerDispatcherHost::RegistrationComplete(
int32 thread_id,
int32 request_id,
int thread_id,
int request_id,
ServiceWorkerStatusCode status,
int64 registration_id,
int64 version_id) {
......@@ -328,8 +346,8 @@ void ServiceWorkerDispatcherHost::OnServiceWorkerObjectDestroyed(
}
void ServiceWorkerDispatcherHost::UnregistrationComplete(
int32 thread_id,
int32 request_id,
int thread_id,
int request_id,
ServiceWorkerStatusCode status) {
if (status != SERVICE_WORKER_OK) {
SendRegistrationError(thread_id, request_id, status);
......@@ -340,8 +358,8 @@ void ServiceWorkerDispatcherHost::UnregistrationComplete(
}
void ServiceWorkerDispatcherHost::SendRegistrationError(
int32 thread_id,
int32 request_id,
int thread_id,
int request_id,
ServiceWorkerStatusCode status) {
base::string16 error_message;
blink::WebServiceWorkerError::ErrorType error_type;
......
......@@ -47,12 +47,14 @@ class CONTENT_EXPORT ServiceWorkerDispatcherHost : public BrowserMessageFilter {
friend class TestingServiceWorkerDispatcherHost;
// IPC Message handlers
void OnRegisterServiceWorker(int32 thread_id,
int32 request_id,
void OnRegisterServiceWorker(int thread_id,
int request_id,
int provider_id,
const GURL& pattern,
const GURL& script_url);
void OnUnregisterServiceWorker(int32 thread_id,
int32 request_id,
void OnUnregisterServiceWorker(int thread_id,
int request_id,
int provider_id,
const GURL& pattern);
void OnProviderCreated(int provider_id);
void OnProviderDestroyed(int provider_id);
......@@ -76,18 +78,18 @@ class CONTENT_EXPORT ServiceWorkerDispatcherHost : public BrowserMessageFilter {
void OnServiceWorkerObjectDestroyed(int handle_id);
// Callbacks from ServiceWorkerContextCore
void RegistrationComplete(int32 thread_id,
int32 request_id,
void RegistrationComplete(int thread_id,
int request_id,
ServiceWorkerStatusCode status,
int64 registration_id,
int64 version_id);
void UnregistrationComplete(int32 thread_id,
int32 request_id,
void UnregistrationComplete(int thread_id,
int request_id,
ServiceWorkerStatusCode status);
void SendRegistrationError(int32 thread_id,
int32 request_id,
void SendRegistrationError(int thread_id,
int request_id,
ServiceWorkerStatusCode status);
int render_process_id_;
......
......@@ -89,7 +89,7 @@ TEST_F(ServiceWorkerDispatcherHostTest, DisabledCausesError) {
bool handled;
dispatcher_host->OnMessageReceived(
ServiceWorkerHostMsg_RegisterServiceWorker(-1, -1, GURL(), GURL()),
ServiceWorkerHostMsg_RegisterServiceWorker(-1, -1, -1, GURL(), GURL()),
&handled);
EXPECT_TRUE(handled);
......@@ -116,7 +116,7 @@ TEST_F(ServiceWorkerDispatcherHostTest, DISABLED_Enabled) {
bool handled;
dispatcher_host->OnMessageReceived(
ServiceWorkerHostMsg_RegisterServiceWorker(-1, -1, GURL(), GURL()),
ServiceWorkerHostMsg_RegisterServiceWorker(-1, -1, -1, GURL(), GURL()),
&handled);
EXPECT_TRUE(handled);
base::RunLoop().RunUntilIdle();
......@@ -144,7 +144,7 @@ TEST_F(ServiceWorkerDispatcherHostTest, EarlyContextDeletion) {
bool handled;
dispatcher_host->OnMessageReceived(
ServiceWorkerHostMsg_RegisterServiceWorker(-1, -1, GURL(), GURL()),
ServiceWorkerHostMsg_RegisterServiceWorker(-1, -1, -1, GURL(), GURL()),
&handled);
EXPECT_TRUE(handled);
......
......@@ -284,6 +284,7 @@ void ServiceWorkerInternalsUI::OperationProxy::UnregisterOnIOThread(
context->context()->UnregisterServiceWorker(
scope,
0, // render process id?
NULL, // provider_host
base::Bind(&ServiceWorkerInternalsUI::OperationProxy::OperationComplete,
this));
}
......
......@@ -59,22 +59,24 @@ bool ServiceWorkerDispatcher::Send(IPC::Message* msg) {
}
void ServiceWorkerDispatcher::RegisterServiceWorker(
int provider_id,
const GURL& pattern,
const GURL& script_url,
WebServiceWorkerProvider::WebServiceWorkerCallbacks* callbacks) {
DCHECK(callbacks);
int request_id = pending_callbacks_.Add(callbacks);
thread_safe_sender_->Send(new ServiceWorkerHostMsg_RegisterServiceWorker(
CurrentWorkerId(), request_id, pattern, script_url));
CurrentWorkerId(), request_id, provider_id, pattern, script_url));
}
void ServiceWorkerDispatcher::UnregisterServiceWorker(
int provider_id,
const GURL& pattern,
WebServiceWorkerProvider::WebServiceWorkerCallbacks* callbacks) {
DCHECK(callbacks);
int request_id = pending_callbacks_.Add(callbacks);
thread_safe_sender_->Send(new ServiceWorkerHostMsg_UnregisterServiceWorker(
CurrentWorkerId(), request_id, pattern));
CurrentWorkerId(), request_id, provider_id, pattern));
}
void ServiceWorkerDispatcher::AddScriptClient(
......@@ -112,8 +114,8 @@ ServiceWorkerDispatcher* ServiceWorkerDispatcher::ThreadSpecificInstance(
return dispatcher;
}
void ServiceWorkerDispatcher::OnRegistered(int32 thread_id,
int32 request_id,
void ServiceWorkerDispatcher::OnRegistered(int thread_id,
int request_id,
int handle_id) {
WebServiceWorkerProvider::WebServiceWorkerCallbacks* callbacks =
pending_callbacks_.Lookup(request_id);
......@@ -134,8 +136,8 @@ void ServiceWorkerDispatcher::OnRegistered(int32 thread_id,
}
void ServiceWorkerDispatcher::OnUnregistered(
int32 thread_id,
int32 request_id) {
int thread_id,
int request_id) {
WebServiceWorkerProvider::WebServiceWorkerCallbacks* callbacks =
pending_callbacks_.Lookup(request_id);
DCHECK(callbacks);
......@@ -147,8 +149,8 @@ void ServiceWorkerDispatcher::OnUnregistered(
}
void ServiceWorkerDispatcher::OnRegistrationError(
int32 thread_id,
int32 request_id,
int thread_id,
int request_id,
WebServiceWorkerError::ErrorType error_type,
const base::string16& message) {
WebServiceWorkerProvider::WebServiceWorkerCallbacks* callbacks =
......
......@@ -42,11 +42,13 @@ class ServiceWorkerDispatcher : public WorkerTaskRunner::Observer {
// Corresponds to navigator.serviceWorker.register()
void RegisterServiceWorker(
int provider_id,
const GURL& pattern,
const GURL& script_url,
blink::WebServiceWorkerProvider::WebServiceWorkerCallbacks* callbacks);
// Corresponds to navigator.serviceWorker.unregister()
void UnregisterServiceWorker(
int provider_id,
const GURL& pattern,
blink::WebServiceWorkerProvider::WebServiceWorkerCallbacks* callbacks);
......@@ -68,14 +70,14 @@ class ServiceWorkerDispatcher : public WorkerTaskRunner::Observer {
virtual void OnWorkerRunLoopStopped() OVERRIDE;
// The asynchronous success response to RegisterServiceWorker.
void OnRegistered(int32 thread_id,
int32 request_id,
void OnRegistered(int thread_id,
int request_id,
int handle_id);
// The asynchronous success response to UregisterServiceWorker.
void OnUnregistered(int32 thread_id,
int32 request_id);
void OnRegistrationError(int32 thread_id,
int32 request_id,
void OnUnregistered(int thread_id,
int request_id);
void OnRegistrationError(int thread_id,
int request_id,
blink::WebServiceWorkerError::ErrorType error_type,
const base::string16& message);
......
......@@ -39,13 +39,15 @@ void WebServiceWorkerProviderImpl::registerServiceWorker(
const WebURL& pattern,
const WebURL& script_url,
WebServiceWorkerCallbacks* callbacks) {
GetDispatcher()->RegisterServiceWorker(pattern, script_url, callbacks);
GetDispatcher()->RegisterServiceWorker(
provider_id_, pattern, script_url, callbacks);
}
void WebServiceWorkerProviderImpl::unregisterServiceWorker(
const WebURL& pattern,
WebServiceWorkerCallbacks* callbacks) {
GetDispatcher()->UnregisterServiceWorker(pattern, callbacks);
GetDispatcher()->UnregisterServiceWorker(
provider_id_, pattern, callbacks);
}
ServiceWorkerDispatcher* WebServiceWorkerProviderImpl::GetDispatcher() {
......
......@@ -42,15 +42,17 @@ IPC_STRUCT_TRAITS_END()
// Messages sent from the child process to the browser.
IPC_MESSAGE_CONTROL4(ServiceWorkerHostMsg_RegisterServiceWorker,
int32 /* thread_id */,
int32 /* request_id */,
IPC_MESSAGE_CONTROL5(ServiceWorkerHostMsg_RegisterServiceWorker,
int /* thread_id */,
int /* request_id */,
int /* provider_id */,
GURL /* scope */,
GURL /* script_url */)
IPC_MESSAGE_CONTROL3(ServiceWorkerHostMsg_UnregisterServiceWorker,
int32 /* thread_id */,
int32 /* request_id */,
IPC_MESSAGE_CONTROL4(ServiceWorkerHostMsg_UnregisterServiceWorker,
int /* thread_id */,
int /* request_id */,
int /* provider_id */,
GURL /* scope (url pattern) */)
// Sends a 'message' event to a service worker (renderer->browser).
......@@ -107,20 +109,20 @@ IPC_MESSAGE_CONTROL2(ServiceWorkerHostMsg_FetchEventFinished,
// Response to ServiceWorkerMsg_RegisterServiceWorker
IPC_MESSAGE_CONTROL3(ServiceWorkerMsg_ServiceWorkerRegistered,
int32 /* thread_id */,
int32 /* request_id */,
int /* thread_id */,
int /* request_id */,
int /* handle_id */)
// Response to ServiceWorkerMsg_UnregisterServiceWorker
IPC_MESSAGE_CONTROL2(ServiceWorkerMsg_ServiceWorkerUnregistered,
int32 /* thread_id */,
int32 /* request_id */)
int /* thread_id */,
int /* request_id */)
// Sent when any kind of registration error occurs during a
// RegisterServiceWorker / UnregisterServiceWorker handler above.
IPC_MESSAGE_CONTROL4(ServiceWorkerMsg_ServiceWorkerRegistrationError,
int32 /* thread_id */,
int32 /* request_id */,
int /* thread_id */,
int /* request_id */,
blink::WebServiceWorkerError::ErrorType /* code */,
base::string16 /* 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