CacheablePerformanceTimingData.h (3687B)
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */ 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/. */ 6 7 #ifndef mozilla_dom_CacheablePerformanceTimingData_h 8 #define mozilla_dom_CacheablePerformanceTimingData_h 9 10 #include <stdint.h> 11 12 #include "nsCOMPtr.h" 13 #include "nsITimedChannel.h" 14 #include "nsString.h" 15 #include "nsTArray.h" 16 17 class nsIHttpChannel; 18 19 namespace mozilla::dom { 20 21 class IPCPerformanceTimingData; 22 23 // The subset of PerformanceResourceTiming data that can be cached for the 24 // subsequent requests from a compatible principal. 25 // 26 // This includes the data extracted from the server response, but doesn't 27 // include any timing data. 28 class CacheablePerformanceTimingData { 29 public: 30 CacheablePerformanceTimingData() = default; 31 32 CacheablePerformanceTimingData(nsITimedChannel* aChannel, 33 nsIHttpChannel* aHttpChannel); 34 35 protected: 36 explicit CacheablePerformanceTimingData( 37 const CacheablePerformanceTimingData& aOther); 38 39 explicit CacheablePerformanceTimingData( 40 const IPCPerformanceTimingData& aIPCData); 41 42 public: 43 bool IsInitialized() const { return mInitialized; } 44 45 const nsString& NextHopProtocol() const { return mNextHopProtocol; } 46 47 uint64_t EncodedBodySize() const { return mEncodedBodySize; } 48 49 uint64_t DecodedBodySize() const { return mDecodedBodySize; } 50 51 uint16_t ResponseStatus() const { return mResponseStatus; } 52 53 const nsString& ContentType() const { return mContentType; } 54 55 uint8_t RedirectCountReal() const { return mRedirectCount; } 56 uint8_t GetRedirectCount() const; 57 58 bool AllRedirectsSameOrigin() const { return mAllRedirectsSameOrigin; } 59 60 // Cached result of CheckBodyInfoAccessAllowedForOrigin. 61 nsITimedChannel::BodyInfoAccess BodyInfoAccessAllowed() const { 62 return mBodyInfoAccessAllowed; 63 } 64 65 // Cached result of CheckTimingAllowedForOrigin. If false, security sensitive 66 // attributes of the resourceTiming object will be set to 0 67 bool TimingAllowed() const { return mTimingAllowed; } 68 69 nsTArray<nsCOMPtr<nsIServerTiming>> GetServerTiming(); 70 71 protected: 72 void SetCacheablePropertiesFromHttpChannel(nsIHttpChannel* aHttpChannel, 73 nsITimedChannel* aChannel); 74 75 private: 76 // Checks if the bodyInfo for Resource and Navigation Timing should be 77 // kept opaque or exposed, per Fetch spec. 78 nsITimedChannel::BodyInfoAccess CheckBodyInfoAccessAllowedForOrigin( 79 nsIHttpChannel* aResourceChannel, nsITimedChannel* aChannel); 80 81 // Checks if the resource is either same origin as the page that started 82 // the load, or if the response contains the Timing-Allow-Origin header 83 // with a value of * or matching the domain of the loading Principal 84 bool CheckTimingAllowedForOrigin(nsIHttpChannel* aResourceChannel, 85 nsITimedChannel* aChannel); 86 87 protected: 88 uint64_t mEncodedBodySize = 0; 89 uint64_t mDecodedBodySize = 0; 90 91 uint16_t mResponseStatus = 0; 92 93 uint8_t mRedirectCount = 0; 94 95 nsITimedChannel::BodyInfoAccess mBodyInfoAccessAllowed = 96 nsITimedChannel::BodyInfoAccess::DISALLOWED; 97 98 bool mAllRedirectsSameOrigin = false; 99 100 bool mAllRedirectsPassTAO = false; 101 102 bool mSecureConnection = false; 103 104 bool mTimingAllowed = false; 105 106 bool mInitialized = false; 107 108 nsString mNextHopProtocol; 109 nsString mContentType; 110 111 nsTArray<nsCOMPtr<nsIServerTiming>> mServerTiming; 112 }; 113 114 } // namespace mozilla::dom 115 116 #endif // mozilla_dom_CacheablePerformanceTimingData_h