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

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

Issue 1170503003: Remove resource type-specific fetching logic from ResourceFetcher (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Null-check Document::loader() before calling startPreload() Created 5 years, 6 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
« no previous file with comments | « Source/core/fetch/RawResource.h ('k') | Source/core/fetch/Resource.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2011 Google Inc. All Rights Reserved. 2 * Copyright (C) 2011 Google Inc. All Rights Reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution. 11 * documentation and/or other materials provided with the distribution.
12 * 12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS ``AS IS'' AND ANY 13 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */ 24 */
25 25
26 #include "config.h" 26 #include "config.h"
27 #include "core/fetch/RawResource.h" 27 #include "core/fetch/RawResource.h"
28 28
29 #include "core/fetch/FetchRequest.h"
30 #include "core/fetch/MemoryCache.h"
29 #include "core/fetch/ResourceClientWalker.h" 31 #include "core/fetch/ResourceClientWalker.h"
30 #include "core/fetch/ResourceFetcher.h" 32 #include "core/fetch/ResourceFetcher.h"
31 #include "core/fetch/ResourceLoader.h" 33 #include "core/fetch/ResourceLoader.h"
34 #include "core/fetch/SubstituteData.h"
32 #include "platform/SharedBuffer.h" 35 #include "platform/SharedBuffer.h"
33 36
34 namespace blink { 37 namespace blink {
35 38
39 void RawResource::preCacheSubstituteDataForMainResource(const FetchRequest& requ est, ResourceFetcher* fetcher, const SubstituteData& substituteData)
40 {
41 const String cacheIdentifier = fetcher->getCacheIdentifier();
42 const KURL& url = request.url();
43 if (Resource* oldResource = memoryCache()->resourceForURL(url, cacheIdentifi er))
44 memoryCache()->remove(oldResource);
45
46 ResourceResponse response(url, substituteData.mimeType(), substituteData.con tent()->size(), substituteData.textEncoding(), emptyString());
47 ResourcePtr<Resource> resource = new RawResource(request.resourceRequest(), Resource::MainResource);
48 resource->setNeedsSynchronousCacheHit(substituteData.forceSynchronousLoad()) ;
49 resource->setOptions(request.options());
50 resource->setDataBufferingPolicy(BufferData);
51 resource->responseReceived(response, nullptr);
52 if (substituteData.content()->size())
53 resource->setResourceBuffer(substituteData.content());
54 resource->setCacheIdentifier(cacheIdentifier);
55 resource->finish();
56 memoryCache()->add(resource.get());
57 }
58
59 ResourcePtr<Resource> RawResource::fetchSynchronously(FetchRequest& request, Res ourceFetcher* fetcher)
60 {
61 request.mutableResourceRequest().setTimeoutInterval(10);
62 ResourceLoaderOptions options(request.options());
63 options.synchronousPolicy = RequestSynchronously;
64 request.setOptions(options);
65 return fetcher->requestResource(request, RawResourceFactory(Resource::Raw));
66 }
67
68 ResourcePtr<RawResource> RawResource::fetchImport(FetchRequest& request, Resourc eFetcher* fetcher)
69 {
70 ASSERT(request.resourceRequest().frameType() == WebURLRequest::FrameTypeNone );
71 request.mutableResourceRequest().setRequestContext(WebURLRequest::RequestCon textImport);
72 RawResourceFactory factory(Resource::ImportResource);
73 return toRawResource(fetcher->requestResource(request, RawResourceFactory(Re source::ImportResource)));
74 }
75
76 ResourcePtr<RawResource> RawResource::fetch(FetchRequest& request, ResourceFetch er* fetcher)
77 {
78 ASSERT(request.resourceRequest().frameType() == WebURLRequest::FrameTypeNone );
79 ASSERT(request.resourceRequest().requestContext() != WebURLRequest::RequestC ontextUnspecified);
80 return toRawResource(fetcher->requestResource(request, RawResourceFactory(Re source::Raw)));
81 }
82
83 ResourcePtr<RawResource> RawResource::fetchMainResource(FetchRequest& request, R esourceFetcher* fetcher, const SubstituteData& substituteData)
84 {
85 ASSERT(request.resourceRequest().frameType() != WebURLRequest::FrameTypeNone );
86 ASSERT(request.resourceRequest().requestContext() == WebURLRequest::RequestC ontextForm || request.resourceRequest().requestContext() == WebURLRequest::Reque stContextFrame || request.resourceRequest().requestContext() == WebURLRequest::R equestContextHyperlink || request.resourceRequest().requestContext() == WebURLRe quest::RequestContextIframe || request.resourceRequest().requestContext() == Web URLRequest::RequestContextInternal || request.resourceRequest().requestContext() == WebURLRequest::RequestContextLocation);
87
88 if (substituteData.isValid())
89 preCacheSubstituteDataForMainResource(request, fetcher, substituteData);
90 return toRawResource(fetcher->requestResource(request, RawResourceFactory(Re source::MainResource)));
91 }
92
93 ResourcePtr<RawResource> RawResource::fetchMedia(FetchRequest& request, Resource Fetcher* fetcher)
94 {
95 ASSERT(request.resourceRequest().frameType() == WebURLRequest::FrameTypeNone );
96 ASSERT(request.resourceRequest().requestContext() == WebURLRequest::RequestC ontextAudio || request.resourceRequest().requestContext() == WebURLRequest::Requ estContextVideo);
97 return toRawResource(fetcher->requestResource(request, RawResourceFactory(Re source::Media)));
98 }
99
100 ResourcePtr<RawResource> RawResource::fetchTextTrack(FetchRequest& request, Reso urceFetcher* fetcher)
101 {
102 ASSERT(request.resourceRequest().frameType() == WebURLRequest::FrameTypeNone );
103 request.mutableResourceRequest().setRequestContext(WebURLRequest::RequestCon textTrack);
104 return toRawResource(fetcher->requestResource(request, RawResourceFactory(Re source::TextTrack)));
105 }
106
36 RawResource::RawResource(const ResourceRequest& resourceRequest, Type type) 107 RawResource::RawResource(const ResourceRequest& resourceRequest, Type type)
37 : Resource(resourceRequest, type) 108 : Resource(resourceRequest, type)
38 { 109 {
39 } 110 }
40 111
41 void RawResource::appendData(const char* data, unsigned length) 112 void RawResource::appendData(const char* data, unsigned length)
42 { 113 {
43 Resource::appendData(data, length); 114 Resource::appendData(data, length);
44 115
45 ResourcePtr<RawResource> protect(this); 116 ResourcePtr<RawResource> protect(this);
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 for (const auto& header : oldHeaders) { 264 for (const auto& header : oldHeaders) {
194 AtomicString headerName = header.key; 265 AtomicString headerName = header.key;
195 if (!shouldIgnoreHeaderForCacheReuse(headerName) && header.value != newH eaders.get(headerName)) 266 if (!shouldIgnoreHeaderForCacheReuse(headerName) && header.value != newH eaders.get(headerName))
196 return false; 267 return false;
197 } 268 }
198 269
199 return true; 270 return true;
200 } 271 }
201 272
202 } // namespace blink 273 } // namespace blink
OLDNEW
« no previous file with comments | « Source/core/fetch/RawResource.h ('k') | Source/core/fetch/Resource.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698