Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2011, 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 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 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 71 return loader.release(); | 71 return loader.release(); |
| 72 } | 72 } |
| 73 | 73 |
| 74 DocumentThreadableLoader::DocumentThreadableLoader(Document* document, Threadabl eLoaderClient* client, BlockingBehavior blockingBehavior, const ResourceRequest& request, const ThreadableLoaderOptions& options) | 74 DocumentThreadableLoader::DocumentThreadableLoader(Document* document, Threadabl eLoaderClient* client, BlockingBehavior blockingBehavior, const ResourceRequest& request, const ThreadableLoaderOptions& options) |
| 75 : m_client(client) | 75 : m_client(client) |
| 76 , m_document(document) | 76 , m_document(document) |
| 77 , m_options(options) | 77 , m_options(options) |
| 78 , m_sameOriginRequest(securityOrigin()->canRequest(request.url())) | 78 , m_sameOriginRequest(securityOrigin()->canRequest(request.url())) |
| 79 , m_simpleRequest(true) | 79 , m_simpleRequest(true) |
| 80 , m_async(blockingBehavior == LoadAsynchronously) | 80 , m_async(blockingBehavior == LoadAsynchronously) |
| 81 , m_timeoutTimer(this, &DocumentThreadableLoader::timedOut) | |
| 81 { | 82 { |
| 82 ASSERT(document); | 83 ASSERT(document); |
| 83 ASSERT(client); | 84 ASSERT(client); |
| 84 // Setting an outgoing referer is only supported in the async code path. | 85 // Setting an outgoing referer is only supported in the async code path. |
| 85 ASSERT(m_async || request.httpReferrer().isEmpty()); | 86 ASSERT(m_async || request.httpReferrer().isEmpty()); |
| 86 | 87 |
| 87 if (m_sameOriginRequest || m_options.crossOriginRequestPolicy == AllowCrossO riginRequests) { | 88 if (m_sameOriginRequest || m_options.crossOriginRequestPolicy == AllowCrossO riginRequests) { |
| 88 loadRequest(request, DoSecurityCheck); | 89 loadRequest(request, DoSecurityCheck); |
| 89 return; | 90 return; |
| 90 } | 91 } |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 138 } | 139 } |
| 139 | 140 |
| 140 DocumentThreadableLoader::~DocumentThreadableLoader() | 141 DocumentThreadableLoader::~DocumentThreadableLoader() |
| 141 { | 142 { |
| 142 if (m_resource) | 143 if (m_resource) |
| 143 m_resource->removeClient(this); | 144 m_resource->removeClient(this); |
| 144 } | 145 } |
| 145 | 146 |
| 146 void DocumentThreadableLoader::cancel() | 147 void DocumentThreadableLoader::cancel() |
| 147 { | 148 { |
| 149 cancel(ResourceError()); | |
| 150 } | |
| 151 | |
| 152 void DocumentThreadableLoader::cancel(const ResourceError& error) | |
| 153 { | |
| 148 RefPtr<DocumentThreadableLoader> protect(this); | 154 RefPtr<DocumentThreadableLoader> protect(this); |
| 149 | 155 |
| 150 // Cancel can re-enter and m_resource might be null here as a result. | 156 // Cancel can re-enter and m_resource might be null here as a result. |
| 151 if (m_client && m_resource) { | 157 if (m_client && m_resource) { |
| 152 // FIXME: This error is sent to the client in didFail(), so it should no t be an internal one. Use FrameLoaderClient::cancelledError() instead. | 158 ResourceError errorForCallback = error; |
| 153 ResourceError error(errorDomainWebKitInternal, 0, m_resource->url().stri ng(), "Load cancelled"); | 159 if (error.isNull()) { |
|
abarth-chromium
2013/05/17 05:10:40
I probably would have written errorForCallback.isN
| |
| 154 error.setIsCancellation(true); | 160 // FIXME: This error is sent to the client in didFail(), so it shoul d not be an internal one. Use FrameLoaderClient::cancelledError() instead. |
| 155 didFail(m_resource->identifier(), error); | 161 errorForCallback = ResourceError(errorDomainWebKitInternal, 0, m_res ource->url().string(), "Load cancelled"); |
| 162 errorForCallback.setIsCancellation(true); | |
| 163 } | |
| 164 didFail(m_resource->identifier(), errorForCallback); | |
| 156 } | 165 } |
| 157 clearResource(); | 166 clearResource(); |
| 158 m_client = 0; | 167 m_client = 0; |
| 159 } | 168 } |
| 160 | 169 |
| 161 void DocumentThreadableLoader::setDefersLoading(bool value) | 170 void DocumentThreadableLoader::setDefersLoading(bool value) |
| 162 { | 171 { |
| 163 if (m_resource) | 172 if (m_resource) |
| 164 m_resource->setDefersLoading(value); | 173 m_resource->setDefersLoading(value); |
| 165 } | 174 } |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 316 return; | 325 return; |
| 317 } | 326 } |
| 318 | 327 |
| 319 m_client->didReceiveData(data, dataLength); | 328 m_client->didReceiveData(data, dataLength); |
| 320 } | 329 } |
| 321 | 330 |
| 322 void DocumentThreadableLoader::notifyFinished(CachedResource* resource) | 331 void DocumentThreadableLoader::notifyFinished(CachedResource* resource) |
| 323 { | 332 { |
| 324 ASSERT(m_client); | 333 ASSERT(m_client); |
| 325 ASSERT_UNUSED(resource, resource == m_resource); | 334 ASSERT_UNUSED(resource, resource == m_resource); |
| 335 | |
| 336 m_timeoutTimer.stop(); | |
| 326 | 337 |
| 327 if (m_resource->errorOccurred()) | 338 if (m_resource->errorOccurred()) |
| 328 didFail(m_resource->identifier(), m_resource->resourceError()); | 339 didFail(m_resource->identifier(), m_resource->resourceError()); |
| 329 else | 340 else |
| 330 didFinishLoading(m_resource->identifier(), m_resource->loadFinishTime()) ; | 341 didFinishLoading(m_resource->identifier(), m_resource->loadFinishTime()) ; |
| 331 } | 342 } |
| 332 | 343 |
| 333 void DocumentThreadableLoader::didFinishLoading(unsigned long identifier, double finishTime) | 344 void DocumentThreadableLoader::didFinishLoading(unsigned long identifier, double finishTime) |
| 334 { | 345 { |
| 335 if (m_actualRequest) { | 346 if (m_actualRequest) { |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 364 | 375 |
| 365 void DocumentThreadableLoader::preflightFailure(unsigned long identifier, const String& url, const String& errorDescription) | 376 void DocumentThreadableLoader::preflightFailure(unsigned long identifier, const String& url, const String& errorDescription) |
| 366 { | 377 { |
| 367 ResourceError error(errorDomainWebKitInternal, 0, url, errorDescription); | 378 ResourceError error(errorDomainWebKitInternal, 0, url, errorDescription); |
| 368 if (m_actualRequest) | 379 if (m_actualRequest) |
| 369 InspectorInstrumentation::didFailLoading(m_document->frame(), m_document ->frame()->loader()->documentLoader(), identifier, error); | 380 InspectorInstrumentation::didFailLoading(m_document->frame(), m_document ->frame()->loader()->documentLoader(), identifier, error); |
| 370 m_actualRequest = nullptr; // Prevent didFinishLoading() from bypassing acce ss check. | 381 m_actualRequest = nullptr; // Prevent didFinishLoading() from bypassing acce ss check. |
| 371 m_client->didFailAccessControlCheck(error); | 382 m_client->didFailAccessControlCheck(error); |
| 372 } | 383 } |
| 373 | 384 |
| 385 void DocumentThreadableLoader::timedOut(Timer<DocumentThreadableLoader>* timer) | |
| 386 { | |
| 387 ASSERT_UNUSED(timer, timer == &m_timeoutTimer); | |
| 388 | |
| 389 // Using values from net/base/net_error_list.h ERR_TIMED_OUT, | |
| 390 // Same as existing FIXME above - this error should be coming from FrameLoad erClient to be identifiable. | |
| 391 static const int timeoutError = -7; | |
| 392 static const char* const errorDomain = "net"; | |
| 393 ResourceError error(errorDomain, timeoutError, m_resource->url(), String()); | |
|
abarth-chromium
2013/05/17 05:10:40
I would probably just inline the string constant i
| |
| 394 error.setIsTimeout(true); | |
| 395 cancel(error); | |
| 396 } | |
| 397 | |
| 398 | |
| 374 void DocumentThreadableLoader::loadRequest(const ResourceRequest& request, Secur ityCheckPolicy securityCheck) | 399 void DocumentThreadableLoader::loadRequest(const ResourceRequest& request, Secur ityCheckPolicy securityCheck) |
| 375 { | 400 { |
| 376 // Any credential should have been removed from the cross-site requests. | 401 // Any credential should have been removed from the cross-site requests. |
| 377 const KURL& requestURL = request.url(); | 402 const KURL& requestURL = request.url(); |
| 378 m_options.securityCheck = securityCheck; | 403 m_options.securityCheck = securityCheck; |
| 379 ASSERT(m_sameOriginRequest || requestURL.user().isEmpty()); | 404 ASSERT(m_sameOriginRequest || requestURL.user().isEmpty()); |
| 380 ASSERT(m_sameOriginRequest || requestURL.pass().isEmpty()); | 405 ASSERT(m_sameOriginRequest || requestURL.pass().isEmpty()); |
| 381 | 406 |
| 382 if (m_async) { | 407 if (m_async) { |
| 383 ThreadableLoaderOptions options = m_options; | 408 ThreadableLoaderOptions options = m_options; |
| 384 options.crossOriginCredentialPolicy = DoNotAskClientForCrossOriginCreden tials; | 409 options.crossOriginCredentialPolicy = DoNotAskClientForCrossOriginCreden tials; |
| 385 if (m_actualRequest) { | 410 if (m_actualRequest) { |
| 386 // Don't sniff content or send load callbacks for the preflight requ est. | 411 // Don't sniff content or send load callbacks for the preflight requ est. |
| 387 options.sendLoadCallbacks = DoNotSendCallbacks; | 412 options.sendLoadCallbacks = DoNotSendCallbacks; |
| 388 options.sniffContent = DoNotSniffContent; | 413 options.sniffContent = DoNotSniffContent; |
| 389 // Keep buffering the data for the preflight request. | 414 // Keep buffering the data for the preflight request. |
| 390 options.dataBufferingPolicy = BufferData; | 415 options.dataBufferingPolicy = BufferData; |
| 391 } | 416 } |
| 392 | 417 |
| 418 if (m_options.timeoutMilliseconds > 0) | |
| 419 m_timeoutTimer.startOneShot(m_options.timeoutMilliseconds / 1000.0); | |
| 420 | |
| 393 CachedResourceRequest newRequest(request, options); | 421 CachedResourceRequest newRequest(request, options); |
| 394 newRequest.setInitiator(m_options.initiator); | 422 newRequest.setInitiator(m_options.initiator); |
| 395 ASSERT(!m_resource); | 423 ASSERT(!m_resource); |
| 396 m_resource = m_document->cachedResourceLoader()->requestRawResource(newR equest); | 424 m_resource = m_document->cachedResourceLoader()->requestRawResource(newR equest); |
| 397 if (m_resource) { | 425 if (m_resource) { |
| 398 if (m_resource->loader()) { | 426 if (m_resource->loader()) { |
| 399 unsigned long identifier = m_resource->loader()->identifier(); | 427 unsigned long identifier = m_resource->loader()->identifier(); |
| 400 InspectorInstrumentation::documentThreadableLoaderStartedLoading ForClient(m_document, identifier, m_client); | 428 InspectorInstrumentation::documentThreadableLoaderStartedLoading ForClient(m_document, identifier, m_client); |
| 401 } | 429 } |
| 402 m_resource->addClient(this); | 430 m_resource->addClient(this); |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 458 return true; | 486 return true; |
| 459 return m_document->contentSecurityPolicy()->allowConnectToSource(url); | 487 return m_document->contentSecurityPolicy()->allowConnectToSource(url); |
| 460 } | 488 } |
| 461 | 489 |
| 462 SecurityOrigin* DocumentThreadableLoader::securityOrigin() const | 490 SecurityOrigin* DocumentThreadableLoader::securityOrigin() const |
| 463 { | 491 { |
| 464 return m_options.securityOrigin ? m_options.securityOrigin.get() : m_documen t->securityOrigin(); | 492 return m_options.securityOrigin ? m_options.securityOrigin.get() : m_documen t->securityOrigin(); |
| 465 } | 493 } |
| 466 | 494 |
| 467 } // namespace WebCore | 495 } // namespace WebCore |
| OLD | NEW |