PerformanceNavigationTiming.h (3192B)
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_PerformanceNavigationTiming_h___ 8 #define mozilla_dom_PerformanceNavigationTiming_h___ 9 10 #include <stdint.h> 11 12 #include <utility> 13 14 #include "js/RootingAPI.h" 15 #include "mozilla/UniquePtr.h" 16 #include "mozilla/dom/PerformanceNavigationTimingBinding.h" 17 #include "mozilla/dom/PerformanceResourceTiming.h" 18 #include "nsDOMNavigationTiming.h" 19 #include "nsISupports.h" 20 #include "nsLiteralString.h" 21 #include "nsString.h" 22 #include "nsTLiteralString.h" 23 24 class JSObject; 25 class nsIHttpChannel; 26 class nsITimedChannel; 27 struct JSContext; 28 29 namespace mozilla::dom { 30 31 class Performance; 32 class PerformanceTimingData; 33 34 // https://www.w3.org/TR/navigation-timing-2/#sec-PerformanceNavigationTiming 35 class PerformanceNavigationTiming final : public PerformanceResourceTiming { 36 public: 37 NS_DECL_ISUPPORTS_INHERITED 38 39 // Note that aPerformanceTiming must be initalized with zeroTime = 0 40 // so that timestamps are relative to startTime, as opposed to the 41 // performance.timing object for which timestamps are absolute and has a 42 // zeroTime initialized to navigationStart 43 // aPerformanceTiming and aPerformance must be non-null. 44 PerformanceNavigationTiming( 45 UniquePtr<PerformanceTimingData>&& aPerformanceTiming, 46 Performance* aPerformance, const nsAString& aName) 47 : PerformanceResourceTiming(std::move(aPerformanceTiming), aPerformance, 48 aName) { 49 SetEntryType(nsGkAtoms::navigation); 50 SetInitiatorType(u"navigation"_ns); 51 } 52 53 DOMHighResTimeStamp Duration() const override { 54 return LoadEventEnd() - StartTime(); 55 } 56 57 DOMHighResTimeStamp StartTime() const override { return 0; } 58 59 JSObject* WrapObject(JSContext* aCx, 60 JS::Handle<JSObject*> aGivenProto) override; 61 62 DOMHighResTimeStamp UnloadEventStart() const; 63 DOMHighResTimeStamp UnloadEventEnd() const; 64 65 DOMHighResTimeStamp DomInteractive() const; 66 DOMHighResTimeStamp DomContentLoadedEventStart() const; 67 DOMHighResTimeStamp DomContentLoadedEventEnd() const; 68 DOMHighResTimeStamp DomComplete() const; 69 DOMHighResTimeStamp LoadEventStart() const; 70 DOMHighResTimeStamp LoadEventEnd() const; 71 72 DOMHighResTimeStamp RedirectStart( 73 nsIPrincipal& aSubjectPrincipal) const override; 74 DOMHighResTimeStamp RedirectEnd( 75 nsIPrincipal& aSubjectPrincipal) const override; 76 77 NavigationTimingType Type() const; 78 uint16_t RedirectCount() const; 79 80 void UpdatePropertiesFromHttpChannel(nsIHttpChannel* aHttpChannel, 81 nsITimedChannel* aChannel); 82 83 /* 84 * For use with the WebIDL Func attribute to determine whether 85 * window.PerformanceNavigationTiming is exposed. 86 */ 87 static bool Enabled(JSContext* aCx, JSObject* aGlobal); 88 89 private: 90 ~PerformanceNavigationTiming() = default; 91 }; 92 93 } // namespace mozilla::dom 94 95 #endif // mozilla_dom_PerformanceNavigationTiming_h___