2013-03-18 06:24:54 -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_notification_h__
|
|
|
|
#define mozilla_dom_notification_h__
|
|
|
|
|
2014-03-31 23:13:50 -07:00
|
|
|
#include "mozilla/DOMEventTargetHelper.h"
|
2013-03-18 06:24:54 -07:00
|
|
|
#include "mozilla/dom/NotificationBinding.h"
|
|
|
|
|
|
|
|
#include "nsIObserver.h"
|
|
|
|
|
2013-10-02 18:27:53 -07:00
|
|
|
#include "nsCycleCollectionParticipant.h"
|
|
|
|
|
2013-11-11 15:56:21 -08:00
|
|
|
class nsIPrincipal;
|
2014-08-20 17:56:12 -07:00
|
|
|
class nsIStructuredCloneContainer;
|
|
|
|
class nsIVariant;
|
2013-11-11 15:56:21 -08:00
|
|
|
|
2013-03-18 06:24:54 -07:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
2013-10-02 18:27:53 -07:00
|
|
|
|
2013-03-18 06:24:54 -07:00
|
|
|
class NotificationObserver;
|
2013-10-02 18:27:53 -07:00
|
|
|
class Promise;
|
2013-03-18 06:24:54 -07:00
|
|
|
|
2014-03-31 23:13:50 -07:00
|
|
|
class Notification : public DOMEventTargetHelper
|
2013-03-18 06:24:54 -07:00
|
|
|
{
|
|
|
|
friend class NotificationTask;
|
|
|
|
friend class NotificationPermissionRequest;
|
|
|
|
friend class NotificationObserver;
|
2013-10-02 18:27:53 -07:00
|
|
|
friend class NotificationStorageCallback;
|
|
|
|
|
2013-03-18 06:24:54 -07:00
|
|
|
public:
|
|
|
|
IMPL_EVENT_HANDLER(click)
|
|
|
|
IMPL_EVENT_HANDLER(show)
|
|
|
|
IMPL_EVENT_HANDLER(error)
|
|
|
|
IMPL_EVENT_HANDLER(close)
|
|
|
|
|
2014-08-20 17:56:12 -07:00
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
|
|
|
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(Notification, DOMEventTargetHelper)
|
|
|
|
|
2013-03-18 06:24:54 -07:00
|
|
|
static already_AddRefed<Notification> Constructor(const GlobalObject& aGlobal,
|
|
|
|
const nsAString& aTitle,
|
|
|
|
const NotificationOptions& aOption,
|
|
|
|
ErrorResult& aRv);
|
2013-10-02 18:27:53 -07:00
|
|
|
void GetID(nsAString& aRetval) {
|
|
|
|
aRetval = mID;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GetTitle(nsAString& aRetval)
|
2013-09-12 02:50:29 -07:00
|
|
|
{
|
|
|
|
aRetval = mTitle;
|
|
|
|
}
|
|
|
|
|
|
|
|
NotificationDirection Dir()
|
|
|
|
{
|
|
|
|
return mDir;
|
|
|
|
}
|
|
|
|
|
2013-10-02 18:27:53 -07:00
|
|
|
void GetLang(nsAString& aRetval)
|
2013-09-12 02:50:29 -07:00
|
|
|
{
|
|
|
|
aRetval = mLang;
|
|
|
|
}
|
|
|
|
|
2013-10-02 18:27:53 -07:00
|
|
|
void GetBody(nsAString& aRetval)
|
2013-09-12 02:50:29 -07:00
|
|
|
{
|
|
|
|
aRetval = mBody;
|
|
|
|
}
|
|
|
|
|
2013-10-02 18:27:53 -07:00
|
|
|
void GetTag(nsAString& aRetval)
|
2013-09-12 02:50:29 -07:00
|
|
|
{
|
2013-10-02 18:27:53 -07:00
|
|
|
aRetval = mTag;
|
2013-09-12 02:50:29 -07:00
|
|
|
}
|
|
|
|
|
2013-10-02 18:27:53 -07:00
|
|
|
void GetIcon(nsAString& aRetval)
|
2013-09-12 02:50:29 -07:00
|
|
|
{
|
|
|
|
aRetval = mIconUrl;
|
|
|
|
}
|
2013-03-18 06:24:54 -07:00
|
|
|
|
2014-09-12 07:50:00 -07:00
|
|
|
void SetStoredState(bool val)
|
|
|
|
{
|
|
|
|
mIsStored = val;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IsStored()
|
|
|
|
{
|
|
|
|
return mIsStored;
|
|
|
|
}
|
|
|
|
|
2014-08-20 17:56:12 -07:00
|
|
|
nsIStructuredCloneContainer* GetDataCloneContainer();
|
|
|
|
|
2013-03-18 06:24:54 -07:00
|
|
|
static void RequestPermission(const GlobalObject& aGlobal,
|
|
|
|
const Optional<OwningNonNull<NotificationPermissionCallback> >& aCallback,
|
|
|
|
ErrorResult& aRv);
|
|
|
|
|
|
|
|
static NotificationPermission GetPermission(const GlobalObject& aGlobal,
|
|
|
|
ErrorResult& aRv);
|
|
|
|
|
2013-10-02 18:27:53 -07:00
|
|
|
static already_AddRefed<Promise> Get(const GlobalObject& aGlobal,
|
|
|
|
const GetNotificationOptions& aFilter,
|
|
|
|
ErrorResult& aRv);
|
|
|
|
|
2013-03-18 06:24:54 -07:00
|
|
|
void Close();
|
|
|
|
|
|
|
|
nsPIDOMWindow* GetParentObject()
|
|
|
|
{
|
|
|
|
return GetOwner();
|
|
|
|
}
|
|
|
|
|
2014-04-08 15:27:18 -07:00
|
|
|
virtual JSObject* WrapObject(JSContext* aCx) MOZ_OVERRIDE;
|
2014-08-20 17:56:12 -07:00
|
|
|
|
|
|
|
void GetData(JSContext* aCx, JS::MutableHandle<JS::Value> aRetval);
|
|
|
|
|
|
|
|
void InitFromJSVal(JSContext* aCx, JS::Handle<JS::Value> aData, ErrorResult& aRv);
|
|
|
|
|
|
|
|
void InitFromBase64(JSContext* aCx, const nsAString& aData, ErrorResult& aRv);
|
2014-09-16 14:12:00 -07:00
|
|
|
|
2013-03-18 06:24:54 -07:00
|
|
|
protected:
|
2013-10-02 18:27:53 -07:00
|
|
|
Notification(const nsAString& aID, const nsAString& aTitle, const nsAString& aBody,
|
|
|
|
NotificationDirection aDir, const nsAString& aLang,
|
2014-01-06 18:53:23 -08:00
|
|
|
const nsAString& aTag, const nsAString& aIconUrl,
|
2014-09-16 14:12:00 -07:00
|
|
|
const NotificationBehavior& aBehavior, nsPIDOMWindow* aWindow);
|
2013-10-02 18:27:53 -07:00
|
|
|
|
|
|
|
static already_AddRefed<Notification> CreateInternal(nsPIDOMWindow* aWindow,
|
|
|
|
const nsAString& aID,
|
|
|
|
const nsAString& aTitle,
|
|
|
|
const NotificationOptions& aOptions);
|
|
|
|
|
|
|
|
void ShowInternal();
|
|
|
|
void CloseInternal();
|
2013-03-18 06:24:54 -07:00
|
|
|
|
|
|
|
static NotificationPermission GetPermissionInternal(nsISupports* aGlobal,
|
|
|
|
ErrorResult& rv);
|
|
|
|
|
|
|
|
static const nsString DirectionToString(NotificationDirection aDirection)
|
|
|
|
{
|
|
|
|
switch (aDirection) {
|
2013-05-06 12:28:13 -07:00
|
|
|
case NotificationDirection::Ltr:
|
2013-03-18 06:24:54 -07:00
|
|
|
return NS_LITERAL_STRING("ltr");
|
2013-05-06 12:28:13 -07:00
|
|
|
case NotificationDirection::Rtl:
|
2013-03-18 06:24:54 -07:00
|
|
|
return NS_LITERAL_STRING("rtl");
|
|
|
|
default:
|
|
|
|
return NS_LITERAL_STRING("auto");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-02 18:27:53 -07:00
|
|
|
static const NotificationDirection StringToDirection(const nsAString& aDirection)
|
|
|
|
{
|
|
|
|
if (aDirection.EqualsLiteral("ltr")) {
|
|
|
|
return NotificationDirection::Ltr;
|
|
|
|
}
|
|
|
|
if (aDirection.EqualsLiteral("rtl")) {
|
|
|
|
return NotificationDirection::Rtl;
|
|
|
|
}
|
|
|
|
return NotificationDirection::Auto;
|
|
|
|
}
|
|
|
|
|
|
|
|
static nsresult GetOrigin(nsPIDOMWindow* aWindow, nsString& aOrigin);
|
|
|
|
|
2014-05-08 14:16:00 -07:00
|
|
|
void GetAlertName(nsAString& aRetval)
|
|
|
|
{
|
|
|
|
aRetval = mAlertName;
|
|
|
|
}
|
2013-03-18 06:24:54 -07:00
|
|
|
|
2013-10-02 18:27:53 -07:00
|
|
|
nsString mID;
|
2013-03-18 06:24:54 -07:00
|
|
|
nsString mTitle;
|
|
|
|
nsString mBody;
|
|
|
|
NotificationDirection mDir;
|
|
|
|
nsString mLang;
|
|
|
|
nsString mTag;
|
|
|
|
nsString mIconUrl;
|
2014-08-20 17:56:12 -07:00
|
|
|
nsCOMPtr<nsIStructuredCloneContainer> mDataObjectContainer;
|
2014-09-16 14:12:00 -07:00
|
|
|
NotificationBehavior mBehavior;
|
2014-08-20 17:56:12 -07:00
|
|
|
|
|
|
|
// It's null until GetData is first called
|
|
|
|
nsCOMPtr<nsIVariant> mData;
|
2013-03-18 06:24:54 -07:00
|
|
|
|
2014-05-08 14:16:00 -07:00
|
|
|
nsString mAlertName;
|
|
|
|
|
2013-03-18 06:24:54 -07:00
|
|
|
bool mIsClosed;
|
|
|
|
|
2014-09-12 07:50:00 -07:00
|
|
|
// We need to make a distinction between the notification being closed i.e.
|
|
|
|
// removed from any pending or active lists, and the notification being
|
|
|
|
// removed from the database. NotificationDB might fail when trying to remove
|
|
|
|
// the notification.
|
|
|
|
bool mIsStored;
|
|
|
|
|
2013-03-18 06:24:54 -07:00
|
|
|
static uint32_t sCount;
|
2013-11-11 15:56:21 -08:00
|
|
|
|
|
|
|
private:
|
2014-08-20 17:56:12 -07:00
|
|
|
virtual ~Notification();
|
|
|
|
|
2013-11-11 15:56:21 -08:00
|
|
|
nsIPrincipal* GetPrincipal();
|
2013-03-18 06:24:54 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // mozilla_dom_notification_h__
|
|
|
|
|