dom/src/notification/Notification.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/src/notification/Notification.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,158 @@
     1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.7 +
     1.8 +#ifndef mozilla_dom_notification_h__
     1.9 +#define mozilla_dom_notification_h__
    1.10 +
    1.11 +#include "mozilla/DOMEventTargetHelper.h"
    1.12 +#include "mozilla/dom/NotificationBinding.h"
    1.13 +
    1.14 +#include "nsIObserver.h"
    1.15 +
    1.16 +#include "nsCycleCollectionParticipant.h"
    1.17 +
    1.18 +class nsIPrincipal;
    1.19 +
    1.20 +namespace mozilla {
    1.21 +namespace dom {
    1.22 +
    1.23 +
    1.24 +class NotificationObserver;
    1.25 +class Promise;
    1.26 +
    1.27 +class Notification : public DOMEventTargetHelper
    1.28 +{
    1.29 +  friend class NotificationTask;
    1.30 +  friend class NotificationPermissionRequest;
    1.31 +  friend class NotificationObserver;
    1.32 +  friend class NotificationStorageCallback;
    1.33 +
    1.34 +public:
    1.35 +  IMPL_EVENT_HANDLER(click)
    1.36 +  IMPL_EVENT_HANDLER(show)
    1.37 +  IMPL_EVENT_HANDLER(error)
    1.38 +  IMPL_EVENT_HANDLER(close)
    1.39 +
    1.40 +  static already_AddRefed<Notification> Constructor(const GlobalObject& aGlobal,
    1.41 +                                                    const nsAString& aTitle,
    1.42 +                                                    const NotificationOptions& aOption,
    1.43 +                                                    ErrorResult& aRv);
    1.44 +  void GetID(nsAString& aRetval) {
    1.45 +    aRetval = mID;
    1.46 +  }
    1.47 +
    1.48 +  void GetTitle(nsAString& aRetval)
    1.49 +  {
    1.50 +    aRetval = mTitle;
    1.51 +  }
    1.52 +
    1.53 +  NotificationDirection Dir()
    1.54 +  {
    1.55 +    return mDir;
    1.56 +  }
    1.57 +
    1.58 +  void GetLang(nsAString& aRetval)
    1.59 +  {
    1.60 +    aRetval = mLang;
    1.61 +  }
    1.62 +
    1.63 +  void GetBody(nsAString& aRetval)
    1.64 +  {
    1.65 +    aRetval = mBody;
    1.66 +  }
    1.67 +
    1.68 +  void GetTag(nsAString& aRetval)
    1.69 +  {
    1.70 +    aRetval = mTag;
    1.71 +  }
    1.72 +
    1.73 +  void GetIcon(nsAString& aRetval)
    1.74 +  {
    1.75 +    aRetval = mIconUrl;
    1.76 +  }
    1.77 +
    1.78 +  static void RequestPermission(const GlobalObject& aGlobal,
    1.79 +                                const Optional<OwningNonNull<NotificationPermissionCallback> >& aCallback,
    1.80 +                                ErrorResult& aRv);
    1.81 +
    1.82 +  static NotificationPermission GetPermission(const GlobalObject& aGlobal,
    1.83 +                                              ErrorResult& aRv);
    1.84 +
    1.85 +  static already_AddRefed<Promise> Get(const GlobalObject& aGlobal,
    1.86 +                                       const GetNotificationOptions& aFilter,
    1.87 +                                       ErrorResult& aRv);
    1.88 +
    1.89 +  void Close();
    1.90 +
    1.91 +  nsPIDOMWindow* GetParentObject()
    1.92 +  {
    1.93 +    return GetOwner();
    1.94 +  }
    1.95 +
    1.96 +  virtual JSObject* WrapObject(JSContext* aCx) MOZ_OVERRIDE;
    1.97 +protected:
    1.98 +  Notification(const nsAString& aID, const nsAString& aTitle, const nsAString& aBody,
    1.99 +               NotificationDirection aDir, const nsAString& aLang,
   1.100 +               const nsAString& aTag, const nsAString& aIconUrl,
   1.101 +	       nsPIDOMWindow* aWindow);
   1.102 +
   1.103 +  static already_AddRefed<Notification> CreateInternal(nsPIDOMWindow* aWindow,
   1.104 +                                                       const nsAString& aID,
   1.105 +                                                       const nsAString& aTitle,
   1.106 +                                                       const NotificationOptions& aOptions);
   1.107 +
   1.108 +  void ShowInternal();
   1.109 +  void CloseInternal();
   1.110 +
   1.111 +  static NotificationPermission GetPermissionInternal(nsISupports* aGlobal,
   1.112 +                                                      ErrorResult& rv);
   1.113 +
   1.114 +  static const nsString DirectionToString(NotificationDirection aDirection)
   1.115 +  {
   1.116 +    switch (aDirection) {
   1.117 +    case NotificationDirection::Ltr:
   1.118 +      return NS_LITERAL_STRING("ltr");
   1.119 +    case NotificationDirection::Rtl:
   1.120 +      return NS_LITERAL_STRING("rtl");
   1.121 +    default:
   1.122 +      return NS_LITERAL_STRING("auto");
   1.123 +    }
   1.124 +  }
   1.125 +
   1.126 +  static const NotificationDirection StringToDirection(const nsAString& aDirection)
   1.127 +  {
   1.128 +    if (aDirection.EqualsLiteral("ltr")) {
   1.129 +      return NotificationDirection::Ltr;
   1.130 +    }
   1.131 +    if (aDirection.EqualsLiteral("rtl")) {
   1.132 +      return NotificationDirection::Rtl;
   1.133 +    }
   1.134 +    return NotificationDirection::Auto;
   1.135 +  }
   1.136 +
   1.137 +  static nsresult GetOrigin(nsPIDOMWindow* aWindow, nsString& aOrigin);
   1.138 +
   1.139 +  nsresult GetAlertName(nsString& aAlertName);
   1.140 +
   1.141 +  nsString mID;
   1.142 +  nsString mTitle;
   1.143 +  nsString mBody;
   1.144 +  NotificationDirection mDir;
   1.145 +  nsString mLang;
   1.146 +  nsString mTag;
   1.147 +  nsString mIconUrl;
   1.148 +
   1.149 +  bool mIsClosed;
   1.150 +
   1.151 +  static uint32_t sCount;
   1.152 +
   1.153 +private:
   1.154 +  nsIPrincipal* GetPrincipal();
   1.155 +};
   1.156 +
   1.157 +} // namespace dom
   1.158 +} // namespace mozilla
   1.159 +
   1.160 +#endif // mozilla_dom_notification_h__
   1.161 +

mercurial