Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(37)

Side by Side Diff: Source/core/loader/cache/CachedResourceLoader.cpp

Issue 19574002: Refactoring: Introduce ResouceLoaderHost interface for unloading ResourceLoader. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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 447 matching lines...) Expand 10 before | Expand all | Expand 10 after
496 if (priority != resource->resourceRequest().priority()) { 498 if (priority != resource->resourceRequest().priority()) {
497 resource->resourceRequest().setPriority(priority); 499 resource->resourceRequest().setPriority(priority);
498 resource->didChangePriority(priority); 500 resource->didChangePriority(priority);
499 } 501 }
500 } 502 }
501 503
502 if ((policy != Use || resource->stillNeedsLoad()) && CachedResourceRequest:: NoDefer == request.defer()) { 504 if ((policy != Use || resource->stillNeedsLoad()) && CachedResourceRequest:: NoDefer == request.defer()) {
503 if (!frame()) 505 if (!frame())
504 return 0; 506 return 0;
505 507
506 FrameLoader* frameLoader = frame()->loader(); 508 FrameLoader* frameLoader = this->frameLoader();
507 if (request.options().securityCheck == DoSecurityCheck && (frameLoader-> state() == FrameStateProvisional || !frameLoader->activeDocumentLoader() || fram eLoader->activeDocumentLoader()->isStopping())) 509 if (request.options().securityCheck == DoSecurityCheck && (frameLoader-> state() == FrameStateProvisional || !frameLoader->activeDocumentLoader() || fram eLoader->activeDocumentLoader()->isStopping()))
508 return 0; 510 return 0;
509 511
510 if (!m_documentLoader->scheduleArchiveLoad(resource.get(), request.resou rceRequest())) 512 if (!m_documentLoader->scheduleArchiveLoad(resource.get(), request.resou rceRequest()))
511 resource->load(this, request.options()); 513 resource->load(this, request.options());
512 514
513 // We don't support immediate loads, but we do support immediate failure . 515 // We don't support immediate loads, but we do support immediate failure .
514 if (resource->errorOccurred()) { 516 if (resource->errorOccurred()) {
515 if (resource->inCache()) 517 if (resource->inCache())
516 memoryCache()->remove(resource.get()); 518 memoryCache()->remove(resource.get());
(...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after
889 return CachePolicyVerify; 891 return CachePolicyVerify;
890 892
891 if (type != CachedResource::MainResource) 893 if (type != CachedResource::MainResource)
892 return frame()->loader()->subresourceCachePolicy(); 894 return frame()->loader()->subresourceCachePolicy();
893 895
894 if (frame()->loader()->loadType() == FrameLoadTypeReloadFromOrigin || frame( )->loader()->loadType() == FrameLoadTypeReload) 896 if (frame()->loader()->loadType() == FrameLoadTypeReloadFromOrigin || frame( )->loader()->loadType() == FrameLoadTypeReload)
895 return CachePolicyReload; 897 return CachePolicyReload;
896 return CachePolicyVerify; 898 return CachePolicyVerify;
897 } 899 }
898 900
899 void CachedResourceLoader::loadDone(CachedResource* resource) 901 void CachedResourceLoader::didLoadResource(CachedResource* resource)
900 { 902 {
901 RefPtr<DocumentLoader> protectDocumentLoader(m_documentLoader); 903 RefPtr<DocumentLoader> protectDocumentLoader(m_documentLoader);
902 RefPtr<Document> protectDocument(m_document); 904 RefPtr<Document> protectDocument(m_document);
903 905
904 if (resource && resource->response().isHTTP() && ((!resource->errorOccurred( ) && !resource->wasCanceled()) || resource->response().httpStatusCode() == 304)) { 906 if (resource && resource->response().isHTTP() && ((!resource->errorOccurred( ) && !resource->wasCanceled()) || resource->response().httpStatusCode() == 304)) {
905 HashMap<CachedResource*, CachedResourceInitiatorInfo>::iterator initiato rIt = m_initiatorMap.find(resource); 907 HashMap<CachedResource*, CachedResourceInitiatorInfo>::iterator initiato rIt = m_initiatorMap.find(resource);
906 if (initiatorIt != m_initiatorMap.end()) { 908 if (initiatorIt != m_initiatorMap.end()) {
907 ASSERT(document()); 909 ASSERT(document());
908 Document* initiatorDocument = document(); 910 Document* initiatorDocument = document();
909 if (resource->type() == CachedResource::MainResource) 911 if (resource->type() == CachedResource::MainResource)
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
1073 memoryCache()->remove(res); 1075 memoryCache()->remove(res);
1074 } 1076 }
1075 m_preloads.clear(); 1077 m_preloads.clear();
1076 } 1078 }
1077 1079
1078 void CachedResourceLoader::clearPendingPreloads() 1080 void CachedResourceLoader::clearPendingPreloads()
1079 { 1081 {
1080 m_pendingPreloads.clear(); 1082 m_pendingPreloads.clear();
1081 } 1083 }
1082 1084
1085 inline FrameLoader* CachedResourceLoader::frameLoader()
1086 {
1087 return frame() ? frame()->loader() : 0;
1088 }
1089
1090 void CachedResourceLoader::didFinishLoading(const CachedResource* resource, doub le finishTime, const ResourceLoaderOptions& options)
1091 {
1092 if (options.sendLoadCallbacks != SendCallbacks)
1093 return;
1094 if (FrameLoader* loader = frameLoader())
1095 loader->notifier()->dispatchDidFinishLoading(m_documentLoader, resource- >identifier(), finishTime);
1096 }
1097
1098 void CachedResourceLoader::didChangeLoadingPriority(const CachedResource* resour ce, ResourceLoadPriority loadPriority)
1099 {
1100 if (FrameLoader* loader = frameLoader())
1101 loader->client()->dispatchDidChangeResourcePriority(resource->identifier (), loadPriority);
1102 }
1103
1104 void CachedResourceLoader::didFailLoading(const CachedResource* resource, const ResourceError& error, const ResourceLoaderOptions& options)
1105 {
1106 if (options.sendLoadCallbacks != SendCallbacks)
1107 return;
1108 if (FrameLoader* loader = frameLoader())
1109 loader->notifier()->dispatchDidFail(m_documentLoader, resource->identifi er(), error);
1110 }
1111
1112 void CachedResourceLoader::willSendRequest(const CachedResource* resource, Resou rceRequest& request, const ResourceResponse& redirectResponse, const ResourceLoa derOptions& options)
1113 {
1114 if (options.sendLoadCallbacks == SendCallbacks) {
1115 if (FrameLoader* loader = frameLoader())
1116 loader->notifier()->dispatchWillSendRequest(m_documentLoader, resour ce->identifier(), request, redirectResponse, options.initiatorInfo);
1117 } else {
1118 InspectorInstrumentation::willSendRequest(frame(), resource->identifier( ), m_documentLoader, request, redirectResponse, options.initiatorInfo);
1119 }
1120 }
1121
1122 void CachedResourceLoader::didReceiveResponse(const CachedResource* resource, co nst ResourceResponse& response, const ResourceLoaderOptions& options)
1123 {
1124 if (options.sendLoadCallbacks != SendCallbacks)
1125 return;
1126 if (FrameLoader* loader = frameLoader())
1127 loader->notifier()->dispatchDidReceiveResponse(m_documentLoader, resourc e->identifier(), response);
1128 }
1129
1130 void CachedResourceLoader::didReceiveData(const CachedResource* resource, const char* data, int dataLength, int encodedDataLength, const ResourceLoaderOptions& options)
1131 {
1132 if (options.sendLoadCallbacks != SendCallbacks)
1133 return;
1134 if (FrameLoader* loader = frameLoader())
1135 loader->notifier()->dispatchDidReceiveData(m_documentLoader, resource->i dentifier(), data, dataLength, encodedDataLength);
1136 }
1137
1138 ResourceError CachedResourceLoader::cancelledLoadingError(const ResourceRequest& request)
1139 {
1140 if (FrameLoader* loader = frameLoader())
1141 return loader->cancelledError(request);
1142 return ResourceError(String(), 0, String(), String());
1143 }
1144
1145 ResourceError CachedResourceLoader::cannotShowURLLoadingError(const ResourceRequ est& request)
1146 {
1147 if (FrameLoader* loader = frameLoader())
1148 return loader->cancelledError(request);
1149 return ResourceError(String(), 0, String(), String());
1150 }
1151
1152 void CachedResourceLoader::subresourceLoaderFinishedLoadingOnePart(ResourceLoade r* loader)
1153 {
1154 if (m_documentLoader)
1155 m_documentLoader->subresourceLoaderFinishedLoadingOnePart(loader);
1156 }
1157
1158 void CachedResourceLoader::didInitializeResourceLoader(ResourceLoader* loader)
1159 {
1160 if (m_documentLoader)
1161 m_documentLoader->addResourceLoader(loader);
1162 }
1163
1164 void CachedResourceLoader::willTerminateResourceLoader(ResourceLoader* loader)
1165 {
1166 if (m_documentLoader)
1167 m_documentLoader->removeResourceLoader(loader);
1168 }
1169
1170 void CachedResourceLoader::willStartLoadingResource(ResourceRequest& request)
1171 {
1172 if (m_documentLoader)
1173 m_documentLoader->applicationCacheHost()->willStartLoadingResource(reque st);
1174 }
1175
1176 bool CachedResourceLoader::defersLoading() const
1177 {
1178 if (Frame* frame = this->frame())
1179 return frame->page()->defersLoading();
1180 return false;
1181 }
1182
1183 bool CachedResourceLoader::isLoadedBy(CachedResourceLoader* possibleOwner) const
1184 {
1185 return this == possibleOwner;
1186 }
1187
1188 bool CachedResourceLoader::shouldRequest(CachedResource* resource, const Resourc eRequest& request, const ResourceLoaderOptions& options)
1189 {
1190 if (!canRequest(resource->type(), request.url(), options))
1191 return false;
1192 if (resource->type() == CachedResource::ImageResource && shouldDeferImageLoa d(request.url()))
1193 return false;
1194 return true;
1195 }
1196
1197 Frame* CachedResourceLoader::inspectedFrame() const
1198 {
1199 // FIXME: return frame of master document for imported documents.
1200 return m_documentLoader ? m_documentLoader->frame() : 0;
1201 }
1202
1203 void CachedResourceLoader::refResourceLoaderHost()
1204 {
1205 ref();
1206 }
1207
1208 void CachedResourceLoader::derefResourceLoaderHost()
1209 {
1210 deref();
1211 }
1212
1083 #if PRELOAD_DEBUG 1213 #if PRELOAD_DEBUG
1084 void CachedResourceLoader::printPreloadStats() 1214 void CachedResourceLoader::printPreloadStats()
1085 { 1215 {
1086 unsigned scripts = 0; 1216 unsigned scripts = 0;
1087 unsigned scriptMisses = 0; 1217 unsigned scriptMisses = 0;
1088 unsigned stylesheets = 0; 1218 unsigned stylesheets = 0;
1089 unsigned stylesheetMisses = 0; 1219 unsigned stylesheetMisses = 0;
1090 unsigned images = 0; 1220 unsigned images = 0;
1091 unsigned imageMisses = 0; 1221 unsigned imageMisses = 0;
1092 ListHashSet<CachedResource*>::iterator end = m_preloads.end(); 1222 ListHashSet<CachedResource*>::iterator end = m_preloads.end();
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
1141 info.addMember(m_garbageCollectDocumentResourcesTimer, "garbageCollectDocume ntResourcesTimer"); 1271 info.addMember(m_garbageCollectDocumentResourcesTimer, "garbageCollectDocume ntResourcesTimer");
1142 } 1272 }
1143 1273
1144 const ResourceLoaderOptions& CachedResourceLoader::defaultCachedResourceOptions( ) 1274 const ResourceLoaderOptions& CachedResourceLoader::defaultCachedResourceOptions( )
1145 { 1275 {
1146 DEFINE_STATIC_LOCAL(ResourceLoaderOptions, options, (SendCallbacks, SniffCon tent, BufferData, AllowStoredCredentials, ClientRequestedCredentials, AskClientF orCrossOriginCredentials, DoSecurityCheck, CheckContentSecurityPolicy, UseDefaul tOriginRestrictionsForType, DocumentContext)); 1276 DEFINE_STATIC_LOCAL(ResourceLoaderOptions, options, (SendCallbacks, SniffCon tent, BufferData, AllowStoredCredentials, ClientRequestedCredentials, AskClientF orCrossOriginCredentials, DoSecurityCheck, CheckContentSecurityPolicy, UseDefaul tOriginRestrictionsForType, DocumentContext));
1147 return options; 1277 return options;
1148 } 1278 }
1149 1279
1150 } 1280 }
OLDNEW
« Source/core/loader/ResourceLoaderHost.h ('K') | « Source/core/loader/cache/CachedResourceLoader.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698