2014-05-13 14:49:36 -07:00
|
|
|
/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#ifndef mozilla_dom_workers_serviceworkerevents_h__
|
|
|
|
#define mozilla_dom_workers_serviceworkerevents_h__
|
|
|
|
|
|
|
|
#include "mozilla/dom/Event.h"
|
2014-11-06 07:57:57 -08:00
|
|
|
#include "mozilla/dom/ExtendableEventBinding.h"
|
2014-05-13 14:49:36 -07:00
|
|
|
#include "mozilla/dom/InstallEventBinding.h"
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
class Promise;
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
BEGIN_WORKERS_NAMESPACE
|
|
|
|
|
|
|
|
class ServiceWorker;
|
|
|
|
|
2014-11-06 07:57:57 -08:00
|
|
|
class ExtendableEvent : public Event
|
2014-05-13 14:49:36 -07:00
|
|
|
{
|
|
|
|
nsRefPtr<Promise> mPromise;
|
|
|
|
|
|
|
|
protected:
|
2014-11-06 07:57:57 -08:00
|
|
|
explicit ExtendableEvent(mozilla::dom::EventTarget* aOwner);
|
|
|
|
~ExtendableEvent() {}
|
2014-05-13 14:49:36 -07:00
|
|
|
|
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
2014-11-06 07:57:57 -08:00
|
|
|
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(ExtendableEvent, Event)
|
2014-05-13 14:49:36 -07:00
|
|
|
NS_FORWARD_TO_EVENT
|
|
|
|
|
2014-10-17 16:16:58 -07:00
|
|
|
virtual JSObject* WrapObjectInternal(JSContext* aCx) MOZ_OVERRIDE
|
2014-05-13 14:49:36 -07:00
|
|
|
{
|
2014-11-06 07:57:57 -08:00
|
|
|
return mozilla::dom::ExtendableEventBinding::Wrap(aCx, this);
|
2014-05-13 14:49:36 -07:00
|
|
|
}
|
|
|
|
|
2014-11-06 07:57:57 -08:00
|
|
|
static already_AddRefed<ExtendableEvent>
|
2014-05-13 14:49:36 -07:00
|
|
|
Constructor(mozilla::dom::EventTarget* aOwner,
|
|
|
|
const nsAString& aType,
|
|
|
|
const EventInit& aOptions)
|
|
|
|
{
|
2014-11-06 07:57:57 -08:00
|
|
|
nsRefPtr<ExtendableEvent> e = new ExtendableEvent(aOwner);
|
2014-05-13 14:49:36 -07:00
|
|
|
bool trusted = e->Init(aOwner);
|
|
|
|
e->InitEvent(aType, aOptions.mBubbles, aOptions.mCancelable);
|
|
|
|
e->SetTrusted(trusted);
|
|
|
|
return e.forget();
|
|
|
|
}
|
|
|
|
|
2014-11-06 07:57:57 -08:00
|
|
|
static already_AddRefed<ExtendableEvent>
|
2014-05-13 14:49:36 -07:00
|
|
|
Constructor(const GlobalObject& aGlobal,
|
|
|
|
const nsAString& aType,
|
|
|
|
const EventInit& aOptions,
|
|
|
|
ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
nsCOMPtr<EventTarget> target = do_QueryInterface(aGlobal.GetAsSupports());
|
|
|
|
return Constructor(target, aType, aOptions);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
WaitUntil(Promise& aPromise);
|
|
|
|
|
|
|
|
already_AddRefed<Promise>
|
|
|
|
GetPromise() const
|
|
|
|
{
|
|
|
|
nsRefPtr<Promise> p = mPromise;
|
|
|
|
return p.forget();
|
|
|
|
}
|
2014-12-19 05:01:53 -08:00
|
|
|
|
|
|
|
virtual ExtendableEvent* AsExtendableEvent() MOZ_OVERRIDE
|
|
|
|
{
|
|
|
|
return this;
|
|
|
|
}
|
2014-05-13 14:49:36 -07:00
|
|
|
};
|
|
|
|
|
2014-11-06 07:57:57 -08:00
|
|
|
class InstallEvent MOZ_FINAL : public ExtendableEvent
|
2014-05-13 14:49:36 -07:00
|
|
|
{
|
|
|
|
// FIXME(nsm): Bug 982787 will allow actually populating this.
|
|
|
|
nsRefPtr<ServiceWorker> mActiveWorker;
|
2014-12-19 02:00:29 -08:00
|
|
|
bool mActivateImmediately;
|
2014-05-13 14:49:36 -07:00
|
|
|
|
|
|
|
protected:
|
2014-09-01 15:26:43 -07:00
|
|
|
explicit InstallEvent(mozilla::dom::EventTarget* aOwner);
|
2014-07-08 14:23:17 -07:00
|
|
|
~InstallEvent() {}
|
2014-05-13 14:49:36 -07:00
|
|
|
|
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
2014-11-06 07:57:57 -08:00
|
|
|
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(InstallEvent, ExtendableEvent)
|
2014-05-13 14:49:36 -07:00
|
|
|
NS_FORWARD_TO_EVENT
|
|
|
|
|
2014-10-17 16:16:58 -07:00
|
|
|
virtual JSObject* WrapObjectInternal(JSContext* aCx) MOZ_OVERRIDE
|
2014-05-13 14:49:36 -07:00
|
|
|
{
|
2015-01-20 13:44:14 -08:00
|
|
|
return mozilla::dom::InstallEventBinding::Wrap(aCx, this);
|
2014-05-13 14:49:36 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static already_AddRefed<InstallEvent>
|
|
|
|
Constructor(mozilla::dom::EventTarget* aOwner,
|
|
|
|
const nsAString& aType,
|
|
|
|
const InstallEventInit& aOptions)
|
|
|
|
{
|
|
|
|
nsRefPtr<InstallEvent> e = new InstallEvent(aOwner);
|
|
|
|
bool trusted = e->Init(aOwner);
|
|
|
|
e->InitEvent(aType, aOptions.mBubbles, aOptions.mCancelable);
|
|
|
|
e->SetTrusted(trusted);
|
|
|
|
e->mActiveWorker = aOptions.mActiveWorker;
|
|
|
|
return e.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
static already_AddRefed<InstallEvent>
|
|
|
|
Constructor(const GlobalObject& aGlobal,
|
|
|
|
const nsAString& aType,
|
|
|
|
const InstallEventInit& aOptions,
|
|
|
|
ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
nsCOMPtr<EventTarget> owner = do_QueryInterface(aGlobal.GetAsSupports());
|
|
|
|
return Constructor(owner, aType, aOptions);
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<ServiceWorker>
|
|
|
|
GetActiveWorker() const
|
|
|
|
{
|
|
|
|
nsRefPtr<ServiceWorker> sw = mActiveWorker;
|
|
|
|
return sw.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Replace()
|
|
|
|
{
|
2014-12-19 02:00:29 -08:00
|
|
|
mActivateImmediately = true;
|
2014-05-13 14:49:36 -07:00
|
|
|
};
|
2014-12-19 02:00:29 -08:00
|
|
|
|
|
|
|
bool
|
|
|
|
ActivateImmediately() const
|
|
|
|
{
|
|
|
|
return mActivateImmediately;
|
|
|
|
}
|
2014-12-19 05:01:53 -08:00
|
|
|
|
|
|
|
InstallEvent* AsInstallEvent() MOZ_OVERRIDE
|
|
|
|
{
|
|
|
|
return this;
|
|
|
|
}
|
2014-05-13 14:49:36 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
END_WORKERS_NAMESPACE
|
|
|
|
#endif /* mozilla_dom_workers_serviceworkerevents_h__ */
|