OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "config.h" |
| 6 #include "core/loader/SimplexLoader.h" |
| 7 |
| 8 #include "FetchInitiatorTypeNames.h" |
| 9 #include "core/dom/Document.h" |
| 10 #include "core/fetch/FetchContext.h" |
| 11 #include "core/frame/LocalFrame.h" |
| 12 #include "core/inspector/InspectorInstrumentation.h" |
| 13 #include "core/loader/FrameLoader.h" |
| 14 #include "core/loader/FrameLoaderClient.h" |
| 15 #include "core/loader/UniqueIdentifier.h" |
| 16 #include "core/page/Page.h" |
| 17 #include "platform/exported/WrappedResourceRequest.h" |
| 18 #include "platform/network/ResourceError.h" |
| 19 #include "platform/network/ResourceRequest.h" |
| 20 #include "platform/network/ResourceResponse.h" |
| 21 #include "public/platform/Platform.h" |
| 22 #include "public/platform/WebURLLoader.h" |
| 23 #include "public/platform/WebURLResponse.h" |
| 24 #include "wtf/OwnPtr.h" |
| 25 |
| 26 namespace WebCore { |
| 27 |
| 28 void SimplexLoader::start(LocalFrame* frame, ResourceRequest& request, const Fet
chInitiatorInfo& initiatorInfo, StoredCredentials credentialsAllowed) |
| 29 { |
| 30 OwnPtr<SimplexLoader> loader = adoptPtr(new SimplexLoader(frame, request, in
itiatorInfo, credentialsAllowed)); |
| 31 |
| 32 // Leak the loader, since it will kill itself as soon as it receives a respo
nse. |
| 33 SimplexLoader* ALLOW_UNUSED leakedLoader = loader.leakPtr(); |
| 34 } |
| 35 |
| 36 SimplexLoader::SimplexLoader(LocalFrame* frame, ResourceRequest& request, const
FetchInitiatorInfo& initiatorInfo, StoredCredentials credentialsAllowed) |
| 37 : PageLifecycleObserver(frame->page()) |
| 38 , m_timeout(this, &SimplexLoader::timeout) |
| 39 , m_url(request.url()) |
| 40 , m_identifier(createUniqueIdentifier()) |
| 41 { |
| 42 frame->loader().client()->didDispatchSimplexLoader(request.url()); |
| 43 |
| 44 m_loader = adoptPtr(blink::Platform::current()->createURLLoader()); |
| 45 ASSERT(m_loader); |
| 46 blink::WrappedResourceRequest wrappedRequest(request); |
| 47 wrappedRequest.setAllowStoredCredentials(credentialsAllowed == AllowStoredCr
edentials); |
| 48 m_loader->loadAsynchronously(wrappedRequest, this); |
| 49 |
| 50 InspectorInstrumentation::willSendRequest(frame, m_identifier, frame->loader
().documentLoader(), request, ResourceResponse(), initiatorInfo); |
| 51 |
| 52 // If the server never responds, FrameLoader won't be able to cancel this lo
ad and |
| 53 // we'll sit here waiting forever. Set a very generous timeout, just in case
. |
| 54 m_timeout.startOneShot(60000, FROM_HERE); |
| 55 } |
| 56 |
| 57 SimplexLoader::~SimplexLoader() |
| 58 { |
| 59 if (m_loader) |
| 60 m_loader->cancel(); |
| 61 } |
| 62 |
| 63 void SimplexLoader::didReceiveResponse(blink::WebURLLoader*, const blink::WebURL
Response&) |
| 64 { |
| 65 if (Page* page = this->page()) |
| 66 InspectorInstrumentation::didFailLoading(page->mainFrame(), m_identifier
, ResourceError::cancelledError(m_url)); |
| 67 delete this; |
| 68 } |
| 69 |
| 70 void SimplexLoader::didReceiveData(blink::WebURLLoader*, const char*, int, int) |
| 71 { |
| 72 if (Page* page = this->page()) |
| 73 InspectorInstrumentation::didFailLoading(page->mainFrame(), m_identifier
, ResourceError::cancelledError(m_url)); |
| 74 delete this; |
| 75 } |
| 76 |
| 77 void SimplexLoader::didFinishLoading(blink::WebURLLoader*, double, int64_t) |
| 78 { |
| 79 if (Page* page = this->page()) |
| 80 InspectorInstrumentation::didFailLoading(page->mainFrame(), m_identifier
, ResourceError::cancelledError(m_url)); |
| 81 delete this; |
| 82 } |
| 83 |
| 84 void SimplexLoader::didFail(blink::WebURLLoader*, const blink::WebURLError& reso
urceError) |
| 85 { |
| 86 if (Page* page = this->page()) |
| 87 InspectorInstrumentation::didFailLoading(page->mainFrame(), m_identifier
, ResourceError(resourceError)); |
| 88 delete this; |
| 89 } |
| 90 |
| 91 void SimplexLoader::timeout(Timer<SimplexLoader>*) |
| 92 { |
| 93 if (Page* page = this->page()) |
| 94 InspectorInstrumentation::didFailLoading(page->mainFrame(), m_identifier
, ResourceError::cancelledError(m_url)); |
| 95 delete this; |
| 96 } |
| 97 |
| 98 } // namespace WebCore |
OLD | NEW |