Index: third_party/WebKit/Source/core/loader/PingLoader.cpp |
diff --git a/third_party/WebKit/Source/core/loader/PingLoader.cpp b/third_party/WebKit/Source/core/loader/PingLoader.cpp |
index d32a134369d0be2abdf6beaad061ffaae2698af7..afd0272886840e13c89c970e42d8f1ab990f301f 100644 |
--- a/third_party/WebKit/Source/core/loader/PingLoader.cpp |
+++ b/third_party/WebKit/Source/core/loader/PingLoader.cpp |
@@ -39,6 +39,7 @@ |
#include "core/fetch/FetchInitiatorTypeNames.h" |
#include "core/fetch/FetchUtils.h" |
#include "core/fetch/ResourceFetcher.h" |
+#include "core/fetch/ResourceLoaderOptions.h" |
#include "core/fetch/UniqueIdentifier.h" |
#include "core/fileapi/File.h" |
#include "core/frame/FrameConsole.h" |
@@ -51,8 +52,9 @@ |
#include "core/loader/FrameLoader.h" |
#include "core/loader/FrameLoaderClient.h" |
#include "core/loader/MixedContentChecker.h" |
+#include "core/loader/ThreadableLoader.h" |
+#include "core/loader/ThreadableLoaderClient.h" |
#include "core/page/Page.h" |
-#include "platform/WebFrameScheduler.h" |
#include "platform/exported/WrappedResourceRequest.h" |
#include "platform/exported/WrappedResourceResponse.h" |
#include "platform/network/EncodedFormData.h" |
@@ -188,7 +190,7 @@ class BeaconFormData final : public Beacon { |
class PingLoaderImpl : public GarbageCollectedFinalized<PingLoaderImpl>, |
public DOMWindowProperty, |
- private WebURLLoaderClient { |
+ private ThreadableLoaderClient { |
USING_GARBAGE_COLLECTED_MIXIN(PingLoaderImpl); |
WTF_MAKE_NONCOPYABLE(PingLoaderImpl); |
@@ -196,8 +198,7 @@ class PingLoaderImpl : public GarbageCollectedFinalized<PingLoaderImpl>, |
PingLoaderImpl(LocalFrame*, |
ResourceRequest&, |
const AtomicString&, |
- StoredCredentials, |
- bool); |
+ StoredCredentials); |
~PingLoaderImpl() override; |
DECLARE_VIRTUAL_TRACE(); |
@@ -205,78 +206,46 @@ class PingLoaderImpl : public GarbageCollectedFinalized<PingLoaderImpl>, |
private: |
void dispose(); |
- // WebURLLoaderClient |
- bool willFollowRedirect(WebURLRequest&, const WebURLResponse&) override; |
- void didReceiveResponse(const WebURLResponse&) final; |
- void didReceiveData(const char*, int) final; |
- void didFinishLoading(double, int64_t, int64_t) final; |
- void didFail(const WebURLError&, int64_t, int64_t) final; |
+ // ThreadableLoaderClient |
+ void didFail(const ResourceError&) final; |
+ void didFinishLoading(unsigned long, double) final; |
- void timeout(TimerBase*); |
- |
- void didFailLoading(LocalFrame*); |
- |
- std::unique_ptr<WebURLLoader> m_loader; |
- Timer<PingLoaderImpl> m_timeout; |
+ Member<ThreadableLoader> m_loader; |
String m_url; |
- unsigned long m_identifier; |
SelfKeepAlive<PingLoaderImpl> m_keepAlive; |
- |
- bool m_isBeacon; |
- |
- RefPtr<SecurityOrigin> m_origin; |
- CORSEnabled m_corsMode; |
}; |
PingLoaderImpl::PingLoaderImpl(LocalFrame* frame, |
ResourceRequest& request, |
const AtomicString& initiator, |
- StoredCredentials credentialsAllowed, |
- bool isBeacon) |
- : DOMWindowProperty(frame), |
- m_timeout(this, &PingLoaderImpl::timeout), |
- m_url(request.url()), |
- m_identifier(createUniqueIdentifier()), |
- m_keepAlive(this), |
- m_isBeacon(isBeacon), |
- m_origin(frame->document()->getSecurityOrigin()), |
- m_corsMode(IsCORSEnabled) { |
- const AtomicString contentType = request.httpContentType(); |
- if (!contentType.isNull() && |
- FetchUtils::isSimpleHeader(AtomicString("content-type"), contentType)) |
- m_corsMode = NotCORSEnabled; |
- |
+ StoredCredentials credentialsAllowed) |
+ : DOMWindowProperty(frame), m_url(request.url()), m_keepAlive(this) { |
frame->loader().client()->didDispatchPingLoader(request.url()); |
- FetchContext& fetchContext = frame->document()->fetcher()->context(); |
- |
- fetchContext.willStartLoadingResource(m_identifier, request, Resource::Image); |
- |
- FetchInitiatorInfo initiatorInfo; |
- initiatorInfo.name = initiator; |
- fetchContext.dispatchWillSendRequest(m_identifier, request, |
- ResourceResponse(), initiatorInfo); |
- |
- // Make sure the scheduler doesn't wait for the ping. |
- if (frame->frameScheduler()) |
- frame->frameScheduler()->didStopLoading(m_identifier); |
- |
- m_loader = WTF::wrapUnique(Platform::current()->createURLLoader()); |
- DCHECK(m_loader); |
- WrappedResourceRequest wrappedRequest(request); |
- wrappedRequest.setAllowStoredCredentials(credentialsAllowed == |
- AllowStoredCredentials); |
- m_loader->loadAsynchronously(wrappedRequest, this); |
- |
+ ThreadableLoaderOptions options; |
+ options.preflightPolicy = ConsiderPreflight; |
+ options.crossOriginRequestPolicy = UseAccessControl; |
+ options.initiator = initiator; |
// 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, BLINK_FROM_HERE); |
+ options.timeoutMilliseconds = 60000; |
+ // Make sure the scheduler doesn't wait for the ping. |
+ options.schedulerWaitingPolicy = PreventSchedulerFromWaiting; |
+ |
+ ResourceLoaderOptions resourceLoaderOptions; |
+ resourceLoaderOptions.allowCredentials = AllowStoredCredentials; |
+ resourceLoaderOptions.credentialsRequested = ClientRequestedCredentials; |
+ resourceLoaderOptions.securityOrigin = frame->document()->getSecurityOrigin(); |
+ resourceLoaderOptions.dataBufferingPolicy = DoNotBufferData; |
+ |
+ m_loader = ThreadableLoader::create(*frame->document(), this, options, |
+ resourceLoaderOptions); |
+ DCHECK(m_loader); |
+ m_loader->start(request); |
} |
PingLoaderImpl::~PingLoaderImpl() { |
- if (m_loader) |
- m_loader->cancel(); |
} |
void PingLoaderImpl::dispose() { |
@@ -284,110 +253,19 @@ void PingLoaderImpl::dispose() { |
m_loader->cancel(); |
m_loader = nullptr; |
} |
- m_timeout.stop(); |
m_keepAlive.clear(); |
} |
-bool PingLoaderImpl::willFollowRedirect( |
- WebURLRequest& passedNewRequest, |
- const WebURLResponse& passedRedirectResponse) { |
- if (!m_isBeacon) |
- return true; |
- |
- if (m_corsMode == NotCORSEnabled) |
- return true; |
- |
- DCHECK(passedNewRequest.allowStoredCredentials()); |
- |
- ResourceRequest& newRequest(passedNewRequest.toMutableResourceRequest()); |
- const ResourceResponse& redirectResponse( |
- passedRedirectResponse.toResourceResponse()); |
- |
- DCHECK(!newRequest.isNull()); |
- DCHECK(!redirectResponse.isNull()); |
- |
- String errorDescription; |
- ResourceLoaderOptions options; |
- // TODO(tyoshino): Save updated data in options.securityOrigin and pass it |
- // on the next time. |
- if (!CrossOriginAccessControl::handleRedirect( |
- m_origin, newRequest, redirectResponse, AllowStoredCredentials, |
- options, errorDescription)) { |
- if (LocalFrame* localFrame = frame()) { |
- if (localFrame->document()) { |
- localFrame->document()->addConsoleMessage(ConsoleMessage::create( |
- JSMessageSource, ErrorMessageLevel, errorDescription)); |
- } |
- } |
- // Cancel the load and self destruct. |
- dispose(); |
- |
- return false; |
- } |
- // FIXME: http://crbug.com/427429 is needed to correctly propagate updates of |
- // Origin: following this successful redirect. |
- |
- return true; |
-} |
- |
-void PingLoaderImpl::didReceiveResponse(const WebURLResponse& response) { |
- if (LocalFrame* frame = this->frame()) { |
- TRACE_EVENT1("devtools.timeline", "ResourceFinish", "data", |
- InspectorResourceFinishEvent::data(m_identifier, 0, true)); |
- const ResourceResponse& resourceResponse = response.toResourceResponse(); |
- InspectorInstrumentation::didReceiveResourceResponse(frame, m_identifier, 0, |
- resourceResponse, 0); |
- didFailLoading(frame); |
- } |
- dispose(); |
-} |
- |
-void PingLoaderImpl::didReceiveData(const char*, int) { |
- if (LocalFrame* frame = this->frame()) { |
- TRACE_EVENT1("devtools.timeline", "ResourceFinish", "data", |
- InspectorResourceFinishEvent::data(m_identifier, 0, true)); |
- didFailLoading(frame); |
- } |
- dispose(); |
-} |
- |
-void PingLoaderImpl::didFinishLoading(double, int64_t, int64_t) { |
- if (LocalFrame* frame = this->frame()) { |
- TRACE_EVENT1("devtools.timeline", "ResourceFinish", "data", |
- InspectorResourceFinishEvent::data(m_identifier, 0, true)); |
- didFailLoading(frame); |
- } |
- dispose(); |
-} |
- |
-void PingLoaderImpl::didFail(const WebURLError& resourceError, |
- int64_t, |
- int64_t) { |
- if (LocalFrame* frame = this->frame()) { |
- TRACE_EVENT1("devtools.timeline", "ResourceFinish", "data", |
- InspectorResourceFinishEvent::data(m_identifier, 0, true)); |
- didFailLoading(frame); |
- } |
+void PingLoaderImpl::didFail(const ResourceError& error) { |
dispose(); |
} |
-void PingLoaderImpl::timeout(TimerBase*) { |
- if (LocalFrame* frame = this->frame()) { |
- TRACE_EVENT1("devtools.timeline", "ResourceFinish", "data", |
- InspectorResourceFinishEvent::data(m_identifier, 0, true)); |
- didFailLoading(frame); |
- } |
+void PingLoaderImpl::didFinishLoading(unsigned long, double) { |
dispose(); |
} |
-void PingLoaderImpl::didFailLoading(LocalFrame* frame) { |
- InspectorInstrumentation::didFailLoading( |
- frame, m_identifier, ResourceError::cancelledError(m_url)); |
- frame->console().didFailLoading(m_identifier, |
- ResourceError::cancelledError(m_url)); |
-} |
- |
DEFINE_TRACE(PingLoaderImpl) { |
+ visitor->trace(m_loader); |
DOMWindowProperty::trace(visitor); |
} |
@@ -412,7 +290,7 @@ bool sendPingCommon(LocalFrame* frame, |
// The loader keeps itself alive until it receives a response and disposes |
// itself. |
PingLoaderImpl* loader = |
- new PingLoaderImpl(frame, request, initiator, credentialsAllowed, true); |
+ new PingLoaderImpl(frame, request, initiator, credentialsAllowed); |
DCHECK(loader); |
return true; |