FetchParent.h (3213B)
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/. */ 4 5 #ifndef mozilla_dom_fetchParent_h__ 6 #define mozilla_dom_fetchParent_h__ 7 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" 16 #include "nsCOMPtr.h" 17 #include "nsIContentSecurityPolicy.h" 18 #include "nsID.h" 19 #include "nsISerialEventTarget.h" 20 #include "nsString.h" 21 #include "nsTHashMap.h" 22 23 namespace mozilla::dom { 24 25 class ClientInfo; 26 class FetchServicePromises; 27 class InternalRequest; 28 class InternalResponse; 29 class ServiceWorkerDescriptor; 30 31 class FetchParent final : public PFetchParent { 32 friend class PFetchParent; 33 34 public: 35 NS_INLINE_DECL_THREADSAFE_REFCOUNTING(FetchParent, override); 36 37 mozilla::ipc::IPCResult RecvFetchOp(FetchOpArgs&& aArgs); 38 39 mozilla::ipc::IPCResult RecvAbortFetchOp(bool aForceAbort); 40 41 FetchParent(); 42 43 static RefPtr<FetchParent> GetActorByID(const nsID& aID); 44 45 void OnResponseAvailableInternal(SafeRefPtr<InternalResponse>&& aResponse); 46 47 void OnResponseEnd(const ResponseEndArgs& aArgs); 48 49 void OnDataAvailable(); 50 51 void OnFlushConsoleReport( 52 const nsTArray<net::ConsoleReportCollected>& aReports); 53 54 class FetchParentCSPEventListener final : public nsICSPEventListener { 55 public: 56 NS_DECL_THREADSAFE_ISUPPORTS 57 NS_DECL_NSICSPEVENTLISTENER 58 59 FetchParentCSPEventListener(const nsID& aActorID, 60 nsCOMPtr<nsISerialEventTarget> aEventTarget); 61 62 private: 63 ~FetchParentCSPEventListener() = default; 64 65 nsID mActorID; 66 nsCOMPtr<nsISerialEventTarget> mEventTarget; 67 }; 68 69 nsICSPEventListener* GetCSPEventListener(); 70 71 void OnCSPViolationEvent(const nsAString& aJSON); 72 73 void OnReportPerformanceTiming(const ResponseTiming&& aTiming); 74 75 void OnNotifyNetworkMonitorAlternateStack(uint64_t aChannelID); 76 77 private: 78 ~FetchParent(); 79 80 void ActorDestroy(ActorDestroyReason aReason) override; 81 82 // The map of FetchParent and ID. Should only access in background thread. 83 static nsTHashMap<nsIDHashKey, RefPtr<FetchParent>> sActorTable; 84 85 // The unique ID of the FetchParent 86 nsID mID; 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}; 100 bool mIsThirdPartyContext{true}; 101 bool mIsWorkerFetch{false}; 102 bool mIsOn3PCBExceptionList{false}; 103 104 Atomic<bool> mIsDone{false}; 105 Atomic<bool> mActorDestroyed{false}; 106 107 nsCOMPtr<nsISerialEventTarget> mBackgroundEventTarget; 108 }; 109 110 } // namespace mozilla::dom 111 112 #endif