Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2012 Google Inc. All rights reserved. |
| 3 * Copyright (C) 2012 Intel Inc. All rights reserved. | 3 * Copyright (C) 2012 Intel Inc. All rights reserved. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions are | 6 * modification, are permitted provided that the following conditions are |
| 7 * met: | 7 * met: |
| 8 * | 8 * |
| 9 * * Redistributions of source code must retain the above copyright | 9 * * Redistributions of source code must retain the above copyright |
| 10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 31 | 31 |
| 32 #include "config.h" | 32 #include "config.h" |
| 33 #include "PerformanceResourceTiming.h" | 33 #include "PerformanceResourceTiming.h" |
| 34 | 34 |
| 35 #include "Document.h" | 35 #include "Document.h" |
| 36 #include "DocumentLoadTiming.h" | 36 #include "DocumentLoadTiming.h" |
| 37 #include "DocumentLoader.h" | 37 #include "DocumentLoader.h" |
| 38 #include "KURL.h" | 38 #include "KURL.h" |
| 39 #include "ResourceRequest.h" | 39 #include "ResourceRequest.h" |
| 40 #include "ResourceResponse.h" | 40 #include "ResourceResponse.h" |
| 41 #include "ResourceTimingInfo.h" | |
| 41 #include "SecurityOrigin.h" | 42 #include "SecurityOrigin.h" |
| 42 #include <wtf/Vector.h> | 43 #include <wtf/Vector.h> |
| 43 | 44 |
| 44 namespace WebCore { | 45 namespace WebCore { |
| 45 | 46 |
| 46 static double monotonicTimeToDocumentMilliseconds(Document* document, double sec onds) | 47 static double monotonicTimeToDocumentMilliseconds(Document* document, double sec onds) |
| 47 { | 48 { |
| 48 ASSERT(seconds >= 0.0); | 49 ASSERT(seconds >= 0.0); |
| 49 return document->loader()->timing()->monotonicTimeToZeroBasedDocumentTime(se conds) * 1000.0; | 50 return document->loader()->timing()->monotonicTimeToZeroBasedDocumentTime(se conds) * 1000.0; |
| 50 } | 51 } |
| 51 | 52 |
| 52 static bool passesTimingAllowCheck(const ResourceResponse& response, Document* r equestingDocument) | 53 PerformanceResourceTiming::PerformanceResourceTiming(const ResourceTimingInfo& i nfo, Document* requestingDocument, double startTime, double lastRedirectEndTime, bool shouldReportDetails) |
| 53 { | 54 : PerformanceEntry(info.initialRequest().url().string(), "resource", monoton icTimeToDocumentMilliseconds(requestingDocument, startTime), monotonicTimeToDocu mentMilliseconds(requestingDocument, info.loadFinishTime())) |
| 54 AtomicallyInitializedStatic(AtomicString&, timingAllowOrigin = *new AtomicSt ring("timing-allow-origin")); | 55 , m_initiatorType(info.initiatorType()) |
| 55 | 56 , m_timing(info.finalResponse().resourceLoadTiming()) |
| 56 RefPtr<SecurityOrigin> resourceOrigin = SecurityOrigin::create(response.url( )); | 57 , m_lastRedirectEndTime(lastRedirectEndTime) |
| 57 if (resourceOrigin->isSameSchemeHostPort(requestingDocument->securityOrigin( ))) | 58 , m_finishTime(info.loadFinishTime()) |
| 58 return true; | 59 , m_didReuseConnection(info.finalResponse().connectionReused()) |
| 59 | 60 , m_shouldReportDetails(shouldReportDetails) |
| 60 const String& timingAllowOriginString = response.httpHeaderField(timingAllow Origin); | |
| 61 if (timingAllowOriginString.isEmpty() || equalIgnoringCase(timingAllowOrigin String, "null")) | |
| 62 return false; | |
| 63 | |
| 64 if (timingAllowOriginString == "*") | |
| 65 return true; | |
| 66 | |
| 67 const String& securityOrigin = requestingDocument->securityOrigin()->toStrin g(); | |
| 68 Vector<String> timingAllowOrigins; | |
| 69 timingAllowOriginString.split(" ", timingAllowOrigins); | |
| 70 for (size_t i = 0; i < timingAllowOrigins.size(); ++i) | |
| 71 if (timingAllowOrigins[i] == securityOrigin) | |
| 72 return true; | |
| 73 | |
| 74 return false; | |
| 75 } | |
| 76 | |
| 77 PerformanceResourceTiming::PerformanceResourceTiming(const AtomicString& initiat orType, const ResourceRequest& request, const ResourceResponse& response, double initiationTime, double finishTime, Document* requestingDocument) | |
| 78 : PerformanceEntry(request.url().string(), "resource", monotonicTimeToDocume ntMilliseconds(requestingDocument, initiationTime), monotonicTimeToDocumentMilli seconds(requestingDocument, finishTime)) | |
| 79 , m_initiatorType(initiatorType) | |
| 80 , m_timing(response.resourceLoadTiming()) | |
| 81 , m_finishTime(finishTime) | |
| 82 , m_didReuseConnection(response.connectionReused()) | |
| 83 , m_shouldReportDetails(passesTimingAllowCheck(response, requestingDocument) ) | |
| 84 , m_requestingDocument(requestingDocument) | 61 , m_requestingDocument(requestingDocument) |
| 85 { | 62 { |
| 86 } | 63 } |
| 87 | 64 |
| 88 PerformanceResourceTiming::~PerformanceResourceTiming() | 65 PerformanceResourceTiming::~PerformanceResourceTiming() |
| 89 { | 66 { |
| 90 } | 67 } |
| 91 | 68 |
| 92 AtomicString PerformanceResourceTiming::initiatorType() const | 69 AtomicString PerformanceResourceTiming::initiatorType() const |
| 93 { | 70 { |
| 94 return m_initiatorType; | 71 return m_initiatorType; |
| 95 } | 72 } |
| 96 | 73 |
| 97 double PerformanceResourceTiming::redirectStart() const | 74 double PerformanceResourceTiming::redirectStart() const |
| 98 { | 75 { |
| 99 // FIXME: Need to track and report redirects for resources. | 76 if (!m_shouldReportDetails || !m_lastRedirectEndTime) |
| 100 if (!m_shouldReportDetails) | |
| 101 return 0.0; | 77 return 0.0; |
| 102 return 0; | 78 |
| 79 return PerformanceEntry::startTime(); | |
| 103 } | 80 } |
| 104 | 81 |
| 105 double PerformanceResourceTiming::redirectEnd() const | 82 double PerformanceResourceTiming::redirectEnd() const |
| 106 { | 83 { |
| 107 if (!m_shouldReportDetails) | 84 if (!m_shouldReportDetails || !m_lastRedirectEndTime) |
| 108 return 0.0; | 85 return 0.0; |
| 109 return 0; | 86 |
| 87 return monotonicTimeToDocumentMilliseconds(m_requestingDocument.get(), m_las tRedirectEndTime); | |
| 110 } | 88 } |
| 111 | 89 |
| 112 double PerformanceResourceTiming::fetchStart() const | 90 double PerformanceResourceTiming::fetchStart() const |
| 113 { | 91 { |
| 114 // FIXME: This should be different depending on redirects. | 92 ASSERT(m_timing.get()); |
|
Pan
2013/04/17 15:38:16
in domainLoopUpStart/end connectStart/end, if m_ti
James Simonsen
2013/04/18 02:57:37
I think we should go back to initiationTime, thoug
| |
| 115 return (startTime()); | 93 if (m_lastRedirectEndTime) |
| 94 return monotonicTimeToDocumentMilliseconds(m_requestingDocument.get(), m _timing->requestTime); | |
|
Pan
2013/04/19 14:54:59
For redirect case, we need m_timing->requestTime h
James Simonsen
2013/04/23 00:31:37
Yeah, that seems like the right thing to do.
| |
| 95 | |
| 96 return PerformanceEntry::startTime(); | |
| 116 } | 97 } |
| 117 | 98 |
| 118 double PerformanceResourceTiming::domainLookupStart() const | 99 double PerformanceResourceTiming::domainLookupStart() const |
| 119 { | 100 { |
| 120 if (!m_shouldReportDetails) | 101 if (!m_shouldReportDetails) |
| 121 return 0.0; | 102 return 0.0; |
| 122 | 103 |
| 123 if (!m_timing || m_timing->dnsStart < 0) | 104 if (!m_timing || m_timing->dnsStart < 0) |
| 124 return fetchStart(); | 105 return fetchStart(); |
| 125 | 106 |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 208 } | 189 } |
| 209 | 190 |
| 210 double PerformanceResourceTiming::resourceTimeToDocumentMilliseconds(int deltaMi lliseconds) const | 191 double PerformanceResourceTiming::resourceTimeToDocumentMilliseconds(int deltaMi lliseconds) const |
| 211 { | 192 { |
| 212 if (!deltaMilliseconds) | 193 if (!deltaMilliseconds) |
| 213 return 0.0; | 194 return 0.0; |
| 214 return monotonicTimeToDocumentMilliseconds(m_requestingDocument.get(), m_tim ing->requestTime) + deltaMilliseconds; | 195 return monotonicTimeToDocumentMilliseconds(m_requestingDocument.get(), m_tim ing->requestTime) + deltaMilliseconds; |
| 215 } | 196 } |
| 216 | 197 |
| 217 } // namespace WebCore | 198 } // namespace WebCore |
| OLD | NEW |