Bug 1750871 - run mochitest-remote on fission everywhere. r=releng-reviewers,aki
[gecko.git] / dom / base / InProcessBrowserChildMessageManager.h
blob293a4f04a079770c4baa11f0d1f52a5de7cf5c89
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"
15 #include "nsCOMPtr.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;
25 namespace mozilla {
26 class EventChainPreVisitor;
28 namespace dom {
30 /**
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;
44 private:
45 InProcessBrowserChildMessageManager(nsDocShell* aShell, nsIContent* aOwner,
46 nsFrameMessageManager* aChrome);
48 public:
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)
56 void MarkForCC();
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);
74 /**
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();
88 void Disconnect();
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();
106 protected:
107 virtual ~InProcessBrowserChildMessageManager();
109 RefPtr<nsDocShell> mDocShell;
110 bool mLoadingScript;
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
119 // time.
120 RefPtr<nsFrameLoader> mFrameLoader;
122 public:
123 nsIContent* mOwner;
124 nsFrameMessageManager* mChromeMessageManager;
127 } // namespace dom
128 } // namespace mozilla
130 #endif