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