| 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 26 matching lines...) Expand all Loading... |
| 37 #include "platform/exported/WrappedResourceRequest.h" | 37 #include "platform/exported/WrappedResourceRequest.h" |
| 38 #include "platform/exported/WrappedResourceResponse.h" | 38 #include "platform/exported/WrappedResourceResponse.h" |
| 39 #include "platform/network/ResourceError.h" | 39 #include "platform/network/ResourceError.h" |
| 40 #include "public/platform/Platform.h" | 40 #include "public/platform/Platform.h" |
| 41 #include "public/platform/WebData.h" | 41 #include "public/platform/WebData.h" |
| 42 #include "public/platform/WebURLError.h" | 42 #include "public/platform/WebURLError.h" |
| 43 #include "public/platform/WebURLRequest.h" | 43 #include "public/platform/WebURLRequest.h" |
| 44 #include "public/platform/WebURLResponse.h" | 44 #include "public/platform/WebURLResponse.h" |
| 45 #include "wtf/Assertions.h" | 45 #include "wtf/Assertions.h" |
| 46 #include "wtf/CurrentTime.h" | 46 #include "wtf/CurrentTime.h" |
| 47 #include "wtf/PtrUtil.h" | |
| 48 #include <memory> | |
| 49 | 47 |
| 50 namespace blink { | 48 namespace blink { |
| 51 | 49 |
| 52 ResourceLoader* ResourceLoader::create(ResourceFetcher* fetcher, Resource* resou
rce) | 50 ResourceLoader* ResourceLoader::create(ResourceFetcher* fetcher, Resource* resou
rce) |
| 53 { | 51 { |
| 54 return new ResourceLoader(fetcher, resource); | 52 return new ResourceLoader(fetcher, resource); |
| 55 } | 53 } |
| 56 | 54 |
| 57 ResourceLoader::ResourceLoader(ResourceFetcher* fetcher, Resource* resource) | 55 ResourceLoader::ResourceLoader(ResourceFetcher* fetcher, Resource* resource) |
| 58 : m_fetcher(fetcher) | 56 : m_fetcher(fetcher) |
| (...skipping 16 matching lines...) Expand all Loading... |
| 75 } | 73 } |
| 76 | 74 |
| 77 void ResourceLoader::start(const ResourceRequest& request, WebTaskRunner* loadin
gTaskRunner, bool defersLoading) | 75 void ResourceLoader::start(const ResourceRequest& request, WebTaskRunner* loadin
gTaskRunner, bool defersLoading) |
| 78 { | 76 { |
| 79 ASSERT(!m_loader); | 77 ASSERT(!m_loader); |
| 80 if (m_resource->options().synchronousPolicy == RequestSynchronously && defer
sLoading) { | 78 if (m_resource->options().synchronousPolicy == RequestSynchronously && defer
sLoading) { |
| 81 cancel(); | 79 cancel(); |
| 82 return; | 80 return; |
| 83 } | 81 } |
| 84 | 82 |
| 85 m_loader = wrapUnique(Platform::current()->createURLLoader()); | 83 m_loader = adoptPtr(Platform::current()->createURLLoader()); |
| 86 m_loader->setDefersLoading(defersLoading); | 84 m_loader->setDefersLoading(defersLoading); |
| 87 ASSERT(m_loader); | 85 ASSERT(m_loader); |
| 88 m_loader->setLoadingTaskRunner(loadingTaskRunner); | 86 m_loader->setLoadingTaskRunner(loadingTaskRunner); |
| 89 | 87 |
| 90 if (m_resource->options().synchronousPolicy == RequestSynchronously) | 88 if (m_resource->options().synchronousPolicy == RequestSynchronously) |
| 91 requestSynchronously(request); | 89 requestSynchronously(request); |
| 92 else | 90 else |
| 93 m_loader->loadAsynchronously(WrappedResourceRequest(request), this); | 91 m_loader->loadAsynchronously(WrappedResourceRequest(request), this); |
| 94 } | 92 } |
| 95 | 93 |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 bool ResourceLoader::responseNeedsAccessControlCheck() const | 145 bool ResourceLoader::responseNeedsAccessControlCheck() const |
| 148 { | 146 { |
| 149 // If the fetch was (potentially) CORS enabled, an access control check of t
he response is required. | 147 // If the fetch was (potentially) CORS enabled, an access control check of t
he response is required. |
| 150 return m_resource->options().corsEnabled == IsCORSEnabled; | 148 return m_resource->options().corsEnabled == IsCORSEnabled; |
| 151 } | 149 } |
| 152 | 150 |
| 153 void ResourceLoader::didReceiveResponse(WebURLLoader*, const WebURLResponse& res
ponse, WebDataConsumerHandle* rawHandle) | 151 void ResourceLoader::didReceiveResponse(WebURLLoader*, const WebURLResponse& res
ponse, WebDataConsumerHandle* rawHandle) |
| 154 { | 152 { |
| 155 ASSERT(!response.isNull()); | 153 ASSERT(!response.isNull()); |
| 156 // |rawHandle|'s ownership is transferred to the callee. | 154 // |rawHandle|'s ownership is transferred to the callee. |
| 157 std::unique_ptr<WebDataConsumerHandle> handle = wrapUnique(rawHandle); | 155 OwnPtr<WebDataConsumerHandle> handle = adoptPtr(rawHandle); |
| 158 const ResourceResponse& resourceResponse = response.toResourceResponse(); | 156 const ResourceResponse& resourceResponse = response.toResourceResponse(); |
| 159 | 157 |
| 160 if (responseNeedsAccessControlCheck()) { | 158 if (responseNeedsAccessControlCheck()) { |
| 161 if (response.wasFetchedViaServiceWorker()) { | 159 if (response.wasFetchedViaServiceWorker()) { |
| 162 if (response.wasFallbackRequiredByServiceWorker()) { | 160 if (response.wasFallbackRequiredByServiceWorker()) { |
| 163 m_loader.reset(); | 161 m_loader.reset(); |
| 164 m_loader = wrapUnique(Platform::current()->createURLLoader()); | 162 m_loader = adoptPtr(Platform::current()->createURLLoader()); |
| 165 ASSERT(m_loader); | 163 ASSERT(m_loader); |
| 166 ResourceRequest request = m_resource->lastResourceRequest(); | 164 ResourceRequest request = m_resource->lastResourceRequest(); |
| 167 ASSERT(!request.skipServiceWorker()); | 165 ASSERT(!request.skipServiceWorker()); |
| 168 request.setSkipServiceWorker(true); | 166 request.setSkipServiceWorker(true); |
| 169 m_loader->loadAsynchronously(WrappedResourceRequest(request), th
is); | 167 m_loader->loadAsynchronously(WrappedResourceRequest(request), th
is); |
| 170 return; | 168 return; |
| 171 } | 169 } |
| 172 } else { | 170 } else { |
| 173 if (!m_resource->isCacheValidator() || resourceResponse.httpStatusCo
de() != 304) | 171 if (!m_resource->isCacheValidator() || resourceResponse.httpStatusCo
de() != 304) |
| 174 m_resource->setResponse(resourceResponse); | 172 m_resource->setResponse(resourceResponse); |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 255 // empty buffer is a noop in most cases, but is destructive in the case of | 253 // empty buffer is a noop in most cases, but is destructive in the case of |
| 256 // a 304, where it will overwrite the cached data we should be reusing. | 254 // a 304, where it will overwrite the cached data we should be reusing. |
| 257 if (dataOut.size()) { | 255 if (dataOut.size()) { |
| 258 m_fetcher->didReceiveData(m_resource.get(), dataOut.data(), dataOut.size
(), encodedDataLength); | 256 m_fetcher->didReceiveData(m_resource.get(), dataOut.data(), dataOut.size
(), encodedDataLength); |
| 259 m_resource->setResourceBuffer(dataOut); | 257 m_resource->setResourceBuffer(dataOut); |
| 260 } | 258 } |
| 261 didFinishLoading(0, monotonicallyIncreasingTime(), encodedDataLength); | 259 didFinishLoading(0, monotonicallyIncreasingTime(), encodedDataLength); |
| 262 } | 260 } |
| 263 | 261 |
| 264 } // namespace blink | 262 } // namespace blink |
| OLD | NEW |