/work/obj-fuzz/dist/include/mozilla/dom/DocGroup.h
Line | Count | Source (jump to first uncovered line) |
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/. */ |
6 | | |
7 | | #ifndef DocGroup_h |
8 | | #define DocGroup_h |
9 | | |
10 | | #include "nsISupportsImpl.h" |
11 | | #include "nsIPrincipal.h" |
12 | | #include "nsTHashtable.h" |
13 | | #include "nsString.h" |
14 | | |
15 | | #include "mozilla/dom/TabGroup.h" |
16 | | #include "mozilla/RefPtr.h" |
17 | | #include "mozilla/dom/CustomElementRegistry.h" |
18 | | #include "mozilla/dom/HTMLSlotElement.h" |
19 | | #include "mozilla/PerformanceCounter.h" |
20 | | |
21 | | |
22 | | namespace mozilla { |
23 | | class AbstractThread; |
24 | | namespace dom { |
25 | | |
26 | | class PerformanceInfo; |
27 | | |
28 | | // Two browsing contexts are considered "related" if they are reachable from one |
29 | | // another through window.opener, window.parent, or window.frames. This is the |
30 | | // spec concept of a "unit of related browsing contexts" |
31 | | // |
32 | | // Two browsing contexts are considered "similar-origin" if they can be made to |
33 | | // have the same origin by setting document.domain. This is the spec concept of |
34 | | // a "unit of similar-origin related browsing contexts" |
35 | | // |
36 | | // A TabGroup is a set of browsing contexts which are all "related". Within a |
37 | | // TabGroup, browsing contexts are broken into "similar-origin" DocGroups. In |
38 | | // more detail, a DocGroup is actually a collection of documents, and a |
39 | | // TabGroup is a collection of DocGroups. A TabGroup typically will contain |
40 | | // (through its DocGroups) the documents from one or more tabs related by |
41 | | // window.opener. A DocGroup is a member of exactly one TabGroup. |
42 | | |
43 | | class DocGroup final |
44 | | { |
45 | | public: |
46 | | typedef nsTArray<nsIDocument*>::iterator Iterator; |
47 | | friend class TabGroup; |
48 | | |
49 | | NS_INLINE_DECL_THREADSAFE_REFCOUNTING(DocGroup) |
50 | | |
51 | | // Returns NS_ERROR_FAILURE and sets |aString| to an empty string if the TLD |
52 | | // service isn't available. Returns NS_OK on success, but may still set |
53 | | // |aString| may still be set to an empty string. |
54 | | static MOZ_MUST_USE nsresult |
55 | | GetKey(nsIPrincipal* aPrincipal, nsACString& aString); |
56 | | |
57 | | bool MatchesKey(const nsACString& aKey) |
58 | 0 | { |
59 | 0 | return aKey == mKey; |
60 | 0 | } |
61 | | |
62 | | PerformanceCounter* GetPerformanceCounter() |
63 | 0 | { |
64 | 0 | return mPerformanceCounter; |
65 | 0 | } |
66 | | |
67 | | PerformanceInfo |
68 | | ReportPerformanceInfo(); |
69 | | |
70 | | TabGroup* GetTabGroup() |
71 | 0 | { |
72 | 0 | return mTabGroup; |
73 | 0 | } |
74 | | mozilla::dom::CustomElementReactionsStack* CustomElementReactionsStack() |
75 | 0 | { |
76 | 0 | MOZ_ASSERT(NS_IsMainThread()); |
77 | 0 | if (!mReactionsStack) { |
78 | 0 | mReactionsStack = new mozilla::dom::CustomElementReactionsStack(); |
79 | 0 | } |
80 | 0 |
|
81 | 0 | return mReactionsStack; |
82 | 0 | } |
83 | | void RemoveDocument(nsIDocument* aWindow); |
84 | | |
85 | | // Iterators for iterating over every document within the DocGroup |
86 | | Iterator begin() |
87 | 0 | { |
88 | 0 | MOZ_ASSERT(NS_IsMainThread()); |
89 | 0 | return mDocuments.begin(); |
90 | 0 | } |
91 | | Iterator end() |
92 | 0 | { |
93 | 0 | MOZ_ASSERT(NS_IsMainThread()); |
94 | 0 | return mDocuments.end(); |
95 | 0 | } |
96 | | |
97 | | nsresult Dispatch(TaskCategory aCategory, |
98 | | already_AddRefed<nsIRunnable>&& aRunnable); |
99 | | |
100 | | nsISerialEventTarget* EventTargetFor(TaskCategory aCategory) const; |
101 | | |
102 | | AbstractThread* |
103 | | AbstractMainThreadFor(TaskCategory aCategory); |
104 | | |
105 | | // Ensure that it's valid to access the DocGroup at this time. |
106 | | void ValidateAccess() const |
107 | 0 | { |
108 | 0 | mTabGroup->ValidateAccess(); |
109 | 0 | } |
110 | | |
111 | | // Return a pointer that can be continually checked to see if access to this |
112 | | // DocGroup is valid. This pointer should live at least as long as the |
113 | | // DocGroup. |
114 | | bool* GetValidAccessPtr(); |
115 | | |
116 | | // Append aSlot to the list of signal slot list, and queue a mutation observer |
117 | | // microtask. |
118 | | void SignalSlotChange(HTMLSlotElement& aSlot); |
119 | | |
120 | | void MoveSignalSlotListTo(nsTArray<RefPtr<HTMLSlotElement>>& aDest); |
121 | | |
122 | | // List of DocGroups that has non-empty signal slot list. |
123 | | static AutoTArray<RefPtr<DocGroup>, 2>* sPendingDocGroups; |
124 | | |
125 | | // Returns true if any of its documents are active but not in the bfcache. |
126 | | bool IsActive() const; |
127 | | |
128 | | private: |
129 | | DocGroup(TabGroup* aTabGroup, const nsACString& aKey); |
130 | | ~DocGroup(); |
131 | | |
132 | | nsCString mKey; |
133 | | RefPtr<TabGroup> mTabGroup; |
134 | | nsTArray<nsIDocument*> mDocuments; |
135 | | RefPtr<mozilla::dom::CustomElementReactionsStack> mReactionsStack; |
136 | | nsTArray<RefPtr<HTMLSlotElement>> mSignalSlotList; |
137 | | // This pointer will be null if dom.performance.enable_scheduler_timing is |
138 | | // false (default value) |
139 | | RefPtr<mozilla::PerformanceCounter> mPerformanceCounter; |
140 | | }; |
141 | | |
142 | | } // namespace dom |
143 | | } // namespace mozilla |
144 | | |
145 | | #endif // defined(DocGroup_h) |