2015-05-03 12:32:37 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2014-05-13 14:49:36 -07:00
|
|
|
/* 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"
|
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-04-20 18:47:13 -07:00
|
|
|
#include "mozilla/dom/workers/bindings/ServiceWorker.h"
|
2015-04-10 20:19:28 -07:00
|
|
|
|
|
|
|
#ifndef MOZ_SIMPLEPUSH
|
|
|
|
#include "mozilla/dom/PushEventBinding.h"
|
|
|
|
#include "mozilla/dom/PushMessageDataBinding.h"
|
|
|
|
#endif
|
|
|
|
|
2015-02-18 17:34:29 -08:00
|
|
|
#include "nsProxyRelease.h"
|
2015-07-27 12:35:28 -07:00
|
|
|
#include "nsContentUtils.h"
|
2015-02-18 17:34:29 -08:00
|
|
|
|
|
|
|
class nsIInterceptedChannel;
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
2015-05-12 05:09:51 -07:00
|
|
|
class Blob;
|
|
|
|
class Request;
|
|
|
|
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
|
|
|
|
|
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-07-31 10:30:55 -07:00
|
|
|
RespondWith(Promise& 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
|
|
|
{
|
2015-08-24 15:09:47 -07:00
|
|
|
nsRefPtr<Promise> mPromise;
|
2014-05-13 14:49:36 -07:00
|
|
|
|
|
|
|
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
|
2015-08-18 16:28:04 -07:00
|
|
|
WaitUntil(Promise& aPromise, ErrorResult& aRv);
|
2014-05-13 14:49:36 -07:00
|
|
|
|
|
|
|
already_AddRefed<Promise>
|
2015-08-24 15:09:47 -07:00
|
|
|
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-04-10 20:19:28 -07:00
|
|
|
#ifndef MOZ_SIMPLEPUSH
|
|
|
|
|
|
|
|
class PushMessageData final : public nsISupports,
|
|
|
|
public nsWrapperCache
|
|
|
|
{
|
|
|
|
nsString mData;
|
|
|
|
|
|
|
|
public:
|
2015-07-17 15:17:14 -07:00
|
|
|
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
|
|
|
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(PushMessageData)
|
2015-04-10 20:19:28 -07:00
|
|
|
|
|
|
|
virtual JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override
|
|
|
|
{
|
|
|
|
return mozilla::dom::PushMessageDataBinding_workers::Wrap(aCx, this, aGivenProto);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsISupports* GetParentObject() const {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Json(JSContext* cx, JS::MutableHandle<JSObject*> aRetval);
|
|
|
|
void Text(nsAString& aData);
|
|
|
|
void ArrayBuffer(JSContext* cx, JS::MutableHandle<JSObject*> aRetval);
|
2015-05-12 05:09:51 -07:00
|
|
|
mozilla::dom::Blob* Blob();
|
2015-04-10 20:19:28 -07:00
|
|
|
|
|
|
|
explicit PushMessageData(const nsAString& aData);
|
|
|
|
private:
|
|
|
|
~PushMessageData();
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
class PushEvent final : public ExtendableEvent
|
|
|
|
{
|
2015-08-03 11:04:41 -07:00
|
|
|
// FIXME(nsm): Bug 1149195.
|
|
|
|
// nsRefPtr<PushMessageData> mData;
|
2015-04-10 20:19:28 -07:00
|
|
|
nsMainThreadPtrHandle<ServiceWorker> mServiceWorker;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
explicit PushEvent(mozilla::dom::EventTarget* aOwner);
|
|
|
|
~PushEvent() {}
|
|
|
|
|
|
|
|
public:
|
2015-08-03 11:04:41 -07:00
|
|
|
// FIXME(nsm): Bug 1149195.
|
|
|
|
// Add cycle collection macros once data is re-exposed.
|
2015-04-10 20:19:28 -07:00
|
|
|
NS_FORWARD_TO_EVENT
|
|
|
|
|
|
|
|
virtual JSObject* WrapObjectInternal(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override
|
|
|
|
{
|
|
|
|
return mozilla::dom::PushEventBinding_workers::Wrap(aCx, this, aGivenProto);
|
|
|
|
}
|
|
|
|
|
|
|
|
static already_AddRefed<PushEvent>
|
|
|
|
Constructor(mozilla::dom::EventTarget* aOwner,
|
|
|
|
const nsAString& aType,
|
|
|
|
const PushEventInit& aOptions)
|
|
|
|
{
|
|
|
|
nsRefPtr<PushEvent> e = new PushEvent(aOwner);
|
|
|
|
bool trusted = e->Init(aOwner);
|
|
|
|
e->InitEvent(aType, aOptions.mBubbles, aOptions.mCancelable);
|
|
|
|
e->SetTrusted(trusted);
|
2015-08-03 11:04:41 -07:00
|
|
|
// FIXME(nsm): Bug 1149195.
|
|
|
|
//if(aOptions.mData.WasPassed()){
|
|
|
|
// e->mData = new PushMessageData(aOptions.mData.Value());
|
|
|
|
//}
|
2015-04-10 20:19:28 -07:00
|
|
|
return e.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
static already_AddRefed<PushEvent>
|
|
|
|
Constructor(const GlobalObject& aGlobal,
|
|
|
|
const nsAString& aType,
|
|
|
|
const PushEventInit& aOptions,
|
|
|
|
ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
nsCOMPtr<EventTarget> owner = do_QueryInterface(aGlobal.GetAsSupports());
|
|
|
|
return Constructor(owner, aType, aOptions);
|
|
|
|
}
|
|
|
|
|
|
|
|
void PostInit(nsMainThreadPtrHandle<ServiceWorker>& aServiceWorker)
|
|
|
|
{
|
|
|
|
mServiceWorker = aServiceWorker;
|
|
|
|
}
|
|
|
|
|
2015-07-14 13:10:58 -07:00
|
|
|
PushMessageData* Data()
|
2015-04-10 20:19:28 -07:00
|
|
|
{
|
2015-08-03 11:04:41 -07:00
|
|
|
// FIXME(nsm): Bug 1149195.
|
|
|
|
MOZ_CRASH("Should not be called!");
|
|
|
|
return nullptr;
|
2015-04-10 20:19:28 -07:00
|
|
|
}
|
|
|
|
};
|
|
|
|
#endif /* ! MOZ_SIMPLEPUSH */
|
|
|
|
|
2014-05-13 14:49:36 -07:00
|
|
|
END_WORKERS_NAMESPACE
|
|
|
|
#endif /* mozilla_dom_workers_serviceworkerevents_h__ */
|