Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 4 | |
michael@0 | 5 | #ifndef mozilla_dom_notification_h__ |
michael@0 | 6 | #define mozilla_dom_notification_h__ |
michael@0 | 7 | |
michael@0 | 8 | #include "mozilla/DOMEventTargetHelper.h" |
michael@0 | 9 | #include "mozilla/dom/NotificationBinding.h" |
michael@0 | 10 | |
michael@0 | 11 | #include "nsIObserver.h" |
michael@0 | 12 | |
michael@0 | 13 | #include "nsCycleCollectionParticipant.h" |
michael@0 | 14 | |
michael@0 | 15 | class nsIPrincipal; |
michael@0 | 16 | |
michael@0 | 17 | namespace mozilla { |
michael@0 | 18 | namespace dom { |
michael@0 | 19 | |
michael@0 | 20 | |
michael@0 | 21 | class NotificationObserver; |
michael@0 | 22 | class Promise; |
michael@0 | 23 | |
michael@0 | 24 | class Notification : public DOMEventTargetHelper |
michael@0 | 25 | { |
michael@0 | 26 | friend class NotificationTask; |
michael@0 | 27 | friend class NotificationPermissionRequest; |
michael@0 | 28 | friend class NotificationObserver; |
michael@0 | 29 | friend class NotificationStorageCallback; |
michael@0 | 30 | |
michael@0 | 31 | public: |
michael@0 | 32 | IMPL_EVENT_HANDLER(click) |
michael@0 | 33 | IMPL_EVENT_HANDLER(show) |
michael@0 | 34 | IMPL_EVENT_HANDLER(error) |
michael@0 | 35 | IMPL_EVENT_HANDLER(close) |
michael@0 | 36 | |
michael@0 | 37 | static already_AddRefed<Notification> Constructor(const GlobalObject& aGlobal, |
michael@0 | 38 | const nsAString& aTitle, |
michael@0 | 39 | const NotificationOptions& aOption, |
michael@0 | 40 | ErrorResult& aRv); |
michael@0 | 41 | void GetID(nsAString& aRetval) { |
michael@0 | 42 | aRetval = mID; |
michael@0 | 43 | } |
michael@0 | 44 | |
michael@0 | 45 | void GetTitle(nsAString& aRetval) |
michael@0 | 46 | { |
michael@0 | 47 | aRetval = mTitle; |
michael@0 | 48 | } |
michael@0 | 49 | |
michael@0 | 50 | NotificationDirection Dir() |
michael@0 | 51 | { |
michael@0 | 52 | return mDir; |
michael@0 | 53 | } |
michael@0 | 54 | |
michael@0 | 55 | void GetLang(nsAString& aRetval) |
michael@0 | 56 | { |
michael@0 | 57 | aRetval = mLang; |
michael@0 | 58 | } |
michael@0 | 59 | |
michael@0 | 60 | void GetBody(nsAString& aRetval) |
michael@0 | 61 | { |
michael@0 | 62 | aRetval = mBody; |
michael@0 | 63 | } |
michael@0 | 64 | |
michael@0 | 65 | void GetTag(nsAString& aRetval) |
michael@0 | 66 | { |
michael@0 | 67 | aRetval = mTag; |
michael@0 | 68 | } |
michael@0 | 69 | |
michael@0 | 70 | void GetIcon(nsAString& aRetval) |
michael@0 | 71 | { |
michael@0 | 72 | aRetval = mIconUrl; |
michael@0 | 73 | } |
michael@0 | 74 | |
michael@0 | 75 | static void RequestPermission(const GlobalObject& aGlobal, |
michael@0 | 76 | const Optional<OwningNonNull<NotificationPermissionCallback> >& aCallback, |
michael@0 | 77 | ErrorResult& aRv); |
michael@0 | 78 | |
michael@0 | 79 | static NotificationPermission GetPermission(const GlobalObject& aGlobal, |
michael@0 | 80 | ErrorResult& aRv); |
michael@0 | 81 | |
michael@0 | 82 | static already_AddRefed<Promise> Get(const GlobalObject& aGlobal, |
michael@0 | 83 | const GetNotificationOptions& aFilter, |
michael@0 | 84 | ErrorResult& aRv); |
michael@0 | 85 | |
michael@0 | 86 | void Close(); |
michael@0 | 87 | |
michael@0 | 88 | nsPIDOMWindow* GetParentObject() |
michael@0 | 89 | { |
michael@0 | 90 | return GetOwner(); |
michael@0 | 91 | } |
michael@0 | 92 | |
michael@0 | 93 | virtual JSObject* WrapObject(JSContext* aCx) MOZ_OVERRIDE; |
michael@0 | 94 | protected: |
michael@0 | 95 | Notification(const nsAString& aID, const nsAString& aTitle, const nsAString& aBody, |
michael@0 | 96 | NotificationDirection aDir, const nsAString& aLang, |
michael@0 | 97 | const nsAString& aTag, const nsAString& aIconUrl, |
michael@0 | 98 | nsPIDOMWindow* aWindow); |
michael@0 | 99 | |
michael@0 | 100 | static already_AddRefed<Notification> CreateInternal(nsPIDOMWindow* aWindow, |
michael@0 | 101 | const nsAString& aID, |
michael@0 | 102 | const nsAString& aTitle, |
michael@0 | 103 | const NotificationOptions& aOptions); |
michael@0 | 104 | |
michael@0 | 105 | void ShowInternal(); |
michael@0 | 106 | void CloseInternal(); |
michael@0 | 107 | |
michael@0 | 108 | static NotificationPermission GetPermissionInternal(nsISupports* aGlobal, |
michael@0 | 109 | ErrorResult& rv); |
michael@0 | 110 | |
michael@0 | 111 | static const nsString DirectionToString(NotificationDirection aDirection) |
michael@0 | 112 | { |
michael@0 | 113 | switch (aDirection) { |
michael@0 | 114 | case NotificationDirection::Ltr: |
michael@0 | 115 | return NS_LITERAL_STRING("ltr"); |
michael@0 | 116 | case NotificationDirection::Rtl: |
michael@0 | 117 | return NS_LITERAL_STRING("rtl"); |
michael@0 | 118 | default: |
michael@0 | 119 | return NS_LITERAL_STRING("auto"); |
michael@0 | 120 | } |
michael@0 | 121 | } |
michael@0 | 122 | |
michael@0 | 123 | static const NotificationDirection StringToDirection(const nsAString& aDirection) |
michael@0 | 124 | { |
michael@0 | 125 | if (aDirection.EqualsLiteral("ltr")) { |
michael@0 | 126 | return NotificationDirection::Ltr; |
michael@0 | 127 | } |
michael@0 | 128 | if (aDirection.EqualsLiteral("rtl")) { |
michael@0 | 129 | return NotificationDirection::Rtl; |
michael@0 | 130 | } |
michael@0 | 131 | return NotificationDirection::Auto; |
michael@0 | 132 | } |
michael@0 | 133 | |
michael@0 | 134 | static nsresult GetOrigin(nsPIDOMWindow* aWindow, nsString& aOrigin); |
michael@0 | 135 | |
michael@0 | 136 | nsresult GetAlertName(nsString& aAlertName); |
michael@0 | 137 | |
michael@0 | 138 | nsString mID; |
michael@0 | 139 | nsString mTitle; |
michael@0 | 140 | nsString mBody; |
michael@0 | 141 | NotificationDirection mDir; |
michael@0 | 142 | nsString mLang; |
michael@0 | 143 | nsString mTag; |
michael@0 | 144 | nsString mIconUrl; |
michael@0 | 145 | |
michael@0 | 146 | bool mIsClosed; |
michael@0 | 147 | |
michael@0 | 148 | static uint32_t sCount; |
michael@0 | 149 | |
michael@0 | 150 | private: |
michael@0 | 151 | nsIPrincipal* GetPrincipal(); |
michael@0 | 152 | }; |
michael@0 | 153 | |
michael@0 | 154 | } // namespace dom |
michael@0 | 155 | } // namespace mozilla |
michael@0 | 156 | |
michael@0 | 157 | #endif // mozilla_dom_notification_h__ |
michael@0 | 158 |