Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 #ifndef mozilla_dom_notification_h__
6 #define mozilla_dom_notification_h__
8 #include "mozilla/DOMEventTargetHelper.h"
9 #include "mozilla/dom/NotificationBinding.h"
11 #include "nsIObserver.h"
13 #include "nsCycleCollectionParticipant.h"
15 class nsIPrincipal;
17 namespace mozilla {
18 namespace dom {
21 class NotificationObserver;
22 class Promise;
24 class Notification : public DOMEventTargetHelper
25 {
26 friend class NotificationTask;
27 friend class NotificationPermissionRequest;
28 friend class NotificationObserver;
29 friend class NotificationStorageCallback;
31 public:
32 IMPL_EVENT_HANDLER(click)
33 IMPL_EVENT_HANDLER(show)
34 IMPL_EVENT_HANDLER(error)
35 IMPL_EVENT_HANDLER(close)
37 static already_AddRefed<Notification> Constructor(const GlobalObject& aGlobal,
38 const nsAString& aTitle,
39 const NotificationOptions& aOption,
40 ErrorResult& aRv);
41 void GetID(nsAString& aRetval) {
42 aRetval = mID;
43 }
45 void GetTitle(nsAString& aRetval)
46 {
47 aRetval = mTitle;
48 }
50 NotificationDirection Dir()
51 {
52 return mDir;
53 }
55 void GetLang(nsAString& aRetval)
56 {
57 aRetval = mLang;
58 }
60 void GetBody(nsAString& aRetval)
61 {
62 aRetval = mBody;
63 }
65 void GetTag(nsAString& aRetval)
66 {
67 aRetval = mTag;
68 }
70 void GetIcon(nsAString& aRetval)
71 {
72 aRetval = mIconUrl;
73 }
75 static void RequestPermission(const GlobalObject& aGlobal,
76 const Optional<OwningNonNull<NotificationPermissionCallback> >& aCallback,
77 ErrorResult& aRv);
79 static NotificationPermission GetPermission(const GlobalObject& aGlobal,
80 ErrorResult& aRv);
82 static already_AddRefed<Promise> Get(const GlobalObject& aGlobal,
83 const GetNotificationOptions& aFilter,
84 ErrorResult& aRv);
86 void Close();
88 nsPIDOMWindow* GetParentObject()
89 {
90 return GetOwner();
91 }
93 virtual JSObject* WrapObject(JSContext* aCx) MOZ_OVERRIDE;
94 protected:
95 Notification(const nsAString& aID, const nsAString& aTitle, const nsAString& aBody,
96 NotificationDirection aDir, const nsAString& aLang,
97 const nsAString& aTag, const nsAString& aIconUrl,
98 nsPIDOMWindow* aWindow);
100 static already_AddRefed<Notification> CreateInternal(nsPIDOMWindow* aWindow,
101 const nsAString& aID,
102 const nsAString& aTitle,
103 const NotificationOptions& aOptions);
105 void ShowInternal();
106 void CloseInternal();
108 static NotificationPermission GetPermissionInternal(nsISupports* aGlobal,
109 ErrorResult& rv);
111 static const nsString DirectionToString(NotificationDirection aDirection)
112 {
113 switch (aDirection) {
114 case NotificationDirection::Ltr:
115 return NS_LITERAL_STRING("ltr");
116 case NotificationDirection::Rtl:
117 return NS_LITERAL_STRING("rtl");
118 default:
119 return NS_LITERAL_STRING("auto");
120 }
121 }
123 static const NotificationDirection StringToDirection(const nsAString& aDirection)
124 {
125 if (aDirection.EqualsLiteral("ltr")) {
126 return NotificationDirection::Ltr;
127 }
128 if (aDirection.EqualsLiteral("rtl")) {
129 return NotificationDirection::Rtl;
130 }
131 return NotificationDirection::Auto;
132 }
134 static nsresult GetOrigin(nsPIDOMWindow* aWindow, nsString& aOrigin);
136 nsresult GetAlertName(nsString& aAlertName);
138 nsString mID;
139 nsString mTitle;
140 nsString mBody;
141 NotificationDirection mDir;
142 nsString mLang;
143 nsString mTag;
144 nsString mIconUrl;
146 bool mIsClosed;
148 static uint32_t sCount;
150 private:
151 nsIPrincipal* GetPrincipal();
152 };
154 } // namespace dom
155 } // namespace mozilla
157 #endif // mozilla_dom_notification_h__