Index: Source/core/loader/DocumentThreadableLoader.cpp |
diff --git a/Source/core/loader/DocumentThreadableLoader.cpp b/Source/core/loader/DocumentThreadableLoader.cpp |
index 88dde159b88a9d7bf8b16b9c89951158f72552f7..88b0b4ace20390025b4227aedb27cb052bfc5384 100644 |
--- a/Source/core/loader/DocumentThreadableLoader.cpp |
+++ b/Source/core/loader/DocumentThreadableLoader.cpp |
@@ -78,6 +78,7 @@ DocumentThreadableLoader::DocumentThreadableLoader(Document* document, Threadabl |
, m_sameOriginRequest(securityOrigin()->canRequest(request.url())) |
, m_simpleRequest(true) |
, m_async(blockingBehavior == LoadAsynchronously) |
+ , m_timeoutTimer(this, &DocumentThreadableLoader::timedOut) |
{ |
ASSERT(document); |
ASSERT(client); |
@@ -145,14 +146,22 @@ DocumentThreadableLoader::~DocumentThreadableLoader() |
void DocumentThreadableLoader::cancel() |
{ |
+ cancel(ResourceError()); |
+} |
+ |
+void DocumentThreadableLoader::cancel(const ResourceError& error) |
+{ |
RefPtr<DocumentThreadableLoader> protect(this); |
// Cancel can re-enter and m_resource might be null here as a result. |
if (m_client && m_resource) { |
- // FIXME: This error is sent to the client in didFail(), so it should not be an internal one. Use FrameLoaderClient::cancelledError() instead. |
- ResourceError error(errorDomainWebKitInternal, 0, m_resource->url().string(), "Load cancelled"); |
- error.setIsCancellation(true); |
- didFail(m_resource->identifier(), error); |
+ ResourceError errorForCallback = error; |
+ if (error.isNull()) { |
abarth-chromium
2013/05/17 05:10:40
I probably would have written errorForCallback.isN
|
+ // FIXME: This error is sent to the client in didFail(), so it should not be an internal one. Use FrameLoaderClient::cancelledError() instead. |
+ errorForCallback = ResourceError(errorDomainWebKitInternal, 0, m_resource->url().string(), "Load cancelled"); |
+ errorForCallback.setIsCancellation(true); |
+ } |
+ didFail(m_resource->identifier(), errorForCallback); |
} |
clearResource(); |
m_client = 0; |
@@ -323,6 +332,8 @@ void DocumentThreadableLoader::notifyFinished(CachedResource* resource) |
{ |
ASSERT(m_client); |
ASSERT_UNUSED(resource, resource == m_resource); |
+ |
+ m_timeoutTimer.stop(); |
if (m_resource->errorOccurred()) |
didFail(m_resource->identifier(), m_resource->resourceError()); |
@@ -371,6 +382,20 @@ void DocumentThreadableLoader::preflightFailure(unsigned long identifier, const |
m_client->didFailAccessControlCheck(error); |
} |
+void DocumentThreadableLoader::timedOut(Timer<DocumentThreadableLoader>* timer) |
+{ |
+ ASSERT_UNUSED(timer, timer == &m_timeoutTimer); |
+ |
+ // Using values from net/base/net_error_list.h ERR_TIMED_OUT, |
+ // Same as existing FIXME above - this error should be coming from FrameLoaderClient to be identifiable. |
+ static const int timeoutError = -7; |
+ static const char* const errorDomain = "net"; |
+ 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
|
+ error.setIsTimeout(true); |
+ cancel(error); |
+} |
+ |
+ |
void DocumentThreadableLoader::loadRequest(const ResourceRequest& request, SecurityCheckPolicy securityCheck) |
{ |
// Any credential should have been removed from the cross-site requests. |
@@ -390,6 +415,9 @@ void DocumentThreadableLoader::loadRequest(const ResourceRequest& request, Secur |
options.dataBufferingPolicy = BufferData; |
} |
+ if (m_options.timeoutMilliseconds > 0) |
+ m_timeoutTimer.startOneShot(m_options.timeoutMilliseconds / 1000.0); |
+ |
CachedResourceRequest newRequest(request, options); |
newRequest.setInitiator(m_options.initiator); |
ASSERT(!m_resource); |