Index: Source/core/loader/SimplexLoader.cpp |
diff --git a/Source/core/loader/SimplexLoader.cpp b/Source/core/loader/SimplexLoader.cpp |
new file mode 100644 |
index 0000000000000000000000000000000000000000..7d9555835fe39b65f51820bdd1c522592537b35b |
--- /dev/null |
+++ b/Source/core/loader/SimplexLoader.cpp |
@@ -0,0 +1,98 @@ |
+// Copyright 2014 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "config.h" |
+#include "core/loader/SimplexLoader.h" |
+ |
+#include "FetchInitiatorTypeNames.h" |
+#include "core/dom/Document.h" |
+#include "core/fetch/FetchContext.h" |
+#include "core/frame/LocalFrame.h" |
+#include "core/inspector/InspectorInstrumentation.h" |
+#include "core/loader/FrameLoader.h" |
+#include "core/loader/FrameLoaderClient.h" |
+#include "core/loader/UniqueIdentifier.h" |
+#include "core/page/Page.h" |
+#include "platform/exported/WrappedResourceRequest.h" |
+#include "platform/network/ResourceError.h" |
+#include "platform/network/ResourceRequest.h" |
+#include "platform/network/ResourceResponse.h" |
+#include "public/platform/Platform.h" |
+#include "public/platform/WebURLLoader.h" |
+#include "public/platform/WebURLResponse.h" |
+#include "wtf/OwnPtr.h" |
+ |
+namespace WebCore { |
+ |
+void SimplexLoader::start(LocalFrame* frame, ResourceRequest& request, const FetchInitiatorInfo& initiatorInfo, StoredCredentials credentialsAllowed) |
+{ |
+ OwnPtr<SimplexLoader> loader = adoptPtr(new SimplexLoader(frame, request, initiatorInfo, credentialsAllowed)); |
+ |
+ // Leak the loader, since it will kill itself as soon as it receives a response. |
+ SimplexLoader* ALLOW_UNUSED leakedLoader = loader.leakPtr(); |
+} |
+ |
+SimplexLoader::SimplexLoader(LocalFrame* frame, ResourceRequest& request, const FetchInitiatorInfo& initiatorInfo, StoredCredentials credentialsAllowed) |
+ : PageLifecycleObserver(frame->page()) |
+ , m_timeout(this, &SimplexLoader::timeout) |
+ , m_url(request.url()) |
+ , m_identifier(createUniqueIdentifier()) |
+{ |
+ frame->loader().client()->didDispatchSimplexLoader(request.url()); |
+ |
+ m_loader = adoptPtr(blink::Platform::current()->createURLLoader()); |
+ ASSERT(m_loader); |
+ blink::WrappedResourceRequest wrappedRequest(request); |
+ wrappedRequest.setAllowStoredCredentials(credentialsAllowed == AllowStoredCredentials); |
+ m_loader->loadAsynchronously(wrappedRequest, this); |
+ |
+ InspectorInstrumentation::willSendRequest(frame, m_identifier, frame->loader().documentLoader(), request, ResourceResponse(), initiatorInfo); |
+ |
+ // If the server never responds, FrameLoader won't be able to cancel this load and |
+ // we'll sit here waiting forever. Set a very generous timeout, just in case. |
+ m_timeout.startOneShot(60000, FROM_HERE); |
+} |
+ |
+SimplexLoader::~SimplexLoader() |
+{ |
+ if (m_loader) |
+ m_loader->cancel(); |
+} |
+ |
+void SimplexLoader::didReceiveResponse(blink::WebURLLoader*, const blink::WebURLResponse&) |
+{ |
+ if (Page* page = this->page()) |
+ InspectorInstrumentation::didFailLoading(page->mainFrame(), m_identifier, ResourceError::cancelledError(m_url)); |
+ delete this; |
+} |
+ |
+void SimplexLoader::didReceiveData(blink::WebURLLoader*, const char*, int, int) |
+{ |
+ if (Page* page = this->page()) |
+ InspectorInstrumentation::didFailLoading(page->mainFrame(), m_identifier, ResourceError::cancelledError(m_url)); |
+ delete this; |
+} |
+ |
+void SimplexLoader::didFinishLoading(blink::WebURLLoader*, double, int64_t) |
+{ |
+ if (Page* page = this->page()) |
+ InspectorInstrumentation::didFailLoading(page->mainFrame(), m_identifier, ResourceError::cancelledError(m_url)); |
+ delete this; |
+} |
+ |
+void SimplexLoader::didFail(blink::WebURLLoader*, const blink::WebURLError& resourceError) |
+{ |
+ if (Page* page = this->page()) |
+ InspectorInstrumentation::didFailLoading(page->mainFrame(), m_identifier, ResourceError(resourceError)); |
+ delete this; |
+} |
+ |
+void SimplexLoader::timeout(Timer<SimplexLoader>*) |
+{ |
+ if (Page* page = this->page()) |
+ InspectorInstrumentation::didFailLoading(page->mainFrame(), m_identifier, ResourceError::cancelledError(m_url)); |
+ delete this; |
+} |
+ |
+} // namespace WebCore |