Bug 1446287 - Port AllowWindowInteractionHandler to WorkerRef, r=catalinb

This commit is contained in:
Andrea Marchesini 2018-03-16 15:46:21 +01:00
Родитель 4368f4dfab
Коммит 0586913a90
1 изменённых файлов: 19 добавлений и 17 удалений

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

@ -34,6 +34,7 @@
#include "mozilla/dom/PushEventBinding.h" #include "mozilla/dom/PushEventBinding.h"
#include "mozilla/dom/RequestBinding.h" #include "mozilla/dom/RequestBinding.h"
#include "mozilla/dom/WorkerDebugger.h" #include "mozilla/dom/WorkerDebugger.h"
#include "mozilla/dom/WorkerRef.h"
#include "mozilla/dom/WorkerRunnable.h" #include "mozilla/dom/WorkerRunnable.h"
#include "mozilla/dom/WorkerScope.h" #include "mozilla/dom/WorkerScope.h"
#include "mozilla/Unused.h" #include "mozilla/Unused.h"
@ -1072,15 +1073,15 @@ namespace {
class AllowWindowInteractionHandler final : public ExtendableEventCallback class AllowWindowInteractionHandler final : public ExtendableEventCallback
, public nsITimerCallback , public nsITimerCallback
, public nsINamed , public nsINamed
, public WorkerHolder
{ {
nsCOMPtr<nsITimer> mTimer; nsCOMPtr<nsITimer> mTimer;
RefPtr<StrongWorkerRef> mWorkerRef;
~AllowWindowInteractionHandler() ~AllowWindowInteractionHandler()
{ {
// We must either fail to initialize or call ClearWindowAllowed. // We must either fail to initialize or call ClearWindowAllowed.
MOZ_DIAGNOSTIC_ASSERT(!mTimer); MOZ_DIAGNOSTIC_ASSERT(!mTimer);
MOZ_DIAGNOSTIC_ASSERT(!mWorkerPrivate); MOZ_DIAGNOSTIC_ASSERT(!mWorkerRef);
} }
void void
@ -1105,7 +1106,7 @@ class AllowWindowInteractionHandler final : public ExtendableEventCallback
mTimer->Cancel(); mTimer->Cancel();
mTimer = nullptr; mTimer = nullptr;
ReleaseWorker(); mWorkerRef = nullptr;
} }
void void
@ -1121,7 +1122,19 @@ class AllowWindowInteractionHandler final : public ExtendableEventCallback
return; return;
} }
if (!HoldWorker(aWorkerPrivate, Closing)) { MOZ_ASSERT(!mWorkerRef);
RefPtr<AllowWindowInteractionHandler> self = this;
mWorkerRef =
StrongWorkerRef::Create(aWorkerPrivate,
"AllowWindowInteractionHandler",
[self]() {
// We could try to hold the worker alive until the timer fires, but
// other APIs are not likely to work in this partially shutdown state.
// We might as well let the worker thread exit.
self->ClearWindowAllowed(self->mWorkerRef->Private());
});
if (!mWorkerRef) {
return; return;
} }
@ -1147,7 +1160,8 @@ class AllowWindowInteractionHandler final : public ExtendableEventCallback
Notify(nsITimer* aTimer) override Notify(nsITimer* aTimer) override
{ {
MOZ_DIAGNOSTIC_ASSERT(mTimer == aTimer); MOZ_DIAGNOSTIC_ASSERT(mTimer == aTimer);
ClearWindowAllowed(mWorkerPrivate); WorkerPrivate* workerPrivate = GetCurrentThreadWorkerPrivate();
ClearWindowAllowed(workerPrivate);
return NS_OK; return NS_OK;
} }
@ -1159,22 +1173,10 @@ class AllowWindowInteractionHandler final : public ExtendableEventCallback
return NS_OK; return NS_OK;
} }
// WorkerHolder virtual methods
bool
Notify(WorkerStatus aStatus) override
{
// We could try to hold the worker alive until the timer fires, but other
// APIs are not likely to work in this partially shutdown state. We might
// as well let the worker thread exit.
ClearWindowAllowed(mWorkerPrivate);
return true;
}
public: public:
NS_DECL_THREADSAFE_ISUPPORTS NS_DECL_THREADSAFE_ISUPPORTS
explicit AllowWindowInteractionHandler(WorkerPrivate* aWorkerPrivate) explicit AllowWindowInteractionHandler(WorkerPrivate* aWorkerPrivate)
: WorkerHolder("AllowWindowInteractionHandler")
{ {
StartClearWindowTimer(aWorkerPrivate); StartClearWindowTimer(aWorkerPrivate);
} }