Bug 1252055 P1 Make equivalent ServiceWorker DOM objects strictly equal in js. r=ehsan

This commit is contained in:
Ben Kelly 2016-03-03 19:37:57 -05:00
Родитель 5bd73efa9b
Коммит a9358d515b
3 изменённых файлов: 30 добавлений и 4 удалений

Просмотреть файл

@ -27,7 +27,7 @@ ServiceWorkerVisible(JSContext* aCx, JSObject* aObj);
class ServiceWorker final : public DOMEventTargetHelper
{
friend class ServiceWorkerManager;
friend class ServiceWorkerInfo;
public:
NS_DECL_ISUPPORTS_INHERITED
@ -68,7 +68,7 @@ public:
ErrorResult& aRv);
private:
// This class can only be created from the ServiceWorkerManager.
// This class can only be created from ServiceWorkerInfo::GetOrCreateInstance().
ServiceWorker(nsPIDOMWindowInner* aWindow, ServiceWorkerInfo* aInfo);
// This class is reference-counted and will be destroyed from Release().

Просмотреть файл

@ -3566,7 +3566,7 @@ ServiceWorkerManager::GetServiceWorkerForScope(nsPIDOMWindowInner* aWindow,
return NS_ERROR_DOM_NOT_FOUND_ERR;
}
RefPtr<ServiceWorker> serviceWorker = new ServiceWorker(aWindow, info);
RefPtr<ServiceWorker> serviceWorker = info->GetOrCreateInstance(aWindow);
serviceWorker->SetState(info->State());
serviceWorker.forget(aServiceWorker);
@ -3793,7 +3793,7 @@ ServiceWorkerManager::GetDocumentController(nsPIDOMWindowInner* aWindow,
MOZ_ASSERT(registration->mActiveWorker);
RefPtr<ServiceWorker> serviceWorker =
new ServiceWorker(aWindow, registration->mActiveWorker);
registration->mActiveWorker->GetOrCreateInstance(aWindow);
serviceWorker.forget(aServiceWorker);
return NS_OK;
@ -5250,4 +5250,27 @@ ServiceWorkerInfo::GetNextID() const
return ++gServiceWorkerInfoCurrentID;
}
already_AddRefed<ServiceWorker>
ServiceWorkerInfo::GetOrCreateInstance(nsPIDOMWindowInner* aWindow)
{
AssertIsOnMainThread();
MOZ_ASSERT(aWindow);
RefPtr<ServiceWorker> ref;
for (uint32_t i = 0; i < mInstances.Length(); ++i) {
MOZ_ASSERT(mInstances[i]);
if (mInstances[i]->GetOwner() == aWindow) {
ref = mInstances[i];
break;
}
}
if (!ref) {
ref = new ServiceWorker(aWindow, this);
}
return ref.forget();
}
END_WORKERS_NAMESPACE

Просмотреть файл

@ -305,6 +305,9 @@ public:
void
RemoveWorker(ServiceWorker* aWorker);
already_AddRefed<ServiceWorker>
GetOrCreateInstance(nsPIDOMWindowInner* aWindow);
};
#define NS_SERVICEWORKERMANAGER_IMPL_IID \