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 "nsIScriptContext.h"
19 #include "nsDocShell.h"
20 #include "nsCOMArray.h"
21 #include "nsWeakReference.h"
23 class nsFrameMessageManager
;
26 class EventChainPreVisitor
;
31 * This class implements a ContentFrameMessageManager for use by frame loaders
32 * in the parent process. It is bound to a DocShell rather than a BrowserChild,
33 * and does not use any IPC infrastructure for its message passing.
36 class InProcessBrowserChildMessageManager final
37 : public ContentFrameMessageManager
,
38 public nsMessageManagerScriptExecutor
,
39 public nsIInProcessContentFrameMessageManager
,
40 public nsSupportsWeakReference
,
41 public mozilla::dom::ipc::MessageManagerCallback
{
42 using StructuredCloneData
= mozilla::dom::ipc::StructuredCloneData
;
45 InProcessBrowserChildMessageManager(nsDocShell
* aShell
, nsIContent
* aOwner
,
46 nsFrameMessageManager
* aChrome
);
49 static already_AddRefed
<InProcessBrowserChildMessageManager
> Create(
50 nsDocShell
* aShell
, nsIContent
* aOwner
, nsFrameMessageManager
* aChrome
);
52 NS_DECL_ISUPPORTS_INHERITED
53 NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_INHERITED(
54 InProcessBrowserChildMessageManager
, DOMEventTargetHelper
)
58 virtual JSObject
* WrapObject(JSContext
* aCx
,
59 JS::Handle
<JSObject
*> aGivenProto
) override
;
61 Nullable
<WindowProxyHolder
> GetContent(ErrorResult
& aError
) override
;
62 virtual already_AddRefed
<nsIDocShell
> GetDocShell(
63 ErrorResult
& aError
) override
{
64 return do_AddRef(mDocShell
);
66 virtual already_AddRefed
<nsIEventTarget
> GetTabEventTarget() override
;
68 NS_FORWARD_SAFE_NSIMESSAGESENDER(mMessageManager
)
70 NS_DECL_NSIINPROCESSCONTENTFRAMEMESSAGEMANAGER
72 void CacheFrameLoader(nsFrameLoader
* aFrameLoader
);
75 * MessageManagerCallback methods that we override.
77 virtual bool DoSendBlockingMessage(
78 const nsAString
& aMessage
, StructuredCloneData
& aData
,
79 nsTArray
<StructuredCloneData
>* aRetVal
) override
;
80 virtual nsresult
DoSendAsyncMessage(const nsAString
& aMessage
,
81 StructuredCloneData
& aData
) override
;
83 void GetEventTargetParent(EventChainPreVisitor
& aVisitor
) override
;
85 void LoadFrameScript(const nsAString
& aURL
, bool aRunInGlobalScope
);
86 void FireUnloadEvent();
87 void DisconnectEventListeners();
89 void SendMessageToParent(const nsString
& aMessage
, bool aSync
,
90 const nsString
& aJSON
,
91 nsTArray
<nsString
>* aJSONRetVal
);
92 nsFrameMessageManager
* GetInnerManager() {
93 return static_cast<nsFrameMessageManager
*>(mMessageManager
.get());
96 void SetOwner(nsIContent
* aOwner
) { mOwner
= aOwner
; }
97 nsFrameMessageManager
* GetChromeMessageManager() {
98 return mChromeMessageManager
;
100 void SetChromeMessageManager(nsFrameMessageManager
* aParent
) {
101 mChromeMessageManager
= aParent
;
104 already_AddRefed
<nsFrameLoader
> GetFrameLoader();
107 virtual ~InProcessBrowserChildMessageManager();
109 RefPtr
<nsDocShell
> mDocShell
;
112 // Is this the message manager for an in-process <iframe mozbrowser>? This
113 // affects where events get sent, so it affects GetEventTargetParent.
114 bool mIsBrowserFrame
;
115 bool mPreventEventsEscaping
;
117 // We keep a strong reference to the frameloader after we've started
118 // teardown. This allows us to dispatch message manager messages during this
120 RefPtr
<nsFrameLoader
> mFrameLoader
;
124 nsFrameMessageManager
* mChromeMessageManager
;
128 } // namespace mozilla