2 * Copyright (C) 2011 Google, Inc. All Rights Reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY GOOGLE INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GOOGLE INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 #include "core/loader/DocumentLoadTiming.h"
29 #include "core/loader/DocumentLoader.h"
30 #include "platform/TraceEvent.h"
31 #include "platform/weborigin/SecurityOrigin.h"
32 #include "wtf/RawPtr.h"
33 #include "wtf/RefPtr.h"
37 DocumentLoadTiming::DocumentLoadTiming(DocumentLoader
& documentLoader
)
38 : m_referenceMonotonicTime(0.0)
39 , m_referenceWallTime(0.0)
40 , m_navigationStart(0.0)
41 , m_unloadEventStart(0.0)
42 , m_unloadEventEnd(0.0)
43 , m_redirectStart(0.0)
48 , m_loadEventStart(0.0)
50 , m_hasCrossOriginRedirect(false)
51 , m_hasSameOriginAsPreviousDocument(false)
52 , m_documentLoader(documentLoader
)
56 DEFINE_TRACE(DocumentLoadTiming
)
58 visitor
->trace(m_documentLoader
);
61 void DocumentLoadTiming::notifyDocumentTimingChanged()
64 m_documentLoader
->didChangePerformanceTiming();
67 double DocumentLoadTiming::monotonicTimeToZeroBasedDocumentTime(double monotonicTime
) const
71 return monotonicTime
- m_referenceMonotonicTime
;
74 double DocumentLoadTiming::monotonicTimeToPseudoWallTime(double monotonicTime
) const
78 return m_referenceWallTime
+ monotonicTime
- m_referenceMonotonicTime
;
81 double DocumentLoadTiming::pseudoWallTimeToMonotonicTime(double pseudoWallTime
) const
85 return m_referenceMonotonicTime
+ pseudoWallTime
- m_referenceWallTime
;
88 void DocumentLoadTiming::markNavigationStart()
90 TRACE_EVENT_MARK("blink.user_timing", "navigationStart");
91 ASSERT(!m_navigationStart
&& !m_referenceMonotonicTime
&& !m_referenceWallTime
);
93 m_navigationStart
= m_referenceMonotonicTime
= monotonicallyIncreasingTime();
94 m_referenceWallTime
= currentTime();
95 notifyDocumentTimingChanged();
98 void DocumentLoadTiming::setNavigationStart(double navigationStart
)
100 TRACE_EVENT_MARK_WITH_TIMESTAMP("blink.user_timing", "navigationStart", navigationStart
);
101 ASSERT(m_referenceMonotonicTime
&& m_referenceWallTime
);
102 m_navigationStart
= navigationStart
;
104 // |m_referenceMonotonicTime| and |m_referenceWallTime| represent
105 // navigationStart. When the embedder sets navigationStart (because the
106 // navigation started earlied on the browser side), we need to adjust these
108 m_referenceWallTime
= monotonicTimeToPseudoWallTime(navigationStart
);
109 m_referenceMonotonicTime
= navigationStart
;
110 notifyDocumentTimingChanged();
113 void DocumentLoadTiming::addRedirect(const KURL
& redirectingUrl
, const KURL
& redirectedUrl
)
116 if (!m_redirectStart
) {
117 setRedirectStart(m_fetchStart
);
122 // Check if the redirected url is allowed to access the redirecting url's timing information.
123 RefPtr
<SecurityOrigin
> redirectedSecurityOrigin
= SecurityOrigin::create(redirectedUrl
);
124 m_hasCrossOriginRedirect
|= !redirectedSecurityOrigin
->canRequest(redirectingUrl
);
127 void DocumentLoadTiming::markUnloadEventStart()
129 TRACE_EVENT_MARK("blink.user_timing", "unloadEventStart");
130 m_unloadEventStart
= monotonicallyIncreasingTime();
131 notifyDocumentTimingChanged();
134 void DocumentLoadTiming::markUnloadEventEnd()
136 TRACE_EVENT_MARK("blink.user_timing", "unloadEventEnd");
137 m_unloadEventEnd
= monotonicallyIncreasingTime();
138 notifyDocumentTimingChanged();
141 void DocumentLoadTiming::markFetchStart()
143 TRACE_EVENT_MARK("blink.user_timing", "fetchStart");
144 m_fetchStart
= monotonicallyIncreasingTime();
145 notifyDocumentTimingChanged();
148 void DocumentLoadTiming::setResponseEnd(double responseEnd
)
150 TRACE_EVENT_MARK_WITH_TIMESTAMP("blink.user_timing", "responseEnd", responseEnd
);
151 m_responseEnd
= responseEnd
;
152 notifyDocumentTimingChanged();
155 void DocumentLoadTiming::markLoadEventStart()
157 TRACE_EVENT_MARK("blink.user_timing", "loadEventStart");
158 m_loadEventStart
= monotonicallyIncreasingTime();
159 notifyDocumentTimingChanged();
162 void DocumentLoadTiming::markLoadEventEnd()
164 TRACE_EVENT_MARK("blink.user_timing", "loadEventEnd");
165 m_loadEventEnd
= monotonicallyIncreasingTime();
166 notifyDocumentTimingChanged();
169 void DocumentLoadTiming::setRedirectStart(double redirectStart
)
171 TRACE_EVENT_MARK_WITH_TIMESTAMP("blink.user_timing", "redirectStart", redirectStart
);
172 m_redirectStart
= m_fetchStart
;
173 notifyDocumentTimingChanged();
176 void DocumentLoadTiming::markRedirectEnd()
178 TRACE_EVENT_MARK("blink.user_timing", "redirectEnd");
179 m_redirectEnd
= monotonicallyIncreasingTime();
180 notifyDocumentTimingChanged();