| 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 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 } | 103 } |
| 104 | 104 |
| 105 const AtomicString& PerformanceBase::interfaceName() const { | 105 const AtomicString& PerformanceBase::interfaceName() const { |
| 106 return EventTargetNames::Performance; | 106 return EventTargetNames::Performance; |
| 107 } | 107 } |
| 108 | 108 |
| 109 PerformanceTiming* PerformanceBase::timing() const { | 109 PerformanceTiming* PerformanceBase::timing() const { |
| 110 return nullptr; | 110 return nullptr; |
| 111 } | 111 } |
| 112 | 112 |
| 113 PerformanceEntryVector PerformanceBase::getEntries() const { | 113 PerformanceEntryVector PerformanceBase::getEntries() { |
| 114 PerformanceEntryVector entries; | 114 PerformanceEntryVector entries; |
| 115 | 115 |
| 116 entries.appendVector(m_resourceTimingBuffer); | 116 entries.appendVector(m_resourceTimingBuffer); |
| 117 if (!m_navigationTiming) |
| 118 m_navigationTiming = createNavigationTimingInstance(); |
| 119 // This extra checking is needed when WorkerPerformance |
| 120 // calls this method. |
| 117 if (m_navigationTiming) | 121 if (m_navigationTiming) |
| 118 entries.push_back(m_navigationTiming); | 122 entries.push_back(m_navigationTiming); |
| 119 entries.appendVector(m_frameTimingBuffer); | 123 entries.appendVector(m_frameTimingBuffer); |
| 120 | 124 |
| 121 if (m_userTiming) { | 125 if (m_userTiming) { |
| 122 entries.appendVector(m_userTiming->getMarks()); | 126 entries.appendVector(m_userTiming->getMarks()); |
| 123 entries.appendVector(m_userTiming->getMeasures()); | 127 entries.appendVector(m_userTiming->getMeasures()); |
| 124 } | 128 } |
| 125 | 129 |
| 126 std::sort(entries.begin(), entries.end(), | 130 std::sort(entries.begin(), entries.end(), |
| 127 PerformanceEntry::startTimeCompareLessThan); | 131 PerformanceEntry::startTimeCompareLessThan); |
| 128 return entries; | 132 return entries; |
| 129 } | 133 } |
| 130 | 134 |
| 131 PerformanceEntryVector PerformanceBase::getEntriesByType( | 135 PerformanceEntryVector PerformanceBase::getEntriesByType( |
| 132 const String& entryType) { | 136 const String& entryType) { |
| 133 PerformanceEntryVector entries; | 137 PerformanceEntryVector entries; |
| 134 PerformanceEntry::EntryType type = | 138 PerformanceEntry::EntryType type = |
| 135 PerformanceEntry::toEntryTypeEnum(entryType); | 139 PerformanceEntry::toEntryTypeEnum(entryType); |
| 136 | 140 |
| 137 switch (type) { | 141 switch (type) { |
| 138 case PerformanceEntry::Resource: | 142 case PerformanceEntry::Resource: |
| 139 for (const auto& resource : m_resourceTimingBuffer) | 143 for (const auto& resource : m_resourceTimingBuffer) |
| 140 entries.push_back(resource); | 144 entries.push_back(resource); |
| 141 break; | 145 break; |
| 142 case PerformanceEntry::Navigation: | 146 case PerformanceEntry::Navigation: |
| 147 if (!m_navigationTiming) |
| 148 m_navigationTiming = createNavigationTimingInstance(); |
| 143 if (m_navigationTiming) | 149 if (m_navigationTiming) |
| 144 entries.push_back(m_navigationTiming); | 150 entries.push_back(m_navigationTiming); |
| 145 break; | 151 break; |
| 146 case PerformanceEntry::Composite: | 152 case PerformanceEntry::Composite: |
| 147 case PerformanceEntry::Render: | 153 case PerformanceEntry::Render: |
| 148 for (const auto& frame : m_frameTimingBuffer) { | 154 for (const auto& frame : m_frameTimingBuffer) { |
| 149 if (type == frame->entryTypeEnum()) { | 155 if (type == frame->entryTypeEnum()) { |
| 150 entries.push_back(frame); | 156 entries.push_back(frame); |
| 151 } | 157 } |
| 152 } | 158 } |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 188 return entries; | 194 return entries; |
| 189 | 195 |
| 190 if (entryType.isNull() || type == PerformanceEntry::Resource) { | 196 if (entryType.isNull() || type == PerformanceEntry::Resource) { |
| 191 for (const auto& resource : m_resourceTimingBuffer) { | 197 for (const auto& resource : m_resourceTimingBuffer) { |
| 192 if (resource->name() == name) | 198 if (resource->name() == name) |
| 193 entries.push_back(resource); | 199 entries.push_back(resource); |
| 194 } | 200 } |
| 195 } | 201 } |
| 196 | 202 |
| 197 if (entryType.isNull() || type == PerformanceEntry::Navigation) { | 203 if (entryType.isNull() || type == PerformanceEntry::Navigation) { |
| 204 if (!m_navigationTiming) |
| 205 m_navigationTiming = createNavigationTimingInstance(); |
| 198 if (m_navigationTiming && m_navigationTiming->name() == name) | 206 if (m_navigationTiming && m_navigationTiming->name() == name) |
| 199 entries.push_back(m_navigationTiming); | 207 entries.push_back(m_navigationTiming); |
| 200 } | 208 } |
| 201 | 209 |
| 202 if (entryType.isNull() || type == PerformanceEntry::Composite || | 210 if (entryType.isNull() || type == PerformanceEntry::Composite || |
| 203 type == PerformanceEntry::Render) { | 211 type == PerformanceEntry::Render) { |
| 204 for (const auto& frame : m_frameTimingBuffer) { | 212 for (const auto& frame : m_frameTimingBuffer) { |
| 205 if (frame->name() == name && | 213 if (frame->name() == name && |
| 206 (entryType.isNull() || entryType == frame->entryType())) | 214 (entryType.isNull() || entryType == frame->entryType())) |
| 207 entries.push_back(frame); | 215 entries.push_back(frame); |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 337 double lastRedirectEndTime = lastRedirectTiming->receiveHeadersEnd(); | 345 double lastRedirectEndTime = lastRedirectTiming->receiveHeadersEnd(); |
| 338 | 346 |
| 339 PerformanceEntry* entry = PerformanceResourceTiming::create( | 347 PerformanceEntry* entry = PerformanceResourceTiming::create( |
| 340 info, timeOrigin(), startTime, lastRedirectEndTime, allowTimingDetails, | 348 info, timeOrigin(), startTime, lastRedirectEndTime, allowTimingDetails, |
| 341 allowRedirectDetails); | 349 allowRedirectDetails); |
| 342 notifyObserversOfEntry(*entry); | 350 notifyObserversOfEntry(*entry); |
| 343 if (!isResourceTimingBufferFull()) | 351 if (!isResourceTimingBufferFull()) |
| 344 addResourceTimingBuffer(*entry); | 352 addResourceTimingBuffer(*entry); |
| 345 } | 353 } |
| 346 | 354 |
| 347 void PerformanceBase::addNavigationTiming(LocalFrame* frame) { | 355 // Called after loadEventEnd happens. |
| 348 if (!RuntimeEnabledFeatures::performanceNavigationTiming2Enabled()) | 356 void PerformanceBase::notifyNavigationTimingToObservers() { |
| 349 return; | 357 if (!m_navigationTiming) |
| 350 DCHECK(frame); | 358 m_navigationTiming = createNavigationTimingInstance(); |
| 351 const DocumentLoader* documentLoader = frame->loader().documentLoader(); | 359 if (m_navigationTiming) |
| 352 DCHECK(documentLoader); | 360 notifyObserversOfEntry(*m_navigationTiming); |
| 353 | |
| 354 const DocumentLoadTiming& documentLoadTiming = documentLoader->timing(); | |
| 355 | |
| 356 const DocumentTiming* documentTiming = | |
| 357 frame->document() ? &(frame->document()->timing()) : nullptr; | |
| 358 | |
| 359 ResourceTimingInfo* navigationTimingInfo = | |
| 360 documentLoader->getNavigationTimingInfo(); | |
| 361 if (!navigationTimingInfo) | |
| 362 return; | |
| 363 | |
| 364 const ResourceResponse& finalResponse = navigationTimingInfo->finalResponse(); | |
| 365 | |
| 366 ResourceLoadTiming* resourceLoadTiming = finalResponse.resourceLoadTiming(); | |
| 367 // Don't create a navigation timing instance when | |
| 368 // resourceLoadTiming is null, which could happen when visiting non-http sites | |
| 369 // such as about:blank or in some error cases. | |
| 370 if (!resourceLoadTiming) | |
| 371 return; | |
| 372 double lastRedirectEndTime = documentLoadTiming.redirectEnd(); | |
| 373 double finishTime = documentLoadTiming.loadEventEnd(); | |
| 374 | |
| 375 ExecutionContext* context = getExecutionContext(); | |
| 376 SecurityOrigin* securityOrigin = getSecurityOrigin(context); | |
| 377 if (!securityOrigin) | |
| 378 return; | |
| 379 | |
| 380 bool allowRedirectDetails = | |
| 381 allowsTimingRedirect(navigationTimingInfo->redirectChain(), finalResponse, | |
| 382 *securityOrigin, context); | |
| 383 | |
| 384 unsigned long long transferSize = navigationTimingInfo->transferSize(); | |
| 385 unsigned long long encodedBodyLength = finalResponse.encodedBodyLength(); | |
| 386 unsigned long long decodedBodyLength = finalResponse.decodedBodyLength(); | |
| 387 bool didReuseConnection = finalResponse.connectionReused(); | |
| 388 PerformanceNavigationTiming::NavigationType type = | |
| 389 getNavigationType(documentLoader->getNavigationType(), frame->document()); | |
| 390 | |
| 391 m_navigationTiming = new PerformanceNavigationTiming( | |
| 392 timeOrigin(), navigationTimingInfo->initialURL().getString(), | |
| 393 documentLoadTiming.unloadEventStart(), | |
| 394 documentLoadTiming.unloadEventEnd(), documentLoadTiming.loadEventStart(), | |
| 395 documentLoadTiming.loadEventEnd(), documentLoadTiming.redirectCount(), | |
| 396 documentTiming ? documentTiming->domInteractive() : 0, | |
| 397 documentTiming ? documentTiming->domContentLoadedEventStart() : 0, | |
| 398 documentTiming ? documentTiming->domContentLoadedEventEnd() : 0, | |
| 399 documentTiming ? documentTiming->domComplete() : 0, type, | |
| 400 documentLoadTiming.redirectStart(), documentLoadTiming.redirectEnd(), | |
| 401 documentLoadTiming.fetchStart(), documentLoadTiming.responseEnd(), | |
| 402 allowRedirectDetails, | |
| 403 documentLoadTiming.hasSameOriginAsPreviousDocument(), resourceLoadTiming, | |
| 404 lastRedirectEndTime, finishTime, transferSize, encodedBodyLength, | |
| 405 decodedBodyLength, didReuseConnection); | |
| 406 notifyObserversOfEntry(*m_navigationTiming); | |
| 407 } | 361 } |
| 408 | 362 |
| 409 void PerformanceBase::addFirstPaintTiming(double startTime) { | 363 void PerformanceBase::addFirstPaintTiming(double startTime) { |
| 410 addPaintTiming(PerformancePaintTiming::PaintType::FirstPaint, startTime); | 364 addPaintTiming(PerformancePaintTiming::PaintType::FirstPaint, startTime); |
| 411 } | 365 } |
| 412 | 366 |
| 413 void PerformanceBase::addFirstContentfulPaintTiming(double startTime) { | 367 void PerformanceBase::addFirstContentfulPaintTiming(double startTime) { |
| 414 addPaintTiming(PerformancePaintTiming::PaintType::FirstContentfulPaint, | 368 addPaintTiming(PerformancePaintTiming::PaintType::FirstContentfulPaint, |
| 415 startTime); | 369 startTime); |
| 416 } | 370 } |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 601 visitor->trace(m_resourceTimingBuffer); | 555 visitor->trace(m_resourceTimingBuffer); |
| 602 visitor->trace(m_navigationTiming); | 556 visitor->trace(m_navigationTiming); |
| 603 visitor->trace(m_userTiming); | 557 visitor->trace(m_userTiming); |
| 604 visitor->trace(m_observers); | 558 visitor->trace(m_observers); |
| 605 visitor->trace(m_activeObservers); | 559 visitor->trace(m_activeObservers); |
| 606 visitor->trace(m_suspendedObservers); | 560 visitor->trace(m_suspendedObservers); |
| 607 EventTargetWithInlineData::trace(visitor); | 561 EventTargetWithInlineData::trace(visitor); |
| 608 } | 562 } |
| 609 | 563 |
| 610 } // namespace blink | 564 } // namespace blink |
| OLD | NEW |