Bug 1925561 - Use a quicker radius calculation for ArcParams. r=aosmond
[gecko.git] / dom / ipc / WindowGlobalParent.h
blob1a1bda69a8e14b9fd0715c81a3c6db2c4f77c4cd
1 /* -*- Mode: C++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 8 -*- */
2 /* vim: set sw=2 ts=8 et tw=80 ft=cpp : */
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 mozilla_dom_WindowGlobalParent_h
8 #define mozilla_dom_WindowGlobalParent_h
10 #include "mozilla/ContentBlockingLog.h"
11 #include "mozilla/ContentBlockingNotifier.h"
12 #include "mozilla/Maybe.h"
13 #include "mozilla/RefPtr.h"
14 #include "mozilla/UniquePtr.h"
15 #include "mozilla/dom/ClientInfo.h"
16 #include "mozilla/dom/ClientIPCTypes.h"
17 #include "mozilla/dom/DOMRect.h"
18 #include "mozilla/dom/PWindowGlobalParent.h"
19 #include "mozilla/dom/WindowContext.h"
20 #include "mozilla/dom/WindowGlobalActorsBinding.h"
21 #include "nsTHashMap.h"
22 #include "nsRefPtrHashtable.h"
23 #include "nsWrapperCache.h"
24 #include "nsISupports.h"
25 #include "nsIDOMProcessParent.h"
26 #include "mozilla/dom/WindowGlobalActor.h"
27 #include "mozilla/dom/CanonicalBrowsingContext.h"
28 #include "mozilla/net/CookieJarSettings.h"
30 class nsIPrincipal;
31 class nsIURI;
32 class nsFrameLoader;
34 namespace mozilla {
36 namespace gfx {
37 class CrossProcessPaint;
38 } // namespace gfx
40 namespace dom {
42 class BrowserParent;
43 class WindowGlobalChild;
44 class JSWindowActorParent;
45 class JSActorMessageMeta;
46 struct PageUseCounters;
47 class WindowSessionStoreState;
48 struct WindowSessionStoreUpdate;
49 class SSCacheQueryResult;
51 /**
52 * A handle in the parent process to a specific nsGlobalWindowInner object.
54 class WindowGlobalParent final : public WindowContext,
55 public WindowGlobalActor,
56 public PWindowGlobalParent {
57 friend class gfx::CrossProcessPaint;
58 friend class PWindowGlobalParent;
60 public:
61 NS_DECL_ISUPPORTS_INHERITED
62 NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_INHERITED(WindowGlobalParent,
63 WindowContext)
65 static already_AddRefed<WindowGlobalParent> GetByInnerWindowId(
66 uint64_t aInnerWindowId);
68 static already_AddRefed<WindowGlobalParent> GetByInnerWindowId(
69 const GlobalObject& aGlobal, uint64_t aInnerWindowId) {
70 return GetByInnerWindowId(aInnerWindowId);
73 // The same as the corresponding methods on `WindowContext`, except that the
74 // return types are already cast to their parent-process type variants, such
75 // as `WindowGlobalParent` or `CanonicalBrowsingContext`.
76 WindowGlobalParent* GetParentWindowContext() {
77 return static_cast<WindowGlobalParent*>(
78 WindowContext::GetParentWindowContext());
80 WindowGlobalParent* TopWindowContext() {
81 return static_cast<WindowGlobalParent*>(WindowContext::TopWindowContext());
83 CanonicalBrowsingContext* GetBrowsingContext() const {
84 return CanonicalBrowsingContext::Cast(WindowContext::GetBrowsingContext());
87 Element* GetRootOwnerElement();
89 // Has this actor been shut down
90 bool IsClosed() { return !CanSend(); }
92 // Get the other side of this actor if it is an in-process actor. Returns
93 // |nullptr| if the actor has been torn down, or is not in-process.
94 already_AddRefed<WindowGlobalChild> GetChildActor();
96 // Get a JS actor object by name.
97 already_AddRefed<JSWindowActorParent> GetActor(JSContext* aCx,
98 const nsACString& aName,
99 ErrorResult& aRv);
100 already_AddRefed<JSWindowActorParent> GetExistingActor(
101 const nsACString& aName);
103 // Get this actor's manager if it is not an in-process actor. Returns
104 // |nullptr| if the actor has been torn down, or is in-process.
105 BrowserParent* GetBrowserParent();
107 ContentParent* GetContentParent();
109 // The principal of this WindowGlobal. This value will not change over the
110 // lifetime of the WindowGlobal object, even to reflect changes in
111 // |document.domain|.
112 nsIPrincipal* DocumentPrincipal() { return mDocumentPrincipal; }
114 nsIPrincipal* DocumentStoragePrincipal() { return mDocumentStoragePrincipal; }
116 // The BrowsingContext which this WindowGlobal has been loaded into.
117 // FIXME: It's quite awkward that this method has a slightly different name
118 // than the one on WindowContext.
119 CanonicalBrowsingContext* BrowsingContext() override {
120 return GetBrowsingContext();
123 // Get the root nsFrameLoader object for the tree of BrowsingContext nodes
124 // which this WindowGlobal is a part of. This will be the nsFrameLoader
125 // holding the BrowserParent for remote tabs, and the root content frameloader
126 // for non-remote tabs.
127 already_AddRefed<nsFrameLoader> GetRootFrameLoader();
129 // The current URI which loaded in the document.
130 nsIURI* GetDocumentURI() override { return mDocumentURI; }
132 void GetDocumentTitle(nsAString& aTitle) const {
133 aTitle = mDocumentTitle.valueOr(nsString());
136 nsIPrincipal* GetContentBlockingAllowListPrincipal() const {
137 return mDocContentBlockingAllowListPrincipal;
140 Maybe<ClientInfo> GetClientInfo() { return mClientInfo; }
142 uint64_t ContentParentId();
144 int32_t OsPid();
146 bool IsCurrentGlobal();
148 bool IsActiveInTab();
150 bool IsProcessRoot();
152 uint32_t ContentBlockingEvents();
154 void GetContentBlockingLog(nsAString& aLog);
156 bool IsInitialDocument() {
157 return mIsInitialDocument.isSome() && mIsInitialDocument.value();
160 already_AddRefed<mozilla::dom::Promise> PermitUnload(
161 PermitUnloadAction aAction, uint32_t aTimeout, mozilla::ErrorResult& aRv);
163 void PermitUnload(std::function<void(bool)>&& aResolver);
165 already_AddRefed<mozilla::dom::Promise> DrawSnapshot(
166 const DOMRect* aRect, double aScale, const nsACString& aBackgroundColor,
167 bool aResetScrollPosition, mozilla::ErrorResult& aRv);
169 static already_AddRefed<WindowGlobalParent> CreateDisconnected(
170 const WindowGlobalInit& aInit);
172 // Initialize the mFrameLoader fields for a created WindowGlobalParent. Must
173 // be called after setting the Manager actor.
174 void Init() final;
176 nsIGlobalObject* GetParentObject();
177 JSObject* WrapObject(JSContext* aCx,
178 JS::Handle<JSObject*> aGivenProto) override;
180 void NotifyContentBlockingEvent(
181 uint32_t aEvent, nsIRequest* aRequest, bool aBlocked,
182 const nsACString& aTrackingOrigin,
183 const nsTArray<nsCString>& aTrackingFullHashes,
184 const Maybe<
185 ContentBlockingNotifier::StorageAccessPermissionGrantedReason>&
186 aReason,
187 const Maybe<ContentBlockingNotifier::CanvasFingerprinter>&
188 aCanvasFingerprinter,
189 const Maybe<bool> aCanvasFingerprinterKnownText);
191 ContentBlockingLog* GetContentBlockingLog() { return &mContentBlockingLog; }
193 nsIDOMProcessParent* GetDomProcess();
195 nsICookieJarSettings* CookieJarSettings() { return mCookieJarSettings; }
197 nsICookieJarSettings* GetCookieJarSettings() const {
198 return mCookieJarSettings;
201 bool DocumentHasLoaded() { return mDocumentHasLoaded; }
203 bool DocumentHasUserInteracted() { return mDocumentHasUserInteracted; }
205 uint32_t SandboxFlags() { return mSandboxFlags; }
207 bool GetDocumentBlockAllMixedContent() { return mBlockAllMixedContent; }
209 bool GetDocumentUpgradeInsecureRequests() { return mUpgradeInsecureRequests; }
211 void DidBecomeCurrentWindowGlobal(bool aCurrent);
213 uint32_t HttpsOnlyStatus() { return mHttpsOnlyStatus; }
215 void AddSecurityState(uint32_t aStateFlags);
216 uint32_t GetSecurityFlags() { return mSecurityState; }
218 nsITransportSecurityInfo* GetSecurityInfo() { return mSecurityInfo; }
220 const nsACString& GetRemoteType() override;
222 void NotifySessionStoreUpdatesComplete(Element* aEmbedder);
224 Maybe<uint64_t> GetSingleChannelId() { return mSingleChannelId; }
226 uint32_t GetBFCacheStatus() { return mBFCacheStatus; }
228 bool HasActivePeerConnections();
230 bool Fullscreen() { return mFullscreen; }
231 void SetFullscreen(bool aFullscreen) { mFullscreen = aFullscreen; }
233 void ExitTopChromeDocumentFullscreen();
235 void SetShouldReportHasBlockedOpaqueResponse(
236 nsContentPolicyType aContentPolicy);
238 protected:
239 already_AddRefed<JSActor> InitJSActor(JS::Handle<JSObject*> aMaybeActor,
240 const nsACString& aName,
241 ErrorResult& aRv) override;
242 mozilla::ipc::IProtocol* AsNativeActor() override { return this; }
244 // IPC messages
245 mozilla::ipc::IPCResult RecvLoadURI(
246 const MaybeDiscarded<dom::BrowsingContext>& aTargetBC,
247 nsDocShellLoadState* aLoadState, bool aSetNavigating);
248 mozilla::ipc::IPCResult RecvInternalLoad(nsDocShellLoadState* aLoadState);
249 mozilla::ipc::IPCResult RecvUpdateDocumentURI(NotNull<nsIURI*> aURI);
250 mozilla::ipc::IPCResult RecvUpdateDocumentPrincipal(
251 nsIPrincipal* aNewDocumentPrincipal,
252 nsIPrincipal* aNewDocumentStoragePrincipal);
253 mozilla::ipc::IPCResult RecvUpdateDocumentHasLoaded(bool aDocumentHasLoaded);
254 mozilla::ipc::IPCResult RecvUpdateDocumentHasUserInteracted(
255 bool aDocumentHasUserInteracted);
256 mozilla::ipc::IPCResult RecvUpdateSandboxFlags(uint32_t aSandboxFlags);
257 mozilla::ipc::IPCResult RecvUpdateDocumentCspSettings(
258 bool aBlockAllMixedContent, bool aUpgradeInsecureRequests);
259 mozilla::ipc::IPCResult RecvUpdateDocumentTitle(const nsString& aTitle);
260 mozilla::ipc::IPCResult RecvUpdateHttpsOnlyStatus(uint32_t aHttpsOnlyStatus);
261 mozilla::ipc::IPCResult RecvSetIsInitialDocument(bool aIsInitialDocument) {
262 if (aIsInitialDocument && mIsInitialDocument.isSome() &&
263 (mIsInitialDocument.value() != aIsInitialDocument)) {
264 return IPC_FAIL_NO_REASON(this);
267 mIsInitialDocument = Some(aIsInitialDocument);
268 return IPC_OK();
270 mozilla::ipc::IPCResult RecvUpdateDocumentSecurityInfo(
271 nsITransportSecurityInfo* aSecurityInfo);
272 mozilla::ipc::IPCResult RecvSetClientInfo(
273 const IPCClientInfo& aIPCClientInfo);
274 mozilla::ipc::IPCResult RecvDestroy();
275 mozilla::ipc::IPCResult RecvRawMessage(
276 const JSActorMessageMeta& aMeta, const Maybe<ClonedMessageData>& aData,
277 const Maybe<ClonedMessageData>& aStack);
279 mozilla::ipc::IPCResult RecvGetContentBlockingEvents(
280 GetContentBlockingEventsResolver&& aResolver);
281 mozilla::ipc::IPCResult RecvUpdateCookieJarSettings(
282 const CookieJarSettingsArgs& aCookieJarSettingsArgs);
284 void ActorDestroy(ActorDestroyReason aWhy) override;
286 void DrawSnapshotInternal(gfx::CrossProcessPaint* aPaint,
287 const Maybe<IntRect>& aRect, float aScale,
288 nscolor aBackgroundColor, uint32_t aFlags);
290 // WebShare API - try to share
291 mozilla::ipc::IPCResult RecvShare(IPCWebShareData&& aData,
292 ShareResolver&& aResolver);
294 mozilla::ipc::IPCResult RecvCheckPermitUnload(
295 bool aHasInProcessBlocker, XPCOMPermitUnloadAction aAction,
296 CheckPermitUnloadResolver&& aResolver);
298 mozilla::ipc::IPCResult RecvExpectPageUseCounters(
299 const MaybeDiscarded<dom::WindowContext>& aTop);
300 mozilla::ipc::IPCResult RecvAccumulatePageUseCounters(
301 const UseCounters& aUseCounters);
303 mozilla::ipc::IPCResult RecvRequestRestoreTabContent();
305 mozilla::ipc::IPCResult RecvUpdateBFCacheStatus(const uint32_t& aOnFlags,
306 const uint32_t& aOffFlags);
308 // This IPC method is to notify the parent process that the caller process
309 // creates the first active peer connection (aIsAdded = true) or closes the
310 // last active peer connection (aIsAdded = false).
311 mozilla::ipc::IPCResult RecvUpdateActivePeerConnectionStatus(bool aIsAdded);
313 public:
314 mozilla::ipc::IPCResult RecvSetSingleChannelId(
315 const Maybe<uint64_t>& aSingleChannelId);
317 mozilla::ipc::IPCResult RecvSetDocumentDomain(NotNull<nsIURI*> aDomain);
319 mozilla::ipc::IPCResult RecvReloadWithHttpsOnlyException();
321 mozilla::ipc::IPCResult RecvGetIdentityCredential(
322 const IdentityCredentialRequestOptions& aOptions,
323 const CredentialMediationRequirement& aMediationRequirement,
324 const GetIdentityCredentialResolver& aResolver);
325 mozilla::ipc::IPCResult RecvStoreIdentityCredential(
326 const IPCIdentityCredential& aCredential,
327 const StoreIdentityCredentialResolver& aResolver);
328 mozilla::ipc::IPCResult RecvPreventSilentAccess(
329 const PreventSilentAccessResolver& aResolver);
331 mozilla::ipc::IPCResult RecvGetStorageAccessPermission(
332 bool aIncludeIdentityCredential,
333 GetStorageAccessPermissionResolver&& aResolve);
335 mozilla::ipc::IPCResult RecvSetCookies(
336 const nsCString& aBaseDomain, const OriginAttributes& aOriginAttributes,
337 nsIURI* aHost, bool aFromHttp, bool aIsThirdParty,
338 const nsTArray<CookieStruct>& aCookies);
340 mozilla::ipc::IPCResult RecvOnInitialStorageAccess();
342 mozilla::ipc::IPCResult RecvRecordUserActivationForBTP();
344 private:
345 WindowGlobalParent(CanonicalBrowsingContext* aBrowsingContext,
346 uint64_t aInnerWindowId, uint64_t aOuterWindowId,
347 FieldValues&& aInit);
349 ~WindowGlobalParent();
351 bool ShouldTrackSiteOriginTelemetry();
352 void FinishAccumulatingPageUseCounters();
354 // Returns failure if the new storage principal cannot be validated
355 // against the current document principle.
356 nsresult SetDocumentStoragePrincipal(
357 nsIPrincipal* aNewDocumentStoragePrincipal);
359 // NOTE: Neither this document principal nor the document storage
360 // principal doesn't reflect possible |document.domain| mutations
361 // which may have been made in the actual document.
362 nsCOMPtr<nsIPrincipal> mDocumentPrincipal;
363 nsCOMPtr<nsIPrincipal> mDocumentStoragePrincipal;
365 // The principal to use for the content blocking allow list.
366 nsCOMPtr<nsIPrincipal> mDocContentBlockingAllowListPrincipal;
368 nsCOMPtr<nsIURI> mDocumentURI;
369 Maybe<nsString> mDocumentTitle;
371 Maybe<bool> mIsInitialDocument;
373 // True if this window has a "beforeunload" event listener.
374 bool mHasBeforeUnload;
376 // The log of all content blocking actions taken on the document related to
377 // this WindowGlobalParent. This is only stored on top-level documents and
378 // includes the activity log for all of the nested subdocuments as well.
379 ContentBlockingLog mContentBlockingLog;
381 uint32_t mSecurityState = 0;
383 Maybe<ClientInfo> mClientInfo;
384 // Fields being mirrored from the corresponding document
385 nsCOMPtr<nsICookieJarSettings> mCookieJarSettings;
386 nsCOMPtr<nsITransportSecurityInfo> mSecurityInfo;
388 uint32_t mSandboxFlags;
390 struct OriginCounter {
391 void UpdateSiteOriginsFrom(WindowGlobalParent* aParent, bool aIncrease);
392 void Accumulate();
394 nsTHashMap<nsCStringHashKey, int32_t> mOriginMap;
395 uint32_t mMaxOrigins = 0;
398 // Used to collect unique site origin telemetry.
400 // Is only Some() on top-level content windows.
401 Maybe<OriginCounter> mOriginCounter;
403 bool mDocumentHasLoaded;
404 bool mDocumentHasUserInteracted;
405 bool mDocumentTreeWouldPreloadResources = false;
406 bool mBlockAllMixedContent;
407 bool mUpgradeInsecureRequests;
409 // HTTPS-Only Mode flags
410 uint32_t mHttpsOnlyStatus;
412 // The window of the document whose page use counters our document's use
413 // counters will contribute to. (If we are a top-level document, this
414 // will point to ourselves.)
415 RefPtr<WindowGlobalParent> mPageUseCountersWindow;
417 // Our page use counters, if we are a top-level document.
418 UniquePtr<PageUseCounters> mPageUseCounters;
420 // Whether we have sent our page use counters, and so should ignore any
421 // subsequent ExpectPageUseCounters calls.
422 bool mSentPageUseCounters = false;
424 uint32_t mBFCacheStatus = 0;
426 // If this WindowGlobalParent is a top window, this field indicates how many
427 // child processes have active peer connections for this window and its
428 // descendants.
429 uint32_t mNumOfProcessesWithActivePeerConnections = 0;
431 // mSingleChannelId records whether the loadgroup contains a single request
432 // with an id. If there is one channel in the loadgroup and it has an id then
433 // mSingleChannelId is set to Some(id) (ids are non-zero). If there is one
434 // request in the loadgroup and it's not a channel or it doesn't have an id,
435 // or there are multiple requests in the loadgroup, then mSingleChannelId is
436 // set to Some(0). If there are no requests in the loadgroup then
437 // mSingleChannelId is set to Nothing().
438 // Note: We ignore favicon loads when considering the requests in the
439 // loadgroup.
440 Maybe<uint64_t> mSingleChannelId;
442 // True if the current loaded document is in fullscreen.
443 bool mFullscreen = false;
445 bool mShouldReportHasBlockedOpaqueResponse = false;
448 } // namespace dom
449 } // namespace mozilla
451 inline nsISupports* ToSupports(
452 mozilla::dom::WindowGlobalParent* aWindowGlobal) {
453 return static_cast<mozilla::dom::WindowContext*>(aWindowGlobal);
456 #endif // !defined(mozilla_dom_WindowGlobalParent_h)