2017-10-27 01:08:41 +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: */
|
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/. */
|
|
|
|
|
|
|
|
#include "PushNotifier.h"
|
|
|
|
|
|
|
|
#include "nsContentUtils.h"
|
|
|
|
#include "nsCOMPtr.h"
|
2016-03-28 23:33:20 +03:00
|
|
|
#include "nsICategoryManager.h"
|
2016-01-14 08:19:51 +03:00
|
|
|
#include "nsIXULRuntime.h"
|
2016-03-28 23:33:20 +03:00
|
|
|
#include "nsNetUtil.h"
|
|
|
|
#include "nsXPCOM.h"
|
2018-01-27 00:08:59 +03:00
|
|
|
#include "mozilla/dom/ServiceWorkerManager.h"
|
2019-12-05 07:44:32 +03:00
|
|
|
#include "mozilla/BasePrincipal.h"
|
2016-01-14 08:19:51 +03:00
|
|
|
#include "mozilla/Services.h"
|
2016-08-23 07:09:32 +03:00
|
|
|
#include "mozilla/Unused.h"
|
2016-01-14 08:19:51 +03:00
|
|
|
|
2016-02-28 00:54:11 +03:00
|
|
|
#include "mozilla/dom/BodyUtil.h"
|
2016-04-21 21:11:03 +03:00
|
|
|
#include "mozilla/dom/ContentChild.h"
|
2016-01-14 08:19:51 +03:00
|
|
|
#include "mozilla/dom/ContentParent.h"
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
|
|
|
PushNotifier::PushNotifier() {}
|
|
|
|
|
|
|
|
PushNotifier::~PushNotifier() {}
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_0(PushNotifier)
|
|
|
|
|
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(PushNotifier)
|
|
|
|
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIPushNotifier)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIPushNotifier)
|
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(PushNotifier)
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_RELEASE(PushNotifier)
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
PushNotifier::NotifyPushWithData(const nsACString& aScope,
|
|
|
|
nsIPrincipal* aPrincipal,
|
2019-05-10 10:15:08 +03:00
|
|
|
const nsAString& aMessageId,
|
|
|
|
const nsTArray<uint8_t>& aData) {
|
2016-06-27 18:22:59 +03:00
|
|
|
NS_ENSURE_ARG(aPrincipal);
|
2019-05-10 10:15:08 +03:00
|
|
|
// We still need to do this copying business, if we want the copy to be
|
|
|
|
// fallible. Just passing Some(aData) would do an infallible copy at the
|
|
|
|
// point where the Some() call happens.
|
2016-01-14 08:19:51 +03:00
|
|
|
nsTArray<uint8_t> data;
|
2019-05-10 10:15:08 +03:00
|
|
|
if (!data.AppendElements(aData, fallible)) {
|
2016-01-14 08:19:51 +03:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
2019-05-10 10:15:08 +03:00
|
|
|
PushMessageDispatcher dispatcher(aScope, aPrincipal, aMessageId,
|
|
|
|
Some(std::move(data)));
|
2016-05-20 05:01:34 +03:00
|
|
|
return Dispatch(dispatcher);
|
2016-01-14 08:19:51 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2016-03-28 21:50:39 +03:00
|
|
|
PushNotifier::NotifyPush(const nsACString& aScope, nsIPrincipal* aPrincipal,
|
|
|
|
const nsAString& aMessageId) {
|
2016-06-27 18:22:59 +03:00
|
|
|
NS_ENSURE_ARG(aPrincipal);
|
2016-05-20 05:01:34 +03:00
|
|
|
PushMessageDispatcher dispatcher(aScope, aPrincipal, aMessageId, Nothing());
|
|
|
|
return Dispatch(dispatcher);
|
2016-01-14 08:19:51 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
PushNotifier::NotifySubscriptionChange(const nsACString& aScope,
|
|
|
|
nsIPrincipal* aPrincipal) {
|
2016-06-27 18:22:59 +03:00
|
|
|
NS_ENSURE_ARG(aPrincipal);
|
2016-05-20 05:01:34 +03:00
|
|
|
PushSubscriptionChangeDispatcher dispatcher(aScope, aPrincipal);
|
|
|
|
return Dispatch(dispatcher);
|
2016-01-14 08:19:51 +03:00
|
|
|
}
|
|
|
|
|
2016-04-21 22:04:15 +03:00
|
|
|
NS_IMETHODIMP
|
2016-05-02 18:20:14 +03:00
|
|
|
PushNotifier::NotifySubscriptionModified(const nsACString& aScope,
|
|
|
|
nsIPrincipal* aPrincipal) {
|
2016-06-27 18:22:59 +03:00
|
|
|
NS_ENSURE_ARG(aPrincipal);
|
2016-05-20 05:01:34 +03:00
|
|
|
PushSubscriptionModifiedDispatcher dispatcher(aScope, aPrincipal);
|
|
|
|
return Dispatch(dispatcher);
|
2016-04-21 22:04:15 +03:00
|
|
|
}
|
|
|
|
|
2016-03-28 23:33:20 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
PushNotifier::NotifyError(const nsACString& aScope, nsIPrincipal* aPrincipal,
|
|
|
|
const nsAString& aMessage, uint32_t aFlags) {
|
2016-06-27 18:22:59 +03:00
|
|
|
NS_ENSURE_ARG(aPrincipal);
|
2016-05-20 05:01:34 +03:00
|
|
|
PushErrorDispatcher dispatcher(aScope, aPrincipal, aMessage, aFlags);
|
|
|
|
return Dispatch(dispatcher);
|
2016-01-14 08:19:51 +03:00
|
|
|
}
|
|
|
|
|
2016-05-20 05:01:34 +03:00
|
|
|
nsresult PushNotifier::Dispatch(PushDispatcher& aDispatcher) {
|
|
|
|
if (XRE_IsParentProcess()) {
|
|
|
|
// Always notify XPCOM observers in the parent process.
|
|
|
|
Unused << NS_WARN_IF(NS_FAILED(aDispatcher.NotifyObservers()));
|
|
|
|
|
|
|
|
nsTArray<ContentParent*> contentActors;
|
|
|
|
ContentParent::GetAll(contentActors);
|
2018-06-23 20:13:10 +03:00
|
|
|
if (!contentActors.IsEmpty() && !ServiceWorkerParentInterceptEnabled()) {
|
2016-05-20 05:01:34 +03:00
|
|
|
// At least one content process is active, so e10s must be enabled.
|
|
|
|
// Broadcast a message to notify observers and service workers.
|
|
|
|
for (uint32_t i = 0; i < contentActors.Length(); ++i) {
|
2017-07-25 06:28:41 +03:00
|
|
|
// We need to filter based on process type, only "web" AKA the default
|
2019-09-26 09:54:22 +03:00
|
|
|
// remote type is acceptable. This should not run when Fission is
|
|
|
|
// enabled, and we specifically don't want this for
|
|
|
|
// LARGE_ALLOCATION_REMOTE_TYPE, so don't use IsWebRemoteType().
|
2017-07-25 06:28:41 +03:00
|
|
|
if (!contentActors[i]->GetRemoteType().EqualsLiteral(
|
|
|
|
DEFAULT_REMOTE_TYPE)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2017-04-04 21:24:36 +03:00
|
|
|
// Ensure that the content actor has the permissions avaliable for the
|
|
|
|
// principal the push is being sent for before sending the push message
|
|
|
|
// down.
|
|
|
|
Unused << contentActors[i]->TransmitPermissionsForPrincipal(
|
|
|
|
aDispatcher.GetPrincipal());
|
2017-03-08 17:59:36 +03:00
|
|
|
if (aDispatcher.SendToChild(contentActors[i])) {
|
|
|
|
// Only send the push message to the first content process to avoid
|
|
|
|
// multiple SWs showing the same notification. See bug 1300112.
|
|
|
|
break;
|
|
|
|
}
|
2016-05-20 05:01:34 +03:00
|
|
|
}
|
2016-04-21 21:11:03 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2016-03-28 23:33:20 +03:00
|
|
|
|
2018-06-23 20:13:10 +03:00
|
|
|
if (BrowserTabsRemoteAutostart() &&
|
|
|
|
!ServiceWorkerParentInterceptEnabled()) {
|
2016-05-20 05:01:34 +03:00
|
|
|
// e10s is enabled, but no content processes are active.
|
|
|
|
return aDispatcher.HandleNoChildProcesses();
|
2016-03-28 23:33:20 +03:00
|
|
|
}
|
|
|
|
|
2016-05-20 05:01:34 +03:00
|
|
|
// e10s is disabled; notify workers in the parent.
|
|
|
|
return aDispatcher.NotifyWorkers();
|
2016-01-14 08:19:51 +03:00
|
|
|
}
|
|
|
|
|
2016-05-20 05:01:34 +03:00
|
|
|
// Otherwise, we're in the content process, so e10s must be enabled. Notify
|
|
|
|
// observers and workers, then send a message to notify observers in the
|
|
|
|
// parent.
|
|
|
|
MOZ_ASSERT(XRE_IsContentProcess());
|
2016-03-07 08:46:10 +03:00
|
|
|
|
2016-05-20 05:01:34 +03:00
|
|
|
nsresult rv = aDispatcher.NotifyObserversAndWorkers();
|
2016-04-21 22:04:15 +03:00
|
|
|
|
2016-05-20 05:01:34 +03:00
|
|
|
ContentChild* parentActor = ContentChild::GetSingleton();
|
|
|
|
if (!NS_WARN_IF(!parentActor)) {
|
|
|
|
Unused << NS_WARN_IF(!aDispatcher.SendToParent(parentActor));
|
2016-01-14 08:19:51 +03:00
|
|
|
}
|
|
|
|
|
2016-05-20 05:01:34 +03:00
|
|
|
return rv;
|
2016-01-14 08:19:51 +03:00
|
|
|
}
|
|
|
|
|
2016-05-02 19:38:47 +03:00
|
|
|
PushData::PushData(const nsTArray<uint8_t>& aData) : mData(aData) {}
|
2016-01-14 08:19:51 +03:00
|
|
|
|
2016-05-02 19:38:47 +03:00
|
|
|
PushData::~PushData() {}
|
2016-01-14 08:19:51 +03:00
|
|
|
|
2016-05-02 19:38:47 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_0(PushData)
|
2016-01-14 08:19:51 +03:00
|
|
|
|
2016-05-02 19:38:47 +03:00
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(PushData)
|
|
|
|
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIPushData)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIPushData)
|
2016-01-14 08:19:51 +03:00
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
2016-05-02 19:38:47 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(PushData)
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_RELEASE(PushData)
|
2016-01-14 08:19:51 +03:00
|
|
|
|
2016-05-02 19:38:47 +03:00
|
|
|
nsresult PushData::EnsureDecodedText() {
|
2016-01-14 08:19:51 +03:00
|
|
|
if (mData.IsEmpty() || !mDecodedText.IsEmpty()) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2016-02-28 00:54:11 +03:00
|
|
|
nsresult rv = BodyUtil::ConsumeText(
|
2016-01-14 08:19:51 +03:00
|
|
|
mData.Length(), reinterpret_cast<uint8_t*>(mData.Elements()),
|
|
|
|
mDecodedText);
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
mDecodedText.Truncate();
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2016-05-02 19:38:47 +03:00
|
|
|
PushData::Text(nsAString& aText) {
|
2016-01-14 08:19:51 +03:00
|
|
|
nsresult rv = EnsureDecodedText();
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
aText = mDecodedText;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2016-05-02 19:38:47 +03:00
|
|
|
PushData::Json(JSContext* aCx, JS::MutableHandle<JS::Value> aResult) {
|
2016-01-14 08:19:51 +03:00
|
|
|
nsresult rv = EnsureDecodedText();
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
ErrorResult error;
|
2016-02-28 00:54:11 +03:00
|
|
|
BodyUtil::ConsumeJson(aCx, aResult, mDecodedText, error);
|
2016-04-27 04:26:30 +03:00
|
|
|
return error.StealNSResult();
|
2016-01-14 08:19:51 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2019-05-10 10:15:08 +03:00
|
|
|
PushData::Binary(nsTArray<uint8_t>& aData) {
|
|
|
|
aData = mData;
|
2016-01-14 08:19:51 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2016-05-02 19:38:47 +03:00
|
|
|
PushMessage::PushMessage(nsIPrincipal* aPrincipal, nsIPushData* aData)
|
|
|
|
: mPrincipal(aPrincipal), mData(aData) {}
|
|
|
|
|
|
|
|
PushMessage::~PushMessage() {}
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION(PushMessage, mPrincipal, mData)
|
|
|
|
|
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(PushMessage)
|
|
|
|
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIPushMessage)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIPushMessage)
|
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(PushMessage)
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_RELEASE(PushMessage)
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
PushMessage::GetPrincipal(nsIPrincipal** aPrincipal) {
|
|
|
|
NS_ENSURE_ARG_POINTER(aPrincipal);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIPrincipal> principal = mPrincipal;
|
|
|
|
principal.forget(aPrincipal);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
PushMessage::GetData(nsIPushData** aData) {
|
|
|
|
NS_ENSURE_ARG_POINTER(aData);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIPushData> data = mData;
|
|
|
|
data.forget(aData);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2016-05-20 05:01:34 +03:00
|
|
|
PushDispatcher::PushDispatcher(const nsACString& aScope,
|
|
|
|
nsIPrincipal* aPrincipal)
|
|
|
|
: mScope(aScope), mPrincipal(aPrincipal) {}
|
|
|
|
|
|
|
|
PushDispatcher::~PushDispatcher() {}
|
|
|
|
|
|
|
|
nsresult PushDispatcher::HandleNoChildProcesses() { return NS_OK; }
|
|
|
|
|
|
|
|
nsresult PushDispatcher::NotifyObserversAndWorkers() {
|
|
|
|
Unused << NS_WARN_IF(NS_FAILED(NotifyObservers()));
|
|
|
|
return NotifyWorkers();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool PushDispatcher::ShouldNotifyWorkers() {
|
2016-06-27 18:22:59 +03:00
|
|
|
if (NS_WARN_IF(!mPrincipal)) {
|
|
|
|
return false;
|
|
|
|
}
|
2019-01-29 23:27:03 +03:00
|
|
|
|
2016-05-20 05:01:34 +03:00
|
|
|
// System subscriptions use observer notifications instead of service worker
|
|
|
|
// events. The `testing.notifyWorkers` pref disables worker events for
|
|
|
|
// non-system subscriptions.
|
2019-12-05 07:44:32 +03:00
|
|
|
if (mPrincipal->IsSystemPrincipal() ||
|
2019-01-29 23:27:03 +03:00
|
|
|
!Preferences::GetBool("dom.push.testing.notifyWorkers", true)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If e10s is off, no need to worry about processes.
|
|
|
|
if (!BrowserTabsRemoteAutostart()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If parent intercept is enabled, then we only want to notify in the parent
|
|
|
|
// process. Otherwise, we only want to notify in the child process.
|
|
|
|
bool isContentProcess = XRE_GetProcessType() == GeckoProcessType_Content;
|
|
|
|
bool parentInterceptEnabled = ServiceWorkerParentInterceptEnabled();
|
|
|
|
if (parentInterceptEnabled) {
|
|
|
|
return !isContentProcess;
|
|
|
|
}
|
|
|
|
|
|
|
|
return isContentProcess;
|
2016-05-20 05:01:34 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult PushDispatcher::DoNotifyObservers(nsISupports* aSubject,
|
|
|
|
const char* aTopic,
|
|
|
|
const nsACString& aScope) {
|
|
|
|
nsCOMPtr<nsIObserverService> obsService =
|
|
|
|
mozilla::services::GetObserverService();
|
|
|
|
if (!obsService) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
// If there's a service for this push category, make sure it is alive.
|
|
|
|
nsCOMPtr<nsICategoryManager> catMan =
|
|
|
|
do_GetService(NS_CATEGORYMANAGER_CONTRACTID);
|
|
|
|
if (catMan) {
|
2017-08-21 13:01:27 +03:00
|
|
|
nsCString contractId;
|
2018-07-24 03:41:06 +03:00
|
|
|
nsresult rv = catMan->GetCategoryEntry("push", mScope, contractId);
|
2016-05-20 05:01:34 +03:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
// Ensure the service is created - we don't need to do anything with
|
|
|
|
// it though - we assume the service constructor attaches a listener.
|
2017-08-21 13:01:27 +03:00
|
|
|
nsCOMPtr<nsISupports> service = do_GetService(contractId.get());
|
2016-05-20 05:01:34 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return obsService->NotifyObservers(aSubject, aTopic,
|
|
|
|
NS_ConvertUTF8toUTF16(mScope).get());
|
|
|
|
}
|
|
|
|
|
|
|
|
PushMessageDispatcher::PushMessageDispatcher(
|
|
|
|
const nsACString& aScope, nsIPrincipal* aPrincipal,
|
|
|
|
const nsAString& aMessageId, const Maybe<nsTArray<uint8_t>>& aData)
|
|
|
|
: PushDispatcher(aScope, aPrincipal),
|
|
|
|
mMessageId(aMessageId),
|
|
|
|
mData(aData) {}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2016-05-20 05:01:34 +03:00
|
|
|
PushMessageDispatcher::~PushMessageDispatcher() {}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2016-05-20 05:01:34 +03:00
|
|
|
nsresult PushMessageDispatcher::NotifyObservers() {
|
|
|
|
nsCOMPtr<nsIPushData> data;
|
|
|
|
if (mData) {
|
|
|
|
data = new PushData(mData.ref());
|
|
|
|
}
|
|
|
|
nsCOMPtr<nsIPushMessage> message = new PushMessage(mPrincipal, data);
|
|
|
|
return DoNotifyObservers(message, OBSERVER_TOPIC_PUSH, mScope);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult PushMessageDispatcher::NotifyWorkers() {
|
|
|
|
if (!ShouldNotifyWorkers()) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
RefPtr<ServiceWorkerManager> swm = ServiceWorkerManager::GetInstance();
|
|
|
|
if (!swm) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
nsAutoCString originSuffix;
|
|
|
|
nsresult rv = mPrincipal->GetOriginSuffix(originSuffix);
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
return swm->SendPushEvent(originSuffix, mScope, mMessageId, mData);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool PushMessageDispatcher::SendToParent(ContentChild* aParentActor) {
|
|
|
|
if (mData) {
|
|
|
|
return aParentActor->SendNotifyPushObserversWithData(
|
|
|
|
mScope, IPC::Principal(mPrincipal), mMessageId, mData.ref());
|
|
|
|
}
|
|
|
|
return aParentActor->SendNotifyPushObservers(
|
|
|
|
mScope, IPC::Principal(mPrincipal), mMessageId);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool PushMessageDispatcher::SendToChild(ContentParent* aContentActor) {
|
|
|
|
if (mData) {
|
|
|
|
return aContentActor->SendPushWithData(mScope, IPC::Principal(mPrincipal),
|
|
|
|
mMessageId, mData.ref());
|
|
|
|
}
|
|
|
|
return aContentActor->SendPush(mScope, IPC::Principal(mPrincipal),
|
|
|
|
mMessageId);
|
|
|
|
}
|
|
|
|
|
|
|
|
PushSubscriptionChangeDispatcher::PushSubscriptionChangeDispatcher(
|
|
|
|
const nsACString& aScope, nsIPrincipal* aPrincipal)
|
|
|
|
: PushDispatcher(aScope, aPrincipal) {}
|
|
|
|
|
|
|
|
PushSubscriptionChangeDispatcher::~PushSubscriptionChangeDispatcher() {}
|
|
|
|
|
|
|
|
nsresult PushSubscriptionChangeDispatcher::NotifyObservers() {
|
|
|
|
return DoNotifyObservers(mPrincipal, OBSERVER_TOPIC_SUBSCRIPTION_CHANGE,
|
|
|
|
mScope);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult PushSubscriptionChangeDispatcher::NotifyWorkers() {
|
|
|
|
if (!ShouldNotifyWorkers()) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
RefPtr<ServiceWorkerManager> swm = ServiceWorkerManager::GetInstance();
|
|
|
|
if (!swm) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
nsAutoCString originSuffix;
|
|
|
|
nsresult rv = mPrincipal->GetOriginSuffix(originSuffix);
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
return swm->SendPushSubscriptionChangeEvent(originSuffix, mScope);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool PushSubscriptionChangeDispatcher::SendToParent(
|
|
|
|
ContentChild* aParentActor) {
|
|
|
|
return aParentActor->SendNotifyPushSubscriptionChangeObservers(
|
|
|
|
mScope, IPC::Principal(mPrincipal));
|
|
|
|
}
|
|
|
|
|
|
|
|
bool PushSubscriptionChangeDispatcher::SendToChild(
|
|
|
|
ContentParent* aContentActor) {
|
|
|
|
return aContentActor->SendPushSubscriptionChange(mScope,
|
|
|
|
IPC::Principal(mPrincipal));
|
|
|
|
}
|
|
|
|
|
|
|
|
PushSubscriptionModifiedDispatcher::PushSubscriptionModifiedDispatcher(
|
|
|
|
const nsACString& aScope, nsIPrincipal* aPrincipal)
|
|
|
|
: PushDispatcher(aScope, aPrincipal) {}
|
|
|
|
|
|
|
|
PushSubscriptionModifiedDispatcher::~PushSubscriptionModifiedDispatcher() {}
|
|
|
|
|
|
|
|
nsresult PushSubscriptionModifiedDispatcher::NotifyObservers() {
|
|
|
|
return DoNotifyObservers(mPrincipal, OBSERVER_TOPIC_SUBSCRIPTION_MODIFIED,
|
|
|
|
mScope);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult PushSubscriptionModifiedDispatcher::NotifyWorkers() { return NS_OK; }
|
|
|
|
|
|
|
|
bool PushSubscriptionModifiedDispatcher::SendToParent(
|
|
|
|
ContentChild* aParentActor) {
|
|
|
|
return aParentActor->SendNotifyPushSubscriptionModifiedObservers(
|
|
|
|
mScope, IPC::Principal(mPrincipal));
|
|
|
|
}
|
|
|
|
|
2016-05-15 02:54:51 +03:00
|
|
|
bool PushSubscriptionModifiedDispatcher::SendToChild(
|
|
|
|
ContentParent* aContentActor) {
|
|
|
|
return aContentActor->SendNotifyPushSubscriptionModifiedObservers(
|
|
|
|
mScope, IPC::Principal(mPrincipal));
|
2016-05-20 05:01:34 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
PushErrorDispatcher::PushErrorDispatcher(const nsACString& aScope,
|
|
|
|
nsIPrincipal* aPrincipal,
|
|
|
|
const nsAString& aMessage,
|
|
|
|
uint32_t aFlags)
|
|
|
|
: PushDispatcher(aScope, aPrincipal), mMessage(aMessage), mFlags(aFlags) {}
|
|
|
|
|
|
|
|
PushErrorDispatcher::~PushErrorDispatcher() {}
|
|
|
|
|
|
|
|
nsresult PushErrorDispatcher::NotifyObservers() { return NS_OK; }
|
|
|
|
|
|
|
|
nsresult PushErrorDispatcher::NotifyWorkers() {
|
2019-01-29 23:27:03 +03:00
|
|
|
if (!ShouldNotifyWorkers() &&
|
2019-12-05 07:44:32 +03:00
|
|
|
(!mPrincipal || mPrincipal->IsSystemPrincipal())) {
|
2016-05-20 05:01:34 +03:00
|
|
|
// For system subscriptions, log the error directly to the browser console.
|
|
|
|
return nsContentUtils::ReportToConsoleNonLocalized(
|
|
|
|
mMessage, mFlags, NS_LITERAL_CSTRING("Push"), nullptr, /* aDocument */
|
|
|
|
nullptr, /* aURI */
|
|
|
|
EmptyString(), /* aLine */
|
|
|
|
0, /* aLineNumber */
|
|
|
|
0, /* aColumnNumber */
|
|
|
|
nsContentUtils::eOMIT_LOCATION);
|
|
|
|
}
|
2019-01-29 23:27:03 +03:00
|
|
|
|
2016-05-20 05:01:34 +03:00
|
|
|
// For service worker subscriptions, report the error to all clients.
|
|
|
|
RefPtr<ServiceWorkerManager> swm = ServiceWorkerManager::GetInstance();
|
|
|
|
if (swm) {
|
|
|
|
swm->ReportToAllClients(mScope, mMessage,
|
|
|
|
NS_ConvertUTF8toUTF16(mScope), /* aFilename */
|
|
|
|
EmptyString(), /* aLine */
|
|
|
|
0, /* aLineNumber */
|
|
|
|
0, /* aColumnNumber */
|
|
|
|
mFlags);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2019-01-29 23:27:03 +03:00
|
|
|
bool PushErrorDispatcher::SendToParent(ContentChild* aContentActor) {
|
|
|
|
return aContentActor->SendPushError(mScope, IPC::Principal(mPrincipal),
|
|
|
|
mMessage, mFlags);
|
|
|
|
}
|
2016-05-20 05:01:34 +03:00
|
|
|
|
|
|
|
bool PushErrorDispatcher::SendToChild(ContentParent* aContentActor) {
|
|
|
|
return aContentActor->SendPushError(mScope, IPC::Principal(mPrincipal),
|
|
|
|
mMessage, mFlags);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult PushErrorDispatcher::HandleNoChildProcesses() {
|
|
|
|
// Report to the console if no content processes are active.
|
|
|
|
nsCOMPtr<nsIURI> scopeURI;
|
|
|
|
nsresult rv = NS_NewURI(getter_AddRefs(scopeURI), mScope);
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
return nsContentUtils::ReportToConsoleNonLocalized(
|
|
|
|
mMessage, mFlags, NS_LITERAL_CSTRING("Push"), nullptr, /* aDocument */
|
|
|
|
scopeURI, /* aURI */
|
|
|
|
EmptyString(), /* aLine */
|
|
|
|
0, /* aLineNumber */
|
|
|
|
0, /* aColumnNumber */
|
|
|
|
nsContentUtils::eOMIT_LOCATION);
|
|
|
|
}
|
|
|
|
|
2016-01-14 08:19:51 +03:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|