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_CYCLE_COLLECTING_ISUPPORTS
26 mozilla::EventListenerManager
* GetExistingListenerManager() const override
;
27 mozilla::EventListenerManager
* GetOrCreateListenerManager() override
;
29 bool ComputeDefaultWantsUntrusted(mozilla::ErrorResult
& aRv
) final
;
31 // TODO: Convert this to MOZ_CAN_RUN_SCRIPT (bug 1415230)
32 MOZ_CAN_RUN_SCRIPT_BOUNDARY
bool DispatchEvent(
33 mozilla::dom::Event
& aEvent
, mozilla::dom::CallerType aCallerType
,
34 mozilla::ErrorResult
& aRv
) override
;
36 void GetEventTargetParent(mozilla::EventChainPreVisitor
& aVisitor
) override
;
38 nsresult
PostHandleEvent(mozilla::EventChainPostVisitor
& aVisitor
) override
;
42 nsPIDOMWindowOuter
* GetWindow() override
;
44 nsresult
GetControllers(bool aForVisibleWindow
,
45 nsIControllers
** aResult
) override
;
46 nsresult
GetControllerForCommand(const char* aCommand
, bool aForVisibleWindow
,
47 nsIController
** _retval
) override
;
49 void GetEnabledDisabledCommands(
50 nsTArray
<nsCString
>& aEnabledCommands
,
51 nsTArray
<nsCString
>& aDisabledCommands
) override
;
53 already_AddRefed
<nsINode
> GetPopupNode() override
;
54 void SetPopupNode(nsINode
* aNode
) override
;
56 void SetParentTarget(mozilla::dom::EventTarget
* aTarget
) override
{
59 mozilla::dom::EventTarget
* GetParentTarget() override
{ return mParent
; }
60 nsPIDOMWindowOuter
* GetOwnerGlobalForBindingsInternal() override
;
61 nsIGlobalObject
* GetOwnerGlobal() const override
;
63 nsIGlobalObject
* GetParentObject();
65 JSObject
* WrapObject(JSContext
*, JS::Handle
<JSObject
*> aGivenProto
) override
;
67 NS_DECL_CYCLE_COLLECTION_WRAPPERCACHE_CLASS(nsWindowRoot
)
69 void AddBrowser(nsIRemoteTab
* aBrowser
) override
;
70 void RemoveBrowser(nsIRemoteTab
* aBrowser
) override
;
71 void EnumerateBrowsers(BrowserEnumerator aEnumFunc
, void* aArg
) override
;
74 virtual ~nsWindowRoot();
76 void GetEnabledDisabledCommandsForControllers(
77 nsIControllers
* aControllers
, nsTHashSet
<nsCString
>& aCommandsHandled
,
78 nsTArray
<nsCString
>& aEnabledCommands
,
79 nsTArray
<nsCString
>& aDisabledCommands
);
82 nsCOMPtr
<nsPIDOMWindowOuter
> mWindow
;
83 // We own the manager, which owns event listeners attached to us.
84 RefPtr
<mozilla::EventListenerManager
> mListenerManager
; // [Strong]
87 nsCOMPtr
<mozilla::dom::EventTarget
> mParent
;
89 // The BrowserParents that are currently registered with this top-level
91 using WeakBrowserTable
= nsTHashSet
<RefPtr
<nsIWeakReference
>>;
92 WeakBrowserTable mWeakBrowsers
;
95 extern already_AddRefed
<mozilla::dom::EventTarget
> NS_NewWindowRoot(
96 nsPIDOMWindowOuter
* aWindow
);