1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
5 * You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef mozilla_ipc_ExtensionKitUtils_h
8 #define mozilla_ipc_ExtensionKitUtils_h
12 #include "mozilla/DarwinObjectPtr.h"
13 #include "mozilla/Result.h"
14 #include "mozilla/ResultVariant.h"
15 #include "mozilla/UniquePtr.h"
16 #include "mozilla/ipc/LaunchError.h"
18 namespace mozilla::ipc
{
20 class BEProcessCapabilityGrantDeleter
{
22 void operator()(void* aGrant
) const;
25 using UniqueBEProcessCapabilityGrant
=
26 mozilla::UniquePtr
<void, BEProcessCapabilityGrantDeleter
>;
28 class ExtensionKitProcess
{
36 // Called to start the process. The `aCompletion` function may be executed on
37 // a background libdispatch thread.
38 static void StartProcess(
40 const std::function
<void(Result
<ExtensionKitProcess
, LaunchError
>&&)>&
43 // Get the kind of process being started.
44 Kind
GetKind() const { return mKind
; }
46 // Make an xpc_connection_t to this process. If an error is encountered,
47 // `aError` will be populated with the error.
49 // Ownership over the newly created connection is returned to the caller.
50 // The connection is returned in a suspended state, and must be resumed.
51 DarwinObjectPtr
<xpc_connection_t
> MakeLibXPCConnection();
53 UniqueBEProcessCapabilityGrant
GrantForegroundCapability();
55 // Invalidate the process, indicating that it should be cleaned up &
59 // Explicit copy constructors
60 ExtensionKitProcess(const ExtensionKitProcess
&);
61 ExtensionKitProcess
& operator=(const ExtensionKitProcess
&);
63 // Release the object when completed.
64 ~ExtensionKitProcess();
67 ExtensionKitProcess(Kind aKind
, void* aProcessObject
)
68 : mKind(aKind
), mProcessObject(aProcessObject
) {}
70 // Type tag for `mProcessObject`.
73 // This is one of `BEWebContentProcess`, `BENetworkingProcess` or
74 // `BERenderingProcess`. It has been type erased to be usable from C++ code.
78 } // namespace mozilla::ipc
80 #endif // mozilla_ipc_ExtensionKitUtils_h