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"
|
2015-02-18 17:34:29 -08:00
|
|
|
#include "mozilla/dom/FetchEventBinding.h"
|
2014-05-13 14:49:36 -07:00
|
|
|
#include "mozilla/dom/InstallEventBinding.h"
|
2015-02-06 10:08:31 -08:00
|
|
|
#include "mozilla/dom/Promise.h"
|
2015-03-20 08:44:20 -07:00
|
|
|
#include "mozilla/dom/Response.h"
|
2015-02-18 17:34:29 -08:00
|
|
|
#include "nsProxyRelease.h"
|
|
|
|
|
|
|
|
class nsIInterceptedChannel;
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
class Request;
|
2015-03-24 00:37:39 -07:00
|
|
|
class ResponseOrPromise;
|
2015-02-18 17:34:29 -08:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
2014-05-13 14:49:36 -07:00
|
|
|
|
|
|
|
BEGIN_WORKERS_NAMESPACE
|
|
|
|
|
|
|
|
class ServiceWorker;
|
2015-02-18 17:34:29 -08:00
|
|
|
class ServiceWorkerClient;
|
|
|
|
|
2015-03-21 09:28:04 -07:00
|
|
|
class FetchEvent final : public Event
|
2015-02-18 17:34:29 -08:00
|
|
|
{
|
|
|
|
nsMainThreadPtrHandle<nsIInterceptedChannel> mChannel;
|
|
|
|
nsMainThreadPtrHandle<ServiceWorker> mServiceWorker;
|
|
|
|
nsRefPtr<ServiceWorkerClient> mClient;
|
|
|
|
nsRefPtr<Request> mRequest;
|
2015-03-06 05:04:49 -08:00
|
|
|
nsAutoPtr<ServiceWorkerClientInfo> mClientInfo;
|
2015-02-18 17:34:29 -08:00
|
|
|
bool mIsReload;
|
|
|
|
bool mWaitToRespond;
|
|
|
|
protected:
|
|
|
|
explicit FetchEvent(EventTarget* aOwner);
|
|
|
|
~FetchEvent();
|
|
|
|
|
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
|
|
|
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(FetchEvent, Event)
|
|
|
|
NS_FORWARD_TO_EVENT
|
|
|
|
|
2015-03-21 09:28:04 -07:00
|
|
|
virtual JSObject* WrapObjectInternal(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override
|
2015-02-18 17:34:29 -08:00
|
|
|
{
|
Bug 1117172 part 3. Change the wrappercached WrapObject methods to allow passing in aGivenProto. r=peterv
The only manual changes here are to BindingUtils.h, BindingUtils.cpp,
Codegen.py, Element.cpp, IDBFileRequest.cpp, IDBObjectStore.cpp,
dom/workers/Navigator.cpp, WorkerPrivate.cpp, DeviceStorageRequestChild.cpp,
Notification.cpp, nsGlobalWindow.cpp, MessagePort.cpp, nsJSEnvironment.cpp,
Sandbox.cpp, XPCConvert.cpp, ExportHelpers.cpp, and DataStoreService.cpp. The
rest of this diff was generated by running the following commands:
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObject\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(Binding(?:_workers)?::Wrap\((?:aCx|cx|aContext|aCtx|js), [^,)]+)\)/\1, aGivenProto)/g'
2015-03-19 07:13:33 -07:00
|
|
|
return FetchEventBinding::Wrap(aCx, this, aGivenProto);
|
2015-02-18 17:34:29 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
void PostInit(nsMainThreadPtrHandle<nsIInterceptedChannel>& aChannel,
|
|
|
|
nsMainThreadPtrHandle<ServiceWorker>& aServiceWorker,
|
2015-03-06 05:04:49 -08:00
|
|
|
nsAutoPtr<ServiceWorkerClientInfo>& aClientInfo);
|
2015-02-18 17:34:29 -08:00
|
|
|
|
|
|
|
static already_AddRefed<FetchEvent>
|
|
|
|
Constructor(const GlobalObject& aGlobal,
|
|
|
|
const nsAString& aType,
|
|
|
|
const FetchEventInit& aOptions,
|
|
|
|
ErrorResult& aRv);
|
|
|
|
|
|
|
|
bool
|
|
|
|
WaitToRespond() const
|
|
|
|
{
|
|
|
|
return mWaitToRespond;
|
|
|
|
}
|
|
|
|
|
|
|
|
Request*
|
|
|
|
Request_() const
|
|
|
|
{
|
|
|
|
return mRequest;
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<ServiceWorkerClient>
|
2015-03-06 05:04:49 -08:00
|
|
|
GetClient();
|
2015-02-18 17:34:29 -08:00
|
|
|
|
|
|
|
bool
|
|
|
|
IsReload() const
|
|
|
|
{
|
|
|
|
return mIsReload;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2015-03-24 00:37:39 -07:00
|
|
|
RespondWith(const ResponseOrPromise& aArg, ErrorResult& aRv);
|
2015-03-20 08:44:20 -07:00
|
|
|
|
2015-02-18 17:34:29 -08:00
|
|
|
already_AddRefed<Promise>
|
|
|
|
ForwardTo(const nsAString& aUrl);
|
|
|
|
|
|
|
|
already_AddRefed<Promise>
|
|
|
|
Default();
|
|
|
|
};
|
2014-05-13 14:49:36 -07:00
|
|
|
|
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
|
|
|
|
|
2015-03-21 09:28:04 -07:00
|
|
|
virtual JSObject* WrapObjectInternal(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override
|
2014-05-13 14:49:36 -07:00
|
|
|
{
|
Bug 1117172 part 3. Change the wrappercached WrapObject methods to allow passing in aGivenProto. r=peterv
The only manual changes here are to BindingUtils.h, BindingUtils.cpp,
Codegen.py, Element.cpp, IDBFileRequest.cpp, IDBObjectStore.cpp,
dom/workers/Navigator.cpp, WorkerPrivate.cpp, DeviceStorageRequestChild.cpp,
Notification.cpp, nsGlobalWindow.cpp, MessagePort.cpp, nsJSEnvironment.cpp,
Sandbox.cpp, XPCConvert.cpp, ExportHelpers.cpp, and DataStoreService.cpp. The
rest of this diff was generated by running the following commands:
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObject\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(Binding(?:_workers)?::Wrap\((?:aCx|cx|aContext|aCtx|js), [^,)]+)\)/\1, aGivenProto)/g'
2015-03-19 07:13:33 -07:00
|
|
|
return mozilla::dom::ExtendableEventBinding::Wrap(aCx, this, aGivenProto);
|
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
|
|
|
|
2015-03-21 09:28:04 -07:00
|
|
|
virtual ExtendableEvent* AsExtendableEvent() override
|
2014-12-19 05:01:53 -08:00
|
|
|
{
|
|
|
|
return this;
|
|
|
|
}
|
2014-05-13 14:49:36 -07:00
|
|
|
};
|
|
|
|
|
2015-03-21 09:28:04 -07:00
|
|
|
class InstallEvent 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
|
|
|
|
|
2015-03-21 09:28:04 -07:00
|
|
|
virtual JSObject* WrapObjectInternal(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override
|
2014-05-13 14:49:36 -07:00
|
|
|
{
|
Bug 1117172 part 3. Change the wrappercached WrapObject methods to allow passing in aGivenProto. r=peterv
The only manual changes here are to BindingUtils.h, BindingUtils.cpp,
Codegen.py, Element.cpp, IDBFileRequest.cpp, IDBObjectStore.cpp,
dom/workers/Navigator.cpp, WorkerPrivate.cpp, DeviceStorageRequestChild.cpp,
Notification.cpp, nsGlobalWindow.cpp, MessagePort.cpp, nsJSEnvironment.cpp,
Sandbox.cpp, XPCConvert.cpp, ExportHelpers.cpp, and DataStoreService.cpp. The
rest of this diff was generated by running the following commands:
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObject\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(Binding(?:_workers)?::Wrap\((?:aCx|cx|aContext|aCtx|js), [^,)]+)\)/\1, aGivenProto)/g'
2015-03-19 07:13:33 -07:00
|
|
|
return mozilla::dom::InstallEventBinding::Wrap(aCx, this, aGivenProto);
|
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
|
|
|
|
2015-03-21 09:28:04 -07:00
|
|
|
InstallEvent* AsInstallEvent() override
|
2014-12-19 05:01:53 -08:00
|
|
|
{
|
|
|
|
return this;
|
|
|
|
}
|
2014-05-13 14:49:36 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
END_WORKERS_NAMESPACE
|
|
|
|
#endif /* mozilla_dom_workers_serviceworkerevents_h__ */
|