OLD | NEW |
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 |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 void RawResource::responseReceived( | 176 void RawResource::responseReceived( |
177 const ResourceResponse& response, | 177 const ResourceResponse& response, |
178 std::unique_ptr<WebDataConsumerHandle> handle) { | 178 std::unique_ptr<WebDataConsumerHandle> handle) { |
179 bool isSuccessfulRevalidation = | 179 bool isSuccessfulRevalidation = |
180 isCacheValidator() && response.httpStatusCode() == 304; | 180 isCacheValidator() && response.httpStatusCode() == 304; |
181 Resource::responseReceived(response, nullptr); | 181 Resource::responseReceived(response, nullptr); |
182 | 182 |
183 ResourceClientWalker<RawResourceClient> w(clients()); | 183 ResourceClientWalker<RawResourceClient> w(clients()); |
184 DCHECK(clients().size() <= 1 || !handle); | 184 DCHECK(clients().size() <= 1 || !handle); |
185 while (RawResourceClient* c = w.next()) { | 185 while (RawResourceClient* c = w.next()) { |
186 // |handle| is cleared when passed, but it's not a problem because | 186 // |handle| is cleared when passed, but it's not a problem because |handle| |
187 // |handle| is null when there are two or more clients, as asserted. | 187 // is null when there are two or more clients, as asserted. |
188 c->responseReceived(this, this->response(), std::move(handle)); | 188 c->responseReceived(this, this->response(), std::move(handle)); |
189 } | 189 } |
190 | 190 |
191 // If we successfully revalidated, we won't get appendData() calls. | 191 // If we successfully revalidated, we won't get appendData() calls. Forward |
192 // Forward the data to clients now instead. | 192 // the data to clients now instead. Note: |m_data| can be null when no data is |
193 // Note: |m_data| can be null when no data is appended to the original | 193 // appended to the original resource. |
194 // resource. | |
195 if (isSuccessfulRevalidation && data()) { | 194 if (isSuccessfulRevalidation && data()) { |
196 ResourceClientWalker<RawResourceClient> w(clients()); | 195 ResourceClientWalker<RawResourceClient> w(clients()); |
197 while (RawResourceClient* c = w.next()) | 196 while (RawResourceClient* c = w.next()) |
198 c->dataReceived(this, data()->data(), data()->size()); | 197 c->dataReceived(this, data()->data(), data()->size()); |
199 } | 198 } |
200 } | 199 } |
201 | 200 |
202 void RawResource::setSerializedCachedMetadata(const char* data, size_t size) { | 201 void RawResource::setSerializedCachedMetadata(const char* data, size_t size) { |
203 Resource::setSerializedCachedMetadata(data, size); | 202 Resource::setSerializedCachedMetadata(data, size); |
204 ResourceClientWalker<RawResourceClient> w(clients()); | 203 ResourceClientWalker<RawResourceClient> w(clients()); |
(...skipping 20 matching lines...) Expand all Loading... |
225 while (RawResourceClient* c = w.next()) | 224 while (RawResourceClient* c = w.next()) |
226 c->didReceiveResourceTiming(this, info); | 225 c->didReceiveResourceTiming(this, info); |
227 } | 226 } |
228 | 227 |
229 void RawResource::setDefersLoading(bool defers) { | 228 void RawResource::setDefersLoading(bool defers) { |
230 if (loader()) | 229 if (loader()) |
231 loader()->setDefersLoading(defers); | 230 loader()->setDefersLoading(defers); |
232 } | 231 } |
233 | 232 |
234 static bool shouldIgnoreHeaderForCacheReuse(AtomicString headerName) { | 233 static bool shouldIgnoreHeaderForCacheReuse(AtomicString headerName) { |
235 // FIXME: This list of headers that don't affect cache policy almost certainly
isn't complete. | 234 // FIXME: This list of headers that don't affect cache policy almost certainly |
| 235 // isn't complete. |
236 DEFINE_STATIC_LOCAL( | 236 DEFINE_STATIC_LOCAL( |
237 HashSet<AtomicString>, headers, | 237 HashSet<AtomicString>, headers, |
238 ({ | 238 ({ |
239 "Cache-Control", "If-Modified-Since", "If-None-Match", "Origin", | 239 "Cache-Control", "If-Modified-Since", "If-None-Match", "Origin", |
240 "Pragma", "Purpose", "Referer", "User-Agent", | 240 "Pragma", "Purpose", "Referer", "User-Agent", |
241 HTTPNames::X_DevTools_Emulate_Network_Conditions_Client_Id, | 241 HTTPNames::X_DevTools_Emulate_Network_Conditions_Client_Id, |
242 })); | 242 })); |
243 return headers.contains(headerName); | 243 return headers.contains(headerName); |
244 } | 244 } |
245 | 245 |
(...skipping 12 matching lines...) Expand all Loading... |
258 if (resourceRequest().httpMethod() != newRequest.httpMethod()) | 258 if (resourceRequest().httpMethod() != newRequest.httpMethod()) |
259 return false; | 259 return false; |
260 | 260 |
261 if (resourceRequest().httpBody() != newRequest.httpBody()) | 261 if (resourceRequest().httpBody() != newRequest.httpBody()) |
262 return false; | 262 return false; |
263 | 263 |
264 if (resourceRequest().allowStoredCredentials() != | 264 if (resourceRequest().allowStoredCredentials() != |
265 newRequest.allowStoredCredentials()) | 265 newRequest.allowStoredCredentials()) |
266 return false; | 266 return false; |
267 | 267 |
268 // Ensure most headers match the existing headers before continuing. | 268 // Ensure most headers match the existing headers before continuing. Note that |
269 // Note that the list of ignored headers includes some headers explicitly rela
ted to caching. | 269 // the list of ignored headers includes some headers explicitly related to |
270 // A more detailed check of caching policy will be performed later, this is si
mply a list of | 270 // caching. A more detailed check of caching policy will be performed later, |
271 // headers that we might permit to be different and still reuse the existing R
esource. | 271 // this is simply a list of headers that we might permit to be different and |
| 272 // still reuse the existing Resource. |
272 const HTTPHeaderMap& newHeaders = newRequest.httpHeaderFields(); | 273 const HTTPHeaderMap& newHeaders = newRequest.httpHeaderFields(); |
273 const HTTPHeaderMap& oldHeaders = resourceRequest().httpHeaderFields(); | 274 const HTTPHeaderMap& oldHeaders = resourceRequest().httpHeaderFields(); |
274 | 275 |
275 for (const auto& header : newHeaders) { | 276 for (const auto& header : newHeaders) { |
276 AtomicString headerName = header.key; | 277 AtomicString headerName = header.key; |
277 if (!shouldIgnoreHeaderForCacheReuse(headerName) && | 278 if (!shouldIgnoreHeaderForCacheReuse(headerName) && |
278 header.value != oldHeaders.get(headerName)) | 279 header.value != oldHeaders.get(headerName)) |
279 return false; | 280 return false; |
280 } | 281 } |
281 | 282 |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
355 SECURITY_CHECK(m_state != NotAddedAsClient); | 356 SECURITY_CHECK(m_state != NotAddedAsClient); |
356 SECURITY_CHECK(m_state != NotifyFinished); | 357 SECURITY_CHECK(m_state != NotifyFinished); |
357 SECURITY_CHECK(resource->errorOccurred() || | 358 SECURITY_CHECK(resource->errorOccurred() || |
358 (m_state == ResponseReceived || | 359 (m_state == ResponseReceived || |
359 m_state == SetSerializedCachedMetadata || | 360 m_state == SetSerializedCachedMetadata || |
360 m_state == DataReceived || m_state == DataDownloaded)); | 361 m_state == DataReceived || m_state == DataDownloaded)); |
361 m_state = NotifyFinished; | 362 m_state = NotifyFinished; |
362 } | 363 } |
363 | 364 |
364 } // namespace blink | 365 } // namespace blink |
OLD | NEW |