예제 #1
0
void Performance::addResourceTiming(const ResourceTimingInfo& info, Document* initiatorDocument)
{
    if (isResourceTimingBufferFull())
        return;

    const ResourceResponse& finalResponse = info.finalResponse();
    bool allowTimingDetails = passesTimingAllowCheck(finalResponse, initiatorDocument);
    double startTime = info.initialTime();

    if (info.redirectChain().isEmpty()) {
        RefPtr<PerformanceEntry> entry = PerformanceResourceTiming::create(info, initiatorDocument, startTime, allowTimingDetails);
        addResourceTimingBuffer(entry);
        return;
    }

    const Vector<ResourceResponse>& redirectChain = info.redirectChain();
    bool allowRedirectDetails = allowsTimingRedirect(redirectChain, finalResponse, initiatorDocument);

    if (!allowRedirectDetails) {
        ResourceLoadTiming* finalTiming = finalResponse.resourceLoadTiming();
        ASSERT(finalTiming);
        if (finalTiming)
            startTime = finalTiming->requestTime;
    }

    ResourceLoadTiming* lastRedirectTiming = redirectChain.last().resourceLoadTiming();
    ASSERT(lastRedirectTiming);
    double lastRedirectEndTime = lastRedirectTiming->receiveHeadersEnd;

    RefPtr<PerformanceEntry> entry = PerformanceResourceTiming::create(info, initiatorDocument, startTime, lastRedirectEndTime, allowTimingDetails, allowRedirectDetails);
    addResourceTimingBuffer(entry);
}
예제 #2
0
void PerformanceBase::addResourceTiming(const ResourceTimingInfo& info) {
  if (isResourceTimingBufferFull() &&
      !hasObserverFor(PerformanceEntry::Resource))
    return;
  SecurityOrigin* securityOrigin = nullptr;
  ExecutionContext* context = getExecutionContext();
  if (context)
    securityOrigin = context->getSecurityOrigin();
  if (!securityOrigin)
    return;

  const ResourceResponse& finalResponse = info.finalResponse();
  bool allowTimingDetails =
      passesTimingAllowCheck(finalResponse, *securityOrigin,
                             info.originalTimingAllowOrigin(), context);
  double startTime = info.initialTime();

  if (info.redirectChain().isEmpty()) {
    PerformanceEntry* entry = PerformanceResourceTiming::create(
        info, timeOrigin(), startTime, allowTimingDetails);
    notifyObserversOfEntry(*entry);
    if (!isResourceTimingBufferFull())
      addResourceTimingBuffer(*entry);
    return;
  }

  const Vector<ResourceResponse>& redirectChain = info.redirectChain();
  bool allowRedirectDetails = allowsTimingRedirect(redirectChain, finalResponse,
                                                   *securityOrigin, context);

  if (!allowRedirectDetails) {
    ResourceLoadTiming* finalTiming = finalResponse.resourceLoadTiming();
    ASSERT(finalTiming);
    if (finalTiming)
      startTime = finalTiming->requestTime();
  }

  ResourceLoadTiming* lastRedirectTiming =
      redirectChain.back().resourceLoadTiming();
  ASSERT(lastRedirectTiming);
  double lastRedirectEndTime = lastRedirectTiming->receiveHeadersEnd();

  PerformanceEntry* entry = PerformanceResourceTiming::create(
      info, timeOrigin(), startTime, lastRedirectEndTime, allowTimingDetails,
      allowRedirectDetails);
  notifyObserversOfEntry(*entry);
  if (!isResourceTimingBufferFull())
    addResourceTimingBuffer(*entry);
}