Line data Source code
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 :
19 : namespace mozilla {
20 : class AbstractThread;
21 : namespace dom {
22 :
23 : // Two browsing contexts are considered "related" if they are reachable from one
24 : // another through window.opener, window.parent, or window.frames. This is the
25 : // spec concept of a "unit of related browsing contexts"
26 : //
27 : // Two browsing contexts are considered "similar-origin" if they can be made to
28 : // have the same origin by setting document.domain. This is the spec concept of
29 : // a "unit of similar-origin related browsing contexts"
30 : //
31 : // A TabGroup is a set of browsing contexts which are all "related". Within a
32 : // TabGroup, browsing contexts are broken into "similar-origin" DocGroups. In
33 : // more detail, a DocGroup is actually a collection of documents, and a
34 : // TabGroup is a collection of DocGroups. A TabGroup typically will contain
35 : // (through its DocGroups) the documents from one or more tabs related by
36 : // window.opener. A DocGroup is a member of exactly one TabGroup.
37 :
38 : class DocGroup final
39 : {
40 : public:
41 : typedef nsTArray<nsIDocument*>::iterator Iterator;
42 : friend class TabGroup;
43 :
44 27 : NS_INLINE_DECL_THREADSAFE_REFCOUNTING(DocGroup)
45 :
46 : // Returns NS_ERROR_FAILURE and sets |aString| to an empty string if the TLD
47 : // service isn't available. Returns NS_OK on success, but may still set
48 : // |aString| may still be set to an empty string.
49 : static MOZ_MUST_USE nsresult
50 : GetKey(nsIPrincipal* aPrincipal, nsACString& aString);
51 :
52 793 : bool MatchesKey(const nsACString& aKey)
53 : {
54 793 : return aKey == mKey;
55 : }
56 0 : TabGroup* GetTabGroup()
57 : {
58 0 : return mTabGroup;
59 : }
60 602 : mozilla::dom::CustomElementReactionsStack* CustomElementReactionsStack()
61 : {
62 602 : MOZ_ASSERT(NS_IsMainThread());
63 602 : if (!mReactionsStack) {
64 2 : mReactionsStack = new mozilla::dom::CustomElementReactionsStack();
65 : }
66 :
67 602 : return mReactionsStack;
68 : }
69 : void RemoveDocument(nsIDocument* aWindow);
70 :
71 : // Iterators for iterating over every document within the DocGroup
72 : Iterator begin()
73 : {
74 : MOZ_ASSERT(NS_IsMainThread());
75 : return mDocuments.begin();
76 : }
77 : Iterator end()
78 : {
79 : MOZ_ASSERT(NS_IsMainThread());
80 : return mDocuments.end();
81 : }
82 :
83 : nsresult Dispatch(const char* aName,
84 : TaskCategory aCategory,
85 : already_AddRefed<nsIRunnable>&& aRunnable);
86 :
87 : nsISerialEventTarget* EventTargetFor(TaskCategory aCategory) const;
88 :
89 : AbstractThread*
90 : AbstractMainThreadFor(TaskCategory aCategory);
91 :
92 : // Ensure that it's valid to access the DocGroup at this time.
93 622 : void ValidateAccess() const
94 : {
95 622 : mTabGroup->ValidateAccess();
96 622 : }
97 :
98 : // Return a pointer that can be continually checked to see if access to this
99 : // DocGroup is valid. This pointer should live at least as long as the
100 : // DocGroup.
101 : bool* GetValidAccessPtr();
102 :
103 : private:
104 : DocGroup(TabGroup* aTabGroup, const nsACString& aKey);
105 : ~DocGroup();
106 :
107 : nsCString mKey;
108 : RefPtr<TabGroup> mTabGroup;
109 : nsTArray<nsIDocument*> mDocuments;
110 : RefPtr<mozilla::dom::CustomElementReactionsStack> mReactionsStack;
111 : };
112 :
113 : } // namespace dom
114 : } // namespace mozilla
115 :
116 : #endif // defined(DocGroup_h)
|