Backed out changeset 4ed31c8b45c6 (
bug 1041340) for causing multiple timeouts on different platforms in service worker tests on a CLOSED TREE
--- a/dom/workers/ServiceWorkerManager.cpp
+++ b/dom/workers/ServiceWorkerManager.cpp
@@ -1925,71 +1925,46 @@ ServiceWorkerManager::RemoveScope(nsTArr
{
aList.RemoveElement(aScope);
}
void
ServiceWorkerManager::MaybeStartControlling(nsIDocument* aDoc)
{
AssertIsOnMainThread();
+ if (!Preferences::GetBool("dom.serviceWorkers.enabled")) {
+ return;
+ }
+
nsRefPtr<ServiceWorkerRegistrationInfo> registration =
GetServiceWorkerRegistrationInfo(aDoc);
if (registration) {
MOZ_ASSERT(!mControlledDocuments.Contains(aDoc));
registration->StartControllingADocument();
// Use the already_AddRefed<> form of Put to avoid the addref-deref since
// we don't need the registration pointer in this function anymore.
mControlledDocuments.Put(aDoc, registration.forget());
}
}
-class ServiceWorkerActivateAfterUnloadingJob MOZ_FINAL : public ServiceWorkerJob
-{
- nsRefPtr<ServiceWorkerRegistrationInfo> mRegistration;
-public:
- ServiceWorkerActivateAfterUnloadingJob(ServiceWorkerJobQueue* aQueue,
- ServiceWorkerRegistrationInfo* aReg)
- : ServiceWorkerJob(aQueue)
- , mRegistration(aReg)
- { }
-
- void
- Start()
- {
- if (mRegistration->mPendingUninstall) {
- mRegistration->Clear();
- nsRefPtr<ServiceWorkerManager> swm = ServiceWorkerManager::GetInstance();
- swm->RemoveRegistration(mRegistration);
- } else {
- mRegistration->TryToActivate();
- }
-
- Done(NS_OK);
- }
-};
-
void
ServiceWorkerManager::MaybeStopControlling(nsIDocument* aDoc)
{
MOZ_ASSERT(aDoc);
+ if (!Preferences::GetBool("dom.serviceWorkers.enabled")) {
+ return;
+ }
+
nsRefPtr<ServiceWorkerRegistrationInfo> registration;
mControlledDocuments.Remove(aDoc, getter_AddRefs(registration));
// A document which was uncontrolled does not maintain that state itself, so
// it will always call MaybeStopControlling() even if there isn't an
// associated registration. So this check is required.
if (registration) {
registration->StopControllingADocument();
- if (!registration->IsControllingDocuments()) {
- ServiceWorkerJobQueue* queue = GetOrCreateJobQueue(registration->mScope);
- // The remaining tasks touch registration->mPendingUninstall, so queue
- // them up in a job.
- nsRefPtr<ServiceWorkerActivateAfterUnloadingJob> job =
- new ServiceWorkerActivateAfterUnloadingJob(queue, registration);
- queue->Append(job);
- }
}
}
NS_IMETHODIMP
ServiceWorkerManager::GetScopeForUrl(const nsAString& aUrl, nsAString& aScope)
{
nsCOMPtr<nsIURI> uri;
nsresult rv = NS_NewURI(getter_AddRefs(uri), aUrl, nullptr, nullptr);
--- a/dom/workers/ServiceWorkerManager.h
+++ b/dom/workers/ServiceWorkerManager.h
@@ -285,23 +285,22 @@ public:
* installation, querying and event dispatch of ServiceWorkers for all the
* origins in the process.
*/
class ServiceWorkerManager MOZ_FINAL
: public nsIServiceWorkerManager
, public nsIIPCBackgroundChildCreateCallback
{
friend class ActivationRunnable;
+ friend class ServiceWorkerRegistrationInfo;
+ friend class ServiceWorkerRegisterJob;
friend class GetReadyPromiseRunnable;
friend class GetRegistrationsRunnable;
friend class GetRegistrationRunnable;
friend class QueueFireUpdateFoundRunnable;
- friend class ServiceWorkerActivateAfterUnloadingJob;
- friend class ServiceWorkerRegisterJob;
- friend class ServiceWorkerRegistrationInfo;
friend class ServiceWorkerUnregisterJob;
public:
NS_DECL_ISUPPORTS
NS_DECL_NSISERVICEWORKERMANAGER
NS_DECL_NSIIPCBACKGROUNDCHILDCREATECALLBACK
NS_DECLARE_STATIC_IID_ACCESSOR(NS_SERVICEWORKERMANAGER_IMPL_IID)
@@ -345,18 +344,16 @@ public:
}
ServiceWorkerRegistrationInfo*
CreateNewRegistration(const nsCString& aScope, nsIPrincipal* aPrincipal);
void
RemoveRegistration(ServiceWorkerRegistrationInfo* aRegistration)
{
- MOZ_ASSERT(aRegistration);
- MOZ_ASSERT(!aRegistration->IsControllingDocuments());
MOZ_ASSERT(mServiceWorkerRegistrationInfos.Contains(aRegistration->mScope));
ServiceWorkerManager::RemoveScope(mOrderedScopes, aRegistration->mScope);
mServiceWorkerRegistrationInfos.Remove(aRegistration->mScope);
}
ServiceWorkerJobQueue*
GetOrCreateJobQueue(const nsCString& aScope)
{
--- a/dom/workers/test/serviceworkers/test_installation_simple.html
+++ b/dom/workers/test/serviceworkers/test_installation_simple.html
@@ -135,17 +135,18 @@
window.onmessage = function(e) {
if (e.data.type == "ready") {
continueTest();
} else if (e.data.type == "finish") {
window.onmessage = null;
// We have to make frame navigate away, otherwise it will call
// MaybeStopControlling() when this document is unloaded. At that point
- // the pref has been disabled, so the ServiceWorkerManager is not available.
+ // the pref has been disabled, and so MaybeStopControlling() will just
+ // return since it is currently gated.
frame.setAttribute("src", new URL("about:blank").href);
resolve();
} else if (e.data.type == "check") {
ok(e.data.status, e.data.msg);
}
}
return p;
}