Bug 1812499 [wpt PR 38184] - Simplify handling of name-to-subdir mapping in canvas...
[gecko.git] / dom / base / nsWindowRoot.h
blob7fb56acd189358efde5d9ee4381ac373ba72c6ed
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 {
21 public:
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;
40 // nsPIWindowRoot
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 {
57 mParent = aTarget;
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;
73 protected:
74 virtual ~nsWindowRoot();
76 void GetEnabledDisabledCommandsForControllers(
77 nsIControllers* aControllers, nsTHashSet<nsCString>& aCommandsHandled,
78 nsTArray<nsCString>& aEnabledCommands,
79 nsTArray<nsCString>& aDisabledCommands);
81 // Members
82 nsCOMPtr<nsPIDOMWindowOuter> mWindow;
83 // We own the manager, which owns event listeners attached to us.
84 RefPtr<mozilla::EventListenerManager> mListenerManager; // [Strong]
85 nsWeakPtr mPopupNode;
87 nsCOMPtr<mozilla::dom::EventTarget> mParent;
89 // The BrowserParents that are currently registered with this top-level
90 // window.
91 using WeakBrowserTable = nsTHashSet<RefPtr<nsIWeakReference>>;
92 WeakBrowserTable mWeakBrowsers;
95 extern already_AddRefed<mozilla::dom::EventTarget> NS_NewWindowRoot(
96 nsPIDOMWindowOuter* aWindow);
98 #endif