Bug 1867190 - Initialise the PHC allocate delay later r=glandium
[gecko.git] / dom / ipc / WindowGlobalChild.h
blob107b3f471d2df5bed0ccd38690bb84b306a33d28
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_WindowGlobalChild_h
8 #define mozilla_dom_WindowGlobalChild_h
10 #include "mozilla/RefPtr.h"
11 #include "mozilla/WeakPtr.h"
12 #include "mozilla/dom/PWindowGlobalChild.h"
13 #include "nsRefPtrHashtable.h"
14 #include "nsWrapperCache.h"
15 #include "mozilla/dom/Document.h"
16 #include "mozilla/dom/WindowGlobalActor.h"
18 class nsGlobalWindowInner;
19 class nsDocShell;
21 namespace mozilla::dom {
23 class BrowsingContext;
24 class FeaturePolicy;
25 class WindowContext;
26 class WindowGlobalParent;
27 class JSWindowActorChild;
28 class JSActorMessageMeta;
29 class BrowserChild;
31 /**
32 * Actor for a single nsGlobalWindowInner. This actor is used to communicate
33 * information to the parent process asynchronously.
35 class WindowGlobalChild final : public WindowGlobalActor,
36 public nsWrapperCache,
37 public PWindowGlobalChild,
38 public SupportsWeakPtr {
39 friend class PWindowGlobalChild;
41 public:
42 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
43 NS_DECL_CYCLE_COLLECTION_WRAPPERCACHE_CLASS(WindowGlobalChild)
45 static already_AddRefed<WindowGlobalChild> GetByInnerWindowId(
46 uint64_t aInnerWindowId);
48 static already_AddRefed<WindowGlobalChild> GetByInnerWindowId(
49 const GlobalObject& aGlobal, uint64_t aInnerWindowId) {
50 return GetByInnerWindowId(aInnerWindowId);
53 dom::BrowsingContext* BrowsingContext() override;
54 dom::WindowContext* WindowContext() const { return mWindowContext; }
55 nsGlobalWindowInner* GetWindowGlobal() const { return mWindowGlobal; }
57 // Has this actor been shut down
58 bool IsClosed() { return !CanSend(); }
59 void Destroy();
61 // Check if this actor is managed by PInProcess, as-in the document is loaded
62 // in the chrome process.
63 bool IsInProcess() { return XRE_IsParentProcess(); }
65 nsIURI* GetDocumentURI() override { return mDocumentURI; }
66 void SetDocumentURI(nsIURI* aDocumentURI);
67 // See the corresponding comment for `UpdateDocumentPrincipal` in
68 // PWindowGlobal on why and when this is allowed
69 void SetDocumentPrincipal(nsIPrincipal* aNewDocumentPrincipal,
70 nsIPrincipal* aNewDocumentStoragePrincipal);
72 nsIPrincipal* DocumentPrincipal() { return mDocumentPrincipal; }
74 // The Window ID for this WindowGlobal
75 uint64_t InnerWindowId();
76 uint64_t OuterWindowId();
78 uint64_t ContentParentId();
80 int64_t BeforeUnloadListeners() { return mBeforeUnloadListeners; }
81 void BeforeUnloadAdded();
82 void BeforeUnloadRemoved();
84 bool IsCurrentGlobal();
86 bool IsProcessRoot();
88 // Get the other side of this actor if it is an in-process actor. Returns
89 // |nullptr| if the actor has been torn down, or is not in-process.
90 already_AddRefed<WindowGlobalParent> GetParentActor();
92 // Get this actor's manager if it is not an in-process actor. Returns
93 // |nullptr| if the actor has been torn down, or is in-process.
94 already_AddRefed<BrowserChild> GetBrowserChild();
96 // Get a JS actor object by name.
97 already_AddRefed<JSWindowActorChild> GetActor(JSContext* aCx,
98 const nsACString& aName,
99 ErrorResult& aRv);
100 already_AddRefed<JSWindowActorChild> GetExistingActor(
101 const nsACString& aName);
103 // Create and initialize the WindowGlobalChild object.
104 static already_AddRefed<WindowGlobalChild> Create(
105 nsGlobalWindowInner* aWindow);
106 static already_AddRefed<WindowGlobalChild> CreateDisconnected(
107 const WindowGlobalInit& aInit);
109 void Init();
111 void InitWindowGlobal(nsGlobalWindowInner* aWindow);
113 // Called when a new document is loaded in this WindowGlobalChild.
114 void OnNewDocument(Document* aNewDocument);
116 // Returns true if this WindowGlobal is same-origin with the given
117 // WindowContext. Out-of-process WindowContexts are supported, and are assumed
118 // to be cross-origin.
120 // The given WindowContext must be in the same BrowsingContextGroup as this
121 // window global.
122 bool IsSameOriginWith(const dom::WindowContext* aOther) const;
124 bool SameOriginWithTop();
126 // Returns `true` if this WindowGlobal is allowed to navigate the given
127 // BrowsingContext. BrowsingContexts which are currently out-of-process are
128 // supported, and assumed to be cross-origin.
130 // The given BrowsingContext must be in the same BrowsingContextGroup as this
131 // WindowGlobal.
132 bool CanNavigate(dom::BrowsingContext* aTarget, bool aConsiderOpener = true);
134 // Using the rules for choosing a browsing context we try to find
135 // the browsing context with the given name in the set of
136 // transitively reachable browsing contexts. Performs access control
137 // checks with regard to this.
138 // See
139 // https://html.spec.whatwg.org/multipage/browsers.html#the-rules-for-choosing-a-browsing-context-given-a-browsing-context-name.
140 dom::BrowsingContext* FindBrowsingContextWithName(
141 const nsAString& aName, bool aUseEntryGlobalForAccessCheck = true);
143 nsISupports* GetParentObject();
144 JSObject* WrapObject(JSContext* aCx,
145 JS::Handle<JSObject*> aGivenProto) override;
147 dom::FeaturePolicy* GetContainerFeaturePolicy() const {
148 return mContainerFeaturePolicy;
151 void UnblockBFCacheFor(BFCacheStatus aStatus);
152 void BlockBFCacheFor(BFCacheStatus aStatus);
154 protected:
155 const nsACString& GetRemoteType() override;
157 already_AddRefed<JSActor> InitJSActor(JS::Handle<JSObject*> aMaybeActor,
158 const nsACString& aName,
159 ErrorResult& aRv) override;
160 mozilla::ipc::IProtocol* AsNativeActor() override { return this; }
162 // IPC messages
163 mozilla::ipc::IPCResult RecvRawMessage(
164 const JSActorMessageMeta& aMeta, const Maybe<ClonedMessageData>& aData,
165 const Maybe<ClonedMessageData>& aStack);
167 mozilla::ipc::IPCResult RecvMakeFrameLocal(
168 const MaybeDiscarded<dom::BrowsingContext>& aFrameContext,
169 uint64_t aPendingSwitchId);
171 mozilla::ipc::IPCResult RecvMakeFrameRemote(
172 const MaybeDiscarded<dom::BrowsingContext>& aFrameContext,
173 ManagedEndpoint<PBrowserBridgeChild>&& aEndpoint, const TabId& aTabId,
174 const LayersId& aLayersId, MakeFrameRemoteResolver&& aResolve);
176 mozilla::ipc::IPCResult RecvDrawSnapshot(const Maybe<IntRect>& aRect,
177 const float& aScale,
178 const nscolor& aBackgroundColor,
179 const uint32_t& aFlags,
180 DrawSnapshotResolver&& aResolve);
182 mozilla::ipc::IPCResult RecvDispatchSecurityPolicyViolation(
183 const nsString& aViolationEventJSON);
185 mozilla::ipc::IPCResult RecvSaveStorageAccessPermissionGranted();
187 mozilla::ipc::IPCResult RecvAddBlockedFrameNodeByClassifier(
188 const MaybeDiscardedBrowsingContext& aNode);
190 mozilla::ipc::IPCResult RecvResetScalingZoom();
192 mozilla::ipc::IPCResult RecvSetContainerFeaturePolicy(
193 dom::FeaturePolicy* aContainerFeaturePolicy);
195 mozilla::ipc::IPCResult RecvRestoreDocShellState(
196 const dom::sessionstore::DocShellRestoreState& aState,
197 RestoreDocShellStateResolver&& aResolve);
199 // TODO: Use MOZ_CAN_RUN_SCRIPT when it gains IPDL support (bug 1539864)
200 MOZ_CAN_RUN_SCRIPT_BOUNDARY mozilla::ipc::IPCResult RecvRestoreTabContent(
201 dom::SessionStoreRestoreData* aData,
202 RestoreTabContentResolver&& aResolve);
204 mozilla::ipc::IPCResult RecvNotifyPermissionChange(const nsCString& aType,
205 uint32_t aPermission);
207 virtual void ActorDestroy(ActorDestroyReason aWhy) override;
209 private:
210 WindowGlobalChild(dom::WindowContext* aWindowContext,
211 nsIPrincipal* aPrincipal, nsIURI* aURI);
213 ~WindowGlobalChild();
215 RefPtr<nsGlobalWindowInner> mWindowGlobal;
216 RefPtr<dom::WindowContext> mWindowContext;
217 nsCOMPtr<nsIPrincipal> mDocumentPrincipal;
218 RefPtr<dom::FeaturePolicy> mContainerFeaturePolicy;
219 nsCOMPtr<nsIURI> mDocumentURI;
220 int64_t mBeforeUnloadListeners = 0;
223 } // namespace mozilla::dom
225 #endif // !defined(mozilla_dom_WindowGlobalChild_h)