Bug 1266433 - Clean up `nsIPushNotifier` static casts. r=dragana
MozReview-Commit-ID: AsZZ4TJquuB
--- a/dom/interfaces/push/nsIPushNotifier.idl
+++ b/dom/interfaces/push/nsIPushNotifier.idl
@@ -1,32 +1,62 @@
/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* 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/. */
#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.
*/
[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);
/**
* Fires a `push-subscription-lost` observer notification. Chrome code can
* listen for this notification to see when the Push service removes or
* expires a subscription for the |scope|.
*
* This is useful for Dev Tools and debugging add-ons that need to be
@@ -36,16 +66,44 @@ interface nsIPushNotifier : nsISupports
* |reason| is an `nsIPushErrorReporter` unsubscribe reason. The reason is
* wrapped in an `nsISupportsPRUint16` and passed as the subject.
*/
void notifySubscriptionLost(in ACString scope, in nsIPrincipal principal,
[optional] in uint16_t reason);
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);
};
/**
* A push message sent to a system subscription, used as the subject of a
* `push-message` observer notification. System subscriptions are created by
* the system principal, and do not use worker events.
*
* This interface resembles the `PushMessageData` WebIDL interface.
--- a/dom/ipc/ContentChild.cpp
+++ b/dom/ipc/ContentChild.cpp
@@ -163,17 +163,17 @@
#endif
#include "NuwaChild.h"
#ifdef MOZ_GAMEPAD
#include "mozilla/dom/GamepadService.h"
#endif
#ifndef MOZ_SIMPLEPUSH
-#include "mozilla/dom/PushNotifier.h"
+#include "nsIPushNotifier.h"
#endif
#include "mozilla/dom/File.h"
#include "mozilla/dom/cellbroadcast/CellBroadcastIPCService.h"
#include "mozilla/dom/icc/IccChild.h"
#include "mozilla/dom/mobileconnection/MobileConnectionChild.h"
#include "mozilla/dom/mobilemessage/SmsChild.h"
#include "mozilla/dom/devicestorage/DeviceStorageRequestChild.h"
@@ -3262,23 +3262,21 @@ ContentChild::RecvEndDragSession(const b
}
bool
ContentChild::RecvPush(const nsCString& aScope,
const IPC::Principal& aPrincipal,
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));
rv = pushNotifier->NotifyPushWorkers(aScope, aPrincipal,
aMessageId, Nothing());
Unused << NS_WARN_IF(NS_FAILED(rv));
#endif
@@ -3287,67 +3285,61 @@ ContentChild::RecvPush(const nsCString&
bool
ContentChild::RecvPushWithData(const nsCString& aScope,
const IPC::Principal& aPrincipal,
const nsString& aMessageId,
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));
rv = pushNotifier->NotifyPushWorkers(aScope, aPrincipal,
aMessageId, Some(aData));
Unused << NS_WARN_IF(NS_FAILED(rv));
#endif
return true;
}
bool
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));
rv = pushNotifier->NotifySubscriptionChangeWorkers(aScope, aPrincipal);
Unused << NS_WARN_IF(NS_FAILED(rv));
#endif
return true;
}
bool
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;
}
} // namespace dom
} // namespace mozilla
--- a/dom/ipc/ContentParent.cpp
+++ b/dom/ipc/ContentParent.cpp
@@ -260,17 +260,17 @@ using namespace mozilla::system;
#include "nsIProfileSaveEvent.h"
#endif
#ifdef MOZ_GAMEPAD
#include "mozilla/dom/GamepadMonitoring.h"
#endif
#ifndef MOZ_SIMPLEPUSH
-#include "mozilla/dom/PushNotifier.h"
+#include "nsIPushNotifier.h"
#endif
#ifdef XP_WIN
#include "mozilla/widget/AudioSession.h"
#endif
#include "VRManagerParent.h" // for VRManagerParent
@@ -5837,80 +5837,72 @@ ContentParent::StartProfiler(nsIProfiler
#endif
}
bool
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));
#endif
return true;
}
bool
ContentParent::RecvNotifyPushObserversWithData(const nsCString& aScope,
const nsString& aMessageId,
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));
#endif
return true;
}
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));
#endif
return true;
}
bool
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));
#endif
return true;
}
} // namespace dom
--- a/dom/push/PushNotifier.h
+++ b/dom/push/PushNotifier.h
@@ -5,73 +5,41 @@
#ifndef mozilla_dom_PushNotifier_h
#define mozilla_dom_PushNotifier_h
#include "nsIPushNotifier.h"
#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();
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(PushNotifier, nsIPushNotifier)
NS_DECL_NSIPUSHNOTIFIER
private:
virtual ~PushNotifier();
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);
};
/**
* `PushMessage` implements the `nsIPushMessage` interface, similar to
* the `PushMessageData` WebIDL interface. Instances of this class are
@@ -83,20 +51,19 @@ class PushMessage final : public nsIPush
public:
explicit PushMessage(const nsTArray<uint8_t>& aData);
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(PushMessage,
nsIPushMessage)
NS_DECL_NSIPUSHMESSAGE
-protected:
+private:
virtual ~PushMessage();
-private:
nsresult EnsureDecodedText();
nsTArray<uint8_t> mData;
nsString mDecodedText;
};
} // namespace dom
} // namespace mozilla