2016-01-30 20:05:36 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- *//* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2013-03-18 17:24:54 +04: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-04-01 10:13:50 +04:00
|
|
|
#include "mozilla/DOMEventTargetHelper.h"
|
2015-06-26 04:53:02 +03:00
|
|
|
#include "mozilla/UniquePtr.h"
|
2013-03-18 17:24:54 +04:00
|
|
|
#include "mozilla/dom/NotificationBinding.h"
|
2016-06-23 11:53:14 +03:00
|
|
|
#include "mozilla/dom/workers/bindings/WorkerHolder.h"
|
2013-03-18 17:24:54 +04:00
|
|
|
|
|
|
|
#include "nsIObserver.h"
|
2017-05-09 19:24:01 +03:00
|
|
|
#include "nsISupports.h"
|
2013-03-18 17:24:54 +04:00
|
|
|
|
2013-10-03 05:27:53 +04:00
|
|
|
#include "nsCycleCollectionParticipant.h"
|
2015-11-14 08:22:59 +03:00
|
|
|
#include "nsHashKeys.h"
|
|
|
|
#include "nsTHashtable.h"
|
2015-12-30 01:06:28 +03:00
|
|
|
#include "nsWeakReference.h"
|
2015-11-14 08:22:59 +03:00
|
|
|
|
|
|
|
#define NOTIFICATIONTELEMETRYSERVICE_CONTRACTID \
|
|
|
|
"@mozilla.org/notificationTelemetryService;1"
|
2013-10-03 05:27:53 +04:00
|
|
|
|
2013-11-12 03:56:21 +04:00
|
|
|
class nsIPrincipal;
|
2014-08-21 04:56:12 +04:00
|
|
|
class nsIVariant;
|
2013-11-12 03:56:21 +04:00
|
|
|
|
2013-03-18 17:24:54 +04:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
2015-06-26 04:53:02 +03:00
|
|
|
class NotificationRef;
|
|
|
|
class WorkerNotificationObserver;
|
2015-06-26 02:52:40 +03:00
|
|
|
class Promise;
|
2015-06-25 21:36:53 +03:00
|
|
|
|
2015-06-26 04:53:02 +03:00
|
|
|
namespace workers {
|
|
|
|
class WorkerPrivate;
|
|
|
|
} // namespace workers
|
|
|
|
|
|
|
|
class Notification;
|
2016-06-23 11:53:14 +03:00
|
|
|
class NotificationWorkerHolder final : public workers::WorkerHolder
|
2015-06-26 04:53:02 +03:00
|
|
|
{
|
2015-06-26 04:53:02 +03:00
|
|
|
// Since the feature is strongly held by a Notification, it is ok to hold
|
|
|
|
// a raw pointer here.
|
2015-06-26 04:53:02 +03:00
|
|
|
Notification* mNotification;
|
|
|
|
|
|
|
|
public:
|
2016-06-23 11:53:14 +03:00
|
|
|
explicit NotificationWorkerHolder(Notification* aNotification);
|
2015-06-26 04:53:02 +03:00
|
|
|
|
|
|
|
bool
|
2016-03-28 20:28:14 +03:00
|
|
|
Notify(workers::Status aStatus) override;
|
2015-06-26 04:53:02 +03:00
|
|
|
};
|
|
|
|
|
2015-11-14 08:22:59 +03:00
|
|
|
// Records telemetry probes at application startup, when a notification is
|
|
|
|
// shown, and when the notification permission is revoked for a site.
|
2017-05-09 19:24:01 +03:00
|
|
|
class NotificationTelemetryService final : public nsISupports
|
2015-11-14 08:22:59 +03:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
|
|
|
|
NotificationTelemetryService();
|
|
|
|
|
|
|
|
static already_AddRefed<NotificationTelemetryService> GetInstance();
|
|
|
|
|
|
|
|
nsresult Init();
|
|
|
|
void RecordDNDSupported();
|
|
|
|
void RecordPermissions();
|
|
|
|
|
|
|
|
private:
|
|
|
|
virtual ~NotificationTelemetryService();
|
|
|
|
|
|
|
|
bool GetNotificationPermission(nsISupports* aSupports,
|
|
|
|
uint32_t* aCapability);
|
|
|
|
|
|
|
|
bool mDNDRecorded;
|
|
|
|
};
|
2015-06-26 04:53:02 +03:00
|
|
|
|
|
|
|
/*
|
2015-06-26 04:53:02 +03:00
|
|
|
* Notifications on workers introduce some lifetime issues. The property we
|
2015-06-26 04:53:02 +03:00
|
|
|
* are trying to satisfy is:
|
|
|
|
* Whenever a task is dispatched to the main thread to operate on
|
|
|
|
* a Notification, the Notification should be addrefed on the worker thread
|
|
|
|
* and a feature should be added to observe the worker lifetime. This main
|
|
|
|
* thread owner should ensure it properly releases the reference to the
|
|
|
|
* Notification, additionally removing the feature if necessary.
|
|
|
|
*
|
|
|
|
* To enforce the correct addref and release, along with managing the feature,
|
|
|
|
* we introduce a NotificationRef. Only one object may ever own
|
|
|
|
* a NotificationRef, so UniquePtr<> is used throughout. The NotificationRef
|
|
|
|
* constructor calls AddRefObject(). When it is destroyed (on any thread) it
|
|
|
|
* releases the Notification on the correct thread.
|
|
|
|
*
|
|
|
|
* Code should only access the underlying Notification object when it can
|
|
|
|
* guarantee that it retains ownership of the NotificationRef while doing so.
|
|
|
|
*
|
|
|
|
* The one kink in this mechanism is that the worker feature may be Notify()ed
|
|
|
|
* if the worker stops running script, even if the Notification's corresponding
|
|
|
|
* UI is still visible to the user. We handle this case with the following
|
|
|
|
* steps:
|
|
|
|
* a) Close the notification. This is done by blocking the worker on the main
|
2015-06-26 04:53:02 +03:00
|
|
|
* thread. This ensures that there are no main thread holders when the worker
|
|
|
|
* resumes. This also deals with the case where Notify() runs on the worker
|
|
|
|
* before the observer has been created on the main thread. Even in such
|
|
|
|
* a situation, the CloseNotificationRunnable() will only run after the
|
|
|
|
* Show task that was previously queued. Since the show task is only queued
|
|
|
|
* once when the Notification is created, we can be sure that no new tasks
|
|
|
|
* will follow the Notify().
|
|
|
|
*
|
2015-06-26 04:53:02 +03:00
|
|
|
* b) Ask the observer to let go of its NotificationRef's underlying
|
|
|
|
* Notification without proper cleanup since the feature will handle the
|
|
|
|
* release. This is only OK because every notification has only one
|
|
|
|
* associated observer. The NotificationRef itself is still owned by the
|
|
|
|
* observer and deleted by the UniquePtr, but it doesn't do anything since
|
|
|
|
* the underlying Notification is null.
|
|
|
|
*
|
|
|
|
* To unify code-paths, we use the same NotificationRef in the main
|
|
|
|
* thread implementation too.
|
|
|
|
*
|
|
|
|
* Note that the Notification's JS wrapper does it's standard
|
|
|
|
* AddRef()/Release() and is not affected by any of this.
|
|
|
|
*
|
2015-08-25 01:40:57 +03:00
|
|
|
* Since the worker event queue can have runnables that will dispatch events on
|
|
|
|
* the Notification, the NotificationRef destructor will first try to release
|
|
|
|
* the Notification by dispatching a normal runnable to the worker so that it is
|
|
|
|
* queued after any event runnables. If that dispatch fails, it means the worker
|
|
|
|
* is no longer running and queued WorkerRunnables will be canceled, so we
|
|
|
|
* dispatch a control runnable instead.
|
2015-06-26 04:53:02 +03:00
|
|
|
*
|
|
|
|
*/
|
2014-04-01 10:13:50 +04:00
|
|
|
class Notification : public DOMEventTargetHelper
|
2015-12-30 01:06:28 +03:00
|
|
|
, public nsIObserver
|
|
|
|
, public nsSupportsWeakReference
|
2013-03-18 17:24:54 +04:00
|
|
|
{
|
2015-06-26 04:53:02 +03:00
|
|
|
friend class CloseNotificationRunnable;
|
2013-03-18 17:24:54 +04:00
|
|
|
friend class NotificationTask;
|
|
|
|
friend class NotificationPermissionRequest;
|
2015-09-25 23:18:28 +03:00
|
|
|
friend class MainThreadNotificationObserver;
|
2013-10-03 05:27:53 +04:00
|
|
|
friend class NotificationStorageCallback;
|
2015-06-26 04:50:25 +03:00
|
|
|
friend class ServiceWorkerNotificationObserver;
|
2015-06-26 04:50:25 +03:00
|
|
|
friend class WorkerGetRunnable;
|
2015-06-26 04:53:02 +03:00
|
|
|
friend class WorkerNotificationObserver;
|
2015-11-14 08:22:59 +03:00
|
|
|
friend class NotificationTelemetryService;
|
2013-10-03 05:27:53 +04:00
|
|
|
|
2013-03-18 17:24:54 +04:00
|
|
|
public:
|
|
|
|
IMPL_EVENT_HANDLER(click)
|
|
|
|
IMPL_EVENT_HANDLER(show)
|
|
|
|
IMPL_EVENT_HANDLER(error)
|
|
|
|
IMPL_EVENT_HANDLER(close)
|
|
|
|
|
2014-08-21 04:56:12 +04:00
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
2015-07-30 22:44:14 +03:00
|
|
|
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_INHERITED(Notification, DOMEventTargetHelper)
|
2015-12-30 01:06:28 +03:00
|
|
|
NS_DECL_NSIOBSERVER
|
2014-08-21 04:56:12 +04:00
|
|
|
|
2016-10-13 02:43:27 +03:00
|
|
|
static bool RequireInteractionEnabled(JSContext* aCx, JSObject* aObj);
|
2015-06-26 04:53:02 +03:00
|
|
|
static bool PrefEnabled(JSContext* aCx, JSObject* aObj);
|
|
|
|
// Returns if Notification.get() is allowed for the current global.
|
|
|
|
static bool IsGetEnabled(JSContext* aCx, JSObject* aObj);
|
|
|
|
|
2013-03-18 17:24:54 +04:00
|
|
|
static already_AddRefed<Notification> Constructor(const GlobalObject& aGlobal,
|
|
|
|
const nsAString& aTitle,
|
|
|
|
const NotificationOptions& aOption,
|
|
|
|
ErrorResult& aRv);
|
2015-06-26 04:50:25 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Used when dispatching the ServiceWorkerEvent.
|
|
|
|
*
|
|
|
|
* Does not initialize the Notification's behavior.
|
|
|
|
* This is because:
|
|
|
|
* 1) The Notification is not shown to the user and so the behavior
|
|
|
|
* parameters don't matter.
|
|
|
|
* 2) The default binding requires main thread for parsing the JSON from the
|
|
|
|
* string behavior.
|
|
|
|
*/
|
|
|
|
static already_AddRefed<Notification>
|
|
|
|
ConstructFromFields(
|
|
|
|
nsIGlobalObject* aGlobal,
|
|
|
|
const nsAString& aID,
|
|
|
|
const nsAString& aTitle,
|
|
|
|
const nsAString& aDir,
|
|
|
|
const nsAString& aLang,
|
|
|
|
const nsAString& aBody,
|
|
|
|
const nsAString& aTag,
|
|
|
|
const nsAString& aIcon,
|
|
|
|
const nsAString& aData,
|
2016-05-26 17:19:09 +03:00
|
|
|
const nsAString& aServiceWorkerRegistrationScope,
|
2015-06-26 04:50:25 +03:00
|
|
|
ErrorResult& aRv);
|
|
|
|
|
2013-10-03 05:27:53 +04:00
|
|
|
void GetID(nsAString& aRetval) {
|
|
|
|
aRetval = mID;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GetTitle(nsAString& aRetval)
|
2013-09-12 13:50:29 +04:00
|
|
|
{
|
|
|
|
aRetval = mTitle;
|
|
|
|
}
|
|
|
|
|
|
|
|
NotificationDirection Dir()
|
|
|
|
{
|
|
|
|
return mDir;
|
|
|
|
}
|
|
|
|
|
2013-10-03 05:27:53 +04:00
|
|
|
void GetLang(nsAString& aRetval)
|
2013-09-12 13:50:29 +04:00
|
|
|
{
|
|
|
|
aRetval = mLang;
|
|
|
|
}
|
|
|
|
|
2013-10-03 05:27:53 +04:00
|
|
|
void GetBody(nsAString& aRetval)
|
2013-09-12 13:50:29 +04:00
|
|
|
{
|
|
|
|
aRetval = mBody;
|
|
|
|
}
|
|
|
|
|
2013-10-03 05:27:53 +04:00
|
|
|
void GetTag(nsAString& aRetval)
|
2013-09-12 13:50:29 +04:00
|
|
|
{
|
2013-10-03 05:27:53 +04:00
|
|
|
aRetval = mTag;
|
2013-09-12 13:50:29 +04:00
|
|
|
}
|
|
|
|
|
2013-10-03 05:27:53 +04:00
|
|
|
void GetIcon(nsAString& aRetval)
|
2013-09-12 13:50:29 +04:00
|
|
|
{
|
|
|
|
aRetval = mIconUrl;
|
|
|
|
}
|
2013-03-18 17:24:54 +04:00
|
|
|
|
2014-09-12 18:50:00 +04:00
|
|
|
void SetStoredState(bool val)
|
|
|
|
{
|
|
|
|
mIsStored = val;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IsStored()
|
|
|
|
{
|
|
|
|
return mIsStored;
|
|
|
|
}
|
|
|
|
|
2015-06-26 04:53:02 +03:00
|
|
|
static bool RequestPermissionEnabledForScope(JSContext* aCx, JSObject* /* unused */);
|
|
|
|
|
2016-01-21 01:23:04 +03:00
|
|
|
static already_AddRefed<Promise>
|
|
|
|
RequestPermission(const GlobalObject& aGlobal,
|
|
|
|
const Optional<OwningNonNull<NotificationPermissionCallback> >& aCallback,
|
|
|
|
ErrorResult& aRv);
|
2013-03-18 17:24:54 +04:00
|
|
|
|
|
|
|
static NotificationPermission GetPermission(const GlobalObject& aGlobal,
|
|
|
|
ErrorResult& aRv);
|
|
|
|
|
2015-06-26 04:50:25 +03:00
|
|
|
static already_AddRefed<Promise>
|
2016-01-30 20:05:36 +03:00
|
|
|
Get(nsPIDOMWindowInner* aWindow,
|
2015-06-26 04:50:25 +03:00
|
|
|
const GetNotificationOptions& aFilter,
|
|
|
|
const nsAString& aScope,
|
|
|
|
ErrorResult& aRv);
|
|
|
|
|
2013-10-03 05:27:53 +04:00
|
|
|
static already_AddRefed<Promise> Get(const GlobalObject& aGlobal,
|
|
|
|
const GetNotificationOptions& aFilter,
|
|
|
|
ErrorResult& aRv);
|
|
|
|
|
2015-06-26 04:50:25 +03:00
|
|
|
static already_AddRefed<Promise> WorkerGet(workers::WorkerPrivate* aWorkerPrivate,
|
|
|
|
const GetNotificationOptions& aFilter,
|
|
|
|
const nsAString& aScope,
|
|
|
|
ErrorResult& aRv);
|
|
|
|
|
2015-06-26 04:50:24 +03:00
|
|
|
// Notification implementation of
|
|
|
|
// ServiceWorkerRegistration.showNotification.
|
2016-03-11 02:07:28 +03:00
|
|
|
//
|
|
|
|
//
|
|
|
|
// Note that aCx may not be in the compartment of aGlobal, but aOptions will
|
|
|
|
// have its JS things in the compartment of aCx.
|
2015-06-26 04:50:24 +03:00
|
|
|
static already_AddRefed<Promise>
|
2016-03-11 02:07:28 +03:00
|
|
|
ShowPersistentNotification(JSContext* aCx,
|
|
|
|
nsIGlobalObject* aGlobal,
|
2015-06-26 04:50:24 +03:00
|
|
|
const nsAString& aScope,
|
|
|
|
const nsAString& aTitle,
|
|
|
|
const NotificationOptions& aOptions,
|
|
|
|
ErrorResult& aRv);
|
|
|
|
|
2013-03-18 17:24:54 +04:00
|
|
|
void Close();
|
|
|
|
|
2016-01-30 20:05:36 +03:00
|
|
|
nsPIDOMWindowInner* GetParentObject()
|
2013-03-18 17:24:54 +04:00
|
|
|
{
|
|
|
|
return GetOwner();
|
|
|
|
}
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
|
2014-08-21 04:56:12 +04:00
|
|
|
|
2016-10-13 03:27:40 +03:00
|
|
|
bool RequireInteraction() const;
|
|
|
|
|
2014-08-21 04:56:12 +04:00
|
|
|
void GetData(JSContext* aCx, JS::MutableHandle<JS::Value> aRetval);
|
|
|
|
|
|
|
|
void InitFromJSVal(JSContext* aCx, JS::Handle<JS::Value> aData, ErrorResult& aRv);
|
|
|
|
|
2016-02-23 23:02:35 +03:00
|
|
|
void InitFromBase64(const nsAString& aData, ErrorResult& aRv);
|
2014-09-17 01:12:00 +04:00
|
|
|
|
2015-06-26 04:53:02 +03:00
|
|
|
void AssertIsOnTargetThread() const
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(IsTargetThread());
|
|
|
|
}
|
|
|
|
|
2015-06-26 04:53:02 +03:00
|
|
|
// Initialized on the worker thread, never unset, and always used in
|
|
|
|
// a read-only capacity. Used on any thread.
|
2015-06-26 04:53:02 +03:00
|
|
|
workers::WorkerPrivate* mWorkerPrivate;
|
2015-06-26 04:53:02 +03:00
|
|
|
|
2015-06-26 04:53:02 +03:00
|
|
|
// Main thread only.
|
|
|
|
WorkerNotificationObserver* mObserver;
|
|
|
|
|
|
|
|
// The NotificationTask calls ShowInternal()/CloseInternal() on the
|
|
|
|
// Notification. At this point the task has ownership of the Notification. It
|
|
|
|
// passes this on to the Notification itself via mTempRef so that
|
|
|
|
// ShowInternal()/CloseInternal() may pass it along appropriately (or release
|
|
|
|
// it).
|
2015-06-26 04:53:02 +03:00
|
|
|
//
|
|
|
|
// Main thread only.
|
2015-06-26 04:53:02 +03:00
|
|
|
UniquePtr<NotificationRef> mTempRef;
|
|
|
|
|
2015-06-26 04:53:02 +03:00
|
|
|
// Returns true if addref succeeded.
|
|
|
|
bool AddRefObject();
|
2015-06-26 04:53:02 +03:00
|
|
|
void ReleaseObject();
|
|
|
|
|
2015-06-26 04:50:24 +03:00
|
|
|
static NotificationPermission GetPermission(nsIGlobalObject* aGlobal,
|
|
|
|
ErrorResult& aRv);
|
|
|
|
|
2015-06-26 04:53:02 +03:00
|
|
|
static NotificationPermission GetPermissionInternal(nsIPrincipal* aPrincipal,
|
|
|
|
ErrorResult& rv);
|
|
|
|
|
2016-03-31 02:54:37 +03:00
|
|
|
static NotificationPermission TestPermission(nsIPrincipal* aPrincipal);
|
|
|
|
|
2015-06-26 04:53:02 +03:00
|
|
|
bool DispatchClickEvent();
|
2015-06-26 04:50:25 +03:00
|
|
|
bool DispatchNotificationClickEvent();
|
2015-10-23 00:10:14 +03:00
|
|
|
|
|
|
|
static nsresult RemovePermission(nsIPrincipal* aPrincipal);
|
2015-10-23 00:20:51 +03:00
|
|
|
static nsresult OpenSettings(nsIPrincipal* aPrincipal);
|
2017-03-29 22:01:45 +03:00
|
|
|
|
|
|
|
nsresult DispatchToMainThread(already_AddRefed<nsIRunnable>&& aRunnable);
|
2013-03-18 17:24:54 +04:00
|
|
|
protected:
|
2015-06-26 04:50:25 +03:00
|
|
|
Notification(nsIGlobalObject* aGlobal, const nsAString& aID,
|
|
|
|
const nsAString& aTitle, const nsAString& aBody,
|
2013-10-03 05:27:53 +04:00
|
|
|
NotificationDirection aDir, const nsAString& aLang,
|
2014-01-07 06:53:23 +04:00
|
|
|
const nsAString& aTag, const nsAString& aIconUrl,
|
2016-10-13 03:27:40 +03:00
|
|
|
bool aRequireNotification,
|
2015-06-26 04:50:24 +03:00
|
|
|
const NotificationBehavior& aBehavior);
|
2013-10-03 05:27:53 +04:00
|
|
|
|
2015-06-26 04:50:25 +03:00
|
|
|
static already_AddRefed<Notification> CreateInternal(nsIGlobalObject* aGlobal,
|
|
|
|
const nsAString& aID,
|
2013-10-03 05:27:53 +04:00
|
|
|
const nsAString& aTitle,
|
|
|
|
const NotificationOptions& aOptions);
|
|
|
|
|
2015-12-30 01:06:28 +03:00
|
|
|
nsresult Init();
|
2015-11-14 08:22:59 +03:00
|
|
|
bool IsInPrivateBrowsing();
|
2013-10-03 05:27:53 +04:00
|
|
|
void ShowInternal();
|
|
|
|
void CloseInternal();
|
2013-03-18 17:24:54 +04:00
|
|
|
|
|
|
|
static NotificationPermission GetPermissionInternal(nsISupports* aGlobal,
|
|
|
|
ErrorResult& rv);
|
|
|
|
|
|
|
|
static const nsString DirectionToString(NotificationDirection aDirection)
|
|
|
|
{
|
|
|
|
switch (aDirection) {
|
2013-05-06 23:28:13 +04:00
|
|
|
case NotificationDirection::Ltr:
|
2013-03-18 17:24:54 +04:00
|
|
|
return NS_LITERAL_STRING("ltr");
|
2013-05-06 23:28:13 +04:00
|
|
|
case NotificationDirection::Rtl:
|
2013-03-18 17:24:54 +04:00
|
|
|
return NS_LITERAL_STRING("rtl");
|
|
|
|
default:
|
|
|
|
return NS_LITERAL_STRING("auto");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-06 04:08:45 +03:00
|
|
|
static NotificationDirection StringToDirection(const nsAString& aDirection)
|
2013-10-03 05:27:53 +04:00
|
|
|
{
|
|
|
|
if (aDirection.EqualsLiteral("ltr")) {
|
|
|
|
return NotificationDirection::Ltr;
|
|
|
|
}
|
|
|
|
if (aDirection.EqualsLiteral("rtl")) {
|
|
|
|
return NotificationDirection::Rtl;
|
|
|
|
}
|
|
|
|
return NotificationDirection::Auto;
|
|
|
|
}
|
|
|
|
|
2015-06-26 04:50:24 +03:00
|
|
|
static nsresult GetOrigin(nsIPrincipal* aPrincipal, nsString& aOrigin);
|
2013-10-03 05:27:53 +04:00
|
|
|
|
2014-05-09 01:16:00 +04:00
|
|
|
void GetAlertName(nsAString& aRetval)
|
|
|
|
{
|
2015-06-26 04:50:24 +03:00
|
|
|
workers::AssertIsOnMainThread();
|
|
|
|
if (mAlertName.IsEmpty()) {
|
|
|
|
SetAlertName();
|
|
|
|
}
|
2014-05-09 01:16:00 +04:00
|
|
|
aRetval = mAlertName;
|
|
|
|
}
|
2013-03-18 17:24:54 +04:00
|
|
|
|
2015-06-26 04:50:25 +03:00
|
|
|
void GetScope(nsAString& aScope)
|
|
|
|
{
|
|
|
|
aScope = mScope;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SetScope(const nsAString& aScope)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mScope.IsEmpty());
|
|
|
|
mScope = aScope;
|
|
|
|
}
|
|
|
|
|
2015-06-26 04:53:02 +03:00
|
|
|
const nsString mID;
|
|
|
|
const nsString mTitle;
|
|
|
|
const nsString mBody;
|
|
|
|
const NotificationDirection mDir;
|
|
|
|
const nsString mLang;
|
|
|
|
const nsString mTag;
|
|
|
|
const nsString mIconUrl;
|
2016-10-13 03:27:40 +03:00
|
|
|
const bool mRequireInteraction;
|
2015-07-30 22:44:14 +03:00
|
|
|
nsString mDataAsBase64;
|
2015-06-26 04:53:02 +03:00
|
|
|
const NotificationBehavior mBehavior;
|
2014-08-21 04:56:12 +04:00
|
|
|
|
|
|
|
// It's null until GetData is first called
|
2015-07-30 22:44:14 +03:00
|
|
|
JS::Heap<JS::Value> mData;
|
2013-03-18 17:24:54 +04:00
|
|
|
|
2014-05-09 01:16:00 +04:00
|
|
|
nsString mAlertName;
|
2015-06-26 04:50:25 +03:00
|
|
|
nsString mScope;
|
2014-05-09 01:16:00 +04:00
|
|
|
|
2015-06-26 04:53:02 +03:00
|
|
|
// Main thread only.
|
2013-03-18 17:24:54 +04:00
|
|
|
bool mIsClosed;
|
|
|
|
|
2014-09-12 18:50:00 +04: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 17:24:54 +04:00
|
|
|
static uint32_t sCount;
|
2013-11-12 03:56:21 +04:00
|
|
|
|
|
|
|
private:
|
2014-08-21 04:56:12 +04:00
|
|
|
virtual ~Notification();
|
|
|
|
|
2015-06-26 04:50:24 +03:00
|
|
|
// Creates a Notification and shows it. Returns a reference to the
|
|
|
|
// Notification if result is NS_OK. The lifetime of this Notification is tied
|
|
|
|
// to an underlying NotificationRef. Do not hold a non-stack raw pointer to
|
|
|
|
// it. Be careful about thread safety if acquiring a strong reference.
|
2016-03-11 02:07:28 +03:00
|
|
|
//
|
|
|
|
// Note that aCx may not be in the compartment of aGlobal, but aOptions will
|
|
|
|
// have its JS things in the compartment of aCx.
|
2015-06-26 04:50:24 +03:00
|
|
|
static already_AddRefed<Notification>
|
2016-03-11 02:07:28 +03:00
|
|
|
CreateAndShow(JSContext* aCx,
|
|
|
|
nsIGlobalObject* aGlobal,
|
2015-06-26 04:50:24 +03:00
|
|
|
const nsAString& aTitle,
|
|
|
|
const NotificationOptions& aOptions,
|
2015-06-26 04:50:25 +03:00
|
|
|
const nsAString& aScope,
|
2015-06-26 04:50:24 +03:00
|
|
|
ErrorResult& aRv);
|
|
|
|
|
2013-11-12 03:56:21 +04:00
|
|
|
nsIPrincipal* GetPrincipal();
|
2015-06-26 04:53:02 +03:00
|
|
|
|
|
|
|
nsresult PersistNotification();
|
|
|
|
void UnpersistNotification();
|
|
|
|
|
2015-06-26 04:50:24 +03:00
|
|
|
void
|
|
|
|
SetAlertName();
|
|
|
|
|
2015-06-26 04:53:02 +03:00
|
|
|
bool IsTargetThread() const
|
|
|
|
{
|
|
|
|
return NS_IsMainThread() == !mWorkerPrivate;
|
|
|
|
}
|
|
|
|
|
2016-06-23 11:53:14 +03:00
|
|
|
bool RegisterWorkerHolder();
|
|
|
|
void UnregisterWorkerHolder();
|
2015-06-26 04:53:02 +03:00
|
|
|
|
|
|
|
nsresult ResolveIconAndSoundURL(nsString&, nsString&);
|
|
|
|
|
2015-06-26 04:53:02 +03:00
|
|
|
// Only used for Notifications on Workers, worker thread only.
|
2016-06-23 11:53:14 +03:00
|
|
|
UniquePtr<NotificationWorkerHolder> mWorkerHolder;
|
2015-06-26 04:53:02 +03:00
|
|
|
// Target thread only.
|
2015-06-26 04:53:02 +03:00
|
|
|
uint32_t mTaskCount;
|
2013-03-18 17:24:54 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // mozilla_dom_notification_h__
|
|
|
|
|