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 nsInProcessBrowserChildGlobal_h
8 #define nsInProcessBrowserChildGlobal_h
10 #include "mozilla/Attributes.h"
11 #include "mozilla/DOMEventTargetHelper.h"
12 #include "mozilla/RefPtr.h"
13 #include "mozilla/dom/ContentFrameMessageManager.h"
14 #include "mozilla/dom/MessageManagerCallback.h"
16 #include "nsIScriptContext.h"
17 #include "nsIScriptObjectPrincipal.h"
18 #include "nsDocShell.h"
19 #include "nsCOMArray.h"
20 #include "nsWeakReference.h"
22 class nsFrameMessageManager
;
25 class EventChainPreVisitor
;
30 * This class implements a ContentFrameMessageManager for use by frame loaders
31 * in the parent process. It is bound to a DocShell rather than a BrowserChild,
32 * and does not use any IPC infrastructure for its message passing.
35 class InProcessBrowserChildMessageManager final
36 : public ContentFrameMessageManager
,
37 public nsMessageManagerScriptExecutor
,
38 public nsIInProcessContentFrameMessageManager
,
39 public nsSupportsWeakReference
,
40 public mozilla::dom::ipc::MessageManagerCallback
{
41 using StructuredCloneData
= mozilla::dom::ipc::StructuredCloneData
;
44 InProcessBrowserChildMessageManager(nsDocShell
* aShell
, nsIContent
* aOwner
,
45 nsFrameMessageManager
* aChrome
);
48 static already_AddRefed
<InProcessBrowserChildMessageManager
> Create(
49 nsDocShell
* aShell
, nsIContent
* aOwner
, nsFrameMessageManager
* aChrome
);
51 NS_DECL_ISUPPORTS_INHERITED
52 NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_INHERITED(
53 InProcessBrowserChildMessageManager
, DOMEventTargetHelper
)
57 virtual JSObject
* WrapObject(JSContext
* aCx
,
58 JS::Handle
<JSObject
*> aGivenProto
) override
;
60 Nullable
<WindowProxyHolder
> GetContent(ErrorResult
& aError
) override
;
61 virtual already_AddRefed
<nsIDocShell
> GetDocShell(
62 ErrorResult
& aError
) override
{
63 return do_AddRef(mDocShell
);
65 virtual already_AddRefed
<nsIEventTarget
> GetTabEventTarget() override
;
67 NS_FORWARD_SAFE_NSIMESSAGESENDER(mMessageManager
)
69 NS_DECL_NSIINPROCESSCONTENTFRAMEMESSAGEMANAGER
71 void CacheFrameLoader(nsFrameLoader
* aFrameLoader
);
74 * MessageManagerCallback methods that we override.
76 virtual bool DoSendBlockingMessage(
77 const nsAString
& aMessage
, StructuredCloneData
& aData
,
78 nsTArray
<StructuredCloneData
>* aRetVal
) override
;
79 virtual nsresult
DoSendAsyncMessage(const nsAString
& aMessage
,
80 StructuredCloneData
& aData
) override
;
82 void GetEventTargetParent(EventChainPreVisitor
& aVisitor
) override
;
84 void LoadFrameScript(const nsAString
& aURL
, bool aRunInGlobalScope
);
85 void FireUnloadEvent();
86 void DisconnectEventListeners();
88 void SendMessageToParent(const nsString
& aMessage
, bool aSync
,
89 const nsString
& aJSON
,
90 nsTArray
<nsString
>* aJSONRetVal
);
91 nsFrameMessageManager
* GetInnerManager() {
92 return static_cast<nsFrameMessageManager
*>(mMessageManager
.get());
95 void SetOwner(nsIContent
* aOwner
) { mOwner
= aOwner
; }
96 nsFrameMessageManager
* GetChromeMessageManager() {
97 return mChromeMessageManager
;
99 void SetChromeMessageManager(nsFrameMessageManager
* aParent
) {
100 mChromeMessageManager
= aParent
;
103 already_AddRefed
<nsFrameLoader
> GetFrameLoader();
106 virtual ~InProcessBrowserChildMessageManager();
108 RefPtr
<nsDocShell
> mDocShell
;
111 bool mPreventEventsEscaping
;
113 // We keep a strong reference to the frameloader after we've started
114 // teardown. This allows us to dispatch message manager messages during this
116 RefPtr
<nsFrameLoader
> mFrameLoader
;
120 nsFrameMessageManager
* mChromeMessageManager
;
124 } // namespace mozilla