2016-01-14 08:19:51 +03: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_PushNotifier_h
|
|
|
|
#define mozilla_dom_PushNotifier_h
|
|
|
|
|
|
|
|
#include "nsIPushNotifier.h"
|
|
|
|
|
|
|
|
#include "nsCycleCollectionParticipant.h"
|
|
|
|
#include "nsIPrincipal.h"
|
|
|
|
#include "nsString.h"
|
2016-03-04 01:37:10 +03:00
|
|
|
|
2016-01-14 08:19:51 +03:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* `PushNotifier` implements the `nsIPushNotifier` interface. This service
|
2016-04-23 06:27:44 +03:00
|
|
|
* broadcasts XPCOM observer notifications for incoming push messages, then
|
2016-04-26 20:20:08 +03:00
|
|
|
* forwards incoming push messages to service workers.
|
|
|
|
*
|
|
|
|
* All scriptable methods on this interface may be called from the parent or
|
|
|
|
* content process. Observer notifications are broadcasted to both processes.
|
2016-01-14 08:19:51 +03:00
|
|
|
*/
|
|
|
|
class PushNotifier final : public nsIPushNotifier
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
PushNotifier();
|
|
|
|
|
|
|
|
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
|
|
|
NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(PushNotifier, nsIPushNotifier)
|
|
|
|
NS_DECL_NSIPUSHNOTIFIER
|
|
|
|
|
2016-04-21 21:11:03 +03:00
|
|
|
private:
|
|
|
|
virtual ~PushNotifier();
|
|
|
|
|
2016-01-14 08:19:51 +03:00
|
|
|
nsresult NotifyPush(const nsACString& aScope, nsIPrincipal* aPrincipal,
|
2016-03-28 21:50:39 +03:00
|
|
|
const nsAString& aMessageId,
|
|
|
|
const Maybe<nsTArray<uint8_t>>& aData);
|
2016-03-07 08:46:10 +03:00
|
|
|
nsresult DoNotifyObservers(nsISupports *aSubject, const char *aTopic,
|
|
|
|
const nsACString& aScope);
|
2016-01-14 08:19:51 +03:00
|
|
|
bool ShouldNotifyWorkers(nsIPrincipal* aPrincipal);
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2016-05-02 19:38:47 +03:00
|
|
|
* `PushData` provides methods for retrieving push message data in different
|
|
|
|
* formats. This class is similar to the `PushMessageData` WebIDL interface.
|
2016-01-14 08:19:51 +03:00
|
|
|
*/
|
2016-05-02 19:38:47 +03:00
|
|
|
class PushData final : public nsIPushData
|
2016-01-14 08:19:51 +03:00
|
|
|
{
|
|
|
|
public:
|
2016-05-02 19:38:47 +03:00
|
|
|
explicit PushData(const nsTArray<uint8_t>& aData);
|
2016-01-14 08:19:51 +03:00
|
|
|
|
|
|
|
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
2016-05-02 19:38:47 +03:00
|
|
|
NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(PushData, nsIPushData)
|
|
|
|
NS_DECL_NSIPUSHDATA
|
2016-01-14 08:19:51 +03:00
|
|
|
|
2016-04-23 06:27:44 +03:00
|
|
|
private:
|
2016-05-02 19:38:47 +03:00
|
|
|
virtual ~PushData();
|
2016-01-14 08:19:51 +03:00
|
|
|
|
|
|
|
nsresult EnsureDecodedText();
|
|
|
|
|
|
|
|
nsTArray<uint8_t> mData;
|
|
|
|
nsString mDecodedText;
|
|
|
|
};
|
|
|
|
|
2016-05-02 19:38:47 +03:00
|
|
|
/**
|
|
|
|
* `PushMessage` exposes the subscription principal and data for a push
|
|
|
|
* message. Each `push-message` observer receives an instance of this class
|
|
|
|
* as the subject.
|
|
|
|
*/
|
|
|
|
class PushMessage final : public nsIPushMessage
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
PushMessage(nsIPrincipal* aPrincipal, nsIPushData* aData);
|
|
|
|
|
|
|
|
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
|
|
|
NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(PushMessage, nsIPushMessage)
|
|
|
|
NS_DECL_NSIPUSHMESSAGE
|
|
|
|
|
|
|
|
private:
|
|
|
|
virtual ~PushMessage();
|
|
|
|
|
|
|
|
nsCOMPtr<nsIPrincipal> mPrincipal;
|
|
|
|
nsCOMPtr<nsIPushData> mData;
|
|
|
|
};
|
|
|
|
|
2016-01-14 08:19:51 +03:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // mozilla_dom_PushNotifier_h
|