Source code

Revision control

Other Tools

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/. */
6
7
#ifndef mozilla_dom_CanonicalBrowsingContext_h
8
#define mozilla_dom_CanonicalBrowsingContext_h
9
10
#include "mozilla/dom/BrowsingContext.h"
11
#include "mozilla/dom/MediaControlKeysEvent.h"
12
#include "mozilla/RefPtr.h"
13
#include "mozilla/MozPromise.h"
14
#include "nsCycleCollectionParticipant.h"
15
#include "nsWrapperCache.h"
16
#include "nsTHashtable.h"
17
#include "nsHashKeys.h"
18
#include "nsISHistory.h"
19
#include "nsISHEntry.h"
20
21
namespace mozilla {
22
namespace dom {
23
24
class WindowGlobalParent;
25
class BrowserParent;
26
class MediaController;
27
class WindowGlobalParent;
28
29
// CanonicalBrowsingContext is a BrowsingContext living in the parent
30
// process, with whatever extra data that a BrowsingContext in the
31
// parent needs.
32
class CanonicalBrowsingContext final : public BrowsingContext {
33
public:
34
NS_DECL_ISUPPORTS_INHERITED
35
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(CanonicalBrowsingContext,
36
BrowsingContext)
37
38
static already_AddRefed<CanonicalBrowsingContext> Get(uint64_t aId);
39
static CanonicalBrowsingContext* Cast(BrowsingContext* aContext);
40
static const CanonicalBrowsingContext* Cast(const BrowsingContext* aContext);
41
42
bool IsOwnedByProcess(uint64_t aProcessId) const {
43
return mProcessId == aProcessId;
44
}
45
bool IsEmbeddedInProcess(uint64_t aProcessId) const {
46
return mEmbedderProcessId == aProcessId;
47
}
48
uint64_t OwnerProcessId() const { return mProcessId; }
49
uint64_t EmbedderProcessId() const { return mEmbedderProcessId; }
50
ContentParent* GetContentParent() const;
51
52
void GetCurrentRemoteType(nsAString& aRemoteType, ErrorResult& aRv) const;
53
54
void SetOwnerProcessId(uint64_t aProcessId);
55
56
void SetInFlightProcessId(uint64_t aProcessId);
57
uint64_t GetInFlightProcessId() const { return mInFlightProcessId; }
58
59
void GetWindowGlobals(nsTArray<RefPtr<WindowGlobalParent>>& aWindows);
60
61
// The current active WindowGlobal.
62
WindowGlobalParent* GetCurrentWindowGlobal() const;
63
64
already_AddRefed<nsIWidget> GetParentProcessWidgetContaining();
65
66
already_AddRefed<WindowGlobalParent> GetEmbedderWindowGlobal() const;
67
68
nsISHistory* GetSessionHistory();
69
void SetSessionHistory(nsISHistory* aSHistory) {
70
mSessionHistory = aSHistory;
71
}
72
JSObject* WrapObject(JSContext* aCx,
73
JS::Handle<JSObject*> aGivenProto) override;
74
75
// This function is used to start the autoplay media which are delayed to
76
// start. If needed, it would also notify the content browsing context which
77
// are related with the canonical browsing content tree to start delayed
78
// autoplay media.
79
void NotifyStartDelayedAutoplayMedia();
80
81
// This function is used to mute or unmute all media within a tab. It would
82
// set the media mute property for the top level window and propagate it to
83
// other top level windows in other processes.
84
void NotifyMediaMutedChanged(bool aMuted);
85
86
// Return the number of unique site origins by iterating all given BCs,
87
// including their subtrees.
88
static uint32_t CountSiteOrigins(
89
GlobalObject& aGlobal,
90
const Sequence<mozilla::OwningNonNull<BrowsingContext>>& aRoots);
91
92
// This function would update the media action for the current outer window
93
// and propogate the action to other browsing contexts in content processes.
94
void UpdateMediaControlKeysEvent(MediaControlKeysEvent aEvent);
95
96
// Triggers a load in the process
97
using BrowsingContext::LoadURI;
98
void LoadURI(const nsAString& aURI, const LoadURIOptions& aOptions,
99
ErrorResult& aError);
100
101
using RemotenessPromise = MozPromise<RefPtr<BrowserParent>, nsresult, false>;
102
RefPtr<RemotenessPromise> ChangeFrameRemoteness(const nsAString& aRemoteType,
103
uint64_t aPendingSwitchId);
104
105
// Helper version for WebIDL - resolves to the PID where the load is being
106
// resumed.
107
already_AddRefed<Promise> ChangeFrameRemoteness(const nsAString& aRemoteType,
108
uint64_t aPendingSwitchId,
109
ErrorResult& aRv);
110
111
// Return a media controller from the top-level browsing context that can
112
// control all media belonging to this browsing context tree. Return nullptr
113
// if the top-level browsing context has been discarded.
114
MediaController* GetMediaController();
115
116
bool HasHistoryEntry(nsISHEntry* aEntry) const {
117
return aEntry && (aEntry == mOSHE || aEntry == mLSHE);
118
}
119
120
void UpdateSHEntries(nsISHEntry* aNewLSHE, nsISHEntry* aNewOSHE) {
121
mLSHE = aNewLSHE;
122
mOSHE = aNewOSHE;
123
}
124
125
void SwapHistoryEntries(nsISHEntry* aOldEntry, nsISHEntry* aNewEntry) {
126
if (aOldEntry == mOSHE) {
127
mOSHE = aNewEntry;
128
}
129
130
if (aOldEntry == mLSHE) {
131
mLSHE = aNewEntry;
132
}
133
}
134
135
protected:
136
// Called when the browsing context is being discarded.
137
void CanonicalDiscard();
138
139
using Type = BrowsingContext::Type;
140
CanonicalBrowsingContext(BrowsingContext* aParent,
141
BrowsingContextGroup* aGroup,
142
uint64_t aBrowsingContextId,
143
uint64_t aOwnerProcessId,
144
uint64_t aEmbedderProcessId, Type aType,
145
FieldTuple&& aFields);
146
147
private:
148
friend class BrowsingContext;
149
150
~CanonicalBrowsingContext() = default;
151
152
class PendingRemotenessChange {
153
public:
154
NS_INLINE_DECL_REFCOUNTING(PendingRemotenessChange)
155
156
PendingRemotenessChange(CanonicalBrowsingContext* aTarget,
157
RemotenessPromise::Private* aPromise,
158
uint64_t aPendingSwitchId)
159
: mTarget(aTarget),
160
mPromise(aPromise),
161
mPendingSwitchId(aPendingSwitchId) {}
162
163
void Cancel(nsresult aRv);
164
void Complete(ContentParent* aContentParent);
165
166
private:
167
~PendingRemotenessChange();
168
void Clear();
169
170
RefPtr<CanonicalBrowsingContext> mTarget;
171
RefPtr<RemotenessPromise::Private> mPromise;
172
173
uint64_t mPendingSwitchId;
174
};
175
176
// XXX(farre): Store a ContentParent pointer here rather than mProcessId?
177
// Indicates which process owns the docshell.
178
uint64_t mProcessId;
179
180
// Indicates which process owns the embedder element.
181
uint64_t mEmbedderProcessId;
182
183
// The ID of the former owner process during an ownership change, which may
184
// have in-flight messages that assume it is still the owner.
185
uint64_t mInFlightProcessId = 0;
186
187
// The current remoteness change which is in a pending state.
188
RefPtr<PendingRemotenessChange> mPendingRemotenessChange;
189
190
nsCOMPtr<nsISHistory> mSessionHistory;
191
192
// Tab media controller is used to control all media existing in the same
193
// browsing context tree, so it would only exist in the top level browsing
194
// context.
195
RefPtr<MediaController> mTabMediaController;
196
197
// These are being mirrored from docshell
198
nsCOMPtr<nsISHEntry> mOSHE;
199
nsCOMPtr<nsISHEntry> mLSHE;
200
};
201
202
} // namespace dom
203
} // namespace mozilla
204
205
#endif // !defined(mozilla_dom_CanonicalBrowsingContext_h)