Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2010 Google Inc. All rights reserved. | 2 * Copyright (C) 2010 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 23 matching lines...) Expand all Loading... | |
| 34 | 34 |
| 35 #include "Document.h" | 35 #include "Document.h" |
| 36 #include "DocumentLoader.h" | 36 #include "DocumentLoader.h" |
| 37 #include "MemoryInfo.h" | 37 #include "MemoryInfo.h" |
| 38 #include "PerformanceEntry.h" | 38 #include "PerformanceEntry.h" |
| 39 #include "PerformanceNavigation.h" | 39 #include "PerformanceNavigation.h" |
| 40 #include "PerformanceResourceTiming.h" | 40 #include "PerformanceResourceTiming.h" |
| 41 #include "PerformanceTiming.h" | 41 #include "PerformanceTiming.h" |
| 42 #include "PerformanceUserTiming.h" | 42 #include "PerformanceUserTiming.h" |
| 43 #include "ResourceResponse.h" | 43 #include "ResourceResponse.h" |
| 44 #include "ResourceTimingInfo.h" | |
| 44 #include <wtf/CurrentTime.h> | 45 #include <wtf/CurrentTime.h> |
| 45 | 46 |
| 46 #include "Frame.h" | 47 #include "Frame.h" |
| 47 | 48 |
| 48 namespace WebCore { | 49 namespace WebCore { |
| 49 | 50 |
| 50 static const size_t defaultResourceTimingBufferSize = 150; | 51 static const size_t defaultResourceTimingBufferSize = 150; |
| 51 | 52 |
| 52 Performance::Performance(Frame* frame) | 53 Performance::Performance(Frame* frame) |
| 53 : DOMWindowProperty(frame) | 54 : DOMWindowProperty(frame) |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 153 m_resourceTimingBuffer.clear(); | 154 m_resourceTimingBuffer.clear(); |
| 154 } | 155 } |
| 155 | 156 |
| 156 void Performance::webkitSetResourceTimingBufferSize(unsigned size) | 157 void Performance::webkitSetResourceTimingBufferSize(unsigned size) |
| 157 { | 158 { |
| 158 m_resourceTimingBufferSize = size; | 159 m_resourceTimingBufferSize = size; |
| 159 if (isResourceTimingBufferFull()) | 160 if (isResourceTimingBufferFull()) |
| 160 dispatchEvent(Event::create(eventNames().webkitresourcetimingbufferfullE vent, false, false)); | 161 dispatchEvent(Event::create(eventNames().webkitresourcetimingbufferfullE vent, false, false)); |
| 161 } | 162 } |
| 162 | 163 |
| 163 void Performance::addResourceTiming(const String& initiatorName, Document* initi atorDocument, const ResourceRequest& request, const ResourceResponse& response, double initiationTime, double finishTime) | 164 static bool passesTimingAllowCheck(const ResourceResponse& response, Document* r equestingDocument) |
| 165 { | |
| 166 AtomicallyInitializedStatic(AtomicString&, timingAllowOrigin = *new AtomicSt ring("timing-allow-origin")); | |
| 167 | |
| 168 RefPtr<SecurityOrigin> resourceOrigin = SecurityOrigin::create(response.url( )); | |
| 169 if (resourceOrigin->isSameSchemeHostPort(requestingDocument->securityOrigin( ))) | |
| 170 return true; | |
| 171 | |
| 172 const String& timingAllowOriginString = response.httpHeaderField(timingAllow Origin); | |
| 173 if (timingAllowOriginString.isEmpty() || equalIgnoringCase(timingAllowOrigin String, "null")) | |
| 174 return false; | |
| 175 | |
| 176 if (timingAllowOriginString == "*") | |
| 177 return true; | |
| 178 | |
| 179 const String& securityOrigin = requestingDocument->securityOrigin()->toStrin g(); | |
| 180 Vector<String> timingAllowOrigins; | |
| 181 timingAllowOriginString.split(" ", timingAllowOrigins); | |
| 182 for (size_t i = 0; i < timingAllowOrigins.size(); ++i) | |
| 183 if (timingAllowOrigins[i] == securityOrigin) | |
| 184 return true; | |
| 185 | |
| 186 return false; | |
| 187 } | |
| 188 | |
| 189 void Performance::addResourceTiming(const ResourceTimingInfo& info, Document* in itiatorDocument) | |
| 164 { | 190 { |
| 165 if (isResourceTimingBufferFull()) | 191 if (isResourceTimingBufferFull()) |
| 166 return; | 192 return; |
| 167 | 193 |
| 168 RefPtr<PerformanceEntry> entry = PerformanceResourceTiming::create(initiator Name, request, response, initiationTime, finishTime, initiatorDocument); | 194 bool shouldReportDetails = true; |
|
James Simonsen
2013/05/20 23:31:37
For me, this function would read much easier if th
Pan
2013/06/03 10:17:34
I seperated the non-redirect case and redirect-cas
| |
| 195 Vector<ResourceResponse> redirectChain = info.redirectChain(); | |
|
James Simonsen
2013/05/20 23:31:37
const&
Pan
2013/06/03 10:17:34
yep done.
| |
| 169 | 196 |
| 197 for (size_t i = 0; i < redirectChain.size(); i++) | |
| 198 if (false == (shouldReportDetails = passesTimingAllowCheck(redirectChain [i], initiatorDocument))) | |
|
James Simonsen
2013/05/20 23:31:37
Separate lines please.
| |
| 199 break; | |
| 200 | |
| 201 if (shouldReportDetails) | |
| 202 shouldReportDetails = passesTimingAllowCheck(info.finalResponse(), initi atorDocument); | |
| 203 | |
| 204 double lastRedirectEndTime = 0.0; | |
| 205 if (redirectChain.size() != 0) { | |
| 206 ResourceLoadTiming* loadTiming = redirectChain.last().resourceLoadTiming (); | |
|
James Simonsen
2013/05/20 23:31:37
loadTiming -> lastRedirectTiming
Pan
2013/06/03 10:17:34
done.
| |
| 207 ASSERT(loadTiming); | |
| 208 if (loadTiming->receiveHeadersEnd > 0) | |
| 209 lastRedirectEndTime = loadTiming->convertResourceLoadTimeToMonotonic Time(loadTiming->receiveHeadersEnd); | |
| 210 else | |
| 211 // Redirect response may be cached in network layer. | |
| 212 lastRedirectEndTime = loadTiming->requestTime; | |
|
James Simonsen
2013/05/20 23:31:37
Isn't it a bug if receiveHeadersEnd isn't set? We'
Pan
2013/06/03 10:17:34
Not a bug, this should be removed once after mmenk
| |
| 213 } | |
| 214 | |
| 215 double startTime = info.initialTime(); | |
| 216 if (!shouldReportDetails && lastRedirectEndTime) | |
| 217 startTime = info.finalResponse().resourceLoadTiming()->requestTime; | |
| 218 | |
| 219 RefPtr<PerformanceEntry> entry = PerformanceResourceTiming::create(info, ini tiatorDocument, startTime, lastRedirectEndTime, shouldReportDetails); | |
| 170 m_resourceTimingBuffer.append(entry); | 220 m_resourceTimingBuffer.append(entry); |
| 171 | 221 |
| 172 if (isResourceTimingBufferFull()) | 222 if (isResourceTimingBufferFull()) |
| 173 dispatchEvent(Event::create(eventNames().webkitresourcetimingbufferfullE vent, false, false)); | 223 dispatchEvent(Event::create(eventNames().webkitresourcetimingbufferfullE vent, false, false)); |
| 174 } | 224 } |
| 175 | 225 |
| 176 bool Performance::isResourceTimingBufferFull() | 226 bool Performance::isResourceTimingBufferFull() |
| 177 { | 227 { |
| 178 return m_resourceTimingBuffer.size() >= m_resourceTimingBufferSize; | 228 return m_resourceTimingBuffer.size() >= m_resourceTimingBufferSize; |
| 179 } | 229 } |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 217 m_userTiming = UserTiming::create(this); | 267 m_userTiming = UserTiming::create(this); |
| 218 m_userTiming->clearMeasures(measureName); | 268 m_userTiming->clearMeasures(measureName); |
| 219 } | 269 } |
| 220 | 270 |
| 221 double Performance::now() const | 271 double Performance::now() const |
| 222 { | 272 { |
| 223 return 1000.0 * m_frame->document()->loader()->timing()->monotonicTimeToZero BasedDocumentTime(monotonicallyIncreasingTime()); | 273 return 1000.0 * m_frame->document()->loader()->timing()->monotonicTimeToZero BasedDocumentTime(monotonicallyIncreasingTime()); |
| 224 } | 274 } |
| 225 | 275 |
| 226 } // namespace WebCore | 276 } // namespace WebCore |
| OLD | NEW |