1/*
2 * Copyright (C) 2011 Google, Inc. All Rights Reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
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.
12 *
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.
24 */
25
26#include "config.h"
27#include "LoadTiming.h"
28
29#include "Document.h"
30#include "DocumentLoader.h"
31#include "Frame.h"
32#include "SecurityOrigin.h"
33#include <wtf/RefPtr.h>
34
35namespace WebCore {
36
37Seconds LoadTiming::secondsSinceStartTime(MonotonicTime timeStamp) const
38{
39 if (!timeStamp)
40 return Seconds(0);
41
42 return timeStamp - m_referenceMonotonicTime;
43}
44
45WallTime LoadTiming::monotonicTimeToPseudoWallTime(MonotonicTime timeStamp) const
46{
47 if (!timeStamp)
48 return WallTime::fromRawSeconds(0);
49
50 return m_referenceWallTime + (timeStamp - m_referenceMonotonicTime);
51}
52
53void LoadTiming::markStartTime()
54{
55 ASSERT(!m_startTime && !m_referenceMonotonicTime && !m_referenceWallTime);
56
57 m_referenceMonotonicTime = m_startTime = MonotonicTime::now();
58 m_referenceWallTime = WallTime::now();
59}
60
61void LoadTiming::addRedirect(const URL& redirectingUrl, const URL& redirectedUrl)
62{
63 m_redirectCount++;
64 if (!m_redirectStart)
65 m_redirectStart = m_fetchStart;
66 m_redirectEnd = m_fetchStart = MonotonicTime::now();
67 // Check if the redirected url is allowed to access the redirecting url's timing information.
68 Ref<SecurityOrigin> redirectedSecurityOrigin(SecurityOrigin::create(redirectedUrl));
69 m_hasCrossOriginRedirect = !redirectedSecurityOrigin.get().canRequest(redirectingUrl);
70}
71
72LoadTiming LoadTiming::isolatedCopy() const
73{
74 LoadTiming result;
75
76 result.m_referenceWallTime = m_referenceWallTime;
77 result.m_referenceMonotonicTime = m_referenceMonotonicTime;
78 result.m_startTime = m_startTime;
79 result.m_unloadEventStart = m_unloadEventStart;
80 result.m_unloadEventEnd = m_unloadEventEnd;
81 result.m_redirectStart = m_redirectStart;
82 result.m_redirectEnd = m_redirectEnd;
83 result.m_fetchStart = m_fetchStart;
84 result.m_responseEnd = m_responseEnd;
85 result.m_loadEventStart = m_loadEventStart;
86 result.m_loadEventEnd = m_loadEventEnd;
87 result.m_redirectCount = m_redirectCount;
88 result.m_hasCrossOriginRedirect = m_hasCrossOriginRedirect;
89 result.m_hasSameOriginAsPreviousDocument = m_hasSameOriginAsPreviousDocument;
90
91 return result;
92}
93
94} // namespace WebCore
95