1 /*
2 * Copyright (C) 2010 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 are
6 * met:
7 *
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
13 * distribution.
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
31 #include "config.h"
32 #include "WebPerformance.h"
33
34 #include "Performance.h"
35
36 using namespace WebCore;
37
38 namespace WebKit {
39
millisecondsToSeconds(unsigned long long milliseconds)40 static double millisecondsToSeconds(unsigned long long milliseconds)
41 {
42 return static_cast<double>(milliseconds / 1000.0);
43 }
44
reset()45 void WebPerformance::reset()
46 {
47 m_private.reset();
48 }
49
assign(const WebPerformance & other)50 void WebPerformance::assign(const WebPerformance& other)
51 {
52 m_private = other.m_private;
53 }
54
navigationType() const55 WebNavigationType WebPerformance::navigationType() const
56 {
57 switch (m_private->navigation()->type()) {
58 case PerformanceNavigation::TYPE_NAVIGATE:
59 return WebNavigationTypeOther;
60 case PerformanceNavigation::TYPE_RELOAD:
61 return WebNavigationTypeReload;
62 case PerformanceNavigation::TYPE_BACK_FORWARD:
63 return WebNavigationTypeBackForward;
64 case PerformanceNavigation::TYPE_RESERVED:
65 return WebNavigationTypeOther;
66 }
67 ASSERT_NOT_REACHED();
68 return WebNavigationTypeOther;
69 }
70
navigationStart() const71 double WebPerformance::navigationStart() const
72 {
73 return millisecondsToSeconds(m_private->timing()->navigationStart());
74 }
75
unloadEventEnd() const76 double WebPerformance::unloadEventEnd() const
77 {
78 return millisecondsToSeconds(m_private->timing()->unloadEventEnd());
79 }
80
redirectStart() const81 double WebPerformance::redirectStart() const
82 {
83 return millisecondsToSeconds(m_private->timing()->redirectStart());
84 }
85
redirectEnd() const86 double WebPerformance::redirectEnd() const
87 {
88 return millisecondsToSeconds(m_private->timing()->redirectEnd());
89 }
90
redirectCount() const91 unsigned short WebPerformance::redirectCount() const
92 {
93 return m_private->navigation()->redirectCount();
94 }
95
fetchStart() const96 double WebPerformance::fetchStart() const
97 {
98 return millisecondsToSeconds(m_private->timing()->fetchStart());
99 }
100
domainLookupStart() const101 double WebPerformance::domainLookupStart() const
102 {
103 return millisecondsToSeconds(m_private->timing()->domainLookupStart());
104 }
105
domainLookupEnd() const106 double WebPerformance::domainLookupEnd() const
107 {
108 return millisecondsToSeconds(m_private->timing()->domainLookupEnd());
109 }
110
connectStart() const111 double WebPerformance::connectStart() const
112 {
113 return millisecondsToSeconds(m_private->timing()->connectStart());
114 }
115
connectEnd() const116 double WebPerformance::connectEnd() const
117 {
118 return millisecondsToSeconds(m_private->timing()->connectEnd());
119 }
120
requestStart() const121 double WebPerformance::requestStart() const
122 {
123 return millisecondsToSeconds(m_private->timing()->requestStart());
124 }
125
responseStart() const126 double WebPerformance::responseStart() const
127 {
128 return millisecondsToSeconds(m_private->timing()->responseStart());
129 }
130
responseEnd() const131 double WebPerformance::responseEnd() const
132 {
133 return millisecondsToSeconds(m_private->timing()->responseEnd());
134 }
135
domLoading() const136 double WebPerformance::domLoading() const
137 {
138 return millisecondsToSeconds(m_private->timing()->domLoading());
139 }
140
domInteractive() const141 double WebPerformance::domInteractive() const
142 {
143 return millisecondsToSeconds(m_private->timing()->domInteractive());
144 }
145
domContentLoadedEventStart() const146 double WebPerformance::domContentLoadedEventStart() const
147 {
148 return millisecondsToSeconds(m_private->timing()->domContentLoadedEventStart());
149 }
150
domContentLoadedEventEnd() const151 double WebPerformance::domContentLoadedEventEnd() const
152 {
153 return millisecondsToSeconds(m_private->timing()->domContentLoadedEventEnd());
154 }
155
domComplete() const156 double WebPerformance::domComplete() const
157 {
158 return millisecondsToSeconds(m_private->timing()->domComplete());
159 }
160
loadEventStart() const161 double WebPerformance::loadEventStart() const
162 {
163 return millisecondsToSeconds(m_private->timing()->loadEventStart());
164 }
165
loadEventEnd() const166 double WebPerformance::loadEventEnd() const
167 {
168 return millisecondsToSeconds(m_private->timing()->loadEventEnd());
169 }
170
WebPerformance(const PassRefPtr<Performance> & performance)171 WebPerformance::WebPerformance(const PassRefPtr<Performance>& performance)
172 : m_private(performance)
173 {
174 }
175
operator =(const PassRefPtr<Performance> & performance)176 WebPerformance& WebPerformance::operator=(const PassRefPtr<Performance>& performance)
177 {
178 m_private = performance;
179 return *this;
180 }
181
operator PassRefPtr<Performance>() const182 WebPerformance::operator PassRefPtr<Performance>() const
183 {
184 return m_private.get();
185 }
186
187 } // namespace WebKit
188