| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2010, 2011, 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2010, 2011, 2012 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 are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ | 29 */ |
| 30 | 30 |
| 31 #include "web/AssociatedURLLoader.h" | 31 #include "web/WebAssociatedURLLoaderImpl.h" |
| 32 | 32 |
| 33 #include "core/dom/ContextLifecycleObserver.h" | 33 #include "core/dom/ContextLifecycleObserver.h" |
| 34 #include "core/fetch/CrossOriginAccessControl.h" | 34 #include "core/fetch/CrossOriginAccessControl.h" |
| 35 #include "core/fetch/FetchUtils.h" | 35 #include "core/fetch/FetchUtils.h" |
| 36 #include "core/loader/DocumentThreadableLoader.h" | 36 #include "core/loader/DocumentThreadableLoader.h" |
| 37 #include "core/loader/DocumentThreadableLoaderClient.h" | 37 #include "core/loader/DocumentThreadableLoaderClient.h" |
| 38 #include "platform/Timer.h" | 38 #include "platform/Timer.h" |
| 39 #include "platform/exported/WrappedResourceRequest.h" | 39 #include "platform/exported/WrappedResourceRequest.h" |
| 40 #include "platform/exported/WrappedResourceResponse.h" | 40 #include "platform/exported/WrappedResourceResponse.h" |
| 41 #include "platform/network/HTTPParsers.h" | 41 #include "platform/network/HTTPParsers.h" |
| 42 #include "platform/network/ResourceError.h" | 42 #include "platform/network/ResourceError.h" |
| 43 #include "public/platform/WebHTTPHeaderVisitor.h" | 43 #include "public/platform/WebHTTPHeaderVisitor.h" |
| 44 #include "public/platform/WebString.h" | 44 #include "public/platform/WebString.h" |
| 45 #include "public/platform/WebURLError.h" | 45 #include "public/platform/WebURLError.h" |
| 46 #include "public/platform/WebURLLoaderClient.h" | |
| 47 #include "public/platform/WebURLRequest.h" | 46 #include "public/platform/WebURLRequest.h" |
| 47 #include "public/web/WebAssociatedURLLoaderClient.h" |
| 48 #include "public/web/WebDataSource.h" | 48 #include "public/web/WebDataSource.h" |
| 49 #include "web/WebLocalFrameImpl.h" | 49 #include "web/WebLocalFrameImpl.h" |
| 50 #include "wtf/HashSet.h" | 50 #include "wtf/HashSet.h" |
| 51 #include "wtf/PtrUtil.h" | 51 #include "wtf/PtrUtil.h" |
| 52 #include "wtf/text/WTFString.h" | 52 #include "wtf/text/WTFString.h" |
| 53 #include <limits.h> | 53 #include <limits.h> |
| 54 #include <memory> | 54 #include <memory> |
| 55 | 55 |
| 56 namespace blink { | 56 namespace blink { |
| 57 | 57 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 75 const WebString& value) { | 75 const WebString& value) { |
| 76 m_isSafe = m_isSafe && isValidHTTPToken(name) && | 76 m_isSafe = m_isSafe && isValidHTTPToken(name) && |
| 77 !FetchUtils::isForbiddenHeaderName(name) && | 77 !FetchUtils::isForbiddenHeaderName(name) && |
| 78 isValidHTTPHeaderValue(value); | 78 isValidHTTPHeaderValue(value); |
| 79 } | 79 } |
| 80 | 80 |
| 81 } // namespace | 81 } // namespace |
| 82 | 82 |
| 83 // This class bridges the interface differences between WebCore and WebKit | 83 // This class bridges the interface differences between WebCore and WebKit |
| 84 // loader clients. | 84 // loader clients. |
| 85 // It forwards its ThreadableLoaderClient notifications to a WebURLLoaderClient. | 85 // It forwards its ThreadableLoaderClient notifications to a |
| 86 class AssociatedURLLoader::ClientAdapter final | 86 // WebAssociatedURLLoaderClient. |
| 87 class WebAssociatedURLLoaderImpl::ClientAdapter final |
| 87 : public DocumentThreadableLoaderClient { | 88 : public DocumentThreadableLoaderClient { |
| 88 WTF_MAKE_NONCOPYABLE(ClientAdapter); | 89 WTF_MAKE_NONCOPYABLE(ClientAdapter); |
| 89 | 90 |
| 90 public: | 91 public: |
| 91 static std::unique_ptr<ClientAdapter> create(AssociatedURLLoader*, | 92 static std::unique_ptr<ClientAdapter> create( |
| 92 WebURLLoaderClient*, | 93 WebAssociatedURLLoaderImpl*, |
| 93 const WebURLLoaderOptions&); | 94 WebAssociatedURLLoaderClient*, |
| 95 const WebAssociatedURLLoaderOptions&); |
| 94 | 96 |
| 95 // ThreadableLoaderClient | 97 // ThreadableLoaderClient |
| 96 void didSendData(unsigned long long /*bytesSent*/, | 98 void didSendData(unsigned long long /*bytesSent*/, |
| 97 unsigned long long /*totalBytesToBeSent*/) override; | 99 unsigned long long /*totalBytesToBeSent*/) override; |
| 98 void didReceiveResponse(unsigned long, | 100 void didReceiveResponse(unsigned long, |
| 99 const ResourceResponse&, | 101 const ResourceResponse&, |
| 100 std::unique_ptr<WebDataConsumerHandle>) override; | 102 std::unique_ptr<WebDataConsumerHandle>) override; |
| 101 void didDownloadData(int /*dataLength*/) override; | 103 void didDownloadData(int /*dataLength*/) override; |
| 102 void didReceiveData(const char*, unsigned /*dataLength*/) override; | 104 void didReceiveData(const char*, unsigned /*dataLength*/) override; |
| 103 void didReceiveCachedMetadata(const char*, int /*dataLength*/) override; | 105 void didReceiveCachedMetadata(const char*, int /*dataLength*/) override; |
| 104 void didFinishLoading(unsigned long /*identifier*/, | 106 void didFinishLoading(unsigned long /*identifier*/, |
| 105 double /*finishTime*/) override; | 107 double /*finishTime*/) override; |
| 106 void didFail(const ResourceError&) override; | 108 void didFail(const ResourceError&) override; |
| 107 void didFailRedirectCheck() override; | 109 void didFailRedirectCheck() override; |
| 108 | 110 |
| 109 // DocumentThreadableLoaderClient | 111 // DocumentThreadableLoaderClient |
| 110 bool willFollowRedirect( | 112 bool willFollowRedirect( |
| 111 const ResourceRequest& /*newRequest*/, | 113 const ResourceRequest& /*newRequest*/, |
| 112 const ResourceResponse& /*redirectResponse*/) override; | 114 const ResourceResponse& /*redirectResponse*/) override; |
| 113 | 115 |
| 114 // Sets an error to be reported back to the client, asychronously. | 116 // Sets an error to be reported back to the client, asychronously. |
| 115 void setDelayedError(const ResourceError&); | 117 void setDelayedError(const ResourceError&); |
| 116 | 118 |
| 117 // Enables forwarding of error notifications to the WebURLLoaderClient. These | 119 // Enables forwarding of error notifications to the |
| 120 // WebAssociatedURLLoaderClient. These |
| 118 // must be deferred until after the call to | 121 // must be deferred until after the call to |
| 119 // AssociatedURLLoader::loadAsynchronously() completes. | 122 // WebAssociatedURLLoader::loadAsynchronously() completes. |
| 120 void enableErrorNotifications(); | 123 void enableErrorNotifications(); |
| 121 | 124 |
| 122 // Stops loading and releases the DocumentThreadableLoader as early as | 125 // Stops loading and releases the DocumentThreadableLoader as early as |
| 123 // possible. | 126 // possible. |
| 124 WebURLLoaderClient* releaseClient() { | 127 WebAssociatedURLLoaderClient* releaseClient() { |
| 125 WebURLLoaderClient* client = m_client; | 128 WebAssociatedURLLoaderClient* client = m_client; |
| 126 m_client = nullptr; | 129 m_client = nullptr; |
| 127 return client; | 130 return client; |
| 128 } | 131 } |
| 129 | 132 |
| 130 private: | 133 private: |
| 131 ClientAdapter(AssociatedURLLoader*, | 134 ClientAdapter(WebAssociatedURLLoaderImpl*, |
| 132 WebURLLoaderClient*, | 135 WebAssociatedURLLoaderClient*, |
| 133 const WebURLLoaderOptions&); | 136 const WebAssociatedURLLoaderOptions&); |
| 134 | 137 |
| 135 void notifyError(TimerBase*); | 138 void notifyError(TimerBase*); |
| 136 | 139 |
| 137 AssociatedURLLoader* m_loader; | 140 WebAssociatedURLLoaderImpl* m_loader; |
| 138 WebURLLoaderClient* m_client; | 141 WebAssociatedURLLoaderClient* m_client; |
| 139 WebURLLoaderOptions m_options; | 142 WebAssociatedURLLoaderOptions m_options; |
| 140 WebURLError m_error; | 143 WebURLError m_error; |
| 141 | 144 |
| 142 Timer<ClientAdapter> m_errorTimer; | 145 Timer<ClientAdapter> m_errorTimer; |
| 143 bool m_enableErrorNotifications; | 146 bool m_enableErrorNotifications; |
| 144 bool m_didFail; | 147 bool m_didFail; |
| 145 }; | 148 }; |
| 146 | 149 |
| 147 std::unique_ptr<AssociatedURLLoader::ClientAdapter> | 150 std::unique_ptr<WebAssociatedURLLoaderImpl::ClientAdapter> |
| 148 AssociatedURLLoader::ClientAdapter::create(AssociatedURLLoader* loader, | 151 WebAssociatedURLLoaderImpl::ClientAdapter::create( |
| 149 WebURLLoaderClient* client, | 152 WebAssociatedURLLoaderImpl* loader, |
| 150 const WebURLLoaderOptions& options) { | 153 WebAssociatedURLLoaderClient* client, |
| 154 const WebAssociatedURLLoaderOptions& options) { |
| 151 return wrapUnique(new ClientAdapter(loader, client, options)); | 155 return wrapUnique(new ClientAdapter(loader, client, options)); |
| 152 } | 156 } |
| 153 | 157 |
| 154 AssociatedURLLoader::ClientAdapter::ClientAdapter( | 158 WebAssociatedURLLoaderImpl::ClientAdapter::ClientAdapter( |
| 155 AssociatedURLLoader* loader, | 159 WebAssociatedURLLoaderImpl* loader, |
| 156 WebURLLoaderClient* client, | 160 WebAssociatedURLLoaderClient* client, |
| 157 const WebURLLoaderOptions& options) | 161 const WebAssociatedURLLoaderOptions& options) |
| 158 : m_loader(loader), | 162 : m_loader(loader), |
| 159 m_client(client), | 163 m_client(client), |
| 160 m_options(options), | 164 m_options(options), |
| 161 m_errorTimer(this, &ClientAdapter::notifyError), | 165 m_errorTimer(this, &ClientAdapter::notifyError), |
| 162 m_enableErrorNotifications(false), | 166 m_enableErrorNotifications(false), |
| 163 m_didFail(false) { | 167 m_didFail(false) { |
| 164 DCHECK(m_loader); | 168 DCHECK(m_loader); |
| 165 DCHECK(m_client); | 169 DCHECK(m_client); |
| 166 } | 170 } |
| 167 | 171 |
| 168 bool AssociatedURLLoader::ClientAdapter::willFollowRedirect( | 172 bool WebAssociatedURLLoaderImpl::ClientAdapter::willFollowRedirect( |
| 169 const ResourceRequest& newRequest, | 173 const ResourceRequest& newRequest, |
| 170 const ResourceResponse& redirectResponse) { | 174 const ResourceResponse& redirectResponse) { |
| 171 if (!m_client) | 175 if (!m_client) |
| 172 return true; | 176 return true; |
| 173 | 177 |
| 174 WrappedResourceRequest wrappedNewRequest(newRequest); | 178 WrappedResourceRequest wrappedNewRequest(newRequest); |
| 175 WrappedResourceResponse wrappedRedirectResponse(redirectResponse); | 179 WrappedResourceResponse wrappedRedirectResponse(redirectResponse); |
| 176 return m_client->willFollowRedirect(m_loader, wrappedNewRequest, | 180 return m_client->willFollowRedirect(wrappedNewRequest, |
| 177 wrappedRedirectResponse); | 181 wrappedRedirectResponse); |
| 178 } | 182 } |
| 179 | 183 |
| 180 void AssociatedURLLoader::ClientAdapter::didSendData( | 184 void WebAssociatedURLLoaderImpl::ClientAdapter::didSendData( |
| 181 unsigned long long bytesSent, | 185 unsigned long long bytesSent, |
| 182 unsigned long long totalBytesToBeSent) { | 186 unsigned long long totalBytesToBeSent) { |
| 183 if (!m_client) | 187 if (!m_client) |
| 184 return; | 188 return; |
| 185 | 189 |
| 186 m_client->didSendData(m_loader, bytesSent, totalBytesToBeSent); | 190 m_client->didSendData(bytesSent, totalBytesToBeSent); |
| 187 } | 191 } |
| 188 | 192 |
| 189 void AssociatedURLLoader::ClientAdapter::didReceiveResponse( | 193 void WebAssociatedURLLoaderImpl::ClientAdapter::didReceiveResponse( |
| 190 unsigned long, | 194 unsigned long, |
| 191 const ResourceResponse& response, | 195 const ResourceResponse& response, |
| 192 std::unique_ptr<WebDataConsumerHandle> handle) { | 196 std::unique_ptr<WebDataConsumerHandle> handle) { |
| 197 ALLOW_UNUSED_LOCAL(handle); |
| 193 DCHECK(!handle); | 198 DCHECK(!handle); |
| 194 if (!m_client) | 199 if (!m_client) |
| 195 return; | 200 return; |
| 196 | 201 |
| 197 if (m_options.exposeAllResponseHeaders || | 202 if (m_options.exposeAllResponseHeaders || |
| 198 m_options.crossOriginRequestPolicy != | 203 m_options.crossOriginRequestPolicy != |
| 199 WebURLLoaderOptions::CrossOriginRequestPolicyUseAccessControl) { | 204 WebAssociatedURLLoaderOptions:: |
| 205 CrossOriginRequestPolicyUseAccessControl) { |
| 200 // Use the original ResourceResponse. | 206 // Use the original ResourceResponse. |
| 201 m_client->didReceiveResponse(m_loader, WrappedResourceResponse(response)); | 207 m_client->didReceiveResponse(WrappedResourceResponse(response)); |
| 202 return; | 208 return; |
| 203 } | 209 } |
| 204 | 210 |
| 205 HTTPHeaderSet exposedHeaders; | 211 HTTPHeaderSet exposedHeaders; |
| 206 extractCorsExposedHeaderNamesList(response, exposedHeaders); | 212 extractCorsExposedHeaderNamesList(response, exposedHeaders); |
| 207 HTTPHeaderSet blockedHeaders; | 213 HTTPHeaderSet blockedHeaders; |
| 208 for (const auto& header : response.httpHeaderFields()) { | 214 for (const auto& header : response.httpHeaderFields()) { |
| 209 if (FetchUtils::isForbiddenResponseHeaderName(header.key) || | 215 if (FetchUtils::isForbiddenResponseHeaderName(header.key) || |
| 210 (!isOnAccessControlResponseHeaderWhitelist(header.key) && | 216 (!isOnAccessControlResponseHeaderWhitelist(header.key) && |
| 211 !exposedHeaders.contains(header.key))) | 217 !exposedHeaders.contains(header.key))) |
| 212 blockedHeaders.add(header.key); | 218 blockedHeaders.add(header.key); |
| 213 } | 219 } |
| 214 | 220 |
| 215 if (blockedHeaders.isEmpty()) { | 221 if (blockedHeaders.isEmpty()) { |
| 216 // Use the original ResourceResponse. | 222 // Use the original ResourceResponse. |
| 217 m_client->didReceiveResponse(m_loader, WrappedResourceResponse(response)); | 223 m_client->didReceiveResponse(WrappedResourceResponse(response)); |
| 218 return; | 224 return; |
| 219 } | 225 } |
| 220 | 226 |
| 221 // If there are blocked headers, copy the response so we can remove them. | 227 // If there are blocked headers, copy the response so we can remove them. |
| 222 WebURLResponse validatedResponse = WrappedResourceResponse(response); | 228 WebURLResponse validatedResponse = WrappedResourceResponse(response); |
| 223 for (const auto& header : blockedHeaders) | 229 for (const auto& header : blockedHeaders) |
| 224 validatedResponse.clearHTTPHeaderField(header); | 230 validatedResponse.clearHTTPHeaderField(header); |
| 225 m_client->didReceiveResponse(m_loader, validatedResponse); | 231 m_client->didReceiveResponse(validatedResponse); |
| 226 } | 232 } |
| 227 | 233 |
| 228 void AssociatedURLLoader::ClientAdapter::didDownloadData(int dataLength) { | 234 void WebAssociatedURLLoaderImpl::ClientAdapter::didDownloadData( |
| 235 int dataLength) { |
| 229 if (!m_client) | 236 if (!m_client) |
| 230 return; | 237 return; |
| 231 | 238 |
| 232 m_client->didDownloadData(m_loader, dataLength, -1); | 239 m_client->didDownloadData(dataLength); |
| 233 } | 240 } |
| 234 | 241 |
| 235 void AssociatedURLLoader::ClientAdapter::didReceiveData(const char* data, | 242 void WebAssociatedURLLoaderImpl::ClientAdapter::didReceiveData( |
| 236 unsigned dataLength) { | 243 const char* data, |
| 244 unsigned dataLength) { |
| 237 if (!m_client) | 245 if (!m_client) |
| 238 return; | 246 return; |
| 239 | 247 |
| 240 CHECK_LE(dataLength, static_cast<unsigned>(std::numeric_limits<int>::max())); | 248 CHECK_LE(dataLength, static_cast<unsigned>(std::numeric_limits<int>::max())); |
| 241 | 249 |
| 242 m_client->didReceiveData(m_loader, data, dataLength, -1, dataLength); | 250 m_client->didReceiveData(data, dataLength); |
| 243 } | 251 } |
| 244 | 252 |
| 245 void AssociatedURLLoader::ClientAdapter::didReceiveCachedMetadata( | 253 void WebAssociatedURLLoaderImpl::ClientAdapter::didReceiveCachedMetadata( |
| 246 const char* data, | 254 const char* data, |
| 247 int dataLength) { | 255 int dataLength) { |
| 248 if (!m_client) | 256 if (!m_client) |
| 249 return; | 257 return; |
| 250 | 258 |
| 251 m_client->didReceiveCachedMetadata(m_loader, data, dataLength); | 259 m_client->didReceiveCachedMetadata(data, dataLength); |
| 252 } | 260 } |
| 253 | 261 |
| 254 void AssociatedURLLoader::ClientAdapter::didFinishLoading( | 262 void WebAssociatedURLLoaderImpl::ClientAdapter::didFinishLoading( |
| 255 unsigned long identifier, | 263 unsigned long identifier, |
| 256 double finishTime) { | 264 double finishTime) { |
| 257 if (!m_client) | 265 if (!m_client) |
| 258 return; | 266 return; |
| 259 | 267 |
| 260 m_loader->clientAdapterDone(); | 268 m_loader->clientAdapterDone(); |
| 261 | 269 |
| 262 releaseClient()->didFinishLoading( | 270 releaseClient()->didFinishLoading(finishTime); |
| 263 m_loader, finishTime, WebURLLoaderClient::kUnknownEncodedDataLength); | |
| 264 // |this| may be dead here. | 271 // |this| may be dead here. |
| 265 } | 272 } |
| 266 | 273 |
| 267 void AssociatedURLLoader::ClientAdapter::didFail(const ResourceError& error) { | 274 void WebAssociatedURLLoaderImpl::ClientAdapter::didFail( |
| 275 const ResourceError& error) { |
| 268 if (!m_client) | 276 if (!m_client) |
| 269 return; | 277 return; |
| 270 | 278 |
| 271 m_loader->clientAdapterDone(); | 279 m_loader->clientAdapterDone(); |
| 272 | 280 |
| 273 m_didFail = true; | 281 m_didFail = true; |
| 274 m_error = WebURLError(error); | 282 m_error = WebURLError(error); |
| 275 if (m_enableErrorNotifications) | 283 if (m_enableErrorNotifications) |
| 276 notifyError(&m_errorTimer); | 284 notifyError(&m_errorTimer); |
| 277 } | 285 } |
| 278 | 286 |
| 279 void AssociatedURLLoader::ClientAdapter::didFailRedirectCheck() { | 287 void WebAssociatedURLLoaderImpl::ClientAdapter::didFailRedirectCheck() { |
| 280 didFail(ResourceError()); | 288 didFail(ResourceError()); |
| 281 } | 289 } |
| 282 | 290 |
| 283 void AssociatedURLLoader::ClientAdapter::enableErrorNotifications() { | 291 void WebAssociatedURLLoaderImpl::ClientAdapter::enableErrorNotifications() { |
| 284 m_enableErrorNotifications = true; | 292 m_enableErrorNotifications = true; |
| 285 // If an error has already been received, start a timer to report it to the | 293 // If an error has already been received, start a timer to report it to the |
| 286 // client after AssociatedURLLoader::loadAsynchronously has returned to the | 294 // client after WebAssociatedURLLoader::loadAsynchronously has returned to the |
| 287 // caller. | 295 // caller. |
| 288 if (m_didFail) | 296 if (m_didFail) |
| 289 m_errorTimer.startOneShot(0, BLINK_FROM_HERE); | 297 m_errorTimer.startOneShot(0, BLINK_FROM_HERE); |
| 290 } | 298 } |
| 291 | 299 |
| 292 void AssociatedURLLoader::ClientAdapter::notifyError(TimerBase* timer) { | 300 void WebAssociatedURLLoaderImpl::ClientAdapter::notifyError(TimerBase* timer) { |
| 293 DCHECK_EQ(timer, &m_errorTimer); | 301 DCHECK_EQ(timer, &m_errorTimer); |
| 294 | 302 |
| 295 if (m_client) | 303 if (m_client) |
| 296 releaseClient()->didFail(m_loader, m_error); | 304 releaseClient()->didFail(m_error); |
| 297 // |this| may be dead here. | 305 // |this| may be dead here. |
| 298 } | 306 } |
| 299 | 307 |
| 300 class AssociatedURLLoader::Observer final : public GarbageCollected<Observer>, | 308 class WebAssociatedURLLoaderImpl::Observer final |
| 301 public ContextLifecycleObserver { | 309 : public GarbageCollected<Observer>, |
| 310 public ContextLifecycleObserver { |
| 302 USING_GARBAGE_COLLECTED_MIXIN(Observer); | 311 USING_GARBAGE_COLLECTED_MIXIN(Observer); |
| 303 | 312 |
| 304 public: | 313 public: |
| 305 Observer(AssociatedURLLoader* parent, Document* document) | 314 Observer(WebAssociatedURLLoaderImpl* parent, Document* document) |
| 306 : ContextLifecycleObserver(document), m_parent(parent) {} | 315 : ContextLifecycleObserver(document), m_parent(parent) {} |
| 307 | 316 |
| 308 void dispose() { | 317 void dispose() { |
| 309 m_parent = nullptr; | 318 m_parent = nullptr; |
| 310 clearContext(); | 319 clearContext(); |
| 311 } | 320 } |
| 312 | 321 |
| 313 void contextDestroyed() override { | 322 void contextDestroyed() override { |
| 314 if (m_parent) | 323 if (m_parent) |
| 315 m_parent->documentDestroyed(); | 324 m_parent->documentDestroyed(); |
| 316 } | 325 } |
| 317 | 326 |
| 318 DEFINE_INLINE_VIRTUAL_TRACE() { ContextLifecycleObserver::trace(visitor); } | 327 DEFINE_INLINE_VIRTUAL_TRACE() { ContextLifecycleObserver::trace(visitor); } |
| 319 | 328 |
| 320 AssociatedURLLoader* m_parent; | 329 WebAssociatedURLLoaderImpl* m_parent; |
| 321 }; | 330 }; |
| 322 | 331 |
| 323 AssociatedURLLoader::AssociatedURLLoader(WebLocalFrameImpl* frameImpl, | 332 WebAssociatedURLLoaderImpl::WebAssociatedURLLoaderImpl( |
| 324 const WebURLLoaderOptions& options) | 333 WebLocalFrameImpl* frameImpl, |
| 334 const WebAssociatedURLLoaderOptions& options) |
| 325 : m_client(nullptr), | 335 : m_client(nullptr), |
| 326 m_options(options), | 336 m_options(options), |
| 327 m_observer(new Observer(this, frameImpl->frame()->document())) {} | 337 m_observer(new Observer(this, frameImpl->frame()->document())) {} |
| 328 | 338 |
| 329 AssociatedURLLoader::~AssociatedURLLoader() { | 339 WebAssociatedURLLoaderImpl::~WebAssociatedURLLoaderImpl() { |
| 330 cancel(); | 340 cancel(); |
| 331 } | 341 } |
| 332 | 342 |
| 333 #define STATIC_ASSERT_ENUM(a, b) \ | 343 #define STATIC_ASSERT_ENUM(a, b) \ |
| 334 static_assert(static_cast<int>(a) == static_cast<int>(b), \ | 344 static_assert(static_cast<int>(a) == static_cast<int>(b), \ |
| 335 "mismatching enum: " #a) | 345 "mismatching enum: " #a) |
| 336 | 346 |
| 337 STATIC_ASSERT_ENUM(WebURLLoaderOptions::CrossOriginRequestPolicyDeny, | 347 STATIC_ASSERT_ENUM(WebAssociatedURLLoaderOptions::CrossOriginRequestPolicyDeny, |
| 338 DenyCrossOriginRequests); | 348 DenyCrossOriginRequests); |
| 339 STATIC_ASSERT_ENUM( | 349 STATIC_ASSERT_ENUM( |
| 340 WebURLLoaderOptions::CrossOriginRequestPolicyUseAccessControl, | 350 WebAssociatedURLLoaderOptions::CrossOriginRequestPolicyUseAccessControl, |
| 341 UseAccessControl); | 351 UseAccessControl); |
| 342 STATIC_ASSERT_ENUM(WebURLLoaderOptions::CrossOriginRequestPolicyAllow, | 352 STATIC_ASSERT_ENUM(WebAssociatedURLLoaderOptions::CrossOriginRequestPolicyAllow, |
| 343 AllowCrossOriginRequests); | 353 AllowCrossOriginRequests); |
| 344 | 354 |
| 345 STATIC_ASSERT_ENUM(WebURLLoaderOptions::ConsiderPreflight, ConsiderPreflight); | 355 STATIC_ASSERT_ENUM(WebAssociatedURLLoaderOptions::ConsiderPreflight, |
| 346 STATIC_ASSERT_ENUM(WebURLLoaderOptions::ForcePreflight, ForcePreflight); | 356 ConsiderPreflight); |
| 347 STATIC_ASSERT_ENUM(WebURLLoaderOptions::PreventPreflight, PreventPreflight); | 357 STATIC_ASSERT_ENUM(WebAssociatedURLLoaderOptions::ForcePreflight, |
| 358 ForcePreflight); |
| 359 STATIC_ASSERT_ENUM(WebAssociatedURLLoaderOptions::PreventPreflight, |
| 360 PreventPreflight); |
| 348 | 361 |
| 349 void AssociatedURLLoader::loadSynchronously(const WebURLRequest& request, | 362 void WebAssociatedURLLoaderImpl::loadAsynchronously( |
| 350 WebURLResponse& response, | 363 const WebURLRequest& request, |
| 351 WebURLError& error, | 364 WebAssociatedURLLoaderClient* client) { |
| 352 WebData& data, | |
| 353 int64_t& encodedDataLength) { | |
| 354 DCHECK(0); // Synchronous loading is not supported. | |
| 355 } | |
| 356 | |
| 357 void AssociatedURLLoader::loadAsynchronously(const WebURLRequest& request, | |
| 358 WebURLLoaderClient* client) { | |
| 359 DCHECK(!m_client); | 365 DCHECK(!m_client); |
| 360 DCHECK(!m_loader); | 366 DCHECK(!m_loader); |
| 361 DCHECK(!m_clientAdapter); | 367 DCHECK(!m_clientAdapter); |
| 362 | 368 |
| 363 DCHECK(client); | 369 DCHECK(client); |
| 364 | 370 |
| 365 bool allowLoad = true; | 371 bool allowLoad = true; |
| 366 WebURLRequest newRequest(request); | 372 WebURLRequest newRequest(request); |
| 367 if (m_options.untrustedHTTP) { | 373 if (m_options.untrustedHTTP) { |
| 368 WebString method = newRequest.httpMethod(); | 374 WebString method = newRequest.httpMethod(); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 409 m_loader->start(webcoreRequest); | 415 m_loader->start(webcoreRequest); |
| 410 } | 416 } |
| 411 | 417 |
| 412 if (!m_loader) { | 418 if (!m_loader) { |
| 413 // FIXME: return meaningful error codes. | 419 // FIXME: return meaningful error codes. |
| 414 m_clientAdapter->didFail(ResourceError()); | 420 m_clientAdapter->didFail(ResourceError()); |
| 415 } | 421 } |
| 416 m_clientAdapter->enableErrorNotifications(); | 422 m_clientAdapter->enableErrorNotifications(); |
| 417 } | 423 } |
| 418 | 424 |
| 419 void AssociatedURLLoader::cancel() { | 425 void WebAssociatedURLLoaderImpl::cancel() { |
| 420 disposeObserver(); | 426 disposeObserver(); |
| 421 cancelLoader(); | 427 cancelLoader(); |
| 422 releaseClient(); | 428 releaseClient(); |
| 423 } | 429 } |
| 424 | 430 |
| 425 void AssociatedURLLoader::clientAdapterDone() { | 431 void WebAssociatedURLLoaderImpl::clientAdapterDone() { |
| 426 disposeObserver(); | 432 disposeObserver(); |
| 427 releaseClient(); | 433 releaseClient(); |
| 428 } | 434 } |
| 429 | 435 |
| 430 void AssociatedURLLoader::cancelLoader() { | 436 void WebAssociatedURLLoaderImpl::cancelLoader() { |
| 431 if (!m_clientAdapter) | 437 if (!m_clientAdapter) |
| 432 return; | 438 return; |
| 433 | 439 |
| 434 // Prevent invocation of the WebURLLoaderClient methods. | 440 // Prevent invocation of the WebAssociatedURLLoaderClient methods. |
| 435 m_clientAdapter->releaseClient(); | 441 m_clientAdapter->releaseClient(); |
| 436 | 442 |
| 437 if (m_loader) { | 443 if (m_loader) { |
| 438 m_loader->cancel(); | 444 m_loader->cancel(); |
| 439 m_loader = nullptr; | 445 m_loader = nullptr; |
| 440 } | 446 } |
| 441 m_clientAdapter.reset(); | 447 m_clientAdapter.reset(); |
| 442 } | 448 } |
| 443 | 449 |
| 444 void AssociatedURLLoader::setDefersLoading(bool defersLoading) { | 450 void WebAssociatedURLLoaderImpl::setDefersLoading(bool defersLoading) { |
| 445 if (m_loader) | 451 if (m_loader) |
| 446 m_loader->setDefersLoading(defersLoading); | 452 m_loader->setDefersLoading(defersLoading); |
| 447 } | 453 } |
| 448 | 454 |
| 449 void AssociatedURLLoader::setLoadingTaskRunner(blink::WebTaskRunner*) { | 455 void WebAssociatedURLLoaderImpl::setLoadingTaskRunner(blink::WebTaskRunner*) { |
| 450 // TODO(alexclarke): Maybe support this one day if it proves worthwhile. | 456 // TODO(alexclarke): Maybe support this one day if it proves worthwhile. |
| 451 } | 457 } |
| 452 | 458 |
| 453 void AssociatedURLLoader::documentDestroyed() { | 459 void WebAssociatedURLLoaderImpl::documentDestroyed() { |
| 454 disposeObserver(); | 460 disposeObserver(); |
| 455 cancelLoader(); | 461 cancelLoader(); |
| 456 | 462 |
| 457 if (!m_client) | 463 if (!m_client) |
| 458 return; | 464 return; |
| 459 | 465 |
| 460 releaseClient()->didFail(this, ResourceError()); | 466 releaseClient()->didFail(ResourceError()); |
| 461 // |this| may be dead here. | 467 // |this| may be dead here. |
| 462 } | 468 } |
| 463 | 469 |
| 464 void AssociatedURLLoader::disposeObserver() { | 470 void WebAssociatedURLLoaderImpl::disposeObserver() { |
| 465 if (!m_observer) | 471 if (!m_observer) |
| 466 return; | 472 return; |
| 467 | 473 |
| 468 // TODO(tyoshino): Remove this assert once Document is fixed so that | 474 // TODO(tyoshino): Remove this assert once Document is fixed so that |
| 469 // contextDestroyed() is invoked for all kinds of Documents. | 475 // contextDestroyed() is invoked for all kinds of Documents. |
| 470 // | 476 // |
| 471 // Currently, the method of detecting Document destruction implemented here | 477 // Currently, the method of detecting Document destruction implemented here |
| 472 // doesn't work for all kinds of Documents. In case we reached here after | 478 // doesn't work for all kinds of Documents. In case we reached here after |
| 473 // the Oilpan is destroyed, we just crash the renderer process to prevent | 479 // the Oilpan is destroyed, we just crash the renderer process to prevent |
| 474 // UaF. | 480 // UaF. |
| 475 // | 481 // |
| 476 // We could consider just skipping the rest of code in case | 482 // We could consider just skipping the rest of code in case |
| 477 // ThreadState::current() is null. However, the fact we reached here | 483 // ThreadState::current() is null. However, the fact we reached here |
| 478 // without cancelling the loader means that it's possible there're some | 484 // without cancelling the loader means that it's possible there're some |
| 479 // non-Blink non-on-heap objects still facing on-heap Blink objects. E.g. | 485 // non-Blink non-on-heap objects still facing on-heap Blink objects. E.g. |
| 480 // there could be a WebURLLoader instance behind the | 486 // there could be a WebURLLoader instance behind the |
| 481 // DocumentThreadableLoader instance. So, for safety, we chose to just | 487 // DocumentThreadableLoader instance. So, for safety, we chose to just |
| 482 // crash here. | 488 // crash here. |
| 483 RELEASE_ASSERT(ThreadState::current()); | 489 CHECK(ThreadState::current()); |
| 484 | 490 |
| 485 m_observer->dispose(); | 491 m_observer->dispose(); |
| 486 m_observer = nullptr; | 492 m_observer = nullptr; |
| 487 } | 493 } |
| 488 | 494 |
| 489 } // namespace blink | 495 } // namespace blink |
| OLD | NEW |