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" | |
35 #include "core/loader/DocumentLoader.h" | 34 #include "core/loader/DocumentLoader.h" |
36 #include "core/loader/FrameLoader.h" | 35 #include "core/loader/FrameLoader.h" |
37 #include "core/loader/FrameLoaderClient.h" | 36 #include "core/loader/FrameLoaderClient.h" |
38 #include "core/loader/PingLoader.h" | 37 #include "core/loader/PingLoader.h" |
39 #include "core/loader/UniqueIdentifier.h" | 38 #include "core/loader/UniqueIdentifier.h" |
40 #include "core/loader/appcache/ApplicationCacheHost.h" | |
41 #include "core/loader/cache/CachedCSSStyleSheet.h" | 39 #include "core/loader/cache/CachedCSSStyleSheet.h" |
42 #include "core/loader/cache/CachedDocument.h" | 40 #include "core/loader/cache/CachedDocument.h" |
43 #include "core/loader/cache/CachedFont.h" | 41 #include "core/loader/cache/CachedFont.h" |
44 #include "core/loader/cache/CachedImage.h" | 42 #include "core/loader/cache/CachedImage.h" |
45 #include "core/loader/cache/CachedRawResource.h" | 43 #include "core/loader/cache/CachedRawResource.h" |
46 #include "core/loader/cache/CachedResourceRequest.h" | 44 #include "core/loader/cache/CachedResourceRequest.h" |
47 #include "core/loader/cache/CachedScript.h" | 45 #include "core/loader/cache/CachedScript.h" |
48 #include "core/loader/cache/CachedShader.h" | 46 #include "core/loader/cache/CachedShader.h" |
49 #include "core/loader/cache/CachedTextTrack.h" | 47 #include "core/loader/cache/CachedTextTrack.h" |
50 #include "core/loader/cache/CachedXSLStyleSheet.h" | 48 #include "core/loader/cache/CachedXSLStyleSheet.h" |
(...skipping 444 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
495 if (priority != resource->resourceRequest().priority()) { | 493 if (priority != resource->resourceRequest().priority()) { |
496 resource->resourceRequest().setPriority(priority); | 494 resource->resourceRequest().setPriority(priority); |
497 resource->didChangePriority(priority); | 495 resource->didChangePriority(priority); |
498 } | 496 } |
499 } | 497 } |
500 | 498 |
501 if ((policy != Use || resource->stillNeedsLoad()) && CachedResourceRequest::
NoDefer == request.defer()) { | 499 if ((policy != Use || resource->stillNeedsLoad()) && CachedResourceRequest::
NoDefer == request.defer()) { |
502 if (!frame()) | 500 if (!frame()) |
503 return 0; | 501 return 0; |
504 | 502 |
505 FrameLoader* frameLoader = this->frameLoader(); | 503 FrameLoader* frameLoader = frame()->loader(); |
506 if (request.options().securityCheck == DoSecurityCheck && (frameLoader->
state() == FrameStateProvisional || !frameLoader->activeDocumentLoader() || fram
eLoader->activeDocumentLoader()->isStopping())) | 504 if (request.options().securityCheck == DoSecurityCheck && (frameLoader->
state() == FrameStateProvisional || !frameLoader->activeDocumentLoader() || fram
eLoader->activeDocumentLoader()->isStopping())) |
507 return 0; | 505 return 0; |
508 | 506 |
509 if (!m_documentLoader->scheduleArchiveLoad(resource.get(), request.resou
rceRequest())) | 507 if (!m_documentLoader->scheduleArchiveLoad(resource.get(), request.resou
rceRequest())) |
510 resource->load(this, request.options()); | 508 resource->load(this, request.options()); |
511 | 509 |
512 // We don't support immediate loads, but we do support immediate failure
. | 510 // We don't support immediate loads, but we do support immediate failure
. |
513 if (resource->errorOccurred()) { | 511 if (resource->errorOccurred()) { |
514 if (resource->inCache()) | 512 if (resource->inCache()) |
515 memoryCache()->remove(resource.get()); | 513 memoryCache()->remove(resource.get()); |
(...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
888 return CachePolicyVerify; | 886 return CachePolicyVerify; |
889 | 887 |
890 if (type != CachedResource::MainResource) | 888 if (type != CachedResource::MainResource) |
891 return frame()->loader()->subresourceCachePolicy(); | 889 return frame()->loader()->subresourceCachePolicy(); |
892 | 890 |
893 if (frame()->loader()->loadType() == FrameLoadTypeReloadFromOrigin || frame(
)->loader()->loadType() == FrameLoadTypeReload) | 891 if (frame()->loader()->loadType() == FrameLoadTypeReloadFromOrigin || frame(
)->loader()->loadType() == FrameLoadTypeReload) |
894 return CachePolicyReload; | 892 return CachePolicyReload; |
895 return CachePolicyVerify; | 893 return CachePolicyVerify; |
896 } | 894 } |
897 | 895 |
898 void CachedResourceLoader::didLoadResource(CachedResource* resource) | 896 void CachedResourceLoader::loadDone(CachedResource* resource) |
899 { | 897 { |
900 RefPtr<DocumentLoader> protectDocumentLoader(m_documentLoader); | 898 RefPtr<DocumentLoader> protectDocumentLoader(m_documentLoader); |
901 RefPtr<Document> protectDocument(m_document); | 899 RefPtr<Document> protectDocument(m_document); |
902 | 900 |
903 if (resource && resource->response().isHTTP() && ((!resource->errorOccurred(
) && !resource->wasCanceled()) || resource->response().httpStatusCode() == 304))
{ | 901 if (resource && resource->response().isHTTP() && ((!resource->errorOccurred(
) && !resource->wasCanceled()) || resource->response().httpStatusCode() == 304))
{ |
904 HashMap<CachedResource*, CachedResourceInitiatorInfo>::iterator initiato
rIt = m_initiatorMap.find(resource); | 902 HashMap<CachedResource*, CachedResourceInitiatorInfo>::iterator initiato
rIt = m_initiatorMap.find(resource); |
905 if (initiatorIt != m_initiatorMap.end()) { | 903 if (initiatorIt != m_initiatorMap.end()) { |
906 ASSERT(document()); | 904 ASSERT(document()); |
907 Document* initiatorDocument = document(); | 905 Document* initiatorDocument = document(); |
908 if (resource->type() == CachedResource::MainResource) | 906 if (resource->type() == CachedResource::MainResource) |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1072 memoryCache()->remove(res); | 1070 memoryCache()->remove(res); |
1073 } | 1071 } |
1074 m_preloads.clear(); | 1072 m_preloads.clear(); |
1075 } | 1073 } |
1076 | 1074 |
1077 void CachedResourceLoader::clearPendingPreloads() | 1075 void CachedResourceLoader::clearPendingPreloads() |
1078 { | 1076 { |
1079 m_pendingPreloads.clear(); | 1077 m_pendingPreloads.clear(); |
1080 } | 1078 } |
1081 | 1079 |
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 | |
1196 #if PRELOAD_DEBUG | 1080 #if PRELOAD_DEBUG |
1197 void CachedResourceLoader::printPreloadStats() | 1081 void CachedResourceLoader::printPreloadStats() |
1198 { | 1082 { |
1199 unsigned scripts = 0; | 1083 unsigned scripts = 0; |
1200 unsigned scriptMisses = 0; | 1084 unsigned scriptMisses = 0; |
1201 unsigned stylesheets = 0; | 1085 unsigned stylesheets = 0; |
1202 unsigned stylesheetMisses = 0; | 1086 unsigned stylesheetMisses = 0; |
1203 unsigned images = 0; | 1087 unsigned images = 0; |
1204 unsigned imageMisses = 0; | 1088 unsigned imageMisses = 0; |
1205 ListHashSet<CachedResource*>::iterator end = m_preloads.end(); | 1089 ListHashSet<CachedResource*>::iterator end = m_preloads.end(); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1242 } | 1126 } |
1243 #endif | 1127 #endif |
1244 | 1128 |
1245 const ResourceLoaderOptions& CachedResourceLoader::defaultCachedResourceOptions(
) | 1129 const ResourceLoaderOptions& CachedResourceLoader::defaultCachedResourceOptions(
) |
1246 { | 1130 { |
1247 DEFINE_STATIC_LOCAL(ResourceLoaderOptions, options, (SendCallbacks, SniffCon
tent, BufferData, AllowStoredCredentials, ClientRequestedCredentials, AskClientF
orCrossOriginCredentials, DoSecurityCheck, CheckContentSecurityPolicy, UseDefaul
tOriginRestrictionsForType, DocumentContext)); | 1131 DEFINE_STATIC_LOCAL(ResourceLoaderOptions, options, (SendCallbacks, SniffCon
tent, BufferData, AllowStoredCredentials, ClientRequestedCredentials, AskClientF
orCrossOriginCredentials, DoSecurityCheck, CheckContentSecurityPolicy, UseDefaul
tOriginRestrictionsForType, DocumentContext)); |
1248 return options; | 1132 return options; |
1249 } | 1133 } |
1250 | 1134 |
1251 } | 1135 } |
OLD | NEW |