Bug 1941128 - Turn off network.dns.native_https_query on Mac again
[gecko.git] / dom / performance / CacheablePerformanceTimingData.h
blobae1273b565a970644d631b7eda02d2f669866945
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/. */
7 #ifndef mozilla_dom_CacheablePerformanceTimingData_h
8 #define mozilla_dom_CacheablePerformanceTimingData_h
10 #include <stdint.h>
12 #include "nsCOMPtr.h"
13 #include "nsITimedChannel.h"
14 #include "nsStringFwd.h"
15 #include "nsTArray.h"
17 class nsIHttpChannel;
19 namespace mozilla::dom {
21 class IPCPerformanceTimingData;
23 // The subset of PerformanceResourceTiming data that can be cached for the
24 // subsequent requests from a compatible principal.
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;
32 CacheablePerformanceTimingData(nsITimedChannel* aChannel,
33 nsIHttpChannel* aHttpChannel);
35 protected:
36 explicit CacheablePerformanceTimingData(
37 const CacheablePerformanceTimingData& aOther);
39 explicit CacheablePerformanceTimingData(
40 const IPCPerformanceTimingData& aIPCData);
42 public:
43 bool IsInitialized() const { return mInitialized; }
45 const nsString& NextHopProtocol() const { return mNextHopProtocol; }
47 uint64_t EncodedBodySize() const { return mEncodedBodySize; }
49 uint64_t DecodedBodySize() const { return mDecodedBodySize; }
51 uint16_t ResponseStatus() const { return mResponseStatus; }
53 const nsString& ContentType() const { return mContentType; }
55 uint8_t RedirectCountReal() const { return mRedirectCount; }
56 uint8_t GetRedirectCount() const;
58 bool AllRedirectsSameOrigin() const { return mAllRedirectsSameOrigin; }
60 // Cached result of CheckBodyInfoAccessAllowedForOrigin.
61 nsITimedChannel::BodyInfoAccess BodyInfoAccessAllowed() const {
62 return mBodyInfoAccessAllowed;
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; }
69 nsTArray<nsCOMPtr<nsIServerTiming>> GetServerTiming();
71 protected:
72 void SetCacheablePropertiesFromHttpChannel(nsIHttpChannel* aHttpChannel,
73 nsITimedChannel* aChannel);
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);
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);
87 protected:
88 uint64_t mEncodedBodySize = 0;
89 uint64_t mDecodedBodySize = 0;
91 uint16_t mResponseStatus = 0;
93 uint8_t mRedirectCount = 0;
95 nsITimedChannel::BodyInfoAccess mBodyInfoAccessAllowed =
96 nsITimedChannel::BodyInfoAccess::DISALLOWED;
98 bool mAllRedirectsSameOrigin = false;
100 bool mAllRedirectsPassTAO = false;
102 bool mSecureConnection = false;
104 bool mTimingAllowed = false;
106 bool mInitialized = false;
108 nsString mNextHopProtocol;
109 nsString mContentType;
111 nsTArray<nsCOMPtr<nsIServerTiming>> mServerTiming;
114 } // namespace mozilla::dom
116 #endif // mozilla_dom_CacheablePerformanceTimingData_h