| 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 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 | 89 |
| 90 RawResource::RawResource(const ResourceRequest& resourceRequest, Type type, cons
t ResourceLoaderOptions& options) | 90 RawResource::RawResource(const ResourceRequest& resourceRequest, Type type, cons
t ResourceLoaderOptions& options) |
| 91 : Resource(resourceRequest, type, options) | 91 : Resource(resourceRequest, type, options) |
| 92 { | 92 { |
| 93 } | 93 } |
| 94 | 94 |
| 95 void RawResource::appendData(const char* data, size_t length) | 95 void RawResource::appendData(const char* data, size_t length) |
| 96 { | 96 { |
| 97 Resource::appendData(data, length); | 97 Resource::appendData(data, length); |
| 98 | 98 |
| 99 ResourceClientWalker<RawResourceClient> w(m_clients); | 99 ResourceClientWalker<RawResourceClient> w(clients()); |
| 100 while (RawResourceClient* c = w.next()) | 100 while (RawResourceClient* c = w.next()) |
| 101 c->dataReceived(this, data, length); | 101 c->dataReceived(this, data, length); |
| 102 } | 102 } |
| 103 | 103 |
| 104 void RawResource::didAddClient(ResourceClient* c) | 104 void RawResource::didAddClient(ResourceClient* c) |
| 105 { | 105 { |
| 106 if (!hasClient(c)) | 106 if (!hasClient(c)) |
| 107 return; | 107 return; |
| 108 ASSERT(RawResourceClient::isExpectedType(c)); | 108 ASSERT(RawResourceClient::isExpectedType(c)); |
| 109 RawResourceClient* client = static_cast<RawResourceClient*>(c); | 109 RawResourceClient* client = static_cast<RawResourceClient*>(c); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 124 if (!clientWeak || !hasClient(c)) | 124 if (!clientWeak || !hasClient(c)) |
| 125 return; | 125 return; |
| 126 Resource::didAddClient(client); | 126 Resource::didAddClient(client); |
| 127 } | 127 } |
| 128 | 128 |
| 129 void RawResource::willFollowRedirect(ResourceRequest& newRequest, const Resource
Response& redirectResponse) | 129 void RawResource::willFollowRedirect(ResourceRequest& newRequest, const Resource
Response& redirectResponse) |
| 130 { | 130 { |
| 131 Resource::willFollowRedirect(newRequest, redirectResponse); | 131 Resource::willFollowRedirect(newRequest, redirectResponse); |
| 132 | 132 |
| 133 ASSERT(!redirectResponse.isNull()); | 133 ASSERT(!redirectResponse.isNull()); |
| 134 ResourceClientWalker<RawResourceClient> w(m_clients); | 134 ResourceClientWalker<RawResourceClient> w(clients()); |
| 135 while (RawResourceClient* c = w.next()) | 135 while (RawResourceClient* c = w.next()) |
| 136 c->redirectReceived(this, newRequest, redirectResponse); | 136 c->redirectReceived(this, newRequest, redirectResponse); |
| 137 } | 137 } |
| 138 | 138 |
| 139 void RawResource::willNotFollowRedirect() | 139 void RawResource::willNotFollowRedirect() |
| 140 { | 140 { |
| 141 ResourceClientWalker<RawResourceClient> w(m_clients); | 141 ResourceClientWalker<RawResourceClient> w(clients()); |
| 142 while (RawResourceClient* c = w.next()) | 142 while (RawResourceClient* c = w.next()) |
| 143 c->redirectBlocked(); | 143 c->redirectBlocked(); |
| 144 } | 144 } |
| 145 | 145 |
| 146 void RawResource::responseReceived(const ResourceResponse& response, std::unique
_ptr<WebDataConsumerHandle> handle) | 146 void RawResource::responseReceived(const ResourceResponse& response, std::unique
_ptr<WebDataConsumerHandle> handle) |
| 147 { | 147 { |
| 148 bool isSuccessfulRevalidation = isCacheValidator() && response.httpStatusCod
e() == 304; | 148 bool isSuccessfulRevalidation = isCacheValidator() && response.httpStatusCod
e() == 304; |
| 149 Resource::responseReceived(response, nullptr); | 149 Resource::responseReceived(response, nullptr); |
| 150 | 150 |
| 151 ResourceClientWalker<RawResourceClient> w(m_clients); | 151 ResourceClientWalker<RawResourceClient> w(clients()); |
| 152 ASSERT(count() <= 1 || !handle); | 152 ASSERT(count() <= 1 || !handle); |
| 153 while (RawResourceClient* c = w.next()) { | 153 while (RawResourceClient* c = w.next()) { |
| 154 // |handle| is cleared when passed, but it's not a problem because | 154 // |handle| is cleared when passed, but it's not a problem because |
| 155 // |handle| is null when there are two or more clients, as asserted. | 155 // |handle| is null when there are two or more clients, as asserted. |
| 156 c->responseReceived(this, m_response, std::move(handle)); | 156 c->responseReceived(this, m_response, std::move(handle)); |
| 157 } | 157 } |
| 158 | 158 |
| 159 // If we successfully revalidated, we won't get appendData() calls. | 159 // If we successfully revalidated, we won't get appendData() calls. |
| 160 // Forward the data to clients now instead. | 160 // Forward the data to clients now instead. |
| 161 // Note: |m_data| can be null when no data is appended to the original | 161 // Note: |m_data| can be null when no data is appended to the original |
| 162 // resource. | 162 // resource. |
| 163 if (isSuccessfulRevalidation && m_data) { | 163 if (isSuccessfulRevalidation && m_data) { |
| 164 ResourceClientWalker<RawResourceClient> w(m_clients); | 164 ResourceClientWalker<RawResourceClient> w(clients()); |
| 165 while (RawResourceClient* c = w.next()) | 165 while (RawResourceClient* c = w.next()) |
| 166 c->dataReceived(this, m_data->data(), m_data->size()); | 166 c->dataReceived(this, m_data->data(), m_data->size()); |
| 167 } | 167 } |
| 168 } | 168 } |
| 169 | 169 |
| 170 void RawResource::setSerializedCachedMetadata(const char* data, size_t size) | 170 void RawResource::setSerializedCachedMetadata(const char* data, size_t size) |
| 171 { | 171 { |
| 172 Resource::setSerializedCachedMetadata(data, size); | 172 Resource::setSerializedCachedMetadata(data, size); |
| 173 ResourceClientWalker<RawResourceClient> w(m_clients); | 173 ResourceClientWalker<RawResourceClient> w(clients()); |
| 174 while (RawResourceClient* c = w.next()) | 174 while (RawResourceClient* c = w.next()) |
| 175 c->setSerializedCachedMetadata(this, data, size); | 175 c->setSerializedCachedMetadata(this, data, size); |
| 176 } | 176 } |
| 177 | 177 |
| 178 void RawResource::didSendData(unsigned long long bytesSent, unsigned long long t
otalBytesToBeSent) | 178 void RawResource::didSendData(unsigned long long bytesSent, unsigned long long t
otalBytesToBeSent) |
| 179 { | 179 { |
| 180 ResourceClientWalker<RawResourceClient> w(m_clients); | 180 ResourceClientWalker<RawResourceClient> w(clients()); |
| 181 while (RawResourceClient* c = w.next()) | 181 while (RawResourceClient* c = w.next()) |
| 182 c->dataSent(this, bytesSent, totalBytesToBeSent); | 182 c->dataSent(this, bytesSent, totalBytesToBeSent); |
| 183 } | 183 } |
| 184 | 184 |
| 185 void RawResource::didDownloadData(int dataLength) | 185 void RawResource::didDownloadData(int dataLength) |
| 186 { | 186 { |
| 187 ResourceClientWalker<RawResourceClient> w(m_clients); | 187 ResourceClientWalker<RawResourceClient> w(clients()); |
| 188 while (RawResourceClient* c = w.next()) | 188 while (RawResourceClient* c = w.next()) |
| 189 c->dataDownloaded(this, dataLength); | 189 c->dataDownloaded(this, dataLength); |
| 190 } | 190 } |
| 191 | 191 |
| 192 void RawResource::reportResourceTimingToClients(const ResourceTimingInfo& info) | 192 void RawResource::reportResourceTimingToClients(const ResourceTimingInfo& info) |
| 193 { | 193 { |
| 194 ResourceClientWalker<RawResourceClient> w(m_clients); | 194 ResourceClientWalker<RawResourceClient> w(clients()); |
| 195 while (RawResourceClient* c = w.next()) | 195 while (RawResourceClient* c = w.next()) |
| 196 c->didReceiveResourceTiming(this, info); | 196 c->didReceiveResourceTiming(this, info); |
| 197 } | 197 } |
| 198 | 198 |
| 199 void RawResource::setDefersLoading(bool defers) | 199 void RawResource::setDefersLoading(bool defers) |
| 200 { | 200 { |
| 201 if (m_loader) | 201 if (m_loader) |
| 202 m_loader->setDefersLoading(defers); | 202 m_loader->setDefersLoading(defers); |
| 203 } | 203 } |
| 204 | 204 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 222 | 222 |
| 223 static bool isCacheableHTTPMethod(const AtomicString& method) | 223 static bool isCacheableHTTPMethod(const AtomicString& method) |
| 224 { | 224 { |
| 225 // Per http://www.w3.org/Protocols/rfc2616/rfc2616-sec13.html#sec13.10, | 225 // Per http://www.w3.org/Protocols/rfc2616/rfc2616-sec13.html#sec13.10, |
| 226 // these methods always invalidate the cache entry. | 226 // these methods always invalidate the cache entry. |
| 227 return method != "POST" && method != "PUT" && method != "DELETE"; | 227 return method != "POST" && method != "PUT" && method != "DELETE"; |
| 228 } | 228 } |
| 229 | 229 |
| 230 bool RawResource::canReuse(const ResourceRequest& newRequest) const | 230 bool RawResource::canReuse(const ResourceRequest& newRequest) const |
| 231 { | 231 { |
| 232 if (m_options.dataBufferingPolicy == DoNotBufferData) | 232 if (dataBufferingPolicy() == DoNotBufferData) |
| 233 return false; | 233 return false; |
| 234 | 234 |
| 235 if (!isCacheableHTTPMethod(m_resourceRequest.httpMethod())) | 235 if (!isCacheableHTTPMethod(m_resourceRequest.httpMethod())) |
| 236 return false; | 236 return false; |
| 237 if (m_resourceRequest.httpMethod() != newRequest.httpMethod()) | 237 if (m_resourceRequest.httpMethod() != newRequest.httpMethod()) |
| 238 return false; | 238 return false; |
| 239 | 239 |
| 240 if (m_resourceRequest.httpBody() != newRequest.httpBody()) | 240 if (m_resourceRequest.httpBody() != newRequest.httpBody()) |
| 241 return false; | 241 return false; |
| 242 | 242 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 259 for (const auto& header : oldHeaders) { | 259 for (const auto& header : oldHeaders) { |
| 260 AtomicString headerName = header.key; | 260 AtomicString headerName = header.key; |
| 261 if (!shouldIgnoreHeaderForCacheReuse(headerName) && header.value != newH
eaders.get(headerName)) | 261 if (!shouldIgnoreHeaderForCacheReuse(headerName) && header.value != newH
eaders.get(headerName)) |
| 262 return false; | 262 return false; |
| 263 } | 263 } |
| 264 | 264 |
| 265 return true; | 265 return true; |
| 266 } | 266 } |
| 267 | 267 |
| 268 } // namespace blink | 268 } // namespace blink |
| OLD | NEW |