Bug 1835710 - Cancel off-thread JIT compilation before changing nursery allocation...
[gecko.git] / dom / base / ContentProcessMessageManager.h
blobb7c54ba4526a4cf4cf6717794d9d74494e376785
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
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef mozilla_dom_ContentProcessMessageManager_h
8 #define mozilla_dom_ContentProcessMessageManager_h
10 #include "mozilla/Attributes.h"
11 #include "mozilla/dom/MessageManagerGlobal.h"
12 #include "mozilla/dom/MessageManagerCallback.h"
13 #include "nsCOMPtr.h"
14 #include "nsIScriptContext.h"
15 #include "nsServiceManagerUtils.h"
16 #include "nsWeakReference.h"
17 #include "nsWrapperCache.h"
18 #include "xpcpublic.h"
20 class nsFrameMessageManager;
22 namespace mozilla::dom {
24 namespace ipc {
25 class SharedMap;
28 /**
29 * This class implements a singleton process message manager for content
30 * processes. Each child process has exactly one instance of this class, which
31 * hosts the process's process scripts, and may exchange messages with its
32 * corresponding ParentProcessMessageManager on the parent side.
35 class ContentProcessMessageManager : public nsIMessageSender,
36 public nsMessageManagerScriptExecutor,
37 public nsSupportsWeakReference,
38 public ipc::MessageManagerCallback,
39 public MessageManagerGlobal,
40 public nsWrapperCache {
41 public:
42 explicit ContentProcessMessageManager(nsFrameMessageManager* aMessageManager);
44 using ipc::MessageManagerCallback::GetProcessMessageManager;
45 using MessageManagerGlobal::GetProcessMessageManager;
47 bool Init();
49 static ContentProcessMessageManager* Get();
50 static bool WasCreated();
52 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
53 NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_AMBIGUOUS(
54 ContentProcessMessageManager, nsIMessageSender)
56 void MarkForCC();
58 virtual JSObject* WrapObject(JSContext* aCx,
59 JS::Handle<JSObject*> aGivenProto) override;
61 JSObject* GetOrCreateWrapper();
63 using MessageManagerGlobal::AddMessageListener;
64 using MessageManagerGlobal::AddWeakMessageListener;
65 using MessageManagerGlobal::RemoveMessageListener;
66 using MessageManagerGlobal::RemoveWeakMessageListener;
68 // ContentProcessMessageManager
69 void GetInitialProcessData(JSContext* aCx,
70 JS::MutableHandle<JS::Value> aInitialProcessData,
71 ErrorResult& aError) {
72 if (!mMessageManager) {
73 aError.Throw(NS_ERROR_NOT_INITIALIZED);
74 return;
76 mMessageManager->GetInitialProcessData(aCx, aInitialProcessData, aError);
79 already_AddRefed<ipc::SharedMap> GetSharedData();
81 NS_FORWARD_SAFE_NSIMESSAGESENDER(mMessageManager)
83 nsIGlobalObject* GetParentObject() const {
84 return xpc::NativeGlobal(xpc::PrivilegedJunkScope());
87 virtual void LoadScript(const nsAString& aURL);
89 bool IsProcessScoped() const override { return true; }
91 void SetInitialProcessData(JS::Handle<JS::Value> aInitialData);
93 protected:
94 virtual ~ContentProcessMessageManager();
96 private:
97 bool mInitialized;
99 static bool sWasCreated;
102 } // namespace mozilla::dom
104 #endif // mozilla_dom_ContentProcessMessageManager_h