nsLoadGroup.h (4094B)
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* This Source Code Form is subject to the terms of the Mozilla Public 3 * License, v. 2.0. If a copy of the MPL was not distributed with this 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 5 6 #ifndef nsLoadGroup_h__ 7 #define nsLoadGroup_h__ 8 9 #include "nsILoadGroup.h" 10 #include "nsILoadGroupChild.h" 11 #include "nsIObserver.h" 12 #include "nsCOMPtr.h" 13 #include "nsWeakReference.h" 14 #include "nsISupportsPriority.h" 15 #include "PLDHashTable.h" 16 #include "mozilla/TimeStamp.h" 17 18 class nsIRequestContext; 19 class nsIRequestContextService; 20 class nsITimedChannel; 21 22 namespace mozilla { 23 namespace net { 24 25 class nsLoadGroup : public nsILoadGroup, 26 public nsILoadGroupChild, 27 public nsIObserver, 28 public nsISupportsPriority, 29 public nsSupportsWeakReference { 30 public: 31 NS_DECL_ISUPPORTS 32 33 //////////////////////////////////////////////////////////////////////////// 34 // nsIRequest methods: 35 NS_DECL_NSIREQUEST 36 37 //////////////////////////////////////////////////////////////////////////// 38 // nsILoadGroup methods: 39 NS_DECL_NSILOADGROUP 40 41 //////////////////////////////////////////////////////////////////////////// 42 // nsILoadGroupChild methods: 43 NS_DECL_NSILOADGROUPCHILD 44 45 //////////////////////////////////////////////////////////////////////////// 46 // nsISupportsPriority methods: 47 NS_DECL_NSISUPPORTSPRIORITY 48 49 //////////////////////////////////////////////////////////////////////////// 50 // nsIObserver methods: 51 NS_DECL_NSIOBSERVER 52 53 //////////////////////////////////////////////////////////////////////////// 54 // nsLoadGroup methods: 55 56 nsLoadGroup(); 57 58 nsresult Init(); 59 nsresult InitWithRequestContextId(const uint64_t& aRequestContextId); 60 61 void SetGroupObserver(nsIRequestObserver* aObserver, 62 bool aIncludeBackgroundRequests); 63 64 /** 65 * Flags inherited from the default request in the load group onto other loads 66 * added to the load group. 67 * 68 * NOTE(emilio): If modifying these, be aware that we allow these flags to be 69 * effectively set from the content process on a document navigation, and 70 * thus nothing security-critical should be allowed here. 71 */ 72 static constexpr nsLoadFlags kInheritedLoadFlags = 73 LOAD_BACKGROUND | LOAD_BYPASS_CACHE | LOAD_FROM_CACHE | VALIDATE_ALWAYS | 74 VALIDATE_ONCE_PER_SESSION | VALIDATE_NEVER; 75 76 protected: 77 virtual ~nsLoadGroup(); 78 79 nsresult MergeLoadFlags(nsIRequest* aRequest, nsLoadFlags& flags); 80 nsresult MergeDefaultLoadFlags(nsIRequest* aRequest, nsLoadFlags& flags); 81 82 private: 83 void TelemetryReport(); 84 void TelemetryReportChannel(nsITimedChannel* timedChannel, 85 bool defaultRequest); 86 87 nsresult RemoveRequestFromHashtable(nsIRequest* aRequest, nsresult aStatus); 88 nsresult NotifyRemovalObservers(nsIRequest* aRequest, nsresult aStatus); 89 90 protected: 91 uint32_t mForegroundCount{0}; 92 uint32_t mLoadFlags{LOAD_NORMAL}; 93 uint32_t mDefaultLoadFlags{0}; 94 int32_t mPriority{PRIORITY_NORMAL}; 95 96 nsCOMPtr<nsILoadGroup> mLoadGroup; // load groups can contain load groups 97 nsCOMPtr<nsIInterfaceRequestor> mCallbacks; 98 nsCOMPtr<nsIRequestContext> mRequestContext; 99 nsCOMPtr<nsIRequestContextService> mRequestContextService; 100 101 nsCOMPtr<nsIRequest> mDefaultLoadRequest; 102 PLDHashTable mRequests; 103 104 nsWeakPtr mObserver; 105 nsWeakPtr mParentLoadGroup; 106 107 nsresult mStatus{NS_OK}; 108 nsresult mDefaultStatus{NS_OK}; 109 bool mIsCanceling{false}; 110 bool mDefaultLoadIsTimed{false}; 111 bool mBrowsingContextDiscarded{false}; 112 bool mExternalRequestContext{false}; 113 bool mNotifyObserverAboutBackgroundRequests{false}; 114 115 // size of requests with keepalive flag for this load group 116 uint64_t mPendingKeepaliveRequestSize{0}; 117 118 /* Telemetry */ 119 mozilla::TimeStamp mDefaultRequestCreationTime; 120 uint32_t mTimedRequests{0}; 121 uint32_t mCachedRequests{0}; 122 uint64_t mPageSize{0}; 123 uint64_t mTotalSubresourcesSize{0}; 124 }; 125 126 } // namespace net 127 } // namespace mozilla 128 129 #endif // nsLoadGroup_h__