зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1266433 - Clean up `nsIPushNotifier` static casts. r=dragana
MozReview-Commit-ID: AsZZ4TJquuB --HG-- extra : rebase_source : c38f971c435748947c85c1f2bba9ea69d7fddaf1
This commit is contained in:
Родитель
87fd821095
Коммит
6de951432a
|
@ -5,8 +5,23 @@
|
|||
|
||||
#include "nsISupports.idl"
|
||||
|
||||
%{C++
|
||||
#include "nsTArray.h"
|
||||
#include "mozilla/Maybe.h"
|
||||
|
||||
#define PUSHNOTIFIER_CONTRACTID \
|
||||
"@mozilla.org/push/Notifier;1"
|
||||
|
||||
// These constants are duplicated in `PushComponents.js`.
|
||||
#define OBSERVER_TOPIC_PUSH "push-message"
|
||||
#define OBSERVER_TOPIC_SUBSCRIPTION_CHANGE "push-subscription-change"
|
||||
#define OBSERVER_TOPIC_SUBSCRIPTION_LOST "push-subscription-lost"
|
||||
%}
|
||||
|
||||
interface nsIPrincipal;
|
||||
|
||||
[ref] native MaybeData(const mozilla::Maybe<nsTArray<uint8_t>>);
|
||||
|
||||
/**
|
||||
* Fires service worker events for push messages sent to content subscriptions,
|
||||
* and XPCOM observer notifications for system subscriptions.
|
||||
|
@ -14,14 +29,29 @@ interface nsIPrincipal;
|
|||
[scriptable, builtinclass, uuid(b00dfdeb-14e5-425b-adc7-b531442e3216)]
|
||||
interface nsIPushNotifier : nsISupports
|
||||
{
|
||||
/**
|
||||
* Fires a `push-message` observer notification, and sends a `push` event to
|
||||
* the service worker registered for the |scope|. |messageId| is an opaque ID
|
||||
* used to report errors if the worker fails to handle the message.
|
||||
*/
|
||||
void notifyPush(in ACString scope, in nsIPrincipal principal,
|
||||
in DOMString messageId);
|
||||
|
||||
/**
|
||||
* Same as `notifyPush`, except the subject of the observer notification
|
||||
* receives an `nsIPushMessage` instance containing the |data|. Service
|
||||
* workers can access the |data| via the `PushMessageData` WebIDL interface.
|
||||
*/
|
||||
void notifyPushWithData(in ACString scope, in nsIPrincipal principal,
|
||||
in DOMString messageId,
|
||||
[optional] in uint32_t dataLen,
|
||||
[array, size_is(dataLen)] in uint8_t data);
|
||||
|
||||
/**
|
||||
* Fires a `push-subscription-change` observer notification, and sends a
|
||||
* `pushsubscriptionchange` event to the service worker registered for the
|
||||
* |scope|.
|
||||
*/
|
||||
void notifySubscriptionChange(in ACString scope, in nsIPrincipal principal);
|
||||
|
||||
/**
|
||||
|
@ -41,6 +71,34 @@ interface nsIPushNotifier : nsISupports
|
|||
|
||||
void notifyError(in ACString scope, in nsIPrincipal principal,
|
||||
in DOMString message, in uint32_t flags);
|
||||
|
||||
/**
|
||||
* Internal methods used to fire service worker events and XPCOM observer
|
||||
* notifications. These are not exposed to JavaScript.
|
||||
*/
|
||||
|
||||
[noscript, nostdcall]
|
||||
void notifyPushWorkers(in ACString scope,
|
||||
in nsIPrincipal principal,
|
||||
in DOMString messageId,
|
||||
in MaybeData data);
|
||||
|
||||
[noscript, nostdcall]
|
||||
void notifyPushObservers(in ACString scope, in MaybeData data);
|
||||
|
||||
[noscript, nostdcall]
|
||||
void notifySubscriptionChangeWorkers(in ACString scope,
|
||||
in nsIPrincipal principal);
|
||||
|
||||
[noscript, nostdcall]
|
||||
void notifySubscriptionChangeObservers(in ACString scope);
|
||||
|
||||
[noscript, nostdcall]
|
||||
void notifySubscriptionLostObservers(in ACString scope, in uint16_t reason);
|
||||
|
||||
[noscript, nostdcall, notxpcom]
|
||||
void notifyErrorWorkers(in ACString scope, in DOMString message,
|
||||
in uint32_t flags);
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -168,7 +168,7 @@
|
|||
#endif
|
||||
|
||||
#ifndef MOZ_SIMPLEPUSH
|
||||
#include "mozilla/dom/PushNotifier.h"
|
||||
#include "nsIPushNotifier.h"
|
||||
#endif
|
||||
|
||||
#include "mozilla/dom/File.h"
|
||||
|
@ -3267,13 +3267,11 @@ ContentChild::RecvPush(const nsCString& aScope,
|
|||
const nsString& aMessageId)
|
||||
{
|
||||
#ifndef MOZ_SIMPLEPUSH
|
||||
nsCOMPtr<nsIPushNotifier> pushNotifierIface =
|
||||
nsCOMPtr<nsIPushNotifier> pushNotifier =
|
||||
do_GetService("@mozilla.org/push/Notifier;1");
|
||||
if (NS_WARN_IF(!pushNotifierIface)) {
|
||||
if (NS_WARN_IF(!pushNotifier)) {
|
||||
return true;
|
||||
}
|
||||
PushNotifier* pushNotifier =
|
||||
static_cast<PushNotifier*>(pushNotifierIface.get());
|
||||
|
||||
nsresult rv = pushNotifier->NotifyPushObservers(aScope, Nothing());
|
||||
Unused << NS_WARN_IF(NS_FAILED(rv));
|
||||
|
@ -3292,13 +3290,11 @@ ContentChild::RecvPushWithData(const nsCString& aScope,
|
|||
InfallibleTArray<uint8_t>&& aData)
|
||||
{
|
||||
#ifndef MOZ_SIMPLEPUSH
|
||||
nsCOMPtr<nsIPushNotifier> pushNotifierIface =
|
||||
nsCOMPtr<nsIPushNotifier> pushNotifier =
|
||||
do_GetService("@mozilla.org/push/Notifier;1");
|
||||
if (NS_WARN_IF(!pushNotifierIface)) {
|
||||
if (NS_WARN_IF(!pushNotifier)) {
|
||||
return true;
|
||||
}
|
||||
PushNotifier* pushNotifier =
|
||||
static_cast<PushNotifier*>(pushNotifierIface.get());
|
||||
|
||||
nsresult rv = pushNotifier->NotifyPushObservers(aScope, Some(aData));
|
||||
Unused << NS_WARN_IF(NS_FAILED(rv));
|
||||
|
@ -3315,13 +3311,11 @@ ContentChild::RecvPushSubscriptionChange(const nsCString& aScope,
|
|||
const IPC::Principal& aPrincipal)
|
||||
{
|
||||
#ifndef MOZ_SIMPLEPUSH
|
||||
nsCOMPtr<nsIPushNotifier> pushNotifierIface =
|
||||
nsCOMPtr<nsIPushNotifier> pushNotifier =
|
||||
do_GetService("@mozilla.org/push/Notifier;1");
|
||||
if (NS_WARN_IF(!pushNotifierIface)) {
|
||||
if (NS_WARN_IF(!pushNotifier)) {
|
||||
return true;
|
||||
}
|
||||
PushNotifier* pushNotifier =
|
||||
static_cast<PushNotifier*>(pushNotifierIface.get());
|
||||
|
||||
nsresult rv = pushNotifier->NotifySubscriptionChangeObservers(aScope);
|
||||
Unused << NS_WARN_IF(NS_FAILED(rv));
|
||||
|
@ -3337,13 +3331,11 @@ ContentChild::RecvPushError(const nsCString& aScope, const nsString& aMessage,
|
|||
const uint32_t& aFlags)
|
||||
{
|
||||
#ifndef MOZ_SIMPLEPUSH
|
||||
nsCOMPtr<nsIPushNotifier> pushNotifierIface =
|
||||
nsCOMPtr<nsIPushNotifier> pushNotifier =
|
||||
do_GetService("@mozilla.org/push/Notifier;1");
|
||||
if (NS_WARN_IF(!pushNotifierIface)) {
|
||||
if (NS_WARN_IF(!pushNotifier)) {
|
||||
return true;
|
||||
}
|
||||
PushNotifier* pushNotifier =
|
||||
static_cast<PushNotifier*>(pushNotifierIface.get());
|
||||
pushNotifier->NotifyErrorWorkers(aScope, aMessage, aFlags);
|
||||
#endif
|
||||
return true;
|
||||
|
|
|
@ -265,7 +265,7 @@ using namespace mozilla::system;
|
|||
#endif
|
||||
|
||||
#ifndef MOZ_SIMPLEPUSH
|
||||
#include "mozilla/dom/PushNotifier.h"
|
||||
#include "nsIPushNotifier.h"
|
||||
#endif
|
||||
|
||||
#ifdef XP_WIN
|
||||
|
@ -5842,13 +5842,11 @@ ContentParent::RecvNotifyPushObservers(const nsCString& aScope,
|
|||
const nsString& aMessageId)
|
||||
{
|
||||
#ifndef MOZ_SIMPLEPUSH
|
||||
nsCOMPtr<nsIPushNotifier> pushNotifierIface =
|
||||
nsCOMPtr<nsIPushNotifier> pushNotifier =
|
||||
do_GetService("@mozilla.org/push/Notifier;1");
|
||||
if (NS_WARN_IF(!pushNotifierIface)) {
|
||||
if (NS_WARN_IF(!pushNotifier)) {
|
||||
return true;
|
||||
}
|
||||
PushNotifier* pushNotifier =
|
||||
static_cast<PushNotifier*>(pushNotifierIface.get());
|
||||
|
||||
nsresult rv = pushNotifier->NotifyPushObservers(aScope, Nothing());
|
||||
Unused << NS_WARN_IF(NS_FAILED(rv));
|
||||
|
@ -5862,13 +5860,11 @@ ContentParent::RecvNotifyPushObserversWithData(const nsCString& aScope,
|
|||
InfallibleTArray<uint8_t>&& aData)
|
||||
{
|
||||
#ifndef MOZ_SIMPLEPUSH
|
||||
nsCOMPtr<nsIPushNotifier> pushNotifierIface =
|
||||
nsCOMPtr<nsIPushNotifier> pushNotifier =
|
||||
do_GetService("@mozilla.org/push/Notifier;1");
|
||||
if (NS_WARN_IF(!pushNotifierIface)) {
|
||||
if (NS_WARN_IF(!pushNotifier)) {
|
||||
return true;
|
||||
}
|
||||
PushNotifier* pushNotifier =
|
||||
static_cast<PushNotifier*>(pushNotifierIface.get());
|
||||
|
||||
nsresult rv = pushNotifier->NotifyPushObservers(aScope, Some(aData));
|
||||
Unused << NS_WARN_IF(NS_FAILED(rv));
|
||||
|
@ -5880,13 +5876,11 @@ bool
|
|||
ContentParent::RecvNotifyPushSubscriptionChangeObservers(const nsCString& aScope)
|
||||
{
|
||||
#ifndef MOZ_SIMPLEPUSH
|
||||
nsCOMPtr<nsIPushNotifier> pushNotifierIface =
|
||||
nsCOMPtr<nsIPushNotifier> pushNotifier =
|
||||
do_GetService("@mozilla.org/push/Notifier;1");
|
||||
if (NS_WARN_IF(!pushNotifierIface)) {
|
||||
if (NS_WARN_IF(!pushNotifier)) {
|
||||
return true;
|
||||
}
|
||||
PushNotifier* pushNotifier =
|
||||
static_cast<PushNotifier*>(pushNotifierIface.get());
|
||||
|
||||
nsresult rv = pushNotifier->NotifySubscriptionChangeObservers(aScope);
|
||||
Unused << NS_WARN_IF(NS_FAILED(rv));
|
||||
|
@ -5899,13 +5893,11 @@ ContentParent::RecvNotifyPushSubscriptionLostObservers(const nsCString& aScope,
|
|||
const uint16_t& aReason)
|
||||
{
|
||||
#ifndef MOZ_SIMPLEPUSH
|
||||
nsCOMPtr<nsIPushNotifier> pushNotifierIface =
|
||||
nsCOMPtr<nsIPushNotifier> pushNotifier =
|
||||
do_GetService("@mozilla.org/push/Notifier;1");
|
||||
if (NS_WARN_IF(!pushNotifierIface)) {
|
||||
if (NS_WARN_IF(!pushNotifier)) {
|
||||
return true;
|
||||
}
|
||||
PushNotifier* pushNotifier =
|
||||
static_cast<PushNotifier*>(pushNotifierIface.get());
|
||||
|
||||
nsresult rv = pushNotifier->NotifySubscriptionLostObservers(aScope, aReason);
|
||||
Unused << NS_WARN_IF(NS_FAILED(rv));
|
||||
|
|
|
@ -10,37 +10,18 @@
|
|||
#include "nsCycleCollectionParticipant.h"
|
||||
#include "nsIPrincipal.h"
|
||||
#include "nsString.h"
|
||||
#include "nsTArray.h"
|
||||
|
||||
#include "mozilla/Maybe.h"
|
||||
|
||||
#define PUSHNOTIFIER_CONTRACTID \
|
||||
"@mozilla.org/push/Notifier;1"
|
||||
|
||||
// These constants are duplicated in `PushComponents.js`.
|
||||
#define OBSERVER_TOPIC_PUSH "push-message"
|
||||
#define OBSERVER_TOPIC_SUBSCRIPTION_CHANGE "push-subscription-change"
|
||||
#define OBSERVER_TOPIC_SUBSCRIPTION_LOST "push-subscription-lost"
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
|
||||
class ContentParent;
|
||||
class ContentChild;
|
||||
|
||||
/**
|
||||
* `PushNotifier` implements the `nsIPushNotifier` interface. This service
|
||||
* broadcasts XPCOM observer notifications for incoming push messages, then
|
||||
* forwards incoming push messages to service workers running in the content
|
||||
* process, and emits XPCOM observer notifications for system subscriptions.
|
||||
*
|
||||
* This service exists solely to support `PushService.jsm`. Other callers
|
||||
* should use `ServiceWorkerManager` directly.
|
||||
* process.
|
||||
*/
|
||||
class PushNotifier final : public nsIPushNotifier
|
||||
{
|
||||
friend class ContentParent;
|
||||
friend class ContentChild;
|
||||
|
||||
public:
|
||||
PushNotifier();
|
||||
|
||||
|
@ -54,19 +35,6 @@ private:
|
|||
nsresult NotifyPush(const nsACString& aScope, nsIPrincipal* aPrincipal,
|
||||
const nsAString& aMessageId,
|
||||
const Maybe<nsTArray<uint8_t>>& aData);
|
||||
nsresult NotifyPushWorkers(const nsACString& aScope,
|
||||
nsIPrincipal* aPrincipal,
|
||||
const nsAString& aMessageId,
|
||||
const Maybe<nsTArray<uint8_t>>& aData);
|
||||
nsresult NotifySubscriptionChangeWorkers(const nsACString& aScope,
|
||||
nsIPrincipal* aPrincipal);
|
||||
void NotifyErrorWorkers(const nsACString& aScope, const nsAString& aMessage,
|
||||
uint32_t aFlags);
|
||||
nsresult NotifyPushObservers(const nsACString& aScope,
|
||||
const Maybe<nsTArray<uint8_t>>& aData);
|
||||
nsresult NotifySubscriptionChangeObservers(const nsACString& aScope);
|
||||
nsresult NotifySubscriptionLostObservers(const nsACString& aScope,
|
||||
uint16_t aReason);
|
||||
nsresult DoNotifyObservers(nsISupports *aSubject, const char *aTopic,
|
||||
const nsACString& aScope);
|
||||
bool ShouldNotifyWorkers(nsIPrincipal* aPrincipal);
|
||||
|
@ -88,10 +56,9 @@ public:
|
|||
nsIPushMessage)
|
||||
NS_DECL_NSIPUSHMESSAGE
|
||||
|
||||
protected:
|
||||
private:
|
||||
virtual ~PushMessage();
|
||||
|
||||
private:
|
||||
nsresult EnsureDecodedText();
|
||||
|
||||
nsTArray<uint8_t> mData;
|
||||
|
|
Загрузка…
Ссылка в новой задаче