mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-27 06:43:32 +00:00
Bug 1928702 - Part 2: Create PNotification via PBackground r=asuth
Differential Revision: https://phabricator.services.mozilla.com/D227687
This commit is contained in:
parent
b9e417e526
commit
21033fe93d
@ -12,6 +12,7 @@ include "mozilla/dom/PermissionMessageUtils.h";
|
||||
include "mozilla/dom/PropertyBagUtils.h";
|
||||
include "mozilla/dom/ReferrerInfoUtils.h";
|
||||
include "mozilla/dom/TabMessageUtils.h";
|
||||
include "mozilla/dom/notification/IPCUtils.h";
|
||||
include "mozilla/ipc/URIUtils.h";
|
||||
include "mozilla/layers/LayersMessageUtils.h";
|
||||
include "mozilla/net/NeckoMessageUtils.h";
|
||||
@ -55,6 +56,8 @@ using mozilla::dom::MaybeDiscardedBrowsingContext from "mozilla/dom/BrowsingCont
|
||||
using mozilla::TimeStamp from "mozilla/TimeStamp.h";
|
||||
[RefCounted] using class mozilla::RemoteLazyInputStream from "mozilla/RemoteLazyInputStream.h";
|
||||
[MoveOnly] using class mozilla::ipc::BigBuffer from "mozilla/ipc/BigBuffer.h";
|
||||
using mozilla::dom::NotificationDirection from "mozilla/dom/NotificationBinding.h";
|
||||
using mozilla::dom::NotificationBehavior from "mozilla/dom/NotificationBinding.h";
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
@ -190,7 +193,7 @@ struct DocShellLoadStateInit
|
||||
uint32_t LoadType;
|
||||
uint32_t LoadFlags;
|
||||
uint32_t InternalLoadFlags;
|
||||
|
||||
|
||||
// The TriggineringSandboxFlags are the SandboxFlags of the entity
|
||||
// responsible for causing the load to occur.
|
||||
uint32_t TriggeringSandboxFlags;
|
||||
@ -329,5 +332,23 @@ struct IPCImage {
|
||||
ImageIntSize size;
|
||||
};
|
||||
|
||||
// Mostly same as NotificationOptions except:
|
||||
// * `title` is included (it's a separate parameter in the Notification constructor)
|
||||
// * `data` is serialized to base64 string by StructuredCloneContainer
|
||||
// * `vibrate` is normalized to sequence
|
||||
struct IPCNotificationOptions {
|
||||
nsString title;
|
||||
NotificationDirection dir;
|
||||
nsString lang;
|
||||
nsString body;
|
||||
nsString tag;
|
||||
nsString icon;
|
||||
bool requireInteraction;
|
||||
bool silent;
|
||||
uint32_t[] vibrate;
|
||||
nsString dataSerialized;
|
||||
NotificationBehavior behavior;
|
||||
};
|
||||
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
||||
|
29
dom/notification/IPCUtils.h
Normal file
29
dom/notification/IPCUtils.h
Normal file
@ -0,0 +1,29 @@
|
||||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
||||
/* 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 DOM_NOTIFICATION_IPCUTILS_H_
|
||||
#define DOM_NOTIFICATION_IPCUTILS_H_
|
||||
|
||||
#include "ipc/EnumSerializer.h"
|
||||
#include "ipc/IPCMessageUtils.h"
|
||||
#include "mozilla/dom/NotificationBinding.h"
|
||||
|
||||
namespace IPC {
|
||||
|
||||
using NotificationDirection = mozilla::dom::NotificationDirection;
|
||||
template <>
|
||||
struct ParamTraits<NotificationDirection>
|
||||
: public ContiguousEnumSerializerInclusive<NotificationDirection,
|
||||
NotificationDirection::Auto,
|
||||
NotificationDirection::Rtl> {};
|
||||
|
||||
DEFINE_IPC_SERIALIZER_WITH_FIELDS(mozilla::dom::NotificationBehavior, mNoclear,
|
||||
mNoscreen, mShowOnlyOnce, mSoundFile,
|
||||
mVibrationPattern);
|
||||
|
||||
} // namespace IPC
|
||||
|
||||
#endif // DOM_NOTIFICATION_IPCUTILS_H_
|
@ -30,6 +30,9 @@
|
||||
#include "mozilla/dom/WorkerRunnable.h"
|
||||
#include "mozilla/dom/WorkerScope.h"
|
||||
#include "mozilla/dom/quota/ResultExtensions.h"
|
||||
#include "mozilla/ipc/BackgroundChild.h"
|
||||
#include "mozilla/ipc/BackgroundUtils.h"
|
||||
#include "mozilla/ipc/PBackgroundChild.h"
|
||||
#include "Navigator.h"
|
||||
#include "NotificationUtils.h"
|
||||
#include "nsComponentManagerUtils.h"
|
||||
@ -2237,6 +2240,52 @@ already_AddRefed<Notification> Notification::CreateAndShow(
|
||||
return notification.forget();
|
||||
}
|
||||
|
||||
bool Notification::CreateActor(Promise* aPromise) {
|
||||
mozilla::ipc::PBackgroundChild* backgroundActor =
|
||||
mozilla::ipc::BackgroundChild::GetOrCreateForCurrentThread();
|
||||
IPCNotificationOptions options(mTitle, mDir, mLang, mBody, mTag, mIconUrl,
|
||||
mRequireInteraction, mSilent, mVibrate,
|
||||
mDataAsBase64, mBehavior);
|
||||
|
||||
// Note: We are not using the typical PBackground managed actor here as we
|
||||
// want the actor to be in the main thread of the main process. Instead we
|
||||
// pass the endpoint to PBackground, it dispatches a runnable to the main
|
||||
// thread, and the endpoint is bound there.
|
||||
|
||||
mozilla::ipc::Endpoint<notification::PNotificationParent> parentEndpoint;
|
||||
mozilla::ipc::Endpoint<notification::PNotificationChild> childEndpoint;
|
||||
notification::PNotification::CreateEndpoints(&parentEndpoint, &childEndpoint);
|
||||
|
||||
mActor = new notification::NotificationChild();
|
||||
if (!childEndpoint.Bind(mActor)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
nsIPrincipal* principal;
|
||||
nsIPrincipal* effectiveStoragePrincipal;
|
||||
bool isSecureContext;
|
||||
|
||||
// TODO: Should get nsIGlobalObject methods for each method
|
||||
if (WorkerPrivate* workerPrivate = GetCurrentThreadWorkerPrivate()) {
|
||||
principal = workerPrivate->GetPrincipal();
|
||||
effectiveStoragePrincipal = workerPrivate->GetEffectiveStoragePrincipal();
|
||||
isSecureContext = workerPrivate->IsSecureContext();
|
||||
} else {
|
||||
nsGlobalWindowInner* win = GetOwnerWindow();
|
||||
NS_ENSURE_TRUE(win, false);
|
||||
principal = win->GetPrincipal();
|
||||
effectiveStoragePrincipal = win->GetEffectiveStoragePrincipal();
|
||||
isSecureContext = win->IsSecureContext();
|
||||
}
|
||||
|
||||
(void)backgroundActor->SendCreateNotificationParent(
|
||||
std::move(parentEndpoint), WrapNotNull(principal),
|
||||
WrapNotNull(effectiveStoragePrincipal), isSecureContext, mID, mScope,
|
||||
options);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/* static */
|
||||
nsresult Notification::RemovePermission(nsIPrincipal* aPrincipal) {
|
||||
MOZ_ASSERT(XRE_IsParentProcess());
|
||||
|
@ -11,6 +11,7 @@
|
||||
#include "mozilla/GlobalFreezeObserver.h"
|
||||
#include "mozilla/UniquePtr.h"
|
||||
#include "mozilla/dom/NotificationBinding.h"
|
||||
#include "mozilla/dom/notification/NotificationChild.h"
|
||||
#include "mozilla/dom/WorkerPrivate.h"
|
||||
#include "mozilla/dom/quota/QuotaCommon.h"
|
||||
|
||||
@ -273,6 +274,8 @@ class Notification : public DOMEventTargetHelper, public GlobalFreezeObserver {
|
||||
mScope = aScope;
|
||||
}
|
||||
|
||||
WeakPtr<notification::NotificationChild> mActor;
|
||||
|
||||
const nsString mID;
|
||||
const nsString mTitle;
|
||||
const nsString mBody;
|
||||
@ -318,6 +321,8 @@ class Notification : public DOMEventTargetHelper, public GlobalFreezeObserver {
|
||||
const NotificationOptions& aOptions, const nsAString& aScope,
|
||||
ErrorResult& aRv);
|
||||
|
||||
bool CreateActor(Promise* aPromise);
|
||||
|
||||
nsIPrincipal* GetPrincipal();
|
||||
|
||||
nsresult PersistNotification();
|
||||
|
@ -7,11 +7,13 @@
|
||||
#ifndef DOM_NOTIFICATION_NOTIFICATIONCHILD_H_
|
||||
#define DOM_NOTIFICATION_NOTIFICATIONCHILD_H_
|
||||
|
||||
#include "mozilla/WeakPtr.h"
|
||||
#include "mozilla/dom/notification/PNotificationChild.h"
|
||||
|
||||
namespace mozilla::dom::notification {
|
||||
|
||||
class NotificationChild final : public PNotificationChild {
|
||||
class NotificationChild final : public PNotificationChild,
|
||||
public SupportsWeakPtr {
|
||||
NS_INLINE_DECL_REFCOUNTING(NotificationChild)
|
||||
|
||||
private:
|
||||
|
@ -6,6 +6,8 @@
|
||||
|
||||
#include "NotificationParent.h"
|
||||
|
||||
#include "mozilla/ipc/Endpoint.h"
|
||||
|
||||
namespace mozilla::dom::notification {
|
||||
|
||||
NS_IMPL_ISUPPORTS(NotificationParent, nsIObserver)
|
||||
@ -20,4 +22,22 @@ mozilla::ipc::IPCResult NotificationParent::RecvShow(ShowResolver&& aResolver) {
|
||||
return IPC_OK();
|
||||
}
|
||||
|
||||
nsresult NotificationParent::BindToMainThread(
|
||||
Endpoint<PNotificationParent>&& aParentEndpoint,
|
||||
PBackgroundParent::CreateNotificationParentResolver&& aResolver) {
|
||||
nsCOMPtr<nsIThread> thread = NS_GetCurrentThread();
|
||||
|
||||
NS_DispatchToMainThread(NS_NewRunnableFunction(
|
||||
"NotificationParent::BindToMainThread",
|
||||
[self = RefPtr(this), endpoint = std::move(aParentEndpoint),
|
||||
resolver = std::move(aResolver), thread]() mutable {
|
||||
bool result = endpoint.Bind(self);
|
||||
thread->Dispatch(NS_NewRunnableFunction(
|
||||
"NotificationParent::BindToMainThreadResult",
|
||||
[result, resolver = std::move(resolver)]() { resolver(result); }));
|
||||
}));
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
} // namespace mozilla::dom::notification
|
||||
|
@ -22,11 +22,34 @@ class NotificationParent final : public PNotificationParent,
|
||||
NS_DECL_THREADSAFE_ISUPPORTS
|
||||
NS_DECL_NSIOBSERVER
|
||||
|
||||
NotificationParent(NotNull<nsIPrincipal*> aPrincipal,
|
||||
NotNull<nsIPrincipal*> aEffectiveStoragePrincipal,
|
||||
bool aIsSecureContext, const nsAString& aId,
|
||||
const nsAString& aScope,
|
||||
const IPCNotificationOptions& aOptions)
|
||||
: mPrincipal(aPrincipal),
|
||||
mEffectiveStoragePrincipal(aEffectiveStoragePrincipal),
|
||||
mIsSecureContext(aIsSecureContext),
|
||||
mId(aId),
|
||||
mScope(aScope),
|
||||
mOptions(aOptions) {};
|
||||
|
||||
IPCResult RecvShow(ShowResolver&& aResolver);
|
||||
IPCResult RecvClose();
|
||||
|
||||
nsresult BindToMainThread(
|
||||
Endpoint<PNotificationParent>&& aParentEndpoint,
|
||||
PBackgroundParent::CreateNotificationParentResolver&& aResolver);
|
||||
|
||||
private:
|
||||
~NotificationParent() = default;
|
||||
|
||||
NotNull<nsCOMPtr<nsIPrincipal>> mPrincipal;
|
||||
NotNull<nsCOMPtr<nsIPrincipal>> mEffectiveStoragePrincipal;
|
||||
bool mIsSecureContext;
|
||||
nsString mId;
|
||||
nsString mScope;
|
||||
IPCNotificationOptions mOptions;
|
||||
};
|
||||
|
||||
} // namespace mozilla::dom::notification
|
||||
|
@ -21,6 +21,7 @@ EXPORTS.mozilla.dom += [
|
||||
]
|
||||
|
||||
EXPORTS.mozilla.dom.notification += [
|
||||
"IPCUtils.h",
|
||||
"NotificationChild.h",
|
||||
"NotificationParent.h",
|
||||
]
|
||||
|
@ -54,6 +54,7 @@
|
||||
#include "mozilla/dom/locks/LockManagerParent.h"
|
||||
#include "mozilla/dom/localstorage/ActorsParent.h"
|
||||
#include "mozilla/dom/network/UDPSocketParent.h"
|
||||
#include "mozilla/dom/notification/NotificationParent.h"
|
||||
#include "mozilla/dom/quota/ActorsParent.h"
|
||||
#include "mozilla/dom/quota/QuotaParent.h"
|
||||
#include "mozilla/dom/simpledb/ActorsParent.h"
|
||||
@ -479,6 +480,23 @@ mozilla::ipc::IPCResult BackgroundParentImpl::RecvCreateWebTransportParent(
|
||||
return IPC_OK();
|
||||
}
|
||||
|
||||
mozilla::ipc::IPCResult BackgroundParentImpl::RecvCreateNotificationParent(
|
||||
Endpoint<dom::notification::PNotificationParent>&& aParentEndpoint,
|
||||
NotNull<nsIPrincipal*> aPrincipal,
|
||||
NotNull<nsIPrincipal*> aEffectiveStoragePrincipal,
|
||||
const bool& aIsSecureContext, const nsAString& aId, const nsAString& aScope,
|
||||
const IPCNotificationOptions& aOptions,
|
||||
CreateNotificationParentResolver&& aResolver) {
|
||||
AssertIsInMainProcess();
|
||||
AssertIsOnBackgroundThread();
|
||||
|
||||
auto actor = MakeRefPtr<dom::notification::NotificationParent>(
|
||||
aPrincipal, aEffectiveStoragePrincipal, aIsSecureContext, aId, aScope,
|
||||
aOptions);
|
||||
actor->BindToMainThread(std::move(aParentEndpoint), std::move(aResolver));
|
||||
return IPC_OK();
|
||||
}
|
||||
|
||||
already_AddRefed<PIdleSchedulerParent>
|
||||
BackgroundParentImpl::AllocPIdleSchedulerParent() {
|
||||
AssertIsOnBackgroundThread();
|
||||
@ -1381,8 +1399,7 @@ mozilla::ipc::IPCResult BackgroundParentImpl::RecvPLockManagerConstructor(
|
||||
already_AddRefed<dom::locks::PLockManagerParent>
|
||||
BackgroundParentImpl::AllocPLockManagerParent(NotNull<nsIPrincipal*> aPrincipal,
|
||||
const Maybe<nsID>& aClientId) {
|
||||
return MakeAndAddRef<mozilla::dom::locks::LockManagerParent>(aPrincipal,
|
||||
aClientId);
|
||||
return MakeAndAddRef<dom::locks::LockManagerParent>(aPrincipal, aClientId);
|
||||
}
|
||||
|
||||
already_AddRefed<dom::PFetchParent> BackgroundParentImpl::AllocPFetchParent() {
|
||||
|
@ -129,6 +129,14 @@ class BackgroundParentImpl : public PBackgroundParent {
|
||||
Endpoint<PWebTransportParent>&& aParentEndpoint,
|
||||
CreateWebTransportParentResolver&& aResolver) override;
|
||||
|
||||
mozilla::ipc::IPCResult RecvCreateNotificationParent(
|
||||
Endpoint<dom::notification::PNotificationParent>&& aParentEndpoint,
|
||||
NotNull<nsIPrincipal*> aPrincipal,
|
||||
NotNull<nsIPrincipal*> aEffectiveStoragePrincipal,
|
||||
const bool& aIsSecureContext, const nsAString& aId,
|
||||
const nsAString& aScope, const IPCNotificationOptions& aOptions,
|
||||
CreateNotificationParentResolver&& aResolver) final;
|
||||
|
||||
already_AddRefed<PIdleSchedulerParent> AllocPIdleSchedulerParent() override;
|
||||
|
||||
PTemporaryIPCBlobParent* AllocPTemporaryIPCBlobParent() override;
|
||||
|
@ -48,6 +48,7 @@ include protocol PVsync;
|
||||
include protocol PRemoteDecoderManager;
|
||||
include protocol PWebTransport;
|
||||
include protocol PFetch;
|
||||
include protocol PNotification;
|
||||
|
||||
include ClientIPCTypes;
|
||||
include DOMTypes;
|
||||
@ -186,6 +187,21 @@ parent:
|
||||
Endpoint<PWebTransportParent> aParentEndpoint)
|
||||
returns(nsresult rv, uint8_t aReliability); // Actually WebTransportReliabityMode enum
|
||||
|
||||
|
||||
// XXX(krosylight): This should ultimately use nsID instead of scope, see bug 1881812.
|
||||
/**
|
||||
* Finish the setup of a new PNotification top level protocol.
|
||||
*/
|
||||
async CreateNotificationParent(
|
||||
Endpoint<PNotificationParent> aParentEndpoint,
|
||||
nsIPrincipal aPrincipal,
|
||||
nsIPrincipal aEffectiveStoragePrincipal,
|
||||
bool aIsSecureContext,
|
||||
nsString aId,
|
||||
nsString aScope,
|
||||
IPCNotificationOptions aOptions
|
||||
) returns (bool rv);
|
||||
|
||||
async PVsync();
|
||||
|
||||
async PCameras();
|
||||
|
Loading…
Reference in New Issue
Block a user