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 13 matching lines...) Expand all Loading... |
24 pages from the web. It has a memory cache for these objects. | 24 pages from the web. It has a memory cache for these objects. |
25 */ | 25 */ |
26 | 26 |
27 #include "config.h" | 27 #include "config.h" |
28 #include "core/loader/cache/CachedResourceLoader.h" | 28 #include "core/loader/cache/CachedResourceLoader.h" |
29 | 29 |
30 #include "bindings/v8/ScriptController.h" | 30 #include "bindings/v8/ScriptController.h" |
31 #include "core/dom/Document.h" | 31 #include "core/dom/Document.h" |
32 #include "core/html/HTMLElement.h" | 32 #include "core/html/HTMLElement.h" |
33 #include "core/html/HTMLFrameOwnerElement.h" | 33 #include "core/html/HTMLFrameOwnerElement.h" |
| 34 #include "core/inspector/InspectorInstrumentation.h" |
34 #include "core/loader/DocumentLoader.h" | 35 #include "core/loader/DocumentLoader.h" |
35 #include "core/loader/FrameLoader.h" | 36 #include "core/loader/FrameLoader.h" |
36 #include "core/loader/FrameLoaderClient.h" | 37 #include "core/loader/FrameLoaderClient.h" |
37 #include "core/loader/PingLoader.h" | 38 #include "core/loader/PingLoader.h" |
38 #include "core/loader/UniqueIdentifier.h" | 39 #include "core/loader/UniqueIdentifier.h" |
| 40 #include "core/loader/appcache/ApplicationCacheHost.h" |
39 #include "core/loader/cache/CachedCSSStyleSheet.h" | 41 #include "core/loader/cache/CachedCSSStyleSheet.h" |
40 #include "core/loader/cache/CachedDocument.h" | 42 #include "core/loader/cache/CachedDocument.h" |
41 #include "core/loader/cache/CachedFont.h" | 43 #include "core/loader/cache/CachedFont.h" |
42 #include "core/loader/cache/CachedImage.h" | 44 #include "core/loader/cache/CachedImage.h" |
43 #include "core/loader/cache/CachedRawResource.h" | 45 #include "core/loader/cache/CachedRawResource.h" |
44 #include "core/loader/cache/CachedResourceRequest.h" | 46 #include "core/loader/cache/CachedResourceRequest.h" |
45 #include "core/loader/cache/CachedScript.h" | 47 #include "core/loader/cache/CachedScript.h" |
46 #include "core/loader/cache/CachedShader.h" | 48 #include "core/loader/cache/CachedShader.h" |
47 #include "core/loader/cache/CachedTextTrack.h" | 49 #include "core/loader/cache/CachedTextTrack.h" |
48 #include "core/loader/cache/CachedXSLStyleSheet.h" | 50 #include "core/loader/cache/CachedXSLStyleSheet.h" |
(...skipping 444 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
493 if (priority != resource->resourceRequest().priority()) { | 495 if (priority != resource->resourceRequest().priority()) { |
494 resource->resourceRequest().setPriority(priority); | 496 resource->resourceRequest().setPriority(priority); |
495 resource->didChangePriority(priority); | 497 resource->didChangePriority(priority); |
496 } | 498 } |
497 } | 499 } |
498 | 500 |
499 if ((policy != Use || resource->stillNeedsLoad()) && CachedResourceRequest::
NoDefer == request.defer()) { | 501 if ((policy != Use || resource->stillNeedsLoad()) && CachedResourceRequest::
NoDefer == request.defer()) { |
500 if (!frame()) | 502 if (!frame()) |
501 return 0; | 503 return 0; |
502 | 504 |
503 FrameLoader* frameLoader = frame()->loader(); | 505 FrameLoader* frameLoader = this->frameLoader(); |
504 if (request.options().securityCheck == DoSecurityCheck && (frameLoader->
state() == FrameStateProvisional || !frameLoader->activeDocumentLoader() || fram
eLoader->activeDocumentLoader()->isStopping())) | 506 if (request.options().securityCheck == DoSecurityCheck && (frameLoader->
state() == FrameStateProvisional || !frameLoader->activeDocumentLoader() || fram
eLoader->activeDocumentLoader()->isStopping())) |
505 return 0; | 507 return 0; |
506 | 508 |
507 if (!m_documentLoader->scheduleArchiveLoad(resource.get(), request.resou
rceRequest())) | 509 if (!m_documentLoader->scheduleArchiveLoad(resource.get(), request.resou
rceRequest())) |
508 resource->load(this, request.options()); | 510 resource->load(this, request.options()); |
509 | 511 |
510 // We don't support immediate loads, but we do support immediate failure
. | 512 // We don't support immediate loads, but we do support immediate failure
. |
511 if (resource->errorOccurred()) { | 513 if (resource->errorOccurred()) { |
512 if (resource->inCache()) | 514 if (resource->inCache()) |
513 memoryCache()->remove(resource.get()); | 515 memoryCache()->remove(resource.get()); |
(...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
886 return CachePolicyVerify; | 888 return CachePolicyVerify; |
887 | 889 |
888 if (type != CachedResource::MainResource) | 890 if (type != CachedResource::MainResource) |
889 return frame()->loader()->subresourceCachePolicy(); | 891 return frame()->loader()->subresourceCachePolicy(); |
890 | 892 |
891 if (frame()->loader()->loadType() == FrameLoadTypeReloadFromOrigin || frame(
)->loader()->loadType() == FrameLoadTypeReload) | 893 if (frame()->loader()->loadType() == FrameLoadTypeReloadFromOrigin || frame(
)->loader()->loadType() == FrameLoadTypeReload) |
892 return CachePolicyReload; | 894 return CachePolicyReload; |
893 return CachePolicyVerify; | 895 return CachePolicyVerify; |
894 } | 896 } |
895 | 897 |
896 void CachedResourceLoader::loadDone(CachedResource* resource) | 898 void CachedResourceLoader::didLoadResource(CachedResource* resource) |
897 { | 899 { |
898 RefPtr<DocumentLoader> protectDocumentLoader(m_documentLoader); | 900 RefPtr<DocumentLoader> protectDocumentLoader(m_documentLoader); |
899 RefPtr<Document> protectDocument(m_document); | 901 RefPtr<Document> protectDocument(m_document); |
900 | 902 |
901 if (resource && resource->response().isHTTP() && ((!resource->errorOccurred(
) && !resource->wasCanceled()) || resource->response().httpStatusCode() == 304))
{ | 903 if (resource && resource->response().isHTTP() && ((!resource->errorOccurred(
) && !resource->wasCanceled()) || resource->response().httpStatusCode() == 304))
{ |
902 HashMap<CachedResource*, CachedResourceInitiatorInfo>::iterator initiato
rIt = m_initiatorMap.find(resource); | 904 HashMap<CachedResource*, CachedResourceInitiatorInfo>::iterator initiato
rIt = m_initiatorMap.find(resource); |
903 if (initiatorIt != m_initiatorMap.end()) { | 905 if (initiatorIt != m_initiatorMap.end()) { |
904 ASSERT(document()); | 906 ASSERT(document()); |
905 Document* initiatorDocument = document(); | 907 Document* initiatorDocument = document(); |
906 if (resource->type() == CachedResource::MainResource) | 908 if (resource->type() == CachedResource::MainResource) |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1070 memoryCache()->remove(res); | 1072 memoryCache()->remove(res); |
1071 } | 1073 } |
1072 m_preloads.clear(); | 1074 m_preloads.clear(); |
1073 } | 1075 } |
1074 | 1076 |
1075 void CachedResourceLoader::clearPendingPreloads() | 1077 void CachedResourceLoader::clearPendingPreloads() |
1076 { | 1078 { |
1077 m_pendingPreloads.clear(); | 1079 m_pendingPreloads.clear(); |
1078 } | 1080 } |
1079 | 1081 |
| 1082 inline FrameLoader* CachedResourceLoader::frameLoader() |
| 1083 { |
| 1084 return frame() ? frame()->loader() : 0; |
| 1085 } |
| 1086 |
| 1087 void CachedResourceLoader::didFinishLoading(const CachedResource* resource, doub
le finishTime, const ResourceLoaderOptions& options) |
| 1088 { |
| 1089 if (options.sendLoadCallbacks != SendCallbacks) |
| 1090 return; |
| 1091 if (FrameLoader* loader = frameLoader()) |
| 1092 loader->notifier()->dispatchDidFinishLoading(m_documentLoader, resource-
>identifier(), finishTime); |
| 1093 } |
| 1094 |
| 1095 void CachedResourceLoader::didChangeLoadingPriority(const CachedResource* resour
ce, ResourceLoadPriority loadPriority) |
| 1096 { |
| 1097 if (FrameLoader* loader = frameLoader()) |
| 1098 loader->client()->dispatchDidChangeResourcePriority(resource->identifier
(), loadPriority); |
| 1099 } |
| 1100 |
| 1101 void CachedResourceLoader::didFailLoading(const CachedResource* resource, const
ResourceError& error, const ResourceLoaderOptions& options) |
| 1102 { |
| 1103 if (options.sendLoadCallbacks != SendCallbacks) |
| 1104 return; |
| 1105 if (FrameLoader* loader = frameLoader()) |
| 1106 loader->notifier()->dispatchDidFail(m_documentLoader, resource->identifi
er(), error); |
| 1107 } |
| 1108 |
| 1109 void CachedResourceLoader::willSendRequest(const CachedResource* resource, Resou
rceRequest& request, const ResourceResponse& redirectResponse, const ResourceLoa
derOptions& options) |
| 1110 { |
| 1111 if (options.sendLoadCallbacks == SendCallbacks) { |
| 1112 if (FrameLoader* loader = frameLoader()) |
| 1113 loader->notifier()->dispatchWillSendRequest(m_documentLoader, resour
ce->identifier(), request, redirectResponse, options.initiatorInfo); |
| 1114 } else { |
| 1115 InspectorInstrumentation::willSendRequest(frame(), resource->identifier(
), m_documentLoader, request, redirectResponse, options.initiatorInfo); |
| 1116 } |
| 1117 } |
| 1118 |
| 1119 void CachedResourceLoader::didReceiveResponse(const CachedResource* resource, co
nst ResourceResponse& response, const ResourceLoaderOptions& options) |
| 1120 { |
| 1121 if (options.sendLoadCallbacks != SendCallbacks) |
| 1122 return; |
| 1123 if (FrameLoader* loader = frameLoader()) |
| 1124 loader->notifier()->dispatchDidReceiveResponse(m_documentLoader, resourc
e->identifier(), response); |
| 1125 } |
| 1126 |
| 1127 void CachedResourceLoader::didReceiveData(const CachedResource* resource, const
char* data, int dataLength, int encodedDataLength, const ResourceLoaderOptions&
options) |
| 1128 { |
| 1129 if (options.sendLoadCallbacks != SendCallbacks) |
| 1130 return; |
| 1131 if (FrameLoader* loader = frameLoader()) |
| 1132 loader->notifier()->dispatchDidReceiveData(m_documentLoader, resource->i
dentifier(), data, dataLength, encodedDataLength); |
| 1133 } |
| 1134 |
| 1135 void CachedResourceLoader::subresourceLoaderFinishedLoadingOnePart(ResourceLoade
r* loader) |
| 1136 { |
| 1137 if (m_documentLoader) |
| 1138 m_documentLoader->subresourceLoaderFinishedLoadingOnePart(loader); |
| 1139 } |
| 1140 |
| 1141 void CachedResourceLoader::didInitializeResourceLoader(ResourceLoader* loader) |
| 1142 { |
| 1143 if (m_documentLoader) |
| 1144 m_documentLoader->addResourceLoader(loader); |
| 1145 } |
| 1146 |
| 1147 void CachedResourceLoader::willTerminateResourceLoader(ResourceLoader* loader) |
| 1148 { |
| 1149 if (m_documentLoader) |
| 1150 m_documentLoader->removeResourceLoader(loader); |
| 1151 } |
| 1152 |
| 1153 void CachedResourceLoader::willStartLoadingResource(ResourceRequest& request) |
| 1154 { |
| 1155 if (m_documentLoader) |
| 1156 m_documentLoader->applicationCacheHost()->willStartLoadingResource(reque
st); |
| 1157 } |
| 1158 |
| 1159 bool CachedResourceLoader::defersLoading() const |
| 1160 { |
| 1161 if (Frame* frame = this->frame()) |
| 1162 return frame->page()->defersLoading(); |
| 1163 return false; |
| 1164 } |
| 1165 |
| 1166 bool CachedResourceLoader::isLoadedBy(ResourceLoaderHost* possibleOwner) const |
| 1167 { |
| 1168 return this == possibleOwner; |
| 1169 } |
| 1170 |
| 1171 bool CachedResourceLoader::shouldRequest(CachedResource* resource, const Resourc
eRequest& request, const ResourceLoaderOptions& options) |
| 1172 { |
| 1173 if (!canRequest(resource->type(), request.url(), options)) |
| 1174 return false; |
| 1175 if (resource->type() == CachedResource::ImageResource && shouldDeferImageLoa
d(request.url())) |
| 1176 return false; |
| 1177 return true; |
| 1178 } |
| 1179 |
| 1180 Frame* CachedResourceLoader::inspectedFrame() const |
| 1181 { |
| 1182 // FIXME: return frame of master document for imported documents. |
| 1183 return m_documentLoader ? m_documentLoader->frame() : 0; |
| 1184 } |
| 1185 |
| 1186 void CachedResourceLoader::refResourceLoaderHost() |
| 1187 { |
| 1188 ref(); |
| 1189 } |
| 1190 |
| 1191 void CachedResourceLoader::derefResourceLoaderHost() |
| 1192 { |
| 1193 deref(); |
| 1194 } |
| 1195 |
1080 #if PRELOAD_DEBUG | 1196 #if PRELOAD_DEBUG |
1081 void CachedResourceLoader::printPreloadStats() | 1197 void CachedResourceLoader::printPreloadStats() |
1082 { | 1198 { |
1083 unsigned scripts = 0; | 1199 unsigned scripts = 0; |
1084 unsigned scriptMisses = 0; | 1200 unsigned scriptMisses = 0; |
1085 unsigned stylesheets = 0; | 1201 unsigned stylesheets = 0; |
1086 unsigned stylesheetMisses = 0; | 1202 unsigned stylesheetMisses = 0; |
1087 unsigned images = 0; | 1203 unsigned images = 0; |
1088 unsigned imageMisses = 0; | 1204 unsigned imageMisses = 0; |
1089 ListHashSet<CachedResource*>::iterator end = m_preloads.end(); | 1205 ListHashSet<CachedResource*>::iterator end = m_preloads.end(); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1126 } | 1242 } |
1127 #endif | 1243 #endif |
1128 | 1244 |
1129 const ResourceLoaderOptions& CachedResourceLoader::defaultCachedResourceOptions(
) | 1245 const ResourceLoaderOptions& CachedResourceLoader::defaultCachedResourceOptions(
) |
1130 { | 1246 { |
1131 DEFINE_STATIC_LOCAL(ResourceLoaderOptions, options, (SendCallbacks, SniffCon
tent, BufferData, AllowStoredCredentials, ClientRequestedCredentials, AskClientF
orCrossOriginCredentials, DoSecurityCheck, CheckContentSecurityPolicy, UseDefaul
tOriginRestrictionsForType, DocumentContext)); | 1247 DEFINE_STATIC_LOCAL(ResourceLoaderOptions, options, (SendCallbacks, SniffCon
tent, BufferData, AllowStoredCredentials, ClientRequestedCredentials, AskClientF
orCrossOriginCredentials, DoSecurityCheck, CheckContentSecurityPolicy, UseDefaul
tOriginRestrictionsForType, DocumentContext)); |
1132 return options; | 1248 return options; |
1133 } | 1249 } |
1134 | 1250 |
1135 } | 1251 } |
OLD | NEW |