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 "core/timing/Performance.h" 35 36 using namespace WebCore; 37 38 namespace blink { 39 40 static double millisecondsToSeconds(unsigned long long milliseconds) 41 { 42 return static_cast<double>(milliseconds / 1000.0); 43 } 44 45 void WebPerformance::reset() 46 { 47 m_private.reset(); 48 } 49 50 void WebPerformance::assign(const WebPerformance& other) 51 { 52 m_private = other.m_private; 53 } 54 55 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 71 double WebPerformance::navigationStart() const 72 { 73 return millisecondsToSeconds(m_private->timing()->navigationStart()); 74 } 75 76 double WebPerformance::unloadEventEnd() const 77 { 78 return millisecondsToSeconds(m_private->timing()->unloadEventEnd()); 79 } 80 81 double WebPerformance::redirectStart() const 82 { 83 return millisecondsToSeconds(m_private->timing()->redirectStart()); 84 } 85 86 double WebPerformance::redirectEnd() const 87 { 88 return millisecondsToSeconds(m_private->timing()->redirectEnd()); 89 } 90 91 unsigned short WebPerformance::redirectCount() const 92 { 93 return m_private->navigation()->redirectCount(); 94 } 95 96 double WebPerformance::fetchStart() const 97 { 98 return millisecondsToSeconds(m_private->timing()->fetchStart()); 99 } 100 101 double WebPerformance::domainLookupStart() const 102 { 103 return millisecondsToSeconds(m_private->timing()->domainLookupStart()); 104 } 105 106 double WebPerformance::domainLookupEnd() const 107 { 108 return millisecondsToSeconds(m_private->timing()->domainLookupEnd()); 109 } 110 111 double WebPerformance::connectStart() const 112 { 113 return millisecondsToSeconds(m_private->timing()->connectStart()); 114 } 115 116 double WebPerformance::connectEnd() const 117 { 118 return millisecondsToSeconds(m_private->timing()->connectEnd()); 119 } 120 121 double WebPerformance::requestStart() const 122 { 123 return millisecondsToSeconds(m_private->timing()->requestStart()); 124 } 125 126 double WebPerformance::responseStart() const 127 { 128 return millisecondsToSeconds(m_private->timing()->responseStart()); 129 } 130 131 double WebPerformance::responseEnd() const 132 { 133 return millisecondsToSeconds(m_private->timing()->responseEnd()); 134 } 135 136 double WebPerformance::domLoading() const 137 { 138 return millisecondsToSeconds(m_private->timing()->domLoading()); 139 } 140 141 double WebPerformance::domInteractive() const 142 { 143 return millisecondsToSeconds(m_private->timing()->domInteractive()); 144 } 145 146 double WebPerformance::domContentLoadedEventStart() const 147 { 148 return millisecondsToSeconds(m_private->timing()->domContentLoadedEventStart()); 149 } 150 151 double WebPerformance::domContentLoadedEventEnd() const 152 { 153 return millisecondsToSeconds(m_private->timing()->domContentLoadedEventEnd()); 154 } 155 156 double WebPerformance::domComplete() const 157 { 158 return millisecondsToSeconds(m_private->timing()->domComplete()); 159 } 160 161 double WebPerformance::loadEventStart() const 162 { 163 return millisecondsToSeconds(m_private->timing()->loadEventStart()); 164 } 165 166 double WebPerformance::loadEventEnd() const 167 { 168 return millisecondsToSeconds(m_private->timing()->loadEventEnd()); 169 } 170 171 WebPerformance::WebPerformance(const PassRefPtr<Performance>& performance) 172 : m_private(performance) 173 { 174 } 175 176 WebPerformance& WebPerformance::operator=(const PassRefPtr<Performance>& performance) 177 { 178 m_private = performance; 179 return *this; 180 } 181 182 WebPerformance::operator PassRefPtr<Performance>() const 183 { 184 return m_private.get(); 185 } 186 187 } // namespace blink 188