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