|
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/. */ |
|
4 |
|
5 #ifndef mozilla_dom_notification_h__ |
|
6 #define mozilla_dom_notification_h__ |
|
7 |
|
8 #include "mozilla/DOMEventTargetHelper.h" |
|
9 #include "mozilla/dom/NotificationBinding.h" |
|
10 |
|
11 #include "nsIObserver.h" |
|
12 |
|
13 #include "nsCycleCollectionParticipant.h" |
|
14 |
|
15 class nsIPrincipal; |
|
16 |
|
17 namespace mozilla { |
|
18 namespace dom { |
|
19 |
|
20 |
|
21 class NotificationObserver; |
|
22 class Promise; |
|
23 |
|
24 class Notification : public DOMEventTargetHelper |
|
25 { |
|
26 friend class NotificationTask; |
|
27 friend class NotificationPermissionRequest; |
|
28 friend class NotificationObserver; |
|
29 friend class NotificationStorageCallback; |
|
30 |
|
31 public: |
|
32 IMPL_EVENT_HANDLER(click) |
|
33 IMPL_EVENT_HANDLER(show) |
|
34 IMPL_EVENT_HANDLER(error) |
|
35 IMPL_EVENT_HANDLER(close) |
|
36 |
|
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 } |
|
44 |
|
45 void GetTitle(nsAString& aRetval) |
|
46 { |
|
47 aRetval = mTitle; |
|
48 } |
|
49 |
|
50 NotificationDirection Dir() |
|
51 { |
|
52 return mDir; |
|
53 } |
|
54 |
|
55 void GetLang(nsAString& aRetval) |
|
56 { |
|
57 aRetval = mLang; |
|
58 } |
|
59 |
|
60 void GetBody(nsAString& aRetval) |
|
61 { |
|
62 aRetval = mBody; |
|
63 } |
|
64 |
|
65 void GetTag(nsAString& aRetval) |
|
66 { |
|
67 aRetval = mTag; |
|
68 } |
|
69 |
|
70 void GetIcon(nsAString& aRetval) |
|
71 { |
|
72 aRetval = mIconUrl; |
|
73 } |
|
74 |
|
75 static void RequestPermission(const GlobalObject& aGlobal, |
|
76 const Optional<OwningNonNull<NotificationPermissionCallback> >& aCallback, |
|
77 ErrorResult& aRv); |
|
78 |
|
79 static NotificationPermission GetPermission(const GlobalObject& aGlobal, |
|
80 ErrorResult& aRv); |
|
81 |
|
82 static already_AddRefed<Promise> Get(const GlobalObject& aGlobal, |
|
83 const GetNotificationOptions& aFilter, |
|
84 ErrorResult& aRv); |
|
85 |
|
86 void Close(); |
|
87 |
|
88 nsPIDOMWindow* GetParentObject() |
|
89 { |
|
90 return GetOwner(); |
|
91 } |
|
92 |
|
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); |
|
99 |
|
100 static already_AddRefed<Notification> CreateInternal(nsPIDOMWindow* aWindow, |
|
101 const nsAString& aID, |
|
102 const nsAString& aTitle, |
|
103 const NotificationOptions& aOptions); |
|
104 |
|
105 void ShowInternal(); |
|
106 void CloseInternal(); |
|
107 |
|
108 static NotificationPermission GetPermissionInternal(nsISupports* aGlobal, |
|
109 ErrorResult& rv); |
|
110 |
|
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 } |
|
122 |
|
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 } |
|
133 |
|
134 static nsresult GetOrigin(nsPIDOMWindow* aWindow, nsString& aOrigin); |
|
135 |
|
136 nsresult GetAlertName(nsString& aAlertName); |
|
137 |
|
138 nsString mID; |
|
139 nsString mTitle; |
|
140 nsString mBody; |
|
141 NotificationDirection mDir; |
|
142 nsString mLang; |
|
143 nsString mTag; |
|
144 nsString mIconUrl; |
|
145 |
|
146 bool mIsClosed; |
|
147 |
|
148 static uint32_t sCount; |
|
149 |
|
150 private: |
|
151 nsIPrincipal* GetPrincipal(); |
|
152 }; |
|
153 |
|
154 } // namespace dom |
|
155 } // namespace mozilla |
|
156 |
|
157 #endif // mozilla_dom_notification_h__ |
|
158 |