Backed out changeset 2450366cf7ca (bug 1891629) for causing win msix mochitest failures
[gecko.git] / dom / base / DocGroup.h
blobe0c944ceb5f933dd68cd408bf7e09d8e73dbbd14
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 file,
5 * You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef DocGroup_h
8 #define DocGroup_h
10 #include "nsISupportsImpl.h"
11 #include "nsIPrincipal.h"
12 #include "nsThreadUtils.h"
13 #include "nsTHashSet.h"
14 #include "nsString.h"
15 #include "mozilla/RefPtr.h"
16 #include "mozilla/dom/BrowsingContextGroup.h"
17 #include "mozilla/dom/HTMLSlotElement.h"
19 namespace mozilla {
20 class AbstractThread;
21 namespace dom {
23 class CustomElementReactionsStack;
24 class JSExecutionManager;
26 // Two browsing contexts are considered "related" if they are reachable from one
27 // another through window.opener, window.parent, or window.frames. This is the
28 // spec concept of a browsing context group.
30 // Two browsing contexts are considered "similar-origin" if they can be made to
31 // have the same origin by setting document.domain. This is the spec concept of
32 // a "unit of similar-origin related browsing contexts"
34 // A BrowsingContextGroup is a set of browsing contexts which are all
35 // "related". Within a BrowsingContextGroup, browsing contexts are
36 // broken into "similar-origin" DocGroups. A DocGroup is a member
37 // of exactly one BrowsingContextGroup.
38 class DocGroup final {
39 public:
40 typedef nsTArray<Document*>::iterator Iterator;
42 NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(DocGroup)
43 NS_DECL_CYCLE_COLLECTION_NATIVE_CLASS(DocGroup)
45 static already_AddRefed<DocGroup> Create(
46 BrowsingContextGroup* aBrowsingContextGroup, const nsACString& aKey);
48 // Returns NS_ERROR_FAILURE and sets |aString| to an empty string if the TLD
49 // service isn't available. Returns NS_OK on success, but may still set
50 // |aString| may still be set to an empty string.
51 [[nodiscard]] static nsresult GetKey(nsIPrincipal* aPrincipal,
52 bool aCrossOriginIsolated,
53 nsACString& aKey);
55 bool MatchesKey(const nsACString& aKey) { return aKey == mKey; }
57 const nsACString& GetKey() const { return mKey; }
59 JSExecutionManager* GetExecutionManager() const { return mExecutionManager; }
60 void SetExecutionManager(JSExecutionManager*);
62 BrowsingContextGroup* GetBrowsingContextGroup() const {
63 return mBrowsingContextGroup;
66 mozilla::dom::DOMArena* ArenaAllocator() { return mArena; }
68 mozilla::dom::CustomElementReactionsStack* CustomElementReactionsStack();
70 // Adding documents to a DocGroup should be done through
71 // BrowsingContextGroup::AddDocument (which in turn calls
72 // DocGroup::AddDocument).
73 void AddDocument(Document* aDocument);
75 // Removing documents from a DocGroup should be done through
76 // BrowsingContextGroup::RemoveDocument(which in turn calls
77 // DocGroup::RemoveDocument).
78 void RemoveDocument(Document* aDocument);
80 // Iterators for iterating over every document within the DocGroup
81 Iterator begin() {
82 MOZ_ASSERT(NS_IsMainThread());
83 return mDocuments.begin();
85 Iterator end() {
86 MOZ_ASSERT(NS_IsMainThread());
87 return mDocuments.end();
90 // Return a pointer that can be continually checked to see if access to this
91 // DocGroup is valid. This pointer should live at least as long as the
92 // DocGroup.
93 bool* GetValidAccessPtr();
95 // Append aSlot to the list of signal slot list, and queue a mutation observer
96 // microtask.
97 void SignalSlotChange(HTMLSlotElement& aSlot);
99 nsTArray<RefPtr<HTMLSlotElement>> MoveSignalSlotList();
101 // List of DocGroups that has non-empty signal slot list.
102 static AutoTArray<RefPtr<DocGroup>, 2>* sPendingDocGroups;
104 // Returns true if any of its documents are active but not in the bfcache.
105 bool IsActive() const;
107 const nsID& AgentClusterId() const { return mAgentClusterId; }
109 bool IsEmpty() const { return mDocuments.IsEmpty(); }
111 private:
112 DocGroup(BrowsingContextGroup* aBrowsingContextGroup, const nsACString& aKey);
114 ~DocGroup();
116 nsCString mKey;
117 nsTArray<Document*> mDocuments;
118 RefPtr<mozilla::dom::CustomElementReactionsStack> mReactionsStack;
119 nsTArray<RefPtr<HTMLSlotElement>> mSignalSlotList;
120 RefPtr<BrowsingContextGroup> mBrowsingContextGroup;
122 // non-null if the JS execution for this docgroup is regulated with regards
123 // to worker threads. This should only be used when we are forcing serialized
124 // SAB access.
125 RefPtr<JSExecutionManager> mExecutionManager;
127 // Each DocGroup has a persisted agent cluster ID.
128 const nsID mAgentClusterId;
130 RefPtr<mozilla::dom::DOMArena> mArena;
133 } // namespace dom
134 } // namespace mozilla
136 #endif // defined(DocGroup_h)