Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
michael@0 | 2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | #ifndef nsDOMNavigationTiming_h___ |
michael@0 | 7 | #define nsDOMNavigationTiming_h___ |
michael@0 | 8 | |
michael@0 | 9 | #include "nsCOMPtr.h" |
michael@0 | 10 | #include "nsCOMArray.h" |
michael@0 | 11 | #include "mozilla/TimeStamp.h" |
michael@0 | 12 | |
michael@0 | 13 | class nsIURI; |
michael@0 | 14 | |
michael@0 | 15 | typedef unsigned long long DOMTimeMilliSec; |
michael@0 | 16 | typedef double DOMHighResTimeStamp; |
michael@0 | 17 | typedef unsigned short nsDOMPerformanceNavigationType; |
michael@0 | 18 | |
michael@0 | 19 | namespace mozilla { |
michael@0 | 20 | namespace dom { |
michael@0 | 21 | namespace PerformanceNavigation { |
michael@0 | 22 | static const nsDOMPerformanceNavigationType TYPE_NAVIGATE = 0; |
michael@0 | 23 | static const nsDOMPerformanceNavigationType TYPE_RELOAD = 1; |
michael@0 | 24 | static const nsDOMPerformanceNavigationType TYPE_BACK_FORWARD = 2; |
michael@0 | 25 | static const nsDOMPerformanceNavigationType TYPE_RESERVED = 255; |
michael@0 | 26 | } |
michael@0 | 27 | } |
michael@0 | 28 | } |
michael@0 | 29 | |
michael@0 | 30 | class nsDOMNavigationTiming MOZ_FINAL |
michael@0 | 31 | { |
michael@0 | 32 | public: |
michael@0 | 33 | nsDOMNavigationTiming(); |
michael@0 | 34 | |
michael@0 | 35 | NS_INLINE_DECL_REFCOUNTING(nsDOMNavigationTiming) |
michael@0 | 36 | |
michael@0 | 37 | nsDOMPerformanceNavigationType GetType() const { |
michael@0 | 38 | return mNavigationType; |
michael@0 | 39 | } |
michael@0 | 40 | inline DOMHighResTimeStamp GetNavigationStartHighRes() const { |
michael@0 | 41 | return mNavigationStartHighRes; |
michael@0 | 42 | } |
michael@0 | 43 | DOMTimeMilliSec GetNavigationStart() const { |
michael@0 | 44 | return static_cast<int64_t>(GetNavigationStartHighRes()); |
michael@0 | 45 | } |
michael@0 | 46 | mozilla::TimeStamp GetNavigationStartTimeStamp() const { |
michael@0 | 47 | return mNavigationStartTimeStamp; |
michael@0 | 48 | } |
michael@0 | 49 | DOMTimeMilliSec GetUnloadEventStart(); |
michael@0 | 50 | DOMTimeMilliSec GetUnloadEventEnd(); |
michael@0 | 51 | DOMTimeMilliSec GetDomLoading() const { |
michael@0 | 52 | return mDOMLoading; |
michael@0 | 53 | } |
michael@0 | 54 | DOMTimeMilliSec GetDomInteractive() const { |
michael@0 | 55 | return mDOMInteractive; |
michael@0 | 56 | } |
michael@0 | 57 | DOMTimeMilliSec GetDomContentLoadedEventStart() const { |
michael@0 | 58 | return mDOMContentLoadedEventStart; |
michael@0 | 59 | } |
michael@0 | 60 | DOMTimeMilliSec GetDomContentLoadedEventEnd() const { |
michael@0 | 61 | return mDOMContentLoadedEventEnd; |
michael@0 | 62 | } |
michael@0 | 63 | DOMTimeMilliSec GetDomComplete() const { |
michael@0 | 64 | return mDOMComplete; |
michael@0 | 65 | } |
michael@0 | 66 | DOMTimeMilliSec GetLoadEventStart() const { |
michael@0 | 67 | return mLoadEventStart; |
michael@0 | 68 | } |
michael@0 | 69 | DOMTimeMilliSec GetLoadEventEnd() const { |
michael@0 | 70 | return mLoadEventEnd; |
michael@0 | 71 | } |
michael@0 | 72 | |
michael@0 | 73 | void NotifyNavigationStart(); |
michael@0 | 74 | void NotifyFetchStart(nsIURI* aURI, nsDOMPerformanceNavigationType aNavigationType); |
michael@0 | 75 | void NotifyBeforeUnload(); |
michael@0 | 76 | void NotifyUnloadAccepted(nsIURI* aOldURI); |
michael@0 | 77 | void NotifyUnloadEventStart(); |
michael@0 | 78 | void NotifyUnloadEventEnd(); |
michael@0 | 79 | void NotifyLoadEventStart(); |
michael@0 | 80 | void NotifyLoadEventEnd(); |
michael@0 | 81 | |
michael@0 | 82 | // Document changes state to 'loading' before connecting to timing |
michael@0 | 83 | void SetDOMLoadingTimeStamp(nsIURI* aURI, mozilla::TimeStamp aValue); |
michael@0 | 84 | void NotifyDOMLoading(nsIURI* aURI); |
michael@0 | 85 | void NotifyDOMInteractive(nsIURI* aURI); |
michael@0 | 86 | void NotifyDOMComplete(nsIURI* aURI); |
michael@0 | 87 | void NotifyDOMContentLoadedStart(nsIURI* aURI); |
michael@0 | 88 | void NotifyDOMContentLoadedEnd(nsIURI* aURI); |
michael@0 | 89 | DOMTimeMilliSec TimeStampToDOM(mozilla::TimeStamp aStamp) const; |
michael@0 | 90 | |
michael@0 | 91 | inline DOMHighResTimeStamp TimeStampToDOMHighRes(mozilla::TimeStamp aStamp) |
michael@0 | 92 | { |
michael@0 | 93 | mozilla::TimeDuration duration = aStamp - mNavigationStartTimeStamp; |
michael@0 | 94 | return duration.ToMilliseconds(); |
michael@0 | 95 | } |
michael@0 | 96 | |
michael@0 | 97 | private: |
michael@0 | 98 | nsDOMNavigationTiming(const nsDOMNavigationTiming &) MOZ_DELETE; |
michael@0 | 99 | ~nsDOMNavigationTiming(); |
michael@0 | 100 | |
michael@0 | 101 | void Clear(); |
michael@0 | 102 | |
michael@0 | 103 | nsCOMPtr<nsIURI> mUnloadedURI; |
michael@0 | 104 | nsCOMPtr<nsIURI> mLoadedURI; |
michael@0 | 105 | |
michael@0 | 106 | nsDOMPerformanceNavigationType mNavigationType; |
michael@0 | 107 | DOMHighResTimeStamp mNavigationStartHighRes; |
michael@0 | 108 | mozilla::TimeStamp mNavigationStartTimeStamp; |
michael@0 | 109 | DOMTimeMilliSec DurationFromStart(); |
michael@0 | 110 | |
michael@0 | 111 | DOMTimeMilliSec mBeforeUnloadStart; |
michael@0 | 112 | DOMTimeMilliSec mUnloadStart; |
michael@0 | 113 | DOMTimeMilliSec mUnloadEnd; |
michael@0 | 114 | DOMTimeMilliSec mLoadEventStart; |
michael@0 | 115 | DOMTimeMilliSec mLoadEventEnd; |
michael@0 | 116 | |
michael@0 | 117 | DOMTimeMilliSec mDOMLoading; |
michael@0 | 118 | DOMTimeMilliSec mDOMInteractive; |
michael@0 | 119 | DOMTimeMilliSec mDOMContentLoadedEventStart; |
michael@0 | 120 | DOMTimeMilliSec mDOMContentLoadedEventEnd; |
michael@0 | 121 | DOMTimeMilliSec mDOMComplete; |
michael@0 | 122 | |
michael@0 | 123 | // Booleans to keep track of what things we've already been notified |
michael@0 | 124 | // about. We don't update those once we've been notified about them |
michael@0 | 125 | // once. |
michael@0 | 126 | bool mLoadEventStartSet : 1; |
michael@0 | 127 | bool mLoadEventEndSet : 1; |
michael@0 | 128 | bool mDOMLoadingSet : 1; |
michael@0 | 129 | bool mDOMInteractiveSet : 1; |
michael@0 | 130 | bool mDOMContentLoadedEventStartSet : 1; |
michael@0 | 131 | bool mDOMContentLoadedEventEndSet : 1; |
michael@0 | 132 | bool mDOMCompleteSet : 1; |
michael@0 | 133 | }; |
michael@0 | 134 | |
michael@0 | 135 | #endif /* nsDOMNavigationTiming_h___ */ |