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 nsWindowRoot_h__
8 #define nsWindowRoot_h__
10 class nsIGlobalObject
;
12 #include "mozilla/Attributes.h"
13 #include "mozilla/EventListenerManager.h"
14 #include "nsIWeakReferenceUtils.h"
15 #include "nsPIWindowRoot.h"
16 #include "nsCycleCollectionParticipant.h"
17 #include "nsTHashSet.h"
18 #include "nsHashKeys.h"
20 class nsWindowRoot final
: public nsPIWindowRoot
{
22 explicit nsWindowRoot(nsPIDOMWindowOuter
* aWindow
);
24 NS_DECL_ISUPPORTS_INHERITED
25 NS_IMETHOD_(void) DeleteCycleCollectable() override
;
27 mozilla::EventListenerManager
* GetExistingListenerManager() const override
;
28 mozilla::EventListenerManager
* GetOrCreateListenerManager() override
;
30 bool ComputeDefaultWantsUntrusted(mozilla::ErrorResult
& aRv
) final
;
32 // TODO: Convert this to MOZ_CAN_RUN_SCRIPT (bug 1415230)
33 MOZ_CAN_RUN_SCRIPT_BOUNDARY
bool DispatchEvent(
34 mozilla::dom::Event
& aEvent
, mozilla::dom::CallerType aCallerType
,
35 mozilla::ErrorResult
& aRv
) override
;
37 void GetEventTargetParent(mozilla::EventChainPreVisitor
& aVisitor
) override
;
39 nsresult
PostHandleEvent(mozilla::EventChainPostVisitor
& aVisitor
) override
;
43 nsPIDOMWindowOuter
* GetWindow() override
;
45 nsresult
GetControllers(bool aForVisibleWindow
,
46 nsIControllers
** aResult
) override
;
47 nsresult
GetControllerForCommand(const char* aCommand
, bool aForVisibleWindow
,
48 nsIController
** _retval
) override
;
50 void GetEnabledDisabledCommands(
51 nsTArray
<nsCString
>& aEnabledCommands
,
52 nsTArray
<nsCString
>& aDisabledCommands
) override
;
54 already_AddRefed
<nsINode
> GetPopupNode() override
;
55 void SetPopupNode(nsINode
* aNode
) override
;
57 void SetParentTarget(mozilla::dom::EventTarget
* aTarget
) override
{
60 mozilla::dom::EventTarget
* GetParentTarget() override
{ return mParent
; }
61 nsPIDOMWindowOuter
* GetOwnerGlobalForBindingsInternal() override
;
62 nsIGlobalObject
* GetOwnerGlobal() const override
;
64 nsIGlobalObject
* GetParentObject();
66 JSObject
* WrapObject(JSContext
*, JS::Handle
<JSObject
*> aGivenProto
) override
;
68 NS_DECL_CYCLE_COLLECTION_WRAPPERCACHE_CLASS(nsWindowRoot
)
70 void AddBrowser(nsIRemoteTab
* aBrowser
) override
;
71 void RemoveBrowser(nsIRemoteTab
* aBrowser
) override
;
72 void EnumerateBrowsers(BrowserEnumerator aEnumFunc
, void* aArg
) override
;
75 virtual ~nsWindowRoot();
77 void GetEnabledDisabledCommandsForControllers(
78 nsIControllers
* aControllers
, nsTHashSet
<nsCString
>& aCommandsHandled
,
79 nsTArray
<nsCString
>& aEnabledCommands
,
80 nsTArray
<nsCString
>& aDisabledCommands
);
83 nsCOMPtr
<nsPIDOMWindowOuter
> mWindow
;
84 // We own the manager, which owns event listeners attached to us.
85 RefPtr
<mozilla::EventListenerManager
> mListenerManager
; // [Strong]
88 nsCOMPtr
<mozilla::dom::EventTarget
> mParent
;
90 // The BrowserParents that are currently registered with this top-level
92 using WeakBrowserTable
= nsTHashSet
<RefPtr
<nsIWeakReference
>>;
93 WeakBrowserTable mWeakBrowsers
;
96 extern already_AddRefed
<mozilla::dom::EventTarget
> NS_NewWindowRoot(
97 nsPIDOMWindowOuter
* aWindow
);