Commit 0402f764 authored by falken@chromium.org's avatar falken@chromium.org

Don't share ServiceWorkerHandle between provider hosts.

This prevents an ASSERT failure in ServiceWorker::from() when it's
passed an existing SW from a different execution context. Since
ServiceWorkers minted in different documents should have
different prototypes, we shouldn't expect JavaScript equality so don't
need to share ServiceWorkerHandles.

BUG=400980
TEST=https://codereview.chromium.org/443883003/

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@287852 0039d316-1c4b-4281-b951-d872f2087c98
parent 7e03b959
...@@ -208,6 +208,7 @@ void ServiceWorkerDispatcherHost::OnRegisterServiceWorker( ...@@ -208,6 +208,7 @@ void ServiceWorkerDispatcherHost::OnRegisterServiceWorker(
base::Bind(&ServiceWorkerDispatcherHost::RegistrationComplete, base::Bind(&ServiceWorkerDispatcherHost::RegistrationComplete,
this, this,
thread_id, thread_id,
provider_id,
request_id)); request_id));
} }
...@@ -315,22 +316,24 @@ void ServiceWorkerDispatcherHost::OnSetHostedVersionId( ...@@ -315,22 +316,24 @@ void ServiceWorkerDispatcherHost::OnSetHostedVersionId(
BadMessageReceived(); BadMessageReceived();
} }
ServiceWorkerHandle* ServiceWorkerDispatcherHost::FindHandle(int thread_id, ServiceWorkerHandle* ServiceWorkerDispatcherHost::FindHandle(int provider_id,
int64 version_id) { int64 version_id) {
for (IDMap<ServiceWorkerHandle, IDMapOwnPointer>::iterator iter(&handles_); for (IDMap<ServiceWorkerHandle, IDMapOwnPointer>::iterator iter(&handles_);
!iter.IsAtEnd(); !iter.IsAtEnd();
iter.Advance()) { iter.Advance()) {
ServiceWorkerHandle* handle = iter.GetCurrentValue(); ServiceWorkerHandle* handle = iter.GetCurrentValue();
DCHECK(handle); DCHECK(handle);
if (handle->thread_id() == thread_id && handle->version() && if (handle->provider_id() == provider_id && handle->version() &&
handle->version()->version_id() == version_id) handle->version()->version_id() == version_id) {
return handle; return handle;
}
} }
return NULL; return NULL;
} }
void ServiceWorkerDispatcherHost::RegistrationComplete( void ServiceWorkerDispatcherHost::RegistrationComplete(
int thread_id, int thread_id,
int provider_id,
int request_id, int request_id,
ServiceWorkerStatusCode status, ServiceWorkerStatusCode status,
int64 registration_id, int64 registration_id,
...@@ -347,13 +350,14 @@ void ServiceWorkerDispatcherHost::RegistrationComplete( ...@@ -347,13 +350,14 @@ void ServiceWorkerDispatcherHost::RegistrationComplete(
DCHECK(version); DCHECK(version);
DCHECK_EQ(registration_id, version->registration_id()); DCHECK_EQ(registration_id, version->registration_id());
ServiceWorkerObjectInfo info; ServiceWorkerObjectInfo info;
ServiceWorkerHandle* handle = FindHandle(thread_id, version_id); ServiceWorkerHandle* handle = FindHandle(provider_id, version_id);
if (handle) { if (handle) {
DCHECK_EQ(thread_id, handle->thread_id());
info = handle->GetObjectInfo(); info = handle->GetObjectInfo();
handle->IncrementRefCount(); handle->IncrementRefCount();
} else { } else {
scoped_ptr<ServiceWorkerHandle> new_handle = ServiceWorkerHandle::Create( scoped_ptr<ServiceWorkerHandle> new_handle = ServiceWorkerHandle::Create(
GetContext()->AsWeakPtr(), this, thread_id, version); GetContext()->AsWeakPtr(), this, thread_id, provider_id, version);
info = new_handle->GetObjectInfo(); info = new_handle->GetObjectInfo();
RegisterServiceWorkerHandle(new_handle.Pass()); RegisterServiceWorkerHandle(new_handle.Pass());
} }
......
...@@ -97,10 +97,11 @@ class CONTENT_EXPORT ServiceWorkerDispatcherHost : public BrowserMessageFilter { ...@@ -97,10 +97,11 @@ class CONTENT_EXPORT ServiceWorkerDispatcherHost : public BrowserMessageFilter {
const std::vector<int>& sent_message_port_ids); const std::vector<int>& sent_message_port_ids);
void OnServiceWorkerObjectDestroyed(int handle_id); void OnServiceWorkerObjectDestroyed(int handle_id);
ServiceWorkerHandle* FindHandle(int thread_id, int64 version_id); ServiceWorkerHandle* FindHandle(int provider_id, int64 version_id);
// Callbacks from ServiceWorkerContextCore // Callbacks from ServiceWorkerContextCore
void RegistrationComplete(int thread_id, void RegistrationComplete(int thread_id,
int provider_id,
int request_id, int request_id,
ServiceWorkerStatusCode status, ServiceWorkerStatusCode status,
int64 registration_id, int64 registration_id,
......
...@@ -43,25 +43,27 @@ scoped_ptr<ServiceWorkerHandle> ServiceWorkerHandle::Create( ...@@ -43,25 +43,27 @@ scoped_ptr<ServiceWorkerHandle> ServiceWorkerHandle::Create(
base::WeakPtr<ServiceWorkerContextCore> context, base::WeakPtr<ServiceWorkerContextCore> context,
IPC::Sender* sender, IPC::Sender* sender,
int thread_id, int thread_id,
int provider_id,
ServiceWorkerVersion* version) { ServiceWorkerVersion* version) {
if (!context || !version) if (!context || !version)
return scoped_ptr<ServiceWorkerHandle>(); return scoped_ptr<ServiceWorkerHandle>();
ServiceWorkerRegistration* registration = ServiceWorkerRegistration* registration =
context->GetLiveRegistration(version->registration_id()); context->GetLiveRegistration(version->registration_id());
return make_scoped_ptr( return make_scoped_ptr(new ServiceWorkerHandle(
new ServiceWorkerHandle(context, sender, thread_id, context, sender, thread_id, provider_id, registration, version));
registration, version));
} }
ServiceWorkerHandle::ServiceWorkerHandle( ServiceWorkerHandle::ServiceWorkerHandle(
base::WeakPtr<ServiceWorkerContextCore> context, base::WeakPtr<ServiceWorkerContextCore> context,
IPC::Sender* sender, IPC::Sender* sender,
int thread_id, int thread_id,
int provider_id,
ServiceWorkerRegistration* registration, ServiceWorkerRegistration* registration,
ServiceWorkerVersion* version) ServiceWorkerVersion* version)
: context_(context), : context_(context),
sender_(sender), sender_(sender),
thread_id_(thread_id), thread_id_(thread_id),
provider_id_(provider_id),
handle_id_(context.get() ? context->GetNewServiceWorkerHandleId() : -1), handle_id_(context.get() ? context->GetNewServiceWorkerHandleId() : -1),
ref_count_(1), ref_count_(1),
registration_(registration), registration_(registration),
......
...@@ -40,11 +40,13 @@ class CONTENT_EXPORT ServiceWorkerHandle ...@@ -40,11 +40,13 @@ class CONTENT_EXPORT ServiceWorkerHandle
base::WeakPtr<ServiceWorkerContextCore> context, base::WeakPtr<ServiceWorkerContextCore> context,
IPC::Sender* sender, IPC::Sender* sender,
int thread_id, int thread_id,
int provider_id,
ServiceWorkerVersion* version); ServiceWorkerVersion* version);
ServiceWorkerHandle(base::WeakPtr<ServiceWorkerContextCore> context, ServiceWorkerHandle(base::WeakPtr<ServiceWorkerContextCore> context,
IPC::Sender* sender, IPC::Sender* sender,
int thread_id, int thread_id,
int provider_id,
ServiceWorkerRegistration* registration, ServiceWorkerRegistration* registration,
ServiceWorkerVersion* version); ServiceWorkerVersion* version);
virtual ~ServiceWorkerHandle(); virtual ~ServiceWorkerHandle();
...@@ -68,6 +70,7 @@ class CONTENT_EXPORT ServiceWorkerHandle ...@@ -68,6 +70,7 @@ class CONTENT_EXPORT ServiceWorkerHandle
ServiceWorkerObjectInfo GetObjectInfo(); ServiceWorkerObjectInfo GetObjectInfo();
int thread_id() const { return thread_id_; } int thread_id() const { return thread_id_; }
int provider_id() const { return provider_id_; }
int handle_id() const { return handle_id_; } int handle_id() const { return handle_id_; }
ServiceWorkerRegistration* registration() { return registration_.get(); } ServiceWorkerRegistration* registration() { return registration_.get(); }
ServiceWorkerVersion* version() { return version_.get(); } ServiceWorkerVersion* version() { return version_.get(); }
...@@ -80,6 +83,7 @@ class CONTENT_EXPORT ServiceWorkerHandle ...@@ -80,6 +83,7 @@ class CONTENT_EXPORT ServiceWorkerHandle
base::WeakPtr<ServiceWorkerContextCore> context_; base::WeakPtr<ServiceWorkerContextCore> context_;
IPC::Sender* sender_; // Not owned, it should always outlive this. IPC::Sender* sender_; // Not owned, it should always outlive this.
const int thread_id_; const int thread_id_;
const int provider_id_;
const int handle_id_; const int handle_id_;
int ref_count_; // Created with 1. int ref_count_; // Created with 1.
scoped_refptr<ServiceWorkerRegistration> registration_; scoped_refptr<ServiceWorkerRegistration> registration_;
......
...@@ -81,6 +81,7 @@ TEST_F(ServiceWorkerHandleTest, OnVersionStateChanged) { ...@@ -81,6 +81,7 @@ TEST_F(ServiceWorkerHandleTest, OnVersionStateChanged) {
ServiceWorkerHandle::Create(helper_->context()->AsWeakPtr(), ServiceWorkerHandle::Create(helper_->context()->AsWeakPtr(),
helper_.get(), helper_.get(),
1 /* thread_id */, 1 /* thread_id */,
33 /* provider_id */,
version_); version_);
// Start the worker, and then... // Start the worker, and then...
......
...@@ -225,8 +225,11 @@ ServiceWorkerObjectInfo ServiceWorkerProviderHost::CreateHandleAndPass( ...@@ -225,8 +225,11 @@ ServiceWorkerObjectInfo ServiceWorkerProviderHost::CreateHandleAndPass(
ServiceWorkerObjectInfo info; ServiceWorkerObjectInfo info;
if (context_ && version) { if (context_ && version) {
scoped_ptr<ServiceWorkerHandle> handle = scoped_ptr<ServiceWorkerHandle> handle =
ServiceWorkerHandle::Create(context_, dispatcher_host_, ServiceWorkerHandle::Create(context_,
kDocumentMainThreadId, version); dispatcher_host_,
kDocumentMainThreadId,
provider_id_,
version);
info = handle->GetObjectInfo(); info = handle->GetObjectInfo();
dispatcher_host_->RegisterServiceWorkerHandle(handle.Pass()); dispatcher_host_->RegisterServiceWorkerHandle(handle.Pass());
} }
......
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