Backed out changeset 1ecf6afb4dc7 for causing failures.
[gecko.git] / ipc / glue / ExtensionKitUtils.h
blob88ee5ac0f9aa329b950c027da84920da142ec3b0
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
10 #include <functional>
11 #include <xpc/xpc.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 {
21 public:
22 void operator()(void* aGrant) const;
25 using UniqueBEProcessCapabilityGrant =
26 mozilla::UniquePtr<void, BEProcessCapabilityGrantDeleter>;
28 class ExtensionKitProcess {
29 public:
30 enum class Kind {
31 WebContent,
32 Networking,
33 Rendering,
36 // Called to start the process. The `aCompletion` function may be executed on
37 // a background libdispatch thread.
38 static void StartProcess(
39 Kind aKind,
40 const std::function<void(Result<ExtensionKitProcess, LaunchError>&&)>&
41 aCompletion);
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 &
56 // destroyed.
57 void Invalidate();
59 // Explicit copy constructors
60 ExtensionKitProcess(const ExtensionKitProcess&);
61 ExtensionKitProcess& operator=(const ExtensionKitProcess&);
63 // Release the object when completed.
64 ~ExtensionKitProcess();
66 private:
67 ExtensionKitProcess(Kind aKind, void* aProcessObject)
68 : mKind(aKind), mProcessObject(aProcessObject) {}
70 // Type tag for `mProcessObject`.
71 Kind mKind;
73 // This is one of `BEWebContentProcess`, `BENetworkingProcess` or
74 // `BERenderingProcess`. It has been type erased to be usable from C++ code.
75 void* mProcessObject;
78 } // namespace mozilla::ipc
80 #endif // mozilla_ipc_ExtensionKitUtils_h