OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2011, 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2011, 2012 Google Inc. All rights reserved. |
3 * Copyright (C) 2013, Intel Corporation | 3 * Copyright (C) 2013, Intel Corporation |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions are | 6 * modification, are permitted provided that the following conditions are |
7 * met: | 7 * met: |
8 * | 8 * |
9 * * Redistributions of source code must retain the above copyright | 9 * * Redistributions of source code must retain the above copyright |
10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 , m_sameOriginRequest(false) | 144 , m_sameOriginRequest(false) |
145 , m_crossOriginNonSimpleRequest(false) | 145 , m_crossOriginNonSimpleRequest(false) |
146 , m_isUsingDataConsumerHandle(false) | 146 , m_isUsingDataConsumerHandle(false) |
147 , m_async(blockingBehavior == LoadAsynchronously) | 147 , m_async(blockingBehavior == LoadAsynchronously) |
148 , m_requestContext(WebURLRequest::RequestContextUnspecified) | 148 , m_requestContext(WebURLRequest::RequestContextUnspecified) |
149 , m_timeoutTimer(this, &DocumentThreadableLoader::didTimeout) | 149 , m_timeoutTimer(this, &DocumentThreadableLoader::didTimeout) |
150 , m_requestStartedSeconds(0.0) | 150 , m_requestStartedSeconds(0.0) |
151 , m_corsRedirectLimit(m_options.crossOriginRequestPolicy == UseAccessControl
? kMaxCORSRedirects : 0) | 151 , m_corsRedirectLimit(m_options.crossOriginRequestPolicy == UseAccessControl
? kMaxCORSRedirects : 0) |
152 , m_redirectMode(WebURLRequest::FetchRedirectModeFollow) | 152 , m_redirectMode(WebURLRequest::FetchRedirectModeFollow) |
153 , m_didRedirect(false) | 153 , m_didRedirect(false) |
154 , m_weakFactory(this) | |
155 { | 154 { |
156 DCHECK(client); | 155 DCHECK(client); |
157 } | 156 } |
158 | 157 |
159 void DocumentThreadableLoader::start(const ResourceRequest& request) | 158 void DocumentThreadableLoader::start(const ResourceRequest& request) |
160 { | 159 { |
161 // Setting an outgoing referer is only supported in the async code path. | 160 // Setting an outgoing referer is only supported in the async code path. |
162 DCHECK(m_async || request.httpReferrer().isEmpty()); | 161 DCHECK(m_async || request.httpReferrer().isEmpty()); |
163 | 162 |
164 m_sameOriginRequest = getSecurityOrigin()->canRequestNoSuborigin(request.url
()); | 163 m_sameOriginRequest = getSecurityOrigin()->canRequestNoSuborigin(request.url
()); |
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
427 reportResponseReceived(resource->identifier(), redirectResponse); | 426 reportResponseReceived(resource->identifier(), redirectResponse); |
428 | 427 |
429 handlePreflightFailure(redirectResponse.url().getString(), "Response for
preflight is invalid (redirect)"); | 428 handlePreflightFailure(redirectResponse.url().getString(), "Response for
preflight is invalid (redirect)"); |
430 | 429 |
431 request = ResourceRequest(); | 430 request = ResourceRequest(); |
432 | 431 |
433 return; | 432 return; |
434 } | 433 } |
435 | 434 |
436 if (m_redirectMode == WebURLRequest::FetchRedirectModeManual) { | 435 if (m_redirectMode == WebURLRequest::FetchRedirectModeManual) { |
437 // Keep |this| alive even if the client release a reference in | |
438 // responseReceived(). | |
439 WeakPtr<DocumentThreadableLoader> self(m_weakFactory.createWeakPtr()); | |
440 | |
441 // We use |m_redirectMode| to check the original redirect mode. | 436 // We use |m_redirectMode| to check the original redirect mode. |
442 // |request| is a new request for redirect. So we don't set the redirect | 437 // |request| is a new request for redirect. So we don't set the redirect |
443 // mode of it in WebURLLoaderImpl::Context::OnReceivedRedirect(). | 438 // mode of it in WebURLLoaderImpl::Context::OnReceivedRedirect(). |
444 DCHECK(request.useStreamOnResponse()); | 439 DCHECK(request.useStreamOnResponse()); |
445 // There is no need to read the body of redirect response because there | 440 // There is no need to read the body of redirect response because there |
446 // is no way to read the body of opaque-redirect filtered response's | 441 // is no way to read the body of opaque-redirect filtered response's |
447 // internal response. | 442 // internal response. |
448 // TODO(horo): If we support any API which expose the internal body, we | 443 // TODO(horo): If we support any API which expose the internal body, we |
449 // will have to read the body. And also HTTPCache changes will be needed | 444 // will have to read the body. And also HTTPCache changes will be needed |
450 // because it doesn't store the body of redirect responses. | 445 // because it doesn't store the body of redirect responses. |
451 responseReceived(resource, redirectResponse, wrapUnique(new EmptyDataHan
dle())); | 446 responseReceived(resource, redirectResponse, wrapUnique(new EmptyDataHan
dle())); |
452 | 447 |
453 if (!self) { | |
454 request = ResourceRequest(); | |
455 return; | |
456 } | |
457 | |
458 if (m_client) { | 448 if (m_client) { |
459 DCHECK(m_actualRequest.isNull()); | 449 DCHECK(m_actualRequest.isNull()); |
460 notifyFinished(resource); | 450 notifyFinished(resource); |
461 } | 451 } |
462 | 452 |
463 request = ResourceRequest(); | 453 request = ResourceRequest(); |
464 | 454 |
465 return; | 455 return; |
466 } | 456 } |
467 | 457 |
(...skipping 393 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
861 resourceLoaderOptions.dataBufferingPolicy = BufferData; | 851 resourceLoaderOptions.dataBufferingPolicy = BufferData; |
862 | 852 |
863 if (m_options.timeoutMilliseconds > 0) | 853 if (m_options.timeoutMilliseconds > 0) |
864 m_timeoutTimer.startOneShot(m_options.timeoutMilliseconds / 1000.0,
BLINK_FROM_HERE); | 854 m_timeoutTimer.startOneShot(m_options.timeoutMilliseconds / 1000.0,
BLINK_FROM_HERE); |
865 | 855 |
866 FetchRequest newRequest(request, m_options.initiator, resourceLoaderOpti
ons); | 856 FetchRequest newRequest(request, m_options.initiator, resourceLoaderOpti
ons); |
867 if (m_options.crossOriginRequestPolicy == AllowCrossOriginRequests) | 857 if (m_options.crossOriginRequestPolicy == AllowCrossOriginRequests) |
868 newRequest.setOriginRestriction(FetchRequest::NoOriginRestriction); | 858 newRequest.setOriginRestriction(FetchRequest::NoOriginRestriction); |
869 DCHECK(!resource()); | 859 DCHECK(!resource()); |
870 | 860 |
871 WeakPtr<DocumentThreadableLoader> self(m_weakFactory.createWeakPtr()); | |
872 | |
873 if (request.requestContext() == WebURLRequest::RequestContextVideo || re
quest.requestContext() == WebURLRequest::RequestContextAudio) | 861 if (request.requestContext() == WebURLRequest::RequestContextVideo || re
quest.requestContext() == WebURLRequest::RequestContextAudio) |
874 setResource(RawResource::fetchMedia(newRequest, document().fetcher()
)); | 862 setResource(RawResource::fetchMedia(newRequest, document().fetcher()
)); |
875 else if (request.requestContext() == WebURLRequest::RequestContextManife
st) | 863 else if (request.requestContext() == WebURLRequest::RequestContextManife
st) |
876 setResource(RawResource::fetchManifest(newRequest, document().fetche
r())); | 864 setResource(RawResource::fetchManifest(newRequest, document().fetche
r())); |
877 else | 865 else |
878 setResource(RawResource::fetch(newRequest, document().fetcher())); | 866 setResource(RawResource::fetch(newRequest, document().fetcher())); |
879 | 867 |
880 // setResource() might call notifyFinished() synchronously, and thus | |
881 if (!self) | |
882 return; | |
883 | |
884 if (!resource()) { | 868 if (!resource()) { |
885 InspectorInstrumentation::documentThreadableLoaderFailedToStartLoadi
ngForClient(m_document, m_client); | 869 InspectorInstrumentation::documentThreadableLoaderFailedToStartLoadi
ngForClient(m_document, m_client); |
886 ThreadableLoaderClient* client = m_client; | 870 ThreadableLoaderClient* client = m_client; |
887 clear(); | 871 clear(); |
888 // setResource() might call notifyFinished() and thus clear() | 872 // setResource() might call notifyFinished() and thus clear() |
889 // synchronously, and in such cases ThreadableLoaderClient is | 873 // synchronously, and in such cases ThreadableLoaderClient is |
890 // already notified and |client| is null. | 874 // already notified and |client| is null. |
891 if (!client) | 875 if (!client) |
892 return; | 876 return; |
893 client->didFail(ResourceError(errorDomainBlinkInternal, 0, requestUR
L.getString(), "Failed to start loading.")); | 877 client->didFail(ResourceError(errorDomainBlinkInternal, 0, requestUR
L.getString(), "Failed to start loading.")); |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
987 | 971 |
988 DEFINE_TRACE(DocumentThreadableLoader) | 972 DEFINE_TRACE(DocumentThreadableLoader) |
989 { | 973 { |
990 visitor->trace(m_resource); | 974 visitor->trace(m_resource); |
991 visitor->trace(m_document); | 975 visitor->trace(m_document); |
992 ThreadableLoader::trace(visitor); | 976 ThreadableLoader::trace(visitor); |
993 RawResourceClient::trace(visitor); | 977 RawResourceClient::trace(visitor); |
994 } | 978 } |
995 | 979 |
996 } // namespace blink | 980 } // namespace blink |
OLD | NEW |