OLD | NEW |
1 /* | 1 /* |
2 Copyright (C) 1998 Lars Knoll (knoll@mpi-hd.mpg.de) | 2 Copyright (C) 1998 Lars Knoll (knoll@mpi-hd.mpg.de) |
3 Copyright (C) 2001 Dirk Mueller (mueller@kde.org) | 3 Copyright (C) 2001 Dirk Mueller (mueller@kde.org) |
4 Copyright (C) 2002 Waldo Bastian (bastian@kde.org) | 4 Copyright (C) 2002 Waldo Bastian (bastian@kde.org) |
5 Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All
rights reserved. | 5 Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All
rights reserved. |
6 Copyright (C) 2009 Torch Mobile Inc. http://www.torchmobile.com/ | 6 Copyright (C) 2009 Torch Mobile Inc. http://www.torchmobile.com/ |
7 | 7 |
8 This library is free software; you can redistribute it and/or | 8 This library is free software; you can redistribute it and/or |
9 modify it under the terms of the GNU Library General Public | 9 modify it under the terms of the GNU Library General Public |
10 License as published by the Free Software Foundation; either | 10 License as published by the Free Software Foundation; either |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 Resource* resource = createResource(Resource::Image, request, charset); | 158 Resource* resource = createResource(Resource::Image, request, charset); |
159 resource->setOptions(resourceOptions); | 159 resource->setOptions(resourceOptions); |
160 resource->responseReceived(response); | 160 resource->responseReceived(response); |
161 // FIXME: AppendData causes an unnecessary memcpy. | 161 // FIXME: AppendData causes an unnecessary memcpy. |
162 if (data->size()) | 162 if (data->size()) |
163 resource->appendData(data->data(), data->size()); | 163 resource->appendData(data->data(), data->size()); |
164 resource->finish(); | 164 resource->finish(); |
165 return resource; | 165 return resource; |
166 } | 166 } |
167 | 167 |
| 168 static void reportResourceTiming(ResourceTimingInfo* info, Resource* resource, d
ouble finishTime, Document* initiatorDocument, bool clearLoadTimings) |
| 169 { |
| 170 if (resource->type() == Resource::MainResource) |
| 171 initiatorDocument = initiatorDocument->parentDocument(); |
| 172 ASSERT(initiatorDocument); |
| 173 info->setInitialRequest(resource->resourceRequest()); |
| 174 info->setFinalResponse(resource->response()); |
| 175 if (clearLoadTimings) |
| 176 info->clearLoadTimings(); |
| 177 info->setLoadFinishTime(finishTime); |
| 178 if (DOMWindow* initiatorWindow = initiatorDocument->domWindow()) { |
| 179 if (Performance* performance = initiatorWindow->performance()) |
| 180 performance->addResourceTiming(*info, initiatorDocument); |
| 181 } |
| 182 } |
| 183 |
168 ResourceFetcher::ResourceFetcher(DocumentLoader* documentLoader) | 184 ResourceFetcher::ResourceFetcher(DocumentLoader* documentLoader) |
169 : m_document(0) | 185 : m_document(0) |
170 , m_documentLoader(documentLoader) | 186 , m_documentLoader(documentLoader) |
171 , m_requestCount(0) | 187 , m_requestCount(0) |
172 , m_garbageCollectDocumentResourcesTimer(this, &ResourceFetcher::garbageColl
ectDocumentResourcesTimerFired) | 188 , m_garbageCollectDocumentResourcesTimer(this, &ResourceFetcher::garbageColl
ectDocumentResourcesTimerFired) |
173 , m_autoLoadImages(true) | 189 , m_autoLoadImages(true) |
174 , m_imagesEnabled(true) | 190 , m_imagesEnabled(true) |
175 , m_allowStaleResources(false) | 191 , m_allowStaleResources(false) |
176 { | 192 { |
177 } | 193 } |
(...skipping 433 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
611 // Ensure main resources aren't preloaded, and other main resource loads | 627 // Ensure main resources aren't preloaded, and other main resource loads |
612 // are removed from cache to prevent reuse. | 628 // are removed from cache to prevent reuse. |
613 if (type == Resource::MainResource) { | 629 if (type == Resource::MainResource) { |
614 ASSERT(policy != Use); | 630 ASSERT(policy != Use); |
615 ASSERT(policy != Revalidate); | 631 ASSERT(policy != Revalidate); |
616 memoryCache()->remove(resource.get()); | 632 memoryCache()->remove(resource.get()); |
617 if (request.forPreload()) | 633 if (request.forPreload()) |
618 return 0; | 634 return 0; |
619 } | 635 } |
620 | 636 |
621 if (!request.resourceRequest().url().protocolIsData()) | 637 if (!request.resourceRequest().url().protocolIsData()) { |
| 638 if (policy == Use && !m_validatedURLs.contains(request.resourceRequest()
.url())) { |
| 639 // Resources loaded from memory cache should be reported the first t
ime they're used. |
| 640 RefPtr<ResourceTimingInfo> info = ResourceTimingInfo::create(request
.options().initiatorInfo.name, monotonicallyIncreasingTime()); |
| 641 reportResourceTiming(info.get(), resource.get(), monotonicallyIncrea
singTime(), document(), true); |
| 642 } |
| 643 |
622 m_validatedURLs.add(request.resourceRequest().url()); | 644 m_validatedURLs.add(request.resourceRequest().url()); |
| 645 } |
623 | 646 |
624 ASSERT(resource->url() == url.string()); | 647 ASSERT(resource->url() == url.string()); |
625 m_documentResources.set(resource->url(), resource); | 648 m_documentResources.set(resource->url(), resource); |
626 return resource; | 649 return resource; |
627 } | 650 } |
628 | 651 |
629 void ResourceFetcher::determineTargetType(ResourceRequest& request, Resource::Ty
pe type) | 652 void ResourceFetcher::determineTargetType(ResourceRequest& request, Resource::Ty
pe type) |
630 { | 653 { |
631 ResourceRequest::TargetType targetType; | 654 ResourceRequest::TargetType targetType; |
632 | 655 |
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
956 } | 979 } |
957 | 980 |
958 void ResourceFetcher::didLoadResource(Resource* resource) | 981 void ResourceFetcher::didLoadResource(Resource* resource) |
959 { | 982 { |
960 RefPtr<DocumentLoader> protectDocumentLoader(m_documentLoader); | 983 RefPtr<DocumentLoader> protectDocumentLoader(m_documentLoader); |
961 RefPtr<Document> protectDocument(m_document); | 984 RefPtr<Document> protectDocument(m_document); |
962 | 985 |
963 if (resource && resource->response().isHTTP() && ((!resource->errorOccurred(
) && !resource->wasCanceled()) || resource->response().httpStatusCode() == 304)
&& document()) { | 986 if (resource && resource->response().isHTTP() && ((!resource->errorOccurred(
) && !resource->wasCanceled()) || resource->response().httpStatusCode() == 304)
&& document()) { |
964 ResourceTimingInfoMap::iterator it = m_resourceTimingInfoMap.find(resour
ce); | 987 ResourceTimingInfoMap::iterator it = m_resourceTimingInfoMap.find(resour
ce); |
965 if (it != m_resourceTimingInfoMap.end()) { | 988 if (it != m_resourceTimingInfoMap.end()) { |
966 Document* initiatorDocument = document(); | |
967 if (resource->type() == Resource::MainResource) | |
968 initiatorDocument = document()->parentDocument(); | |
969 ASSERT(initiatorDocument); | |
970 RefPtr<ResourceTimingInfo> info = it->value; | 989 RefPtr<ResourceTimingInfo> info = it->value; |
971 m_resourceTimingInfoMap.remove(it); | 990 m_resourceTimingInfoMap.remove(it); |
972 info->setInitialRequest(resource->resourceRequest()); | 991 reportResourceTiming(info.get(), resource, resource->loadFinishTime(
), document(), false); |
973 info->setFinalResponse(resource->response()); | |
974 info->setLoadFinishTime(resource->loadFinishTime()); | |
975 if (DOMWindow* initiatorWindow = initiatorDocument->domWindow()) { | |
976 if (Performance* performance = initiatorWindow->performance()) | |
977 performance->addResourceTiming(*info, initiatorDocument); | |
978 } | |
979 } | 992 } |
980 } | 993 } |
981 | 994 |
982 if (frame()) | 995 if (frame()) |
983 frame()->loader()->loadDone(); | 996 frame()->loader()->loadDone(); |
984 performPostLoadActions(); | 997 performPostLoadActions(); |
985 | 998 |
986 if (!m_garbageCollectDocumentResourcesTimer.isActive()) | 999 if (!m_garbageCollectDocumentResourcesTimer.isActive()) |
987 m_garbageCollectDocumentResourcesTimer.startOneShot(0); | 1000 m_garbageCollectDocumentResourcesTimer.startOneShot(0); |
988 } | 1001 } |
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1321 } | 1334 } |
1322 #endif | 1335 #endif |
1323 | 1336 |
1324 const ResourceLoaderOptions& ResourceFetcher::defaultResourceOptions() | 1337 const ResourceLoaderOptions& ResourceFetcher::defaultResourceOptions() |
1325 { | 1338 { |
1326 DEFINE_STATIC_LOCAL(ResourceLoaderOptions, options, (SendCallbacks, SniffCon
tent, BufferData, AllowStoredCredentials, ClientRequestedCredentials, AskClientF
orCrossOriginCredentials, DoSecurityCheck, CheckContentSecurityPolicy, UseDefaul
tOriginRestrictionsForType, DocumentContext)); | 1339 DEFINE_STATIC_LOCAL(ResourceLoaderOptions, options, (SendCallbacks, SniffCon
tent, BufferData, AllowStoredCredentials, ClientRequestedCredentials, AskClientF
orCrossOriginCredentials, DoSecurityCheck, CheckContentSecurityPolicy, UseDefaul
tOriginRestrictionsForType, DocumentContext)); |
1327 return options; | 1340 return options; |
1328 } | 1341 } |
1329 | 1342 |
1330 } | 1343 } |
OLD | NEW |