This source file includes following definitions.
- toIntegerMilliseconds
- navigationStart
- unloadEventStart
- unloadEventEnd
- redirectStart
- redirectEnd
- fetchStart
- domainLookupStart
- domainLookupEnd
- connectStart
- connectEnd
- secureConnectionStart
- requestStart
- responseStart
- responseEnd
- domLoading
- domInteractive
- domContentLoadedEventStart
- domContentLoadedEventEnd
- domComplete
- loadEventStart
- loadEventEnd
- documentLoader
- documentTiming
- documentLoadTiming
- resourceLoadTiming
- monotonicTimeToIntegerMilliseconds
#include "config.h"
#include "core/timing/PerformanceTiming.h"
#include "core/dom/Document.h"
#include "core/dom/DocumentTiming.h"
#include "core/frame/LocalFrame.h"
#include "core/loader/DocumentLoadTiming.h"
#include "core/loader/DocumentLoader.h"
#include "core/loader/FrameLoader.h"
#include "platform/network/ResourceLoadTiming.h"
#include "platform/network/ResourceResponse.h"
namespace WebCore {
static unsigned long long toIntegerMilliseconds(double seconds)
{
ASSERT(seconds >= 0);
return static_cast<unsigned long long>(seconds * 1000.0);
}
PerformanceTiming::PerformanceTiming(LocalFrame* frame)
: DOMWindowProperty(frame)
{
ScriptWrappable::init(this);
}
unsigned long long PerformanceTiming::navigationStart() const
{
DocumentLoadTiming* timing = documentLoadTiming();
if (!timing)
return 0;
return monotonicTimeToIntegerMilliseconds(timing->navigationStart());
}
unsigned long long PerformanceTiming::unloadEventStart() const
{
DocumentLoadTiming* timing = documentLoadTiming();
if (!timing)
return 0;
if (timing->hasCrossOriginRedirect() || !timing->hasSameOriginAsPreviousDocument())
return 0;
return monotonicTimeToIntegerMilliseconds(timing->unloadEventStart());
}
unsigned long long PerformanceTiming::unloadEventEnd() const
{
DocumentLoadTiming* timing = documentLoadTiming();
if (!timing)
return 0;
if (timing->hasCrossOriginRedirect() || !timing->hasSameOriginAsPreviousDocument())
return 0;
return monotonicTimeToIntegerMilliseconds(timing->unloadEventEnd());
}
unsigned long long PerformanceTiming::redirectStart() const
{
DocumentLoadTiming* timing = documentLoadTiming();
if (!timing)
return 0;
if (timing->hasCrossOriginRedirect())
return 0;
return monotonicTimeToIntegerMilliseconds(timing->redirectStart());
}
unsigned long long PerformanceTiming::redirectEnd() const
{
DocumentLoadTiming* timing = documentLoadTiming();
if (!timing)
return 0;
if (timing->hasCrossOriginRedirect())
return 0;
return monotonicTimeToIntegerMilliseconds(timing->redirectEnd());
}
unsigned long long PerformanceTiming::fetchStart() const
{
DocumentLoadTiming* timing = documentLoadTiming();
if (!timing)
return 0;
return monotonicTimeToIntegerMilliseconds(timing->fetchStart());
}
unsigned long long PerformanceTiming::domainLookupStart() const
{
ResourceLoadTiming* timing = resourceLoadTiming();
if (!timing)
return fetchStart();
double dnsStart = timing->dnsStart;
if (dnsStart == 0.0)
return fetchStart();
return monotonicTimeToIntegerMilliseconds(dnsStart);
}
unsigned long long PerformanceTiming::domainLookupEnd() const
{
ResourceLoadTiming* timing = resourceLoadTiming();
if (!timing)
return domainLookupStart();
double dnsEnd = timing->dnsEnd;
if (dnsEnd == 0.0)
return domainLookupStart();
return monotonicTimeToIntegerMilliseconds(dnsEnd);
}
unsigned long long PerformanceTiming::connectStart() const
{
DocumentLoader* loader = documentLoader();
if (!loader)
return domainLookupEnd();
ResourceLoadTiming* timing = loader->response().resourceLoadTiming();
if (!timing)
return domainLookupEnd();
double connectStart = timing->connectStart;
if (connectStart == 0.0 || loader->response().connectionReused())
return domainLookupEnd();
if (timing->dnsEnd > 0.0 && timing->dnsEnd > connectStart)
connectStart = timing->dnsEnd;
return monotonicTimeToIntegerMilliseconds(connectStart);
}
unsigned long long PerformanceTiming::connectEnd() const
{
DocumentLoader* loader = documentLoader();
if (!loader)
return connectStart();
ResourceLoadTiming* timing = loader->response().resourceLoadTiming();
if (!timing)
return connectStart();
double connectEnd = timing->connectEnd;
if (connectEnd == 0.0 || loader->response().connectionReused())
return connectStart();
return monotonicTimeToIntegerMilliseconds(connectEnd);
}
unsigned long long PerformanceTiming::secureConnectionStart() const
{
DocumentLoader* loader = documentLoader();
if (!loader)
return 0;
ResourceLoadTiming* timing = loader->response().resourceLoadTiming();
if (!timing)
return 0;
double sslStart = timing->sslStart;
if (sslStart == 0.0)
return 0;
return monotonicTimeToIntegerMilliseconds(sslStart);
}
unsigned long long PerformanceTiming::requestStart() const
{
ResourceLoadTiming* timing = resourceLoadTiming();
if (!timing || timing->sendStart == 0.0)
return connectEnd();
return monotonicTimeToIntegerMilliseconds(timing->sendStart);
}
unsigned long long PerformanceTiming::responseStart() const
{
ResourceLoadTiming* timing = resourceLoadTiming();
if (!timing || timing->receiveHeadersEnd == 0.0)
return requestStart();
return monotonicTimeToIntegerMilliseconds(timing->receiveHeadersEnd);
}
unsigned long long PerformanceTiming::responseEnd() const
{
DocumentLoadTiming* timing = documentLoadTiming();
if (!timing)
return 0;
return monotonicTimeToIntegerMilliseconds(timing->responseEnd());
}
unsigned long long PerformanceTiming::domLoading() const
{
const DocumentTiming* timing = documentTiming();
if (!timing)
return fetchStart();
return monotonicTimeToIntegerMilliseconds(timing->domLoading);
}
unsigned long long PerformanceTiming::domInteractive() const
{
const DocumentTiming* timing = documentTiming();
if (!timing)
return 0;
return monotonicTimeToIntegerMilliseconds(timing->domInteractive);
}
unsigned long long PerformanceTiming::domContentLoadedEventStart() const
{
const DocumentTiming* timing = documentTiming();
if (!timing)
return 0;
return monotonicTimeToIntegerMilliseconds(timing->domContentLoadedEventStart);
}
unsigned long long PerformanceTiming::domContentLoadedEventEnd() const
{
const DocumentTiming* timing = documentTiming();
if (!timing)
return 0;
return monotonicTimeToIntegerMilliseconds(timing->domContentLoadedEventEnd);
}
unsigned long long PerformanceTiming::domComplete() const
{
const DocumentTiming* timing = documentTiming();
if (!timing)
return 0;
return monotonicTimeToIntegerMilliseconds(timing->domComplete);
}
unsigned long long PerformanceTiming::loadEventStart() const
{
DocumentLoadTiming* timing = documentLoadTiming();
if (!timing)
return 0;
return monotonicTimeToIntegerMilliseconds(timing->loadEventStart());
}
unsigned long long PerformanceTiming::loadEventEnd() const
{
DocumentLoadTiming* timing = documentLoadTiming();
if (!timing)
return 0;
return monotonicTimeToIntegerMilliseconds(timing->loadEventEnd());
}
DocumentLoader* PerformanceTiming::documentLoader() const
{
if (!m_frame)
return 0;
return m_frame->loader().documentLoader();
}
const DocumentTiming* PerformanceTiming::documentTiming() const
{
if (!m_frame)
return 0;
Document* document = m_frame->document();
if (!document)
return 0;
return &document->timing();
}
DocumentLoadTiming* PerformanceTiming::documentLoadTiming() const
{
DocumentLoader* loader = documentLoader();
if (!loader)
return 0;
return loader->timing();
}
ResourceLoadTiming* PerformanceTiming::resourceLoadTiming() const
{
DocumentLoader* loader = documentLoader();
if (!loader)
return 0;
return loader->response().resourceLoadTiming();
}
unsigned long long PerformanceTiming::monotonicTimeToIntegerMilliseconds(double monotonicSeconds) const
{
ASSERT(monotonicSeconds >= 0);
const DocumentLoadTiming* timing = documentLoadTiming();
if (!timing)
return 0;
return toIntegerMilliseconds(timing->monotonicTimeToPseudoWallTime(monotonicSeconds));
}
}