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"
14 #include "nsIScriptContext.h"
15 #include "nsIScriptContext.h"
16 #include "nsServiceManagerUtils.h"
17 #include "nsWeakReference.h"
18 #include "nsWrapperCache.h"
19 #include "xpcpublic.h"
21 class nsFrameMessageManager
;
31 * This class implements a singleton process message manager for content
32 * processes. Each child process has exactly one instance of this class, which
33 * hosts the process's process scripts, and may exchange messages with its
34 * corresponding ParentProcessMessageManager on the parent side.
37 class ContentProcessMessageManager
: public nsIMessageSender
,
38 public nsMessageManagerScriptExecutor
,
39 public nsSupportsWeakReference
,
40 public ipc::MessageManagerCallback
,
41 public MessageManagerGlobal
,
42 public nsWrapperCache
{
44 explicit ContentProcessMessageManager(nsFrameMessageManager
* aMessageManager
);
46 using ipc::MessageManagerCallback::GetProcessMessageManager
;
47 using MessageManagerGlobal::GetProcessMessageManager
;
51 static ContentProcessMessageManager
* Get();
52 static bool WasCreated();
54 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
55 NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_AMBIGUOUS(
56 ContentProcessMessageManager
, nsIMessageSender
)
60 virtual JSObject
* WrapObject(JSContext
* aCx
,
61 JS::Handle
<JSObject
*> aGivenProto
) override
;
63 JSObject
* GetOrCreateWrapper();
65 using MessageManagerGlobal::AddMessageListener
;
66 using MessageManagerGlobal::AddWeakMessageListener
;
67 using MessageManagerGlobal::RemoveMessageListener
;
68 using MessageManagerGlobal::RemoveWeakMessageListener
;
70 // ContentProcessMessageManager
71 void GetInitialProcessData(JSContext
* aCx
,
72 JS::MutableHandle
<JS::Value
> aInitialProcessData
,
73 ErrorResult
& aError
) {
74 if (!mMessageManager
) {
75 aError
.Throw(NS_ERROR_NOT_INITIALIZED
);
78 mMessageManager
->GetInitialProcessData(aCx
, aInitialProcessData
, aError
);
81 already_AddRefed
<ipc::SharedMap
> GetSharedData();
83 NS_FORWARD_SAFE_NSIMESSAGESENDER(mMessageManager
)
85 nsIGlobalObject
* GetParentObject() const {
86 return xpc::NativeGlobal(xpc::PrivilegedJunkScope());
89 virtual void LoadScript(const nsAString
& aURL
);
91 bool IsProcessScoped() const override
{ return true; }
93 void SetInitialProcessData(JS::HandleValue aInitialData
);
96 virtual ~ContentProcessMessageManager();
101 static bool sWasCreated
;
105 } // namespace mozilla
107 #endif // mozilla_dom_ContentProcessMessageManager_h