Bumping manifests a=b2g-bump
[gecko.git] / dom / base / nsDOMNavigationTiming.cpp
blobf381024e31b5a922eb461bb5c493da960273bb2b
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/. */
6 #include "nsDOMNavigationTiming.h"
7 #include "nsPerformance.h"
8 #include "nsCOMPtr.h"
9 #include "nsContentUtils.h"
10 #include "nsIScriptSecurityManager.h"
11 #include "prtime.h"
12 #include "nsIURI.h"
13 #include "mozilla/TimeStamp.h"
15 nsDOMNavigationTiming::nsDOMNavigationTiming()
17 Clear();
20 nsDOMNavigationTiming::~nsDOMNavigationTiming()
24 void
25 nsDOMNavigationTiming::Clear()
27 mNavigationType = mozilla::dom::PerformanceNavigation::TYPE_RESERVED;
28 mNavigationStartHighRes = 0;
29 mBeforeUnloadStart = 0;
30 mUnloadStart = 0;
31 mUnloadEnd = 0;
32 mLoadEventStart = 0;
33 mLoadEventEnd = 0;
34 mDOMLoading = 0;
35 mDOMInteractive = 0;
36 mDOMContentLoadedEventStart = 0;
37 mDOMContentLoadedEventEnd = 0;
38 mDOMComplete = 0;
40 mLoadEventStartSet = false;
41 mLoadEventEndSet = false;
42 mDOMLoadingSet = false;
43 mDOMInteractiveSet = false;
44 mDOMContentLoadedEventStartSet = false;
45 mDOMContentLoadedEventEndSet = false;
46 mDOMCompleteSet = false;
49 DOMTimeMilliSec
50 nsDOMNavigationTiming::TimeStampToDOM(mozilla::TimeStamp aStamp) const
52 if (aStamp.IsNull()) {
53 return 0;
55 mozilla::TimeDuration duration = aStamp - mNavigationStartTimeStamp;
56 return GetNavigationStart() + static_cast<int64_t>(duration.ToMilliseconds());
59 DOMTimeMilliSec nsDOMNavigationTiming::DurationFromStart(){
60 return TimeStampToDOM(mozilla::TimeStamp::Now());
63 void
64 nsDOMNavigationTiming::NotifyNavigationStart()
66 mNavigationStartHighRes = (double)PR_Now() / PR_USEC_PER_MSEC;
67 mNavigationStartTimeStamp = mozilla::TimeStamp::Now();
70 void
71 nsDOMNavigationTiming::NotifyFetchStart(nsIURI* aURI, nsDOMPerformanceNavigationType aNavigationType)
73 mNavigationType = aNavigationType;
74 // At the unload event time we don't really know the loading uri.
75 // Need it for later check for unload timing access.
76 mLoadedURI = aURI;
79 void
80 nsDOMNavigationTiming::NotifyBeforeUnload()
82 mBeforeUnloadStart = DurationFromStart();
85 void
86 nsDOMNavigationTiming::NotifyUnloadAccepted(nsIURI* aOldURI)
88 mUnloadStart = mBeforeUnloadStart;
89 mUnloadedURI = aOldURI;
92 void
93 nsDOMNavigationTiming::NotifyUnloadEventStart()
95 mUnloadStart = DurationFromStart();
98 void
99 nsDOMNavigationTiming::NotifyUnloadEventEnd()
101 mUnloadEnd = DurationFromStart();
104 void
105 nsDOMNavigationTiming::NotifyLoadEventStart()
107 if (!mLoadEventStartSet) {
108 mLoadEventStart = DurationFromStart();
109 mLoadEventStartSet = true;
113 void
114 nsDOMNavigationTiming::NotifyLoadEventEnd()
116 if (!mLoadEventEndSet) {
117 mLoadEventEnd = DurationFromStart();
118 mLoadEventEndSet = true;
122 void
123 nsDOMNavigationTiming::SetDOMLoadingTimeStamp(nsIURI* aURI, mozilla::TimeStamp aValue)
125 if (!mDOMLoadingSet) {
126 mLoadedURI = aURI;
127 mDOMLoading = TimeStampToDOM(aValue);
128 mDOMLoadingSet = true;
132 void
133 nsDOMNavigationTiming::NotifyDOMLoading(nsIURI* aURI)
135 if (!mDOMLoadingSet) {
136 mLoadedURI = aURI;
137 mDOMLoading = DurationFromStart();
138 mDOMLoadingSet = true;
142 void
143 nsDOMNavigationTiming::NotifyDOMInteractive(nsIURI* aURI)
145 if (!mDOMInteractiveSet) {
146 mLoadedURI = aURI;
147 mDOMInteractive = DurationFromStart();
148 mDOMInteractiveSet = true;
152 void
153 nsDOMNavigationTiming::NotifyDOMComplete(nsIURI* aURI)
155 if (!mDOMCompleteSet) {
156 mLoadedURI = aURI;
157 mDOMComplete = DurationFromStart();
158 mDOMCompleteSet = true;
162 void
163 nsDOMNavigationTiming::NotifyDOMContentLoadedStart(nsIURI* aURI)
165 if (!mDOMContentLoadedEventStartSet) {
166 mLoadedURI = aURI;
167 mDOMContentLoadedEventStart = DurationFromStart();
168 mDOMContentLoadedEventStartSet = true;
172 void
173 nsDOMNavigationTiming::NotifyDOMContentLoadedEnd(nsIURI* aURI)
175 if (!mDOMContentLoadedEventEndSet) {
176 mLoadedURI = aURI;
177 mDOMContentLoadedEventEnd = DurationFromStart();
178 mDOMContentLoadedEventEndSet = true;
182 DOMTimeMilliSec
183 nsDOMNavigationTiming::GetUnloadEventStart()
185 nsIScriptSecurityManager* ssm = nsContentUtils::GetSecurityManager();
186 nsresult rv = ssm->CheckSameOriginURI(mLoadedURI, mUnloadedURI, false);
187 if (NS_SUCCEEDED(rv)) {
188 return mUnloadStart;
190 return 0;
193 DOMTimeMilliSec
194 nsDOMNavigationTiming::GetUnloadEventEnd()
196 nsIScriptSecurityManager* ssm = nsContentUtils::GetSecurityManager();
197 nsresult rv = ssm->CheckSameOriginURI(mLoadedURI, mUnloadedURI, false);
198 if (NS_SUCCEEDED(rv)) {
199 return mUnloadEnd;
201 return 0;