1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set sw=2 ts=8 et tw=80 : */
3 
4 /* This Source Code Form is subject to the terms of the Mozilla Public
5  * License, v. 2.0. If a copy of the MPL was not distributed with this
6  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 
8 #include "mozilla/BasePrincipal.h"
9 #include "mozilla/net/PNeckoParent.h"
10 #include "mozilla/net/NeckoCommon.h"
11 #include "nsIAuthPrompt2.h"
12 #include "nsINetworkPredictor.h"
13 #include "nsNetUtil.h"
14 
15 #ifndef mozilla_net_NeckoParent_h
16 #  define mozilla_net_NeckoParent_h
17 
18 namespace mozilla {
19 namespace net {
20 
21 // Used to override channel Private Browsing status if needed.
22 enum PBOverrideStatus {
23   kPBOverride_Unset = 0,
24   kPBOverride_Private,
25   kPBOverride_NotPrivate
26 };
27 
28 // Header file contents
29 class NeckoParent : public PNeckoParent {
30   friend class PNeckoParent;
31 
32  public:
33   NeckoParent();
34   virtual ~NeckoParent() = default;
35 
36   [[nodiscard]] static const char* GetValidatedOriginAttributes(
37       const SerializedLoadContext& aSerialized, PContentParent* aBrowser,
38       nsIPrincipal* aRequestingPrincipal, mozilla::OriginAttributes& aAttrs);
39 
40   /*
41    * Creates LoadContext for parent-side of an e10s channel.
42    *
43    * PContentParent corresponds to the process that is requesting the load.
44    *
45    * Returns null if successful, or an error string if failed.
46    */
47   [[nodiscard]] static const char* CreateChannelLoadContext(
48       PBrowserParent* aBrowser, PContentParent* aContent,
49       const SerializedLoadContext& aSerialized,
50       nsIPrincipal* aRequestingPrincipal, nsCOMPtr<nsILoadContext>& aResult);
51 
52   virtual void ActorDestroy(ActorDestroyReason aWhy) override;
53   PCookieServiceParent* AllocPCookieServiceParent();
RecvPCookieServiceConstructor(PCookieServiceParent * aActor)54   virtual mozilla::ipc::IPCResult RecvPCookieServiceConstructor(
55       PCookieServiceParent* aActor) override {
56     return PNeckoParent::RecvPCookieServiceConstructor(aActor);
57   }
58 
59   /*
60    * This implementation of nsIAuthPrompt2 is used for nested remote iframes
61    * that want an auth prompt.  This class lives in the parent process and
62    * informs the NeckoChild that we want an auth prompt, which forwards the
63    * request to the BrowserParent in the remote iframe that contains the nested
64    * iframe
65    */
66   class NestedFrameAuthPrompt final : public nsIAuthPrompt2 {
~NestedFrameAuthPrompt()67     ~NestedFrameAuthPrompt() {}
68 
69    public:
70     NS_DECL_ISUPPORTS
71 
72     NestedFrameAuthPrompt(PNeckoParent* aParent, TabId aNestedFrameId);
73 
PromptAuth(nsIChannel *,uint32_t,nsIAuthInformation *,bool *)74     NS_IMETHOD PromptAuth(nsIChannel*, uint32_t, nsIAuthInformation*,
75                           bool*) override {
76       return NS_ERROR_NOT_IMPLEMENTED;
77     }
78 
79     NS_IMETHOD AsyncPromptAuth(nsIChannel* aChannel,
80                                nsIAuthPromptCallback* callback, nsISupports*,
81                                uint32_t, nsIAuthInformation* aInfo,
82                                nsICancelable**) override;
83 
84    protected:
85     PNeckoParent* mNeckoParent;
86     TabId mNestedFrameId;
87   };
88 
89  protected:
90   bool mSocketProcessBridgeInited;
91 
92   already_AddRefed<PHttpChannelParent> AllocPHttpChannelParent(
93       PBrowserParent*, const SerializedLoadContext&,
94       const HttpChannelCreationArgs& aOpenArgs);
95   virtual mozilla::ipc::IPCResult RecvPHttpChannelConstructor(
96       PHttpChannelParent* aActor, PBrowserParent* aBrowser,
97       const SerializedLoadContext& aSerialized,
98       const HttpChannelCreationArgs& aOpenArgs) override;
99 
100   PStunAddrsRequestParent* AllocPStunAddrsRequestParent();
101   bool DeallocPStunAddrsRequestParent(PStunAddrsRequestParent* aActor);
102 
103   PWebrtcTCPSocketParent* AllocPWebrtcTCPSocketParent(
104       const Maybe<TabId>& aTabId);
105   bool DeallocPWebrtcTCPSocketParent(PWebrtcTCPSocketParent* aActor);
106 
107   PAltDataOutputStreamParent* AllocPAltDataOutputStreamParent(
108       const nsCString& type, const int64_t& predictedSize,
109       PHttpChannelParent* channel);
110   bool DeallocPAltDataOutputStreamParent(PAltDataOutputStreamParent* aActor);
111 
112   bool DeallocPCookieServiceParent(PCookieServiceParent*);
113   PFTPChannelParent* AllocPFTPChannelParent(
114       PBrowserParent* aBrowser, const SerializedLoadContext& aSerialized,
115       const FTPChannelCreationArgs& aOpenArgs);
116   virtual mozilla::ipc::IPCResult RecvPFTPChannelConstructor(
117       PFTPChannelParent* aActor, PBrowserParent* aBrowser,
118       const SerializedLoadContext& aSerialized,
119       const FTPChannelCreationArgs& aOpenArgs) override;
120   bool DeallocPFTPChannelParent(PFTPChannelParent*);
121   PWebSocketParent* AllocPWebSocketParent(
122       PBrowserParent* browser, const SerializedLoadContext& aSerialized,
123       const uint32_t& aSerial);
124   bool DeallocPWebSocketParent(PWebSocketParent*);
125   PTCPSocketParent* AllocPTCPSocketParent(const nsString& host,
126                                           const uint16_t& port);
127 
128   already_AddRefed<PDocumentChannelParent> AllocPDocumentChannelParent(
129       const dom::MaybeDiscarded<dom::BrowsingContext>& aContext,
130       const DocumentChannelCreationArgs& args);
131   virtual mozilla::ipc::IPCResult RecvPDocumentChannelConstructor(
132       PDocumentChannelParent* aActor,
133       const dom::MaybeDiscarded<dom::BrowsingContext>& aContext,
134       const DocumentChannelCreationArgs& aArgs) override;
135   bool DeallocPDocumentChannelParent(PDocumentChannelParent* channel);
136 
137   bool DeallocPTCPSocketParent(PTCPSocketParent*);
138   PTCPServerSocketParent* AllocPTCPServerSocketParent(
139       const uint16_t& aLocalPort, const uint16_t& aBacklog,
140       const bool& aUseArrayBuffers);
141   virtual mozilla::ipc::IPCResult RecvPTCPServerSocketConstructor(
142       PTCPServerSocketParent*, const uint16_t& aLocalPort,
143       const uint16_t& aBacklog, const bool& aUseArrayBuffers) override;
144   bool DeallocPTCPServerSocketParent(PTCPServerSocketParent*);
145   PUDPSocketParent* AllocPUDPSocketParent(nsIPrincipal* aPrincipal,
146                                           const nsCString& aFilter);
147   virtual mozilla::ipc::IPCResult RecvPUDPSocketConstructor(
148       PUDPSocketParent*, nsIPrincipal* aPrincipal,
149       const nsCString& aFilter) override;
150   bool DeallocPUDPSocketParent(PUDPSocketParent*);
151   already_AddRefed<PDNSRequestParent> AllocPDNSRequestParent(
152       const nsCString& aHost, const nsCString& aTrrServer,
153       const uint16_t& aType, const OriginAttributes& aOriginAttributes,
154       const uint32_t& aFlags);
155   virtual mozilla::ipc::IPCResult RecvPDNSRequestConstructor(
156       PDNSRequestParent* actor, const nsCString& hostName,
157       const nsCString& trrServer, const uint16_t& type,
158       const OriginAttributes& aOriginAttributes,
159       const uint32_t& flags) override;
160   mozilla::ipc::IPCResult RecvSpeculativeConnect(nsIURI* aURI,
161                                                  nsIPrincipal* aPrincipal,
162                                                  const bool& aAnonymous);
163   mozilla::ipc::IPCResult RecvHTMLDNSPrefetch(
164       const nsString& hostname, const bool& isHttps,
165       const OriginAttributes& aOriginAttributes, const uint32_t& flags);
166   mozilla::ipc::IPCResult RecvCancelHTMLDNSPrefetch(
167       const nsString& hostname, const bool& isHttps,
168       const OriginAttributes& aOriginAttributes, const uint32_t& flags,
169       const nsresult& reason);
170   PWebSocketEventListenerParent* AllocPWebSocketEventListenerParent(
171       const uint64_t& aInnerWindowID);
172   bool DeallocPWebSocketEventListenerParent(PWebSocketEventListenerParent*);
173 
174   already_AddRefed<PDataChannelParent> AllocPDataChannelParent(
175       const uint32_t& channelId);
176 
177   virtual mozilla::ipc::IPCResult RecvPDataChannelConstructor(
178       PDataChannelParent* aActor, const uint32_t& channelId) override;
179 
180   PSimpleChannelParent* AllocPSimpleChannelParent(const uint32_t& channelId);
181   bool DeallocPSimpleChannelParent(PSimpleChannelParent* parent);
182 
183   virtual mozilla::ipc::IPCResult RecvPSimpleChannelConstructor(
184       PSimpleChannelParent* aActor, const uint32_t& channelId) override;
185 
186   already_AddRefed<PFileChannelParent> AllocPFileChannelParent(
187       const uint32_t& channelId);
188 
189   virtual mozilla::ipc::IPCResult RecvPFileChannelConstructor(
190       PFileChannelParent* aActor, const uint32_t& channelId) override;
191 
192   PChannelDiverterParent* AllocPChannelDiverterParent(
193       const ChannelDiverterArgs& channel);
194   virtual mozilla::ipc::IPCResult RecvPChannelDiverterConstructor(
195       PChannelDiverterParent* actor,
196       const ChannelDiverterArgs& channel) override;
197   bool DeallocPChannelDiverterParent(PChannelDiverterParent* actor);
198   PTransportProviderParent* AllocPTransportProviderParent();
199   bool DeallocPTransportProviderParent(PTransportProviderParent* aActor);
200 
201   mozilla::ipc::IPCResult RecvOnAuthAvailable(const uint64_t& aCallbackId,
202                                               const nsString& aUser,
203                                               const nsString& aPassword,
204                                               const nsString& aDomain);
205   mozilla::ipc::IPCResult RecvOnAuthCancelled(const uint64_t& aCallbackId,
206                                               const bool& aUserCancel);
207 
208   /* Predictor Messages */
209   mozilla::ipc::IPCResult RecvPredPredict(
210       nsIURI* aTargetURI, nsIURI* aSourceURI,
211       const PredictorPredictReason& aReason,
212       const OriginAttributes& aOriginAttributes, const bool& hasVerifier);
213 
214   mozilla::ipc::IPCResult RecvPredLearn(
215       nsIURI* aTargetURI, nsIURI* aSourceURI,
216       const PredictorPredictReason& aReason,
217       const OriginAttributes& aOriginAttributes);
218   mozilla::ipc::IPCResult RecvPredReset();
219 
220   mozilla::ipc::IPCResult RecvRequestContextLoadBegin(const uint64_t& rcid);
221   mozilla::ipc::IPCResult RecvRequestContextAfterDOMContentLoaded(
222       const uint64_t& rcid);
223   mozilla::ipc::IPCResult RecvRemoveRequestContext(const uint64_t& rcid);
224 
225   /* WebExtensions */
226   mozilla::ipc::IPCResult RecvGetExtensionStream(
227       nsIURI* aURI, GetExtensionStreamResolver&& aResolve);
228 
229   mozilla::ipc::IPCResult RecvGetExtensionFD(nsIURI* aURI,
230                                              GetExtensionFDResolver&& aResolve);
231 
232   /* Page thumbnails remote resource loading */
233   mozilla::ipc::IPCResult RecvGetPageThumbStream(
234       nsIURI* aURI, GetPageThumbStreamResolver&& aResolve);
235 
236   PClassifierDummyChannelParent* AllocPClassifierDummyChannelParent(
237       nsIURI* aURI, nsIURI* aTopWindowURI, const nsresult& aTopWindowURIResult,
238       const Maybe<LoadInfoArgs>& aLoadInfo);
239 
240   bool DeallocPClassifierDummyChannelParent(
241       PClassifierDummyChannelParent* aParent);
242 
243   virtual mozilla::ipc::IPCResult RecvPClassifierDummyChannelConstructor(
244       PClassifierDummyChannelParent* aActor, nsIURI* aURI,
245       nsIURI* aTopWindowURI, const nsresult& aTopWindowURIResult,
246       const Maybe<LoadInfoArgs>& aLoadInfo) override;
247 
248   mozilla::ipc::IPCResult RecvInitSocketProcessBridge(
249       InitSocketProcessBridgeResolver&& aResolver);
250 
251   mozilla::ipc::IPCResult RecvEnsureHSTSData(
252       EnsureHSTSDataResolver&& aResolver);
253 };
254 
255 }  // namespace net
256 }  // namespace mozilla
257 
258 #endif  // mozilla_net_NeckoParent_h
259