1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 #ifndef mozilla_dom_fetchParent_h__
6 #define mozilla_dom_fetchParent_h__
8 #include "mozilla/Maybe.h"
9 #include "mozilla/MozPromise.h"
10 #include "mozilla/Mutex.h"
11 #include "mozilla/RefPtr.h"
12 #include "mozilla/dom/PFetchParent.h"
13 #include "mozilla/dom/SafeRefPtr.h"
14 #include "mozilla/ipc/PBackgroundSharedTypes.h"
15 #include "mozilla/net/NeckoChannelParams.h"
17 #include "nsIContentSecurityPolicy.h"
19 #include "nsISerialEventTarget.h"
21 #include "nsTHashMap.h"
23 namespace mozilla::dom
{
26 class FetchServicePromises
;
27 class InternalRequest
;
28 class InternalResponse
;
29 class ServiceWorkerDescriptor
;
31 class FetchParent final
: public PFetchParent
{
32 friend class PFetchParent
;
35 NS_INLINE_DECL_THREADSAFE_REFCOUNTING(FetchParent
, override
);
37 mozilla::ipc::IPCResult
RecvFetchOp(FetchOpArgs
&& aArgs
);
39 mozilla::ipc::IPCResult
RecvAbortFetchOp();
43 static RefPtr
<FetchParent
> GetActorByID(const nsID
& aID
);
45 void OnResponseAvailableInternal(SafeRefPtr
<InternalResponse
>&& aResponse
);
47 void OnResponseEnd(const ResponseEndArgs
& aArgs
);
49 void OnDataAvailable();
51 void OnFlushConsoleReport(
52 const nsTArray
<net::ConsoleReportCollected
>& aReports
);
54 class FetchParentCSPEventListener final
: public nsICSPEventListener
{
56 NS_DECL_THREADSAFE_ISUPPORTS
57 NS_DECL_NSICSPEVENTLISTENER
59 FetchParentCSPEventListener(const nsID
& aActorID
,
60 nsCOMPtr
<nsISerialEventTarget
> aEventTarget
);
63 ~FetchParentCSPEventListener() = default;
66 nsCOMPtr
<nsISerialEventTarget
> mEventTarget
;
69 nsICSPEventListener
* GetCSPEventListener();
71 void OnCSPViolationEvent(const nsAString
& aJSON
);
73 void OnReportPerformanceTiming(const ResponseTiming
&& aTiming
);
75 void OnNotifyNetworkMonitorAlternateStack(uint64_t aChannelID
);
80 void ActorDestroy(ActorDestroyReason aReason
) override
;
82 // The map of FetchParent and ID. Should only access in background thread.
83 static nsTHashMap
<nsIDHashKey
, RefPtr
<FetchParent
>> sActorTable
;
85 // The unique ID of the FetchParent
87 SafeRefPtr
<InternalRequest
> mRequest
;
88 RefPtr
<FetchServicePromises
> mResponsePromises
;
89 RefPtr
<GenericPromise::Private
> mPromise
;
90 PrincipalInfo mPrincipalInfo
;
91 nsCString mWorkerScript
;
92 Maybe
<ClientInfo
> mClientInfo
;
93 Maybe
<ServiceWorkerDescriptor
> mController
;
94 Maybe
<CookieJarSettingsArgs
> mCookieJarSettings
;
95 nsCOMPtr
<nsICSPEventListener
> mCSPEventListener
;
96 bool mNeedOnDataAvailable
{false};
97 bool mHasCSPEventListener
{false};
98 bool mExtendForCSPEventListener
{false};
99 uint64_t mAssociatedBrowsingContextID
{0};
101 Atomic
<bool> mIsDone
{false};
102 Atomic
<bool> mActorDestroyed
{false};
104 nsCOMPtr
<nsISerialEventTarget
> mBackgroundEventTarget
;
107 } // namespace mozilla::dom