Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1037)

Unified Diff: Source/core/loader/DocumentThreadableLoader.cpp

Issue 1264453002: Split the constructor of ThreadableLoader into two methods (ctor and start()) (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: Source/core/loader/DocumentThreadableLoader.cpp
diff --git a/Source/core/loader/DocumentThreadableLoader.cpp b/Source/core/loader/DocumentThreadableLoader.cpp
index 8b84b7147cada891d7ace3393be6bb007a543489..829281d33898a29c442b3bea450c5727b81c8ac6 100644
--- a/Source/core/loader/DocumentThreadableLoader.cpp
+++ b/Source/core/loader/DocumentThreadableLoader.cpp
@@ -67,38 +67,44 @@ static const int kMaxCORSRedirects = 20;
void DocumentThreadableLoader::loadResourceSynchronously(Document& document, const ResourceRequest& request, ThreadableLoaderClient& client, const ThreadableLoaderOptions& options, const ResourceLoaderOptions& resourceLoaderOptions)
{
// The loader will be deleted as soon as this function exits.
- RefPtr<DocumentThreadableLoader> loader = adoptRef(new DocumentThreadableLoader(document, &client, LoadSynchronously, request, options, resourceLoaderOptions));
+ RefPtr<DocumentThreadableLoader> loader = adoptRef(new DocumentThreadableLoader(document, &client, LoadSynchronously, options, resourceLoaderOptions));
+ loader->start(request);
ASSERT(loader->hasOneRef());
}
-PassRefPtr<DocumentThreadableLoader> DocumentThreadableLoader::create(Document& document, ThreadableLoaderClient* client, const ResourceRequest& request, const ThreadableLoaderOptions& options, const ResourceLoaderOptions& resourceLoaderOptions)
+PassRefPtr<DocumentThreadableLoader> DocumentThreadableLoader::create(Document& document, ThreadableLoaderClient* client, const ThreadableLoaderOptions& options, const ResourceLoaderOptions& resourceLoaderOptions)
{
- RefPtr<DocumentThreadableLoader> loader = adoptRef(new DocumentThreadableLoader(document, client, LoadAsynchronously, request, options, resourceLoaderOptions));
- if (!loader->resource())
- loader = nullptr;
+ RefPtr<DocumentThreadableLoader> loader = adoptRef(new DocumentThreadableLoader(document, client, LoadAsynchronously, options, resourceLoaderOptions));
return loader.release();
hiroshige 2015/07/30 12:07:21 Now can we merge the two lines above into one?
tyoshino (SeeGerritForStatus) 2015/07/31 08:00:42 Done.
}
-DocumentThreadableLoader::DocumentThreadableLoader(Document& document, ThreadableLoaderClient* client, BlockingBehavior blockingBehavior, const ResourceRequest& request, const ThreadableLoaderOptions& options, const ResourceLoaderOptions& resourceLoaderOptions)
+DocumentThreadableLoader::DocumentThreadableLoader(Document& document, ThreadableLoaderClient* client, BlockingBehavior blockingBehavior, const ThreadableLoaderOptions& options, const ResourceLoaderOptions& resourceLoaderOptions)
: m_client(client)
, m_document(document)
, m_options(options)
, m_resourceLoaderOptions(resourceLoaderOptions)
, m_forceDoNotAllowStoredCredentials(false)
, m_securityOrigin(m_resourceLoaderOptions.securityOrigin)
- , m_sameOriginRequest(securityOrigin()->canRequestNoSuborigin(request.url()))
+ , m_sameOriginRequest(false)
hiroshige 2015/07/30 12:07:21 optional: Should we add a comment in the header th
tyoshino (SeeGerritForStatus) 2015/07/31 08:00:42 Said that start() must always follow create().
, m_crossOriginNonSimpleRequest(false)
, m_isUsingDataConsumerHandle(false)
, m_async(blockingBehavior == LoadAsynchronously)
- , m_requestContext(request.requestContext())
+ , m_requestContext(WebURLRequest::RequestContextUnspecified)
hiroshige 2015/07/30 12:07:21 ditto.
tyoshino (SeeGerritForStatus) 2015/07/31 08:00:42 Done.
, m_timeoutTimer(this, &DocumentThreadableLoader::didTimeout)
, m_requestStartedSeconds(0.0)
, m_corsRedirectLimit(kMaxCORSRedirects)
{
ASSERT(client);
+}
+
+void DocumentThreadableLoader::start(const ResourceRequest& request)
+{
// Setting an outgoing referer is only supported in the async code path.
ASSERT(m_async || request.httpReferrer().isEmpty());
+ m_sameOriginRequest = securityOrigin()->canRequestNoSuborigin(request.url());
+ m_requestContext = request.requestContext();
+
if (!m_sameOriginRequest && m_options.crossOriginRequestPolicy == DenyCrossOriginRequests) {
m_client->didFail(ResourceError(errorDomainBlinkInternal, 0, request.url().string(), "Cross origin requests are not supported."));
return;
@@ -128,7 +134,7 @@ DocumentThreadableLoader::DocumentThreadableLoader(Document& document, Threadabl
// of FetchRequestMode is not speced yet except for XHR. So we set here.
// FIXME: When we support fetch API in document, this value should not
// be overridden here.
- if (options.preflightPolicy == ForcePreflight)
+ if (m_options.preflightPolicy == ForcePreflight)
newRequest.setFetchRequestMode(WebURLRequest::FetchRequestModeCORSWithForcedPreflight);
else
newRequest.setFetchRequestMode(WebURLRequest::FetchRequestModeCORS);
@@ -593,11 +599,18 @@ void DocumentThreadableLoader::loadRequest(const ResourceRequest& request, Resou
if (m_options.crossOriginRequestPolicy == AllowCrossOriginRequests)
newRequest.setOriginRestriction(FetchRequest::NoOriginRestriction);
ASSERT(!resource());
+
if (request.requestContext() == WebURLRequest::RequestContextVideo || request.requestContext() == WebURLRequest::RequestContextAudio)
setResource(RawResource::fetchMedia(newRequest, m_document.fetcher()));
else
setResource(RawResource::fetch(newRequest, m_document.fetcher()));
- if (resource() && resource()->loader()) {
+
+ if (!resource()) {
+ m_client->didFail(ResourceError(errorDomainBlinkInternal, 0, requestURL.string(), "Failed to start loading."));
+ return;
+ }
+
+ if (resource()->loader()) {
unsigned long identifier = resource()->identifier();
InspectorInstrumentation::documentThreadableLoaderStartedLoadingForClient(&m_document, identifier, m_client);
}

Powered by Google App Engine
This is Rietveld 408576698