1 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 : /* ***** BEGIN LICENSE BLOCK *****
3 : * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 : *
5 : * The contents of this file are subject to the Mozilla Public License Version
6 : * 1.1 (the "License"); you may not use this file except in compliance with
7 : * the License. You may obtain a copy of the License at
8 : * http://www.mozilla.org/MPL/
9 : *
10 : * Software distributed under the License is distributed on an "AS IS" basis,
11 : * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 : * for the specific language governing rights and limitations under the
13 : * License.
14 : *
15 : * The Original Code is implementation of Web Timing draft specification
16 : * http://dev.w3.org/2006/webapi/WebTiming/
17 : *
18 : * The Initial Developer of the Original Code is Google Inc.
19 : * Portions created by the Initial Developer are Copyright (C) 2010
20 : * the Initial Developer. All Rights Reserved.
21 : *
22 : * Contributor(s):
23 : * Sergey Novikov <sergeyn@google.com> (original author)
24 : * Igor Bazarny <igor.bazarny@gmail.com> (update to match bearly-final spec)
25 : *
26 : * Alternatively, the contents of this file may be used under the terms of
27 : * either of the GNU General Public License Version 2 or later (the "GPL"),
28 : * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
29 : * in which case the provisions of the GPL or the LGPL are applicable instead
30 : * of those above. If you wish to allow use of your version of this file only
31 : * under the terms of either the GPL or the LGPL, and not to allow others to
32 : * use your version of this file under the terms of the MPL, indicate your
33 : * decision by deleting the provisions above and replace them with the notice
34 : * and other provisions required by the GPL or the LGPL. If you do not delete
35 : * the provisions above, a recipient may use your version of this file under
36 : * the terms of any one of the MPL, the GPL or the LGPL.
37 : *
38 : * ***** END LICENSE BLOCK ***** */
39 :
40 : #include "nsPerformance.h"
41 : #include "TimeStamp.h"
42 : #include "nsCOMPtr.h"
43 : #include "nscore.h"
44 : #include "nsIDocShell.h"
45 : #include "nsITimedChannel.h"
46 : #include "nsDOMClassInfoID.h"
47 : #include "nsDOMNavigationTiming.h"
48 :
49 : DOMCI_DATA(PerformanceTiming, nsPerformanceTiming)
50 :
51 0 : NS_IMPL_ADDREF(nsPerformanceTiming)
52 0 : NS_IMPL_RELEASE(nsPerformanceTiming)
53 :
54 : // QueryInterface implementation for nsPerformanceTiming
55 0 : NS_INTERFACE_MAP_BEGIN(nsPerformanceTiming)
56 0 : NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMPerformanceTiming)
57 0 : NS_INTERFACE_MAP_ENTRY(nsIDOMPerformanceTiming)
58 0 : NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(PerformanceTiming)
59 0 : NS_INTERFACE_MAP_END
60 :
61 0 : nsPerformanceTiming::nsPerformanceTiming(nsDOMNavigationTiming* aDOMTiming,
62 0 : nsITimedChannel* aChannel)
63 : {
64 0 : NS_ASSERTION(aDOMTiming, "DOM timing data should be provided");
65 0 : mDOMTiming = aDOMTiming;
66 0 : mChannel = aChannel;
67 0 : }
68 :
69 0 : nsPerformanceTiming::~nsPerformanceTiming()
70 : {
71 0 : }
72 :
73 : NS_IMETHODIMP
74 0 : nsPerformanceTiming::GetNavigationStart(DOMTimeMilliSec* aTime)
75 : {
76 0 : return mDOMTiming->GetNavigationStart(aTime);
77 : }
78 :
79 : NS_IMETHODIMP
80 0 : nsPerformanceTiming::GetUnloadEventStart(DOMTimeMilliSec* aTime)
81 : {
82 0 : return mDOMTiming->GetUnloadEventStart(aTime);
83 : }
84 :
85 : NS_IMETHODIMP
86 0 : nsPerformanceTiming::GetUnloadEventEnd(DOMTimeMilliSec* aTime)
87 : {
88 0 : return mDOMTiming->GetUnloadEventEnd(aTime);
89 : }
90 :
91 : NS_IMETHODIMP
92 0 : nsPerformanceTiming::GetRedirectStart(DOMTimeMilliSec* aTime)
93 : {
94 0 : return mDOMTiming->GetRedirectStart(aTime);
95 : }
96 :
97 : NS_IMETHODIMP
98 0 : nsPerformanceTiming::GetRedirectEnd(DOMTimeMilliSec* aTime)
99 : {
100 0 : return mDOMTiming->GetRedirectEnd(aTime);
101 : }
102 :
103 : NS_IMETHODIMP
104 0 : nsPerformanceTiming::GetFetchStart(DOMTimeMilliSec* aTime)
105 : {
106 0 : return mDOMTiming->GetFetchStart(aTime);
107 : }
108 :
109 : NS_IMETHODIMP
110 0 : nsPerformanceTiming::GetDomainLookupStart(DOMTimeMilliSec* aTime)
111 : {
112 0 : if (!mChannel) {
113 0 : return GetFetchStart(aTime);
114 : }
115 0 : mozilla::TimeStamp stamp;
116 0 : mChannel->GetDomainLookupStart(&stamp);
117 0 : return mDOMTiming->TimeStampToDOMOrFetchStart(stamp, aTime);
118 : }
119 :
120 : NS_IMETHODIMP
121 0 : nsPerformanceTiming::GetDomainLookupEnd(DOMTimeMilliSec* aTime)
122 : {
123 0 : if (!mChannel) {
124 0 : return GetFetchStart(aTime);
125 : }
126 0 : mozilla::TimeStamp stamp;
127 0 : mChannel->GetDomainLookupEnd(&stamp);
128 0 : return mDOMTiming->TimeStampToDOMOrFetchStart(stamp, aTime);
129 : }
130 :
131 : NS_IMETHODIMP
132 0 : nsPerformanceTiming::GetConnectStart(DOMTimeMilliSec* aTime)
133 : {
134 0 : if (!mChannel) {
135 0 : return GetFetchStart(aTime);
136 : }
137 0 : mozilla::TimeStamp stamp;
138 0 : mChannel->GetConnectStart(&stamp);
139 0 : return mDOMTiming->TimeStampToDOMOrFetchStart(stamp, aTime);
140 : }
141 :
142 : NS_IMETHODIMP
143 0 : nsPerformanceTiming::GetConnectEnd(DOMTimeMilliSec* aTime)
144 : {
145 0 : if (!mChannel) {
146 0 : return GetFetchStart(aTime);
147 : }
148 0 : mozilla::TimeStamp stamp;
149 0 : mChannel->GetConnectEnd(&stamp);
150 0 : return mDOMTiming->TimeStampToDOMOrFetchStart(stamp, aTime);
151 : }
152 :
153 : NS_IMETHODIMP
154 0 : nsPerformanceTiming::GetRequestStart(DOMTimeMilliSec* aTime)
155 : {
156 0 : if (!mChannel) {
157 0 : return GetFetchStart(aTime);
158 : }
159 0 : mozilla::TimeStamp stamp;
160 0 : mChannel->GetRequestStart(&stamp);
161 0 : return mDOMTiming->TimeStampToDOMOrFetchStart(stamp, aTime);
162 : }
163 :
164 : NS_IMETHODIMP
165 0 : nsPerformanceTiming::GetResponseStart(DOMTimeMilliSec* aTime)
166 : {
167 0 : if (!mChannel) {
168 0 : return GetFetchStart(aTime);
169 : }
170 0 : mozilla::TimeStamp stamp;
171 0 : mChannel->GetResponseStart(&stamp);
172 0 : mozilla::TimeStamp cacheStamp;
173 0 : mChannel->GetCacheReadStart(&cacheStamp);
174 0 : if (stamp.IsNull() || (!cacheStamp.IsNull() && cacheStamp < stamp)) {
175 0 : stamp = cacheStamp;
176 : }
177 0 : return mDOMTiming->TimeStampToDOMOrFetchStart(stamp, aTime);
178 : }
179 :
180 : NS_IMETHODIMP
181 0 : nsPerformanceTiming::GetResponseEnd(DOMTimeMilliSec* aTime)
182 : {
183 0 : if (!mChannel) {
184 0 : return GetFetchStart(aTime);
185 : }
186 0 : mozilla::TimeStamp stamp;
187 0 : mChannel->GetResponseEnd(&stamp);
188 0 : mozilla::TimeStamp cacheStamp;
189 0 : mChannel->GetCacheReadEnd(&cacheStamp);
190 0 : if (stamp.IsNull() || (!cacheStamp.IsNull() && cacheStamp < stamp)) {
191 0 : stamp = cacheStamp;
192 : }
193 0 : return mDOMTiming->TimeStampToDOMOrFetchStart(stamp, aTime);
194 : }
195 :
196 : NS_IMETHODIMP
197 0 : nsPerformanceTiming::GetDomLoading(DOMTimeMilliSec* aTime)
198 : {
199 0 : return mDOMTiming->GetDomLoading(aTime);
200 : }
201 :
202 : NS_IMETHODIMP
203 0 : nsPerformanceTiming::GetDomInteractive(DOMTimeMilliSec* aTime)
204 : {
205 0 : return mDOMTiming->GetDomInteractive(aTime);
206 : }
207 :
208 : NS_IMETHODIMP
209 0 : nsPerformanceTiming::GetDomContentLoadedEventStart(DOMTimeMilliSec* aTime)
210 : {
211 0 : return mDOMTiming->GetDomContentLoadedEventStart(aTime);
212 : }
213 :
214 : NS_IMETHODIMP
215 0 : nsPerformanceTiming::GetDomContentLoadedEventEnd(DOMTimeMilliSec* aTime)
216 : {
217 0 : return mDOMTiming->GetDomContentLoadedEventEnd(aTime);
218 : }
219 :
220 : NS_IMETHODIMP
221 0 : nsPerformanceTiming::GetDomComplete(DOMTimeMilliSec* aTime)
222 : {
223 0 : return mDOMTiming->GetDomComplete(aTime);
224 : }
225 :
226 : NS_IMETHODIMP
227 0 : nsPerformanceTiming::GetLoadEventStart(DOMTimeMilliSec* aTime)
228 : {
229 0 : return mDOMTiming->GetLoadEventStart(aTime);
230 : }
231 :
232 : NS_IMETHODIMP
233 0 : nsPerformanceTiming::GetLoadEventEnd(DOMTimeMilliSec* aTime)
234 : {
235 0 : return mDOMTiming->GetLoadEventEnd(aTime);
236 : }
237 :
238 :
239 :
240 : DOMCI_DATA(PerformanceNavigation, nsPerformanceNavigation)
241 :
242 0 : NS_IMPL_ADDREF(nsPerformanceNavigation)
243 0 : NS_IMPL_RELEASE(nsPerformanceNavigation)
244 :
245 : // QueryInterface implementation for nsPerformanceNavigation
246 0 : NS_INTERFACE_MAP_BEGIN(nsPerformanceNavigation)
247 0 : NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMPerformanceNavigation)
248 0 : NS_INTERFACE_MAP_ENTRY(nsIDOMPerformanceNavigation)
249 0 : NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(PerformanceNavigation)
250 0 : NS_INTERFACE_MAP_END
251 :
252 0 : nsPerformanceNavigation::nsPerformanceNavigation(nsDOMNavigationTiming* aData)
253 : {
254 0 : NS_ASSERTION(aData, "Timing data should be provided");
255 0 : mData = aData;
256 0 : }
257 :
258 0 : nsPerformanceNavigation::~nsPerformanceNavigation()
259 : {
260 0 : }
261 :
262 : NS_IMETHODIMP
263 0 : nsPerformanceNavigation::GetType(
264 : nsDOMPerformanceNavigationType* aNavigationType)
265 : {
266 0 : return mData->GetType(aNavigationType);
267 : }
268 :
269 : NS_IMETHODIMP
270 0 : nsPerformanceNavigation::GetRedirectCount(PRUint16* aRedirectCount)
271 : {
272 0 : return mData->GetRedirectCount(aRedirectCount);
273 : }
274 :
275 :
276 : DOMCI_DATA(Performance, nsPerformance)
277 :
278 0 : NS_IMPL_ADDREF(nsPerformance)
279 0 : NS_IMPL_RELEASE(nsPerformance)
280 :
281 0 : nsPerformance::nsPerformance(nsDOMNavigationTiming* aDOMTiming,
282 0 : nsITimedChannel* aChannel)
283 : {
284 0 : NS_ASSERTION(aDOMTiming, "DOM timing data should be provided");
285 0 : mDOMTiming = aDOMTiming;
286 0 : mChannel = aChannel;
287 0 : }
288 :
289 0 : nsPerformance::~nsPerformance()
290 : {
291 0 : }
292 :
293 : // QueryInterface implementation for nsPerformance
294 0 : NS_INTERFACE_MAP_BEGIN(nsPerformance)
295 0 : NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMPerformance)
296 0 : NS_INTERFACE_MAP_ENTRY(nsIDOMPerformance)
297 0 : NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(Performance)
298 0 : NS_INTERFACE_MAP_END
299 :
300 : //
301 : // nsIDOMPerformance methods
302 : //
303 : NS_IMETHODIMP
304 0 : nsPerformance::GetTiming(nsIDOMPerformanceTiming** aTiming)
305 : {
306 0 : if (!mTiming) {
307 0 : mTiming = new nsPerformanceTiming(mDOMTiming, mChannel);
308 : }
309 0 : NS_IF_ADDREF(*aTiming = mTiming);
310 0 : return NS_OK;
311 : }
312 :
313 : NS_IMETHODIMP
314 0 : nsPerformance::GetNavigation(nsIDOMPerformanceNavigation** aNavigation)
315 : {
316 0 : if (!mNavigation) {
317 0 : mNavigation = new nsPerformanceNavigation(mDOMTiming);
318 : }
319 0 : NS_IF_ADDREF(*aNavigation = mNavigation);
320 0 : return NS_OK;
321 : }
|