1 /* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
2 /* vim: set ts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #include "ServiceWorkerEvents.h"
9 #include "nsContentUtils.h"
11 #include "mozilla/dom/Promise.h"
12 #include "mozilla/dom/WorkerScope.h"
13 #include "mozilla/dom/workers/bindings/ServiceWorker.h"
14 #include "mozilla/dom/ServiceWorkerGlobalScopeBinding.h"
16 using namespace mozilla::dom
;
18 BEGIN_WORKERS_NAMESPACE
21 ServiceWorkerEventsVisible(JSContext
* aCx
, JSObject
* aObj
)
23 ServiceWorkerGlobalScope
* scope
= nullptr;
24 nsresult rv
= UnwrapObject
<prototypes::id::ServiceWorkerGlobalScope_workers
,
25 mozilla::dom::ServiceWorkerGlobalScopeBinding_workers::NativeType
>(aObj
, scope
);
26 return NS_SUCCEEDED(rv
) && scope
;
29 InstallPhaseEvent::InstallPhaseEvent(EventTarget
* aOwner
)
30 : Event(aOwner
, nullptr, nullptr)
35 InstallPhaseEvent::WaitUntil(Promise
& aPromise
)
37 MOZ_ASSERT(!NS_IsMainThread());
39 // Only first caller counts.
40 if (EventPhase() == AT_TARGET
&& !mPromise
) {
45 NS_IMPL_ADDREF_INHERITED(InstallPhaseEvent
, Event
)
46 NS_IMPL_RELEASE_INHERITED(InstallPhaseEvent
, Event
)
48 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(InstallPhaseEvent
)
49 NS_INTERFACE_MAP_END_INHERITING(Event
)
51 NS_IMPL_CYCLE_COLLECTION_INHERITED(InstallPhaseEvent
, Event
, mPromise
)
53 InstallEvent::InstallEvent(EventTarget
* aOwner
)
54 : InstallPhaseEvent(aOwner
)
58 NS_IMPL_ADDREF_INHERITED(InstallEvent
, InstallPhaseEvent
)
59 NS_IMPL_RELEASE_INHERITED(InstallEvent
, InstallPhaseEvent
)
61 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(InstallEvent
)
62 NS_INTERFACE_MAP_END_INHERITING(InstallPhaseEvent
)
64 NS_IMPL_CYCLE_COLLECTION_INHERITED(InstallEvent
, InstallPhaseEvent
, mActiveWorker
)