| 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 22 matching lines...) Expand all Loading... |
| 33 #include "core/page/Performance.h" | 33 #include "core/page/Performance.h" |
| 34 | 34 |
| 35 #include "core/dom/Document.h" | 35 #include "core/dom/Document.h" |
| 36 #include "core/loader/DocumentLoader.h" | 36 #include "core/loader/DocumentLoader.h" |
| 37 #include "core/page/MemoryInfo.h" | 37 #include "core/page/MemoryInfo.h" |
| 38 #include "core/page/PerformanceEntry.h" | 38 #include "core/page/PerformanceEntry.h" |
| 39 #include "core/page/PerformanceNavigation.h" | 39 #include "core/page/PerformanceNavigation.h" |
| 40 #include "core/page/PerformanceResourceTiming.h" | 40 #include "core/page/PerformanceResourceTiming.h" |
| 41 #include "core/page/PerformanceTiming.h" | 41 #include "core/page/PerformanceTiming.h" |
| 42 #include "core/page/PerformanceUserTiming.h" | 42 #include "core/page/PerformanceUserTiming.h" |
| 43 #include "core/page/ResourceTimingInfo.h" | |
| 44 #include "weborigin/SecurityOrigin.h" | |
| 45 #include <wtf/CurrentTime.h> | 43 #include <wtf/CurrentTime.h> |
| 46 | 44 |
| 47 #include "core/page/Frame.h" | 45 #include "core/page/Frame.h" |
| 48 | 46 |
| 49 namespace WebCore { | 47 namespace WebCore { |
| 50 | 48 |
| 51 static const size_t defaultResourceTimingBufferSize = 150; | 49 static const size_t defaultResourceTimingBufferSize = 150; |
| 52 | 50 |
| 53 Performance::Performance(Frame* frame) | 51 Performance::Performance(Frame* frame) |
| 54 : DOMWindowProperty(frame) | 52 : DOMWindowProperty(frame) |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 154 m_resourceTimingBuffer.clear(); | 152 m_resourceTimingBuffer.clear(); |
| 155 } | 153 } |
| 156 | 154 |
| 157 void Performance::webkitSetResourceTimingBufferSize(unsigned size) | 155 void Performance::webkitSetResourceTimingBufferSize(unsigned size) |
| 158 { | 156 { |
| 159 m_resourceTimingBufferSize = size; | 157 m_resourceTimingBufferSize = size; |
| 160 if (isResourceTimingBufferFull()) | 158 if (isResourceTimingBufferFull()) |
| 161 dispatchEvent(Event::create(eventNames().webkitresourcetimingbufferfullE
vent, false, false)); | 159 dispatchEvent(Event::create(eventNames().webkitresourcetimingbufferfullE
vent, false, false)); |
| 162 } | 160 } |
| 163 | 161 |
| 164 static bool passesTimingAllowCheck(const ResourceResponse& response, Document* r
equestingDocument) | 162 void Performance::addResourceTiming(const String& initiatorName, Document* initi
atorDocument, const ResourceRequest& request, const ResourceResponse& response,
double initiationTime, double finishTime) |
| 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 | |
| 187 return false; | |
| 188 } | |
| 189 | |
| 190 static bool allowsTimingRedirect(const Vector<ResourceResponse>& redirectChain,
const ResourceResponse& finalResponse, Document* initiatorDocument) | |
| 191 { | |
| 192 if (!passesTimingAllowCheck(finalResponse, initiatorDocument)) | |
| 193 return false; | |
| 194 | |
| 195 for (size_t i = 0; i < redirectChain.size(); i++) { | |
| 196 if (!passesTimingAllowCheck(redirectChain[i], initiatorDocument)) | |
| 197 return false; | |
| 198 } | |
| 199 | |
| 200 return true; | |
| 201 } | |
| 202 | |
| 203 void Performance::addResourceTiming(const ResourceTimingInfo& info, Document* in
itiatorDocument) | |
| 204 { | 163 { |
| 205 if (isResourceTimingBufferFull()) | 164 if (isResourceTimingBufferFull()) |
| 206 return; | 165 return; |
| 207 | 166 |
| 208 const ResourceResponse& finalResponse = info.finalResponse(); | 167 RefPtr<PerformanceEntry> entry = PerformanceResourceTiming::create(initiator
Name, request, response, initiationTime, finishTime, initiatorDocument); |
| 209 bool allowTimingDetails = passesTimingAllowCheck(finalResponse, initiatorDoc
ument); | |
| 210 double startTime = info.initialTime(); | |
| 211 | 168 |
| 212 if (info.redirectChain().isEmpty()) { | |
| 213 RefPtr<PerformanceEntry> entry = PerformanceResourceTiming::create(info,
initiatorDocument, startTime, allowTimingDetails); | |
| 214 addResourceTimingBuffer(entry); | |
| 215 return; | |
| 216 } | |
| 217 | |
| 218 const Vector<ResourceResponse>& redirectChain = info.redirectChain(); | |
| 219 bool allowRedirectDetails = allowsTimingRedirect(redirectChain, finalRespons
e, initiatorDocument); | |
| 220 | |
| 221 if (!allowRedirectDetails) { | |
| 222 ResourceLoadTiming* finalTiming = finalResponse.resourceLoadTiming(); | |
| 223 ASSERT(finalTiming); | |
| 224 startTime = finalTiming->requestTime; | |
| 225 } | |
| 226 | |
| 227 ResourceLoadTiming* lastRedirectTiming = redirectChain.last().resourceLoadTi
ming(); | |
| 228 ASSERT(lastRedirectTiming); | |
| 229 double lastRedirectEndTime = lastRedirectTiming->receiveHeadersEnd; | |
| 230 | |
| 231 RefPtr<PerformanceEntry> entry = PerformanceResourceTiming::create(info, ini
tiatorDocument, startTime, lastRedirectEndTime, allowTimingDetails, allowRedirec
tDetails); | |
| 232 addResourceTimingBuffer(entry); | |
| 233 } | |
| 234 | |
| 235 void Performance::addResourceTimingBuffer(PassRefPtr<PerformanceEntry> entry) | |
| 236 { | |
| 237 m_resourceTimingBuffer.append(entry); | 169 m_resourceTimingBuffer.append(entry); |
| 238 | 170 |
| 239 if (isResourceTimingBufferFull()) | 171 if (isResourceTimingBufferFull()) |
| 240 dispatchEvent(Event::create(eventNames().webkitresourcetimingbufferfullE
vent, false, false)); | 172 dispatchEvent(Event::create(eventNames().webkitresourcetimingbufferfullE
vent, false, false)); |
| 241 } | 173 } |
| 242 | 174 |
| 243 bool Performance::isResourceTimingBufferFull() | 175 bool Performance::isResourceTimingBufferFull() |
| 244 { | 176 { |
| 245 return m_resourceTimingBuffer.size() >= m_resourceTimingBufferSize; | 177 return m_resourceTimingBuffer.size() >= m_resourceTimingBufferSize; |
| 246 } | 178 } |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 284 m_userTiming = UserTiming::create(this); | 216 m_userTiming = UserTiming::create(this); |
| 285 m_userTiming->clearMeasures(measureName); | 217 m_userTiming->clearMeasures(measureName); |
| 286 } | 218 } |
| 287 | 219 |
| 288 double Performance::now() const | 220 double Performance::now() const |
| 289 { | 221 { |
| 290 return 1000.0 * m_frame->document()->loader()->timing()->monotonicTimeToZero
BasedDocumentTime(monotonicallyIncreasingTime()); | 222 return 1000.0 * m_frame->document()->loader()->timing()->monotonicTimeToZero
BasedDocumentTime(monotonicallyIncreasingTime()); |
| 291 } | 223 } |
| 292 | 224 |
| 293 } // namespace WebCore | 225 } // namespace WebCore |
| OLD | NEW |