Bug 1255894: Part 3 - Create skeleton IPDL framework for OOP stream filters. r?baku
This interface will allow extensions running into a content process to attach
a filtering stream listener to an HTTP request in the parent process. The
content process attaches a listener by sending a message from the content
process containing the ID of the request to filter, and the ID of the add-on
making the request. The permissions and request mappings for this are handled
by the web request service added in part 2.
MozReview-Commit-ID: B7Dd3ywwCBX
--- a/ipc/glue/BackgroundChildImpl.cpp
+++ b/ipc/glue/BackgroundChildImpl.cpp
@@ -27,16 +27,17 @@
#include "mozilla/dom/quota/PQuotaChild.h"
#include "mozilla/dom/StorageIPC.h"
#include "mozilla/dom/GamepadEventChannelChild.h"
#include "mozilla/dom/GamepadTestChannelChild.h"
#include "mozilla/dom/LocalStorage.h"
#include "mozilla/dom/MessagePortChild.h"
#include "mozilla/dom/TabChild.h"
#include "mozilla/dom/TabGroup.h"
+#include "mozilla/extensions/StreamFilterChild.h"
#include "mozilla/ipc/IPCStreamAlloc.h"
#include "mozilla/ipc/PBackgroundTestChild.h"
#include "mozilla/ipc/PChildToParentStreamChild.h"
#include "mozilla/ipc/PParentToChildStreamChild.h"
#include "mozilla/layout/VsyncChild.h"
#include "mozilla/net/HttpBackgroundChannelChild.h"
#include "mozilla/net/PUDPSocketChild.h"
#include "mozilla/dom/network/UDPSocketChild.h"
@@ -422,16 +423,36 @@ BackgroundChildImpl::AllocPCacheStreamCo
bool
BackgroundChildImpl::DeallocPCacheStreamControlChild(PCacheStreamControlChild* aActor)
{
dom::cache::DeallocPCacheStreamControlChild(aActor);
return true;
}
// -----------------------------------------------------------------------------
+// StreamFilter API
+// -----------------------------------------------------------------------------
+
+extensions::PStreamFilterChild*
+BackgroundChildImpl::AllocPStreamFilterChild(const uint64_t& aChannelId, const nsString& aAddonId)
+{
+ RefPtr<extensions::StreamFilterChild> agent = new extensions::StreamFilterChild();
+ return agent.forget().take();
+}
+
+bool
+BackgroundChildImpl::DeallocPStreamFilterChild(PStreamFilterChild* aActor)
+{
+ RefPtr<extensions::StreamFilterChild> child =
+ dont_AddRef(static_cast<extensions::StreamFilterChild*>(aActor));
+ MOZ_ASSERT(child);
+ return true;
+}
+
+// -----------------------------------------------------------------------------
// MessageChannel/MessagePort API
// -----------------------------------------------------------------------------
dom::PMessagePortChild*
BackgroundChildImpl::AllocPMessagePortChild(const nsID& aUUID,
const nsID& aDestinationUUID,
const uint32_t& aSequenceID)
{
--- a/ipc/glue/BackgroundChildImpl.h
+++ b/ipc/glue/BackgroundChildImpl.h
@@ -148,16 +148,23 @@ protected:
virtual PMessagePortChild*
AllocPMessagePortChild(const nsID& aUUID, const nsID& aDestinationUUID,
const uint32_t& aSequenceID) override;
virtual bool
DeallocPMessagePortChild(PMessagePortChild* aActor) override;
+ virtual PStreamFilterChild*
+ AllocPStreamFilterChild(const uint64_t& aChannelId,
+ const nsString& aAddonId) override;
+
+ virtual bool
+ DeallocPStreamFilterChild(PStreamFilterChild* aActor) override;
+
virtual PChildToParentStreamChild*
AllocPChildToParentStreamChild() override;
virtual bool
DeallocPChildToParentStreamChild(PChildToParentStreamChild* aActor) override;
virtual PParentToChildStreamChild*
AllocPParentToChildStreamChild() override;
--- a/ipc/glue/BackgroundParentImpl.cpp
+++ b/ipc/glue/BackgroundParentImpl.cpp
@@ -25,16 +25,17 @@
#include "mozilla/dom/ServiceWorkerRegistrar.h"
#include "mozilla/dom/asmjscache/AsmJSCache.h"
#include "mozilla/dom/cache/ActorUtils.h"
#include "mozilla/dom/indexedDB/ActorsParent.h"
#include "mozilla/dom/ipc/IPCBlobInputStreamParent.h"
#include "mozilla/dom/ipc/PendingIPCBlobParent.h"
#include "mozilla/dom/quota/ActorsParent.h"
#include "mozilla/dom/StorageIPC.h"
+#include "mozilla/extensions/StreamFilterParent.h"
#include "mozilla/ipc/BackgroundParent.h"
#include "mozilla/ipc/BackgroundUtils.h"
#include "mozilla/ipc/IPCStreamAlloc.h"
#include "mozilla/ipc/PBackgroundSharedTypes.h"
#include "mozilla/ipc/PBackgroundTestParent.h"
#include "mozilla/ipc/PChildToParentStreamParent.h"
#include "mozilla/ipc/PParentToChildStreamParent.h"
#include "mozilla/layout/VsyncParent.h"
@@ -63,16 +64,17 @@ using mozilla::dom::cache::PCacheParent;
using mozilla::dom::cache::PCacheStorageParent;
using mozilla::dom::cache::PCacheStreamControlParent;
using mozilla::dom::FileSystemBase;
using mozilla::dom::FileSystemRequestParent;
using mozilla::dom::MessagePortParent;
using mozilla::dom::PMessagePortParent;
using mozilla::dom::UDPSocketParent;
using mozilla::dom::WebAuthnTransactionParent;
+using mozilla::extensions::StreamFilterParent;
namespace {
void
AssertIsOnMainThread()
{
MOZ_ASSERT(NS_IsMainThread());
}
@@ -710,16 +712,54 @@ BackgroundParentImpl::AllocPCacheStreamC
bool
BackgroundParentImpl::DeallocPCacheStreamControlParent(PCacheStreamControlParent* aActor)
{
dom::cache::DeallocPCacheStreamControlParent(aActor);
return true;
}
+PStreamFilterParent*
+BackgroundParentImpl::AllocPStreamFilterParent(const uint64_t& aChannelId, const nsString& aAddonId)
+{
+ AssertIsInMainProcess();
+ AssertIsOnBackgroundThread();
+
+ return StreamFilterParent::Create(aChannelId, aAddonId).take();
+}
+
+mozilla::ipc::IPCResult
+BackgroundParentImpl::RecvPStreamFilterConstructor(PStreamFilterParent* aActor,
+ const uint64_t& aChannelId,
+ const nsString& aAddonId)
+{
+ AssertIsInMainProcess();
+ AssertIsOnBackgroundThread();
+
+ StreamFilterParent* filter = static_cast<StreamFilterParent*>(aActor);
+
+ RefPtr<ContentParent> parent = BackgroundParent::GetContentParent(this);
+
+ filter->Init(parent.forget());
+
+ return IPC_OK();
+}
+
+bool
+BackgroundParentImpl::DeallocPStreamFilterParent(PStreamFilterParent* aActor)
+{
+ AssertIsInMainProcess();
+ AssertIsOnBackgroundThread();
+ MOZ_ASSERT(aActor);
+
+ RefPtr<StreamFilterParent> filter = dont_AddRef(
+ static_cast<StreamFilterParent*>(aActor));
+ return true;
+}
+
PMessagePortParent*
BackgroundParentImpl::AllocPMessagePortParent(const nsID& aUUID,
const nsID& aDestinationUUID,
const uint32_t& aSequenceID)
{
AssertIsInMainProcess();
AssertIsOnBackgroundThread();
--- a/ipc/glue/BackgroundParentImpl.h
+++ b/ipc/glue/BackgroundParentImpl.h
@@ -13,16 +13,18 @@
namespace mozilla {
namespace layout {
class VsyncParent;
} // namespace layout
namespace ipc {
+using mozilla::extensions::PStreamFilterParent;
+
// Instances of this class should never be created directly. This class is meant
// to be inherited in BackgroundImpl.
class BackgroundParentImpl : public PBackgroundParent
{
protected:
BackgroundParentImpl();
virtual ~BackgroundParentImpl();
@@ -197,16 +199,28 @@ protected:
virtual bool
DeallocPMessagePortParent(PMessagePortParent* aActor) override;
virtual mozilla::ipc::IPCResult
RecvMessagePortForceClose(const nsID& aUUID,
const nsID& aDestinationUUID,
const uint32_t& aSequenceID) override;
+ virtual PStreamFilterParent*
+ AllocPStreamFilterParent(const uint64_t& aChannelId,
+ const nsString& aAddonId) override;
+
+ virtual mozilla::ipc::IPCResult
+ RecvPStreamFilterConstructor(PStreamFilterParent* aActor,
+ const uint64_t& aChannelId,
+ const nsString& aAddonId) override;
+
+ virtual bool
+ DeallocPStreamFilterParent(PStreamFilterParent* aActor) override;
+
virtual PAsmJSCacheEntryParent*
AllocPAsmJSCacheEntryParent(const dom::asmjscache::OpenMode& aOpenMode,
const dom::asmjscache::WriteParams& aWriteParams,
const PrincipalInfo& aPrincipalInfo) override;
virtual bool
DeallocPAsmJSCacheEntryParent(PAsmJSCacheEntryParent* aActor) override;
--- a/ipc/glue/PBackground.ipdl
+++ b/ipc/glue/PBackground.ipdl
@@ -14,16 +14,17 @@ include protocol PCacheStreamControl;
include protocol PFileDescriptorSet;
include protocol PFileSystemRequest;
include protocol PGamepadEventChannel;
include protocol PGamepadTestChannel;
include protocol PHttpBackgroundChannel;
include protocol PIPCBlobInputStream;
include protocol PPendingIPCBlob;
include protocol PMessagePort;
+include protocol PStreamFilter;
include protocol PCameras;
include protocol PQuota;
include protocol PChildToParentStream;
include protocol PParentToChildStream;
include protocol PServiceWorkerManager;
include protocol PWebAuthnTransaction;
include protocol PUDPSocket;
include protocol PVsync;
@@ -63,16 +64,17 @@ sync protocol PBackground
manages PFileDescriptorSet;
manages PFileSystemRequest;
manages PGamepadEventChannel;
manages PGamepadTestChannel;
manages PHttpBackgroundChannel;
manages PIPCBlobInputStream;
manages PPendingIPCBlob;
manages PMessagePort;
+ manages PStreamFilter;
manages PCameras;
manages PQuota;
manages PChildToParentStream;
manages PParentToChildStream;
manages PServiceWorkerManager;
manages PWebAuthnTransaction;
manages PUDPSocket;
manages PVsync;
@@ -107,16 +109,18 @@ parent:
async PServiceWorkerManager();
async ShutdownServiceWorkerRegistrar();
async PCacheStorage(Namespace aNamespace, PrincipalInfo aPrincipalInfo);
async PMessagePort(nsID uuid, nsID destinationUuid, uint32_t sequenceId);
+ async PStreamFilter(uint64_t channelId, nsString addonId);
+
async PChildToParentStream();
async MessagePortForceClose(nsID uuid, nsID destinationUuid, uint32_t sequenceId);
async PAsmJSCacheEntry(OpenMode openMode,
WriteParams write,
PrincipalInfo principalInfo);
new file mode 100644
--- /dev/null
+++ b/toolkit/components/extensions/webrequest/PStreamFilter.ipdl
@@ -0,0 +1,20 @@
+/* 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 protocol PBackground;
+
+namespace mozilla {
+namespace extensions {
+
+protocol PStreamFilter
+{
+ manager PBackground;
+
+child:
+ async __delete__();
+};
+
+} // namespace extensions
+} // namespace mozilla
+
new file mode 100644
--- /dev/null
+++ b/toolkit/components/extensions/webrequest/StreamFilterChild.cpp
@@ -0,0 +1,18 @@
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/* 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/. */
+
+#include "StreamFilterChild.h"
+
+namespace mozilla {
+namespace extensions {
+
+void
+StreamFilterChild::ActorDestroy(ActorDestroyReason aWhy)
+{
+}
+
+} // namespace extensions
+} // namespace mozilla
new file mode 100644
--- /dev/null
+++ b/toolkit/components/extensions/webrequest/StreamFilterChild.h
@@ -0,0 +1,37 @@
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/* 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 mozilla_extensions_StreamFilterChild_h
+#define mozilla_extensions_StreamFilterChild_h
+
+#include "mozilla/extensions/PStreamFilterChild.h"
+#include "nsISupportsImpl.h"
+
+namespace mozilla {
+namespace extensions {
+
+using mozilla::ipc::IPCResult;
+
+class StreamFilterChild final : public PStreamFilterChild
+{
+public:
+ NS_INLINE_DECL_REFCOUNTING(StreamFilterChild)
+
+ StreamFilterChild() {}
+
+protected:
+ virtual IPCResult Recv__delete__() override { return IPC_OK(); }
+
+private:
+ ~StreamFilterChild() {}
+
+ virtual void ActorDestroy(ActorDestroyReason aWhy) override;
+};
+
+} // namespace extensions
+} // namespace mozilla
+
+#endif // mozilla_extensions_StreamFilterChild_h
new file mode 100644
--- /dev/null
+++ b/toolkit/components/extensions/webrequest/StreamFilterParent.cpp
@@ -0,0 +1,44 @@
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/* 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/. */
+
+#include "StreamFilterParent.h"
+
+#include "mozilla/Unused.h"
+#include "mozilla/dom/nsIContentParent.h"
+#include "nsProxyRelease.h"
+
+namespace mozilla {
+namespace extensions {
+
+using namespace mozilla::dom;
+
+StreamFilterParent::StreamFilterParent(uint64_t aChannelId, const nsAString& aAddonId)
+ : mChannelId(aChannelId)
+ , mAddonId(NS_Atomize(aAddonId))
+{
+}
+
+StreamFilterParent::~StreamFilterParent()
+{
+}
+
+void
+StreamFilterParent::Init(already_AddRefed<nsIContentParent> aContentParent)
+{
+ nsCOMPtr<nsIContentParent> contentParent = aContentParent;
+ NS_ReleaseOnMainThread(contentParent.forget());
+}
+
+void
+StreamFilterParent::ActorDestroy(ActorDestroyReason aWhy)
+{
+}
+
+NS_IMPL_ISUPPORTS0(StreamFilterParent)
+
+} // namespace extensions
+} // namespace mozilla
+
new file mode 100644
--- /dev/null
+++ b/toolkit/components/extensions/webrequest/StreamFilterParent.h
@@ -0,0 +1,52 @@
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/* 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 mozilla_extensions_StreamFilterParent_h
+#define mozilla_extensions_StreamFilterParent_h
+
+#include "mozilla/extensions/PStreamFilterParent.h"
+
+namespace mozilla {
+namespace dom {
+ class nsIContentParent;
+}
+
+namespace extensions {
+
+using namespace mozilla::dom;
+using mozilla::ipc::IPCResult;
+
+class StreamFilterParent final : public PStreamFilterParent
+ , public nsISupports
+{
+public:
+ NS_DECL_THREADSAFE_ISUPPORTS
+
+ explicit StreamFilterParent(uint64_t aChannelId, const nsAString& aAddonId);
+
+ static already_AddRefed<StreamFilterParent>
+ Create(uint64_t aChannelId, const nsAString& aAddonId)
+ {
+ RefPtr<StreamFilterParent> filter = new StreamFilterParent(aChannelId, aAddonId);
+ return filter.forget();
+ }
+
+ void Init(already_AddRefed<nsIContentParent> aContentParent);
+
+protected:
+ virtual ~StreamFilterParent();
+
+private:
+ virtual void ActorDestroy(ActorDestroyReason aWhy) override;
+
+ const uint64_t mChannelId;
+ const nsCOMPtr<nsIAtom> mAddonId;
+};
+
+} // namespace extensions
+} // namespace mozilla
+
+#endif // mozilla_extensions_StreamFilterParent_h
--- a/toolkit/components/extensions/webrequest/moz.build
+++ b/toolkit/components/extensions/webrequest/moz.build
@@ -8,23 +8,36 @@ XPIDL_SOURCES += [
'mozIWebRequestService.idl',
'nsIWebRequestListener.idl',
]
XPIDL_MODULE = 'webextensions'
UNIFIED_SOURCES += [
'nsWebRequestListener.cpp',
+ 'StreamFilterChild.cpp',
+ 'StreamFilterParent.cpp',
'WebRequestService.cpp',
]
+IPDL_SOURCES += [
+ 'PStreamFilter.ipdl',
+]
+
EXPORTS += [
'nsWebRequestListener.h',
]
EXPORTS.mozilla += [
'WebRequestService.h',
]
+EXPORTS.mozilla.extensions += [
+ 'StreamFilterChild.h',
+ 'StreamFilterParent.h',
+]
+
+include('/ipc/chromium/chromium-config.mozbuild')
+
FINAL_LIBRARY = 'xul'
with Files("**"):
BUG_COMPONENT = ("Toolkit", "WebExtensions: Request Handling")