OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2006, 2007, 2010, 2011 Apple Inc. All rights reserved. | 2 * Copyright (C) 2006, 2007, 2010, 2011 Apple Inc. All rights reserved. |
3 * (C) 2007 Graham Dennis (graham.dennis@gmail.com) | 3 * (C) 2007 Graham Dennis (graham.dennis@gmail.com) |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
7 * are met: | 7 * are met: |
8 * | 8 * |
9 * 1. Redistributions of source code must retain the above copyright | 9 * 1. Redistributions of source code must retain the above copyright |
10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 | 50 |
51 ResourceLoader* ResourceLoader::create(ResourceFetcher* fetcher, Resource* resou
rce) | 51 ResourceLoader* ResourceLoader::create(ResourceFetcher* fetcher, Resource* resou
rce) |
52 { | 52 { |
53 return new ResourceLoader(fetcher, resource); | 53 return new ResourceLoader(fetcher, resource); |
54 } | 54 } |
55 | 55 |
56 ResourceLoader::ResourceLoader(ResourceFetcher* fetcher, Resource* resource) | 56 ResourceLoader::ResourceLoader(ResourceFetcher* fetcher, Resource* resource) |
57 : m_fetcher(fetcher) | 57 : m_fetcher(fetcher) |
58 , m_resource(resource) | 58 , m_resource(resource) |
59 { | 59 { |
60 ASSERT(m_resource); | 60 DCHECK(m_resource); |
61 ASSERT(m_fetcher); | 61 DCHECK(m_fetcher); |
62 m_resource->setLoader(this); | 62 m_resource->setLoader(this); |
63 } | 63 } |
64 | 64 |
65 ResourceLoader::~ResourceLoader() | 65 ResourceLoader::~ResourceLoader() |
66 { | 66 { |
67 DCHECK(!m_loader); | 67 DCHECK(!m_loader); |
68 } | 68 } |
69 | 69 |
70 DEFINE_TRACE(ResourceLoader) | 70 DEFINE_TRACE(ResourceLoader) |
71 { | 71 { |
72 visitor->trace(m_fetcher); | 72 visitor->trace(m_fetcher); |
73 visitor->trace(m_resource); | 73 visitor->trace(m_resource); |
74 } | 74 } |
75 | 75 |
76 void ResourceLoader::start(const ResourceRequest& request, WebTaskRunner* loadin
gTaskRunner, bool defersLoading) | 76 void ResourceLoader::start(const ResourceRequest& request, WebTaskRunner* loadin
gTaskRunner, bool defersLoading) |
77 { | 77 { |
78 ASSERT(!m_loader); | 78 DCHECK(!m_loader); |
79 if (m_resource->options().synchronousPolicy == RequestSynchronously && defer
sLoading) { | 79 if (m_resource->options().synchronousPolicy == RequestSynchronously && defer
sLoading) { |
80 cancel(); | 80 cancel(); |
81 return; | 81 return; |
82 } | 82 } |
83 | 83 |
84 m_loader = wrapUnique(Platform::current()->createURLLoader()); | 84 m_loader = wrapUnique(Platform::current()->createURLLoader()); |
85 m_loader->setDefersLoading(defersLoading); | 85 m_loader->setDefersLoading(defersLoading); |
86 ASSERT(m_loader); | 86 DCHECK(m_loader); |
87 m_loader->setLoadingTaskRunner(loadingTaskRunner); | 87 m_loader->setLoadingTaskRunner(loadingTaskRunner); |
88 | 88 |
89 if (m_resource->options().synchronousPolicy == RequestSynchronously) | 89 if (m_resource->options().synchronousPolicy == RequestSynchronously) |
90 requestSynchronously(request); | 90 requestSynchronously(request); |
91 else | 91 else |
92 m_loader->loadAsynchronously(WrappedResourceRequest(request), this); | 92 m_loader->loadAsynchronously(WrappedResourceRequest(request), this); |
93 } | 93 } |
94 | 94 |
95 void ResourceLoader::restartForServiceWorkerFallback(const ResourceRequest& requ
est) | 95 void ResourceLoader::restartForServiceWorkerFallback(const ResourceRequest& requ
est) |
96 { | 96 { |
97 m_loader.reset(); | 97 m_loader.reset(); |
98 m_loader = wrapUnique(Platform::current()->createURLLoader()); | 98 m_loader = wrapUnique(Platform::current()->createURLLoader()); |
99 DCHECK(m_loader); | 99 DCHECK(m_loader); |
100 m_loader->loadAsynchronously(WrappedResourceRequest(request), this); | 100 m_loader->loadAsynchronously(WrappedResourceRequest(request), this); |
101 } | 101 } |
102 | 102 |
103 void ResourceLoader::setDefersLoading(bool defers) | 103 void ResourceLoader::setDefersLoading(bool defers) |
104 { | 104 { |
105 ASSERT(m_loader); | 105 DCHECK(m_loader); |
106 m_loader->setDefersLoading(defers); | 106 m_loader->setDefersLoading(defers); |
107 } | 107 } |
108 | 108 |
109 void ResourceLoader::didDownloadData(WebURLLoader*, int length, int encodedDataL
ength) | 109 void ResourceLoader::didDownloadData(WebURLLoader*, int length, int encodedDataL
ength) |
110 { | 110 { |
111 m_fetcher->didDownloadData(m_resource.get(), length, encodedDataLength); | 111 m_fetcher->didDownloadData(m_resource.get(), length, encodedDataLength); |
112 m_resource->didDownloadData(length); | 112 m_resource->didDownloadData(length); |
113 } | 113 } |
114 | 114 |
115 void ResourceLoader::didChangePriority(ResourceLoadPriority loadPriority, int in
traPriorityValue) | 115 void ResourceLoader::didChangePriority(ResourceLoadPriority loadPriority, int in
traPriorityValue) |
116 { | 116 { |
117 if (m_loader) | 117 if (m_loader) |
118 m_loader->didChangePriority(static_cast<WebURLRequest::Priority>(loadPri
ority), intraPriorityValue); | 118 m_loader->didChangePriority(static_cast<WebURLRequest::Priority>(loadPri
ority), intraPriorityValue); |
119 } | 119 } |
120 | 120 |
121 void ResourceLoader::cancel() | 121 void ResourceLoader::cancel() |
122 { | 122 { |
123 didFail(nullptr, ResourceError::cancelledError(m_resource->lastResourceReque
st().url())); | 123 didFail(nullptr, ResourceError::cancelledError(m_resource->lastResourceReque
st().url())); |
124 } | 124 } |
125 | 125 |
126 void ResourceLoader::willFollowRedirect(WebURLLoader*, WebURLRequest& passedNewR
equest, const WebURLResponse& passedRedirectResponse, int64_t encodedDataLength) | 126 void ResourceLoader::willFollowRedirect(WebURLLoader*, WebURLRequest& passedNewR
equest, const WebURLResponse& passedRedirectResponse, int64_t encodedDataLength) |
127 { | 127 { |
128 ASSERT(!passedNewRequest.isNull()); | 128 DCHECK(!passedNewRequest.isNull()); |
129 ASSERT(!passedRedirectResponse.isNull()); | 129 DCHECK(!passedRedirectResponse.isNull()); |
130 | 130 |
131 ResourceRequest& newRequest(passedNewRequest.toMutableResourceRequest()); | 131 ResourceRequest& newRequest(passedNewRequest.toMutableResourceRequest()); |
132 const ResourceResponse& redirectResponse(passedRedirectResponse.toResourceRe
sponse()); | 132 const ResourceResponse& redirectResponse(passedRedirectResponse.toResourceRe
sponse()); |
133 newRequest.setRedirectStatus(ResourceRequest::RedirectStatus::FollowedRedire
ct); | 133 newRequest.setRedirectStatus(ResourceRequest::RedirectStatus::FollowedRedire
ct); |
134 | 134 |
135 if (m_fetcher->willFollowRedirect(m_resource.get(), newRequest, redirectResp
onse, encodedDataLength)) { | 135 if (m_fetcher->willFollowRedirect(m_resource.get(), newRequest, redirectResp
onse, encodedDataLength)) { |
136 m_resource->willFollowRedirect(newRequest, redirectResponse); | 136 m_resource->willFollowRedirect(newRequest, redirectResponse); |
137 } else { | 137 } else { |
138 m_resource->willNotFollowRedirect(); | 138 m_resource->willNotFollowRedirect(); |
139 if (m_loader) | 139 if (m_loader) |
(...skipping 17 matching lines...) Expand all Loading... |
157 m_fetcher->didReceiveResponse(m_resource.get(), response.toResourceResponse(
), handle); | 157 m_fetcher->didReceiveResponse(m_resource.get(), response.toResourceResponse(
), handle); |
158 } | 158 } |
159 | 159 |
160 void ResourceLoader::didReceiveResponse(WebURLLoader* loader, const WebURLRespon
se& response) | 160 void ResourceLoader::didReceiveResponse(WebURLLoader* loader, const WebURLRespon
se& response) |
161 { | 161 { |
162 didReceiveResponse(loader, response, nullptr); | 162 didReceiveResponse(loader, response, nullptr); |
163 } | 163 } |
164 | 164 |
165 void ResourceLoader::didReceiveData(WebURLLoader*, const char* data, int length,
int encodedDataLength, int encodedBodyLength) | 165 void ResourceLoader::didReceiveData(WebURLLoader*, const char* data, int length,
int encodedDataLength, int encodedBodyLength) |
166 { | 166 { |
167 RELEASE_ASSERT(length >= 0); | 167 CHECK_GE(length, 0); |
168 m_fetcher->didReceiveData(m_resource.get(), data, length, encodedDataLength)
; | 168 m_fetcher->didReceiveData(m_resource.get(), data, length, encodedDataLength)
; |
169 m_resource->addToEncodedBodyLength(encodedBodyLength); | 169 m_resource->addToEncodedBodyLength(encodedBodyLength); |
170 m_resource->addToDecodedBodyLength(length); | 170 m_resource->addToDecodedBodyLength(length); |
171 m_resource->appendData(data, length); | 171 m_resource->appendData(data, length); |
172 } | 172 } |
173 | 173 |
174 void ResourceLoader::didFinishLoadingFirstPartInMultipart() | 174 void ResourceLoader::didFinishLoadingFirstPartInMultipart() |
175 { | 175 { |
176 m_fetcher->didFinishLoading(m_resource.get(), 0, WebURLLoaderClient::kUnknow
nEncodedDataLength, ResourceFetcher::DidFinishFirstPartInMultipart); | 176 m_fetcher->didFinishLoading(m_resource.get(), 0, WebURLLoaderClient::kUnknow
nEncodedDataLength, ResourceFetcher::DidFinishFirstPartInMultipart); |
177 } | 177 } |
178 | 178 |
179 void ResourceLoader::didFinishLoading(WebURLLoader*, double finishTime, int64_t
encodedDataLength) | 179 void ResourceLoader::didFinishLoading(WebURLLoader*, double finishTime, int64_t
encodedDataLength) |
180 { | 180 { |
181 m_loader.reset(); | 181 m_loader.reset(); |
182 m_fetcher->didFinishLoading(m_resource.get(), finishTime, encodedDataLength,
ResourceFetcher::DidFinishLoading); | 182 m_fetcher->didFinishLoading(m_resource.get(), finishTime, encodedDataLength,
ResourceFetcher::DidFinishLoading); |
183 } | 183 } |
184 | 184 |
185 void ResourceLoader::didFail(WebURLLoader*, const WebURLError& error) | 185 void ResourceLoader::didFail(WebURLLoader*, const WebURLError& error) |
186 { | 186 { |
187 m_loader.reset(); | 187 m_loader.reset(); |
188 m_fetcher->didFailLoading(m_resource.get(), error); | 188 m_fetcher->didFailLoading(m_resource.get(), error); |
189 } | 189 } |
190 | 190 |
191 void ResourceLoader::requestSynchronously(const ResourceRequest& request) | 191 void ResourceLoader::requestSynchronously(const ResourceRequest& request) |
192 { | 192 { |
193 // downloadToFile is not supported for synchronous requests. | 193 // downloadToFile is not supported for synchronous requests. |
194 ASSERT(!request.downloadToFile()); | 194 DCHECK(!request.downloadToFile()); |
195 ASSERT(m_loader); | 195 DCHECK(m_loader); |
196 DCHECK(request.priority() == ResourceLoadPriorityHighest); | 196 DCHECK_EQ(request.priority(), ResourceLoadPriorityHighest); |
197 | 197 |
198 WrappedResourceRequest requestIn(request); | 198 WrappedResourceRequest requestIn(request); |
199 WebURLResponse responseOut; | 199 WebURLResponse responseOut; |
200 WebURLError errorOut; | 200 WebURLError errorOut; |
201 WebData dataOut; | 201 WebData dataOut; |
202 int64_t encodedDataLength = WebURLLoaderClient::kUnknownEncodedDataLength; | 202 int64_t encodedDataLength = WebURLLoaderClient::kUnknownEncodedDataLength; |
203 m_loader->loadSynchronously(requestIn, responseOut, errorOut, dataOut, encod
edDataLength); | 203 m_loader->loadSynchronously(requestIn, responseOut, errorOut, dataOut, encod
edDataLength); |
204 | 204 |
205 // A message dispatched while synchronously fetching the resource | 205 // A message dispatched while synchronously fetching the resource |
206 // can bring about the cancellation of this load. | 206 // can bring about the cancellation of this load. |
(...skipping 13 matching lines...) Expand all Loading... |
220 // empty buffer is a noop in most cases, but is destructive in the case of | 220 // empty buffer is a noop in most cases, but is destructive in the case of |
221 // a 304, where it will overwrite the cached data we should be reusing. | 221 // a 304, where it will overwrite the cached data we should be reusing. |
222 if (dataOut.size()) { | 222 if (dataOut.size()) { |
223 m_fetcher->didReceiveData(m_resource.get(), dataOut.data(), dataOut.size
(), encodedDataLength); | 223 m_fetcher->didReceiveData(m_resource.get(), dataOut.data(), dataOut.size
(), encodedDataLength); |
224 m_resource->setResourceBuffer(dataOut); | 224 m_resource->setResourceBuffer(dataOut); |
225 } | 225 } |
226 didFinishLoading(0, monotonicallyIncreasingTime(), encodedDataLength); | 226 didFinishLoading(0, monotonicallyIncreasingTime(), encodedDataLength); |
227 } | 227 } |
228 | 228 |
229 } // namespace blink | 229 } // namespace blink |
OLD | NEW |