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

Side by Side Diff: Source/core/fetch/ResourceFetcher.cpp

Issue 24009002: Move synchronously fetching to ResourceFetcher, as well as most of the logic (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 7 years, 3 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 19 matching lines...) Expand all
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/fetch/CSSStyleSheetResource.h" 32 #include "core/fetch/CSSStyleSheetResource.h"
33 #include "core/fetch/DocumentResource.h" 33 #include "core/fetch/DocumentResource.h"
34 #include "core/fetch/FetchContext.h" 34 #include "core/fetch/FetchContext.h"
35 #include "core/fetch/FetchRequest.h" 35 #include "core/fetch/FetchRequest.h"
36 #include "core/fetch/FontResource.h" 36 #include "core/fetch/FontResource.h"
37 #include "core/fetch/ImageResource.h" 37 #include "core/fetch/ImageResource.h"
38 #include "core/fetch/MemoryCache.h" 38 #include "core/fetch/MemoryCache.h"
39 #include "core/fetch/RawResource.h" 39 #include "core/fetch/RawResource.h"
40 #include "core/fetch/ResourceLoader.h"
40 #include "core/fetch/ResourceLoaderSet.h" 41 #include "core/fetch/ResourceLoaderSet.h"
41 #include "core/fetch/ScriptResource.h" 42 #include "core/fetch/ScriptResource.h"
42 #include "core/fetch/ShaderResource.h" 43 #include "core/fetch/ShaderResource.h"
43 #include "core/fetch/TextTrackResource.h" 44 #include "core/fetch/TextTrackResource.h"
44 #include "core/fetch/XSLStyleSheetResource.h" 45 #include "core/fetch/XSLStyleSheetResource.h"
45 #include "core/html/HTMLElement.h" 46 #include "core/html/HTMLElement.h"
46 #include "core/html/HTMLFrameOwnerElement.h" 47 #include "core/html/HTMLFrameOwnerElement.h"
47 #include "core/html/HTMLImport.h" 48 #include "core/html/HTMLImport.h"
48 #include "core/inspector/InspectorInstrumentation.h" 49 #include "core/inspector/InspectorInstrumentation.h"
49 #include "core/loader/DocumentLoader.h" 50 #include "core/loader/DocumentLoader.h"
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 return 0; 204 return 0;
204 } 205 }
205 206
206 FetchContext& ResourceFetcher::context() const 207 FetchContext& ResourceFetcher::context() const
207 { 208 {
208 if (Frame* frame = this->frame()) 209 if (Frame* frame = this->frame())
209 return frame->fetchContext(); 210 return frame->fetchContext();
210 return FetchContext::nullInstance(); 211 return FetchContext::nullInstance();
211 } 212 }
212 213
214 unsigned long ResourceFetcher::fetchSynchronously(const ResourceRequest& passedR equest, StoredCredentials storedCredentials, ResourceError& error, ResourceRespo nse& response, Vector<char>& data)
215 {
216 ASSERT(document());
217 ResourceRequest request(passedRequest);
218 request.setTimeoutInterval(10);
219 addAdditionalRequestHeaders(request, Resource::Raw);
220
221 unsigned long identifier = createUniqueIdentifier();
222 context().dispatchWillSendRequest(m_documentLoader, identifier, request, Res ourceResponse());
223 documentLoader()->applicationCacheHost()->willStartLoadingSynchronously(requ est);
224 ResourceLoader::loadResourceSynchronously(request, storedCredentials, error, response, data);
225 int encodedDataLength = response.resourceLoadInfo() ? static_cast<int>(respo nse.resourceLoadInfo()->encodedDataLength) : -1;
226 context().sendRemainingDelegateMessages(m_documentLoader, identifier, respon se, data.data(), data.size(), encodedDataLength, error);
227 return identifier;
228 }
229
213 ResourcePtr<ImageResource> ResourceFetcher::fetchImage(FetchRequest& request) 230 ResourcePtr<ImageResource> ResourceFetcher::fetchImage(FetchRequest& request)
214 { 231 {
215 if (Frame* f = frame()) { 232 if (Frame* f = frame()) {
216 if (f->document()->pageDismissalEventBeingDispatched() != Document::NoDi smissal) { 233 if (f->document()->pageDismissalEventBeingDispatched() != Document::NoDi smissal) {
217 KURL requestURL = request.resourceRequest().url(); 234 KURL requestURL = request.resourceRequest().url();
218 if (requestURL.isValid() && canRequest(Resource::Image, requestURL, request.options(), request.forPreload())) 235 if (requestURL.isValid() && canRequest(Resource::Image, requestURL, request.options(), request.forPreload()))
219 PingLoader::loadImage(f, requestURL); 236 PingLoader::loadImage(f, requestURL);
220 return 0; 237 return 0;
221 } 238 }
222 } 239 }
(...skipping 750 matching lines...) Expand 10 before | Expand all | Expand 10 after
973 m_documentResources.remove(*it); 990 m_documentResources.remove(*it);
974 } 991 }
975 992
976 void ResourceFetcher::performPostLoadActions() 993 void ResourceFetcher::performPostLoadActions()
977 { 994 {
978 checkForPendingPreloads(); 995 checkForPendingPreloads();
979 } 996 }
980 997
981 void ResourceFetcher::notifyLoadedFromMemoryCache(Resource* resource) 998 void ResourceFetcher::notifyLoadedFromMemoryCache(Resource* resource)
982 { 999 {
983 if (!frame() || resource->status() != Resource::Cached || m_validatedURLs.co ntains(resource->url())) 1000 if (!frame() || !frame()->page() || resource->status() != Resource::Cached | | m_validatedURLs.contains(resource->url()))
1001 return;
1002 if (!resource->shouldSendResourceLoadCallbacks())
984 return; 1003 return;
985 1004
986 // FIXME: If the WebKit client changes or cancels the request, WebCore does not respect this and continues the load. 1005 ResourceRequest request(resource->url());
987 frame()->loader()->loadedResourceFromMemoryCache(resource); 1006 unsigned long identifier = createUniqueIdentifier();
1007 context().dispatchDidLoadResourceFromMemoryCache(request, resource->response ());
1008 // FIXME: If willSendRequest changes the request, we don't respect it.
1009 willSendRequest(resource, request, ResourceResponse(), resource->options());
1010 InspectorInstrumentation::markResourceAsCached(frame()->page(), identifier);
1011 context().sendRemainingDelegateMessages(m_documentLoader, identifier, resour ce->response(), 0, resource->encodedSize(), 0, ResourceError());
988 } 1012 }
989 1013
990 void ResourceFetcher::incrementRequestCount(const Resource* res) 1014 void ResourceFetcher::incrementRequestCount(const Resource* res)
991 { 1015 {
992 if (res->ignoreForRequestCount()) 1016 if (res->ignoreForRequestCount())
993 return; 1017 return;
994 1018
995 ++m_requestCount; 1019 ++m_requestCount;
996 } 1020 }
997 1021
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after
1286 } 1310 }
1287 #endif 1311 #endif
1288 1312
1289 const ResourceLoaderOptions& ResourceFetcher::defaultResourceOptions() 1313 const ResourceLoaderOptions& ResourceFetcher::defaultResourceOptions()
1290 { 1314 {
1291 DEFINE_STATIC_LOCAL(ResourceLoaderOptions, options, (SendCallbacks, SniffCon tent, BufferData, AllowStoredCredentials, ClientRequestedCredentials, AskClientF orCrossOriginCredentials, DoSecurityCheck, CheckContentSecurityPolicy, UseDefaul tOriginRestrictionsForType, DocumentContext)); 1315 DEFINE_STATIC_LOCAL(ResourceLoaderOptions, options, (SendCallbacks, SniffCon tent, BufferData, AllowStoredCredentials, ClientRequestedCredentials, AskClientF orCrossOriginCredentials, DoSecurityCheck, CheckContentSecurityPolicy, UseDefaul tOriginRestrictionsForType, DocumentContext));
1292 return options; 1316 return options;
1293 } 1317 }
1294 1318
1295 } 1319 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698