Bug 1581859: Part 4a - Add skeleton PExtensions actor. r=zombie,nika

This is the start of an actor which will be automatically instantiated in the
parent and each content process which can be used to route most process-level
IPC traffic needed by the extensions framework. It should allow the extensions
framework to keep its IPC glue close to the code that uses it, and simplify
matters for child-side code which needs to run in both parent and content
processes.

Differential Revision: https://phabricator.services.mozilla.com/D103212
This commit is contained in:
Kris Maglione 2021-03-18 05:51:07 +00:00
Родитель 82fc76ce55
Коммит 9970502b03
12 изменённых файлов: 215 добавлений и 0 удалений

Просмотреть файл

@ -81,6 +81,7 @@
#include "mozilla/dom/WorkerDebugger.h"
#include "mozilla/dom/WorkerDebuggerManager.h"
#include "mozilla/dom/ipc/SharedMap.h"
#include "mozilla/extensions/ExtensionsChild.h"
#include "mozilla/extensions/StreamFilterParent.h"
#include "mozilla/gfx/Logging.h"
#include "mozilla/gfx/gfxVars.h"

Просмотреть файл

@ -126,6 +126,7 @@
#include "mozilla/dom/power/PowerManagerService.h"
#include "mozilla/dom/quota/QuotaManagerService.h"
#include "mozilla/embedding/printingui/PrintingParent.h"
#include "mozilla/extensions/ExtensionsParent.h"
#include "mozilla/extensions/StreamFilterParent.h"
#include "mozilla/gfx/GPUProcessManager.h"
#include "mozilla/gfx/gfxVars.h"
@ -5000,6 +5001,11 @@ mozilla::ipc::IPCResult ContentParent::RecvCreateAudioIPCConnection(
return IPC_OK();
}
already_AddRefed<extensions::PExtensionsParent>
ContentParent::AllocPExtensionsParent() {
return MakeAndAddRef<extensions::ExtensionsParent>();
}
PFileDescriptorSetParent* ContentParent::AllocPFileDescriptorSetParent(
const FileDescriptor& aFD) {
return new FileDescriptorSetParent(aFD);

Просмотреть файл

@ -1177,6 +1177,8 @@ class ContentParent final
mozilla::ipc::IPCResult RecvCreateAudioIPCConnection(
CreateAudioIPCConnectionResolver&& aResolver);
already_AddRefed<extensions::PExtensionsParent> AllocPExtensionsParent();
PFileDescriptorSetParent* AllocPFileDescriptorSetParent(
const mozilla::ipc::FileDescriptor&);

Просмотреть файл

@ -10,6 +10,7 @@ include protocol PCompositorManager;
include protocol PContentPermissionRequest;
include protocol PCycleCollectWithLogs;
include protocol PDocumentChannel;
include protocol PExtensions;
include protocol PExternalHelperApp;
include protocol PHandlerService;
include protocol PFileDescriptorSet;
@ -406,6 +407,7 @@ nested(upto inside_cpow) sync protocol PContent
manages PBrowser;
manages PContentPermissionRequest;
manages PCycleCollectWithLogs;
manages PExtensions;
manages PExternalHelperApp;
manages PFileDescriptorSet;
manages PHal;
@ -470,6 +472,8 @@ parent:
async CloneDocumentTreeInto(MaybeDiscardedBrowsingContext aSourceBc,
MaybeDiscardedBrowsingContext aTargetBc);
async PExtensions();
child:
async ConstructBrowser(ManagedEndpoint<PBrowserChild> browserEp,
ManagedEndpoint<PWindowGlobalChild> windowEp,

Просмотреть файл

@ -4,6 +4,7 @@
* 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 PExtensions;
include protocol PWindowGlobal;
include DOMTypes;
@ -21,6 +22,7 @@ namespace dom {
*/
async refcounted protocol PInProcess
{
manages PExtensions;
manages PWindowGlobal;
};

Просмотреть файл

@ -0,0 +1,61 @@
/* -*- Mode: C++; 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 "mozilla/extensions/ExtensionsChild.h"
#include "mozilla/extensions/ExtensionsParent.h"
#include "mozilla/ClearOnShutdown.h"
#include "mozilla/dom/ContentChild.h"
#include "mozilla/dom/InProcessChild.h"
#include "mozilla/dom/InProcessParent.h"
#include "mozilla/ipc/Endpoint.h"
#include "nsXULAppAPI.h"
using namespace mozilla::dom;
namespace mozilla {
namespace extensions {
NS_IMPL_ISUPPORTS0(ExtensionsChild)
/* static */
ExtensionsChild& ExtensionsChild::Get() {
static RefPtr<ExtensionsChild> sInstance;
if (MOZ_UNLIKELY(!sInstance)) {
sInstance = new ExtensionsChild();
sInstance->Init();
ClearOnShutdown(&sInstance);
}
return *sInstance;
}
/* static */
already_AddRefed<ExtensionsChild> ExtensionsChild::GetSingleton() {
return do_AddRef(&Get());
}
void ExtensionsChild::Init() {
if (XRE_IsContentProcess()) {
ContentChild::GetSingleton()->SendPExtensionsConstructor(this);
} else {
InProcessChild* ipChild = InProcessChild::Singleton();
InProcessParent* ipParent = InProcessParent::Singleton();
if (!ipChild || !ipParent) {
return;
}
RefPtr parent = new ExtensionsParent();
ManagedEndpoint<PExtensionsParent> endpoint =
ipChild->OpenPExtensionsEndpoint(this);
ipParent->BindPExtensionsEndpoint(std::move(endpoint), parent);
}
}
void ExtensionsChild::ActorDestroy(ActorDestroyReason aWhy) {}
} // namespace extensions
} // namespace mozilla

Просмотреть файл

@ -0,0 +1,36 @@
/* -*- Mode: C++; tab-width: 4; 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/. */
#ifndef mozilla_extensions_ExtensionsChild_h
#define mozilla_extensions_ExtensionsChild_h
#include "mozilla/extensions/PExtensionsChild.h"
#include "nsISupportsImpl.h"
namespace mozilla {
namespace extensions {
class ExtensionsChild final : public nsISupports, public PExtensionsChild {
public:
NS_DECL_ISUPPORTS
static already_AddRefed<ExtensionsChild> GetSingleton();
static ExtensionsChild& Get();
private:
ExtensionsChild() = default;
~ExtensionsChild() = default;
void Init();
protected:
void ActorDestroy(ActorDestroyReason aWhy) override;
};
} // namespace extensions
} // namespace mozilla
#endif // mozilla_extensions_ExtensionsChild_h

Просмотреть файл

@ -0,0 +1,16 @@
/* -*- Mode: C++; 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 "mozilla/extensions/ExtensionsParent.h"
#include "mozilla/dom/ContentParent.h"
#include "mozilla/RefPtr.h"
namespace mozilla {
namespace extensions {
void ExtensionsParent::ActorDestroy(ActorDestroyReason aWhy) {}
} // namespace extensions
} // namespace mozilla

Просмотреть файл

@ -0,0 +1,31 @@
/* -*- Mode: C++; tab-width: 4; 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/. */
#ifndef mozilla_extensions_ExtensionsParent_h
#define mozilla_extensions_ExtensionsParent_h
#include "mozilla/extensions/PExtensionsParent.h"
#include "nsISupportsImpl.h"
namespace mozilla {
namespace extensions {
class ExtensionsParent final : public PExtensionsParent {
public:
NS_INLINE_DECL_REFCOUNTING(ExtensionsParent, final)
ExtensionsParent() = default;
private:
~ExtensionsParent() = default;
protected:
void ActorDestroy(ActorDestroyReason aWhy) override;
};
} // namespace extensions
} // namespace mozilla
#endif // mozilla_extensions_ExtensionsParent_h

Просмотреть файл

@ -0,0 +1,28 @@
/* -*- Mode: C++; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 8 -*- */
/* vim: set sw=4 ts=8 et tw=80 ft=cpp : */
/* 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 PContent;
include protocol PInProcess;
namespace mozilla {
namespace extensions {
/**
* A generic protocol used by the extension framework for process-level IPC. A
* child instance is created at startup in the parent process and each content
* child process, which can be accessed via
* `mozilla::extensions::ExtensionsChild::Get()`.
*/
refcounted protocol PExtensions
{
manager PContent or PInProcess;
parent:
async __delete__();
};
} // namespace extensions
} // namespace mozilla

Просмотреть файл

@ -0,0 +1,16 @@
# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
# vim: set filetype=python:
# 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/.
Classes = [
{
'cid': '{db82286d-d649-47fb-8599-ba31673a58c5}',
'contract_ids': ['@mozilla.org/extensions/child;1'],
'type': 'mozilla::extensions::ExtensionsChild',
'constructor': 'mozilla::extensions::ExtensionsChild::GetSingleton',
'headers': ['mozilla/extensions/ExtensionsChild.h'],
'categories': {'app-startup': 'ExtensionsChild'},
},
]

Просмотреть файл

@ -69,6 +69,10 @@ DIRS += [
"webrequest",
]
IPDL_SOURCES += [
"PExtensions.ipdl",
]
XPIDL_SOURCES += [
"mozIExtensionProcessScript.idl",
]
@ -81,6 +85,8 @@ EXPORTS.mozilla = [
EXPORTS.mozilla.extensions = [
"DocumentObserver.h",
"ExtensionsChild.h",
"ExtensionsParent.h",
"MatchGlob.h",
"MatchPattern.h",
"WebExtensionContentScript.h",
@ -89,10 +95,16 @@ EXPORTS.mozilla.extensions = [
UNIFIED_SOURCES += [
"ExtensionPolicyService.cpp",
"ExtensionsChild.cpp",
"ExtensionsParent.cpp",
"MatchPattern.cpp",
"WebExtensionPolicy.cpp",
]
XPCOM_MANIFESTS += [
"components.conf",
]
FINAL_LIBRARY = "xul"