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" | |
43 #include <wtf/CurrentTime.h> | 45 #include <wtf/CurrentTime.h> |
44 | 46 |
45 #include "core/page/Frame.h" | 47 #include "core/page/Frame.h" |
46 | 48 |
47 namespace WebCore { | 49 namespace WebCore { |
48 | 50 |
49 static const size_t defaultResourceTimingBufferSize = 150; | 51 static const size_t defaultResourceTimingBufferSize = 150; |
50 | 52 |
51 Performance::Performance(Frame* frame) | 53 Performance::Performance(Frame* frame) |
52 : DOMWindowProperty(frame) | 54 : DOMWindowProperty(frame) |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
152 m_resourceTimingBuffer.clear(); | 154 m_resourceTimingBuffer.clear(); |
153 } | 155 } |
154 | 156 |
155 void Performance::webkitSetResourceTimingBufferSize(unsigned size) | 157 void Performance::webkitSetResourceTimingBufferSize(unsigned size) |
156 { | 158 { |
157 m_resourceTimingBufferSize = size; | 159 m_resourceTimingBufferSize = size; |
158 if (isResourceTimingBufferFull()) | 160 if (isResourceTimingBufferFull()) |
159 dispatchEvent(Event::create(eventNames().webkitresourcetimingbufferfullE vent, false, false)); | 161 dispatchEvent(Event::create(eventNames().webkitresourcetimingbufferfullE vent, false, false)); |
160 } | 162 } |
161 | 163 |
162 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 | |
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) | |
163 { | 204 { |
164 if (isResourceTimingBufferFull()) | 205 if (isResourceTimingBufferFull()) |
165 return; | 206 return; |
166 | 207 |
167 RefPtr<PerformanceEntry> entry = PerformanceResourceTiming::create(initiator Name, request, response, initiationTime, finishTime, initiatorDocument); | 208 const ResourceResponse& finalResponse = info.finalResponse(); |
209 bool allowTimingDetails = passesTimingAllowCheck(finalResponse, initiatorDoc ument); | |
210 double startTime = info.initialTime(); | |
168 | 211 |
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; | |
Pan
2013/06/21 15:22:28
James and Tony
Resource Timing spec says last byt
James Simonsen
2013/06/22 00:26:32
Personally, I'd rather fix all the cases in net/ a
| |
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 { | |
169 m_resourceTimingBuffer.append(entry); | 237 m_resourceTimingBuffer.append(entry); |
170 | 238 |
171 if (isResourceTimingBufferFull()) | 239 if (isResourceTimingBufferFull()) |
172 dispatchEvent(Event::create(eventNames().webkitresourcetimingbufferfullE vent, false, false)); | 240 dispatchEvent(Event::create(eventNames().webkitresourcetimingbufferfullE vent, false, false)); |
173 } | 241 } |
174 | 242 |
175 bool Performance::isResourceTimingBufferFull() | 243 bool Performance::isResourceTimingBufferFull() |
176 { | 244 { |
177 return m_resourceTimingBuffer.size() >= m_resourceTimingBufferSize; | 245 return m_resourceTimingBuffer.size() >= m_resourceTimingBufferSize; |
178 } | 246 } |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
216 m_userTiming = UserTiming::create(this); | 284 m_userTiming = UserTiming::create(this); |
217 m_userTiming->clearMeasures(measureName); | 285 m_userTiming->clearMeasures(measureName); |
218 } | 286 } |
219 | 287 |
220 double Performance::now() const | 288 double Performance::now() const |
221 { | 289 { |
222 return 1000.0 * m_frame->document()->loader()->timing()->monotonicTimeToZero BasedDocumentTime(monotonicallyIncreasingTime()); | 290 return 1000.0 * m_frame->document()->loader()->timing()->monotonicTimeToZero BasedDocumentTime(monotonicallyIncreasingTime()); |
223 } | 291 } |
224 | 292 |
225 } // namespace WebCore | 293 } // namespace WebCore |
OLD | NEW |